Skip to content

Commit c0f326c

Browse files
committed
More code formatting
1 parent dea60f3 commit c0f326c

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

saas-modules/temporal/src/test/java/com/baeldung/temporal/HelloWorkerUnitTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ public void startWorker() {
3939
HelloWorkflowRegistrar.newInstance().register(worker);
4040
client = testEnv.getWorkflowClient();
4141

42-
// var serviceStubs = WorkflowServiceStubs.newServiceStubs(WorkflowServiceStubsOptions
43-
// .newBuilder()
44-
// .setTarget("localhost:7233")
45-
// .setEnableKeepAlive(true)
46-
// .setEnableHttps(false)
47-
// .build());
48-
//
49-
// client = WorkflowClient.newInstance(serviceStubs);
50-
5142
testEnv.start();
5243
}
5344

saas-modules/temporal/src/test/java/com/baeldung/temporal/HelloWorkflowIntegrationTest.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22

33
import com.baeldung.temporal.workflows.hello.HelloWorkflow;
44
import com.baeldung.temporal.workflows.hello.HelloWorkflowRegistrar;
5-
import com.baeldung.temporal.workflows.hellov2.HelloWorkflowV2;
65
import io.temporal.client.WorkflowClient;
76
import io.temporal.client.WorkflowOptions;
87
import io.temporal.serviceclient.WorkflowServiceStubs;
98
import io.temporal.worker.Worker;
109
import io.temporal.worker.WorkerFactory;
11-
import io.temporal.worker.WorkerOptions;
1210
import org.junit.jupiter.api.AfterEach;
1311
import org.junit.jupiter.api.BeforeEach;
1412
import org.junit.jupiter.api.Test;
1513
import org.slf4j.Logger;
1614
import org.slf4j.LoggerFactory;
1715

1816
import java.util.UUID;
17+
import java.util.concurrent.ExecutionException;
1918

2019
import static org.junit.jupiter.api.Assertions.assertEquals;
2120

@@ -52,8 +51,8 @@ public void stopWorker() {
5251
@Test
5352
void givenPerson_whenSayHello_thenSuccess() {
5453

55-
WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();
56-
WorkflowClient client = WorkflowClient.newInstance(service);
54+
var service = WorkflowServiceStubs.newLocalServiceStubs();
55+
var client = WorkflowClient.newInstance(service);
5756

5857
var wfid = UUID.randomUUID().toString();
5958

@@ -68,9 +67,35 @@ void givenPerson_whenSayHello_thenSuccess() {
6867
// Run the workflow synchronously
6968
var result = workflow.hello("Baeldung");
7069
assertEquals("Hello, Baeldung", result);
71-
7270
}
7371

72+
@Test
73+
void givenPerson_whenSayHelloAsync_thenSuccess() throws ExecutionException, InterruptedException {
74+
75+
var service = WorkflowServiceStubs.newLocalServiceStubs();
76+
var client = WorkflowClient.newInstance(service);
77+
78+
var wfid = UUID.randomUUID().toString();
79+
80+
var workflow = client.newWorkflowStub(
81+
HelloWorkflow.class,
82+
WorkflowOptions.newBuilder()
83+
.setTaskQueue(QUEUE_NAME)
84+
.setWorkflowId(wfid)
85+
.build()
86+
);
87+
88+
var execution = WorkflowClient.start(workflow::hello,"Baeldung");
89+
90+
var workflowStub = client.newUntypedWorkflowStub(execution.getWorkflowId());
7491

92+
// Retrieve a CompletableFuture we can use to wait for the result.
93+
var future = workflowStub.getResultAsync(String.class);
94+
log.info("Waiting for workflow to complete...");
95+
var result = future.get();
96+
log.info("Workflow completed with result: {}", result);
97+
assertEquals("Hello, Baeldung", result);
98+
99+
}
75100

76101
}

0 commit comments

Comments
 (0)