use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testSignalStartEventDataMapping.
@Test
@BZ("1154557")
public void testSignalStartEventDataMapping() throws Exception {
KieSession ksession = createKSession(SIGNAL_DATA_MAPPING);
final List<Long> list = new ArrayList<Long>();
final List<String> variableList = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
variableList.add((String) ((WorkflowProcessInstance) event.getProcessInstance()).getVariable("x"));
}
});
ksession.signalEvent("MyStartSignal", "NewValue");
Assertions.assertThat(list).hasSize(1);
Assertions.assertThat(variableList.get(0)).isEqualTo("NewValue");
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testMultipleProcessesInSingleCaseCompletedInSequence.
@Test
public void testMultipleProcessesInSingleCaseCompletedInSequence() {
final Set<Long> ksessionUsed = new HashSet<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id > 0);
ProcessInstance pi1 = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_COMPLETED, pi1.getState());
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession = runtime.getKieSession();
ProcessInstance pi2 = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_COMPLETED, pi2.getState());
// there should be only one ksession used
assertEquals(1, ksessionUsed.size());
assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
manager.close();
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testExecuteReusableSubprocess.
@Test
public void testExecuteReusableSubprocess() {
final Set<Long> ksessionUsed = new HashSet<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 2);
ProcessInstance pi1 = ksession.startProcess("ParentProcess");
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession = runtime.getKieSession();
ksession.getWorkItemManager().completeWorkItem(1, null);
AuditService logService = runtime.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("ParentProcess");
assertNotNull(logs);
assertEquals(0, logs.size());
logs = logService.findActiveProcessInstances("SubProcess");
assertNotNull(logs);
assertEquals(0, logs.size());
logs = logService.findProcessInstances("ParentProcess");
assertNotNull(logs);
assertEquals(1, logs.size());
String externalId = logs.get(0).getExternalId();
assertEquals(manager.getIdentifier(), externalId);
logs = logService.findProcessInstances("SubProcess");
assertNotNull(logs);
assertEquals(1, logs.size());
externalId = logs.get(0).getExternalId();
assertEquals(manager.getIdentifier(), externalId);
assertEquals(1, ksessionUsed.size());
assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testTimerOnPerCaseManager.
@Test(timeout = 10000)
public void testTimerOnPerCaseManager() throws Exception {
final Set<Long> ksessionUsed = new HashSet<Long>();
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
final List<Long> timerExpirations = new ArrayList<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExpirations.add(event.getProcessInstance().getId());
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
}
});
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
long ksession1Id = ksession.getIdentifier();
ProcessInstance pi1 = ksession.startProcess("IntermediateCatchEvent");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
// wait a bit for some timers to fire
countDownListener.waitTillCompleted();
runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession = runtime.getKieSession();
ksession.abortProcessInstance(pi1.getId());
manager.disposeRuntimeEngine(runtime);
manager.close();
// there should be only one ksession used
assertEquals(1, ksessionUsed.size());
assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testEventSignalingBetweenProcesses.
@Test
public void testEventSignalingBetweenProcesses() {
final Map<String, Integer> processStates = new HashMap<String, Integer>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().persistence(false).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/throw-an-event.bpmn"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = new ArrayList<ProcessEventListener>();
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
}
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ksession.startProcess("com.sample.bpmn.hello");
assertEquals(2, processStates.size());
assertTrue(processStates.containsKey("com.sample.bpmn.hello"));
assertTrue(processStates.containsKey("com.sample.bpmn.Second"));
assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.hello").intValue());
assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.Second").intValue());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
Aggregations