Search in sources :

Example 11 with PrivilegedEvent

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression)

Example 12 with PrivilegedEvent

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression)

Example 13 with PrivilegedEvent

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) Test(org.junit.Test)

Example 14 with PrivilegedEvent

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"));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 15 with PrivilegedEvent

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"));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) Test(org.junit.Test)

Aggregations

PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)56 Test (org.junit.Test)35 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)22 DataType (org.mule.runtime.api.metadata.DataType)17 Message (org.mule.runtime.api.message.Message)15 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)13 ParserContext (org.mule.mvel2.ParserContext)10 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)9 MuleException (org.mule.runtime.api.exception.MuleException)7 UTF_16 (java.nio.charset.StandardCharsets.UTF_16)6 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)6 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)6 TypedValue (org.mule.runtime.api.metadata.TypedValue)6 Processor (org.mule.runtime.core.api.processor.Processor)6 Serializable (java.io.Serializable)5 HashMap (java.util.HashMap)5 Message.of (org.mule.runtime.api.message.Message.of)5 IOException (java.io.IOException)4 BigDecimal (java.math.BigDecimal)4 BigInteger (java.math.BigInteger)4