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
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
29
30
31
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
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
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
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
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 }