Search in sources :

Example 1 with TransformationService

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));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DataType(org.mule.runtime.api.metadata.DataType) TransformationService(org.mule.runtime.api.transformation.TransformationService) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 2 with TransformationService

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));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DataType(org.mule.runtime.api.metadata.DataType) TransformationService(org.mule.runtime.api.transformation.TransformationService) MessageContext(org.mule.runtime.core.internal.el.context.MessageContext)

Example 3 with TransformationService

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));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DataType(org.mule.runtime.api.metadata.DataType) TransformationService(org.mule.runtime.api.transformation.TransformationService) MessageContext(org.mule.runtime.core.internal.el.context.MessageContext)

Example 4 with TransformationService

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);
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DataType(org.mule.runtime.api.metadata.DataType) TransformationService(org.mule.runtime.api.transformation.TransformationService) Test(org.junit.Test)

Aggregations

DataType (org.mule.runtime.api.metadata.DataType)4 TransformationService (org.mule.runtime.api.transformation.TransformationService)4 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)4 Test (org.junit.Test)2 MessageContext (org.mule.runtime.core.internal.el.context.MessageContext)2 TypedValue (org.mule.runtime.api.metadata.TypedValue)1