001: package org.apache.commons.betwixt.xmlunit;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: import java.io.File;
021: import java.io.FileInputStream;
022:
023: import junit.framework.AssertionFailedError;
024:
025: import org.xml.sax.InputSource;
026:
027: /**
028: * Test harness which test xml unit
029: *
030: * @author Robert Burrell Donkin
031: * @version $Id: TestXmlTestCase.java 438373 2006-08-30 05:17:21Z bayard $
032: */
033: public class TestXmlTestCase extends XmlTestCase {
034:
035: public TestXmlTestCase(String name) {
036: super (name);
037: }
038:
039: public void testXMLUnit() throws Exception {
040: xmlAssertIsomorphicContent(
041: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
042: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"));
043: }
044:
045: public void testXMLUnit2() throws Exception {
046: boolean failed = false;
047: try {
048: xmlAssertIsomorphicContent(
049: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
050: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-morphed.xml"),
051: false);
052: failed = true;
053: } catch (AssertionFailedError er) {
054: // this is expected
055: }
056: if (failed) {
057: fail("Expected unit test to fail!");
058: }
059: }
060:
061: public void testXMLUnit3() throws Exception {
062: boolean failed = false;
063: try {
064: xmlAssertIsomorphicContent(
065: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
066: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-not.xml"));
067: failed = true;
068: } catch (AssertionFailedError er) {
069: // this is expected
070: }
071: if (failed) {
072: fail("Expected unit test to fail!");
073: }
074: }
075:
076: public void testXMLUnit4() throws Exception {
077: xmlAssertIsomorphicContent(
078: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
079: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-morphed.xml"),
080: true);
081: }
082:
083: public void testXMLUnit5() throws Exception {
084: boolean failed = false;
085: try {
086: xmlAssertIsomorphicContent(
087: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example.xml"),
088: parseFile("src/test/org/apache/commons/betwixt/xmlunit/rss-example-not.xml"),
089: true);
090: failed = true;
091: } catch (AssertionFailedError er) {
092: // this is expected
093: }
094: if (failed) {
095: fail("Expected unit test to fail!");
096: }
097: }
098:
099: public void testXMLUnit6() throws Exception {
100: boolean failed = false;
101: try {
102: xmlAssertIsomorphicContent(
103: parseFile("src/test/org/apache/commons/betwixt/xmlunit/scarab-one.xml"),
104: parseFile("src/test/org/apache/commons/betwixt/xmlunit/scarab-two.xml"),
105: true);
106: failed = true;
107: } catch (AssertionFailedError er) {
108: // this is expected
109: }
110: if (failed) {
111: fail("Expected unit test to fail!");
112: }
113: }
114:
115: public void testValidateSchemaValidOne() throws Exception {
116: String basedir = System.getProperty("basedir");
117: InputSource document = new InputSource(
118: new FileInputStream(
119: new File(basedir,
120: "src/test/org/apache/commons/betwixt/xmlunit/valid.xml")));
121: InputSource schema = new InputSource(
122: new FileInputStream(
123: new File(basedir,
124: "src/test/org/apache/commons/betwixt/xmlunit/test.xsd")));
125: assertTrue(isValid(document, schema));
126: }
127:
128: public void testValidateSchemaInvalidOne() throws Exception {
129: String basedir = System.getProperty("basedir");
130: InputSource document = new InputSource(
131: new FileInputStream(
132: new File(basedir,
133: "src/test/org/apache/commons/betwixt/xmlunit/invalid.xml")));
134: InputSource schema = new InputSource(
135: new FileInputStream(
136: new File(basedir,
137: "src/test/org/apache/commons/betwixt/xmlunit/test.xsd")));
138: assertFalse(isValid(document, schema));
139: }
140:
141: public void testValidateSchemaValidTwo() throws Exception {
142: String basedir = System.getProperty("basedir");
143: InputSource document = new InputSource(
144: new FileInputStream(
145: new File(basedir,
146: "src/test/org/apache/commons/betwixt/xmlunit/valid-personnel-schema.xml")));
147: InputSource schema = new InputSource(
148: new FileInputStream(
149: new File(basedir,
150: "src/test/org/apache/commons/betwixt/xmlunit/personnel.xsd")));
151: assertTrue(isValid(document, schema));
152: }
153:
154: public void testValidateSchemaInvalidTwo() throws Exception {
155: String basedir = System.getProperty("basedir");
156: InputSource document = new InputSource(
157: new FileInputStream(
158: new File(basedir,
159: "src/test/org/apache/commons/betwixt/xmlunit/invalid-personnel-schema.xml")));
160: InputSource schema = new InputSource(
161: new FileInputStream(
162: new File(basedir,
163: "src/test/org/apache/commons/betwixt/xmlunit/personnel.xsd")));
164: assertFalse(isValid(document, schema));
165: }
166:
167: }
|