use of org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair 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());
}
use of org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair in project mule by mulesoft.
the class MessageEnricherTestCase method enrichFlowVariable.
@Test
public void enrichFlowVariable() throws Exception {
MessageEnricher enricher = baseEnricher();
enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:flowVars.foo]"));
enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value("bar").build()).build());
CoreEvent out = process(enricher, testEvent());
assertEquals("bar", out.getVariables().get("foo").getValue());
}
use of org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair in project mule by mulesoft.
the class MessageEnricherTestCase method doNotImplicitlyEnrichFlowVariable.
@Test
public void doNotImplicitlyEnrichFlowVariable() throws Exception {
MessageEnricher enricher = baseEnricher();
enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.myHeader]"));
enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).addVariable("flowFoo", "bar").build());
CoreEvent out = process(enricher, testEvent());
assertThat(out.getVariables().keySet(), not(hasItem("flowFoo")));
}
use of org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair 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.enricher.MessageEnricher.EnrichExpressionPair in project mule by mulesoft.
the class MessageEnricherTestCase method propagatesVariables.
@Test
public void propagatesVariables() 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(of("")).addVariable("flowFoo", "bar").build();
((PrivilegedEvent) in).getSession().setProperty("sessionFoo", "bar");
CoreEvent out = process(enricher, in);
assertEquals("bar", ((PrivilegedEvent) out).getSession().getProperty("sessionFoo"));
assertEquals("bar", out.getVariables().get("flowFoo").getValue());
}
Aggregations