Search in sources :

Example 26 with ProcessDefinition

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

Example 27 with ProcessDefinition

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

Example 28 with ProcessDefinition

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

Example 29 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class ProcessDefinitionSuspensionTest method testContinueProcessAfterProcessDefinitionSuspend.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testContinueProcessAfterProcessDefinitionSuspend() {
    // Start Process Instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    // Verify one task is created
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    // Suspend process definition
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    // Process should be able to continue
    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 30 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class ProcessDefinitionSuspensionTest method testDelayedActivateProcessDefinition.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedActivateProcessDefinition() {
    Date startTime = new Date();
    processEngineConfiguration.getClock().setCurrentTime(startTime);
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    // Try to start process instance. It should fail now.
    try {
        runtimeService.startProcessInstanceById(processDefinition.getId());
        fail();
    } catch (ActivitiException e) {
        assertTextPresentIgnoreCase("suspended", e.getMessage());
    }
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Activate in a day from now
    long oneDayFromStart = startTime.getTime() + (24 * 60 * 60 * 1000);
    repositoryService.activateProcessDefinitionById(processDefinition.getId(), false, new Date(oneDayFromStart));
    // Move clock two days and let job executor run
    long twoDaysFromStart = startTime.getTime() + (2 * 24 * 60 * 60 * 1000);
    processEngineConfiguration.getClock().setCurrentTime(new Date(twoDaysFromStart));
    waitForJobExecutorToProcessAllJobs(5000L, 50L);
    // Starting a process instance should now succeed
    runtimeService.startProcessInstanceById(processDefinition.getId());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Date(java.util.Date) 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