-
Notifications
You must be signed in to change notification settings - Fork 38
Add quarkus-flow-testing module for testing workflow executions #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mcruzdev
wants to merge
2
commits into
quarkiverse:main
Choose a base branch
from
mcruzdev:issue-469
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
core/deployment/src/main/java/io/quarkiverse/flow/deployment/FlowTestingProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package io.quarkiverse.flow.deployment; | ||
|
|
||
| import org.jboss.jandex.DotName; | ||
|
|
||
| import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
| import io.quarkus.deployment.IsTest; | ||
| import io.quarkus.deployment.annotations.BuildProducer; | ||
| import io.quarkus.deployment.annotations.BuildStep; | ||
| import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
|
|
||
| public class FlowTestingProcessor { | ||
|
|
||
| private static final DotName FLOW_TESTING_PRODUCER = DotName | ||
| .createSimple("io.quarkiverse.flow.testing.FlowTestingProducer"); | ||
|
|
||
| @BuildStep(onlyIf = IsTest.class) | ||
| void additionalTestBeans(BuildProducer<AdditionalBeanBuildItem> bean, CombinedIndexBuildItem jandex) { | ||
| if (jandex.getIndex().getClassByName(FLOW_TESTING_PRODUCER) != null) { | ||
| bean.produce(AdditionalBeanBuildItem.builder() | ||
| .addBeanClasses(FLOW_TESTING_PRODUCER.toString()) | ||
| .build()); | ||
| } | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...eployment/src/test/java/io/quarkiverse/flow/deployment/test/FlowTestingProcessorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package io.quarkiverse.flow.deployment.test; | ||
|
|
||
| import jakarta.enterprise.inject.Instance; | ||
| import jakarta.inject.Inject; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| import io.quarkiverse.flow.testing.TestWorkflowExecutionListener; | ||
| import io.quarkiverse.flow.testing.WorkflowEventStore; | ||
| import io.quarkus.test.QuarkusExtensionTest; | ||
| import io.serverlessworkflow.impl.lifecycle.WorkflowExecutionListener; | ||
|
|
||
| public class FlowTestingProcessorTest { | ||
|
|
||
| @RegisterExtension | ||
| static final QuarkusExtensionTest config = new QuarkusExtensionTest() | ||
| // quarkus-flow-testing was added as a test dependency | ||
| .withEmptyApplication(); | ||
|
|
||
| @Inject | ||
| WorkflowEventStore listener; | ||
|
|
||
| @Inject | ||
| Instance<WorkflowExecutionListener> listeners; | ||
|
|
||
| @Test | ||
| void should_inject_test_workflow_execution_listener() { | ||
| Assertions.assertNotNull(listener); | ||
| boolean isAvailable = listeners.stream() | ||
| .anyMatch(listener -> listener instanceof TestWorkflowExecutionListener); | ||
| Assertions.assertTrue(isAvailable); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
examples/suspend-resume-abort/src/test/java/org/acme/flow/SwitchLoopWaitTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package org.acme.flow; | ||
|
|
||
| import io.quarkiverse.flow.testing.WorkflowEventStore; | ||
| import io.quarkiverse.flow.testing.assertions.AsyncFlowAssertions; | ||
| import io.quarkiverse.flow.testing.assertions.FlowAssertions; | ||
| import io.quarkus.test.junit.QuarkusTest; | ||
| import io.restassured.RestAssured; | ||
| import io.restassured.common.mapper.TypeRef; | ||
| import io.restassured.http.ContentType; | ||
| import jakarta.inject.Inject; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @QuarkusTest | ||
| public class SwitchLoopWaitTest { | ||
|
|
||
| @Inject | ||
| WorkflowEventStore eventStore; | ||
|
|
||
| @Test | ||
| void let_run_max_count_5_test_switch_loop_wait_with_flow_assertions() { | ||
|
|
||
| Map<String, Object> response = RestAssured.given() | ||
| .contentType(ContentType.JSON) | ||
| .accept(ContentType.JSON) | ||
| .body(new FlowRequest(5)) | ||
| .post("/api/flow/start") | ||
| .then() | ||
| .statusCode(202) | ||
| .extract() | ||
| .body() | ||
| .as(new TypeRef<Map<String, Object>>() { | ||
| }); | ||
|
|
||
| AsyncFlowAssertions.assertWith(eventStore) | ||
| .filteringBy(((String) response.get("instanceId"))) | ||
| .workflowStarted() | ||
| .taskCompleted("inc") | ||
| .taskCompleted("looping") | ||
| .taskCompleted("waitABit") | ||
| .workflowCompleted(); | ||
|
|
||
| AsyncFlowAssertions.assertWith(eventStore) | ||
| .strictly() | ||
| .filteringBy(((String) response.get("instanceId"))) | ||
| .workflowStarted() | ||
| .taskCompleted("looping") | ||
| .taskCompleted("inc") | ||
| .taskCompleted("waitABit") | ||
| .workflowCompleted(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>io.quarkiverse.flow</groupId> | ||
| <artifactId>quarkus-flow-parent</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>quarkus-flow-testing</artifactId> | ||
| <name>Quarkus Flow :: Testing</name> | ||
| <description>Testing utilities for Quarkus Flow workflows</description> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-arc</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-junit5</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-core</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-http</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-openapi</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-jq</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-experimental-fluent-func</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-model</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-validation</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-experimental-model</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-lifecycle-events</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-fluent-spec</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-experimental-lambda</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-jackson-jwt</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.serverlessworkflow</groupId> | ||
| <artifactId>serverlessworkflow-impl-jackson</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> | ||
37 changes: 37 additions & 0 deletions
37
testing/src/main/java/io/quarkiverse/flow/testing/DefaultWorkflowEventStorage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package io.quarkiverse.flow.testing; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.concurrent.CopyOnWriteArrayList; | ||
|
|
||
| import io.quarkiverse.flow.testing.events.RecordedWorkflowEvent; | ||
|
|
||
| public class DefaultWorkflowEventStorage implements WorkflowEventStorage { | ||
|
|
||
| private final List<RecordedWorkflowEvent> events = new CopyOnWriteArrayList<>(); | ||
|
|
||
| @Override | ||
| public void record(RecordedWorkflowEvent event) { | ||
| events.add(event); | ||
| } | ||
|
|
||
| @Override | ||
| public List<RecordedWorkflowEvent> getAll() { | ||
| return Collections.unmodifiableList(events); | ||
| } | ||
|
|
||
| @Override | ||
| public void clear() { | ||
| events.clear(); | ||
| } | ||
|
|
||
| @Override | ||
| public int size() { | ||
| return events.size(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEmpty() { | ||
| return events.isEmpty(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.