Skip to content

Commit

Permalink
KOGITO-1943 - Add integration tests with Infinispan (apache#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianonicolai committed Apr 28, 2020
1 parent f6163e8 commit cd880e7
Show file tree
Hide file tree
Showing 16 changed files with 387 additions and 41 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<!-- infinispan -->
<infinispan.version>10.1.5.Final</infinispan.version>
<infinispan.starter.version>2.2.3.Final</infinispan.starter.version>
<container.image.infinispan>quay.io/infinispan/server:${infinispan.version}</container.image.infinispan>
<version.testcontainers>1.12.4</version.testcontainers>
<!-- jsonpath-->
<version.jayway.jsonpath>2.4.0</version.jayway.jsonpath>
Expand Down Expand Up @@ -171,6 +172,11 @@
<artifactId>testcontainers</artifactId>
<version>${version.testcontainers}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${version.testcontainers}</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
Expand Down
33 changes: 25 additions & 8 deletions process-infinispan-persistence-quarkus/pom.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
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"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -16,9 +16,6 @@
<name>Kogito Examples :: Process Infinispan Persistence Quarkus</name>
<description>Process with Infinispan persistence - Quarkus</description>




<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -47,7 +44,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>

<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>infinispan-persistence-addon</artifactId>
Expand All @@ -62,7 +58,11 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
Expand All @@ -86,6 +86,23 @@
</systemProperties>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<container.image.infinispan>${container.image.infinispan}</container.image.infinispan>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package org.acme.travels;
/*
* Copyright 2020 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.acme.deals;

public class Address {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package org.acme.travels;
/*
* Copyright 2020 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.acme.deals;

public class Traveller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.omg.org/bpmn20" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpsim="http://www.bpsim.org/schemas/1.0" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" id="_JmONwEk-EeqlMa7ut9bglw" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd http://www.omg.org/spec/DD/20100524/DC DC.xsd http://www.omg.org/spec/DD/20100524/DI DI.xsd " exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
<bpmn2:itemDefinition id="_dealItem" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="_reviewItem" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="_travellerItem" structureRef="org.acme.travels.Traveller"/>
<bpmn2:itemDefinition id="_travellerItem" structureRef="org.acme.deals.Traveller"/>
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_SkippableInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_PriorityInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_CommentInputXItem" structureRef="Object"/>
Expand All @@ -16,7 +16,7 @@
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_NotStartedNotifyInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_NotCompletedNotifyInputXItem" structureRef="Object"/>
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_dealInputXItem" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_travellerInputXItem" structureRef="org.acme.travels.Traveller"/>
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_travellerInputXItem" structureRef="org.acme.deals.Traveller"/>
<bpmn2:itemDefinition id="__3597E33A-1C00-41B3-924E-09EA47F79D93_reviewOutputXItem" structureRef="java.lang.String"/>
<bpmn2:process id="dealreviews" drools:packageName="org.acme.deals" drools:version="1.0" drools:adHoc="false" name="Deal Review" isExecutable="true">
<bpmn2:extensionElements>
Expand Down Expand Up @@ -64,7 +64,7 @@
<bpmn2:ioSpecification id="_JmONwUk-EeqlMa7ut9bglw">
<bpmn2:dataInput id="_3597E33A-1C00-41B3-924E-09EA47F79D93_TaskNameInputX" drools:dtype="Object" itemSubjectRef="__3597E33A-1C00-41B3-924E-09EA47F79D93_TaskNameInputXItem" name="TaskName"/>
<bpmn2:dataInput id="_3597E33A-1C00-41B3-924E-09EA47F79D93_dealInputX" drools:dtype="java.lang.String" itemSubjectRef="__3597E33A-1C00-41B3-924E-09EA47F79D93_dealInputXItem" name="deal"/>
<bpmn2:dataInput id="_3597E33A-1C00-41B3-924E-09EA47F79D93_travellerInputX" drools:dtype="org.acme.travels.Traveller" itemSubjectRef="__3597E33A-1C00-41B3-924E-09EA47F79D93_travellerInputXItem" name="traveller"/>
<bpmn2:dataInput id="_3597E33A-1C00-41B3-924E-09EA47F79D93_travellerInputX" drools:dtype="org.acme.deals.Traveller" itemSubjectRef="__3597E33A-1C00-41B3-924E-09EA47F79D93_travellerInputXItem" name="traveller"/>
<bpmn2:dataInput id="_3597E33A-1C00-41B3-924E-09EA47F79D93_SkippableInputX" drools:dtype="Object" itemSubjectRef="__3597E33A-1C00-41B3-924E-09EA47F79D93_SkippableInputXItem" name="Skippable"/>
<bpmn2:dataOutput id="_3597E33A-1C00-41B3-924E-09EA47F79D93_reviewOutputX" drools:dtype="java.lang.String" itemSubjectRef="__3597E33A-1C00-41B3-924E-09EA47F79D93_reviewOutputXItem" name="review"/>
<bpmn2:inputSet id="_JmONwkk-EeqlMa7ut9bglw">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.omg.org/bpmn20" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpsim="http://www.bpsim.org/schemas/1.0" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" id="_29WqoEk8EeqlMa7ut9bglw" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd http://www.omg.org/spec/DD/20100524/DC DC.xsd http://www.omg.org/spec/DD/20100524/DI DI.xsd " exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
<bpmn2:itemDefinition id="_nameItem" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="_reviewItem" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="_travellerItem" structureRef="org.acme.travels.Traveller"/>
<bpmn2:itemDefinition id="_travellerItem" structureRef="org.acme.deals.Traveller"/>
<bpmn2:itemDefinition id="__C3082C6F-963E-40A2-B31B-1E8F336AA4C6_dealInputXItem" structureRef="java.lang.String"/>
<bpmn2:itemDefinition id="__C3082C6F-963E-40A2-B31B-1E8F336AA4C6_travellerInputXItem" structureRef="org.acme.travels.Traveller"/>
<bpmn2:itemDefinition id="__C3082C6F-963E-40A2-B31B-1E8F336AA4C6_travellerInputXItem" structureRef="org.acme.deals.Traveller"/>
<bpmn2:itemDefinition id="__C3082C6F-963E-40A2-B31B-1E8F336AA4C6_reviewOutputXItem" structureRef="java.lang.String"/>
<bpmn2:process id="deals" drools:packageName="org.acme.deals" drools:version="1.0" drools:adHoc="false" name="SubmitDeal" isExecutable="true">
<bpmn2:extensionElements>
Expand Down Expand Up @@ -71,7 +71,7 @@
<bpmn2:outgoing>_A186F5CE-4300-4506-A89D-50DEDC8F24CF</bpmn2:outgoing>
<bpmn2:ioSpecification id="_29XRsEk8EeqlMa7ut9bglw">
<bpmn2:dataInput id="_C3082C6F-963E-40A2-B31B-1E8F336AA4C6_dealInputX" drools:dtype="java.lang.String" itemSubjectRef="__C3082C6F-963E-40A2-B31B-1E8F336AA4C6_dealInputXItem" name="deal"/>
<bpmn2:dataInput id="_C3082C6F-963E-40A2-B31B-1E8F336AA4C6_travellerInputX" drools:dtype="org.acme.travels.Traveller" itemSubjectRef="__C3082C6F-963E-40A2-B31B-1E8F336AA4C6_travellerInputXItem" name="traveller"/>
<bpmn2:dataInput id="_C3082C6F-963E-40A2-B31B-1E8F336AA4C6_travellerInputX" drools:dtype="org.acme.deals.Traveller" itemSubjectRef="__C3082C6F-963E-40A2-B31B-1E8F336AA4C6_travellerInputXItem" name="traveller"/>
<bpmn2:dataOutput id="_C3082C6F-963E-40A2-B31B-1E8F336AA4C6_reviewOutputX" drools:dtype="java.lang.String" itemSubjectRef="__C3082C6F-963E-40A2-B31B-1E8F336AA4C6_reviewOutputXItem" name="review"/>
<bpmn2:inputSet id="_29XRsUk8EeqlMa7ut9bglw">
<bpmn2:dataInputRefs>_C3082C6F-963E-40A2-B31B-1E8F336AA4C6_dealInputX</bpmn2:dataInputRefs>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2020 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.acme.deals;

import java.util.Map;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
import org.kie.api.definition.type.ClassReactive;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@Testcontainers
@QuarkusTest
public class DealsRestIT {

private static final Logger LOGGER = LoggerFactory.getLogger(DealsRestIT.class);

@Container
public static GenericContainer INFINISPAN = new FixedHostPortGenericContainer(System.getProperty("container.image.infinispan"))
.withFixedExposedPort(11222, 11222)
.withEnv("USER", "admin")
.withEnv("PASS", "admin")
.withLogConsumer(new Slf4jLogConsumer(LOGGER))
.waitingFor(Wait.forLogMessage(".*ISPN080001.*", 1));

@Test
public void testDealsRest() {
// test adding new deal
String addDealPayload = "{\"name\" : \"my fancy deal\", \"traveller\" : { \"firstName\" : \"John\", \"lastName\" : \"Doe\", \"email\" : \"jon.doe@example.com\", \"nationality\" : \"American\",\"address\" : { \"street\" : \"main street\", \"city\" : \"Boston\", \"zipCode\" : \"10005\", \"country\" : \"US\" }}}";
String dealId = given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addDealPayload)
.when().post("/deals")
.then().log().ifValidationFails().statusCode(200).body("id", notNullValue()).extract().path("id");

// test getting the created deal
given().accept(ContentType.JSON)
.when().get("/deals")
.then().log().ifValidationFails().statusCode(200).body("$.size()", is(1), "[0].id", is(dealId));

// test getting order by id
given().accept(ContentType.JSON)
.when().get("/deals/" + dealId)
.then().log().ifValidationFails().statusCode(200).body("id", is(dealId));

// get deals for review
String dealReviewId = given().accept(ContentType.JSON)
.when().get("/dealreviews")
.then().log().ifValidationFails().statusCode(200).body("$.size()", is(1)).body("[0].id", notNullValue()).extract().path("[0].id");

// get task for john
Map<String, String> tasks = given().accept(ContentType.JSON)
.when().get("/dealreviews/{uuid}/tasks?user=john", dealReviewId)
.then().log().ifValidationFails().statusCode(200).extract().as(Map.class);
assertNotNull(tasks);
assertEquals(1, tasks.size());

// complete review task
given().contentType(ContentType.JSON).accept(ContentType.JSON).body("{\"review\" : \"very good work\"}")
.when().post("/dealreviews/{uuid}/review/{tuuid}?user=john", dealReviewId, tasks.keySet().iterator().next())
.then().log().ifValidationFails().statusCode(200);

//verify no deals to review
given().accept(ContentType.JSON)
.when().get("/dealreviews")
.then().log().ifValidationFails().statusCode(200).body("$.size()", is(0));

//verify no deals
given().accept(ContentType.JSON)
.when().get("/deals")
.then().log().ifValidationFails().statusCode(200).body("$.size()", is(0));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Infinispan
quarkus.infinispan-client.use-auth=true
quarkus.infinispan-client.auth-username=admin
quarkus.infinispan-client.auth-password=admin
35 changes: 32 additions & 3 deletions process-infinispan-persistence-springboot/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
Expand Down Expand Up @@ -68,6 +68,16 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -118,6 +128,25 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Due to spring-boot repackage, without adding this property test classes are not found
See https://github.com/spring-projects/spring-boot/issues/6254 -->
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<systemProperties>
<container.image.infinispan>${container.image.infinispan}</container.image.infinispan>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package org.acme.travels;
/*
* Copyright 2020 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.acme.deals;

public class Address {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020 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.acme.deals;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = {"org.kie.kogito.**", "org.acme.deals.**"})
public class KogitoApplication {

public static void main(String[] args) {
SpringApplication.run(KogitoApplication.class, args);
}
}

0 comments on commit cd880e7

Please sign in to comment.