Search in sources :

Example 1 with ProcessInstanceQuery

use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.

the class StartTimerEventTest method testCycleDateStartTimerEvent.

// FIXME: This test likes to run in an endless loop when invoking the waitForJobExecutorOnCondition method
@Deployment
public void testCycleDateStartTimerEvent() throws Exception {
    processEngineConfiguration.getClock().setCurrentTime(new Date());
    // After process start, there should be timer created
    JobQuery jobQuery = managementService.createJobQuery();
    assertEquals(1, jobQuery.count());
    final ProcessInstanceQuery piq = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample");
    moveByMinutes(5);
    waitForJobExecutorOnCondition(10000, 500, new Callable<Boolean>() {

        public Boolean call() throws Exception {
            return 1 == piq.count();
        }
    });
    assertEquals(1, jobQuery.count());
    moveByMinutes(5);
    waitForJobExecutorOnCondition(10000, 500, new Callable<Boolean>() {

        public Boolean call() throws Exception {
            return 2 == piq.count();
        }
    });
    assertEquals(1, jobQuery.count());
    //have to manually delete pending timer
    cleanDB();
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) JobQuery(org.activiti.engine.runtime.JobQuery) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ProcessInstanceQuery

use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.

the class ProcessInstanceAndVariablesQueryTest method testOrQueryMultipleVariableValues.

public void testOrQueryMultipleVariableValues() {
    ProcessInstanceQuery query0 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or();
    for (int i = 0; i < 20; i++) {
        query0 = query0.variableValueEquals("anothertest", i);
    }
    query0 = query0.endOr();
    assertNull(query0.singleResult());
    ProcessInstanceQuery query1 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
    for (int i = 0; i < 20; i++) {
        query1 = query1.variableValueEquals("anothertest", i);
    }
    query1 = query1.endOr();
    assertNull(query0.singleResult());
    ProcessInstance processInstance = query1.singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
    ProcessInstanceQuery query2 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or();
    for (int i = 0; i < 20; i++) {
        query2 = query2.variableValueEquals("anothertest", i);
    }
    query2 = query2.endOr().or().processDefinitionKey(PROCESS_DEFINITION_KEY_2).processDefinitionId("undefined").endOr();
    assertNull(query2.singleResult());
    ProcessInstanceQuery query3 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
    for (int i = 0; i < 20; i++) {
        query3 = query3.variableValueEquals("anothertest", i);
    }
    query3 = query3.endOr().or().processDefinitionKey(PROCESS_DEFINITION_KEY_2).processDefinitionId("undefined").endOr();
    variableMap = query3.singleResult().getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 3 with ProcessInstanceQuery

use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.

the class ProcessInstanceQueryAndWithExceptionTest method testQueryWithException.

public void testQueryWithException() throws InterruptedException {
    ProcessInstance processNoException = runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY_NO_EXCEPTION);
    ProcessInstanceQuery queryNoException = runtimeService.createProcessInstanceQuery();
    assertEquals(1, queryNoException.count());
    assertEquals(1, queryNoException.list().size());
    assertEquals(processNoException.getId(), queryNoException.list().get(0).getId());
    ProcessInstanceQuery queryWithException = runtimeService.createProcessInstanceQuery();
    assertEquals(0, queryWithException.withJobException().count());
    assertEquals(0, queryWithException.withJobException().list().size());
    ProcessInstance processWithException1 = startProcessInstanceWithFailingJob(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_1);
    JobQuery jobQuery1 = managementService.createJobQuery().processInstanceId(processWithException1.getId());
    assertEquals(1, jobQuery1.withException().count());
    assertEquals(1, jobQuery1.withException().list().size());
    assertEquals(1, queryWithException.withJobException().count());
    assertEquals(1, queryWithException.withJobException().list().size());
    assertEquals(processWithException1.getId(), queryWithException.withJobException().list().get(0).getId());
    ProcessInstance processWithException2 = startProcessInstanceWithFailingJob(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_2);
    JobQuery jobQuery2 = managementService.createJobQuery().processInstanceId(processWithException2.getId());
    assertEquals(2, jobQuery2.withException().count());
    assertEquals(2, jobQuery2.withException().list().size());
    assertEquals(2, queryWithException.withJobException().count());
    assertEquals(2, queryWithException.withJobException().list().size());
    assertEquals(processWithException1.getId(), queryWithException.withJobException().processDefinitionKey(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_1).list().get(0).getId());
    assertEquals(processWithException2.getId(), queryWithException.withJobException().processDefinitionKey(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_2).list().get(0).getId());
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JobQuery(org.activiti.engine.runtime.JobQuery)

Example 4 with ProcessInstanceQuery

use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.

the class ProcessInstanceQueryTest method testQueryAllVariableTypes.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryAllVariableTypes() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("nullVar", null);
    vars.put("stringVar", "string");
    vars.put("longVar", 10L);
    vars.put("doubleVar", 1.2);
    vars.put("integerVar", 1234);
    vars.put("booleanVar", true);
    vars.put("shortVar", (short) 123);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("nullVar", null).variableValueEquals("stringVar", "string").variableValueEquals("longVar", 10L).variableValueEquals("doubleVar", 1.2).variableValueEquals("integerVar", 1234).variableValueEquals("booleanVar", true).variableValueEquals("shortVar", (short) 123);
    List<ProcessInstance> processInstances = query.list();
    assertNotNull(processInstances);
    assertEquals(1, processInstances.size());
    assertEquals(processInstance.getId(), processInstances.get(0).getId());
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 5 with ProcessInstanceQuery

use of org.activiti.engine.runtime.ProcessInstanceQuery in project Activiti by Activiti.

the class ProcessInstanceQueryTest method testQueryByProcessDefinitionKeySingleResult.

public void testQueryByProcessDefinitionKeySingleResult() {
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY_2);
    assertEquals(PROCESS_DEFINITION_KEY_2_DEPLOY_COUNT, query.count());
    assertEquals(PROCESS_DEFINITION_KEY_2_DEPLOY_COUNT, query.list().size());
    assertNotNull(query.singleResult());
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery)

Aggregations

ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)32 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)19 Deployment (org.activiti.engine.test.Deployment)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 ActivitiException (org.activiti.engine.ActivitiException)5 RuntimeService (org.activiti.engine.RuntimeService)5 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)5 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)5 HashSet (java.util.HashSet)4 ProcessEngine (org.activiti.engine.ProcessEngine)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 Date (java.util.Date)3 BPMNInstance (org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance)3 Map (java.util.Map)2 Execution (org.activiti.engine.runtime.Execution)2 JobQuery (org.activiti.engine.runtime.JobQuery)2 ResourcesWrapper (eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)1 WorkflowProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)1 SimpleDateFormat (java.text.SimpleDateFormat)1