use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method flowNameBinding.
@Test
public void flowNameBinding() {
CoreEvent event = getEventWithError(empty());
String flowName = "myFlowName";
TypedValue result = expressionLanguage.evaluate("flow.name", event, fromSingleComponent(flowName), BindingContext.builder().build());
assertThat(result.getDataType(), is(assignableTo(STRING)));
assertThat(result.getValue(), is(flowName));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method entrySetFunction.
@Test
public void entrySetFunction() throws Exception {
final String key = "foo";
final String value = "bar";
CoreEvent event = eventBuilder(muleContext).message(Message.builder().value(singletonMap(key, value)).build()).build();
TypedValue result = expressionLanguage.evaluate("dw::core::Objects::entrySet(payload)", event, BindingContext.builder().build());
assertThat(result.getValue(), instanceOf(List.class));
assertThat(((List) result.getValue()).get(0), instanceOf(Map.class));
Map entry = (Map) ((List) result.getValue()).get(0);
assertThat(entry.get("key"), instanceOf(QualifiedName.class));
assertThat(((QualifiedName) entry.get("key")).name(), equalTo(key));
assertThat(entry.get("value"), equalTo(value));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method messageErrorBinding.
@Test
public void messageErrorBinding() throws Exception {
Error error = mock(Error.class);
when(error.getErrorMessage()).thenReturn(Message.of(new Integer[] { 1, 3, 6 }));
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
String expression = "error.errorMessage.payload reduce ($$ + $)";
TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
assertThat(result.getValue(), is(10));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method errorBinding.
@Test
public void errorBinding() throws Exception {
Error error = mock(Error.class);
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
TypedValue result = expressionLanguage.evaluate(ERROR, event, BindingContext.builder().build());
assertThat(result.getValue(), is(sameInstance(error)));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method expectedOutputShouldBeUsed.
@Test
public void expectedOutputShouldBeUsed() throws Exception {
CoreEvent jsonMessage = eventBuilder(muleContext).message(Message.builder().value("{\"student\": false}").mediaType(APPLICATION_JSON).build()).build();
TypedValue result = expressionLanguage.evaluate("payload.student", BOOLEAN, jsonMessage, BindingContext.builder().build());
assertThat(result.getValue(), is(false));
}
Aggregations