use of org.mule.runtime.api.transformation.TransformationService in project mule by mulesoft.
the class MessageContextTestCase method payloadAsType.
@Test
public void payloadAsType() throws Exception {
InternalMessage transformedMessage = mock(InternalMessage.class, RETURNS_DEEP_STUBS);
final TypedValue<Object> expectedPayload = new TypedValue<>(new Object(), OBJECT);
when(transformedMessage.getPayload()).thenReturn(expectedPayload);
TransformationService transformationService = mock(TransformationService.class);
muleContext.setTransformationService(transformationService);
when(transformationService.transform(any(InternalMessage.class), any(DataType.class))).thenReturn(transformedMessage);
assertSame(transformedMessage.getPayload().getValue(), evaluate("message.payloadAs(org.mule.tck.testmodels.fruit.Banana)", event));
}
use of org.mule.runtime.api.transformation.TransformationService in project mule by mulesoft.
the class WildcardExpressionLanguageFunctionTestCase method addMessageToContextWithPayload.
@SuppressWarnings("unchecked")
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, STRING));
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.api.transformation.TransformationService 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.api.transformation.TransformationService in project mule by mulesoft.
the class MessageContextTestCase method payloadAsDataType.
@Test
public void payloadAsDataType() throws Exception {
InternalMessage transformedMessage = mock(InternalMessage.class, RETURNS_DEEP_STUBS);
TransformationService transformationService = mock(TransformationService.class);
when(transformedMessage.getPayload()).thenReturn(new TypedValue<Object>(TEST_PAYLOAD, STRING));
muleContext.setTransformationService(transformationService);
when(transformationService.transform(event.getMessage(), DataType.STRING)).thenReturn(transformedMessage);
Object result = evaluate("message.payloadAs(" + DataType.class.getName() + ".STRING)", event);
assertSame(TEST_PAYLOAD, result);
}
Aggregations