use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class RepositoryServiceTest method testGetBpmnModel.
@Deployment
public void testGetBpmnModel() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
// Some basic assertions
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
assertNotNull(bpmnModel);
assertEquals(1, bpmnModel.getProcesses().size());
assertTrue(!bpmnModel.getLocationMap().isEmpty());
assertTrue(!bpmnModel.getFlowLocationMap().isEmpty());
// Test the flow
org.activiti.bpmn.model.Process process = bpmnModel.getProcesses().get(0);
List<StartEvent> startEvents = process.findFlowElementsOfType(StartEvent.class);
assertEquals(1, startEvents.size());
StartEvent startEvent = startEvents.get(0);
assertEquals(1, startEvent.getOutgoingFlows().size());
assertEquals(0, startEvent.getIncomingFlows().size());
String nextElementId = startEvent.getOutgoingFlows().get(0).getTargetRef();
UserTask userTask = (UserTask) process.getFlowElement(nextElementId);
assertEquals("First Task", userTask.getName());
assertEquals(1, userTask.getOutgoingFlows().size());
assertEquals(1, userTask.getIncomingFlows().size());
nextElementId = userTask.getOutgoingFlows().get(0).getTargetRef();
ParallelGateway parallelGateway = (ParallelGateway) process.getFlowElement(nextElementId);
assertEquals(2, parallelGateway.getOutgoingFlows().size());
nextElementId = parallelGateway.getOutgoingFlows().get(0).getTargetRef();
assertEquals(1, parallelGateway.getIncomingFlows().size());
userTask = (UserTask) process.getFlowElement(nextElementId);
assertEquals(1, userTask.getOutgoingFlows().size());
nextElementId = userTask.getOutgoingFlows().get(0).getTargetRef();
parallelGateway = (ParallelGateway) process.getFlowElement(nextElementId);
assertEquals(1, parallelGateway.getOutgoingFlows().size());
assertEquals(2, parallelGateway.getIncomingFlows().size());
nextElementId = parallelGateway.getOutgoingFlows().get(0).getTargetRef();
EndEvent endEvent = (EndEvent) process.getFlowElement(nextElementId);
assertEquals(0, endEvent.getOutgoingFlows().size());
assertEquals(1, endEvent.getIncomingFlows().size());
}
use of org.activiti.engine.repository.ProcessDefinition 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.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessDefinitionSuspensionTest method testStartProcessInstanceForSuspendedProcessDefinition.
@Deployment(resources = { "org/activiti/engine/test/db/processOne.bpmn20.xml" })
public void testStartProcessInstanceForSuspendedProcessDefinition() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
// By id
try {
runtimeService.startProcessInstanceById(processDefinition.getId());
fail("Exception is expected but not thrown");
} catch (ActivitiException e) {
assertTextPresentIgnoreCase("cannot start process instance", e.getMessage());
}
// By Key
try {
runtimeService.startProcessInstanceByKey(processDefinition.getKey());
fail("Exception is expected but not thrown");
} catch (ActivitiException e) {
assertTextPresentIgnoreCase("cannot start process instance", e.getMessage());
}
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessDefinitionSuspensionTest method testProcessDefinitionActiveByDefault.
@Deployment(resources = { "org/activiti/engine/test/db/processOne.bpmn20.xml" })
public void testProcessDefinitionActiveByDefault() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertFalse(processDefinition.isSuspended());
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessDefinitionSuspensionTest method testQueryForActiveDefinitions.
@Deployment(resources = { "org/activiti/engine/test/db/processOne.bpmn20.xml", "org/activiti/engine/test/db/processTwo.bpmn20.xml" })
public void testQueryForActiveDefinitions() {
// default = all definitions
List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().list();
assertEquals(2, processDefinitionList.size());
assertEquals(2, repositoryService.createProcessDefinitionQuery().active().count());
ProcessDefinition processDefinition = processDefinitionList.get(0);
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
}
Aggregations