Skip to content

Commit 5466b89

Browse files
committed
adding test
Signed-off-by: Tihomir Surdilovic <[email protected]>
1 parent cd65f9f commit 5466b89

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

core/src/main/java/io/temporal/samples/hello/HelloSignalWithStartAndWorkflowInit.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
public class HelloSignalWithStartAndWorkflowInit {
2424
static final String TASK_QUEUE = "HelloWithInitTaskQueue";
25-
static final String WORKFLOW_ID = "HelloWithInitWorkflowId";
2625

2726
public interface MyWorkflow {
2827
@WorkflowMethod
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package io.temporal.samples.hello;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.fail;
5+
6+
import io.temporal.client.WorkflowFailedException;
7+
import io.temporal.client.WorkflowOptions;
8+
import io.temporal.client.WorkflowStub;
9+
import io.temporal.testing.TestWorkflowEnvironment;
10+
import io.temporal.testing.TestWorkflowExtension;
11+
import io.temporal.worker.Worker;
12+
import io.temporal.worker.WorkflowImplementationOptions;
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.extension.RegisterExtension;
15+
16+
public class HelloSignalWithStartAndWorkflowInitTest {
17+
@RegisterExtension
18+
public static final TestWorkflowExtension testWorkflowExtension =
19+
TestWorkflowExtension.newBuilder()
20+
.registerWorkflowImplementationTypes(
21+
HelloSignalWithStartAndWorkflowInit.WithInitMyWorkflowImpl.class)
22+
.registerWorkflowImplementationTypes(
23+
WorkflowImplementationOptions.newBuilder()
24+
.setFailWorkflowExceptionTypes(NullPointerException.class)
25+
.build(),
26+
HelloSignalWithStartAndWorkflowInit.WithoutInitMyWorkflowImpl.class)
27+
.setActivityImplementations(
28+
new HelloSignalWithStartAndWorkflowInit.MyGreetingActivitiesImpl())
29+
.build();
30+
31+
@Test
32+
public void testWithInit(TestWorkflowEnvironment testEnv, Worker worker) {
33+
HelloSignalWithStartAndWorkflowInit.MyWorkflowWithInit withInitStub =
34+
testEnv
35+
.getWorkflowClient()
36+
.newWorkflowStub(
37+
HelloSignalWithStartAndWorkflowInit.MyWorkflowWithInit.class,
38+
WorkflowOptions.newBuilder()
39+
.setWorkflowId("with-init")
40+
.setTaskQueue(worker.getTaskQueue())
41+
.build());
42+
WorkflowStub.fromTyped(withInitStub)
43+
.signalWithStart(
44+
"addGreeting",
45+
new Object[] {new HelloSignalWithStartAndWorkflowInit.Person("Michael", "Jordan", 55)},
46+
new Object[] {new HelloSignalWithStartAndWorkflowInit.Person("John", "Stockton", 57)});
47+
String result = WorkflowStub.fromTyped(withInitStub).getResult(String.class);
48+
assertEquals("Hello Michael Jordan,Hello John Stockton", result);
49+
}
50+
51+
@Test
52+
public void testWithoutInit(TestWorkflowEnvironment testEnv, Worker worker) {
53+
HelloSignalWithStartAndWorkflowInit.MyWorkflowNoInit noInitStub =
54+
testEnv
55+
.getWorkflowClient()
56+
.newWorkflowStub(
57+
HelloSignalWithStartAndWorkflowInit.MyWorkflowNoInit.class,
58+
WorkflowOptions.newBuilder()
59+
.setWorkflowId("without-init")
60+
.setTaskQueue(worker.getTaskQueue())
61+
.build());
62+
WorkflowStub.fromTyped(noInitStub)
63+
.signalWithStart(
64+
"addGreeting",
65+
new Object[] {new HelloSignalWithStartAndWorkflowInit.Person("Michael", "Jordan", 55)},
66+
new Object[] {new HelloSignalWithStartAndWorkflowInit.Person("John", "Stockton", 57)});
67+
try {
68+
WorkflowStub.fromTyped(noInitStub).getResult(String.class);
69+
fail("Workflow execution should have failed");
70+
} catch (Exception e) {
71+
if (!(e instanceof WorkflowFailedException)) {
72+
fail("Workflow execution should have failed");
73+
}
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)