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());
}
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"));
}
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());
}
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());
}
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())));
}
Aggregations