Search in sources :

Example 11 with InternalMessage

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

the class MessageEnricherTestCase method testEnrichHeadersMToN.

@Test
public void testEnrichHeadersMToN() throws Exception {
    MessageEnricher enricher = baseEnricher();
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.header1]", "#[mel:message.outboundProperties.myHeader1]"));
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.header2]", "#[mel:message.outboundProperties.myHeader2]"));
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.header3]", "#[mel:message.outboundProperties.myHeader3]"));
    enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).addOutboundProperty("header1", "test").addOutboundProperty("header2", "test2").addOutboundProperty("header3", "test3").build()).build());
    Message result = process(enricher, testEvent()).getMessage();
    assertNull(((InternalMessage) result).getOutboundProperty("myHeader"));
    assertEquals("test2", ((InternalMessage) result).getOutboundProperty("myHeader2"));
    assertEquals("test3", ((InternalMessage) result).getOutboundProperty("myHeader3"));
    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)

Example 12 with InternalMessage

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

the class MessageEnricherTestCase method doNotImplicitlyEnrichMessageProperties.

@Test
public void doNotImplicitlyEnrichMessageProperties() throws Exception {
    MessageEnricher enricher = baseEnricher();
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.myHeader]"));
    enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).addInboundProperty("foo", "bar").build()).build());
    Message out = process(enricher, testEvent()).getMessage();
    assertNull(((InternalMessage) out).getOutboundProperty("foo"));
}
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)

Example 13 with InternalMessage

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

the class MessageEnricherTestCase method testEnrichHeaderWithPayload.

@Test
public void testEnrichHeaderWithPayload() throws Exception {
    MessageEnricher enricher = createEnricher();
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.myHeader]"));
    enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value(TEST_PAYLOAD).build()).build());
    initialiseIfNeeded(enricher, muleContext);
    Message result = process(enricher, testEvent()).getMessage();
    assertEquals(TEST_PAYLOAD, ((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)

Example 14 with InternalMessage

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

the class AbstractSerializerProtocolContractTestCase method serializeWithoutDefaultConstructor.

@Test
public final void serializeWithoutDefaultConstructor() throws Exception {
    Calendar calendar = Calendar.getInstance();
    Locale locale = Locale.ITALIAN;
    DateTime dateTime = new DateTime(calendar, locale);
    dateTime.changeTimeZone("Pacific/Midway");
    CoreEvent event = eventBuilder(muleContext).message(of(dateTime)).build();
    byte[] bytes = serializationProtocol.serialize(event.getMessage());
    InternalMessage message = serializationProtocol.deserialize(bytes);
    DateTime deserealized = (DateTime) message.getPayload().getValue();
    assertEquals(calendar, deserealized.toCalendar());
    assertEquals(dateTime.format(), deserealized.format());
}
Also used : Locale(java.util.Locale) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Calendar(java.util.Calendar) DateTime(org.mule.runtime.core.internal.el.datetime.DateTime) Test(org.junit.Test)

Example 15 with InternalMessage

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

the class DataWeaveExpressionLanguageAdaptorTestCase method payloadBinding.

@Test
public void payloadBinding() throws Exception {
    CoreEvent event = getEventWithError(empty());
    InternalMessage message = mock(InternalMessage.class, RETURNS_DEEP_STUBS);
    when(event.getMessage()).thenReturn(message);
    TypedValue payload = new TypedValue<>("hey", STRING);
    TypedValue attributes = new TypedValue<>(null, OBJECT);
    when(message.getPayload()).thenReturn(payload);
    when(message.getAttributes()).thenReturn(attributes);
    TypedValue result = expressionLanguage.evaluate(PAYLOAD, event, BindingContext.builder().build());
    assertThat(result.getValue(), is(equalTo(payload.getValue())));
    assertThat(result.getDataType(), is(equalTo(payload.getDataType())));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) 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