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 ElementNameAndTextQualifier
047: * @see test_Diff#testRepeatedElementNamesWithTextQualification()
048: */
049: public class test_ElementNameAndTextQualifier extends TestCase {
050: private static final String TAG_NAME = "tagYoureIt";
051: private static final String TEXT_A = "textA";
052: private static final String TEXT_B = "textB";
053: private Document document;
054: private ElementNameAndTextQualifier elementNameAndTextQualifier;
055:
056: public void testSingleTextValue() throws Exception {
057: Element control = document.createElement(TAG_NAME);
058: control.appendChild(document.createTextNode(TEXT_A));
059:
060: Element test = document.createElement(TAG_NAME);
061:
062: assertFalse("control text not comparable to empty text",
063: elementNameAndTextQualifier.qualifyForComparison(
064: control, test));
065:
066: test.appendChild(document.createTextNode(TEXT_A));
067: assertTrue("control textA comparable to test textA",
068: elementNameAndTextQualifier.qualifyForComparison(
069: control, test));
070:
071: test = document.createElement(TAG_NAME);
072:
073: test.appendChild(document.createTextNode(TEXT_B));
074: assertFalse("control textA not comparable to test textB",
075: elementNameAndTextQualifier.qualifyForComparison(
076: control, test));
077: }
078:
079: public void testMultipleTextValues() throws Exception {
080: Element control = document.createElement(TAG_NAME);
081: control.appendChild(document.createTextNode(TEXT_A));
082: control.appendChild(document.createTextNode(TEXT_B));
083:
084: Element test = document.createElement(TAG_NAME);
085: test.appendChild(document.createTextNode(TEXT_A + TEXT_B));
086: assertTrue(
087: "denormalised control text comparable to normalised test text",
088: elementNameAndTextQualifier.qualifyForComparison(
089: control, test));
090: }
091:
092: public void setUp() throws Exception {
093: document = XMLUnit.newControlParser().newDocument();
094: elementNameAndTextQualifier = new ElementNameAndTextQualifier();
095: }
096:
097: /**
098: * Constructor for test_ElementNameAndTextQualifier.
099: */
100: public test_ElementNameAndTextQualifier() {
101: super ();
102: }
103:
104: /**
105: * Constructor for test_ElementNameAndTextQualifier.
106: * @param name
107: */
108: public test_ElementNameAndTextQualifier(String name) {
109: super (name);
110: }
111:
112: public static TestSuite suite() {
113: return new TestSuite(test_ElementNameAndTextQualifier.class);
114: }
115: }
|