use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method testEvaluateMapOfStringObject.
@Test
public void testEvaluateMapOfStringObject() throws Exception {
PrivilegedEvent event = createEvent();
// Custom variables (via method param)
assertEquals(1, evaluate("foo", singletonMap("foo", 1)));
assertEquals("bar", evaluate("foo", singletonMap("foo", "bar")));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class AbstractVarAssignmentDataTypePropagatorTestCase method doAssignmentDataTypePropagationTest.
protected void doAssignmentDataTypePropagationTest(String expression) throws Exception {
DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
CompiledExpression compiledExpression = compileMelExpression(expression, (PrivilegedEvent) testEvent(), builder);
PrivilegedEvent event = builder.build();
dataTypePropagator.propagate(event, builder, new TypedValue<>(TEST_MESSAGE, expectedDataType), compiledExpression);
event = builder.build();
assertThat(getVariableDataType(event), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class AbstractVarExpressionDataTypeResolverTestCase method doVarDataTypeTest.
protected void doVarDataTypeTest(String expression) throws Exception {
DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
PrivilegedEvent event = setVariable((PrivilegedEvent) testEvent(), EXPRESSION_VALUE, expectedDataType);
final ParserConfiguration parserConfiguration = MVELExpressionLanguage.createParserConfiguration(Collections.EMPTY_MAP);
final MVELExpressionLanguageContext context = createMvelExpressionLanguageContext(event, parserConfiguration);
CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(parserConfiguration));
// Expression must be executed, otherwise the variable accessor is not properly configured
MVEL.executeExpression(compiledExpression, context);
assertThat(expressionDataTypeResolver.resolve(event, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MvelEnricherDataTypePropagatorTestCase method stopsCheckingDataTypePropagatorsAfterSuccessfulPropagation.
@Test
public void stopsCheckingDataTypePropagatorsAfterSuccessfulPropagation() throws Exception {
CompiledExpression compiledExpression = compileMelExpression();
final List<EnricherDataTypePropagator> propagators = new ArrayList<>();
propagators.add(propagator1);
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
when(propagator1.propagate((PrivilegedEvent) testEvent(), builder, typedValue, compiledExpression)).thenReturn(true);
propagators.add(propagator2);
MvelEnricherDataTypePropagator dataTypePropagator = new MvelEnricherDataTypePropagator(propagators);
dataTypePropagator.propagate(typedValue, (PrivilegedEvent) testEvent(), builder, compiledExpression);
verify(propagator1).propagate((PrivilegedEvent) testEvent(), builder, typedValue, compiledExpression);
verify(propagator2, never()).propagate((PrivilegedEvent) testEvent(), builder, typedValue, compiledExpression);
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MvelExpressionDataTypeResolverTestCase method returnsDefaultDataTypeForNullValue.
@Test
public void returnsDefaultDataTypeForNullValue() throws Exception {
CompiledExpression compiledExpression = compileMelExpression();
dataTypeResolver = new MvelDataTypeResolver();
assertThat(dataTypeResolver.resolve(null, (PrivilegedEvent) testEvent(), compiledExpression), like(Object.class, ANY, null));
}
Aggregations