Search in sources :

Example 56 with ProcessDefinition

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

the class ProcessInstanceSuspensionTest method testJobNotExecutedAfterProcessInstanceSuspendByProcessDefinitionKey.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.testJobNotExecutedAfterProcessInstanceSuspend.bpmn20.xml" })
public void testJobNotExecutedAfterProcessInstanceSuspendByProcessDefinitionKey() {
    Date now = new Date();
    ClockUtil.setCurrentTime(now);
    // Suspending the process instance should also stop the execution of jobs for that process instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceById(processDefinition.getId());
    assertEquals(1, managementService.createJobQuery().count());
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    assertEquals(1, managementService.createJobQuery().count());
    // The jobs should not be executed now
    // Timer is set to fire on 5 minutes
    ClockUtil.setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000)));
    assertEquals(0, managementService.createJobQuery().executable().count());
    // Activation of the process instance should now allow for job execution
    runtimeService.activateProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    assertEquals(1, managementService.createJobQuery().executable().count());
    managementService.executeJob(managementService.createJobQuery().singleResult().getId());
    assertEquals(0, managementService.createJobQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 57 with ProcessDefinition

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

the class ProcessInstanceSuspensionTest method testMICallActivityReturnAfterProcessInstanceSuspendByProcessDefinitionKey.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.callMISimpleProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/subProcess.bpmn20.xml" })
public void testMICallActivityReturnAfterProcessInstanceSuspendByProcessDefinitionKey() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("callMISimpleProcess").singleResult();
    runtimeService.startProcessInstanceByKey("callMISimpleProcess");
    runtimeService.suspendProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    List<Task> tasks = taskService.createTaskQuery().list();
    Task task1 = tasks.get(0);
    Task task2 = tasks.get(1);
    try {
        taskService.complete(task1.getId());
        fail("this should not be successful, as the execution of a suspended instance is resumed");
    } catch (SuspendedEntityInteractionException e) {
    // this is expected to fail
    }
    try {
        taskService.complete(task2.getId());
        fail("this should not be successful, as the execution of a suspended instance is resumed");
    } catch (SuspendedEntityInteractionException e) {
    // this is expected to fail
    }
    // should be successful after reactivation
    runtimeService.activateProcessInstanceByProcessDefinitionKey(processDefinition.getKey());
    taskService.complete(task1.getId());
    taskService.complete(task2.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Task(org.camunda.bpm.engine.task.Task) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 58 with ProcessDefinition

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

the class ProcessInstanceSuspensionTest method testTaskLifecycleOperationsFailAfterProcessInstanceSuspendByProcessDefinitionId.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskLifecycleOperationsFailAfterProcessInstanceSuspendByProcessDefinitionId() {
    // Start a new process instance with one task
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    final Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    // Suspend the process instance
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinition.getId());
    // Completing the task should fail
    try {
        taskService.complete(task.getId());
        fail("It is not allowed to complete a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Claiming the task should fail
    try {
        taskService.claim(task.getId(), "jos");
        fail("It is not allowed to claim a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Adding candidate groups on the task should fail
    try {
        taskService.addCandidateGroup(task.getId(), "blahGroup");
        fail("It is not allowed to add a candidate group on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Adding candidate users on the task should fail
    try {
        taskService.addCandidateUser(task.getId(), "blahUser");
        fail("It is not allowed to add a candidate user on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Adding group identity links on the task should fail
    try {
        taskService.addGroupIdentityLink(task.getId(), "blahGroup", IdentityLinkType.CANDIDATE);
        fail("It is not allowed to add a candidate user on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Adding an identity link on the task should fail
    try {
        taskService.addUserIdentityLink(task.getId(), "blahUser", IdentityLinkType.OWNER);
        fail("It is not allowed to add an identityLink on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Set an assignee on the task should fail
    try {
        taskService.setAssignee(task.getId(), "mispiggy");
        fail("It is not allowed to set an assignee on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Set an owner on the task should fail
    try {
        taskService.setOwner(task.getId(), "kermit");
        fail("It is not allowed to set an owner on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Removing candidate groups on the task should fail
    try {
        taskService.deleteCandidateGroup(task.getId(), "blahGroup");
        fail("It is not allowed to remove a candidate group on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Removing candidate users on the task should fail
    try {
        taskService.deleteCandidateUser(task.getId(), "blahUser");
        fail("It is not allowed to remove a candidate user on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Removing group identity links on the task should fail
    try {
        taskService.deleteGroupIdentityLink(task.getId(), "blahGroup", IdentityLinkType.CANDIDATE);
        fail("It is not allowed to remove a candidate user on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
    // Removing an identity link on the task should fail
    try {
        taskService.deleteUserIdentityLink(task.getId(), "blahUser", IdentityLinkType.OWNER);
        fail("It is not allowed to remove an identityLink on a task of a suspended process instance");
    } catch (SuspendedEntityInteractionException e) {
    // This is good
    }
}
Also used : ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Task(org.camunda.bpm.engine.task.Task) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 59 with ProcessDefinition

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

the class ProcessInstanceSuspensionTest method testProcessInstanceSignalFailAfterSuspendByProcessDefinitionId.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceSignalFailAfterSuspendByProcessDefinitionId() {
    // Suspend process instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinition.getId());
    try {
        runtimeService.signal(processInstance.getId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        // This is expected
        assertTextPresent("is suspended", e.getMessage());
        assertTrue(e instanceof BadUserRequestException);
    }
    try {
        runtimeService.signal(processInstance.getId(), new HashMap<String, Object>());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        // This is expected
        assertTextPresent("is suspended", e.getMessage());
        assertTrue(e instanceof BadUserRequestException);
    }
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 60 with ProcessDefinition

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

the class ProcessInstanceSuspensionTest method testMessageEventReceiveFailAfterSuspend.

@Deployment
public void testMessageEventReceiveFailAfterSuspend() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    EventSubscription subscription = runtimeService.createEventSubscriptionQuery().singleResult();
    try {
        runtimeService.messageEventReceived("someMessage", subscription.getExecutionId());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        // This is expected
        assertTextPresent("is suspended", e.getMessage());
    }
    try {
        runtimeService.messageEventReceived("someMessage", subscription.getExecutionId(), new HashMap<String, Object>());
        fail();
    } catch (SuspendedEntityInteractionException e) {
        // This is expected
        assertTextPresent("is suspended", e.getMessage());
    }
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) SuspendedEntityInteractionException(org.camunda.bpm.engine.SuspendedEntityInteractionException) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)1093 Test (org.junit.Test)761 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)474 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)415 Deployment (org.camunda.bpm.engine.test.Deployment)230 Job (org.camunda.bpm.engine.runtime.Job)148 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)119 Batch (org.camunda.bpm.engine.batch.Batch)95 Task (org.camunda.bpm.engine.task.Task)87 HashMap (java.util.HashMap)77 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)64 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)55 JobDefinitionQuery (org.camunda.bpm.engine.management.JobDefinitionQuery)54 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)47 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)41 MigrationPlanValidationException (org.camunda.bpm.engine.migration.MigrationPlanValidationException)40 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)39 Date (java.util.Date)38 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)35