cancel
Showing results for 
Search instead for 
Did you mean: 

different output from Test

tomi87
Champ in-the-making
Champ in-the-making
Hello,
can you explain me why the output for the following test is not in order like the tasks in my xml file?
and can you suggest me how I can get the output in the right order ?

In my xml file I have an userTask connection from "Verify monthly financial report1" to "Verify monthly financial report4".


My Test:

public class TenMinuteTutorial {
   @Rule
//   public ActivitiRule activitiRule = new ActivitiRule("activiti.cfg-mem.xml");

   @Test
   //@Deployment(resources={"FinancialReportProcess.bpmn20.xml"})
   public void startFormSubmit() {
      
      System.out.println("–Create Activiti process engine–");
        // Create Activiti process engine
       ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration() .buildProcessEngine();
       System.out.println("–Get Activiti services–");
       // Get Activiti services
       RepositoryService repositoryService = processEngine.getRepositoryService();
       RuntimeService runtimeService = processEngine.getRuntimeService();
       System.out.println("–Deploy the process definition–");
       // Deploy the process definition
       repositoryService.createDeployment().addClasspathResource("FinancialReport.bpmn20.xml").deploy();
       System.out.println("–Start a process instance–");
       // Start a process instance
       String procId = runtimeService.startProcessInstanceByKey("financialReport").getId();
       System.out.println("–Get the first task–");
       // Get the first task
       TaskService taskService = processEngine.getTaskService();

       List<Task> tasks = taskService.createTaskQuery().list();  

         int i=1;
       for (Task task : tasks) {
           System.out.println(task.getName()+" "+i);    
           i++;
            taskService.complete(task.getId());
          }   

       // verify that the process is actually finished
       HistoryService historyService = processEngine.getHistoryService();
       HistoricProcessInstance historicProcessInstance =
         historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
       System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());
   }
}

I get the following output for my test:

–Create Activiti process engine–
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Jan 27, 2013 3:04:37 PM org.activiti.engine.impl.ProcessEngineImpl <init>
INFO: ProcessEngine default created
–Get Activiti services–
–Deploy the process definition–
Jan 27, 2013 3:04:37 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource FinancialReport.bpmn20.xml
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions
INFO: Process with id='financialReport' hasn't the attribute isExecutable set. Please maintain it, so you are compatible to future activiti versions.
–Start a process instance–
–Get the first task–
Verify monthly financial report1 1
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource FinancialReport.bpmn20.xml
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions
INFO: Process with id='financialReport' hasn't the attribute isExecutable set. Please maintain it, so you are compatible to future activiti versions.
Verify monthly financial report3 2
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource FinancialReport.bpmn20.xml
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions
INFO: Process with id='financialReport' hasn't the attribute isExecutable set. Please maintain it, so you are compatible to future activiti versions.
Verify monthly financial report2 3
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource FinancialReport.bpmn20.xml
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions
INFO: Process with id='financialReport' hasn't the attribute isExecutable set. Please maintain it, so you are compatible to future activiti versions.
Verify monthly financial report1 4
Verify monthly financial report3 5
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
INFO: Processing resource FinancialReport.bpmn20.xml
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XMLSchema currently not supported as typeLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
INFO: XPath currently not supported as expressionLanguage
Jan 27, 2013 3:04:38 PM org.activiti.engine.impl.bpmn.parser.BpmnParse parseProcessDefinitions
INFO: Process with id='financialReport' hasn't the attribute isExecutable set. Please maintain it, so you are compatible to future activiti versions.
Process instance end time: null

In this output I have two times the "Verify monthly financial report1" Task. I'm confussed.
And sometimes the last output "Process instance end time: null" appears and sometimes not.

