forked from kiegroup/droolsjbpm-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DROOLS-1571] allow kie-spring to find resources even when the contex… (
- Loading branch information
1 parent
5a964c8
commit 96b27ea
Showing
11 changed files
with
359 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/target | ||
/local | ||
|
||
# Eclipse, Netbeans and IntelliJ files | ||
/.* | ||
!.gitignore | ||
/nbproject | ||
/*.ipr | ||
/*.iws | ||
/*.iml | ||
|
||
# Repository wide ignore mac DS_Store files | ||
.DS_Store | ||
|
||
# test files | ||
/*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>kie-integration-test-coverage-parent</artifactId> | ||
<groupId>org.drools.testcoverage</groupId> | ||
<version>7.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>kie-spring-test</artifactId> | ||
|
||
<name>KIE Integration :: KIE Spring Integration Test</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.kie</groupId> | ||
<artifactId>kie-spring</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-beans</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency><!-- For unit test logging: configure in src/test/resources/logback-test.xml --> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
41 changes: 41 additions & 0 deletions
41
...ion-test-coverage/kie-spring-test/src/main/java/org/kie/integrationtest/spring/Order.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.integrationtest.spring; | ||
|
||
public class Order { | ||
private final Party buyer; | ||
private final Party seller; | ||
private final OrderType type; | ||
|
||
public Order( final Party seller, final Party buyer, final OrderType type ) { | ||
this.buyer = buyer; | ||
this.seller = seller; | ||
this.type = type; | ||
} | ||
|
||
public Party getBuyer() { | ||
return buyer; | ||
} | ||
|
||
public Party getSeller() { | ||
return seller; | ||
} | ||
|
||
public OrderType getType() { | ||
return type; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...test-coverage/kie-spring-test/src/main/java/org/kie/integrationtest/spring/OrderType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.integrationtest.spring; | ||
|
||
public enum OrderType { | ||
CONSIGNMENT, | ||
SALE, | ||
TRANSFER | ||
} |
20 changes: 20 additions & 0 deletions
20
...ion-test-coverage/kie-spring-test/src/main/java/org/kie/integrationtest/spring/Party.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.integrationtest.spring; | ||
|
||
public class Party { | ||
} |
31 changes: 31 additions & 0 deletions
31
kie-integration-test-coverage/kie-spring-test/src/main/resources/droolsContext.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
~ Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:kie="http://drools.org/schema/kie-spring" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd"> | ||
<bean id="kiePostProcessor" class="org.kie.spring.annotations.KModuleAnnotationPostProcessor"/> | ||
|
||
<kie:kmodule id="drools"> | ||
<kie:kbase name="orderKnowledgeBase" packages="org.kie.integrationtest.spring"> | ||
<kie:ksession name="orderKnowledgeSession" type="stateless"/> | ||
</kie:kbase> | ||
</kie:kmodule> | ||
</beans> |
27 changes: 27 additions & 0 deletions
27
...test-coverage/kie-spring-test/src/main/resources/org.kie.integrationtest.spring/order.drl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.kie.integrationtest.spring; | ||
|
||
import java.util.Set; | ||
|
||
rule "consignment" | ||
when | ||
$errors: Set() | ||
$order: Order(type.equals(OrderType.CONSIGNMENT) && buyer.equals(seller)) | ||
then | ||
$errors.add("A party may not consign to itself."); | ||
end | ||
|
||
rule "sale" | ||
when | ||
$errors: Set() | ||
$order: Order(type.equals(OrderType.SALE) && buyer.equals(seller)) | ||
then | ||
$errors.add("A party may not sell to itself."); | ||
end | ||
|
||
rule "transfer" | ||
when | ||
$errors: Set() | ||
$order: Order(type.equals(OrderType.TRANSFER) && !buyer.equals(seller)) | ||
then | ||
$errors.add("A party may only transfer to itself."); | ||
end |
11 changes: 11 additions & 0 deletions
11
kie-integration-test-coverage/kie-spring-test/src/main/resources/springContext.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
<context:component-scan annotation-config="true" base-package="org.example"/> | ||
|
||
<import resource="droolsContext.xml"/> | ||
</beans> |
81 changes: 81 additions & 0 deletions
81
...test-coverage/kie-spring-test/src/test/java/org/kie/integrationtest/spring/OrderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2017 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.integrationtest.spring; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.kie.api.cdi.KSession; | ||
import org.kie.api.runtime.StatelessKieSession; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@ContextConfiguration(locations = "classpath:springContext.xml") | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
public class OrderTest { | ||
@KSession("orderKnowledgeSession") | ||
private StatelessKieSession orderRulesProcessor; | ||
|
||
private final Party buyer = new Party(); | ||
private final Party seller = new Party(); | ||
|
||
@Test | ||
public void testConsignmentOrder() { | ||
testOrder(new Order(seller, buyer, OrderType.CONSIGNMENT), 0); | ||
|
||
testOrder(new Order(buyer, seller, OrderType.CONSIGNMENT), 0); | ||
|
||
testOrder(new Order(buyer, buyer, OrderType.CONSIGNMENT), 1); | ||
|
||
testOrder(new Order(seller, seller, OrderType.CONSIGNMENT), 1); | ||
} | ||
|
||
@Test | ||
public void testSalesOrder() { | ||
testOrder(new Order(seller, buyer, OrderType.SALE), 0); | ||
|
||
testOrder(new Order(buyer, seller, OrderType.SALE), 0); | ||
|
||
testOrder(new Order(buyer, buyer, OrderType.SALE), 1); | ||
|
||
testOrder(new Order(seller, seller, OrderType.SALE), 1); | ||
} | ||
|
||
@Test | ||
public void testTransferOrder() { | ||
testOrder(new Order(buyer, buyer, OrderType.TRANSFER), 0); | ||
|
||
testOrder(new Order(seller, seller, OrderType.TRANSFER), 0); | ||
|
||
testOrder(new Order(buyer, seller, OrderType.TRANSFER), 1); | ||
|
||
testOrder(new Order(seller, buyer, OrderType.TRANSFER), 1); | ||
} | ||
|
||
private void testOrder(final Order order, final int errorCount) { | ||
final Set<String> errors = new HashSet<>(); | ||
|
||
orderRulesProcessor.execute(Arrays.asList(order, errors)); | ||
|
||
assertEquals(errorCount, errors.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ | |
|
||
<modules> | ||
<module>kie-maven-plugin-tests</module> | ||
<module>kie-spring-test</module> | ||
</modules> | ||
</project> |
Oops, something went wrong.