Skip to content

Commit

Permalink
KOGITO-5941 Introduce changes to successfully run tests with JDK 17 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo authored Sep 23, 2021
1 parent 46d675b commit 568bd01
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void testFindByIdReadMode(MongoDBTransactionManager transactionManager) {
mutablePi.start();
assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
assertThat(mutablePi.error()).hasValueSatisfying(error -> {
assertThat(error.errorMessage()).endsWith("java.lang.NullPointerException - null");
assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
});
assertThat(mutablePi.variables().toMap()).containsExactly(entry("var", "value"));
Expand All @@ -230,7 +230,7 @@ void testFindByIdReadMode(MongoDBTransactionManager transactionManager) {
ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
assertThat(readOnlyPi.error()).hasValueSatisfying(error -> {
assertThat(error.errorMessage()).endsWith("java.lang.NullPointerException - null");
assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
});
assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void testGetNodeInstances() {
.get("/management/processes/{processId}/instances/{processInstanceId}/nodeInstances", "greetings", pid)
.then()
.statusCode(200)
.body("$.size", is(2))
.body("$.size()", is(2))
.body("[0].name", is("Task"))
.body("[0].state", is(0))
.body("[1].name", is("Task"))
Expand All @@ -100,7 +100,7 @@ void testGetProcessNodes() {
.get("/management/processes/{processId}/nodes", "greetings")
.then()
.statusCode(200)
.body("$.size", is(10))
.body("$.size()", is(10))
.body("[0].id", is(1))
.body("[0].name", is("End"))
.body("[0].type", is("EndNode"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void testGetTasks() {
.get("/AdHocFragments/{id}/tasks", id)
.then()
.statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].name", is("Task"));

assertExpectedUnitOfWorkEvents(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testSubmitMovie() {
.get("/cinema/{pid}/tasks", pid)
.then()
.statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].name", is("ReviewRatingTask"))
.extract()
.path("[0].id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void testGetNodeInstances() {
.get("/management/processes/{processId}/instances/{processInstanceId}/nodeInstances", GREETINGS, pid)
.then()
.statusCode(200)
.body("$.size", is(2))
.body("$.size()", is(2))
.body("$", hasItems(hasEntry("name", "Hello1"), hasEntry("name", "Hello2")))
.body("[0].state", is(0))
.body("[1].state", is(0));
Expand All @@ -87,7 +87,7 @@ void testGetProcessNodes() {
.get("/management/processes/{processId}/nodes", GREETINGS)
.then()
.statusCode(200)
.body("$.size", is(10))
.body("$.size()", is(10))
.body("[0].id", is(1))
.body("[0].name", is("End"))
.body("[0].type", is("EndNode"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testParentSubProcessRest() {
String taskId = given().accept(ContentType.JSON)
.when().get("/subprocess/{uuid}/tasks?user=john", subProcessId)
.then().statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].parameters.param_name", is(name))
.extract().path("[0].id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ private void validateSubProcess() {
.get("/pong_message/")
.then()
.statusCode(200)
.body("$.size", equalTo(1)));
.body("$.size()", equalTo(1)));

String pId = given()
.contentType(ContentType.JSON)
.when()
.get("/pong_message/")
.then()
.statusCode(200)
.body("$.size", equalTo(1))
.body("$.size()", equalTo(1))
.extract().body().path("[0].id");

given()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void testGetTasks() {
.get("/AdHocFragments/{id}/tasks", id)
.then()
.statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].name", is("Task"));

assertExpectedUnitOfWorkEvents(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testSubmitMovie() {
.get("/cinema/{pid}/tasks", pid)
.then()
.statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.extract()
.as(TestWorkItem[].class)[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void testGetNodeInstances() {
.get("/management/processes/{processId}/instances/{processInstanceId}/nodeInstances", GREETINGS, pid)
.then()
.statusCode(200)
.body("$.size", is(2))
.body("$.size()", is(2))
.body("$", hasItems(hasEntry("name", "Hello1"),hasEntry("name", "Hello2")))
.body("[0].state", is(0))
.body("[1].state", is(0));
Expand All @@ -88,7 +88,7 @@ void testGetProcessNodes() {
.get("/management/processes/{processId}/nodes", GREETINGS)
.then()
.statusCode(200)
.body("$.size", is(10))
.body("$.size()", is(10))
.body("[0].id", is(1))
.body("[0].name", is("End"))
.body("[0].type", is("EndNode"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testParentSubProcessRest() {
String taskId = given().accept(ContentType.JSON)
.when().get("/subprocess/{uuid}/tasks?user=john", subProcessId)
.then().statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].parameters.param_name", is(name))
.extract().path("[0].id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ private void validateSubProcess(){
.get("/pong_message/")
.then()
.statusCode(200)
.body("$.size", equalTo(1)));
.body("$.size()", equalTo(1)));

String pId = given()
.contentType(ContentType.JSON)
.when()
.get("/pong_message/")
.then()
.statusCode(200)
.body("$.size", equalTo(1))
.body("$.size()", equalTo(1))
.extract().body().path("[0].id");

given()
Expand Down
16 changes: 16 additions & 0 deletions jbpm/jbpm-flow-builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,20 @@
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>java15-javascript</id>
<activation>
<jdk>[15,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino-engine</artifactId> <!-- So that tests still work on JDK 15+. -->
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
13 changes: 13 additions & 0 deletions jbpm/jbpm-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

<!-- test -->
<dependency>
<groupId>org.kie.kogito</groupId>
Expand Down Expand Up @@ -122,5 +123,17 @@
<sonar.exclusions>**/JBPMMessages.java</sonar.exclusions>
</properties>
</profile>
<profile>
<id>java15-javascript</id>
<activation>
<jdk>[15,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>org.mozilla</groupId> <!-- JDKs older than 15 carry their own. -->
<artifactId>rhino-engine</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@

public class JavaScriptAction implements Action, Externalizable {

static ScriptEngine loadJavaScriptEngine() {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
if (engine != null) {
return engine;
}
throw new IllegalStateException("JavaScript implementation not found on the classpath." +
"If you're running JDK 15 or later, please include org.mozilla:rhino-engine in your project.");
}

private static final long serialVersionUID = 630l;

private String expr;
Expand All @@ -54,8 +64,7 @@ public void writeExternal(ObjectOutput out) throws IOException {

@Override
public void execute(KogitoProcessContext context) throws Exception {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
ScriptEngine engine = loadJavaScriptEngine();
engine.put("kcontext", context);

// insert globals into context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Map.Entry;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import org.jbpm.process.core.context.variable.VariableScope;
import org.jbpm.process.instance.context.variable.VariableScopeInstance;
Expand Down Expand Up @@ -53,8 +52,7 @@ public void writeExternal(ObjectOutput out) throws IOException {
}

public Object evaluate(KogitoProcessContext context) throws Exception {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
ScriptEngine engine = JavaScriptAction.loadJavaScriptEngine();

// insert globals into context
Globals globals = context.getKieRuntime().getGlobals();
Expand Down
2 changes: 1 addition & 1 deletion kogito-build/kogito-build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<!-- plugin versions -->
<version.antapacheregexp>1.8.2</version.antapacheregexp>
<version.antrun.plugin>1.8</version.antrun.plugin>
<version.archetype.plugin>3.0.1</version.archetype.plugin>
<version.archetype.plugin>3.2.0</version.archetype.plugin>
<version.asciidoctor.plugin>1.5.2.1</version.asciidoctor.plugin>
<version.build.helper.plugin>3.0.0</version.build.helper.plugin>
<version.clean.plugin>3.1.0</version.clean.plugin>
Expand Down
26 changes: 20 additions & 6 deletions kogito-build/kogito-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<version.org.openapitools>5.0.1</version.org.openapitools>
<version.org.openapitools.jackson.databind.nullable>0.2.0</version.org.openapitools.jackson.databind.nullable>

<version.com.sun.xml.bind>2.3.0</version.com.sun.xml.bind>
<version.com.sun.xml.bind.core>2.3.0.1</version.com.sun.xml.bind.core>
<version.com.sun.xml.bind.impl>2.3.5</version.com.sun.xml.bind.impl>
<version.com.sun.activation>1.2.0</version.com.sun.activation>
<version.com.thoughtworks.xstream>1.4.17</version.com.thoughtworks.xstream>
<version.javax.annotation>1.3.2</version.javax.annotation>
Expand Down Expand Up @@ -68,17 +69,18 @@
<version.org.mongo>4.3.1</version.org.mongo>
<version.org.mongo-image>4.2.3</version.org.mongo-image> <!-- Version 4.3.0 is not existing ... -->
<version.org.mongo.springboot>4.1.0</version.org.mongo.springboot> <!-- https://issues.redhat.com/browse/KOGITO-5031 -->
<version.org.mozilla.rhino>1.7.13</version.org.mozilla.rhino>

<version.org.assertj>3.20.2</version.org.assertj>
<version.org.json-unit-assertj>2.9.0</version.org.json-unit-assertj>
<version.org.hamcrest>1.3</version.org.hamcrest> <!-- else old version coming from Mockito wins and breaks tests -->
<version.org.junit.minor>7.2</version.org.junit.minor> <!-- so that org.junit.platform and org.junit can share the same minor version -->
<version.org.junit.minor>8.0</version.org.junit.minor> <!-- so that org.junit.platform and org.junit can share the same minor version -->
<version.org.junit>5.${version.org.junit.minor}</version.org.junit>
<version.org.junit.jupiter>${version.org.junit}</version.org.junit.jupiter>
<version.org.junit.vintage>${version.org.junit}</version.org.junit.vintage>
<version.org.junit.platform>1.${version.org.junit.minor}</version.org.junit.platform> <!-- otherwise Quarkus brings its own, silently disabling some tests -->
<version.org.junit.pioneer>1.0.0</version.org.junit.pioneer>
<version.org.mockito>3.11.2</version.org.mockito>
<version.org.junit.pioneer>1.4.2</version.org.junit.pioneer>
<version.org.mockito>3.12.4</version.org.mockito>
<version.org.testcontainers>1.15.3</version.org.testcontainers>

<version.org.mvel>2.4.12.Final</version.org.mvel>
Expand Down Expand Up @@ -145,6 +147,18 @@
<version>${version.ch.qos.logback}</version>
</dependency>

<!-- Java 17 compatibility -->
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>${version.org.mozilla.rhino}</version>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino-engine</artifactId>
<version>${version.org.mozilla.rhino}</version>
</dependency>

<!-- code generation -->
<dependency>
<groupId>com.github.javaparser</groupId>
Expand Down Expand Up @@ -406,12 +420,12 @@
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>${version.com.sun.xml.bind}</version>
<version>${version.com.sun.xml.bind.core}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${version.com.sun.xml.bind}</version>
<version>${version.com.sun.xml.bind.impl}</version>
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public void testServiceTaskProcessWithError() throws Exception {
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();// human task is active thus null for leave time

assertThat(body.getError()).isNotNull();
assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException - null");
assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException");
assertThat(body.getError().getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");

parameters.put("s", "john");
Expand All @@ -545,7 +545,7 @@ public void testServiceTaskProcessWithError() throws Exception {
assertThat(events).isNotNull().hasSize(1);
body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
assertThat(body.getError()).isNotNull();
assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException - null");
assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException");
assertThat(body.getError().getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");

uow = app.unitOfWorkManager().newUnitOfWork();
Expand Down
5 changes: 5 additions & 0 deletions kogito-test-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <!-- To see testcońtainer logs. -->
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
16 changes: 16 additions & 0 deletions kogito-test-utils/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- %L lowers performance, %C and %c break indentation and therefore reduce readability, normal %t is verbose -->
<pattern>%d{HH:mm:ss.SSS} [%-12.12t] %-5p %m%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="consoleAppender" />
</root>

</configuration>

Loading

0 comments on commit 568bd01

Please sign in to comment.