Search in sources :

Example 11 with Event

use of org.mule.runtime.api.event.Event in project mule by mulesoft.

the class ProcessorChainExecutorTestCase method testDoProcessOnErrorMessagingException.

@Test
public void testDoProcessOnErrorMessagingException() throws InterruptedException, MuleException {
    final String ERROR_PAYLOAD = "ERROR_PAYLOAD";
    when(chain.apply(any())).thenReturn(error(new MessagingException(createStaticMessage(""), getEventBuilder().message(of(ERROR_PAYLOAD)).build())));
    ImmutableProcessorChainExecutor chainExecutor = new ImmutableProcessorChainExecutor(coreEvent, chain);
    AtomicInteger successCalls = new AtomicInteger(0);
    AtomicInteger errorCalls = new AtomicInteger(0);
    Reference<Event> errorEvent = new Reference<>();
    doProcessAndWait(chainExecutor, r -> successCalls.incrementAndGet(), (t, r) -> {
        errorCalls.incrementAndGet();
        errorEvent.set(((EventedResult) r).getEvent());
    });
    assertThat(successCalls.get(), is(0));
    assertThat(errorCalls.get(), is(1));
    assertThat(errorEvent.get().getMessage().getPayload().getValue(), is(ERROR_PAYLOAD));
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Reference(org.mule.runtime.api.util.Reference) Event(org.mule.runtime.api.event.Event) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 12 with Event

use of org.mule.runtime.api.event.Event in project mule by mulesoft.

the class NonBlockingOperationsTestCase method voidNonBlockingOperation.

@Test
public void voidNonBlockingOperation() throws Exception {
    IronMan ironMan = getIronMan("ironMan");
    final String payload = "take me to the avengers tower";
    Event event = flowRunner("computeFlightPlan").withPayload(payload).run();
    assertThat(event.getMessage().getPayload().getValue().toString(), equalTo(payload));
    new PollingProber().probe(1000, 1000, () -> FLIGHT_PLAN.equals(ironMan.getFlightPlan()));
}
Also used : PollingProber(org.mule.tck.probe.PollingProber) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Event(org.mule.runtime.api.event.Event) MuleExtensionUtils.getInitialiserEvent(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.getInitialiserEvent) IronMan(org.mule.test.marvel.ironman.IronMan) Test(org.junit.Test)

Example 13 with Event

use of org.mule.runtime.api.event.Event in project mule by mulesoft.

the class ScatterGatherRouterTestCase method customTargetDefaultPayload.

@Test
@Description("When a custom target is configured the router result is set in a variable and the input event is output.")
public void customTargetDefaultPayload() throws Exception {
    final String variableName = "foo";
    CoreEvent original = testEvent();
    MessageProcessorChain route1 = newChain(empty(), event -> event);
    MessageProcessorChain route2 = newChain(empty(), event -> event);
    router.setRoutes(asList(route1, route2));
    router.setTarget(variableName);
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage(), equalTo(original.getMessage()));
    final TypedValue<?> typedValue = result.getVariables().get(variableName);
    assertThat(typedValue.getValue(), instanceOf(Map.class));
    assertThat(Map.class.isAssignableFrom(typedValue.getDataType().getType()), is(true));
    Map<String, Message> resultMap = (Map<String, Message>) typedValue.getValue();
    assertThat(resultMap.values(), hasSize(2));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Event(org.mule.runtime.api.event.Event) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 14 with Event

use of org.mule.runtime.api.event.Event in project mule by mulesoft.

the class ScatterGatherRouterTestCase method defaultTarget.

@Test
@Description("By default the router result populates the outgoing message payload.")
public void defaultTarget() throws Exception {
    CoreEvent original = testEvent();
    MessageProcessorChain route1 = newChain(empty(), event -> event);
    MessageProcessorChain route2 = newChain(empty(), event -> event);
    router.setRoutes(asList(route1, route2));
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage().getPayload().getValue(), instanceOf(Map.class));
    Map<String, Message> resultMap = (Map) result.getMessage().getPayload().getValue();
    assertThat(resultMap.values(), hasSize(2));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Event(org.mule.runtime.api.event.Event) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 15 with Event

use of org.mule.runtime.api.event.Event in project mule by mulesoft.

the class ScatterGatherRouterTestCase method customTargetMessage.

@Test
@Description("When a custom target is configured the router result is set in a variable and the input event is output.")
public void customTargetMessage() throws Exception {
    final String variableName = "foo";
    CoreEvent original = testEvent();
    MessageProcessorChain route1 = newChain(empty(), event -> event);
    MessageProcessorChain route2 = newChain(empty(), event -> event);
    router.setRoutes(asList(route1, route2));
    router.setTarget(variableName);
    router.setTargetValue("#[message]");
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage(), equalTo(original.getMessage()));
    assertThat(((Message) result.getVariables().get(variableName).getValue()).getPayload().getValue(), instanceOf(Map.class));
    Map<String, Message> resultMap = (Map) ((Message) result.getVariables().get(variableName).getValue()).getPayload().getValue();
    assertThat(resultMap.values(), hasSize(2));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Event(org.mule.runtime.api.event.Event) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

Event (org.mule.runtime.api.event.Event)15 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)15 Test (org.junit.Test)12 Description (io.qameta.allure.Description)6 Message (org.mule.runtime.api.message.Message)6 MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)6 List (java.util.List)5 InputEvent (org.mule.runtime.api.component.execution.InputEvent)4 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)4 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)4 ArrayList (java.util.ArrayList)3 Collections.singletonList (java.util.Collections.singletonList)3 Collections.singletonMap (java.util.Collections.singletonMap)3 Map (java.util.Map)3 Optional (java.util.Optional)3 ExecutionResult (org.mule.runtime.api.component.execution.ExecutionResult)3 Reference (org.mule.runtime.api.util.Reference)3 MuleContext (org.mule.runtime.core.api.MuleContext)3 String.format (java.lang.String.format)2 Optional.of (java.util.Optional.of)2