Search in sources :

Example 6 with DelegateExecution

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

the class ProcessApplicationEventListenerTest method testIntermediateTimerEvent.

@Deployment
public void testIntermediateTimerEvent() {
    // given
    final List<String> timerEvents = new ArrayList<String>();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution delegateExecution) {
                    String currentActivityId = delegateExecution.getCurrentActivityId();
                    String eventName = delegateExecution.getEventName();
                    if ("timer".equals(currentActivityId) && (ExecutionListener.EVENTNAME_START.equals(eventName) || ExecutionListener.EVENTNAME_END.equals(eventName))) {
                        timerEvents.add(delegateExecution.getEventName());
                    }
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // when
    runtimeService.startProcessInstanceByKey("process");
    String jobId = managementService.createJobQuery().singleResult().getId();
    managementService.executeJob(jobId);
    // then
    assertEquals(2, timerEvents.size());
    // "start" event listener
    assertEquals(ExecutionListener.EVENTNAME_START, timerEvents.get(0));
    // "end" event listener
    assertEquals(ExecutionListener.EVENTNAME_END, timerEvents.get(1));
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) ArrayList(java.util.ArrayList) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 7 with DelegateExecution

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

the class ProcessApplicationEventListenerTest method testExecutionListenerWithTimerBoundaryEvent.

@Deployment
public void testExecutionListenerWithTimerBoundaryEvent() {
    final AtomicInteger eventCount = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    eventCount.incrementAndGet();
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // 1. (start)startEvent(end) -(take)-> (start)userTask(end) -(take)-> (start)endEvent(end) (8 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // complete task
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    assertEquals(10, eventCount.get());
    // reset counter
    eventCount.set(0);
    // 2. (start)startEvent(end) -(take)-> (start)userTask(end)/(start)timerBoundaryEvent(end) -(take)-> (start)endEvent(end) (10 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // fire timer event
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    assertEquals(12, eventCount.get());
}
Also used : DelegateTask(org.camunda.bpm.engine.delegate.DelegateTask) Task(org.camunda.bpm.engine.task.Task) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) Job(org.camunda.bpm.engine.runtime.Job) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with DelegateExecution

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

the class DelegateExecutionContextTest method testDelegateExecutionContext.

@Test
public void testDelegateExecutionContext() {
    // given
    ProcessDefinition definition = testHelper.deployAndGetDefinition(DELEGATION_PROCESS);
    // a process instance with a service task and a java delegate
    ProcessInstance instance = engineRule.getRuntimeService().startProcessInstanceById(definition.getId());
    // then delegation execution context is no more available
    DelegateExecution execution = DelegateExecutionContext.getCurrentDelegationExecution();
    assertNull(execution);
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) Test(org.junit.Test)

Example 9 with DelegateExecution

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

the class DelegateExecutionContextTest method testDelegateExecutionContextWithExecutionListener.

@Test
public void testDelegateExecutionContextWithExecutionListener() {
    // given
    ProcessDefinition definition = testHelper.deployAndGetDefinition(EXEUCTION_LISTENER_PROCESS);
    // a process instance with a service task and an execution listener
    engineRule.getRuntimeService().startProcessInstanceById(definition.getId());
    // then delegation execution context is no more available
    DelegateExecution execution = DelegateExecutionContext.getCurrentDelegationExecution();
    assertNull(execution);
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) Test(org.junit.Test)

Example 10 with DelegateExecution

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

the class DelegateExecutionHierarchyTest method testTaskInsideEmbeddedSubprocess.

public void testTaskInsideEmbeddedSubprocess() {
    deployment(Bpmn.createExecutableProcess("testProcess").startEvent().subProcess().embeddedSubProcess().startEvent().serviceTask().camundaClass(AssertingJavaDelegate.class.getName()).endEvent().subProcessDone().endEvent().done());
    AssertingJavaDelegate.addAsserts(new DelegateExecutionAsserter() {

        public void doAssert(DelegateExecution execution) {
            assertFalse(execution.equals(execution.getProcessInstance()));
            assertNull(execution.getSuperExecution());
        }
    });
    runtimeService.startProcessInstanceByKey("testProcess");
}
Also used : DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) DelegateExecutionAsserter(org.camunda.bpm.engine.test.api.delegate.AssertingJavaDelegate.DelegateExecutionAsserter)

Aggregations

DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)23 EmbeddedProcessApplication (org.camunda.bpm.application.impl.EmbeddedProcessApplication)9 ExecutionListener (org.camunda.bpm.engine.delegate.ExecutionListener)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 DelegateExecutionAsserter (org.camunda.bpm.engine.test.api.delegate.AssertingJavaDelegate.DelegateExecutionAsserter)6 DelegateTask (org.camunda.bpm.engine.delegate.DelegateTask)3 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 Task (org.camunda.bpm.engine.task.Task)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 IdentityService (org.camunda.bpm.engine.IdentityService)2 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)2 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)2 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ProcessApplicationUnavailableException (org.camunda.bpm.application.ProcessApplicationUnavailableException)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 HistoryLevel (org.camunda.bpm.engine.impl.history.HistoryLevel)1