Search in sources :

Example 96 with Message

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

the class EventBenchmark method createMuleEventWithFlowVarsAndProperties.

private CoreEvent createMuleEventWithFlowVarsAndProperties(int numProperties) {
    InternalMessage.Builder builder = InternalMessage.builder().value(PAYLOAD);
    for (int i = 1; i <= numProperties; i++) {
        builder.addInboundProperty("InBoUnDpRoPeRtYkEy" + i, "val");
    }
    Message message = builder.build();
    CoreEvent event = createMuleEvent(message, numProperties);
    return event;
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Example 97 with Message

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

the class DefaultMessageContextTestCase method overrideCorrelationIdInContextSequence.

@Test
public void overrideCorrelationIdInContextSequence() {
    final Message message = of(TEST_PAYLOAD);
    final CoreEvent event = InternalEvent.builder(executionContextWithCorrelation).message(message).correlationId(CUSTOM_CORRELATION_ID).groupCorrelation(Optional.of(GroupCorrelation.of(6))).build();
    assertThat(event.getCorrelationId(), is(CUSTOM_CORRELATION_ID));
}
Also used : Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 98 with Message

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

the class DefaultMessageContextTestCase method correlationIdInContext.

@Test
public void correlationIdInContext() {
    final Message message = of(TEST_PAYLOAD);
    final CoreEvent event = InternalEvent.builder(executionContextWithCorrelation).message(message).build();
    assertThat(event.getCorrelationId(), is(CUSTOM_CORRELATION_ID));
}
Also used : Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 99 with Message

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

the class MessagingExceptionTestCase method payloadInfoException.

@Test
@Ignore("MULE-10266 review how the transformationService is obtained when building an exception.")
public void payloadInfoException() throws Exception {
    MuleException.verboseExceptions = true;
    CoreEvent testEvent = mock(CoreEvent.class);
    Object payload = mock(Object.class);
    // This has to be done this way since mockito doesn't allow to verify toString()
    when(payload.toString()).then(new FailAnswer("toString() expected not to be called."));
    Message muleMessage = of(payload);
    when(transformationService.transform(muleMessage, DataType.STRING)).thenThrow(new TransformerException(createStaticMessage("exception thrown")));
    when(testEvent.getMessage()).thenReturn(muleMessage);
    MessagingException e = new MessagingException(createStaticMessage(message), testEvent);
    assertThat(e.getInfo().get(PAYLOAD_INFO_KEY), is(TransformerException.class.getName() + " while getting payload: exception thrown"));
}
Also used : Message(org.mule.runtime.api.message.Message) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) Ignore(org.junit.Ignore) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 100 with Message

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

the class MessagingExceptionTestCase method payloadInfoConsumable.

@Test
public void payloadInfoConsumable() throws Exception {
    MuleException.verboseExceptions = true;
    CoreEvent testEvent = mock(CoreEvent.class);
    when(testEvent.getError()).thenReturn(empty());
    final ByteArrayInputStream payload = new ByteArrayInputStream(new byte[] {});
    Message muleMessage = of(payload);
    when(testEvent.getMessage()).thenReturn(muleMessage);
    MessagingException e = new MessagingException(createStaticMessage(message), testEvent);
    assertThat((String) e.getInfo().get(PAYLOAD_INFO_KEY), containsString(ByteArrayInputStream.class.getName() + "@"));
    verify(transformationService, never()).transform(muleMessage, DataType.STRING);
}
Also used : Message(org.mule.runtime.api.message.Message) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SmallTest(org.mule.tck.size.SmallTest) 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