Search in sources :

Example 6 with TypedValue

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()));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 7 with TypedValue

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));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Matchers.containsString(org.hamcrest.Matchers.containsString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 8 with TypedValue

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)));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) Optional(java.util.Optional) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Error(org.mule.runtime.api.message.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 9 with TypedValue

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()));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 10 with TypedValue

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));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Aggregations

TypedValue (org.mule.runtime.api.metadata.TypedValue)97 Test (org.junit.Test)74 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)47 DataType (org.mule.runtime.api.metadata.DataType)17 Message (org.mule.runtime.api.message.Message)16 Description (io.qameta.allure.Description)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 List (java.util.List)11 SmallTest (org.mule.tck.size.SmallTest)10 BindingContext (org.mule.runtime.api.el.BindingContext)9 Map (java.util.Map)8 Optional (java.util.Optional)8 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)6 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)5 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 MuleException (org.mule.runtime.api.exception.MuleException)4 Error (org.mule.runtime.api.message.Error)4 ErrorType (org.mule.runtime.api.message.ErrorType)4