Search in sources :

Example 71 with CaseExecution

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

the class VariableListenerTest method testVariableListenerByDelegateExpression.

@Deployment
public void testVariableListenerByDelegateExpression() {
    beans.put("listener", new LogVariableListener());
    caseService.withCaseDefinitionByKey("case").create();
    CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNotNull(taskExecution);
    // when i create a variable on the human task
    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();
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 72 with CaseExecution

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

the class VariableListenerTest method testVariableListenerByExpression.

@Deployment
public void testVariableListenerByExpression() {
    SimpleBean simpleBean = new SimpleBean();
    beans.put("bean", simpleBean);
    caseService.withCaseDefinitionByKey("case").create();
    CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNotNull(taskExecution);
    // when i create a variable on the human task
    caseService.withCaseExecution(taskExecution.getId()).setVariableLocal("aTaskVariable", "aTaskValue").execute();
    // then the listener is invoked
    assertTrue(simpleBean.wasInvoked());
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 73 with CaseExecution

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

the class VariableListenerTest method testTwoListenersOnSameScope.

@Deployment
public void testTwoListenersOnSameScope() {
    caseService.withCaseDefinitionByKey("case").create();
    CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNotNull(taskExecution);
    // when i set a variable
    caseService.withCaseExecution(taskExecution.getId()).setVariableLocal("testVariable", "value1").execute();
    // then both listeners are invoked
    assertEquals(1, LogVariableListener.getInvocations().size());
    DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.CREATE).name("testVariable").value("value1").matches(LogVariableListener.getInvocations().get(0));
    assertEquals(1, LogAndUpdateVariableListener.getInvocations().size());
    DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.CREATE).name("testVariable").value("value1").matches(LogAndUpdateVariableListener.getInvocations().get(0));
    LogVariableListener.reset();
    LogAndUpdateVariableListener.reset();
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 74 with CaseExecution

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

the class VariableListenerTest method testCreateEventListenerByClass.

@Deployment
public void testCreateEventListenerByClass() {
    caseService.withCaseDefinitionByKey("case").create();
    CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNotNull(taskExecution);
    // when i create a variable on the human task
    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 not invoked
    assertTrue(LogVariableListener.getInvocations().isEmpty());
    // when i remove the variable from the human task
    caseService.withCaseExecution(taskExecution.getId()).removeVariable("aTaskVariable").execute();
    // then the listener is not invoked
    assertTrue(LogVariableListener.getInvocations().isEmpty());
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 75 with CaseExecution

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

the class VariableListenerTest method testListenerDoesNotImplementInterface.

@Deployment
public void testListenerDoesNotImplementInterface() {
    caseService.withCaseDefinitionByKey("case").create();
    CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNotNull(taskExecution);
    try {
        caseService.withCaseExecution(taskExecution.getId()).setVariableLocal("aTaskVariable", "aTaskValue").execute();
        fail("expected exception during variable listener invocation");
    } catch (ProcessEngineException e) {
    // happy path
    }
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) 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