1   /*
2    * $Id: AbstractXmlTransformerTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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      }
29  
30      // @Override
31      public boolean compareResults(Object expected, Object result)
32      {
33          if (expected instanceof Document && result instanceof Document)
34          {
35              return XMLUnit.compareXML((Document)expected, (Document)result).similar();
36          }
37          else if (expected instanceof String && result instanceof String)
38          {
39              try
40              {
41                  String expectedString = this.normalizeString((String)expected);
42                  String resultString = this.normalizeString((String)result);
43                  return XMLUnit.compareXML(expectedString, resultString).similar();
44              }
45              catch (Exception ex)
46              {
47                  return false;
48              }
49          }
50  
51          // all other comparisons are passed up
52          return super.compareResults(expected, result);
53      }
54  
55  }