Search in sources :

Example 56 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class MessageEnricherTestCase method doNotImplicitlyEnrichMessagePayload.

@Test
public void doNotImplicitlyEnrichMessagePayload() throws Exception {
    MessageEnricher enricher = baseEnricher();
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.myHeader]"));
    enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value("enriched").build()).build());
    Message out = process(enricher, testEvent()).getMessage();
    assertEquals(TEST_PAYLOAD, out.getPayload().getValue());
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JSON(org.mule.runtime.api.metadata.MediaType.JSON) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Message.of(org.mule.runtime.api.message.Message.of) Assert.assertNull(org.junit.Assert.assertNull) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Assert.assertEquals(org.junit.Assert.assertEquals) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Test(org.junit.Test)

Example 57 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class MessageEnricherTestCase method enrichSessionVariable.

@Test
public void enrichSessionVariable() throws Exception {
    MessageEnricher enricher = baseEnricher();
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:sessionVars['foo']]"));
    enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value("bar").build()).build());
    CoreEvent out = process(enricher, testEvent());
    assertEquals("bar", ((PrivilegedEvent) out).getSession().getProperty("foo"));
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JSON(org.mule.runtime.api.metadata.MediaType.JSON) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Message.of(org.mule.runtime.api.message.Message.of) Assert.assertNull(org.junit.Assert.assertNull) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Assert.assertEquals(org.junit.Assert.assertEquals) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Test(org.junit.Test)

Example 58 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class MessageEnricherTestCase method testEnrichHeaderWithPayload.

@Test
public void testEnrichHeaderWithPayload() throws Exception {
    MessageEnricher enricher = createEnricher();
    enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.myHeader]"));
    enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value(TEST_PAYLOAD).build()).build());
    initialiseIfNeeded(enricher, muleContext);
    Message result = process(enricher, testEvent()).getMessage();
    assertEquals(TEST_PAYLOAD, ((InternalMessage) result).getOutboundProperty("myHeader"));
    assertEquals(TEST_PAYLOAD, result.getPayload().getValue());
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JSON(org.mule.runtime.api.metadata.MediaType.JSON) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Message.of(org.mule.runtime.api.message.Message.of) Assert.assertNull(org.junit.Assert.assertNull) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Assert.assertEquals(org.junit.Assert.assertEquals) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Test(org.junit.Test)

Example 59 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class DefaultMuleMessageBuilderTestCase method createAPIMessageViaMessageInterfaceFromCopy.

@Test
public void createAPIMessageViaMessageInterfaceFromCopy() {
    org.mule.runtime.api.message.Message message;
    message = org.mule.runtime.api.message.Message.builder().value(TEST_PAYLOAD).build();
    org.mule.runtime.api.message.Message messageCopy;
    messageCopy = org.mule.runtime.api.message.Message.builder(message).value(true).attributesValue(BASE_ATTRIBUTES).build();
    assertThat(messageCopy.getPayload().getValue(), is(true));
    assertThat(messageCopy.getPayload().getDataType(), is(BOOLEAN));
    assertThat(messageCopy.getAttributes().getValue(), is(BASE_ATTRIBUTES));
    assertThat(messageCopy.getAttributes().getDataType(), is(BASE_ATTRIBUTES_DATATYPE));
}
Also used : Message(org.mule.runtime.api.message.Message) Test(org.junit.Test)

Example 60 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class DefaultMuleMessageBuilderTestCase method nullPayload.

@Test
public void nullPayload() {
    Message message = of(null);
    assertThat(message.getPayload().getDataType().getType(), equalTo(Object.class));
}
Also used : Message(org.mule.runtime.api.message.Message) DataType.fromObject(org.mule.runtime.api.metadata.DataType.fromObject) Test(org.junit.Test)

Aggregations

Message (org.mule.runtime.api.message.Message)226 Test (org.junit.Test)189 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)104 SmallTest (org.mule.tck.size.SmallTest)68 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)46 Transformer (org.mule.runtime.core.api.transformer.Transformer)35 DataType (org.mule.runtime.api.metadata.DataType)33 ArrayList (java.util.ArrayList)26 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)26 Processor (org.mule.runtime.core.api.processor.Processor)25 List (java.util.List)20 Assert.assertThat (org.junit.Assert.assertThat)19 ExpectedException (org.junit.rules.ExpectedException)19 MuleContextUtils.eventBuilder (org.mule.tck.util.MuleContextUtils.eventBuilder)19 Map (java.util.Map)18 Rule (org.junit.Rule)18 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)18 ExpectedException.none (org.junit.rules.ExpectedException.none)17 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)17 TypedValue (org.mule.runtime.api.metadata.TypedValue)16