BAEL-804 - Spring Drools refactor
This commit is contained in:
parent
52d5fbe603
commit
12166e9016
|
@ -14,42 +14,10 @@
|
|||
</parent>
|
||||
|
||||
<properties>
|
||||
<spring-boot-version>1.1.1.RELEASE</spring-boot-version>
|
||||
<http-component-version>4.0-alpha6</http-component-version>
|
||||
<drools-version>7.0.0.Final</drools-version>
|
||||
<apache-poi-version>3.13</apache-poi-version>
|
||||
<spring-framework.version>4.3.3.RELEASE</spring-framework.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.spring.platform</groupId>
|
||||
<artifactId>platform-bom</artifactId>
|
||||
<version>${spring-boot-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>${http-component-version}</version>
|
||||
</dependency>
|
||||
<!-- ... -->
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
|
@ -61,7 +29,6 @@
|
|||
<artifactId>drools-decisiontables</artifactId>
|
||||
<version>${drools-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-core</artifactId>
|
||||
|
@ -72,54 +39,18 @@
|
|||
<artifactId>drools-compiler</artifactId>
|
||||
<version>${drools-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>${apache-poi-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>${apache-poi-version}</version>
|
||||
</dependency>
|
||||
<!--spring integration-->
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
<artifactId>kie-spring</artifactId>
|
||||
<version>7.0.0.Final</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${drools-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring-framework.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue