use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class FlowExecutionLogger method assertRouteNthExecution.
public static void assertRouteNthExecution(String routeKey, int n, Object... values) {
waitUntilNthExecution(routeKey, n);
ExecutionLog executionLog = executionLogsMap.get(routeKey);
Message message = executionLog.getCollectedMessages().get(n - 1);
if (message.getPayload().getValue() instanceof List) {
List<TypedValue> aggregatedElements = (List<TypedValue>) message.getPayload().getValue();
assertThat(aggregatedElements.stream().map(element -> element.getValue()).collect(toList()), contains(values));
} else {
assertThat(values, arrayWithSize(1));
assertThat(message.getPayload().getValue(), is(equalTo(values[0])));
}
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class AbstractAddVariablePropertyProcessorTestCase method testAddVariableWithNullExpressionValueResult.
@Test
public void testAddVariableWithNullExpressionValueResult() throws MuleException {
addVariableProcessor.setIdentifier(PLAIN_STRING_KEY);
TypedValue typedValue = new TypedValue(null, DataType.OBJECT);
when(mockExpressionManager.evaluate(NULL_EXPRESSION, event)).thenReturn(typedValue);
addVariableProcessor.setValue(NULL_EXPRESSION);
addVariableProcessor.initialise();
event = addVariableProcessor.process(event);
verifyRemoved(event, PLAIN_STRING_KEY);
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method payloadBinding.
@Test
public void payloadBinding() 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(PAYLOAD, event, BindingContext.builder().build());
assertThat(result.getValue(), is(equalTo(payload.getValue())));
assertThat(result.getDataType(), is(equalTo(payload.getDataType())));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method childErrorsErrorBinding.
@Test
public void childErrorsErrorBinding() throws Exception {
String childErrorMessage = "error";
String otherChildErrorMessage = "oops";
ErrorType errorType = mock(ErrorType.class);
Error error = mock(Error.class);
when(error.getChildErrors()).thenReturn(asList(ErrorBuilder.builder(new IOException(childErrorMessage)).errorType(errorType).build(), ErrorBuilder.builder(new DefaultMuleException(otherChildErrorMessage)).errorType(errorType).build()));
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
String expression = "error.childErrors reduce ((child, acc = '') -> acc ++ child.cause.message)";
TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
assertThat(result.getValue(), is(format("%s%s", childErrorMessage, otherChildErrorMessage)));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method noSequenceSizeItemSequenceInfoBinding.
@Test
public void noSequenceSizeItemSequenceInfoBinding() throws Exception {
CoreEvent event = spy(testEvent());
when(event.getItemSequenceInfo()).thenReturn(of(ItemSequenceInfo.of(43)));
TypedValue result = expressionLanguage.evaluate(ITEM_SEQUENCE_INFO + ".position", event, BindingContext.builder().build());
assertThat(result.getValue(), is(43));
result = expressionLanguage.evaluate(ITEM_SEQUENCE_INFO + ".sequenceSize", event, BindingContext.builder().build());
assertThat(result.getValue(), is(nullValue()));
}
Aggregations