1   /*
2    * $Id: XsltTransformerTestCase.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.xml;
12  
13  import org.mule.umo.lifecycle.InitialisationException;
14  import org.mule.umo.transformer.UMOTransformer;
15  import org.mule.util.IOUtils;
16  
17  public class XsltTransformerTestCase extends AbstractXmlTransformerTestCase
18  {
19  
20      private String srcData;
21      private String resultData;
22  
23      // @Override
24      protected void doSetUp() throws Exception
25      {
26          srcData = IOUtils.getResourceAsString("cdcatalog.xml", getClass());
27          resultData = IOUtils.getResourceAsString("cdcatalog.html", getClass());
28      }
29  
30      public UMOTransformer getTransformer() throws Exception
31      {
32          XsltTransformer transformer = new XsltTransformer();
33          transformer.setXslFile("cdcatalog.xsl");
34          transformer.setMaxActiveTransformers(42);
35          transformer.initialise();
36          return transformer;
37      }
38  
39      public UMOTransformer getRoundTripTransformer() throws Exception
40      {
41          return null;
42      }
43  
44      // @Override
45      public void testRoundtripTransform() throws Exception
46      {
47          // disable this test
48      }
49  
50      public Object getTestData()
51      {
52          return srcData;
53      }
54  
55      public Object getResultData()
56      {
57          return resultData;
58      }
59  
60      public void testCustomTransformerFactoryClass() throws InitialisationException
61      {
62          XsltTransformer t = new XsltTransformer();
63          t.setXslTransformerFactory("com.nosuchclass.TransformerFactory");
64          t.setXslFile("cdcatalog.xsl");
65  
66          try
67          {
68              t.initialise();
69              fail("should have failed with ClassNotFoundException");
70          }
71          catch (InitialisationException iex)
72          {
73              assertEquals(ClassNotFoundException.class, iex.getCause().getClass());
74          }
75  
76          // try again with JDK default
77          t.setXslTransformerFactory(null);
78          t.initialise();
79      }
80  
81      // @Override
82      protected void doTestClone(UMOTransformer original, UMOTransformer clone) throws Exception
83      {
84          super.doTestClone(original, clone);
85  
86          XsltTransformer t1 = (XsltTransformer) original;
87          XsltTransformer t2 = (XsltTransformer) clone;
88  
89          // The transformerPool must be a new instance
90          assertNotSame("transformerPool", t1.transformerPool, t2.transformerPool);
91          // ..but it must have the same config value
92          assertEquals("transformerPool.maxActive", t1.getMaxActiveTransformers(), t2
93              .getMaxActiveTransformers());
94      }
95  
96  }