use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessInstanceSuspensionTest method testJobNotExecutedAfterProcessInstanceSuspend.
@Deployment
public void testJobNotExecutedAfterProcessInstanceSuspend() {
Date now = new Date();
processEngineConfiguration.getClock().setCurrentTime(now);
// Suspending the process instance should also stop the execution of jobs for that process instance
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
assertEquals(1, managementService.createJobQuery().count());
runtimeService.suspendProcessInstanceById(processInstance.getId());
assertEquals(1, managementService.createJobQuery().count());
// The jobs should not be executed now
// Timer is set to fire on 5 minutes
processEngineConfiguration.getClock().setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000)));
Job job = managementService.createJobQuery().executable().singleResult();
assertNull(job);
assertEquals(1, managementService.createJobQuery().count());
// Activation of the process instance should now allow for job execution
runtimeService.activateProcessInstanceById(processInstance.getId());
waitForJobExecutorToProcessAllJobs(1000L, 100L);
assertEquals(0, managementService.createJobQuery().count());
assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessInstanceSuspensionTest method testCannotActivateActiveProcessInstance.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testCannotActivateActiveProcessInstance() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
runtimeService.startProcessInstanceByKey(processDefinition.getKey());
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
assertFalse(processInstance.isSuspended());
try {
//activate
runtimeService.activateProcessInstanceById(processInstance.getId());
fail("Expected activiti exception");
} catch (ActivitiException e) {
// expected
}
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class RepositoryServiceTest method testDeleteDeploymentWithRunningInstances.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testDeleteDeploymentWithRunningInstances() {
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
assertEquals(1, processDefinitions.size());
ProcessDefinition processDefinition = processDefinitions.get(0);
runtimeService.startProcessInstanceById(processDefinition.getId());
// Try to delete the deployment
try {
repositoryService.deleteDeployment(processDefinition.getDeploymentId());
fail("Exception expected");
} catch (RuntimeException ae) {
// Exception expected when deleting deployment with running process
}
}
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());
}
Aggregations