use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerDuplicatedRegister.
@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerDuplicatedRegister() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new AsyncWorkItemHandler(executorService, "org.jbpm.executor.commands.PrintOutCommand"));
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
manager.close();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerWthSecurityManager.
@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerWthSecurityManager() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new AsyncWorkItemHandler(executorService, "org.jbpm.executor.commands.PrintOutCommand"));
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
final AtomicBoolean active = new AtomicBoolean(false);
((InternalRuntimeManager) manager).setSecurityManager(new org.kie.internal.runtime.manager.SecurityManager() {
@Override
public void checkPermission() throws SecurityException {
if (active.get() && !AsyncExecutionMarker.isAsync()) {
throw new SecurityException("Only async allowed");
}
}
});
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
manager.disposeRuntimeEngine(runtime);
// activate security manager to enforce checks for async only
active.set(true);
countDownListener.waitTillCompleted();
// reset the security manager again...
active.set(false);
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessConditional.
@Test
public void testEventSubprocessConditional() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessConditional.bpmn2");
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(event.getNodeInstance().getId());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessConditional");
assertProcessInstanceActive(processInstance);
Person person = new Person();
person.setName("john");
ksession.insert(person);
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertThat(executednodes.size()).isEqualTo(1);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class IntermediateEventTest method runTestEventSubprocessSignal.
public void runTestEventSubprocessSignal(String processFile, String[] completedNodes) throws Exception {
KieBase kbase = createKnowledgeBase(processFile);
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("sub-script")) {
executednodes.add(event.getNodeInstance().getId());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessSignal");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
ksession.signalEvent("MySignal", null, processInstance.getId());
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), completedNodes);
assertThat(executednodes.size()).isEqualTo(4);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class SLAComplianceTest method testSLAonProcessViolatedNoTracking.
@Test
public void testSLAonProcessViolatedNoTracking() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
final ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterSLAViolated(SLAViolatedEvent event) {
latch.countDown();
}
};
KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLA.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.addEventListener(listener);
ksession.getEnvironment().set("SLATimerMode", "false");
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
boolean slaViolated = latch.await(5, TimeUnit.SECONDS);
assertFalse("SLA should not violated by timer", slaViolated);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
assertEquals(ProcessInstance.SLA_PENDING, slaCompliance);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
slaCompliance = getSLAComplianceForProcessInstance(processInstance);
assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance);
ksession.dispose();
}
Aggregations