001: /*
002: ******************************************************************
003: Copyright (c) 2001, 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;
038:
039: import org.w3c.dom.Document;
040: import org.w3c.dom.Element;
041:
042: import junit.framework.TestCase;
043: import junit.framework.TestSuite;
044:
045: /**
046: * JUnit testcase for ElementNameEqualifier
047: */
048: public class test_ElementNameQualifier extends TestCase {
049: private Document document;
050: private ElementNameQualifier elementNameQualifier;
051: private static final String NAME_A = "nameA";
052: private static final String NAME_B = "nameB";
053:
054: public void testElementsNoNamespace() throws Exception {
055: Element control = document.createElement(NAME_A);
056: Element test = document.createElement(NAME_A);
057: assertTrue("nameA comparable to nameA", elementNameQualifier
058: .qualifyForComparison(control, test));
059:
060: test = document.createElement(NAME_B);
061: assertFalse("nameA not comparable to nameB",
062: elementNameQualifier
063: .qualifyForComparison(control, test));
064: }
065:
066: public void testElementsWithNamespace() throws Exception {
067: String anURI = "gopher://example.com";
068: String qnameQualifierA = "qnq:";
069:
070: Element control = document.createElementNS(anURI,
071: qnameQualifierA + NAME_A);
072: Element test = document.createElementNS(anURI, qnameQualifierA
073: + NAME_A);
074: assertTrue("qualified nameA comparable to nameA",
075: elementNameQualifier
076: .qualifyForComparison(control, test));
077:
078: test = document
079: .createElementNS(anURI, qnameQualifierA + NAME_B);
080: assertFalse("qualified nameA not comparable to nameB",
081: elementNameQualifier
082: .qualifyForComparison(control, test));
083:
084: String qnameQualifierB = "pgp:";
085: test = document
086: .createElementNS(anURI, qnameQualifierB + NAME_A);
087: assertTrue("qualified nameA comparable to requalified nameA",
088: elementNameQualifier
089: .qualifyForComparison(control, test));
090:
091: test = document
092: .createElementNS(anURI, qnameQualifierB + NAME_B);
093: assertFalse(
094: "qualified nameA not comparable to requalifiednameB",
095: elementNameQualifier
096: .qualifyForComparison(control, test));
097:
098: String anotherURI = "ftp://example.com";
099: test = document.createElementNS(anotherURI, qnameQualifierA
100: + NAME_A);
101: assertFalse(
102: "qualified nameA not comparable to anotherURI nameA",
103: elementNameQualifier
104: .qualifyForComparison(control, test));
105:
106: test = document.createElementNS(anotherURI, qnameQualifierB
107: + NAME_A);
108: assertFalse(
109: "qualified nameA comparable to requalified-anotherURI nameA",
110: elementNameQualifier
111: .qualifyForComparison(control, test));
112:
113: test = document.createElementNS(anotherURI, qnameQualifierB
114: + NAME_B);
115: assertFalse(
116: "qualified nameA not comparable to requalified-anotherURI nameB",
117: elementNameQualifier
118: .qualifyForComparison(control, test));
119: }
120:
121: public void setUp() throws Exception {
122: document = XMLUnit.newControlParser().newDocument();
123: elementNameQualifier = new ElementNameQualifier();
124: }
125:
126: public static TestSuite suite() {
127: return new TestSuite(test_ElementNameQualifier.class);
128: }
129:
130: public test_ElementNameQualifier(String name) {
131: super(name);
132: }
133:
134: }
|