use of org.kie.api.event.process.MessageEvent in project drools by kiegroup.
the class ProcessEventSupport method fireOnMessage.
public void fireOnMessage(final ProcessInstance instance, NodeInstance nodeInstance, KieRuntime kruntime, String messageName, Object messageObject) {
if (hasListeners()) {
final MessageEvent event = new MessageEventImpl(instance, kruntime, nodeInstance, messageName, messageObject);
notifyAllListeners(event, ProcessEventListener::onMessage);
}
}
use of org.kie.api.event.process.MessageEvent in project kogito-runtimes by kiegroup.
the class MessageIntermediateEventIT method testMessageThrowEventProcess.
@Test
public void testMessageThrowEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("messageevent/IntermediateThrowEventMessage.bpmn2");
ProcessEventListener listener = mock(KogitoProcessEventListener.class);
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
Process<? extends Model> p = app.get(Processes.class).processById("IntermediateThrowEventMessage");
Model m = p.createModel();
m.update(Collections.singletonMap("customerId", "Javierito"));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
ArgumentCaptor<MessageEvent> messageEvent = ArgumentCaptor.forClass(MessageEvent.class);
verify(listener).onMessage(messageEvent.capture());
assertThat(messageEvent.getValue().getMessageName()).isEqualTo("customers");
assertThat(messageEvent.getValue().getMessage()).isEqualTo("Javierito");
}
use of org.kie.api.event.process.MessageEvent in project kogito-runtimes by kiegroup.
the class KogitoProcessEventSupportImpl method fireOnMessage.
@Override
public void fireOnMessage(final KogitoProcessInstance instance, KogitoNodeInstance nodeInstance, KieRuntime kruntime, String messageName, Object messageObject) {
if (hasListeners()) {
final MessageEvent event = new MessageEventImpl(instance, kruntime, nodeInstance, messageName, messageObject);
notifyAllListeners(event, ProcessEventListener::onMessage);
}
}
use of org.kie.api.event.process.MessageEvent in project jbpm by kiegroup.
the class IntermediateEventTest method testMessageIntermediateThrow.
@Test
public void testMessageIntermediateThrow() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateThrowEventMessage.bpmn2");
DefaultProcessEventListener listener = Mockito.spy(new DefaultProcessEventListener() {
@Override
public void onMessage(MessageEvent event) {
assertEquals("_2_Message", event.getMessageName());
assertEquals("MyValue", event.getMessage());
}
});
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler());
ksession.addEventListener(listener);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "MyValue");
ProcessInstance processInstance = ksession.startProcess("MessageIntermediateEvent", params);
assertProcessInstanceCompleted(processInstance);
Mockito.verify(listener).onMessage(Mockito.any(MessageEvent.class));
}
use of org.kie.api.event.process.MessageEvent in project kogito-runtimes by kiegroup.
the class MessageIntermediateEventIT method testMessageEndEventProcess.
@Test
public void testMessageEndEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("messageevent/MessageEndEvent.bpmn2");
ProcessEventListener listener = mock(KogitoProcessEventListener.class);
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
Process<? extends Model> p = app.get(Processes.class).processById("MessageEndEvent");
Model m = p.createModel();
m.update(Collections.singletonMap("customerId", "Javierito"));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
ArgumentCaptor<MessageEvent> messageEvent = ArgumentCaptor.forClass(MessageEvent.class);
verify(listener).onMessage(messageEvent.capture());
assertThat(messageEvent.getValue().getMessageName()).isEqualTo("processedcustomers");
assertThat(messageEvent.getValue().getMessage()).isEqualTo("Javierito");
}
Aggregations