Search in sources :

Example 6 with InternalMessage

use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.

the class AbstractSplitterTestCase method simpleSplitter.

@Test
public void simpleSplitter() throws Exception {
    TestSplitter splitter = new TestSplitter(false);
    MultipleEventSensingMessageProcessor listener = new MultipleEventSensingMessageProcessor();
    splitter.setListener(listener);
    splitter.setMuleContext(muleContext);
    Apple apple = new Apple();
    Banana banana = new Banana();
    Orange orange = new Orange();
    FruitBowl fruitBowl = new FruitBowl();
    fruitBowl.addFruit(apple);
    fruitBowl.addFruit(banana);
    fruitBowl.addFruit(orange);
    final CoreEvent inEvent = eventBuilder(muleContext).message(of(fruitBowl)).build();
    CoreEvent resultEvent = splitter.process(inEvent);
    assertThat(listener.events, hasSize(3));
    assertThat(listener.events.get(0).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(listener.events.get(1).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(listener.events.get(2).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(resultEvent.getMessage().getPayload().getValue(), instanceOf(List.class));
    assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()), hasSize(3));
    assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(0).getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(1).getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(2).getPayload().getValue(), instanceOf(Fruit.class));
}
Also used : Apple(org.mule.tck.testmodels.fruit.Apple) FruitBowl(org.mule.tck.testmodels.fruit.FruitBowl) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) Fruit(org.mule.tck.testmodels.fruit.Fruit) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) List(java.util.List) Orange(org.mule.tck.testmodels.fruit.Orange) Banana(org.mule.tck.testmodels.fruit.Banana) Test(org.junit.Test)

Example 7 with InternalMessage

use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.

the class DefaultRouterResultsHandlerTestCase method aggregateMultipleMuleMessageCollections.

@Test
public void aggregateMultipleMuleMessageCollections() {
    Message message1 = Message.of("test event A");
    CoreEvent event1 = InternalEvent.builder(context).message(message1).addVariable("key1", "value1").build();
    Message message2 = Message.of("test event B");
    Message message3 = Message.of("test event C");
    Message message4 = Message.of("test event D");
    Message message5 = Message.of("test event E");
    List<Message> list = new ArrayList<>();
    list.add(message2);
    list.add(message3);
    Message messageCollection = Message.of(list);
    CoreEvent event2 = InternalEvent.builder(context).message(messageCollection).addVariable("key2", "value2").build();
    List<InternalMessage> list2 = new ArrayList<>();
    list.add(message4);
    list.add(message5);
    Message messageCollection2 = Message.of(list2);
    CoreEvent event3 = InternalEvent.builder(context).message(messageCollection2).addVariable("key3", "value3").build();
    List<CoreEvent> events = new ArrayList<>();
    events.add(event2);
    events.add(event3);
    CoreEvent result = resultsHandler.aggregateResults(events, event1);
    assertNotNull(result);
    assertEquals(2, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).size());
    assertTrue(result.getMessage().getPayload().getValue() instanceof List<?>);
    assertEquals(messageCollection, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).get(0));
    assertEquals(messageCollection2, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).get(1));
    // Because a new MuleMessageCollection is created, propagate properties from
    // original event
    assertThat(result.getVariables().get("key1").getValue(), equalTo("value1"));
    assertThat(result.getVariables().get("key2").getValue(), equalTo("value2"));
    assertThat(result.getVariables().get("key3").getValue(), equalTo("value3"));
    // Root id
    assertThat(result.getCorrelationId(), equalTo(event1.getCorrelationId()));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with InternalMessage

use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.

the class ExpressionTransformerTestCase method testNullPayloadIsConsideredAsNullResultEL.

@Test
public void testNullPayloadIsConsideredAsNullResultEL() throws Exception {
    ExpressionTransformer transformer = new ExpressionTransformer();
    transformer.setMuleContext(muleContext);
    transformer.setReturnSourceIfNull(true);
    // MVL doesn't return NullPayload but rather null. So 'optional' needs to be true.
    ExpressionArgument argument = new ExpressionArgument("test", "null", true);
    argument.setMuleContext(muleContext);
    transformer.addArgument(argument);
    Object result = transformer.transformMessage(testEvent(), null);
    assertTrue(result instanceof InternalMessage);
    InternalMessage transformedMessage = (InternalMessage) result;
    assertEquals(TEST_PAYLOAD, transformedMessage.getPayload().getValue());
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpressionTransformer(org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer) ExpressionArgument(org.mule.runtime.core.internal.transformer.expression.ExpressionArgument) Test(org.junit.Test)

Example 9 with InternalMessage

use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.

the class WildcardExpressionLanguageFunctionTestCase method addMessageToContextWithPayload.

@SuppressWarnings("unchecked")
protected void addMessageToContextWithPayload(String payload) throws MuleException {
    message = mock(InternalMessage.class);
    event = getEventBuilder().message(message).build();
    eventBuilder = CoreEvent.builder(event);
    InternalMessage transformedMessage = mock(InternalMessage.class, RETURNS_DEEP_STUBS);
    when(transformedMessage.getPayload()).thenReturn(new TypedValue<>(payload, STRING));
    TransformationService transformationService = mock(TransformationService.class);
    when(muleContext.getTransformationService()).thenReturn(transformationService);
    when(transformationService.transform(any(InternalMessage.class), any(DataType.class))).thenReturn(transformedMessage);
    context.addFinalVariable("message", new MessageContext(event, eventBuilder, muleContext));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DataType(org.mule.runtime.api.metadata.DataType) TransformationService(org.mule.runtime.api.transformation.TransformationService) MessageContext(org.mule.runtime.core.internal.el.context.MessageContext)

Example 10 with InternalMessage

use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.

the class MessageEnricherTestCase method testEnrichWithNullResponse.

@Test
public void testEnrichWithNullResponse() throws Exception {
    MessageEnricher enricher = baseEnricher();
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.myHeader]"));
    enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> null);
    Message result = process(enricher, testEvent()).getMessage();
    assertNull(((InternalMessage) result).getOutboundProperty("myHeader"));
    assertEquals(TEST_PAYLOAD, result.getPayload().getValue());
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JSON(org.mule.runtime.api.metadata.MediaType.JSON) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Message.of(org.mule.runtime.api.message.Message.of) Assert.assertNull(org.junit.Assert.assertNull) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Assert.assertEquals(org.junit.Assert.assertEquals) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Test(org.junit.Test)

Aggregations

InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)27 Test (org.junit.Test)22 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)20 Message (org.mule.runtime.api.message.Message)12 DataType (org.mule.runtime.api.metadata.DataType)12 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)7 UTF_16 (java.nio.charset.StandardCharsets.UTF_16)6 ArrayList (java.util.ArrayList)6 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)6 CoreMatchers.hasItem (org.hamcrest.CoreMatchers.hasItem)6 CoreMatchers.not (org.hamcrest.CoreMatchers.not)6 CoreMatchers.sameInstance (org.hamcrest.CoreMatchers.sameInstance)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Assert.assertNull (org.junit.Assert.assertNull)6 Assert.assertThat (org.junit.Assert.assertThat)6 Rule (org.junit.Rule)6 ExpectedException (org.junit.rules.ExpectedException)6 ExpectedException.none (org.junit.rules.ExpectedException.none)6 Message.of (org.mule.runtime.api.message.Message.of)6 JSON (org.mule.runtime.api.metadata.MediaType.JSON)6