use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method dataTypeBinding.
@Test
public void dataTypeBinding() throws Exception {
CoreEvent event = getEventWithError(empty());
InternalMessage message = mock(InternalMessage.class, RETURNS_DEEP_STUBS);
when(event.getMessage()).thenReturn(message);
TypedValue payload = new TypedValue<>("hey", STRING);
TypedValue attributes = new TypedValue<>(null, OBJECT);
when(message.getPayload()).thenReturn(payload);
when(message.getAttributes()).thenReturn(attributes);
TypedValue result = expressionLanguage.evaluate(DATA_TYPE, event, BindingContext.builder().build());
assertThat(result.getValue(), is(equalTo(STRING)));
assertThat(result.getDataType(), is(assignableTo(fromType(DataType.class))));
}
use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method attributesBinding.
@Test
public void attributesBinding() throws Exception {
CoreEvent event = getEventWithError(empty());
SomeAttributes attributes = new SomeAttributes();
InternalMessage message = (InternalMessage) Message.builder().nullValue().attributesValue(attributes).build();
when(event.getMessage()).thenReturn(message);
TypedValue result = expressionLanguage.evaluate(ATTRIBUTES, event, BindingContext.builder().build());
assertThat(result.getValue(), is(equalTo(attributes)));
assertThat(result.getDataType().getType(), is((equalTo(SomeAttributes.class))));
}
use of org.mule.runtime.core.internal.message.InternalMessage 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.core.internal.message.InternalMessage in project mule by mulesoft.
the class MessageContextTestCase method payload.
@Test
public void payload() throws Exception {
InternalMessage message = mock(InternalMessage.class);
when(event.getMessage()).thenReturn(message);
Object payload = new Object();
when(message.getPayload()).thenReturn(new TypedValue<>(payload, DataType.OBJECT));
assertSame(payload, evaluate("message.payload", event));
}
use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class SimpleCollectionAggregatorTestCase method testAggregateMessageCollections.
@Test
public void testAggregateMessageCollections() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
SimpleCollectionAggregator router = new SimpleCollectionAggregator();
router.setMuleContext(muleContext);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext executionContext = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = of("test event A");
Message message2 = of("test event B");
Message message3 = of("test event C");
Message message4 = of("test event D");
List<Message> list = new ArrayList<>();
List<Message> list2 = new ArrayList<>();
list.add(message1);
list.add(message2);
list2.add(message3);
list2.add(message4);
Message messageCollection1 = Message.of(list);
Message messageCollection2 = Message.of(list2);
CoreEvent event1 = InternalEvent.builder(executionContext).message(messageCollection1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 2))).build();
CoreEvent event2 = InternalEvent.builder(executionContext).message(messageCollection2).groupCorrelation(Optional.of(GroupCorrelation.of(0, 2))).build();
assertNull(router.process(event1));
CoreEvent resultEvent = router.process(event2);
assertNotNull(resultEvent);
Message resultMessage = resultEvent.getMessage();
assertNotNull(resultMessage);
List<InternalMessage> payload = (List<InternalMessage>) resultMessage.getPayload().getValue();
assertEquals(2, payload.size());
assertEquals("test event A", ((List<InternalMessage>) payload.get(0).getPayload().getValue()).get(0).getPayload().getValue());
assertEquals("test event B", ((List<InternalMessage>) payload.get(0).getPayload().getValue()).get(1).getPayload().getValue());
assertEquals("test event C", ((List<InternalMessage>) payload.get(1).getPayload().getValue()).get(0).getPayload().getValue());
assertEquals("test event D", ((List<InternalMessage>) payload.get(1).getPayload().getValue()).get(1).getPayload().getValue());
}
Aggregations