Search in sources :

Example 6 with PrivilegedEvent

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

Example 7 with PrivilegedEvent

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

Example 8 with PrivilegedEvent

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

Example 9 with PrivilegedEvent

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);
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) ArrayList(java.util.ArrayList) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) Test(org.junit.Test)

Example 10 with PrivilegedEvent

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) 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