public interface TestActivityEnvironment
Activity
methods from the tested activities. An example test:
public 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);
}
Use TestWorkflowEnvironment
to test a workflow code.Modifier and Type | Method and Description |
---|---|
void |
close() |
<T> T |
newActivityStub(java.lang.Class<T> activityInterface)
Creates a stub that can be used to invoke activities registered through
registerActivitiesImplementations(Object...) . |
static TestActivityEnvironment |
newInstance() |
static TestActivityEnvironment |
newInstance(TestEnvironmentOptions options) |
void |
registerActivitiesImplementations(java.lang.Object... activityImplementations)
Registers activity implementations to test.
|
void |
requestCancelActivity()
Requests activity cancellation.
|
<T> void |
setActivityHeartbeatListener(java.lang.Class<T> detailsClass,
Functions.Proc1<T> listener)
Sets a listener that is called every time an activity implementation heartbeats through
ActivityExecutionContext.heartbeat(Object) . |
<T> void |
setActivityHeartbeatListener(java.lang.Class<T> detailsClass,
java.lang.reflect.Type detailsType,
Functions.Proc1<T> listener)
Sets a listener that is called every time an activity implementation heartbeats through
ActivityExecutionContext.heartbeat(Object) . |
static TestActivityEnvironment newInstance()
static TestActivityEnvironment newInstance(TestEnvironmentOptions options)
void registerActivitiesImplementations(java.lang.Object... activityImplementations)
newActivityStub(Class)
to create stubs
that can be used to invoke them.<T> T newActivityStub(java.lang.Class<T> activityInterface)
registerActivitiesImplementations(Object...)
.T
- Type of the activity interface.activityInterface
- activity interface class that the object under test implements.<T> void setActivityHeartbeatListener(java.lang.Class<T> detailsClass, Functions.Proc1<T> listener)
ActivityExecutionContext.heartbeat(Object)
.T
- Type of the heartbeat details.detailsClass
- class of the details passed to the ActivityExecutionContext.heartbeat(Object)
.listener
- listener to register.<T> void setActivityHeartbeatListener(java.lang.Class<T> detailsClass, java.lang.reflect.Type detailsType, Functions.Proc1<T> listener)
ActivityExecutionContext.heartbeat(Object)
.T
- Type of the heartbeat details.detailsClass
- class of the details passed to the ActivityExecutionContext.heartbeat(Object)
.detailsType
- type of the details. Differs for detailsClass for generic types.listener
- listener to register.void requestCancelActivity()
void close()