Search in sources :

Example 1 with PrivilegedEvent

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

Example 2 with PrivilegedEvent

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));
}
Also used : PropertyAccessException(org.mule.mvel2.PropertyAccessException) Arrays(java.util.Arrays) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) AbstractDataTypeBuilderFactory(org.mule.runtime.api.metadata.AbstractDataTypeBuilderFactory) URL(java.net.URL) JSON(org.mule.runtime.api.metadata.MediaType.JSON) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Random(java.util.Random) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) EXPRESSION_WITH_DELIMITER(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageTestCase.Variant.EXPRESSION_WITH_DELIMITER) MessageContext(org.mule.runtime.core.internal.el.context.MessageContext) BigDecimal(java.math.BigDecimal) OptimizerFactory(org.mule.mvel2.optimizers.OptimizerFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Map(java.util.Map) Function(org.mule.mvel2.ast.Function) Assert.fail(org.junit.Assert.fail) BigInteger(java.math.BigInteger) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) URI(java.net.URI) SAFE_REFLECTIVE(org.mule.mvel2.optimizers.OptimizerFactory.SAFE_REFLECTIVE) Parameterized(org.junit.runners.Parameterized) RegexExpressionLanguageFuntion(org.mule.runtime.core.internal.el.mvel.function.RegexExpressionLanguageFuntion) Collection(java.util.Collection) ValidationResult(org.mule.runtime.api.el.ValidationResult) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Message.of(org.mule.runtime.api.message.Message.of) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) CompileException(org.mule.mvel2.CompileException) STRING(org.mule.runtime.api.metadata.DataType.STRING) Matchers.is(org.hamcrest.Matchers.is) Mockito.withSettings(org.mockito.Mockito.withSettings) DefaultComponentLocation.fromSingleComponent(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.fromSingleComponent) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Pattern(java.util.regex.Pattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) ParserContext(org.mule.mvel2.ParserContext) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) BindingContext(org.mule.runtime.api.el.BindingContext) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) HashMap(java.util.HashMap) MuleManifest(org.mule.runtime.core.api.config.MuleManifest) DataHandler(javax.activation.DataHandler) EXPRESSION_STRAIGHT_UP(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageTestCase.Variant.EXPRESSION_STRAIGHT_UP) DYNAMIC(org.mule.mvel2.optimizers.OptimizerFactory.DYNAMIC) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) Calendar(java.util.Calendar) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) MuleException(org.mule.runtime.api.exception.MuleException) Component(org.mule.runtime.api.component.Component) MimeType(javax.activation.MimeType) Collections.singletonMap(java.util.Collections.singletonMap) LOCATION_KEY(org.mule.runtime.api.component.AbstractComponent.LOCATION_KEY) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) OBJECT(org.mule.runtime.api.metadata.DataType.OBJECT) TypedValue(org.mule.runtime.api.metadata.TypedValue) Rule(org.junit.Rule) FileReader(java.io.FileReader) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Test(org.junit.Test)

Example 3 with PrivilegedEvent

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

Example 4 with PrivilegedEvent

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

Example 5 with PrivilegedEvent

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DefaultComponentLocation.fromSingleComponent(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.fromSingleComponent) Component(org.mule.runtime.api.component.Component) 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