use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryEqualsIgnoreCase.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryEqualsIgnoreCase() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("mixed", "AbCdEfG");
vars.put("lower", "ABCDEFG");
vars.put("upper", "abcdefg");
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Execution execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("mixed", "abcdefg").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("lower", "abcdefg").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("upper", "abcdefg").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
// Pass in non-lower-case string
execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("upper", "ABCdefg").singleResult();
assertNotNull(execution);
assertEquals(processInstance1.getId(), execution.getId());
// Pass in null-value, should cause exception
try {
execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("upper", null).singleResult();
fail("Exception expected");
} catch (ActivitiIllegalArgumentException ae) {
assertEquals("value is null", ae.getMessage());
}
// Pass in null name, should cause exception
try {
execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase(null, "abcdefg").singleResult();
fail("Exception expected");
} catch (ActivitiIllegalArgumentException ae) {
assertEquals("name is null", ae.getMessage());
}
// Test NOT equals
execution = runtimeService.createExecutionQuery().variableValueNotEqualsIgnoreCase("upper", "UIOP").singleResult();
assertNotNull(execution);
// Should return result when using "ABCdefg" case-insensitive while normal not-equals won't
execution = runtimeService.createExecutionQuery().variableValueNotEqualsIgnoreCase("upper", "ABCdefg").singleResult();
assertNull(execution);
execution = runtimeService.createExecutionQuery().variableValueNotEquals("upper", "ABCdefg").singleResult();
assertNotNull(execution);
// Pass in null-value, should cause exception
try {
execution = runtimeService.createExecutionQuery().variableValueNotEqualsIgnoreCase("upper", null).singleResult();
fail("Exception expected");
} catch (ActivitiIllegalArgumentException ae) {
assertEquals("value is null", ae.getMessage());
}
// Pass in null name, should cause exception
try {
execution = runtimeService.createExecutionQuery().variableValueNotEqualsIgnoreCase(null, "abcdefg").singleResult();
fail("Exception expected");
} catch (ActivitiIllegalArgumentException ae) {
assertEquals("name is null", ae.getMessage());
}
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class RuntimeServiceTest method testFindActiveActivityIds.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testFindActiveActivityIds() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
List<String> activities = runtimeService.getActiveActivityIds(processInstance.getId());
assertNotNull(activities);
assertEquals(1, activities.size());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class RuntimeServiceTest method testStartProcessInstanceByProcessInstanceBuilder.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testStartProcessInstanceByProcessInstanceBuilder() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
// by key
ProcessInstance processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").businessKey("123").start();
assertNotNull(processInstance);
assertEquals("123", processInstance.getBusinessKey());
assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
// by key, with processInstance name with variables
processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").businessKey("456").addVariable("var", "value").processInstanceName("processName1").start();
assertNotNull(processInstance);
assertEquals(2, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
assertEquals("processName1", processInstance.getName());
assertEquals("456", processInstance.getBusinessKey());
assertEquals("value", runtimeService.getVariable(processInstance.getId(), "var"));
processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
// by id
processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("789").start();
assertNotNull(processInstance);
assertEquals(3, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
assertEquals("789", processInstance.getBusinessKey());
processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
// by id with variables
processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("101123").addVariable("var", "value2").start();
assertNotNull(processInstance);
assertEquals(4, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
assertEquals("value2", runtimeService.getVariable(processInstance.getId(), "var"));
assertEquals("101123", processInstance.getBusinessKey());
processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
// by id and processInstance name
processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("101124").processInstanceName("processName2").start();
assertNotNull(processInstance);
assertEquals(5, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
assertEquals("processName2", processInstance.getName());
assertEquals("101124", processInstance.getBusinessKey());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class RuntimeServiceTest method testRemoveVariableLocal.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testRemoveVariableLocal() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("variable1", "value1");
vars.put("variable2", "value2");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
runtimeService.removeVariableLocal(processInstance.getId(), "variable1");
assertNull(runtimeService.getVariable(processInstance.getId(), "variable1"));
assertNull(runtimeService.getVariableLocal(processInstance.getId(), "variable1"));
assertEquals("value2", runtimeService.getVariable(processInstance.getId(), "variable2"));
checkHistoricVariableUpdateEntity("variable1", processInstance.getId());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class RuntimeServiceTest method testSetProcessInstanceName.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSetProcessInstanceName() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
assertNull(processInstance.getName());
// Set the name
runtimeService.setProcessInstanceName(processInstance.getId(), "New name");
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertEquals("New name", processInstance.getName());
// Set the name to null
runtimeService.setProcessInstanceName(processInstance.getId(), null);
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertNull(processInstance.getName());
// Set name for unexisting process instance, should fail
try {
runtimeService.setProcessInstanceName("unexisting", null);
fail("Exception excpected");
} catch (ActivitiObjectNotFoundException aonfe) {
assertEquals(ProcessInstance.class, aonfe.getObjectClass());
}
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertNull(processInstance.getName());
// Set name for suspended process instance, should fail
runtimeService.suspendProcessInstanceById(processInstance.getId());
try {
runtimeService.setProcessInstanceName(processInstance.getId(), null);
fail("Exception excpected");
} catch (ActivitiException ae) {
assertEquals("process instance " + processInstance.getId() + " is suspended, cannot set name", ae.getMessage());
}
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(processInstance);
assertNull(processInstance.getName());
}
Aggregations