Skip to content

Commit

Permalink
KOGITO-1943 - Add integration tests with Infinispan
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianonicolai committed Apr 22, 2020
1 parent 7cbe765 commit 2ee8fed
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 25 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@
<!-- 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:${container.image.infinispan.version}</container.image.infinispan>
<container.image.infinispan.version>10.1.5.Final</container.image.infinispan.version>
<version.testcontainers>1.12.4</version.testcontainers>
<!-- jsonpath-->
<version.jayway.jsonpath>2.4.0</version.jayway.jsonpath>
<version.swagger.plugin>2.1.0</version.swagger.plugin>
<version.surefire.plugin>2.22.0</version.surefire.plugin>
<version.deploy.plugin>2.8.2</version.deploy.plugin>

<version.docker.plugin>0.33.0</version.docker.plugin>
</properties>

<!-- distributionManagement section -->
Expand Down Expand Up @@ -187,6 +191,11 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${version.docker.plugin}</version>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand Down
74 changes: 66 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,11 +58,57 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${container.image.infinispan}</name>
<alias>infinispan</alias>
<run>
<ports>
<port>11222:11222</port>
</ports>
<env>
<USER>admin</USER>
<PASS>admin</PASS>
</env>
<log>
<prefix>Infinispan:</prefix>
<date>default</date>
<color>cyan</color>
</log>
<wait>
<log>.*started.*</log>
<time>40000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker-start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand All @@ -86,6 +128,22 @@
</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>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 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;

@QuarkusTest
public class DealsRestIT {

@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
93 changes: 90 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,21 +68,97 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${container.image.infinispan}</name>
<alias>infinispan</alias>
<run>
<ports>
<port>11222:11222</port>
</ports>
<env>
<USER>admin</USER>
<PASS>admin</PASS>
</env>
<log>
<prefix>Infinispan:</prefix>
<date>default</date>
<color>cyan</color>
</log>
<wait>
<log>.*started.*</log>
<time>40000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker-start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<arguments>
<argument>--infinispan.remote.use-auth=true</argument>
<argument>--infinispan.remote.auth-username=admin</argument>
<argument>--infinispan.remote.auth-password=admin</argument>
<argument>--infinispan.remote.sasl-mechanism=DIGEST-MD5</argument>
</arguments>
<profiles>
<profile>it</profile>
</profiles>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -118,6 +194,17 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

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.kie.kogito.tests;

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);
}
}

This file was deleted.

Loading

0 comments on commit 2ee8fed

Please sign in to comment.