use of org.camunda.bpm.application.impl.EmbeddedProcessApplication in project camunda-bpm-platform by camunda.
the class ProcessApplicationEventListenerTest method testExecutionListener.
@Deployment
public void testExecutionListener() {
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 {
eventCount.incrementAndGet();
}
};
}
};
// register app so that it is notified about events
managementService.registerProcessApplication(deploymentId, processApplication.getReference());
// start process instance
runtimeService.startProcessInstanceByKey("startToEnd");
// 7 events received
assertEquals(7, eventCount.get());
}
use of org.camunda.bpm.application.impl.EmbeddedProcessApplication in project camunda-bpm-platform by camunda.
the class ProcessApplicationEventListenerTest method testExecutionListenerWithMultiInstanceBody.
@Deployment
public void testExecutionListenerWithMultiInstanceBody() {
final AtomicInteger eventCountForMultiInstanceBody = new AtomicInteger();
EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {
public ExecutionListener getExecutionListener() {
return new ExecutionListener() {
public void notify(DelegateExecution execution) throws Exception {
if ("miTasks#multiInstanceBody".equals(execution.getCurrentActivityId()) && (ExecutionListener.EVENTNAME_START.equals(execution.getEventName()) || ExecutionListener.EVENTNAME_END.equals(execution.getEventName()))) {
eventCountForMultiInstanceBody.incrementAndGet();
}
}
};
}
};
// register app so that it is notified about events
managementService.registerProcessApplication(deploymentId, processApplication.getReference());
// start process instance
runtimeService.startProcessInstanceByKey("executionListener");
// complete task
List<Task> miTasks = taskService.createTaskQuery().list();
for (Task task : miTasks) {
taskService.complete(task.getId());
}
// 2 events are expected: one for mi body start; one for mi body end
assertEquals(2, eventCountForMultiInstanceBody.get());
}
use of org.camunda.bpm.application.impl.EmbeddedProcessApplication in project camunda-bpm-platform by camunda.
the class ProcessApplicationEventListenerTest method testIntermediateSignalEvent.
@Deployment
public void testIntermediateSignalEvent() {
// 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 ("signal".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");
runtimeService.signalEventReceived("abort");
// 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));
}
use of org.camunda.bpm.application.impl.EmbeddedProcessApplication 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));
}
use of org.camunda.bpm.application.impl.EmbeddedProcessApplication 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());
}
Aggregations