use of org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair in project mule by mulesoft.
the class MessageEnricherTestCase method propagateMessage.
@Test
public void propagateMessage() 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()).value("enriched").build()).build());
CoreEvent in = eventBuilder(muleContext).message(InternalMessage.builder().value("").addOutboundProperty("foo", "bar").build()).build();
CoreEvent out = process(enricher, in);
assertThat(out.getCorrelationId(), equalTo(in.getCorrelationId()));
assertThat(((InternalMessage) out.getMessage()).getOutboundProperty("foo"), equalTo("bar"));
assertThat(out.getMessage().getPayload().getValue(), equalTo(in.getMessage().getPayload().getValue()));
}
use of org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair in project mule by mulesoft.
the class MessageEnricherTestCase method doEnrichDataTypePropagationTest.
private void doEnrichDataTypePropagationTest(EnrichExpressionPair pair) throws Exception {
final DataType dataType = DataType.builder().type(String.class).mediaType(JSON).charset(UTF_16.name()).build();
MessageEnricher enricher = baseEnricher();
enricher.addEnrichExpressionPair(pair);
enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value("bar").mediaType(dataType.getMediaType()).build()).build());
CoreEvent out = process(enricher, testEvent());
assertEquals("bar", out.getVariables().get("foo").getValue());
assertThat(out.getVariables().get("foo").getDataType(), like(String.class, JSON, UTF_16));
}
use of org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair in project mule by mulesoft.
the class MessageEnricherTestCase method testEnrichHeaderWithHeader.
@Test
public void testEnrichHeaderWithHeader() throws Exception {
MessageEnricher enricher = createEnricher();
enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.header1]", "#[mel:message.outboundProperties.myHeader]"));
enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).addOutboundProperty("header1", "test").build()).build());
Message result = process(enricher, testEvent()).getMessage();
assertEquals("test", ((InternalMessage) result).getOutboundProperty("myHeader"));
assertEquals(TEST_PAYLOAD, result.getPayload().getValue());
}
use of org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair in project mule by mulesoft.
the class MessageEnricherTestCase method testEnrichWithException.
@Test
public void testEnrichWithException() throws Exception {
IllegalStateException testException = new IllegalStateException();
MessageEnricher enricher = baseEnricher();
enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:header:myHeader]"));
enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> {
throw testException;
});
thrown.expect(sameInstance(testException));
process(enricher, testEvent());
}
Aggregations