View Javadoc

1   /*
2    * $Id: XmlDomPrettyPrinterTransformerTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.XmlPrettyPrinter;
15  import org.mule.transformer.AbstractTransformerTestCase;
16  
17  import java.io.ByteArrayInputStream;
18  
19  import javax.xml.parsers.DocumentBuilderFactory;
20  
21  public class XmlDomPrettyPrinterTransformerTestCase extends AbstractTransformerTestCase
22  {
23      private static final String rawData ="<?xml version=\"1.0\" encoding=\"UTF-8\"?><just><a><test>test</test></a></just>";
24  
25      // Do not normalize any Strings for this test since we need to test formatting
26      protected String normalizeString(String rawString)
27      {
28          return rawData;
29      }
30  
31      public Object getResultData()
32      {
33          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" + "<just>\n" + "  <a>\n"
34                 + "    <test>test</test>\n" + "  </a>\n" + "</just>\n";
35      }
36  
37      public Transformer getRoundTripTransformer() throws Exception
38      {
39          // there is no XmlUnprettyPrinter :)
40          return null;
41      }
42  
43      public Object getTestData()
44      {
45          try
46          {
47              return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(rawData.getBytes()));
48          }
49          catch (Exception e)
50          {
51              fail(e.getMessage());
52              return null;
53          }
54  
55      }
56  
57      public Transformer getTransformer() throws Exception
58      {
59          return createObject(XmlPrettyPrinter.class);
60      }
61  }