Skip to content

Commit

Permalink
test(bpmn): use testcontainers and JUnit5
Browse files Browse the repository at this point in the history
* replace zeebe-test with zeebe-testcontainers
* dump junit from 4.13.2 to 5.7.1
  • Loading branch information
saig0 committed May 28, 2021
1 parent f900e7f commit b9d82e5
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 70 deletions.
30 changes: 19 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- script languages -->
Expand All @@ -128,10 +122,10 @@

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.1</version>
<scope>test</scope>
<version>4.13.2</version>
</dependency>

<dependency>
Expand All @@ -142,8 +136,16 @@
</dependency>

<dependency>
<groupId>io.camunda</groupId>
<artifactId>zeebe-test</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.15.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.zeebe</groupId>
<artifactId>zeebe-test-container</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>

Expand All @@ -152,6 +154,12 @@
<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/zeebe/script/EvaluationFeelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class EvaluationFeelTest {

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/zeebe/script/EvaluationGroovyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class EvaluationGroovyTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Collections;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class EvaluationJavaScriptTest {

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/zeebe/script/EvaluationKotlinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class EvaluationKotlinTest {

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/zeebe/script/EvaluationMustacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.zeebe.script;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/zeebe/script/ScriptEvaluatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ScriptEvaluatorTest {

Expand Down
104 changes: 51 additions & 53 deletions src/test/java/io/zeebe/script/WorkflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.ProcessInstanceResult;
import io.zeebe.containers.ZeebeContainer;
import io.camunda.zeebe.model.bpmn.Bpmn;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import io.camunda.zeebe.protocol.record.intent.MessageIntent;
import io.camunda.zeebe.protocol.record.value.MessageRecordValue;
import io.camunda.zeebe.test.ZeebeTestRule;
import io.camunda.zeebe.test.util.record.RecordingExporter;
import java.util.Collections;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

@RunWith(SpringRunner.class)
@SpringBootTest
@Testcontainers
public class WorkflowTest {

@ClassRule public static final ZeebeTestRule TEST_RULE = new ZeebeTestRule();
@Container private static final ZeebeContainer ZEEBE_CONTAINER = new ZeebeContainer();

@BeforeClass
private static ZeebeClient ZEEBE_CLIENT;

@BeforeAll
public static void init() {
System.setProperty(
"zeebe.client.broker.contactPoint",
TEST_RULE.getClient().getConfiguration().getGatewayAddress());
final var gatewayContactPoint = ZEEBE_CONTAINER.getExternalGatewayAddress();
System.setProperty("zeebe.client.broker.contactPoint", gatewayContactPoint);

ZEEBE_CLIENT =
ZeebeClient.newClientBuilder().gatewayAddress(gatewayContactPoint).usePlaintext().build();
}

@Test
Expand All @@ -45,10 +46,10 @@ public void shouldReturnResult() {
.zeebeTaskHeader("script", "x + 1"))
.done();

final ProcessInstanceEvent workflowInstance =
final var workflowInstanceResult =
deployAndCreateInstance(workflow, Collections.singletonMap("x", 2));

ZeebeTestRule.assertThat(workflowInstance).isEnded().hasVariable("result", 3);
assertThat(workflowInstanceResult.getVariablesAsMap()).containsEntry("result", 3);
}

@Test
Expand All @@ -65,59 +66,56 @@ public void shouldGetCurrentJob() {
.zeebeTaskHeader("script", "job.processInstanceKey"))
.done();

final ProcessInstanceEvent workflowInstance =
deployAndCreateInstance(workflow, Collections.emptyMap());
final var workflowInstanceResult = deployAndCreateInstance(workflow, Collections.emptyMap());

ZeebeTestRule.assertThat(workflowInstance)
.isEnded()
.hasVariable("result", workflowInstance.getProcessInstanceKey());
assertThat(workflowInstanceResult.getVariablesAsMap())
.containsEntry("result", workflowInstanceResult.getProcessInstanceKey());
}

@Test
public void shouldUseZeebeClient() {
final String groovyScript =
"zeebeClient.newPublishMessageCommand()"
+ ".messageName('foo')"
+ ".correlationKey(key)"
+ ".timeToLive(java.time.Duration.ofMinutes(1))"
+ ".variables('{\"x\":1}')"
+ ".send().join()";

final BpmnModelInstance workflow =
Bpmn.createExecutableProcess("process")
.startEvent()
.parallelGateway("fork")
.serviceTask(
"task",
t ->
t.zeebeJobType("script")
.zeebeTaskHeader("language", "groovy")
.zeebeTaskHeader(
"script",
"zeebeClient.newPublishMessageCommand().messageName('foo').correlationKey('bar').send().join()"))
t -> {
t.zeebeJobType("script")
.zeebeTaskHeader("language", "groovy")
.zeebeTaskHeader("script", groovyScript);
})
.endEvent()
.moveToNode("fork")
.intermediateCatchEvent(
"message", e -> e.message(m -> m.name("foo").zeebeCorrelationKeyExpression("key")))
.endEvent()
.done();

final ProcessInstanceEvent workflowInstance =
deployAndCreateInstance(workflow, Collections.emptyMap());

ZeebeTestRule.assertThat(workflowInstance).isEnded();
final var workflowInstanceResult = deployAndCreateInstance(workflow, Map.of("key", "key-1"));

final MessageRecordValue publishedMessage =
RecordingExporter.messageRecords(MessageIntent.PUBLISHED).getFirst().getValue();
assertThat(publishedMessage.getName()).isEqualTo("foo");
assertThat(publishedMessage.getCorrelationKey()).isEqualTo("bar");
assertThat(workflowInstanceResult.getVariablesAsMap()).containsEntry("x", 1);
}

private ProcessInstanceEvent deployAndCreateInstance(
private ProcessInstanceResult deployAndCreateInstance(
final BpmnModelInstance workflow, Map<String, Object> variables) {
TEST_RULE
.getClient()
.newDeployCommand()
.addProcessModel(workflow, "process.bpmn")
ZEEBE_CLIENT.newDeployCommand().addProcessModel(workflow, "process.bpmn").send().join();

return ZEEBE_CLIENT
.newCreateInstanceCommand()
.bpmnProcessId("process")
.latestVersion()
.variables(variables)
.withResult()
.send()
.join();

final ProcessInstanceEvent workflowInstance =
TEST_RULE
.getClient()
.newCreateInstanceCommand()
.bpmnProcessId("process")
.latestVersion()
.variables(variables)
.send()
.join();
return workflowInstance;
}
}

0 comments on commit b9d82e5

Please sign in to comment.