Search in sources :

Example 1 with MessageEvent

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);
    }
}
Also used : MessageEvent(org.kie.api.event.process.MessageEvent) ProcessEventListener(org.kie.api.event.process.ProcessEventListener)

Example 2 with MessageEvent

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");
}
Also used : ProcessConfig(org.kie.kogito.process.ProcessConfig) MessageEvent(org.kie.api.event.process.MessageEvent) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) Model(org.kie.kogito.Model) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 3 with MessageEvent

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);
    }
}
Also used : MessageEventImpl(org.drools.core.event.MessageEventImpl) MessageEvent(org.kie.api.event.process.MessageEvent) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener)

Example 4 with MessageEvent

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));
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) MessageEvent(org.kie.api.event.process.MessageEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) SendTaskHandler(org.jbpm.bpmn2.handler.SendTaskHandler) Test(org.junit.Test)

Example 5 with MessageEvent

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");
}
Also used : ProcessConfig(org.kie.kogito.process.ProcessConfig) MessageEvent(org.kie.api.event.process.MessageEvent) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) Model(org.kie.kogito.Model) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Aggregations

MessageEvent (org.kie.api.event.process.MessageEvent)5 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)4 KogitoProcessEventListener (org.kie.kogito.internal.process.event.KogitoProcessEventListener)3 Test (org.junit.jupiter.api.Test)2 Application (org.kie.kogito.Application)2 Model (org.kie.kogito.Model)2 ProcessConfig (org.kie.kogito.process.ProcessConfig)2 Processes (org.kie.kogito.process.Processes)2 HashMap (java.util.HashMap)1 MessageEventImpl (org.drools.core.event.MessageEventImpl)1 SendTaskHandler (org.jbpm.bpmn2.handler.SendTaskHandler)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1