use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoryServiceTest method testHistoricProcessInstanceQueryForDelete.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testHistoricProcessInstanceQueryForDelete() {
String processInstanceId = runtimeService.startProcessInstanceByKey("oneTaskProcess").getId();
runtimeService.deleteProcessInstance(processInstanceId, null);
HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId);
assertEquals(1, processInstanceQuery.count());
HistoricProcessInstance processInstance = processInstanceQuery.singleResult();
assertEquals(processInstanceId, processInstance.getId());
assertEquals("ACTIVITY_DELETED", processInstance.getDeleteReason());
processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).deleted();
assertEquals(1, processInstanceQuery.count());
processInstance = processInstanceQuery.singleResult();
assertEquals(processInstanceId, processInstance.getId());
assertEquals("ACTIVITY_DELETED", processInstance.getDeleteReason());
processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).notDeleted();
assertEquals(0, processInstanceQuery.count());
historyService.deleteHistoricProcessInstance(processInstanceId);
processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId);
assertEquals(0, processInstanceQuery.count());
processInstanceId = runtimeService.startProcessInstanceByKey("oneTaskProcess").getId();
runtimeService.deleteProcessInstance(processInstanceId, "custom message");
processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId);
assertEquals(1, processInstanceQuery.count());
processInstance = processInstanceQuery.singleResult();
assertEquals(processInstanceId, processInstance.getId());
assertEquals("custom message", processInstance.getDeleteReason());
processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).deleted();
assertEquals(1, processInstanceQuery.count());
processInstance = processInstanceQuery.singleResult();
assertEquals(processInstanceId, processInstance.getId());
assertEquals("custom message", processInstance.getDeleteReason());
processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).notDeleted();
assertEquals(0, processInstanceQuery.count());
}
use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class NonCascadeDeleteTest method testHistoricProcessInstanceQuery.
@Test
public void testHistoricProcessInstanceQuery() {
deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml").deploy().getId();
processInstanceId = runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY).getId();
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
taskService.complete(task.getId());
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertEquals(PROCESS_DEFINITION_KEY, processInstance.getProcessDefinitionKey());
// Delete deployment and historic process instance remains.
repositoryService.deleteDeployment(deploymentId, false);
HistoricProcessInstance processInstanceAfterDelete = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertEquals(null, processInstanceAfterDelete.getProcessDefinitionKey());
assertEquals(null, processInstanceAfterDelete.getProcessDefinitionName());
assertEquals(null, processInstanceAfterDelete.getProcessDefinitionVersion());
// clean
historyService.deleteHistoricProcessInstance(processInstanceId);
}
}
use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoryServiceTest method testQueryDateVariable.
/**
* Only do one second type, as the logic is same as in {@link ProcessInstanceQueryTest} and I do not want to duplicate
* all test case logic here.
* Basically copied from {@link ProcessInstanceQueryTest}
*/
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryDateVariable() throws Exception {
Map<String, Object> vars = new HashMap<String, Object>();
Date date1 = Calendar.getInstance().getTime();
vars.put("dateVar", date1);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
taskService.complete(taskService.createTaskQuery().processInstanceId(processInstance1.getId()).singleResult().getId());
Date date2 = Calendar.getInstance().getTime();
vars = new HashMap<String, Object>();
vars.put("dateVar", date1);
vars.put("dateVar2", date2);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
taskService.complete(taskService.createTaskQuery().processInstanceId(processInstance2.getId()).singleResult().getId());
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
vars = new HashMap<String, Object>();
vars.put("dateVar", nextYear.getTime());
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
taskService.complete(taskService.createTaskQuery().processInstanceId(processInstance3.getId()).singleResult().getId());
Calendar nextMonth = Calendar.getInstance();
nextMonth.add(Calendar.MONTH, 1);
Calendar twoYearsLater = Calendar.getInstance();
twoYearsLater.add(Calendar.YEAR, 2);
Calendar oneYearAgo = Calendar.getInstance();
oneYearAgo.add(Calendar.YEAR, -1);
// Query on single short variable, should result in 2 matches
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().variableValueEquals("dateVar", date1);
List<HistoricProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
// Query on two short variables, should result in single value
query = historyService.createHistoricProcessInstanceQuery().variableValueEquals("dateVar", date1).variableValueEquals("dateVar2", date2);
HistoricProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance2.getId(), resultInstance.getId());
// Query with unexisting variable value
Date unexistingDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/01/1989 12:00:00");
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueEquals("dateVar", unexistingDate).singleResult();
assertNull(resultInstance);
// Test NOT_EQUALS
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueNotEquals("dateVar", date1).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueGreaterThan("dateVar", nextMonth.getTime()).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().variableValueGreaterThan("dateVar", nextYear.getTime()).count());
assertEquals(3, historyService.createHistoricProcessInstanceQuery().variableValueGreaterThan("dateVar", oneYearAgo.getTime()).count());
// Test GREATER_THAN_OR_EQUAL
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar", nextMonth.getTime()).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar", nextYear.getTime()).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, historyService.createHistoricProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar", oneYearAgo.getTime()).count());
// Test LESS_THAN
processInstances = historyService.createHistoricProcessInstanceQuery().variableValueLessThan("dateVar", nextYear.getTime()).list();
assertEquals(2, processInstances.size());
List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().variableValueLessThan("dateVar", date1).count());
assertEquals(3, historyService.createHistoricProcessInstanceQuery().variableValueLessThan("dateVar", twoYearsLater.getTime()).count());
// Test LESS_THAN_OR_EQUAL
processInstances = historyService.createHistoricProcessInstanceQuery().variableValueLessThanOrEqual("dateVar", nextYear.getTime()).list();
assertEquals(3, processInstances.size());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().variableValueLessThanOrEqual("dateVar", oneYearAgo.getTime()).count());
// Test value-only matching
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueEquals(nextYear.getTime()).singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
processInstances = historyService.createHistoricProcessInstanceQuery().variableValueEquals(date1).list();
assertEquals(2, processInstances.size());
expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueEquals(twoYearsLater.getTime()).singleResult();
assertNull(resultInstance);
historyService.deleteHistoricProcessInstance(processInstance1.getId());
historyService.deleteHistoricProcessInstance(processInstance2.getId());
historyService.deleteHistoricProcessInstance(processInstance3.getId());
}
use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoryServiceTest method testQueryStringVariable.
/**
* basically copied from {@link ProcessInstanceQueryTest}
*/
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryStringVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("stringVar", "abcdef");
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
taskService.complete(taskService.createTaskQuery().processInstanceId(processInstance1.getId()).singleResult().getId());
vars = new HashMap<String, Object>();
vars.put("stringVar", "abcdef");
vars.put("stringVar2", "ghijkl");
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
taskService.complete(taskService.createTaskQuery().processInstanceId(processInstance2.getId()).singleResult().getId());
vars = new HashMap<String, Object>();
vars.put("stringVar", "azerty");
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
taskService.complete(taskService.createTaskQuery().processInstanceId(processInstance3.getId()).singleResult().getId());
// Test EQUAL on single string variable, should result in 2 matches
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().variableValueEquals("stringVar", "abcdef");
List<HistoricProcessInstance> processInstances = query.list();
assertNotNull(processInstances);
assertEquals(2, processInstances.size());
// Test EQUAL on two string variables, should result in single match
query = historyService.createHistoricProcessInstanceQuery().variableValueEquals("stringVar", "abcdef").variableValueEquals("stringVar2", "ghijkl");
HistoricProcessInstance resultInstance = query.singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance2.getId(), resultInstance.getId());
// Test NOT_EQUAL, should return only 1 resultInstance
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueNotEquals("stringVar", "abcdef").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
// Test GREATER_THAN, should return only matching 'azerty'
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueGreaterThan("stringVar", "abcdef").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueGreaterThan("stringVar", "z").singleResult();
assertNull(resultInstance);
// Test GREATER_THAN_OR_EQUAL, should return 3 results
assertEquals(3, historyService.createHistoricProcessInstanceQuery().variableValueGreaterThanOrEqual("stringVar", "abcdef").count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().variableValueGreaterThanOrEqual("stringVar", "z").count());
// Test LESS_THAN, should return 2 results
processInstances = historyService.createHistoricProcessInstanceQuery().variableValueLessThan("stringVar", "abcdeg").list();
assertEquals(2, processInstances.size());
List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().variableValueLessThan("stringVar", "abcdef").count());
assertEquals(3, historyService.createHistoricProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "z").count());
// Test LESS_THAN_OR_EQUAL
processInstances = historyService.createHistoricProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "abcdef").list();
assertEquals(2, processInstances.size());
expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
assertEquals(3, historyService.createHistoricProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "z").count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "aa").count());
// Test LIKE
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueLike("stringVar", "azert%").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueLike("stringVar", "%y").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueLike("stringVar", "%zer%").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
assertEquals(3, historyService.createHistoricProcessInstanceQuery().variableValueLike("stringVar", "a%").count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().variableValueLike("stringVar", "%x%").count());
// Test value-only matching
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueEquals("azerty").singleResult();
assertNotNull(resultInstance);
assertEquals(processInstance3.getId(), resultInstance.getId());
processInstances = historyService.createHistoricProcessInstanceQuery().variableValueEquals("abcdef").list();
assertEquals(2, processInstances.size());
expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
resultInstance = historyService.createHistoricProcessInstanceQuery().variableValueEquals("notmatchinganyvalues").singleResult();
assertNull(resultInstance);
historyService.deleteHistoricProcessInstance(processInstance1.getId());
historyService.deleteHistoricProcessInstance(processInstance2.getId());
historyService.deleteHistoricProcessInstance(processInstance3.getId());
}
use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.
the class HistoryServiceTest method testHistoricProcessInstanceQueryByDeploymentId.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricProcessInstanceQueryByDeploymentId() {
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());
HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentId(deployment.getId());
assertEquals(5, processInstanceQuery.count());
assertEquals(deployment.getId(), processInstanceQuery.list().get(0).getDeploymentId());
List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
assertNotNull(processInstances);
assertEquals(5, processInstances.size());
processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentId("invalid");
assertEquals(0, processInstanceQuery.count());
}
Aggregations