use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class ExpressionLanguageExtensionTestCase method testMuleMessageAvailableInFunction.
@Test
public void testMuleMessageAvailableInFunction() throws MuleException {
InternalMessage message = mock(InternalMessage.class);
CoreEvent event = getEventBuilder().message(message).build();
assertThat(evaluate("muleMessage()", event), is(message));
}
use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method createEvent.
protected PrivilegedEvent createEvent(String payload, DataType dataType, Object attributes, DataType attributesDataType) {
InternalMessage message = mock(InternalMessage.class);
when(message.getPayload()).thenReturn(new TypedValue<>(payload, dataType));
when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, attributesDataType));
try {
return this.<PrivilegedEvent.Builder>getEventBuilder().message(message).build();
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class RegexExpressionLanguageFunctionTestCase method addMessageToContextWithPayload.
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, DataType.fromObject(payload)));
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));
}
use of org.mule.runtime.core.internal.message.InternalMessage 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.message.InternalMessage 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());
}
Aggregations