11-06-2012 04:07 PM
public class MyProcessTest extends ActivitiTestCase
{
private ProcessInstance startProcessInstance() throws InterruptedException
{
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MyProcessKey");
Assert.assertNotNull(processInstance.getId());
waitAndCompleteUserTask();
waitForJobExecutorToProcessAllJobs(30000, 100);
return processInstance;
}
private void waitAndCompleteUserTask() throws InterruptedException
{
boolean taskIsAssignedToUser = false;
List<Task> taskList = taskService.createTaskQuery().taskAssignee("MyUser").list();
int numberOfUserTask = (int) taskList.size();
System.out.println("numberOfUserTask=" + numberOfUserTask);
int timeout = 0;
while ((numberOfUserTask == 0) && timeout < 10000)
{
taskList = taskService.createTaskQuery().taskAssignee("MyUser").list();
numberOfUserTask = (int) taskList.size();
System.out.println("numberOfUserTask=" + numberOfUserTask);
if (numberOfUserTask == 1)
{
taskIsAssignedToUser = true;
}
Thread.sleep(300);
timeout += 300;
}
assertTrue("No task was assigned to user", taskIsAssignedToUser);
Task userTask = taskList.get(0);
taskService.complete(userTask.getId());
}
@Test
@Deployment(resources =
{
"MyPackage/MyProcess.bpmn20.xml"
})
public void testUserTaskInFirstCase() throws InterruptedException
{
//Init test conditions 1
startProcessInstance();
//Check result 1
}
@Test
@Deployment(resources =
{
"MyPackage/MyProcess.bpmn20.xml"
})
public void testUserTaskInSecondCase() throws InterruptedException
{
//Init test conditions 2
startProcessInstance();
//Check result 2
}
/**
* Wait no more jobs are in execution - useful for asynchronous behavior,
* which is the case of our process.
*
* @param maxMillisToWait
* @param intervalMillis
*/
private void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis) throws InterruptedException
{
//The famous method…
}
}
If I execute each test separately, it works fine. But if I execute all the tests of the class, it works for the first test but it does not work for the second test: the user task is never found: I get an AssertionFailedError "No task was assigned to user". In fact, it seems the process has not even gone through the first service task as I cannot see the corresponding log.<property name="jobExecutorActivate" value="true" />
If I set:<property name="jobExecutorActivate" value="false" />
It is worth: the 2 tests fail with the AssertionFailedError.11-07-2012 03:56 AM
11-08-2012 04:49 AM
11-08-2012 05:19 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.