1   /*
2    * $Id: InlineXsltTransformerTestCase.java 12370 2008-07-17 13:11:17Z tcarlson $
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.api.transformer.Transformer;
14  import org.mule.module.xml.transformer.XsltTransformer;
15  import org.mule.module.xml.util.XMLTestUtils;
16  import org.mule.util.IOUtils;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  
21  public class InlineXsltTransformerTestCase extends AbstractXmlTransformerTestCase
22  {
23  
24      private String srcData;
25      private String resultData;
26  
27      protected void doSetUp() throws Exception
28      {
29          srcData = IOUtils.getResourceAsString("simple.xml", getClass());
30          resultData = IOUtils.getResourceAsString("simple-out.xml", getClass());
31      }
32  
33      public Transformer getTransformer() throws Exception
34      {
35          XsltTransformer transformer = new XsltTransformer();
36          transformer.setXslt("<?xml version='1.0'?>\n"
37                              + "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n"
38                              + "<xsl:output method='xml'/>\n" + "<xsl:template match='/'>\n"
39                              + "  <some-xml>\n" + "    <xsl:copy-of select='.'/>\n" + "  </some-xml>\n"
40                              + "</xsl:template>\n" + "</xsl:stylesheet>");
41          transformer.setReturnClass(String.class);
42          transformer.initialise();
43          return transformer;
44      }
45  
46      public Transformer getRoundTripTransformer() throws Exception
47      {
48          return null;
49      }
50  
51      public void testRoundtripTransform() throws Exception
52      {
53          // disable this test
54      }
55  
56      public Object getTestData()
57      {
58          return srcData;
59      }
60  
61      public Object getResultData()
62      {
63          return resultData;
64      }
65  
66      public void testAllXmlMessageTypes() throws Exception
67      {
68          List list = XMLTestUtils.getXmlMessageVariants("simple.xml");
69          Iterator it = list.iterator();
70          
71          Object expectedResult = getResultData();
72          assertNotNull(expectedResult);
73          
74          Object msg, result;
75          while (it.hasNext())
76          {
77              msg = it.next();
78              // TODO Not working for XMLStreamReader 
79              if (!(msg instanceof javax.xml.stream.XMLStreamReader))
80              {
81                  result = getTransformer().transform(msg);
82                  assertNotNull(result);
83                  assertTrue("Test failed for message type: " + msg.getClass(), compareResults(expectedResult, result));
84              }
85          }        
86      }
87  }