use of org.mule.mvel2.compiler.CompiledExpression 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.mvel2.compiler.CompiledExpression 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));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.
the class PayloadEnricherDataTypePropagatorTestCase method doPayloadDataTypeTest.
private void doPayloadDataTypeTest(String expression) throws Exception {
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
dataTypePropagator.propagate((PrivilegedEvent) testEvent(), builder, new TypedValue<>(TEST_MESSAGE, expectedDataType), compiledExpression);
final CoreEvent event = builder.build();
assertThat(event.getMessage().getPayload().getDataType(), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.
the class PayloadExpressionDataTypeResolverTestCase method doPayloadDataTypeTest.
private void doPayloadDataTypeTest(String expression) throws Exception {
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent event = PrivilegedEvent.builder(testEvent()).message(InternalMessage.builder(testEvent().getMessage()).value(TEST_MESSAGE).mediaType(expectedDataType.getMediaType()).build()).build();
assertThat(dataTypeResolver.resolve(event, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.
the class MVELExpressionLanguage method evaluate.
@Override
public TypedValue evaluate(String expression, CoreEvent event, CoreEvent.Builder eventBuilder, ComponentLocation componentLocation, BindingContext bindingContext) {
expression = removeExpressionMarker(expression);
Map<String, Object> bindingMap = bindingContext.identifiers().stream().collect(toMap(id -> id, id -> bindingContext.lookup(id).get().getValue()));
final Object value = evaluateUntyped(expression, (PrivilegedEvent) event, (PrivilegedEvent.Builder) eventBuilder, componentLocation, bindingMap);
if (value instanceof TypedValue) {
return (TypedValue) value;
} else {
final Serializable compiledExpression = expressionExecutor.getCompiledExpression(expression);
DataType dataType = event != null ? dataTypeResolver.resolve(value, (PrivilegedEvent) event, compiledExpression) : OBJECT;
return new TypedValue(value, dataType);
}
}
Aggregations