Search in sources :

Example 76 with ProcessInstance

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

the class ProcessInstanceAndVariablesQueryTest method testOrQuery.

public void testOrQuery() {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("undefined", 999).variableValueEquals("anothertest", 123).endOr().singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("undefined", 999).endOr().singleResult();
    assertNull(processInstance);
    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123).variableValueEquals("undefined", 999).endOr().singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 999).endOr().singleResult();
    assertNull(processInstance);
    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 999).variableValueEquals("anothertest", 123).endOr().singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 77 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance 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 78 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance 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 79 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance 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 80 with ProcessInstance

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

the class ExecutionQueryTest method testQueryInvalidTypes.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryInvalidTypes() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("bytesVar", "test".getBytes());
    vars.put("serializableVar", new DummySerializable());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    try {
        runtimeService.createExecutionQuery().variableValueEquals("bytesVar", "test".getBytes()).list();
        fail("Expected exception");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Variables of type ByteArray cannot be used to query", ae.getMessage());
    }
    try {
        runtimeService.createExecutionQuery().variableValueEquals("serializableVar", new DummySerializable()).list();
        fail("Expected exception");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Variables of type ByteArray cannot be used to query", ae.getMessage());
    }
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
}
Also used : HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProcessInstance (org.activiti.engine.runtime.ProcessInstance)822 Deployment (org.activiti.engine.test.Deployment)708 Task (org.activiti.engine.task.Task)374 HashMap (java.util.HashMap)242 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)182 Execution (org.activiti.engine.runtime.Execution)76 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)64 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)57 Job (org.activiti.engine.runtime.Job)55 Date (java.util.Date)53 JsonNode (com.fasterxml.jackson.databind.JsonNode)49 Calendar (java.util.Calendar)48 ActivitiException (org.activiti.engine.ActivitiException)41 ArrayList (java.util.ArrayList)38 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)38 HttpGet (org.apache.http.client.methods.HttpGet)38 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)27 StringEntity (org.apache.http.entity.StringEntity)27 HttpPost (org.apache.http.client.methods.HttpPost)25 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)24