Search in sources :

Example 21 with ProcessDefinition

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());
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 22 with ProcessDefinition

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
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 23 with ProcessDefinition

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
    }
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 24 with ProcessDefinition

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());
}
Also used : ParallelGateway(org.activiti.bpmn.model.ParallelGateway) StartEvent(org.activiti.bpmn.model.StartEvent) UserTask(org.activiti.bpmn.model.UserTask) EndEvent(org.activiti.bpmn.model.EndEvent) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel) Deployment(org.activiti.engine.test.Deployment)

Example 25 with ProcessDefinition

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());
}
Also used : ProcessInstanceBuilder(org.activiti.engine.runtime.ProcessInstanceBuilder) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)167 Deployment (org.activiti.engine.test.Deployment)82 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)37 ActivitiException (org.activiti.engine.ActivitiException)24 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)19 Task (org.activiti.engine.task.Task)16 ArrayList (java.util.ArrayList)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 Date (java.util.Date)10 HashMap (java.util.HashMap)9 HttpGet (org.apache.http.client.methods.HttpGet)9 StringEntity (org.apache.http.entity.StringEntity)9 BpmnModel (org.activiti.bpmn.model.BpmnModel)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 IdentityLink (org.activiti.engine.task.IdentityLink)7