Skip to content

Commit

Permalink
feat(environment): create the EZE environment for spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aivinog1 committed Sep 20, 2022
1 parent 9cd09cb commit 1b75e44
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 35 deletions.
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

<hazelcast.exporter.version>1.0.0</hazelcast.exporter.version>

<eze.version>1.0.2</eze.version>
<zeebe-hazelcast-exporter.version>1.2.1</zeebe-hazelcast-exporter.version>
<zeebe-test-container.version>3.5.0</zeebe-test-container.version>
<test-container.version>1.17.3</test-container.version>

Expand Down Expand Up @@ -79,6 +81,18 @@
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.camunda.community</groupId>
<artifactId>eze</artifactId>
<version>${eze.version}</version>
</dependency>

<dependency>
<groupId>io.zeebe.hazelcast</groupId>
<artifactId>zeebe-hazelcast-exporter</artifactId>
<version>${zeebe-hazelcast-exporter.version}</version>
</dependency>

<dependency>
<groupId>io.zeebe</groupId>
<artifactId>zeebe-test-container</artifactId>
Expand Down
16 changes: 15 additions & 1 deletion zeebe-test-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
<artifactId>zeebe-client-java</artifactId>
</dependency>

<dependency>
<groupId>org.camunda.community</groupId>
<artifactId>eze</artifactId>
</dependency>

<dependency>
<groupId>io.zeebe.hazelcast</groupId>
<artifactId>zeebe-hazelcast-exporter</artifactId>
</dependency>

<dependency>
<groupId>io.zeebe</groupId>
<artifactId>zeebe-test-container</artifactId>
Expand Down Expand Up @@ -62,7 +72,6 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.18.0</version>
<scope>test</scope>
</dependency>

Expand All @@ -77,6 +86,11 @@
<artifactId>awaitility-kotlin</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.zeebe.bpmnspec.runner.zeebe

import io.camunda.zeebe.client.ZeebeClient
import io.zeebe.bpmnspec.runner.zeebe.zeeqs.ZeeqsClient

