Search in sources :

Example 41 with Message

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

the class TransformationServiceTestCase method skipsFirstConverterAppliesSecond.

@Test
public void skipsFirstConverterAppliesSecond() throws MuleException {
    // Converter(B -> C) Converter(C->D), payload C: skips converter(B->C), applies Converter(C->D)
    Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).build();
    Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).returning(new D()).build();
    Message message = of(new C());
    message = transformationService.applyTransformers(message, null, converter1, converter2);
    assertTrue(message.getPayload().getValue() instanceof D);
    verifyTransformerNotExecuted(converter1);
    verifyTransformerExecuted(converter2);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Message(org.mule.runtime.api.message.Message) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 42 with Message

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

the class TransformationServiceTestCase method failsOnFirstTransformerIgnoresSecondTransformer.

@Test
public void failsOnFirstTransformerIgnoresSecondTransformer() throws MuleException {
    // Transformer(B ->D) Transformer(C->D), payload C: FAIL
    Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).build();
    Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new C());
    try {
        transformationService.applyTransformers(message, null, transformer1, transformer2);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerNotExecuted(transformer1);
    verifyTransformerNotExecuted(transformer2);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) Message(org.mule.runtime.api.message.Message) MockTransformerBuilder(org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 43 with Message

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

the class TransformationServiceTestCase method appliesTransformerSkipsConverter.

@Test
public void appliesTransformerSkipsConverter() throws MuleException {
    // Transformer(B -> D) Converter(C->D), payload B: converts B->D, skips converter C->D, resulting output is of the expected
    // type -> OK
    Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).returning(new D()).build();
    Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new B());
    message = transformationService.applyTransformers(message, null, transformer1, converter2);
    assertTrue(message.getPayload().getValue() instanceof D);
    verifyTransformerExecuted(transformer1);
    verifyTransformerNotExecuted(converter2);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Message(org.mule.runtime.api.message.Message) MockTransformerBuilder(org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 44 with Message

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

the class TransformerChainingTestCase method testIgnoreBadInputBreaksChainWithTransformationOrderValidInvalid.

@Test
public void testIgnoreBadInputBreaksChainWithTransformationOrderValidInvalid() throws Exception {
    AbstractTransformer invalidTransformer = (AbstractTransformer) this.getInvalidTransformer();
    assertNotNull(invalidTransformer);
    invalidTransformer.setIgnoreBadInput(false);
    AbstractTransformer validTransformer = (AbstractTransformer) this.getIncreaseByOneTransformer();
    assertNotNull(validTransformer);
    Message message = of(new Integer(0));
    Transformer messageTransformer = new TransformerChain(validTransformer, invalidTransformer);
    try {
        transformationService.applyTransformers(message, eventBuilder(muleContext).message(of(0)).build(), messageTransformer);
        fail("Transformer chain is expected to fail because of invalid transformer within chain.");
    } catch (MuleException tfe) {
        assertNotNull(tfe);
    }
}
Also used : Message(org.mule.runtime.api.message.Message) TransformerChain(org.mule.runtime.core.privileged.transformer.TransformerChain) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 45 with Message

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

the class DefaultMessageContextTestCase method noCorrelationIdInContext.

@Test
public void noCorrelationIdInContext() {
    final Message message = of(TEST_PAYLOAD);
    final CoreEvent event = InternalEvent.builder(executionContext).message(message).build();
    assertThat(event.getCorrelationId(), is(GENERATED_CORRELATION_ID));
}
Also used : Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) 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