Skip to content

Commit

Permalink
[DROOLS-1571] allow kie-spring to find resources even when the contex… (
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco authored May 22, 2017
1 parent 5a964c8 commit 96b27ea
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 6 deletions.
16 changes: 16 additions & 0 deletions kie-integration-test-coverage/kie-spring-test/.gitignore
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
79 changes: 79 additions & 0 deletions kie-integration-test-coverage/kie-spring-test/pom.xml
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>
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;
}
}
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
}
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 {
}
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>
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
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>
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());
}
}
1 change: 1 addition & 0 deletions kie-integration-test-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@

<modules>
<module>kie-maven-plugin-tests</module>
<module>kie-spring-test</module>
</modules>
</project>
Loading

0 comments on commit 96b27ea

Please sign in to comment.