Search in sources :

Example 11 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class VariablesTestCase method variableFromFlowScope.

@Test
public void variableFromFlowScope() throws Exception {
    Message message = of("");
    CoreEvent event = InternalEvent.builder(context).message(message).addVariable("foo", "bar").build();
    ((PrivilegedEvent) event).getSession().setProperty("foo", "NOTbar");
    assertEquals(event.getVariables().get("foo").getValue(), evaluate("foo", event));
}
Also used : Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 12 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class SplitAggregateScopeTestCase 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 = createListEvent();
    MessageProcessorChain nested = newChain(empty(), event -> event);
    nested.setMuleContext(muleContext);
    router.setMessageProcessors(singletonList(nested));
    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(List.class));
    assertThat(List.class.isAssignableFrom(typedValue.getDataType().getType()), is(true));
    List<Message> resultList = (List<Message>) typedValue.getValue();
    assertThat(resultList, 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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 13 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class SplitAggregateScopeTestCase method defaultTarget.

@Test
@Description("By default the router result populates the outgoing message payload.")
public void defaultTarget() throws Exception {
    CoreEvent original = createListEvent();
    MessageProcessorChain nested = newChain(empty(), event -> event);
    nested.setMuleContext(muleContext);
    router.setMessageProcessors(singletonList(nested));
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage().getPayload().getValue(), instanceOf(List.class));
    List<Message> resultList = (List<Message>) result.getMessage().getPayload().getValue();
    assertThat(resultList, 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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 14 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class SplitterTestCase method assertRouted.

private void assertRouted(Object payload, int count, boolean counted) throws Exception, MuleException {
    MuleSession session = new DefaultMuleSession();
    Map<String, Serializable> inboundProps = new HashMap<>();
    inboundProps.put("inbound1", "1");
    inboundProps.put("inbound2", 2);
    inboundProps.put("inbound3", session);
    Map<String, Serializable> outboundProps = new HashMap<>();
    outboundProps.put("outbound1", "3");
    outboundProps.put("outbound2", 4);
    outboundProps.put("outbound3", session);
    Map<String, Object> invocationProps = new HashMap<>();
    invocationProps.put("invoke1", "5");
    invocationProps.put("invoke2", 6);
    invocationProps.put("invoke3", session);
    Set<Integer> expectedSequences = new HashSet<>();
    for (int i = 1; i <= count; i++) {
        expectedSequences.add(i);
    }
    Message toSplit = InternalMessage.builder().value(payload).inboundProperties(inboundProps).outboundProperties(outboundProps).build();
    Splitter splitter = new Splitter();
    Grabber grabber = new Grabber();
    splitter.setMuleContext(muleContext);
    splitter.setListener(grabber);
    splitter.initialise();
    final Builder eventBuilder = this.<PrivilegedEvent.Builder>getEventBuilder().message(toSplit).session(session);
    for (Map.Entry<String, Object> entry : invocationProps.entrySet()) {
        eventBuilder.addVariable(entry.getKey(), entry.getValue());
    }
    CoreEvent event = eventBuilder.build();
    splitter.process(event);
    List<CoreEvent> splits = grabber.getEvents();
    assertEquals(count, splits.size());
    Set<Object> actualSequences = new HashSet<>();
    assertSplitParts(count, counted, inboundProps, outboundProps, invocationProps, splits, actualSequences);
    assertEquals(expectedSequences, actualSequences);
}
Also used : Serializable(java.io.Serializable) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) HashMap(java.util.HashMap) Builder(org.mule.runtime.core.api.event.CoreEvent.Builder) MuleSession(org.mule.runtime.core.privileged.event.MuleSession) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 15 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method timeoutEager.

@Test
@Description("When configured with delayErrors='false' the first timeout causes strategy to throw a TimeoutException.")
public void timeoutEager() throws Throwable {
    strategy = createStrategy(processingStrategy, 1, false, 50);
    Message pair2Result = of(2);
    Processor pair2Processor = createProcessorSpy(pair2Result);
    RoutingPair pair2 = of(testEvent(), createChain(pair2Processor));
    expectedException.expect(instanceOf(DefaultMuleException.class));
    expectedException.expectCause(instanceOf(TimeoutException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250), pair2), throwable -> verify(pair2Processor, never()).process(any(CoreEvent.class)));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) Message(org.mule.runtime.api.message.Message) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) TimeoutException(java.util.concurrent.TimeoutException) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

Message (org.mule.runtime.api.message.Message)226 Test (org.junit.Test)189 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)104 SmallTest (org.mule.tck.size.SmallTest)68 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)46 Transformer (org.mule.runtime.core.api.transformer.Transformer)35 DataType (org.mule.runtime.api.metadata.DataType)33 ArrayList (java.util.ArrayList)26 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)26 Processor (org.mule.runtime.core.api.processor.Processor)25 List (java.util.List)20 Assert.assertThat (org.junit.Assert.assertThat)19 ExpectedException (org.junit.rules.ExpectedException)19 MuleContextUtils.eventBuilder (org.mule.tck.util.MuleContextUtils.eventBuilder)19 Map (java.util.Map)18 Rule (org.junit.Rule)18 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)18 ExpectedException.none (org.junit.rules.ExpectedException.none)17 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)17 TypedValue (org.mule.runtime.api.metadata.TypedValue)16