use of org.activiti.engine.history.HistoricProcessInstanceQuery in project Activiti by Activiti.
the class HistoryServiceTest method testHistoricProcessInstanceQueryByProcessInstanceIds.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricProcessInstanceQueryByProcessInstanceIds() {
HashSet<String> processInstanceIds = new HashSet<String>();
for (int i = 0; i < 4; i++) {
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
}
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());
// start an instance that will not be part of the query
runtimeService.startProcessInstanceByKey("oneTaskProcess2", "2");
HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceIds(processInstanceIds);
assertEquals(5, processInstanceQuery.count());
List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
assertNotNull(processInstances);
assertEquals(5, processInstances.size());
for (HistoricProcessInstance historicProcessInstance : processInstances) {
assertTrue(processInstanceIds.contains(historicProcessInstance.getId()));
}
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project Activiti by Activiti.
the class HistoryServiceTest method testHistoricProcessInstanceQueryByDeploymentIdIn.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricProcessInstanceQueryByDeploymentIdIn() {
org.activiti.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
HashSet<String> processInstanceIds = new HashSet<String>();
for (int i = 0; i < 4; i++) {
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
}
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());
List<String> deploymentIds = new ArrayList<String>();
deploymentIds.add(deployment.getId());
deploymentIds.add("invalid");
HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentIdIn(deploymentIds);
assertEquals(5, processInstanceQuery.count());
List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
assertNotNull(processInstances);
assertEquals(5, processInstances.size());
deploymentIds = new ArrayList<String>();
deploymentIds.add("invalid");
processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentIdIn(deploymentIds);
assertEquals(0, processInstanceQuery.count());
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project Activiti by Activiti.
the class HistoricProcessInstanceAndVariablesQueryTest method testOrQueryByprocessDefinition.
public void testOrQueryByprocessDefinition() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
// DeploymentId
String deploymentId = repositoryService.createDeploymentQuery().list().get(0).getId();
HistoricProcessInstanceQuery historicprocessInstanceQuery = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").deploymentId(deploymentId).endOr();
assertEquals(6, historicprocessInstanceQuery.list().size());
assertEquals(6, historicprocessInstanceQuery.count());
Map<String, Object> variableMap = historicprocessInstanceQuery.list().get(4).getProcessVariables();
assertEquals(1, variableMap.size());
assertEquals(123, variableMap.get("anothertest"));
for (HistoricProcessInstance processInstance : historicprocessInstanceQuery.list()) {
assertEquals(deploymentId, processInstance.getDeploymentId());
}
HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").deploymentId("invalid").endOr().singleResult();
assertNull(processInstance);
// ProcessDefinitionName
processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionName(PROCESS_DEFINITION_NAME_2).endOr().singleResult();
variableMap = processInstance.getProcessVariables();
assertEquals(1, variableMap.size());
assertEquals(123, variableMap.get("anothertest"));
assertEquals(PROCESS_DEFINITION_NAME_2, processInstance.getProcessDefinitionName());
processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionName("invalid").endOr().singleResult();
assertNull(processInstance);
// ProcessDefinitionCategory
processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionCategory(PROCESS_DEFINITION_CATEGORY_2).endOr().singleResult();
variableMap = processInstance.getProcessVariables();
assertEquals(1, variableMap.size());
assertEquals(123, variableMap.get("anothertest"));
processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionCategory("invalid").endOr().singleResult();
assertNull(processInstance);
}
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project Activiti by Activiti.
the class HistoricProcessInstanceAndVariablesQueryTest method testOrQueryMultipleVariableValues.
public void testOrQueryMultipleVariableValues() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
HistoricProcessInstanceQuery query0 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or();
for (int i = 0; i < 20; i++) {
query0 = query0.variableValueEquals("anothertest", i);
}
query0 = query0.processDefinitionId("undefined").endOr();
assertNull(query0.singleResult());
HistoricProcessInstanceQuery query1 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
for (int i = 0; i < 20; i++) {
query1 = query1.variableValueEquals("anothertest", i);
}
query1 = query1.processDefinitionId("undefined").endOr();
HistoricProcessInstance processInstance = query1.singleResult();
Map<String, Object> variableMap = processInstance.getProcessVariables();
assertEquals(1, variableMap.size());
assertEquals(123, variableMap.get("anothertest"));
HistoricProcessInstanceQuery query2 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or();
for (int i = 0; i < 20; i++) {
query2 = query2.variableValueEquals("anothertest", i);
}
query2 = query2.processDefinitionId("undefined").endOr().or().processDefinitionKey(PROCESS_DEFINITION_KEY_2).processDefinitionId("undefined").endOr();
assertNull(query2.singleResult());
HistoricProcessInstanceQuery query3 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
for (int i = 0; i < 20; i++) {
query3 = query3.variableValueEquals("anothertest", i);
}
query3 = query3.processDefinitionId("undefined").endOr().or().processDefinitionKey(PROCESS_DEFINITION_KEY_2).processDefinitionId("undefined").endOr();
variableMap = query3.singleResult().getProcessVariables();
assertEquals(1, variableMap.size());
assertEquals(123, variableMap.get("anothertest"));
}
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project Activiti by Activiti.
the class HistoricProcessInstanceQueryAndWithExceptionTest method testQueryWithException.
public void testQueryWithException() throws InterruptedException {
ProcessInstance processNoException = runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY_NO_EXCEPTION);
HistoricProcessInstanceQuery queryNoException = historyService.createHistoricProcessInstanceQuery();
assertEquals(1, queryNoException.count());
assertEquals(1, queryNoException.list().size());
assertEquals(processNoException.getId(), queryNoException.list().get(0).getId());
HistoricProcessInstanceQuery queryWithException = historyService.createHistoricProcessInstanceQuery();
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());
}
Aggregations