1 package org.apache.commons.betwixt.xmlunit;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.File;
20 import java.io.FileInputStream;
21
22 import junit.framework.AssertionFailedError;
23
24 import org.xml.sax.InputSource;
25
26 /***
27 * Test harness which test xml unit
28 *
29 * @author Robert Burrell Donkin
30 * @version $Id: TestXmlTestCase.java 155402 2005-02-26 12:52:00Z dirkv $
31 */
32 public class TestXmlTestCase extends XmlTestCase {
33
34 public TestXmlTestCase(String name) {
35 super(name);
36 }
37
38 public void testXMLUnit() throws Exception {
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 {
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
54 }
55 if (failed) {
56 fail("Expected unit test to fail!");
57 }
58 }
59
60 public void testXMLUnit3() throws Exception {
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
69 }
70 if (failed) {
71 fail("Expected unit test to fail!");
72 }
73 }
74
75
76 public void testXMLUnit4() throws Exception {
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 {
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
94 }
95 if (failed) {
96 fail("Expected unit test to fail!");
97 }
98 }
99
100
101 public void testXMLUnit6() throws Exception {
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
111 }
112 if (failed) {
113 fail("Expected unit test to fail!");
114 }
115 }
116
117 public void testValidateSchemaValidOne() throws Exception {
118 String basedir = System.getProperty("basedir");
119 InputSource document = new InputSource(new FileInputStream(
120 new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/valid.xml")));
121 InputSource schema = new InputSource(new FileInputStream(
122 new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/test.xsd")));
123 assertTrue(isValid(document, schema));
124 }
125
126
127 public void testValidateSchemaInvalidOne() throws Exception {
128 String basedir = System.getProperty("basedir");
129 InputSource document = new InputSource(new FileInputStream(
130 new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/invalid.xml")));
131 InputSource schema = new InputSource(new FileInputStream(
132 new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/test.xsd")));
133 assertFalse(isValid(document, schema));
134 }
135
136 public void testValidateSchemaValidTwo() throws Exception {
137 String basedir = System.getProperty("basedir");
138 InputSource document = new InputSource(new FileInputStream(
139 new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/valid-personnel-schema.xml")));
140 InputSource schema = new InputSource(new FileInputStream(
141 new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/personnel.xsd")));
142 assertTrue(isValid(document, schema));
143 }
144
145
146 public void testValidateSchemaInvalidTwo() throws Exception {
147 String basedir = System.getProperty("basedir");
148 InputSource document = new InputSource(new FileInputStream(
149 new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/invalid-personnel-schema.xml")));
150 InputSource schema = new InputSource(new FileInputStream(
151 new File(basedir,"src/test/org/apache/commons/betwixt/xmlunit/personnel.xsd")));
152 assertFalse(isValid(document, schema));
153 }
154
155 }