Search in sources :

Example 61 with TypedValue

use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.

the class ExtendedExpressionLanguageAdapterTestCase method variablesMutation.

@Test
@Description("Verifies that variables can be modified under MVEL but not DW.")
public void variablesMutation() throws Exception {
    CoreEvent event = testEvent();
    CoreEvent.Builder builder1 = builder(event);
    TypedValue result = expressionLanguageAdapter.evaluate(melify("flowVars.put(\'key\',\'value\')"), event, builder1, TEST_CONNECTOR_LOCATION, emptyBindingContext);
    assertThat(result.getValue(), is(nullValue()));
    assertThat(builder1.build().getVariables().keySet(), contains("key"));
    CoreEvent.Builder builder2 = builder(event);
    TypedValue result2 = expressionLanguageAdapter.evaluate("vars.put(\'key\',\'value\')", event, builder2, TEST_CONNECTOR_LOCATION, emptyBindingContext);
    assertThat(result2.getValue(), is(nullValue()));
    assertThat(builder2.build().getVariables().keySet(), not(contains("key")));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 62 with TypedValue

use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.

the class ExtendedExpressionLanguageAdapterTestCase method payloadMutation.

@Test
@Description("Verifies that the payload can be modified under MVEL but not DW.")
public void payloadMutation() throws Exception {
    CoreEvent event = eventBuilder(muleContext).message(of(1)).build();
    CoreEvent.Builder builder1 = builder(event);
    String expression = "payload = 3";
    TypedValue result = expressionLanguageAdapter.evaluate(melify(expression), event, builder1, TEST_CONNECTOR_LOCATION, emptyBindingContext);
    assertThat(result.getValue(), is(1));
    assertThat(builder1.build().getMessage().getPayload().getValue(), is(3));
    CoreEvent.Builder builder2 = builder(event);
    expectedException.expect(ExpressionRuntimeException.class);
    expressionLanguageAdapter.evaluate(expression, event, builder2, TEST_CONNECTOR_LOCATION, emptyBindingContext);
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 63 with TypedValue

use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.

the class MVELExpressionLanguageTestCase method returnsDataType.

@Test
public void returnsDataType() throws Exception {
    DataType dataType = DataType.builder().type(String.class).mediaType(JSON).charset(UTF_16.name()).build();
    CoreEvent event = createEvent(TEST_MESSAGE, dataType);
    TypedValue typedValue = evaluateTyped("payload", event);
    assertThat((String) typedValue.getValue(), equalTo(TEST_MESSAGE));
    assertThat(typedValue.getDataType(), like(String.class, JSON, UTF_16));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) Matchers.containsString(org.hamcrest.Matchers.containsString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 64 with TypedValue

use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.

the class DefaultExpressionManagerMelDefaultTestCase method simpleCustomVariable.

@Test
@Description("Verifies that custom variables are considered.")
public void simpleCustomVariable() {
    Object object = new Object();
    BindingContext context = builder().addBinding(MY_VAR, new TypedValue(object, OBJECT)).build();
    assertThat(expressionManager.evaluate("#[myVar]", context).getValue(), equalTo(object));
}
Also used : BindingContext(org.mule.runtime.api.el.BindingContext) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 65 with TypedValue

use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.

the class DefaultExpressionManagerTestCase method transformationNotNeeded.

@Test
@Description("Verifies that a simple transformation works even when it's not required.")
public void transformationNotNeeded() throws MuleException {
    String expression = "payload";
    TypedValue result = expressionManager.evaluate(expression, STRING, builder().build(), testEvent());
    assertThat(result.getValue(), is(TEST_PAYLOAD));
    assertThat(result.getDataType(), is(STRING));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) 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