09-07-2016 08:25 AM
@Mock
private TestMockDelegate testMockDelegateMock;
@Mock
private TestMockListener testMockListenerMock;
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
SpringProcessEngineConfiguration configuration = (SpringProcessEngineConfiguration) processEngine.getProcessEngineConfiguration();
configuration.setExpressionManager(new MockExpressionManager());
}
@Test
public void testWithMock() throws Exception {
System.out.println("================= testWithMock() start =================");
Mocks.register("testMockDelegate", testMockDelegateMock);
Mocks.register("testMockListener", testMockListenerMock);
when(testMockDelegateMock.execute((DelegateExecution) anyObject())).thenReturn("mock execute() was used");
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testMockProcess");
assertNotNull(pi);
JobTestHelper.waitForJobExecutorToProcessAllJobs(processEngine.getProcessEngineConfiguration(), managementService, 10000L, 100L);
verify(testMockDelegateMock, times(1)).execute((DelegateExecution) anyObject());
verify(testMockListenerMock, times(1)).execute((ActivityExecution) anyObject());
verify(testMockListenerMock, times(1)).notify((DelegateTask) anyObject());
verifyNoMoreInteractions(testMockDelegateMock);
verifyNoMoreInteractions(testMockListenerMock);
System.out.println("================= testWithMock() end ================= \n");
}
<userTask id="usertask1" name="User Task" activiti:async="true">
<extensionElements>
<activiti:taskListener event="create" expression="${testMockListener.notify(task)}"></activiti:taskListener>
</extensionElements>
</userTask>
public class TestMockListener {
private static final Logger log = Logger.getLogger(TestMockListener.class);
public void notify(DelegateTask task) {
System.out.println("TestMockListener.notify() has been executed");
}
public void execute(ActivityExecution execution) {
System.out.println("TestMockListener.execute() has been executed");
}
}
09-07-2016 01:14 PM
09-08-2016 03:13 AM
09-08-2016 07:39 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.