Search in sources :

Example 11 with CaseExecution

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

the class CaseServiceHumanTaskTest method testCompleteNonFluent.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/twoTaskCase.cmmn" })
public void testCompleteNonFluent() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    caseService.withCaseDefinition(caseDefinitionId).create().getId();
    String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    caseService.withCaseExecution(caseExecutionId).manualStart();
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    // when
    caseService.completeCaseExecution(caseExecutionId);
    // then
    // the task has been completed and has been deleted
    task = taskService.createTaskQuery().singleResult();
    assertNull(task);
    // the corresponding case execution has been also
    // deleted and completed
    CaseExecution caseExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNull(caseExecution);
    // the case instance is still active
    CaseInstance caseInstance = caseService.createCaseInstanceQuery().active().singleResult();
    assertNotNull(caseInstance);
    assertTrue(caseInstance.isActive());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) Task(org.camunda.bpm.engine.task.Task) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 12 with CaseExecution

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

the class CaseServiceHumanTaskTest method testTerminateNonActiveHumanTask.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCaseWithManualActivation.cmmn" })
public void testTerminateNonActiveHumanTask() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    caseService.withCaseDefinition(caseDefinitionId).create();
    CaseExecution taskExecution = queryCaseExecutionByActivityId("PI_HumanTask_1");
    try {
        // when
        caseService.terminateCaseExecution(taskExecution.getId());
        fail("It should not be possible to terminate a task.");
    } catch (NotAllowedException e) {
        boolean result = e.getMessage().contains("The case execution must be in state 'active' to terminate");
        assertTrue(result);
    }
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) NotAllowedException(org.camunda.bpm.engine.exception.NotAllowedException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 13 with CaseExecution

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

the class CaseServiceHumanTaskTest method testDisableAnEnabledHumanTask.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/twoTaskCase.cmmn" })
public void testDisableAnEnabledHumanTask() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance and the containing
    // human task is enabled
    caseService.withCaseDefinition(caseDefinitionId).create();
    CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();
    String caseExecutionId = caseExecutionQuery.activityId("PI_HumanTask_1").singleResult().getId();
    // when
    caseService.withCaseExecution(caseExecutionId).disable();
    // then
    CaseExecution caseExecution = caseExecutionQuery.singleResult();
    // the human task is disabled
    assertTrue(caseExecution.isDisabled());
    assertFalse(caseExecution.isActive());
    assertFalse(caseExecution.isEnabled());
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) CaseExecutionQuery(org.camunda.bpm.engine.runtime.CaseExecutionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 14 with CaseExecution

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

the class CaseServiceHumanTaskTest method testManualStartNonFluent.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testManualStartNonFluent() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    caseService.withCaseDefinition(caseDefinitionId).create();
    CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();
    // an enabled child case execution of
    // the case instance
    String caseExecutionId = caseExecutionQuery.activityId("PI_HumanTask_1").singleResult().getId();
    // then
    // the child case execution is active...
    CaseExecution caseExecution = caseExecutionQuery.singleResult();
    assertTrue(caseExecution.isActive());
    // ... and not enabled
    assertFalse(caseExecution.isEnabled());
    // there exists a task
    Task task = taskService.createTaskQuery().caseExecutionId(caseExecutionId).singleResult();
    assertNotNull(task);
}
Also used : Task(org.camunda.bpm.engine.task.Task) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) CaseExecutionQuery(org.camunda.bpm.engine.runtime.CaseExecutionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 15 with CaseExecution

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

the class CaseServiceHumanTaskTest method testManualStartWithLocalVariables.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCaseWithManualActivation.cmmn" })
public void testManualStartWithLocalVariables() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    String caseInstanceId = caseService.withCaseDefinition(caseDefinitionId).create().getId();
    CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();
    // an enabled child case execution of
    // the case instance
    String caseExecutionId = caseExecutionQuery.activityId("PI_HumanTask_1").singleResult().getId();
    // variables
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariableName", "abc");
    variables.put("anotherVariableName", 999);
    // when
    // activate child case execution
    caseService.withCaseExecution(caseExecutionId).setVariablesLocal(variables).manualStart();
    // then
    // the child case execution is active...
    CaseExecution caseExecution = caseExecutionQuery.singleResult();
    assertTrue(caseExecution.isActive());
    // ... and not enabled
    assertFalse(caseExecution.isEnabled());
    // there exists a task
    Task task = taskService.createTaskQuery().caseExecutionId(caseExecutionId).singleResult();
    assertNotNull(task);
    // the case instance has two variables:
    // - aVariableName
    // - anotherVariableName
    List<VariableInstance> result = runtimeService.createVariableInstanceQuery().list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    for (VariableInstance variable : result) {
        assertEquals(caseExecutionId, variable.getCaseExecutionId());
        assertEquals(caseInstanceId, variable.getCaseInstanceId());
        if (variable.getName().equals("aVariableName")) {
            assertEquals("aVariableName", variable.getName());
            assertEquals("abc", variable.getValue());
        } else if (variable.getName().equals("anotherVariableName")) {
            assertEquals("anotherVariableName", variable.getName());
            assertEquals(999, variable.getValue());
        } else {
            fail("Unexpected variable: " + variable.getName());
        }
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) HashMap(java.util.HashMap) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) CaseExecutionQuery(org.camunda.bpm.engine.runtime.CaseExecutionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)280 Deployment (org.camunda.bpm.engine.test.Deployment)246 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)61 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)48 Task (org.camunda.bpm.engine.task.Task)28 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)27 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)18 Test (org.junit.Test)17 HashMap (java.util.HashMap)13 HistoricCaseActivityInstance (org.camunda.bpm.engine.history.HistoricCaseActivityInstance)11 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)11 NotAllowedException (org.camunda.bpm.engine.exception.NotAllowedException)9 VariableMap (org.camunda.bpm.engine.variable.VariableMap)7 DelegateCaseExecution (org.camunda.bpm.engine.delegate.DelegateCaseExecution)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)4 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)4 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)3 ArrayList (java.util.ArrayList)2 CaseService (org.camunda.bpm.engine.CaseService)2