use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method nullItemSequenceInfoBinding.
@Test
public void nullItemSequenceInfoBinding() throws Exception {
CoreEvent event = testEvent();
TypedValue result = expressionLanguage.evaluate(ITEM_SEQUENCE_INFO, event, BindingContext.builder().build());
assertThat(result.getValue(), is(nullValue()));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method variablesCannotOverrideEventBindings.
@Test
public void variablesCannotOverrideEventBindings() throws MuleException {
CoreEvent event = spy(testEvent());
TypedValue<String> varValue = new TypedValue<>("", STRING);
ImmutableMap<String, TypedValue<?>> variablesMap = ImmutableMap.<String, TypedValue<?>>builder().put(PAYLOAD, varValue).put(ATTRIBUTES, varValue).put(ERROR, varValue).put(VARS, varValue).put(FLOW, varValue).build();
when(event.getVariables()).thenReturn(variablesMap);
String flowName = "myFlowName";
assertThat(expressionLanguage.evaluate(PAYLOAD, event, BindingContext.builder().build()).getValue(), is(TEST_PAYLOAD));
assertThat(expressionLanguage.evaluate(ATTRIBUTES, event, BindingContext.builder().build()).getValue(), is(nullValue()));
assertThat(expressionLanguage.evaluate(ERROR, event, BindingContext.builder().build()).getValue(), is(nullValue()));
assertThat(expressionLanguage.evaluate(VARS, event, BindingContext.builder().build()).getValue(), is(instanceOf(Map.class)));
assertThat(expressionLanguage.evaluate("flow.name", event, fromSingleComponent(flowName), BindingContext.builder().build()).getValue(), is(flowName));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method fullErrorBinding.
@Test
public void fullErrorBinding() throws Exception {
String description = "An error occurred";
String detailedDescription = "A division by zero has collapsed our systems.";
String exceptionMessage = "dividend cannot be zero";
String errorId = "WEAVE_TEST";
ErrorType errorType = mock(ErrorType.class);
when(errorType.getIdentifier()).thenReturn(errorId);
Error error = ErrorBuilder.builder().description(description).detailedDescription(detailedDescription).exception(new IllegalArgumentException(exceptionMessage)).errorType(errorType).build();
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
String expression = "'$(error.description) $(error.detailedDescription) $(error.cause.message) $(error.errorType.identifier)'";
TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
assertThat(result.getValue(), is(format("%s %s %s %s", description, detailedDescription, exceptionMessage, errorId)));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method authenticationBindingWhenNullSecurityContext.
@Test
public void authenticationBindingWhenNullSecurityContext() throws Exception {
CoreEvent event = spy(testEvent());
TypedValue result = expressionLanguage.evaluate(AUTHENTICATION, event, BindingContext.builder().build());
assertThat(result.getValue(), is(nullValue()));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method splitByJson.
@Test
public void splitByJson() throws Exception {
CoreEvent jsonMessage = eventBuilder(muleContext).message(Message.builder().value("[1,2,3]").mediaType(APPLICATION_JSON).build()).build();
Iterator<TypedValue<?>> payload = expressionLanguage.split("payload", jsonMessage, BindingContext.builder().build());
assertThat(payload.hasNext(), is(true));
assertThat(payload.next().getValue().toString(), is("1"));
assertThat(payload.hasNext(), is(true));
assertThat(payload.next().getValue().toString(), is("2"));
assertThat(payload.hasNext(), is(true));
assertThat(payload.next().getValue().toString(), is("3"));
assertThat(payload.hasNext(), is(false));
}
Aggregations