public class TestWorkflowRule
extends java.lang.Object
implements org.junit.rules.TestRule
Test rule that sets up test environment, simplifying workflow worker creation and shutdown.
Can be used with both in-memory and standalone temporal service. (see TestWorkflowRule.Builder.setUseExternalService(boolean)
and TestWorkflowRule.Builder.setTarget(String)
})
Example of usage:
public class MyTest {
@Rule
public TestWorkflowRule workflowRule =
TestWorkflowRule.newBuilder()
.setWorkflowTypes(TestWorkflowImpl.class)
.setActivityImplementations(new TestActivities())
.build();
@Test
public void testMyWorkflow() {
TestWorkflow workflow = workflowRule.getWorkflowClient().newWorkflowStub(
TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(workflowRule.getTaskQueue()).build());
...
}
Modifier and Type | Class and Description |
---|---|
static class |
TestWorkflowRule.Builder |
Modifier and Type | Method and Description |
---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
io.temporal.api.workflowservice.v1.WorkflowServiceGrpc.WorkflowServiceBlockingStub |
blockingStub() |
io.temporal.api.history.v1.History |
getHistory(io.temporal.api.common.v1.WorkflowExecution execution) |
<T extends io.temporal.common.interceptors.WorkerInterceptor> |
getInterceptor(java.lang.Class<T> type) |
java.lang.String |
getTaskQueue() |
TestWorkflowEnvironment |
getTestEnvironment() |
io.temporal.worker.Worker |
getWorker()
This worker listens to the default task queue which is obtainable via the
getTaskQueue() method. |
io.temporal.client.WorkflowClient |
getWorkflowClient() |
io.temporal.api.history.v1.History |
getWorkflowExecutionHistory(io.temporal.api.common.v1.WorkflowExecution execution)
Deprecated.
use
getHistory(io.temporal.api.common.v1.WorkflowExecution) , this method will be reworked to return WorkflowExecutionHistory in the upcoming releases |
boolean |
isUseExternalService()
|
static TestWorkflowRule.Builder |
newBuilder() |
io.temporal.client.WorkflowStub |
newUntypedWorkflowStub(java.lang.String workflow) |
<T> T |
newWorkflowStub(java.lang.Class<T> workflow) |
protected void |
shutdown() |
public static TestWorkflowRule.Builder newBuilder()
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
protected void shutdown()
public boolean isUseExternalService()
public TestWorkflowEnvironment getTestEnvironment()
public java.lang.String getTaskQueue()
public io.temporal.client.WorkflowClient getWorkflowClient()
public io.temporal.api.workflowservice.v1.WorkflowServiceGrpc.WorkflowServiceBlockingStub blockingStub()
public <T extends io.temporal.common.interceptors.WorkerInterceptor> T getInterceptor(java.lang.Class<T> type)
public io.temporal.api.history.v1.History getHistory(io.temporal.api.common.v1.WorkflowExecution execution)
@Deprecated public io.temporal.api.history.v1.History getWorkflowExecutionHistory(io.temporal.api.common.v1.WorkflowExecution execution)
getHistory(io.temporal.api.common.v1.WorkflowExecution)
, this method will be reworked to return WorkflowExecutionHistory
in the upcoming releasespublic io.temporal.worker.Worker getWorker()
getTaskQueue()
method.public <T> T newWorkflowStub(java.lang.Class<T> workflow)
public io.temporal.client.WorkflowStub newUntypedWorkflowStub(java.lang.String workflow)