-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13b72ea
commit 08b311b
Showing
6 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
80 changes: 80 additions & 0 deletions
80
core/src/test/java/io/temporal/samples/nexus/caller/CallerWorkflowTest.java
This file contains 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,80 @@ | ||
package io.temporal.samples.nexus.caller; | ||
|
||
import io.temporal.client.WorkflowOptions; | ||
import io.temporal.samples.nexus.handler.HelloHandlerWorkflow; | ||
import io.temporal.samples.nexus.handler.NexusServiceImpl; | ||
import io.temporal.samples.nexus.service.NexusService; | ||
import io.temporal.testing.TestWorkflowRule; | ||
import io.temporal.worker.WorkflowImplementationOptions; | ||
import io.temporal.workflow.NexusServiceOptions; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class CallerWorkflowTest { | ||
|
||
@Rule | ||
public TestWorkflowRule testWorkflowRule = | ||
TestWorkflowRule.newBuilder() | ||
// If a Nexus service is registered as part of the test, the TestWorkflowRule will ,by | ||
// default, automatically create a Nexus service endpoint and workflows registered as part | ||
// of the TestWorkflowRule will automatically inherit the endpoint if none is set. | ||
.setNexusServiceImplementation(new NexusServiceImpl()) | ||
.setWorkflowTypes(HelloCallerWorkflowImpl.class) | ||
.setDoNotStart(true) | ||
.build(); | ||
|
||
@Test | ||
public void testHelloWorkflow() { | ||
testWorkflowRule | ||
.getWorker() | ||
.registerWorkflowImplementationFactory( | ||
HelloHandlerWorkflow.class, | ||
() -> { | ||
HelloHandlerWorkflow wf = mock(HelloHandlerWorkflow.class); | ||
when(wf.hello(any())).thenReturn(new NexusService.HelloOutput("Hello World 👋")); | ||
return wf; | ||
}); | ||
testWorkflowRule.getTestEnvironment().start(); | ||
|
||
HelloCallerWorkflow workflow = | ||
testWorkflowRule | ||
.getWorkflowClient() | ||
.newWorkflowStub( | ||
HelloCallerWorkflow.class, | ||
WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build()); | ||
String greeting = workflow.hello("World", NexusService.Language.EN); | ||
assertEquals("Hello World 👋", greeting); | ||
|
||
testWorkflowRule.getTestEnvironment().shutdown(); | ||
} | ||
|
||
@Test | ||
public void testEchoWorkflow() { | ||
testWorkflowRule | ||
.getWorker() | ||
.registerWorkflowImplementationTypes( | ||
WorkflowImplementationOptions.newBuilder() | ||
.setDefaultNexusServiceOptions( | ||
NexusServiceOptions.newBuilder() | ||
.setEndpoint(testWorkflowRule.getNexusEndpoint().getSpec().getName()) | ||
.build()) | ||
.build(), | ||
EchoCallerWorkflowImpl.class); | ||
testWorkflowRule.getTestEnvironment().start(); | ||
|
||
EchoCallerWorkflow workflow = | ||
testWorkflowRule | ||
.getWorkflowClient() | ||
.newWorkflowStub( | ||
EchoCallerWorkflow.class, | ||
WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build()); | ||
String greeting = workflow.echo("Hello"); | ||
assertEquals("Hello", greeting); | ||
testWorkflowRule.getTestEnvironment().shutdown(); | ||
} | ||
} |