1   /*
2    * $Id: TransformerChainingTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transformers;
12  
13  import org.mule.tck.AbstractMuleTestCase;
14  import org.mule.umo.transformer.TransformerException;
15  import org.mule.umo.transformer.UMOTransformer;
16  
17  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
18  
19  public class TransformerChainingTestCase extends AbstractMuleTestCase
20  {
21  
22      public UMOTransformer getTransformer() throws Exception
23      {
24          AbstractTransformer transformer = new AbstractTransformer()
25          {
26              protected Object doTransform(final Object src, final String encoding) throws TransformerException
27              {
28                  return src;
29              }
30          };
31          transformer.setName("root");
32          transformer.setReturnClass(this.getClass());
33          transformer.registerSourceType(String.class);
34          transformer.initialise();
35  
36          return transformer;
37      }
38  
39      public void testIgnoreBadInputDoesNotBreakChain() throws Exception
40      {
41          // Grrrr....
42          AbstractTransformer transformer = (AbstractTransformer) this.getTransformer();
43          assertNotNull(transformer);
44  
45          transformer.setIgnoreBadInput(true);
46          final AtomicBoolean nextCalled = new AtomicBoolean(false);
47          final Object marker = new Object();
48          transformer.setNextTransformer(new AbstractTransformer()
49          {
50  
51              protected Object doTransform(Object src, String encoding) throws TransformerException
52              {
53                  nextCalled.set(true);
54                  return marker;
55              }
56          });
57  
58          Object result = transformer.transform(this);
59          assertNotNull(result);
60          assertSame(marker, result);
61          assertTrue("Next transformer not called.", nextCalled.get());
62      }
63  
64  }