Package com.uber.cadence.testing
Interface TestActivityEnvironment
-
- All Known Implementing Classes:
TestActivityEnvironmentInternal
public interface TestActivityEnvironment
The helper class for unit testing activity implementations. Supports calls toActivity
methods from the tested activities. An example test:
Usepublic interface TestActivity { String activity1(String input); } private static class ActivityImpl implements TestActivity { @Override public String activity1(String input) { return Activity.getTask().getActivityType().getName() + "-" + input; } } @Test public void testSuccess() { testEnvironment.registerActivitiesImplementations(new ActivityImpl()); TestActivity activity = testEnvironment.newActivityStub(TestActivity.class); String result = activity.activity1("input1"); assertEquals("TestActivity::activity1-input1", result); }
TestWorkflowEnvironment
to test a workflow code.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> T
newActivityStub(java.lang.Class<T> activityInterface)
Creates a stub that can be used to invoke activities registered throughregisterActivitiesImplementations(Object...)
.static TestActivityEnvironment
newInstance()
static TestActivityEnvironment
newInstance(TestEnvironmentOptions options)
void
registerActivitiesImplementations(java.lang.Object... activityImplementations)
Registers activity implementations to test.<T> void
setActivityHeartbeatListener(java.lang.Class<T> detailsClass, java.lang.reflect.Type detailsType, java.util.function.Consumer<T> listener)
Sets a listener that is called every time an activity implementation heartbeats throughActivity.heartbeat(Object)
.<T> void
setActivityHeartbeatListener(java.lang.Class<T> detailsClass, java.util.function.Consumer<T> listener)
Sets a listener that is called every time an activity implementation heartbeats throughActivity.heartbeat(Object)
.void
setWorkflowService(IWorkflowService workflowService)
-
-
-
Method Detail
-
newInstance
static TestActivityEnvironment newInstance()
-
newInstance
static TestActivityEnvironment newInstance(TestEnvironmentOptions options)
-
registerActivitiesImplementations
void registerActivitiesImplementations(java.lang.Object... activityImplementations)
Registers activity implementations to test. UsenewActivityStub(Class)
to create stubs that can be used to invoke them.
-
newActivityStub
<T> T newActivityStub(java.lang.Class<T> activityInterface)
Creates a stub that can be used to invoke activities registered throughregisterActivitiesImplementations(Object...)
.- Type Parameters:
T
- Type of the activity interface.- Parameters:
activityInterface
- activity interface class that the object under test implements.- Returns:
- The stub that implements the activity interface.
-
setActivityHeartbeatListener
<T> void setActivityHeartbeatListener(java.lang.Class<T> detailsClass, java.util.function.Consumer<T> listener)
Sets a listener that is called every time an activity implementation heartbeats throughActivity.heartbeat(Object)
.- Type Parameters:
T
- Type of the heartbeat details.- Parameters:
detailsClass
- class of the details passed to theActivity.heartbeat(Object)
.listener
- listener to register.
-
setActivityHeartbeatListener
<T> void setActivityHeartbeatListener(java.lang.Class<T> detailsClass, java.lang.reflect.Type detailsType, java.util.function.Consumer<T> listener)
Sets a listener that is called every time an activity implementation heartbeats throughActivity.heartbeat(Object)
.- Type Parameters:
T
- Type of the heartbeat details.- Parameters:
detailsClass
- class of the details passed to theActivity.heartbeat(Object)
.detailsType
- type of the details. Differs for detailsClass for generic types.listener
- listener to register.
-
setWorkflowService
void setWorkflowService(IWorkflowService workflowService)
-
-