1   package org.apache.commons.betwixt.xmlunit;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */ 
19  
20  import java.io.File;
21  import java.io.FileInputStream;
22  
23  import junit.framework.AssertionFailedError;
24  
25  import org.xml.sax.InputSource;
26  
27  /**
28   * Test harness which test xml unit
29   *
30   * @author Robert Burrell Donkin
31   * @version $Id: TestXmlTestCase.java 438373 2006-08-30 05:17:21Z bayard $
32   */
33   public class TestXmlTestCase extends XmlTestCase {
34   
35      public TestXmlTestCase(String name) {
36          super(name);
37      }
38   
39      public void testXMLUnit() throws Exception {
40          xmlAssertIsomorphicContent(
41                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
42                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"));
43      }
44      
45      public void testXMLUnit2() throws Exception {
46          boolean failed = false;
47          try {
48              xmlAssertIsomorphicContent(
49                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
50                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-morphed.xml"),
51                      false);
52              failed = true;
53          } catch (AssertionFailedError er) {
54              // this is expected
55          }
56          if (failed) {
57              fail("Expected unit test to fail!");
58          }
59      }
60      
61      public void testXMLUnit3() throws Exception {
62          boolean failed = false;
63          try {
64              xmlAssertIsomorphicContent(
65                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
66                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-not.xml"));
67              failed = true;
68          } catch (AssertionFailedError er) {
69              // this is expected
70          }
71          if (failed) {
72              fail("Expected unit test to fail!");
73          }
74      }
75  
76      
77      public void testXMLUnit4() throws Exception {
78          xmlAssertIsomorphicContent(
79                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
80                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-morphed.xml"),
81                      true);
82      }
83      
84      
85      public void testXMLUnit5() throws Exception {
86          boolean failed = false;
87          try {
88              xmlAssertIsomorphicContent(
89                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
90                      parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-not.xml"),
91                      true);
92              failed = true;
93          } catch (AssertionFailedError er) {
94              // this is expected
95          }
96          if (failed) {
97              fail("Expected unit test to fail!");
98          }
99      }
100     
101     
102     public void testXMLUnit6() throws Exception {
103         boolean failed = false;
104         try {
105             xmlAssertIsomorphicContent(
106                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/scarab-one.xml"),
107                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/scarab-two.xml"),
108                     true);
109             failed = true;
110         } catch (AssertionFailedError er) {
111             // this is expected
112         }
113         if (failed) {
114             fail("Expected unit test to fail!");
115         }
116     }
117     
118     public void testValidateSchemaValidOne() throws Exception {
119         String basedir = System.getProperty("basedir");
120         InputSource document = new InputSource(new FileInputStream(
121             new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/valid.xml")));
122         InputSource schema = new InputSource(new FileInputStream(
123             new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/test.xsd")));
124         assertTrue(isValid(document, schema));
125     }
126   
127    
128     public void testValidateSchemaInvalidOne() throws Exception {
129         String basedir = System.getProperty("basedir");
130         InputSource document = new InputSource(new FileInputStream(
131             new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/invalid.xml")));
132         InputSource schema = new InputSource(new FileInputStream( 
133             new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/test.xsd")));
134         assertFalse(isValid(document, schema));
135     }
136     
137     public void testValidateSchemaValidTwo() throws Exception {
138         String basedir = System.getProperty("basedir");
139         InputSource document = new InputSource(new FileInputStream(
140             new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/valid-personnel-schema.xml")));
141         InputSource schema = new InputSource(new FileInputStream(
142             new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/personnel.xsd")));
143         assertTrue(isValid(document, schema));
144     }
145   
146    
147     public void testValidateSchemaInvalidTwo() throws Exception {
148         String basedir = System.getProperty("basedir");
149         InputSource document = new InputSource(new FileInputStream(
150             new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/invalid-personnel-schema.xml")));
151         InputSource schema = new InputSource(new FileInputStream( 
152             new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/personnel.xsd")));
153         assertFalse(isValid(document, schema));
154     }
155     
156 }