View Javadoc

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