use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method regexFunction.
@Test
public void regexFunction() throws Exception {
final PrivilegedEvent testEvent = this.<PrivilegedEvent.Builder>getEventBuilder().message(of("TESTfooTEST")).build();
assertEquals("foo", evaluate("regex('TEST(\\\\w+)TEST')", testEvent));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method extensionTakesPrecedenceOverAutoResolved.
@Test
public void extensionTakesPrecedenceOverAutoResolved() throws Exception {
PrivilegedEvent event = this.<PrivilegedEvent.Builder>getEventBuilder().message(of("")).addVariable("foo", "other").build();
((MuleContextWithRegistries) muleContext).getRegistry().registerObject("key", (ExpressionLanguageExtension) context -> context.addVariable("foo", "bar"));
mvel.initialise();
assertEquals("bar", evaluate("foo", event));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method testEvaluateStringMuleEvent.
@Test
public void testEvaluateStringMuleEvent() throws Exception {
PrivilegedEvent event = createEvent();
// Literals
assertEquals("hi", evaluate("'hi'", event));
assertEquals(4, evaluate("2*2", event));
// Static context
assertEquals(Calendar.getInstance().getTimeZone(), evaluate("server.timeZone", event));
assertEquals(MuleManifest.getProductVersion(), evaluate("mule.version", event));
assertEquals(muleContext.getConfiguration().getId(), evaluate("app.name", event));
// Event context
assertEquals("myFlow", evaluate("flow.name", event));
assertEquals("foo", evaluate("message.payload", event));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class ExpressionLanguageEnrichmentTestCase method enrichFlowVariable.
@Test
public void enrichFlowVariable() throws Exception {
CoreEvent event = eventBuilder(muleContext).message(of("")).build();
CoreEvent.Builder eventBuilder = CoreEvent.builder(event);
expressionLanguage.enrich("flowVars['foo']", event, eventBuilder, ((Component) flowConstruct).getLocation(), "bar");
assertThat(eventBuilder.build().getVariables().get("foo").getValue(), is("bar"));
assertThat(((PrivilegedEvent) eventBuilder.build()).getSession().getProperty("foo"), nullValue());
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method collectionAccessPayloadChangedMULE7506.
@Test
public void collectionAccessPayloadChangedMULE7506() throws Exception {
PrivilegedEvent event = this.<PrivilegedEvent.Builder>getEventBuilder().message(of(new String[] { "1", "2" })).build();
assertEquals("1", mvel.evaluateUntyped("payload[0]", event, PrivilegedEvent.builder(event), ((Component) flowConstruct).getLocation(), null));
event = PrivilegedEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value(singletonList("1")).build()).build();
assertEquals("1", mvel.evaluateUntyped("payload[0]", event, PrivilegedEvent.builder(event), ((Component) flowConstruct).getLocation(), null));
}
Aggregations