use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class AbstractVarAssignmentDataTypePropagatorTestCase method doInnerAssignmentDataTypePropagationTest.
protected void doInnerAssignmentDataTypePropagationTest(String expression) throws Exception {
final DataType expectedDataType = DataType.builder().type(Map.class).mediaType(UNKNOWN).charset(CUSTOM_ENCODING).build();
final Map<String, String> propertyValue = new HashMap<>();
propertyValue.put(INNER_PROPERTY_NAME, TEST_MESSAGE);
PrivilegedEvent event = setVariable((PrivilegedEvent) testEvent(), propertyValue, expectedDataType);
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(event);
CompiledExpression compiledExpression = compileMelExpression(expression, event, builder);
event = builder.build();
// Attempts to propagate a different dataType, which should be ignored
dataTypePropagator.propagate(event, builder, new TypedValue<>(propertyValue, DataType.STRING), compiledExpression);
event = builder.build();
assertThat(getVariableDataType(event), like(Map.class, UNKNOWN, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MvelEnricherDataTypePropagatorTestCase method invokesDataTypeAllPropagators.
@Test
public void invokesDataTypeAllPropagators() throws Exception {
CompiledExpression compiledExpression = compileMelExpression();
final List<EnricherDataTypePropagator> propagators = new ArrayList<>();
propagators.add(propagator1);
propagators.add(propagator2);
MvelEnricherDataTypePropagator dataTypePropagator = new MvelEnricherDataTypePropagator(propagators);
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
dataTypePropagator.propagate(typedValue, (PrivilegedEvent) testEvent(), builder, compiledExpression);
verify(propagator1).propagate((PrivilegedEvent) testEvent(), builder, typedValue, compiledExpression);
verify(propagator2).propagate((PrivilegedEvent) testEvent(), builder, typedValue, compiledExpression);
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MvelExpressionDataTypeResolverTestCase method returnsDefaultDataTypeForNonNullValue.
@Test
public void returnsDefaultDataTypeForNonNullValue() throws Exception {
CompiledExpression compiledExpression = compileMelExpression();
dataTypeResolver = new MvelDataTypeResolver(EMPTY_LIST);
assertThat(dataTypeResolver.resolve(EXPRESSION_VALUE, (PrivilegedEvent) testEvent(), compiledExpression), like(String.class, ANY, null));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class PropertyEnricherDataTypePropagatorTestCase method propagatesDataTypeForInlinedInvocationProperty.
@Test
public void propagatesDataTypeForInlinedInvocationProperty() 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("foo = 'unused'", new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent testEvent = this.<PrivilegedEvent.Builder>getEventBuilder().message(of(TEST_MESSAGE)).addVariable("foo", "bar").build();
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent);
dataTypePropagator.propagate(testEvent, builder, new TypedValue<>(TEST_MESSAGE, expectedDataType), compiledExpression);
assertThat(builder.build().getVariables().get("foo").getDataType(), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class PropertyExpressionDataTypeResolverTestCase method returnsInlineSessionPropertyDataType.
@Test
public void returnsInlineSessionPropertyDataType() throws Exception {
final String expression = "foo";
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) testEvent()).getSession().setProperty("foo", EXPRESSION_VALUE, expectedDataType);
assertThat(expressionDataTypeResolver.resolve((PrivilegedEvent) testEvent(), compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
Aggregations