Search in sources :

Example 66 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testSuspendActivateProcessInstance.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testSuspendActivateProcessInstance() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertFalse(processInstance.isSuspended());
    //suspend
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertTrue(processInstance.isSuspended());
    //activate
    runtimeService.activateProcessInstanceById(processInstance.getId());
    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertFalse(processInstance.isSuspended());
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 67 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testTaskSuspendedAfterProcessInstanceSuspension.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testTaskSuspendedAfterProcessInstanceSuspension() {
    // Start Process Instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    // Suspense process instance
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    // Assert that the task is now also suspended
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        assertTrue(task.isSuspended());
    }
    // Activate process instance again
    runtimeService.activateProcessInstanceById(processInstance.getId());
    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        assertFalse(task.isSuspended());
    }
}
Also used : Task(org.activiti.engine.task.Task) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 68 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance 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 69 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceUpdateBusinessKeyTest method testUpdateExistingBusinessKey.

@Deployment
public void testUpdateExistingBusinessKey() {
    runtimeService.startProcessInstanceByKey("businessKeyProcess", "testKey");
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertEquals("testKey", processInstance.getBusinessKey());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
        assertEquals("testKey", historicProcessInstance.getBusinessKey());
    }
    runtimeService.updateBusinessKey(processInstance.getId(), "newKey");
    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertEquals("newKey", processInstance.getBusinessKey());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
        assertEquals("newKey", historicProcessInstance.getBusinessKey());
    }
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 70 with ProcessInstance

use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.

the class ProcessInstanceUpdateBusinessKeyTest method testProcessInstanceUpdateBusinessKey.

@Deployment
public void testProcessInstanceUpdateBusinessKey() {
    runtimeService.startProcessInstanceByKey("businessKeyProcess");
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertEquals("bzKey", processInstance.getBusinessKey());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
        assertEquals("bzKey", historicProcessInstance.getBusinessKey());
    }
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProcessInstance (org.activiti.engine.runtime.ProcessInstance)822 Deployment (org.activiti.engine.test.Deployment)708 Task (org.activiti.engine.task.Task)374 HashMap (java.util.HashMap)242 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)182 Execution (org.activiti.engine.runtime.Execution)76 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)64 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)57 Job (org.activiti.engine.runtime.Job)55 Date (java.util.Date)53 JsonNode (com.fasterxml.jackson.databind.JsonNode)49 Calendar (java.util.Calendar)48 ActivitiException (org.activiti.engine.ActivitiException)41 ArrayList (java.util.ArrayList)38 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)38 HttpGet (org.apache.http.client.methods.HttpGet)38 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)27 StringEntity (org.apache.http.entity.StringEntity)27 HttpPost (org.apache.http.client.methods.HttpPost)25 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)24