Search in sources :

Example 26 with EmbeddedProcessApplication

use of org.camunda.bpm.application.impl.EmbeddedProcessApplication in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListenerWithErrorBoundaryEvent.

@Deployment
public void testExecutionListenerWithErrorBoundaryEvent() {
    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)serviceTask(end) -(take)-> (start)endEvent(end) (8 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    assertEquals(10, eventCount.get());
    // reset counter
    eventCount.set(0);
    // 2. (start)startEvent(end) -(take)-> (start)serviceTask(end)/(start)errorBoundaryEvent(end) -(take)-> (start)endEvent(end) (10 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener", Collections.<String, Object>singletonMap("shouldThrowError", true));
    assertEquals(12, eventCount.get());
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 27 with EmbeddedProcessApplication

use of org.camunda.bpm.application.impl.EmbeddedProcessApplication in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testShouldNotIncrementExecutionListenerCountOnStartAndEndOfProcessInstance.

@Deployment(resources = { "org/camunda/bpm/application/impl/event/ProcessApplicationEventListenerTest.testExecutionListener.bpmn20.xml" })
public void testShouldNotIncrementExecutionListenerCountOnStartAndEndOfProcessInstance() {
    final AtomicInteger eventCount = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            // this process application returns an execution listener
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    if (!(((CoreExecution) execution).getEventSource() instanceof ProcessDefinitionEntity))
                        eventCount.incrementAndGet();
                }
            };
        }
    };
    // register app so that it receives events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // Start process instance.
    runtimeService.startProcessInstanceByKey("startToEnd");
    assertEquals(5, eventCount.get());
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 28 with EmbeddedProcessApplication

use of org.camunda.bpm.application.impl.EmbeddedProcessApplication in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListenerWithSignalBoundaryEvent.

@Deployment
public void testExecutionListenerWithSignalBoundaryEvent() {
    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)signalBoundaryEvent(end) -(take)-> (start)endEvent(end) (10 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // signal event
    runtimeService.signalEventReceived("signal");
    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) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 29 with EmbeddedProcessApplication

use of org.camunda.bpm.application.impl.EmbeddedProcessApplication in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListenerNull.

@Deployment(resources = { "org/camunda/bpm/application/impl/event/ProcessApplicationEventListenerTest.testExecutionListener.bpmn20.xml" })
public void testExecutionListenerNull() {
    // this test verifies that the process application can return a 'null'
    // execution listener
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication();
    // register app so that it receives events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // I can start a process event though the process app does not provide an
    // event listener.
    runtimeService.startProcessInstanceByKey("startToEnd");
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 30 with EmbeddedProcessApplication

use of org.camunda.bpm.application.impl.EmbeddedProcessApplication in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testShouldInvokeExecutionListenerOnStartAndEndOfProcessInstance.

@Deployment(resources = { "org/camunda/bpm/application/impl/event/ProcessApplicationEventListenerTest.testExecutionListener.bpmn20.xml" })
public void testShouldInvokeExecutionListenerOnStartAndEndOfProcessInstance() {
    final AtomicInteger processDefinitionEventCount = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            // this process application returns an execution listener
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    if (((CoreExecution) execution).getEventSource() instanceof ProcessDefinitionEntity)
                        processDefinitionEventCount.incrementAndGet();
                }
            };
        }
    };
    // register app so that it receives events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // Start process instance.
    runtimeService.startProcessInstanceByKey("startToEnd");
    // Start and end of the process
    assertEquals(2, processDefinitionEventCount.get());
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

EmbeddedProcessApplication (org.camunda.bpm.application.impl.EmbeddedProcessApplication)30 Deployment (org.camunda.bpm.engine.test.Deployment)11 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)9 ExecutionListener (org.camunda.bpm.engine.delegate.ExecutionListener)9 ProcessApplicationDeployment (org.camunda.bpm.engine.repository.ProcessApplicationDeployment)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)6 ScriptEngine (javax.script.ScriptEngine)5 ProcessApplicationRegistration (org.camunda.bpm.application.ProcessApplicationRegistration)4 DelegateTask (org.camunda.bpm.engine.delegate.DelegateTask)4 Task (org.camunda.bpm.engine.task.Task)4 ArrayList (java.util.ArrayList)3 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)3 Resource (org.camunda.bpm.engine.repository.Resource)3 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)3 List (java.util.List)2 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)2 TaskListener (org.camunda.bpm.engine.delegate.TaskListener)1 UserOperationLogEntry (org.camunda.bpm.engine.history.UserOperationLogEntry)1 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)1