Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<artifactId>quarkus-flow-dev</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-durable-kubernetes</artifactId>
Expand All @@ -63,7 +62,6 @@
<artifactId>quarkus-flow-durable-kubernetes-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-langchain4j</artifactId>
Expand All @@ -74,7 +72,6 @@
<artifactId>quarkus-flow-langchain4j-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-messaging</artifactId>
Expand All @@ -85,13 +82,11 @@
<artifactId>quarkus-flow-messaging-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-persistence-common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-jpa</artifactId>
Expand All @@ -102,7 +97,6 @@
<artifactId>quarkus-flow-jpa-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-mvstore</artifactId>
Expand All @@ -113,7 +107,6 @@
<artifactId>quarkus-flow-mvstore-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-redis</artifactId>
Expand All @@ -124,7 +117,6 @@
<artifactId>quarkus-flow-redis-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-scheduler</artifactId>
Expand All @@ -135,6 +127,11 @@
<artifactId>quarkus-flow-scheduler-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-testing</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
6 changes: 6 additions & 0 deletions core/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
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());
}
}
}
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);
}

}
8 changes: 7 additions & 1 deletion examples/suspend-resume-abort/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<artifactId>quarkus-flow</artifactId>
<version>${quarkus.flow.version}</version>
</dependency>

<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-mvstore</artifactId>
Expand All @@ -76,6 +76,12 @@
<version>${quarkus.flow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkiverse.flow</groupId>
<artifactId>quarkus-flow-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.smallrye.common.annotation.Identifier;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
Expand Down Expand Up @@ -76,6 +77,15 @@ public Response cancel(@PathParam("instanceId") String instanceId) {
return instanceOperation(instanceId, WorkflowInstance::cancel);
}

@GET
@Path("/status/{instanceId}")
public Response status(@PathParam("instanceId") String instanceId) {
return flow.activeInstance(instanceId)
.map(instance -> Response.ok(Map.of("instanceId", instance.id(), "state", instance.status())).build())
.orElseGet(() -> notFoundResponse(instanceId));

}

private Response instanceOperation(String instanceId, Function<WorkflowInstance, Boolean> function) {
return flow.activeInstance(instanceId)
.map(instance -> function.apply(instance) ? Response.ok().build() : Response.notModified().build())
Expand Down
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();
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>scheduler</module>
<module>bom</module>
<module>quarkus-platform-checks</module>
<module>testing</module>
</modules>

<scm>
Expand Down
88 changes: 88 additions & 0 deletions testing/pom.xml
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>
Comment thread
mcruzdev marked this conversation as resolved.
<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>
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();
}
}
Loading
Loading