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")));
}
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);
}
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));
}
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));
}
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));
}
Aggregations