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 org.dom4j.io.OutputFormat;
14  import org.junit.Test;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertTrue;
18  
19  public class XmlPrettyPrinterTransformerTestCase extends AbstractTransformerTestCase
20  {
21      // Do not normalize any Strings for this test since we need to test formatting
22      @Override
23      protected String normalizeString(String rawString)
24      {
25          return rawString;
26      }
27  
28      @Override
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      @Override
36      public Transformer getRoundTripTransformer() throws Exception
37      {
38          // there is no XmlUnprettyPrinter :)
39          return null;
40      }
41  
42      @Override
43      public Object getTestData()
44      {
45          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><just><a><test>test</test></a></just>";
46      }
47  
48      @Override
49      public Transformer getTransformer() throws Exception
50      {
51          return createObject(XmlPrettyPrinter.class);
52      }
53  
54      @Test
55      public void testOutputOptions()
56      {
57          XmlPrettyPrinter t = new XmlPrettyPrinter();
58          OutputFormat f = t.getOutputFormat();
59          assertEquals(2, f.getIndent().length());
60          assertTrue(f.isPadText());
61  
62          t.setIndentSize(4);
63          t.setPadText(true);
64          assertEquals(4, f.getIndent().length());
65          assertTrue(f.isPadText());
66      }
67  }