Search in sources :

Example 6 with TransformerChain

use of org.mule.runtime.core.privileged.transformer.TransformerChain in project mule by mulesoft.

the class TransformerChainingTestCase method testTwoChainedTransformers.

@Test
public void testTwoChainedTransformers() throws Exception {
    AbstractTransformer validTransformer = (AbstractTransformer) this.getIncreaseByOneTransformer();
    assertNotNull(validTransformer);
    Message message = of(new Integer(0));
    Transformer messageTransformer = new TransformerChain(validTransformer, validTransformer);
    message = transformationService.applyTransformers(message, eventBuilder(muleContext).message(of(0)).build(), singletonList(messageTransformer));
    Object transformedMessage = message.getPayload().getValue();
    assertNotNull(transformedMessage);
    assertEquals(new Integer(2), transformedMessage);
}
Also used : Message(org.mule.runtime.api.message.Message) TransformerChain(org.mule.runtime.core.privileged.transformer.TransformerChain) Test(org.junit.Test)

Example 7 with TransformerChain

use of org.mule.runtime.core.privileged.transformer.TransformerChain in project mule by mulesoft.

the class TransformerChainingTestCase method testIgnoreBadInputBreaksChainWithTransformationOrderInvalidValid.

@Test
public void testIgnoreBadInputBreaksChainWithTransformationOrderInvalidValid() 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(invalidTransformer, validTransformer);
    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) {
    // ignore
    }
}
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)

Aggregations

TransformerChain (org.mule.runtime.core.privileged.transformer.TransformerChain)7 Test (org.junit.Test)6 Message (org.mule.runtime.api.message.Message)6 MuleException (org.mule.runtime.api.exception.MuleException)3 Transformer (org.mule.runtime.core.api.transformer.Transformer)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1 ResolverException (org.mule.runtime.core.internal.transformer.ResolverException)1