Skip to content

Commit 7d40e76

Browse files
committed
add tests
Signed-off-by: Matheus Cruz <[email protected]>
1 parent 3277a00 commit 7d40e76

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

sdk-tests/src/test/java/io/dapr/it/testcontainers/workflows/DaprWorkflowsIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.dapr.testcontainers.DaprContainer;
2121
import io.dapr.testcontainers.DaprLogLevel;
2222
import io.dapr.workflows.client.DaprWorkflowClient;
23+
import io.dapr.workflows.client.WorkflowInstanceStatus;
2324
import io.dapr.workflows.client.WorkflowRuntimeStatus;
2425
import io.dapr.workflows.client.WorkflowState;
2526
import io.dapr.workflows.runtime.WorkflowRuntime;
@@ -120,6 +121,27 @@ public void testWorkflows() throws Exception {
120121
assertEquals(instanceId, workflowOutput.getWorkflowId());
121122
}
122123

124+
@Test
125+
public void testWorkflowsOldApi() throws Exception {
126+
TestWorkflowPayload payload = new TestWorkflowPayload(new ArrayList<>());
127+
String instanceId = workflowClient.scheduleNewWorkflow(TestWorkflow.class, payload);
128+
129+
workflowClient.waitForWorkflowStart(instanceId, Duration.ofSeconds(10), false);
130+
workflowClient.raiseEvent(instanceId, "MoveForward", payload);
131+
132+
Duration timeout = Duration.ofSeconds(10);
133+
WorkflowInstanceStatus workflowStatus = workflowClient.waitForInstanceCompletion(instanceId, timeout, true);
134+
135+
assertNotNull(workflowStatus);
136+
137+
TestWorkflowPayload workflowOutput = deserialize(workflowStatus.getSerializedOutput());
138+
139+
assertEquals(2, workflowOutput.getPayloads().size());
140+
assertEquals("First Activity", workflowOutput.getPayloads().get(0));
141+
assertEquals("Second Activity", workflowOutput.getPayloads().get(1));
142+
assertEquals(instanceId, workflowOutput.getWorkflowId());
143+
}
144+
123145
@Test
124146
public void testSuspendAndResumeWorkflows() throws Exception {
125147
TestWorkflowPayload payload = new TestWorkflowPayload(new ArrayList<>());

sdk-tests/src/test/java/io/dapr/it/testcontainers/workflows/multiapp/WorkflowsMultiAppCallActivityIT.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import io.dapr.workflows.client.WorkflowInstanceStatus;
2323
import io.dapr.workflows.client.WorkflowRuntimeStatus;
2424
import io.dapr.config.Properties;
25-
import net.bytebuddy.utility.dispatcher.JavaDispatcher;
25+
import io.dapr.workflows.client.WorkflowState;
2626
import org.junit.jupiter.api.Tag;
2727
import org.junit.jupiter.api.Test;
2828
import org.testcontainers.containers.Network;
@@ -177,7 +177,46 @@ public void testMultiAppWorkflow() throws Exception {
177177
assertNotNull(instanceId, "Workflow instance ID should not be null");
178178
workflowClient.waitForWorkflowStart(instanceId, Duration.ofSeconds(30), false);
179179

180-
WorkflowInstanceStatus workflowStatus = workflowClient.waitForWorkflowCompletion(instanceId, null, true);
180+
WorkflowState workflowStatus = workflowClient.waitForWorkflowCompletion(instanceId, null, true);
181+
assertNotNull(workflowStatus, "Workflow status should not be null");
182+
assertEquals(WorkflowRuntimeStatus.COMPLETED, workflowStatus.getRuntimeStatus(),
183+
"Workflow should complete successfully");
184+
String workflowOutput = workflowStatus.readOutputAs(String.class);
185+
assertEquals(expectedOutput, workflowOutput, "Workflow output should match expected result");
186+
} finally {
187+
workflowClient.close();
188+
}
189+
}
190+
191+
/**
192+
* It duplicates the {@link #testMultiAppWorkflow()} due to deprecated APIs.
193+
* It must be deleted after {@link WorkflowInstanceStatus} be removed.
194+
*/
195+
@Test
196+
@Deprecated(forRemoval = true)
197+
public void testMultiAppWorkflowOldApi() throws Exception {
198+
// TestContainers wait strategies ensure all containers are ready before this test runs
199+
200+
String input = "Hello World";
201+
String expectedOutput = "HELLO WORLD [TRANSFORMED BY APP2] [FINALIZED BY APP3]";
202+
203+
// Create workflow client connected to the main workflow orchestrator
204+
// Use the same endpoint configuration that the workers use
205+
// The workers use host.testcontainers.internal:50001
206+
Map<String, String> propertyOverrides = Map.of(
207+
"dapr.grpc.endpoint", MAIN_WORKFLOW_SIDECAR.getGrpcEndpoint(),
208+
"dapr.http.endpoint", MAIN_WORKFLOW_SIDECAR.getHttpEndpoint()
209+
);
210+
211+
Properties clientProperties = new Properties(propertyOverrides);
212+
DaprWorkflowClient workflowClient = new DaprWorkflowClient(clientProperties);
213+
214+
try {
215+
String instanceId = workflowClient.scheduleNewWorkflow(MultiAppWorkflow.class, input);
216+
assertNotNull(instanceId, "Workflow instance ID should not be null");
217+
workflowClient.waitForWorkflowStart(instanceId, Duration.ofSeconds(30), false);
218+
219+
WorkflowInstanceStatus workflowStatus = workflowClient.waitForInstanceCompletion(instanceId, null, true);
181220
assertNotNull(workflowStatus, "Workflow status should not be null");
182221
assertEquals(WorkflowRuntimeStatus.COMPLETED, workflowStatus.getRuntimeStatus(),
183222
"Workflow should complete successfully");

0 commit comments

Comments
 (0)