1   /*
2    * $Id: AbstractXmlTransformerTestCase.java 10395 2008-01-18 15:27:42Z 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  
15  import org.custommonkey.xmlunit.XMLUnit;
16  import org.w3c.dom.Document;
17  
18  /**
19   * Use this superclass if you intend to compare Xml contents.
20   */
21  public abstract class AbstractXmlTransformerTestCase extends AbstractTransformerTestCase
22  {
23  
24      protected AbstractXmlTransformerTestCase()
25      {
26          super();
27          XMLUnit.setIgnoreWhitespace(true);
28          XMLUnit.setXSLTVersion("2.0");
29      }
30  
31      // @Override
32      public boolean compareResults(Object expected, Object result)
33      {
34          if (expected instanceof Document && result instanceof Document)
35          {
36              return XMLUnit.compareXML((Document)expected, (Document)result).similar();
37          }
38          else if (expected instanceof String && result instanceof String)
39          {
40              try
41              {
42                  String expectedString = this.normalizeString((String)expected);
43                  String resultString = this.normalizeString((String)result);
44                  return XMLUnit.compareXML(expectedString, resultString).similar();
45              }
46              catch (Exception ex)
47              {
48                  return false;
49              }
50          }
51  
52          // all other comparisons are passed up
53          return super.compareResults(expected, result);
54      }
55  
56  }