001: /*
002: ******************************************************************
003: Copyright (c) 2001-2007, Jeff Martin, Tim Bacon
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: * Redistributions of source code must retain the above copyright
011: notice, this list of conditions and the following disclaimer.
012: * Redistributions in binary form must reproduce the above
013: copyright notice, this list of conditions and the following
014: disclaimer in the documentation and/or other materials provided
015: with the distribution.
016: * Neither the name of the xmlunit.sourceforge.net nor the names
017: of its contributors may be used to endorse or promote products
018: derived from this software without specific prior written
019: permission.
020:
021: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
022: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
023: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
024: FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
025: COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
026: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
027: BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
028: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
029: CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
030: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
031: ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
032: POSSIBILITY OF SUCH DAMAGE.
033:
034: ******************************************************************
035: */
036:
037: package org.custommonkey.xmlunit.examples;
038:
039: import java.io.StringReader;
040:
041: import junit.framework.TestCase;
042:
043: import org.custommonkey.xmlunit.NodeTest;
044: import org.custommonkey.xmlunit.NodeTestException;
045: import org.w3c.dom.Node;
046:
047: /**
048: * JUnit test for CountingNodeTester
049: */
050: public class test_CountingNodeTester extends TestCase {
051: private NodeTest test;
052: private CountingNodeTester tester;
053:
054: public void testPositivePath() throws Exception {
055: test = new NodeTest(new StringReader("<a><b>c</b></a>"));
056: tester = new CountingNodeTester(2);
057: test.performTest(tester, Node.ELEMENT_NODE);
058:
059: tester = new CountingNodeTester(1);
060: test.performTest(tester, Node.TEXT_NODE);
061:
062: tester = new CountingNodeTester(3);
063: test.performTest(tester, new short[] { Node.TEXT_NODE,
064: Node.ELEMENT_NODE });
065:
066: tester = new CountingNodeTester(0);
067: test.performTest(tester, Node.COMMENT_NODE);
068: }
069:
070: public void testNegativePath() throws Exception {
071: test = new NodeTest(new StringReader("<a><b>c</b></a>"));
072: try {
073: tester = new CountingNodeTester(2);
074: test.performTest(tester, Node.TEXT_NODE);
075: fail("Expected NodeTestException");
076: } catch (NodeTestException e) {
077: // failure, as expected
078: }
079:
080: try {
081: tester = new CountingNodeTester(1);
082: test.performTest(tester, Node.ELEMENT_NODE);
083: fail("Expected NodeTestException");
084: } catch (NodeTestException e) {
085: // failure, as expected
086: }
087:
088: try {
089: tester = new CountingNodeTester(2);
090: test.performTest(tester, new short[] { Node.TEXT_NODE,
091: Node.ELEMENT_NODE });
092: fail("Expected NodeTestException");
093: } catch (NodeTestException e) {
094: // failure, as expected
095: }
096:
097: try {
098: tester = new CountingNodeTester(1);
099: test.performTest(tester, Node.COMMENT_NODE);
100: fail("Expected NodeTestException");
101: } catch (NodeTestException e) {
102: // failure, as expected
103: }
104:
105: try {
106: tester = new CountingNodeTester(0);
107: test.performTest(tester, Node.TEXT_NODE);
108: fail("Expected NodeTestException");
109: } catch (NodeTestException e) {
110: // failure, as expected
111: }
112: }
113:
114: public test_CountingNodeTester(String name) {
115: super(name);
116: }
117:
118: }
|