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