The XML file:
      <sequenceFlow id='flow1' sourceRef='theStart' targetRef='verifyReportTask1' />
      <userTask id="verifyReportTask1" name="Verify monthly financial report1"
         activiti:candidateGroups="student"></userTask>
      <sequenceFlow id='flow2' sourceRef='verifyReportTask1'
         targetRef='verifyReportTask2' />
      <userTask id="verifyReportTask2" name="Verify monthly financial report2"
         activiti:candidateGroups="student"></userTask>
      <sequenceFlow id='flow3' sourceRef='verifyReportTask2'
         targetRef='verifyReportTask3' />
      <userTask id="verifyReportTask3" name="Verify monthly financial report3"
         activiti:candidateGroups="student"></userTask>
      <sequenceFlow id='flow4' sourceRef='verifyReportTask3'
         targetRef='verifyReportTask4' />
      <userTask id="verifyReportTask4" name="Verify monthly financial report4"
         activiti:candidateGroups="student"></userTask>
      <sequenceFlow id='flow5' sourceRef='verifyReportTask4'
         targetRef='theEnd' />

Best regards
8 REPLIES 8

trademak
Star Contributor
Star Contributor
Hi,

It looks like you've ran this test multiple times right?
First of all, do you really want to use a standalone H2 database to run this test? It would be better to use an in-memory H2 database, so you have a clean database every time you run the test.
The first time you run it you only have one user task. But the second time you already have two user tasks, one from the first test run (which is already one step further in the process since you completed the task) and a new task of the second test run. And since you don't do any ordering in the query, the order in which you get the tasks back is random.
So therefore you see the test result you described.

Best regards,

tomi87
Champ in-the-making
Champ in-the-making
No I ran it just one time.
Now I get a listSize = 6. Why ? But I didn't change anything.

And my other output is
Verify monthly financial report3 1
Verify monthly financial report4 2
Verify monthly financial report3 3
Verify monthly financial report3 4
Verify monthly financial report2 5
Verify monthly financial report1 6
Process instance end time: null

Because I want to move the execution until the point I want, and test from there.

Can you give me a simple code example how I can get no double tasks?

frederikherema1
Star Contributor
Star Contributor
To be absolutely sure, you're unit-test is only using the tasks from the process that you JUST created, include the "procId" in the task-query. This way, you'll be unaffected by any data left in the DB…


List<Task> tasks = taskService.createTaskQuery().processInstanceId(procInst).list();  

tomi87
Champ in-the-making
Champ in-the-making
I got it now.
I did it now in this way:

ProcessInstance pi = runtimeService.startProcessInstanceByKey("financialReport");
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    
     assertEquals("Verify monthly financial report1", task.getName());
     taskService.complete(task.getId());
     task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();

            assertEquals("Verify monthly financial report2", task.getName());
     taskService.complete(task.getId());
     task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();

What can I do that JUnit didn't use the data and tasks from the database for the next starts?
–>like an "Uninfected start"

frederikherema1
Star Contributor
Star Contributor
If you're using the activiti base-class for your tests and use the @deployment annotation, the deployment should be removed and all data cascades with it… The same applies when you're using the ActivitiRule.

I see you're NOT using the activiti-rule and deployment-annotation, rather you deploy the process manually. If you don't want to use the utilities we provide you, you can always delete the deployment (cascade = true) at the end of your test.

tomi87
Champ in-the-making
Champ in-the-making
I used the whole time this:

@Test
@Deployment(resources={"FinancialReportProcess.bpmn20.xml"})
public void startFormSubmit() {
    
     ProcessEngine processEngine = ProcessEngineConfiguration
       .createStandaloneProcessEngineConfiguration()
       .buildProcessEngine();

But good to know. Thank you!

frederikherema1
Star Contributor
Star Contributor
You're using the @Deployment annotation, but you're creating the process-engine yourself. That's not going to work. You should use the services/engine provided by the ActivitiRule OR - in case of JUnit3 - the ones provided on the abstract base test class. If you're not using either of these approaches, the @Deployment is useless, as there is nothing in place to pick it up, so NO deployments will be cleaned up, either…

tomi87
Champ in-the-making
Champ in-the-making
Thank you!