use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method getEventWithError.
private CoreEvent getEventWithError(Optional<Error> error) {
CoreEvent event = mock(CoreEvent.class, RETURNS_DEEP_STUBS);
doReturn(error).when(event).getError();
when(event.getMessage().getPayload()).thenReturn(new TypedValue<>(null, OBJECT));
when(event.getMessage().getAttributes()).thenReturn(new TypedValue<>(null, OBJECT));
when(event.getAuthentication()).thenReturn(empty());
when(event.getItemSequenceInfo()).thenReturn(empty());
return event;
}
use of org.mule.runtime.core.api.event.CoreEvent 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.core.api.event.CoreEvent in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method payloadExpressionShouldNotBeEvaluate.
@Test
public void payloadExpressionShouldNotBeEvaluate() throws MuleException {
BindingContext bindingContext = BindingContext.builder().build();
MuleContext muleContext = mock(MuleContext.class);
DefaultExpressionLanguageFactoryService languageFactory = mock(DefaultExpressionLanguageFactoryService.class);
ExpressionLanguage expressionLanguage = spy(ExpressionLanguage.class);
when(languageFactory.create()).thenReturn(expressionLanguage);
CoreEvent event = testEvent();
new DataWeaveExpressionLanguageAdaptor(muleContext, registry, languageFactory).evaluate("#[payload]", event, bindingContext);
verify(expressionLanguage, never()).evaluate(eq("payload"), any(BindingContext.class));
}
use of org.mule.runtime.core.api.event.CoreEvent 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.core.api.event.CoreEvent 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)));
}
Aggregations