Search in sources :

Example 56 with CaseInstance

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

the class VariableListenerTest method testDelegateInstanceIsProcessEngineAware.

@Deployment
public void testDelegateInstanceIsProcessEngineAware() {
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("case").create();
    assertFalse(ProcessEngineAwareListener.hasFoundValidRuntimeService());
    // when i set a variable that causes the listener to be notified
    caseService.withCaseExecution(caseInstance.getId()).setVariableLocal("aTaskVariable", "aTaskValue").execute();
    // then the listener is invoked and has found process engine services
    assertTrue(ProcessEngineAwareListener.hasFoundValidRuntimeService());
    ProcessEngineAwareListener.reset();
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 57 with CaseInstance

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

the class VariableListenerTest method testChildListenersNotInvoked.

@Deployment
public void testChildListenersNotInvoked() {
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("case").create();
    // when i set a variable on the parent scope
    caseService.withCaseExecution(caseInstance.getId()).setVariableLocal("aTaskVariable", "aTaskValue").execute();
    // then the listener is not invoked
    assertEquals(0, LogVariableListener.getInvocations().size());
    LogVariableListener.reset();
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 58 with CaseInstance

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

the class VariableListenerTest method testVariableListenerWithProcessTask.

@Deployment(resources = { "org/camunda/bpm/engine/test/cmmn/listener/VariableListenerTest.testVariableListenerWithProcessTask.cmmn", "org/camunda/bpm/engine/test/cmmn/listener/VariableListenerTest.testVariableListenerWithProcessTask.bpmn20.xml" })
public void testVariableListenerWithProcessTask() {
    CaseInstance caseInstance = caseService.createCaseInstanceByKey("case");
    CaseExecution processTask = caseService.createCaseExecutionQuery().activityId("PI_ProcessTask_1").singleResult();
    String processTaskId = processTask.getId();
    caseService.withCaseExecution(processTaskId).manualStart();
    // then the listener is invoked
    assertEquals(1, LogVariableListener.getInvocations().size());
    DelegateVariableInstanceSpec.fromCaseExecution(caseInstance).sourceExecution(processTask).event(VariableListener.CREATE).name("aVariable").value("aValue").matches(LogVariableListener.getInvocations().get(0));
    LogVariableListener.reset();
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 59 with CaseInstance

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

the class VariableListenerTest method testAnyEventListenerByClass.

@Deployment
public void testAnyEventListenerByClass() {
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("case").create();
    CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNotNull(taskExecution);
    // when i set a variable on a higher scope
    caseService.withCaseExecution(caseInstance.getId()).setVariable("anInstanceVariable", "anInstanceValue").execute();
    // then the listener is not invoked
    assertTrue(LogVariableListener.getInvocations().isEmpty());
    // when i set a variable on the human task (ie the source execution matters although the variable ends up in the same place)
    caseService.withCaseExecution(taskExecution.getId()).setVariableLocal("aTaskVariable", "aTaskValue").execute();
    // then the listener is invoked
    assertEquals(1, LogVariableListener.getInvocations().size());
    DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.CREATE).name("aTaskVariable").value("aTaskValue").matches(LogVariableListener.getInvocations().get(0));
    LogVariableListener.reset();
    // when i update the variable on the human task
    caseService.withCaseExecution(taskExecution.getId()).setVariable("aTaskVariable", "aNewTaskValue").execute();
    // then the listener is invoked
    assertEquals(1, LogVariableListener.getInvocations().size());
    DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.UPDATE).name("aTaskVariable").value("aNewTaskValue").activityInstanceId(taskExecution.getId()).matches(LogVariableListener.getInvocations().get(0));
    LogVariableListener.reset();
    // when i remove the variable from the human task
    caseService.withCaseExecution(taskExecution.getId()).removeVariable("aTaskVariable").execute();
    // then the listener is invoked
    assertEquals(1, LogVariableListener.getInvocations().size());
    DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.DELETE).name("aTaskVariable").value(null).activityInstanceId(taskExecution.getId()).matches(LogVariableListener.getInvocations().get(0));
    LogVariableListener.reset();
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 60 with CaseInstance

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

the class VariableListenerTest method testVariableListenerInvokedFromSourceScope.

@Deployment
public void testVariableListenerInvokedFromSourceScope() {
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("case").create();
    CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNotNull(taskExecution);
    // when i create a variable on the case instance
    caseService.withCaseExecution(caseInstance.getId()).setVariable("aTaskVariable", "aTaskValue").execute();
    // then the listener is not invoked
    assertEquals(0, LogVariableListener.getInvocations().size());
    // when i update the variable from the task execution
    caseService.withCaseExecution(taskExecution.getId()).setVariable("aTaskVariable", "aTaskValue").execute();
    // then the listener is invoked
    assertEquals(1, LogVariableListener.getInvocations().size());
    DelegateVariableInstanceSpec.fromCaseExecution(caseInstance).sourceExecution(taskExecution).event(VariableListener.UPDATE).name("aTaskVariable").value("aTaskValue").activityInstanceId(caseInstance.getId()).matches(LogVariableListener.getInvocations().get(0));
    LogVariableListener.reset();
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)183 Deployment (org.camunda.bpm.engine.test.Deployment)149 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)62 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)23 Test (org.junit.Test)21 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)18 Task (org.camunda.bpm.engine.task.Task)18 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)16 CaseDefinition (org.camunda.bpm.engine.repository.CaseDefinition)13 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)10 HashMap (java.util.HashMap)9 CaseInstanceQuery (org.camunda.bpm.engine.runtime.CaseInstanceQuery)9 ArrayList (java.util.ArrayList)6 CaseService (org.camunda.bpm.engine.CaseService)6 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)6 Date (java.util.Date)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 NotAllowedException (org.camunda.bpm.engine.exception.NotAllowedException)5 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)5 VariableMap (org.camunda.bpm.engine.variable.VariableMap)5