View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transformers.xml;
8   
9   import org.mule.api.transformer.Transformer;
10  import org.mule.module.xml.transformer.XmlPrettyPrinter;
11  import org.mule.transformer.AbstractTransformerTestCase;
12  
13  import java.io.ByteArrayInputStream;
14  
15  import javax.xml.parsers.DocumentBuilderFactory;
16  
17  import static org.junit.Assert.fail;
18  
19  public class XmlDomPrettyPrinterTransformerTestCase extends AbstractTransformerTestCase
20  {
21      private static final String rawData ="<?xml version=\"1.0\" encoding=\"UTF-8\"?><just><a><test>test</test></a></just>";
22  
23      // Do not normalize any Strings for this test since we need to test formatting
24      protected String normalizeString(String rawString)
25      {
26          return rawData;
27      }
28  
29      public Object getResultData()
30      {
31          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" + "<just>\n" + "  <a>\n"
32                 + "    <test>test</test>\n" + "  </a>\n" + "</just>\n";
33      }
34  
35      public Transformer getRoundTripTransformer() throws Exception
36      {
37          // there is no XmlUnprettyPrinter :)
38          return null;
39      }
40  
41      public Object getTestData()
42      {
43          try
44          {
45              return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(rawData.getBytes()));
46          }
47          catch (Exception e)
48          {
49              fail(e.getMessage());
50              return null;
51          }
52  
53      }
54  
55      public Transformer getTransformer() throws Exception
56      {
57          return createObject(XmlPrettyPrinter.class);
58      }
59  }