From f8e8aa0fce920b5c23d5017c2767771a459574a7 Mon Sep 17 00:00:00 2001 From: mokhan Date: Sun, 25 Jun 2017 13:40:38 +0530 Subject: [PATCH 1/3] Updated code to use latest version Modifed code sample to easy scenario Deleted exisiting Code/files which are not required --- spring-drools/pom.xml | 4 +- .../baeldung/spring/drools/Application.java | 30 ------ .../spring/drools/DroolConfiguration.java | 83 --------------- .../spring/drools/app/ApplicationRunner.java | 24 +++++ .../spring/drools/model/Applicant.java | 48 --------- .../baeldung/spring/drools/model/Fare.java | 39 +++++++ .../baeldung/spring/drools/model/Product.java | 38 ------- .../spring/drools/model/SuggestedRole.java | 14 --- .../spring/drools/model/TaxiRide.java | 24 +++++ .../drools/service/ApplicantService.java | 25 ----- .../spring/drools/service/ProductService.java | 24 ----- .../service/TaxiFareCalculatorService.java | 22 ++++ .../drools/service/TaxiFareConfiguration.java | 39 +++++++ .../src/main/resources/TAXI_FARE_RULE.drl | 57 +++++++++++ .../spring/drools/rules/Product_rules.xls | Bin 27648 -> 0 bytes .../spring/drools/rules/SuggestApplicant.drl | 31 ------ .../ApplicantServiceIntegrationTest.java | 52 ---------- .../ProductServiceIntegrationTest.java | 34 ------- .../TaxiFareCalculatorServiceTest.java | 95 ++++++++++++++++++ 19 files changed, 302 insertions(+), 381 deletions(-) delete mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/Application.java delete mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/DroolConfiguration.java create mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/app/ApplicationRunner.java delete mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/model/Applicant.java create mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/model/Fare.java delete mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/model/Product.java delete mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/model/SuggestedRole.java create mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/model/TaxiRide.java delete mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/service/ApplicantService.java delete mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/service/ProductService.java create mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareCalculatorService.java create mode 100644 spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java create mode 100644 spring-drools/src/main/resources/TAXI_FARE_RULE.drl delete mode 100644 spring-drools/src/main/resources/com/baeldung/spring/drools/rules/Product_rules.xls delete mode 100644 spring-drools/src/main/resources/com/baeldung/spring/drools/rules/SuggestApplicant.drl delete mode 100644 spring-drools/src/test/java/com/baeldung/spring/drools/service/ApplicantServiceIntegrationTest.java delete mode 100644 spring-drools/src/test/java/com/baeldung/spring/drools/service/ProductServiceIntegrationTest.java create mode 100644 spring-drools/src/test/java/com/baeldung/spring/drools/service/TaxiFareCalculatorServiceTest.java diff --git a/spring-drools/pom.xml b/spring-drools/pom.xml index 8dba1271d7..de2ccd882b 100644 --- a/spring-drools/pom.xml +++ b/spring-drools/pom.xml @@ -16,7 +16,7 @@ 1.1.1.RELEASE 4.0-alpha6 - 7.0.0.CR1 + 7.0.0.Final 3.13 @@ -86,7 +86,7 @@ org.kie kie-spring - 6.4.0.Final + 7.0.0.Final org.springframework diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/Application.java b/spring-drools/src/main/java/com/baeldung/spring/drools/Application.java deleted file mode 100644 index 8f5b915f88..0000000000 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/Application.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.spring.drools; - - -import com.baeldung.spring.drools.model.Applicant; -import com.baeldung.spring.drools.model.Product; -import com.baeldung.spring.drools.model.SuggestedRole; -import com.baeldung.spring.drools.service.ApplicantService; -import com.baeldung.spring.drools.service.ProductService; -import org.kie.api.KieServices; -import org.kie.api.runtime.KieContainer; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Import; - -@SpringBootApplication -@Import(DroolConfiguration.class) -public class Application { - - public static void main(String[] args) { - ApplicationContext ctx = SpringApplication.run(Application.class, args); - ApplicantService applicantService=(ApplicantService)ctx.getBean("applicantService"); - applicantService.suggestARoleForApplicant(new Applicant("Baljeet",37,1200000.0,8),new SuggestedRole()); - - ProductService productService=(ProductService)ctx.getBean("productService"); - Product returnedProduct=productService.applyLabelToProduct(new Product("Microwave","Book")); - } - -} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/DroolConfiguration.java b/spring-drools/src/main/java/com/baeldung/spring/drools/DroolConfiguration.java deleted file mode 100644 index 7a5e833ed5..0000000000 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/DroolConfiguration.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.baeldung.spring.drools; - -import com.baeldung.spring.drools.service.ApplicantService; -import com.baeldung.spring.drools.service.ProductService; -import org.kie.api.KieBase; -import org.kie.api.KieServices; -import org.kie.api.builder.*; -import org.kie.api.runtime.KieContainer; -import org.kie.api.runtime.KieSession; -import org.kie.internal.io.ResourceFactory; -import org.kie.spring.KModuleBeanFactoryPostProcessor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; - -import java.io.IOException; - -@Configuration -public class DroolConfiguration { - - private static final String RULES_PATH = "com/baeldung/spring/drools/rules/"; - - @Bean - public KieFileSystem kieFileSystem() throws IOException { - KieFileSystem kieFileSystem = getKieServices().newKieFileSystem(); - for (Resource file : getRuleFiles()) { - kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + file.getFilename(), "UTF-8")); - } - return kieFileSystem; - } - - private Resource[] getRuleFiles() throws IOException { - ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); - return resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "**/*.*"); - } - - @Bean - public KieContainer kieContainer() throws IOException { - final KieRepository kieRepository = getKieServices().getRepository(); - - kieRepository.addKieModule(new KieModule() { - public ReleaseId getReleaseId() { - return kieRepository.getDefaultReleaseId(); - } - }); - - KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem()); - kieBuilder.buildAll(); - - return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId()); - } - - private KieServices getKieServices() { - return KieServices.Factory.get(); - } - - @Bean - public KieBase kieBase() throws IOException { - return kieContainer().getKieBase(); - } - - @Bean - public KieSession kieSession() throws IOException { - return kieContainer().newKieSession(); - } - - @Bean - public ApplicantService getApplicantService(){ - return new ApplicantService(); - } - - @Bean - public ProductService getProductService(KieContainer kieContainer){ - return new ProductService(); - } - - @Bean - public KModuleBeanFactoryPostProcessor kiePostProcessor() { - return new KModuleBeanFactoryPostProcessor(); - } -} \ No newline at end of file diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/app/ApplicationRunner.java b/spring-drools/src/main/java/com/baeldung/spring/drools/app/ApplicationRunner.java new file mode 100644 index 0000000000..e8f926cc6f --- /dev/null +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/app/ApplicationRunner.java @@ -0,0 +1,24 @@ +package com.baeldung.spring.drools.app; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import com.baeldung.spring.drools.model.TaxiRide; +import com.baeldung.spring.drools.model.Fare; +import com.baeldung.spring.drools.service.TaxiFareCalculatorService; +import com.baeldung.spring.drools.service.TaxiFareConfiguration; + +public class ApplicationRunner { + + public static void main(String[] args) { + ApplicationContext context = new AnnotationConfigApplicationContext(TaxiFareConfiguration.class); + TaxiFareCalculatorService orderService = (TaxiFareCalculatorService) context.getBean(TaxiFareCalculatorService.class); + + TaxiRide taxiRide = new TaxiRide(); + taxiRide.setbNightSurcharge(true); + taxiRide.setDistanceInMile(190L); + Fare rideFare = new Fare(); + orderService.calculateFare(taxiRide, rideFare); + } + +} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/model/Applicant.java b/spring-drools/src/main/java/com/baeldung/spring/drools/model/Applicant.java deleted file mode 100644 index f28d0fcab7..0000000000 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/model/Applicant.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.spring.drools.model; - -public class Applicant { - - private String name; - private int age; - private double currentSalary; - private int experienceInYears; - - public Applicant(String name, int age, Double currentSalary, int experienceInYears) { - this.name = name; - this.age = age; - this.currentSalary = currentSalary; - this.experienceInYears = experienceInYears; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public Double getCurrentSalary() { - return currentSalary; - } - - public void setCurrentSalary(Double currentSalary) { - this.currentSalary = currentSalary; - } - - public int getExperienceInYears() { - return experienceInYears; - } - - public void setExperienceInYears(int experienceInYears) { - this.experienceInYears = experienceInYears; - } -} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/model/Fare.java b/spring-drools/src/main/java/com/baeldung/spring/drools/model/Fare.java new file mode 100644 index 0000000000..a67156f167 --- /dev/null +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/model/Fare.java @@ -0,0 +1,39 @@ +package com.baeldung.spring.drools.model; + +public class Fare { + + private Long nightSurcharge; + private Long rideFare; + private Long totalFare; + + public Fare() { + nightSurcharge = 0L; + rideFare = 0L; + totalFare = 0L; + } + + public Long getNightSurcharge() { + return nightSurcharge; + } + + public void setNightSurcharge(Long nightSurcharge) { + this.nightSurcharge = nightSurcharge; + } + + public Long getRideFare() { + return rideFare; + } + + public void setRideFare(Long rideFare) { + this.rideFare = rideFare; + } + + public Long getTotalFare() { + return nightSurcharge + rideFare; + } + + public void setTotalFare(Long totalFare) { + this.totalFare = totalFare; + } + +} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/model/Product.java b/spring-drools/src/main/java/com/baeldung/spring/drools/model/Product.java deleted file mode 100644 index a861df5834..0000000000 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/model/Product.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.spring.drools.model; - -public class Product { - private String name; - private String type; - - private String label; - - public Product(String name, String type) { - this.name = name; - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - -} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/model/SuggestedRole.java b/spring-drools/src/main/java/com/baeldung/spring/drools/model/SuggestedRole.java deleted file mode 100644 index 1ace5aa4ae..0000000000 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/model/SuggestedRole.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.spring.drools.model; - -public class SuggestedRole { - - private String role; - - public String getRole() { - return role; - } - - public void setRole(String role) { - this.role = role; - } -} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/model/TaxiRide.java b/spring-drools/src/main/java/com/baeldung/spring/drools/model/TaxiRide.java new file mode 100644 index 0000000000..6dc08bbb60 --- /dev/null +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/model/TaxiRide.java @@ -0,0 +1,24 @@ +package com.baeldung.spring.drools.model; + +public class TaxiRide { + + private Boolean bNightSurcharge; + private Long distanceInMile; + + public Boolean getbNightSurcharge() { + return bNightSurcharge; + } + + public void setbNightSurcharge(Boolean bNightSurcharge) { + this.bNightSurcharge = bNightSurcharge; + } + + public Long getDistanceInMile() { + return distanceInMile; + } + + public void setDistanceInMile(Long distanceInMile) { + this.distanceInMile = distanceInMile; + } + +} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/service/ApplicantService.java b/spring-drools/src/main/java/com/baeldung/spring/drools/service/ApplicantService.java deleted file mode 100644 index f78ffe668b..0000000000 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/service/ApplicantService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.spring.drools.service; - -import com.baeldung.spring.drools.model.Applicant; -import com.baeldung.spring.drools.model.SuggestedRole; -import org.kie.api.runtime.KieContainer; -import org.kie.api.runtime.KieSession; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class ApplicantService { - - @Autowired - private KieContainer kieContainer; - - public SuggestedRole suggestARoleForApplicant(Applicant applicant,SuggestedRole suggestedRole){ - KieSession kieSession = kieContainer.newKieSession(); - kieSession.insert(applicant); - kieSession.setGlobal("suggestedRole",suggestedRole); - kieSession.fireAllRules(); - System.out.println(suggestedRole.getRole()); - return suggestedRole; - - } -} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/service/ProductService.java b/spring-drools/src/main/java/com/baeldung/spring/drools/service/ProductService.java deleted file mode 100644 index 21ca9c9730..0000000000 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/service/ProductService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.spring.drools.service; - -import com.baeldung.spring.drools.model.Product; -import org.kie.api.runtime.KieContainer; -import org.kie.api.runtime.KieSession; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class ProductService { - - @Autowired - private KieContainer kieContainer; - - public Product applyLabelToProduct(Product product){ - KieSession kieSession = kieContainer.newKieSession(); - kieSession.insert(product); - kieSession.fireAllRules(); - System.out.println(product.getLabel()); - return product; - - } - -} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareCalculatorService.java b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareCalculatorService.java new file mode 100644 index 0000000000..4279643339 --- /dev/null +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareCalculatorService.java @@ -0,0 +1,22 @@ +package com.baeldung.spring.drools.service; + +import org.kie.api.runtime.KieSession; +import org.springframework.beans.factory.annotation.Autowired; + +import com.baeldung.spring.drools.model.Fare; +import com.baeldung.spring.drools.model.TaxiRide; + +public class TaxiFareCalculatorService { + + @Autowired + private KieSession kieSession; + + public Long calculateFare(TaxiRide taxiRide, Fare rideFare) { + kieSession.setGlobal("rideFare", rideFare); + kieSession.insert(taxiRide); + kieSession.fireAllRules(); + kieSession.dispose(); + System.out.println("!! RIDE FARE !! " + rideFare.getTotalFare()); + return rideFare.getTotalFare(); + } +} diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java new file mode 100644 index 0000000000..69c910f84d --- /dev/null +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java @@ -0,0 +1,39 @@ +package com.baeldung.spring.drools.service; + +import org.kie.api.KieServices; +import org.kie.api.builder.KieBuilder; +import org.kie.api.builder.KieFileSystem; +import org.kie.api.builder.KieModule; +import org.kie.api.runtime.KieContainer; +import org.kie.api.runtime.KieSession; +import org.kie.internal.io.ResourceFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class TaxiFareConfiguration { + + public static final String drlFile = "TAXI_FARE_RULE.drl"; + + @Bean + public KieSession kieSession() { + KieServices kieServices = KieServices.Factory.get(); + + KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); + kieFileSystem.write(ResourceFactory.newClassPathResource(drlFile)); + KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem); + kieBuilder.buildAll(); + KieModule kieModule = kieBuilder.getKieModule(); + + KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId()); + KieSession ksession = kContainer.newKieSession(); + + return ksession; + } + + @Bean + public TaxiFareCalculatorService taxiFareCalculatorService() { + TaxiFareCalculatorService taxiFareCalculatorService = new TaxiFareCalculatorService(); + return taxiFareCalculatorService; + } +} diff --git a/spring-drools/src/main/resources/TAXI_FARE_RULE.drl b/spring-drools/src/main/resources/TAXI_FARE_RULE.drl new file mode 100644 index 0000000000..56335c08b3 --- /dev/null +++ b/spring-drools/src/main/resources/TAXI_FARE_RULE.drl @@ -0,0 +1,57 @@ +import com.baeldung.spring.drools.model.TaxiRide; +import com.baeldung.spring.drools.model.Fare; +import java.util.*; + +global com.baeldung.spring.drools.model.Fare rideFare; +dialect "mvel" + +rule "Calculate Taxi Fare - Scenario 1" + when + taxiRideInstance:TaxiRide(bNightSurcharge == false && distanceInMile < 10); + then + rideFare.setNightSurcharge(0); + rideFare.setRideFare(70); +end + +rule "Calculate Taxi Fare - Scenario 2" + when + taxiRideInstance:TaxiRide(bNightSurcharge == true && distanceInMile < 10); + then + rideFare.setNightSurcharge(30); + rideFare.setRideFare(70); +end + + +rule "Calculate Taxi Fare - Scenario 3" + when + taxiRideInstance:TaxiRide(bNightSurcharge == false && distanceInMile >= 10 && distanceInMile < 100); + then + rideFare.setNightSurcharge(0); + rideFare.setRideFare(70+(2*taxiRideInstance.getDistanceInMile())); +end + + +rule "Calculate Taxi Fare - Scenario 4" + when + taxiRideInstance:TaxiRide(bNightSurcharge == true && distanceInMile >= 10 && distanceInMile < 100); + then + rideFare.setNightSurcharge(30+taxiRideInstance.getDistanceInMile()); + rideFare.setRideFare(70+(2*taxiRideInstance.getDistanceInMile())); +end + + +rule "Calculate Taxi Fare - Scenario 5" + when + taxiRideInstance:TaxiRide(bNightSurcharge == false && distanceInMile >= 100); + then + rideFare.setNightSurcharge(0); + rideFare.setRideFare(70+(1.5*taxiRideInstance.getDistanceInMile())); +end + +rule "Calculate Taxi Fare - Scenario 6" + when + taxiRideInstance:TaxiRide(bNightSurcharge == true && distanceInMile >= 100); + then + rideFare.setNightSurcharge(30+taxiRideInstance.getDistanceInMile()); + rideFare.setRideFare(70+(1.5*taxiRideInstance.getDistanceInMile())); +end diff --git a/spring-drools/src/main/resources/com/baeldung/spring/drools/rules/Product_rules.xls b/spring-drools/src/main/resources/com/baeldung/spring/drools/rules/Product_rules.xls deleted file mode 100644 index 24caaf24707c1c8df2934def23897f213b30a990..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 27648 z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wT zLqIMU_h~rxHH}s%CD;2{_|Sn!8J53Tw#o5GBx%Lu=(qp~o4DM>Dn=wq@d;=A(dSoK z-I(5d^u;G)bg!f}n}GEeJ)0+5AJwQxhpp&n6+cTwo$Z33$}pX78;qk|gUz@@(1h?h zbQFao{v@ym5feYXOV4)u~C{2i7`*aRXL1o!5T*Otzl%7<}iw?5QWOz@WmXRJfx7j zn3Ew#F>1;YmELG?%t?_Wm{=w=%Tb*^oNp?lq0$?xGO;G;o8<`F8+F7o8brOJJ7bP& zQtli$`W>I`5OJZudn^HbNqJlXD|@^pd}nEoZrP;=|L+M z2P=t<#t$hJr(?nR8Tp@#A>QJ@w||`k$OMdDSsW5{3R(Pr708Upkjd2O|5zXsr_cXh z|2YzPgWVhlSMCU)UDHL7tCN;Jei5JU{>8^~*0j-<3*;hFQ9!Pm%JY!OcBUZFh@Oi? zHnbdx+`|qevZZg4$RQUYkxgAjBD;EpM1fy9kdckii-l$rt?)^y)p-Mf^kQ&w9FdfNPt4$SBT8J;OrZ>rl( zfpgP3wKiSg=i^Zpj%2*T@sKy9+Nl0X2PO2(iv5-ysA_oD-<^Jb_eqK9AE~hXmp%PS z&m29o*uReZocYk7-;0f;Khg>50HWmKV;n}ui$RooZ+w#M1|iY5P&yKYoU)N<185`? z>17_0Q4b=|;>!?V!)&nhrxy@Y8?pm&4arS|f4PBGFcgv^$pCs8<0vbb|u}LxmC|oRP?kw6s=y%Zb#v5D xMf*PiF2QyleaAE#TVBa*$Y1UfO|{LvVR;acipi$_uIsPT|GVfK@%%f}{~xuG(?b9N diff --git a/spring-drools/src/main/resources/com/baeldung/spring/drools/rules/SuggestApplicant.drl b/spring-drools/src/main/resources/com/baeldung/spring/drools/rules/SuggestApplicant.drl deleted file mode 100644 index baaf29d0b4..0000000000 --- a/spring-drools/src/main/resources/com/baeldung/spring/drools/rules/SuggestApplicant.drl +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.spring.drools.rules; - -import com.baeldung.spring.drools.model.Applicant; - -global com.baeldung.spring.drools.model.SuggestedRole suggestedRole; - -dialect "mvel" - -rule "Suggest Manager Role" - when - Applicant(experienceInYears > 10) - Applicant(currentSalary > 1000000 && currentSalary <= 2500000) - then - suggestedRole.setRole("Manager"); -end - -rule "Suggest Senior developer Role" - when - Applicant(experienceInYears > 5 && experienceInYears <= 10) - Applicant(currentSalary > 500000 && currentSalary <= 1500000) - then - suggestedRole.setRole("Senior developer"); -end - -rule "Suggest Developer Role" - when - Applicant(experienceInYears > 0 && experienceInYears <= 5) - Applicant(currentSalary > 200000 && currentSalary <= 1000000) - then - suggestedRole.setRole("Developer"); -end diff --git a/spring-drools/src/test/java/com/baeldung/spring/drools/service/ApplicantServiceIntegrationTest.java b/spring-drools/src/test/java/com/baeldung/spring/drools/service/ApplicantServiceIntegrationTest.java deleted file mode 100644 index d7e7634c00..0000000000 --- a/spring-drools/src/test/java/com/baeldung/spring/drools/service/ApplicantServiceIntegrationTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.spring.drools.service; - -import com.baeldung.spring.drools.Application; -import com.baeldung.spring.drools.DroolConfiguration; -import com.baeldung.spring.drools.model.Applicant; -import com.baeldung.spring.drools.model.SuggestedRole; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static junit.framework.Assert.assertNull; -import static junit.framework.TestCase.assertEquals; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {DroolConfiguration.class}) -public class ApplicantServiceIntegrationTest { - - @Autowired - ApplicantService applicantService; - - @Test - public void whenCriteriaMatching_ThenSuggestManagerRole(){ - Applicant applicant=new Applicant("Davis",37,1600000.0,11); - SuggestedRole suggestedRole=new SuggestedRole(); - applicantService.suggestARoleForApplicant(applicant,suggestedRole); - assertEquals("Manager",suggestedRole.getRole()); - } - - @Test - public void whenCriteriaMatching_ThenSuggestSeniorDeveloperRole(){ - Applicant applicant=new Applicant("John",37,1200000.0,8); - SuggestedRole suggestedRole=new SuggestedRole(); - applicantService.suggestARoleForApplicant(applicant,suggestedRole); - assertEquals("Senior developer",suggestedRole.getRole()); - } - @Test - public void whenCriteriaMatching_ThenSuggestDeveloperRole(){ - Applicant applicant=new Applicant("Davis",37,800000.0,3); - SuggestedRole suggestedRole=new SuggestedRole(); - applicantService.suggestARoleForApplicant(applicant,suggestedRole); - assertEquals("Developer",suggestedRole.getRole()); - } - @Test - public void whenCriteriaNotMatching_ThenNoRole(){ - Applicant applicant=new Applicant("John",37,1200000.0,5); - SuggestedRole suggestedRole=new SuggestedRole(); - applicantService.suggestARoleForApplicant(applicant,suggestedRole); - assertNull(suggestedRole.getRole()); - } -} diff --git a/spring-drools/src/test/java/com/baeldung/spring/drools/service/ProductServiceIntegrationTest.java b/spring-drools/src/test/java/com/baeldung/spring/drools/service/ProductServiceIntegrationTest.java deleted file mode 100644 index 7a442e48fd..0000000000 --- a/spring-drools/src/test/java/com/baeldung/spring/drools/service/ProductServiceIntegrationTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.spring.drools.service; - -import com.baeldung.spring.drools.Application; -import com.baeldung.spring.drools.DroolConfiguration; -import com.baeldung.spring.drools.model.Product; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static junit.framework.TestCase.assertEquals; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {DroolConfiguration.class}) -public class ProductServiceIntegrationTest { - - @Autowired - ProductService productService; - - @Test - public void whenProductTypeElectronic_ThenLabelBarcode(){ - Product product=new Product("Microwave","Electronic"); - product=productService.applyLabelToProduct(product); - assertEquals("BarCode",product.getLabel()); - } - - @Test - public void whenProductTypeBook_ThenLabelIsbn(){ - Product product=new Product("AutoBiography","Book"); - product=productService.applyLabelToProduct(product); - assertEquals("ISBN",product.getLabel()); - } -} diff --git a/spring-drools/src/test/java/com/baeldung/spring/drools/service/TaxiFareCalculatorServiceTest.java b/spring-drools/src/test/java/com/baeldung/spring/drools/service/TaxiFareCalculatorServiceTest.java new file mode 100644 index 0000000000..b8e105a785 --- /dev/null +++ b/spring-drools/src/test/java/com/baeldung/spring/drools/service/TaxiFareCalculatorServiceTest.java @@ -0,0 +1,95 @@ +package com.baeldung.spring.drools.service; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import com.baeldung.spring.drools.model.TaxiRide; +import com.baeldung.spring.drools.model.Fare; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class) +public class TaxiFareCalculatorServiceTest { + + ApplicationContext context = null; + TaxiFareCalculatorService taxiFareCalculatorService = null; + + @Before + public void init() { + context = new AnnotationConfigApplicationContext(TaxiFareConfiguration.class); + taxiFareCalculatorService = (TaxiFareCalculatorService) context.getBean(TaxiFareCalculatorService.class); + } + + @Test + public void testCalculateFareScenario1() { + TaxiRide taxiRide = new TaxiRide(); + taxiRide.setbNightSurcharge(false); + taxiRide.setDistanceInMile(9L); + Fare rideFare = new Fare(); + Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); + Assert.assertNotNull(totalCharge); + Assert.assertEquals(Long.valueOf(70), totalCharge); + } + + @Test + public void testCalculateFareScenario2() { + TaxiRide taxiRide = new TaxiRide(); + taxiRide.setbNightSurcharge(true); + taxiRide.setDistanceInMile(5L); + Fare rideFare = new Fare(); + Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); + Assert.assertNotNull(totalCharge); + Assert.assertEquals(Long.valueOf(100), totalCharge); + } + + @Test + public void testCalculateFareScenario3() { + TaxiRide taxiRide = new TaxiRide(); + taxiRide.setbNightSurcharge(false); + taxiRide.setDistanceInMile(50L); + Fare rideFare = new Fare(); + Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); + Assert.assertNotNull(totalCharge); + Assert.assertEquals(Long.valueOf(170), totalCharge); + } + + @Test + public void testCalculateFareScenario4() { + TaxiRide taxiRide = new TaxiRide(); + taxiRide.setbNightSurcharge(true); + taxiRide.setDistanceInMile(50L); + Fare rideFare = new Fare(); + Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); + Assert.assertNotNull(totalCharge); + Assert.assertEquals(Long.valueOf(250), totalCharge); + } + + @Test + public void testCalculateFareScenario5() { + TaxiRide taxiRide = new TaxiRide(); + taxiRide.setbNightSurcharge(false); + taxiRide.setDistanceInMile(100L); + Fare rideFare = new Fare(); + Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); + Assert.assertNotNull(totalCharge); + Assert.assertEquals(Long.valueOf(220), totalCharge); + } + + @Test + public void testCalculateFareScenario6() { + TaxiRide taxiRide = new TaxiRide(); + taxiRide.setbNightSurcharge(true); + taxiRide.setDistanceInMile(100L); + Fare rideFare = new Fare(); + Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); + Assert.assertNotNull(totalCharge); + Assert.assertEquals(Long.valueOf(350), totalCharge); + } + +} From 12166e9016f013a009b0f23e780d06fbd0db8f36 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Tue, 27 Jun 2017 16:02:53 +0100 Subject: [PATCH 2/3] BAEL-804 - Spring Drools refactor --- spring-drools/pom.xml | 87 ++----------------- .../service/TaxiFareCalculatorService.java | 4 +- .../drools/service/TaxiFareConfiguration.java | 5 +- .../TaxiFareCalculatorServiceTest.java | 13 +-- 4 files changed, 18 insertions(+), 91 deletions(-) diff --git a/spring-drools/pom.xml b/spring-drools/pom.xml index de2ccd882b..239c0c065c 100644 --- a/spring-drools/pom.xml +++ b/spring-drools/pom.xml @@ -14,42 +14,10 @@ - 1.1.1.RELEASE - 4.0-alpha6 7.0.0.Final - 3.13 + 4.3.3.RELEASE - - - - io.spring.platform - platform-bom - ${spring-boot-version} - pom - import - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-actuator - - - org.apache.httpcomponents - httpcore - ${http-component-version} - org.kie @@ -61,7 +29,6 @@ drools-decisiontables ${drools-version} - org.drools drools-core @@ -72,54 +39,18 @@ drools-compiler ${drools-version} - - org.apache.poi - poi - ${apache-poi-version} - - - org.apache.poi - poi-ooxml - ${apache-poi-version} - + org.kie kie-spring - 7.0.0.Final - - - org.springframework - spring-tx - - - org.springframework - spring-beans - - - org.springframework - spring-core - - - org.springframework - spring-context - - + ${drools-version} + + + org.springframework + spring-test + ${spring-framework.version} + test - - - - org.springframework.boot - spring-boot-maven-plugin - - - - repackage - - - - - - \ No newline at end of file diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareCalculatorService.java b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareCalculatorService.java index 4279643339..0407eff5d9 100644 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareCalculatorService.java +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareCalculatorService.java @@ -1,5 +1,6 @@ package com.baeldung.spring.drools.service; +import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; import org.springframework.beans.factory.annotation.Autowired; @@ -9,9 +10,10 @@ import com.baeldung.spring.drools.model.TaxiRide; public class TaxiFareCalculatorService { @Autowired - private KieSession kieSession; + private KieContainer kieContainer; public Long calculateFare(TaxiRide taxiRide, Fare rideFare) { + KieSession kieSession = kieContainer.newKieSession(); kieSession.setGlobal("rideFare", rideFare); kieSession.insert(taxiRide); kieSession.fireAllRules(); diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java index 69c910f84d..5c8965991f 100644 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java @@ -16,7 +16,7 @@ public class TaxiFareConfiguration { public static final String drlFile = "TAXI_FARE_RULE.drl"; @Bean - public KieSession kieSession() { + public KieContainer kieSession() { KieServices kieServices = KieServices.Factory.get(); KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); @@ -26,9 +26,8 @@ public class TaxiFareConfiguration { KieModule kieModule = kieBuilder.getKieModule(); KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId()); - KieSession ksession = kContainer.newKieSession(); - return ksession; + return kContainer; } @Bean diff --git a/spring-drools/src/test/java/com/baeldung/spring/drools/service/TaxiFareCalculatorServiceTest.java b/spring-drools/src/test/java/com/baeldung/spring/drools/service/TaxiFareCalculatorServiceTest.java index b8e105a785..5569772c48 100644 --- a/spring-drools/src/test/java/com/baeldung/spring/drools/service/TaxiFareCalculatorServiceTest.java +++ b/spring-drools/src/test/java/com/baeldung/spring/drools/service/TaxiFareCalculatorServiceTest.java @@ -4,6 +4,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.test.context.ContextConfiguration; @@ -14,17 +15,11 @@ import com.baeldung.spring.drools.model.TaxiRide; import com.baeldung.spring.drools.model.Fare; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(loader = AnnotationConfigContextLoader.class) +@ContextConfiguration(classes = TaxiFareConfiguration.class) public class TaxiFareCalculatorServiceTest { - ApplicationContext context = null; - TaxiFareCalculatorService taxiFareCalculatorService = null; - - @Before - public void init() { - context = new AnnotationConfigApplicationContext(TaxiFareConfiguration.class); - taxiFareCalculatorService = (TaxiFareCalculatorService) context.getBean(TaxiFareCalculatorService.class); - } + @Autowired + TaxiFareCalculatorService taxiFareCalculatorService; @Test public void testCalculateFareScenario1() { From 21865398d730fcee89ccaa1779bda3ed3c3c9c94 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Wed, 28 Jun 2017 21:48:29 +0100 Subject: [PATCH 3/3] BAEL-804 - Spring Drools refactor --- .../java/com/baeldung/spring/drools/app/ApplicationRunner.java | 2 +- .../baeldung/spring/drools/service/TaxiFareConfiguration.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/app/ApplicationRunner.java b/spring-drools/src/main/java/com/baeldung/spring/drools/app/ApplicationRunner.java index e8f926cc6f..ce4b49451a 100644 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/app/ApplicationRunner.java +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/app/ApplicationRunner.java @@ -12,7 +12,7 @@ public class ApplicationRunner { public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(TaxiFareConfiguration.class); - TaxiFareCalculatorService orderService = (TaxiFareCalculatorService) context.getBean(TaxiFareCalculatorService.class); + TaxiFareCalculatorService orderService = context.getBean(TaxiFareCalculatorService.class); TaxiRide taxiRide = new TaxiRide(); taxiRide.setbNightSurcharge(true); diff --git a/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java index 5c8965991f..8fed574639 100644 --- a/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java +++ b/spring-drools/src/main/java/com/baeldung/spring/drools/service/TaxiFareConfiguration.java @@ -16,7 +16,7 @@ public class TaxiFareConfiguration { public static final String drlFile = "TAXI_FARE_RULE.drl"; @Bean - public KieContainer kieSession() { + public KieContainer kieContainer() { KieServices kieServices = KieServices.Factory.get(); KieFileSystem kieFileSystem = kieServices.newKieFileSystem();