KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > xmlunit > TestXmlTestCase


1 package org.apache.commons.betwixt.xmlunit;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21
22 import junit.framework.AssertionFailedError;
23
24 import org.xml.sax.InputSource JavaDoc;
25
26 /**
27  * Test harness which test xml unit
28  *
29  * @author Robert Burrell Donkin
30  * @version $Id: TestXmlTestCase.java,v 1.6 2004/06/13 21:32:49 rdonkin Exp $
31  */

32  public class TestXmlTestCase extends XmlTestCase {
33  
34     public TestXmlTestCase(String JavaDoc name) {
35         super(name);
36     }
37  
38     public void testXMLUnit() throws Exception JavaDoc {
39         xmlAssertIsomorphicContent(
40                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
41                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"));
42     }
43     
44     public void testXMLUnit2() throws Exception JavaDoc {
45         boolean failed = false;
46         try {
47             xmlAssertIsomorphicContent(
48                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
49                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-morphed.xml"),
50                     false);
51             failed = true;
52         } catch (AssertionFailedError er) {
53             // this is expected
54
}
55         if (failed) {
56             fail("Expected unit test to fail!");
57         }
58     }
59     
60     public void testXMLUnit3() throws Exception JavaDoc {
61         boolean failed = false;
62         try {
63             xmlAssertIsomorphicContent(
64                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
65                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-not.xml"));
66             failed = true;
67         } catch (AssertionFailedError er) {
68             // this is expected
69
}
70         if (failed) {
71             fail("Expected unit test to fail!");
72         }
73     }
74
75     
76     public void testXMLUnit4() throws Exception JavaDoc {
77         xmlAssertIsomorphicContent(
78                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
79                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-morphed.xml"),
80                     true);
81     }
82     
83     
84     public void testXMLUnit5() throws Exception JavaDoc {
85         boolean failed = false;
86         try {
87             xmlAssertIsomorphicContent(
88                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
89                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-not.xml"),
90                     true);
91             failed = true;
92         } catch (AssertionFailedError er) {
93             // this is expected
94
}
95         if (failed) {
96             fail("Expected unit test to fail!");
97         }
98     }
99     
100     
101     public void testXMLUnit6() throws Exception JavaDoc {
102         boolean failed = false;
103         try {
104             xmlAssertIsomorphicContent(
105                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/scarab-one.xml"),
106                     parseFile("src/test/org/apache/commons/betwixt/xmlunit/scarab-two.xml"),
107                     true);
108             failed = true;
109         } catch (AssertionFailedError er) {
110             // this is expected
111
}
112         if (failed) {
113             fail("Expected unit test to fail!");
114         }
115     }
116     
117     public void testValidateSchemaValidOne() throws Exception JavaDoc {
118         String JavaDoc basedir = System.getProperty("basedir");
119         InputSource JavaDoc document = new InputSource JavaDoc(new FileInputStream JavaDoc(
120             new File JavaDoc(basedir,"src/test/org/apache/commons/betwixt/xmlunit/valid.xml")));
121         InputSource JavaDoc schema = new InputSource JavaDoc(new FileInputStream JavaDoc(
122             new File JavaDoc(basedir,"src/test/org/apache/commons/betwixt/xmlunit/test.xsd")));
123         assertTrue(isValid(document, schema));
124     }
125   
126    
127     public void testValidateSchemaInvalidOne() throws Exception JavaDoc {
128         String JavaDoc basedir = System.getProperty("basedir");
129         InputSource JavaDoc document = new InputSource JavaDoc(new FileInputStream JavaDoc(
130             new File JavaDoc(basedir,"src/test/org/apache/commons/betwixt/xmlunit/invalid.xml")));
131         InputSource JavaDoc schema = new InputSource JavaDoc(new FileInputStream JavaDoc(
132             new File JavaDoc(basedir,"src/test/org/apache/commons/betwixt/xmlunit/test.xsd")));
133         assertFalse(isValid(document, schema));
134     }
135     
136     public void testValidateSchemaValidTwo() throws Exception JavaDoc {
137         String JavaDoc basedir = System.getProperty("basedir");
138         InputSource JavaDoc document = new InputSource JavaDoc(new FileInputStream JavaDoc(
139             new File JavaDoc(basedir,"src/test/org/apache/commons/betwixt/xmlunit/valid-personnel-schema.xml")));
140         InputSource JavaDoc schema = new InputSource JavaDoc(new FileInputStream JavaDoc(
141             new File JavaDoc(basedir,"src/test/org/apache/commons/betwixt/xmlunit/personnel.xsd")));
142         assertTrue(isValid(document, schema));
143     }
144   
145    
146     public void testValidateSchemaInvalidTwo() throws Exception JavaDoc {
147         String JavaDoc basedir = System.getProperty("basedir");
148         InputSource JavaDoc document = new InputSource JavaDoc(new FileInputStream JavaDoc(
149             new File JavaDoc(basedir,"src/test/org/apache/commons/betwixt/xmlunit/invalid-personnel-schema.xml")));
150         InputSource JavaDoc schema = new InputSource JavaDoc(new FileInputStream JavaDoc(
151             new File JavaDoc(basedir,"src/test/org/apache/commons/betwixt/xmlunit/personnel.xsd")));
152         assertFalse(isValid(document, schema));
153     }
154     
155 }
Popular Tags