Search in sources :

Example 21 with SuspendedEntityInteractionException

use of org.camunda.bpm.engine.SuspendedEntityInteractionException in project camunda-bpm-platform by camunda.

the class ProcessDefinitionSuspensionTest method testStartAfterActivityForSuspendProcessDefinition.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testStartAfterActivityForSuspendProcessDefinition() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    // start process instance
    runtimeService.startProcessInstanceById(processDefinition.getId());
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    // Suspend process definition
    repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, null);
    // try to start after activity for suspended processDefinition
    try {
        runtimeService.createProcessInstanceModification(processInstance.getId()).startAfterActivity("theTask").execute();
        fail("Exception is expected but not thrown");
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresentIgnoreCase("is suspended", e.getMessage());
    }
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 22 with SuspendedEntityInteractionException

use of org.camunda.bpm.engine.SuspendedEntityInteractionException in project camunda-bpm-platform by camunda.

the class ProcessDefinitionSuspensionTest method testSuspendProcessInstancesDuringProcessDefinitionSuspend.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testSuspendProcessInstancesDuringProcessDefinitionSuspend() {
    int nrOfProcessInstances = 9;
    // Fire up a few processes for the deployed process definition
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    for (int i = 0; i < nrOfProcessInstances; i++) {
        runtimeService.startProcessInstanceByKey(processDefinition.getKey());
    }
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
    // Suspend process definitions and include process instances
    repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, null);
    // Verify all process instances are also suspended
    for (ProcessInstance processInstance : runtimeService.createProcessInstanceQuery().list()) {
        assertTrue(processInstance.isSuspended());
    }
    // Verify all process instances can't be continued
    for (Task task : taskService.createTaskQuery().list()) {
        try {
            assertTrue(task.isSuspended());
            taskService.complete(task.getId());
            fail("A suspended task shouldn't be able to be continued");
        } catch (SuspendedEntityInteractionException e) {
            assertTextPresentIgnoreCase("is suspended", e.getMessage());
        }
    }
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().active().count());
    // Activate the process definition again
    repositoryService.activateProcessDefinitionById(processDefinition.getId(), true, null);
    // Verify that all process instances can be completed
    for (Task task : taskService.createTaskQuery().list()) {
        taskService.complete(task.getId());
    }
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().active().count());
}
Also used : Task(org.camunda.bpm.engine.task.Task) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 23 with SuspendedEntityInteractionException

use of org.camunda.bpm.engine.SuspendedEntityInteractionException in project camunda-bpm-platform by camunda.

the class ProcessDefinitionSuspensionTest method testDelayedSuspendProcessDefinition.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedSuspendProcessDefinition() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    Date startTime = new Date();
    ClockUtil.setCurrentTime(startTime);
    // Suspend process definition in one week from now
    long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000);
    repositoryService.suspendProcessDefinitionById(processDefinition.getId(), false, new Date(oneWeekFromStartTime));
    // Verify we can just start process instances
    runtimeService.startProcessInstanceById(processDefinition.getId());
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
    // execute job
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    // Try to start process instance. It should fail now.
    try {
        runtimeService.startProcessInstanceById(processDefinition.getId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresentIgnoreCase("suspended", e.getMessage());
    }
    assertEquals(1, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Activate again
    repositoryService.activateProcessDefinitionById(processDefinition.getId());
    runtimeService.startProcessInstanceById(processDefinition.getId());
    assertEquals(2, runtimeService.createProcessInstanceQuery().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 24 with SuspendedEntityInteractionException

use of org.camunda.bpm.engine.SuspendedEntityInteractionException in project camunda-bpm-platform by camunda.

the class ProcessDefinitionSuspensionTest method testDelayedSuspendProcessDefinitionIncludingProcessInstances.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedSuspendProcessDefinitionIncludingProcessInstances() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    Date startTime = new Date();
    ClockUtil.setCurrentTime(startTime);
    // Start some process instances
    int nrOfProcessInstances = 30;
    for (int i = 0; i < nrOfProcessInstances; i++) {
        runtimeService.startProcessInstanceById(processDefinition.getId());
    }
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Suspend process definition in one week from now
    long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000);
    repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, new Date(oneWeekFromStartTime));
    // Verify we can start process instances
    runtimeService.startProcessInstanceById(processDefinition.getId());
    nrOfProcessInstances = nrOfProcessInstances + 1;
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    // execute job
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    // Try to start process instance. It should fail now.
    try {
        runtimeService.startProcessInstanceById(processDefinition.getId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        assertTextPresentIgnoreCase("suspended", e.getMessage());
    }
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Activate again
    repositoryService.activateProcessDefinitionById(processDefinition.getId(), true, null);
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 25 with SuspendedEntityInteractionException

use of org.camunda.bpm.engine.SuspendedEntityInteractionException in project camunda-bpm-platform by camunda.

the class ProcessDefinitionSuspensionTest method testDelayedActivateProcessDefinition.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedActivateProcessDefinition() {
    Date startTime = new Date();
    ClockUtil.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 (SuspendedEntityInteractionException 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));
    // execute job
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    // 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 : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

SuspendedEntityInteractionException (org.camunda.bpm.engine.SuspendedEntityInteractionException)39 Deployment (org.camunda.bpm.engine.test.Deployment)34 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)30 Task (org.camunda.bpm.engine.task.Task)16 ExternalTask (org.camunda.bpm.engine.externaltask.ExternalTask)15 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)8 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)5 Test (org.junit.Test)5 Date (java.util.Date)3 HashMap (java.util.HashMap)3 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)3 Job (org.camunda.bpm.engine.runtime.Job)3