View Javadoc

1   /*
2    * $Id: XmlDomPrettyPrinterTransformerTestCase.java 22377 2011-07-11 12:41:42Z dirk.olmes $
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  import static org.junit.Assert.fail;
22  
23  public class XmlDomPrettyPrinterTransformerTestCase extends AbstractTransformerTestCase
24  {
25      private static final String rawData ="<?xml version=\"1.0\" encoding=\"UTF-8\"?><just><a><test>test</test></a></just>";
26  
27      // Do not normalize any Strings for this test since we need to test formatting
28      protected String normalizeString(String rawString)
29      {
30          return rawData;
31      }
32  
33      public Object getResultData()
34      {
35          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" + "<just>\n" + "  <a>\n"
36                 + "    <test>test</test>\n" + "  </a>\n" + "</just>\n";
37      }
38  
39      public Transformer getRoundTripTransformer() throws Exception
40      {
41          // there is no XmlUnprettyPrinter :)
42          return null;
43      }
44  
45      public Object getTestData()
46      {
47          try
48          {
49              return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(rawData.getBytes()));
50          }
51          catch (Exception e)
52          {
53              fail(e.getMessage());
54              return null;
55          }
56  
57      }
58  
59      public Transformer getTransformer() throws Exception
60      {
61          return createObject(XmlPrettyPrinter.class);
62      }
63  }