1   /*
2    * $Id: TransformerCloningTestCase.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.AbstractTransformerTestCase;
14  import org.mule.tck.MuleTestUtils;
15  import org.mule.umo.endpoint.UMOImmutableEndpoint;
16  import org.mule.umo.transformer.UMOTransformer;
17  
18  public class TransformerCloningTestCase extends AbstractTransformerTestCase
19  {
20  
21      public UMOTransformer getTransformer() throws Exception
22      {
23          NoActionTransformer t1 = new NoActionTransformer();
24          t1.setName("abstract");
25          t1.setReturnClass(this.getClass());
26          t1.registerSourceType(this.getClass());
27  
28          NoActionTransformer t2 = new NoActionTransformer();
29          t2.setName("nextTransformer");
30          t2.setReturnClass(this.getClass());
31          t2.registerSourceType(this.getClass());
32          t2.registerSourceType(StringBuffer.class);
33          
34          t1.setNextTransformer(t2);
35          t1.setEndpoint(MuleTestUtils.getTestEndpoint("abstract", UMOImmutableEndpoint.ENDPOINT_TYPE_SENDER));
36          t1.initialise();
37          return t1;
38      }
39  
40      public UMOTransformer getRoundTripTransformer() throws Exception
41      {
42          return null;
43      }
44  
45      public Object getTestData()
46      {
47          return this;
48      }
49  
50      public Object getResultData()
51      {
52          return this;
53      }
54  
55      // @Override
56      protected void doTestClone(UMOTransformer original, UMOTransformer clone) throws Exception
57      {
58          super.doTestClone(original, clone);
59  
60          NoActionTransformer t1 = (NoActionTransformer) original;
61          NoActionTransformer t2 = (NoActionTransformer) clone;
62  
63          // name must be equal
64          assertEquals("name", t1.name, t2.name);
65  
66          // returnClass must be equal
67          assertEquals("returnClass", t1.returnClass, t2.returnClass);
68  
69          // sourceTypes must be a copy
70          assertNotSame("sourceTypes", t1.sourceTypes, t2.sourceTypes);
71          assertEquals("sourceTypes", t1.sourceTypes, t2.sourceTypes);
72  
73          // TODO HH: is this correct? for now AbstractTransformer.clone() keeps the reference
74          assertSame("endpoint", t1.endpoint, t2.endpoint);
75  
76          // nextTransformer must be a copy of the entire chain!
77          assertNotSame("nextTransformer", t1.nextTransformer, t2.nextTransformer);
78      }
79  
80  }