Search in sources :

Example 31 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class MVELExpressionLanguageTestCase method testEvaluateStringMuleMessage.

@Test
public void testEvaluateStringMuleMessage() throws Exception {
    PrivilegedEvent event = createEvent();
    // Event context
    assertEquals("foo", evaluate("message.payload", event));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Test(org.junit.Test)

Example 32 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class MVELExpressionLanguageTestCase method messageTakesPrecedenceOverEverything.

@Test
public void messageTakesPrecedenceOverEverything() throws Exception {
    mvel.setAliases(singletonMap("message", "'other1'"));
    PrivilegedEvent event = this.<PrivilegedEvent.Builder>getEventBuilder().message(of("")).addVariable("message", "other2").build();
    ((MuleContextWithRegistries) muleContext).getRegistry().registerObject("foo", (ExpressionLanguageExtension) context -> context.addVariable("message", "other3"));
    mvel.initialise();
    assertEquals(MessageContext.class, evaluate("message", event).getClass());
}
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 33 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class MVELExpressionLanguageTestCase method testEvaluateAttributes.

@Test
public void testEvaluateAttributes() throws Exception {
    PrivilegedEvent event = createEventWithAttributes();
    // Event context
    assertEquals("number 1", evaluate("attributes.one", event));
    assertEquals("number 2", evaluate("attributes.two", event));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Test(org.junit.Test)

Example 34 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class ExpressionLanguageEnrichmentTestCase method enrichSessionVariable.

@Test
public void enrichSessionVariable() throws Exception {
    CoreEvent event = eventBuilder(muleContext).message(Message.of("")).build();
    CoreEvent.Builder eventBuilder = CoreEvent.builder(event);
    expressionLanguage.enrich("sessionVars['foo']", event, eventBuilder, ((Component) flowConstruct).getLocation(), "bar");
    assertThat(((PrivilegedEvent) eventBuilder.build()).getSession().getProperty("foo"), equalTo("bar"));
    assertThat(eventBuilder.build().getVariables().keySet(), not(hasItem("foo")));
}
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 35 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class MVELExpressionLanguageTestCase method appTakesPrecedenceOverEverything.

@Test
public void appTakesPrecedenceOverEverything() throws Exception {
    mvel.setAliases(singletonMap("app", "'other1'"));
    PrivilegedEvent event = this.<PrivilegedEvent.Builder>getEventBuilder().message(of("")).addVariable("app", "otherb").build();
    ((MuleContextWithRegistries) muleContext).getRegistry().registerObject("foo", (ExpressionLanguageExtension) context -> context.addVariable("app", "otherc"));
    mvel.initialise();
    assertEquals(MVELArtifactContext.class, evaluate("app", event).getClass());
}
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)

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