interface TestEnvironment {
val zeebeClient: ZeebeClient
val zeeqsClient: ZeeqsClient

val isRunning: Boolean

fun setup()

fun cleanUp()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ZeebeEnvironment(
"ghcr.io/camunda-community-hub/zeebe-with-hazelcast-exporter"
),
val zeebeImageVersion: String = System.getProperty("zeebeImageVersion", "1.0.0-1.0.0")
) {
) : TestEnvironment{

private val logger = LoggerFactory.getLogger(ZeebeTestRunner::class.java)

Expand All @@ -28,12 +28,12 @@ class ZeebeEnvironment(

private val closingSteps = mutableListOf<AutoCloseable>()

lateinit var zeebeClient: ZeebeClient
lateinit var zeeqsClient: ZeeqsClient
override lateinit var zeebeClient: ZeebeClient
override lateinit var zeeqsClient: ZeeqsClient

var isRunning = false
override var isRunning = false

fun setup() {
override fun setup() {
val network = Network.newNetwork()!!
closingSteps.add(network)

Expand Down Expand Up @@ -112,7 +112,7 @@ class ZeebeEnvironment(
zeeqsClient = ZeeqsClient(zeeqsEndpoint = "$zeeqsContainerHost:$zeeqsContainerPort/graphql")
}

fun cleanUp() {
override fun cleanUp() {
logger.debug("Closing resources")
closingSteps.toList().reversed().forEach(AutoCloseable::close)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.io.InputStream
import java.time.Duration

class ZeebeTestRunner(
private val environment: ZeebeEnvironment = ZeebeEnvironment(),
private val environment: TestEnvironment = ZeebeEnvironment(),
private val reuseEnvironment: Boolean = false,
private val beforeEachCallback: (ZeebeTestContext) -> Unit = {},
private val afterEachCallback: (ZeebeTestContext) -> Unit = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.zeebe.bpmnspec.runner.zeebe.eze

import io.camunda.zeebe.client.ZeebeClient
import io.zeebe.bpmnspec.runner.zeebe.TestEnvironment
import io.zeebe.bpmnspec.runner.zeebe.ZeebeEnvironment
import io.zeebe.bpmnspec.runner.zeebe.zeeqs.ZeeqsClient
import io.zeebe.hazelcast.exporter.HazelcastExporter
import org.camunda.community.eze.EngineFactory
import org.camunda.community.eze.ZeebeEngine
import org.testcontainers.Testcontainers
import org.testcontainers.containers.wait.strategy.Wait

class EzeTestEnvironment(
private val hazelcastExporter: HazelcastExporter = HazelcastExporter(),
private val zeebeEngine: ZeebeEngine = EngineFactory.create(listOf(hazelcastExporter)),
private val zeeqsGraphqlPort: Int = 9000,
private val zeeqsImage: String = "ghcr.io/camunda-community-hub/zeeqs",
private val zeeqsImageVersion: String = "2.4.0",
private val zeeqsContainer: ZeebeEnvironment.ZeeqsContainer = ZeebeEnvironment
.ZeeqsContainer(zeeqsImage, zeeqsImageVersion)
.withEnv("zeebe.client.worker.hazelcast.connection", "host.testcontainers.internal:5701")
.withExposedPorts(zeeqsGraphqlPort)
.waitingFor(Wait.forHttp("/actuator/health"))
) : TestEnvironment {
override lateinit var zeebeClient: ZeebeClient
override lateinit var zeeqsClient: ZeeqsClient
override var isRunning: Boolean = false
private val closingSteps = mutableListOf<AutoCloseable>()

override fun setup() {
zeebeEngine.start()
Testcontainers.exposeHostPorts(5701)
zeebeClient = zeebeEngine.createClient()
zeeqsContainer.start()
zeeqsClient = ZeeqsClient("localhost:${zeeqsContainer.getMappedPort(zeeqsGraphqlPort)}/graphql")
closingSteps.add(zeebeClient)
closingSteps.add(AutoCloseable { zeebeEngine.stop() })
closingSteps.add(zeeqsContainer)
isRunning = true
}

override fun cleanUp() {
closingSteps.forEach(AutoCloseable::close)
isRunning = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package io.zeebe.bpmnspec.runner.zeebe
import io.zeebe.bpmnspec.ClasspathResourceResolver
import io.zeebe.bpmnspec.SpecRunner
import io.zeebe.bpmnspec.api.runner.ProcessInstanceState
import io.zeebe.bpmnspec.runner.zeebe.eze.EzeTestEnvironment
import org.assertj.core.api.Assertions.assertThat
import org.awaitility.kotlin.await
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.util.stream.Stream

class ZeebeTestRunnerTest {

private val resourceResolver =
ClasspathResourceResolver(classLoader = ZeebeTestRunnerTest::class.java.classLoader)
private val specRunner = SpecRunner(
testRunner = ZeebeTestRunner(),
resourceResolver = resourceResolver
)
@ParameterizedTest
@ArgumentsSource(TestEnvironmentArgumentsProvider::class)
fun `ZeebeRunner should work standalone`(testEnvironment: TestEnvironment) {

@Test
fun `ZeebeRunner should work standalone`() {

val runner = ZeebeTestRunner()
val runner = ZeebeTestRunner(testEnvironment)

runner.beforeEach()

Expand All @@ -40,35 +40,39 @@ class ZeebeTestRunnerTest {
runner.afterEach()
}

@Test
fun `Runner with ZeebeTestRunner should run the YAML spec`() {
@ParameterizedTest
@ArgumentsSource(SpecRunnerWithDifferentTestEnvironmentArgumentsProvider::class)
fun `Runner with ZeebeTestRunner should run the YAML spec`(specRunner: SpecRunner) {

val spec = ZeebeTestRunnerTest::class.java.getResourceAsStream("/demo.yaml")
val result = specRunner.runSpec(spec)

assertThat(result.testResults).hasSize(1)
}

@Test
fun `Runner with ZeebeTestRunner should run the Kotlin spec`() {
@ParameterizedTest
@ArgumentsSource(SpecRunnerWithDifferentTestEnvironmentArgumentsProvider::class)
fun `Runner with ZeebeTestRunner should run the Kotlin spec`(specRunner: SpecRunner) {

val spec = DemoTestSpecBuilder.demo()
val result = specRunner.runSpec(spec)

assertThat(result.testResults).hasSize(1)
}

@Test
fun `should run the YAML spec with message`() {
@ParameterizedTest
@ArgumentsSource(SpecRunnerWithDifferentTestEnvironmentArgumentsProvider::class)
fun `should run the YAML spec with message`(specRunner: SpecRunner) {

val spec = ZeebeTestRunnerTest::class.java.getResourceAsStream("/demo3.yaml")
val result = specRunner.runSpec(spec)

assertThat(result.testResults).hasSize(1)
}

@Test
fun `should run the Kotlin spec with message`() {
@ParameterizedTest
@ArgumentsSource(SpecRunnerWithDifferentTestEnvironmentArgumentsProvider::class)
fun `should run the Kotlin spec with message`(specRunner: SpecRunner) {

val spec = DemoTestSpecBuilder.demo3()
val result = specRunner.runSpec(spec)
Expand All @@ -77,17 +81,19 @@ class ZeebeTestRunnerTest {
}


@Test
fun `should run the YAML spec with incident`() {
@ParameterizedTest
@ArgumentsSource(SpecRunnerWithDifferentTestEnvironmentArgumentsProvider::class)
fun `should run the YAML spec with incident`(specRunner: SpecRunner) {

val spec = ZeebeTestRunnerTest::class.java.getResourceAsStream("/demo-incident.yaml")
val result = specRunner.runSpec(spec)

assertThat(result.testResults).hasSize(1)
}

@Test
fun `should run the Kotlin spec with incident`() {
@ParameterizedTest
@ArgumentsSource(SpecRunnerWithDifferentTestEnvironmentArgumentsProvider::class)
fun `should run the Kotlin spec with incident`(specRunner: SpecRunner) {

val spec = DemoTestSpecBuilder.demoIncident()
val result = specRunner.runSpec(spec)
Expand All @@ -96,8 +102,9 @@ class ZeebeTestRunnerTest {
}


@Test
fun `should fail verification`() {
@ParameterizedTest
@ArgumentsSource(SpecRunnerWithDifferentTestEnvironmentArgumentsProvider::class)
fun `should fail verification`(specRunner: SpecRunner) {

val spec = ZeebeTestRunnerTest::class.java.getResourceAsStream("/failed-test-case.yaml")
val result = specRunner.runSpec(spec)
Expand All @@ -113,8 +120,9 @@ class ZeebeTestRunnerTest {
assertThat(testResult.failedVerification).isEqualTo(testResult.testCase.verifications[1])
}

@Test
fun `should collect output`() {
@ParameterizedTest
@ArgumentsSource(SpecRunnerWithDifferentTestEnvironmentArgumentsProvider::class)
fun `should collect output`(specRunner: SpecRunner) {

val spec = ZeebeTestRunnerTest::class.java.getResourceAsStream("/demo.yaml")
val result = specRunner.runSpec(spec)
Expand All @@ -132,4 +140,32 @@ class ZeebeTestRunnerTest {
assertThat(testOutput.incidents).isEmpty()
}

class SpecRunnerWithDifferentTestEnvironmentArgumentsProvider : ArgumentsProvider {

override fun provideArguments(context: ExtensionContext): Stream<out Arguments> {
val resourceResolver = ClasspathResourceResolver(classLoader = ZeebeTestRunnerTest::class.java.classLoader)
return Stream.of(
Arguments.of(
SpecRunner(
testRunner = ZeebeTestRunner(),
resourceResolver = resourceResolver
)
),
Arguments.of(
SpecRunner(
testRunner = ZeebeTestRunner(EzeTestEnvironment()),
resourceResolver = resourceResolver
)
)
)
}
}

class TestEnvironmentArgumentsProvider : ArgumentsProvider {
override fun provideArguments(context: ExtensionContext): Stream<out Arguments> = Stream.of(
Arguments.of(EzeTestEnvironment()),
Arguments.of(ZeebeEnvironment())
)

}
}

0 comments on commit 1b75e44

Please sign in to comment.