use of org.mule.runtime.core.privileged.event.PrivilegedEvent 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.runtime.core.privileged.event.PrivilegedEvent 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.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class VariablesTestCase method variableFromSessionScope.
@Test
public void variableFromSessionScope() throws Exception {
Message message = of("");
PrivilegedEvent event = (PrivilegedEvent) InternalEvent.builder(context).message(message).build();
event.getSession().setProperty("foo", "bar");
assertEquals(event.getSession().getProperty("foo"), evaluate("foo", event));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class VariablesTestCase method assignValueToNewSessionVariable.
@Test
public void assignValueToNewSessionVariable() throws Exception {
Message message = of("");
CoreEvent event = InternalEvent.builder(context).message(message).build();
evaluate("sessionVars['foo']='bar'", event);
assertEquals("bar", ((PrivilegedEvent) event).getSession().getProperty("foo"));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class VariablesTestCase method assignValueToSessionVariable.
@Test
public void assignValueToSessionVariable() throws Exception {
Message message = of("");
PrivilegedEvent event = (PrivilegedEvent) InternalEvent.builder(context).message(message).build();
event.getSession().setProperty("foo", "bar_old");
evaluate("sessionVars['foo']='bar'", event);
assertEquals("bar", event.getSession().getProperty("foo"));
}
Aggregations