001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.diff;
034:
035: import java.io.*;
036: import javax.xml.parsers.*;
037:
038: import junit.framework.*;
039: import org.apache.oro.text.perl.*;
040: import org.xml.sax.*;
041:
042: public class TestListDiffPrinter extends TestCase implements
043: ErrorHandler {
044: private static final String SPECIFIC_ENCODING = "iso-latin-1";
045: private static final String SPECIFIC_DTD_PREFIX = "./etc";
046:
047: private XMLReader reader;
048: private Perl5Util perl;
049:
050: protected void setUp() throws Exception {
051: reader = SAXParserFactory.newInstance().newSAXParser()
052: .getXMLReader();
053: reader.setFeature("http://xml.org/sax/features/validation",
054: true);
055: reader
056: .setFeature(
057: "http://apache.org/xml/features/nonvalidating/load-external-dtd",
058: true);
059: reader.setErrorHandler(this );
060:
061: perl = new Perl5Util();
062: }
063:
064: public void testDefaultDTDPrefix() {
065: ListDiffPrinter printer = new ListDiffPrinter();
066:
067: String xmlDocument = printer.toString();
068: assertTrue(xmlDocument + "Missing DTD", perl.match(
069: "/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument));
070: assertTrue("DTD \"" + perl.group(1)
071: + "\" does not have prefix \""
072: + ListDiffPrinter.DEFAULT_DTD_PREFIX + "\"", perl
073: .group(1)
074: .startsWith(ListDiffPrinter.DEFAULT_DTD_PREFIX));
075:
076: try {
077: reader
078: .parse(new InputSource(
079: new StringReader(xmlDocument)));
080: } catch (SAXException ex) {
081: fail("Could not parse XML Document: " + ex.getMessage()
082: + "\n" + xmlDocument);
083: } catch (IOException ex) {
084: fail("Could not read XML Document: " + ex.getMessage()
085: + "\n" + xmlDocument);
086: }
087: }
088:
089: public void testSpecificDTDPrefix() {
090: ListDiffPrinter printer = new ListDiffPrinter(
091: ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
092:
093: String xmlDocument = printer.toString();
094: assertTrue(xmlDocument + "Missing DTD", perl.match(
095: "/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument));
096: assertTrue("DTD \"" + perl.group(1)
097: + "\" does not have prefix \"./etc\"", perl.group(1)
098: .startsWith(SPECIFIC_DTD_PREFIX));
099:
100: try {
101: reader
102: .parse(new InputSource(
103: new StringReader(xmlDocument)));
104: } catch (SAXException ex) {
105: fail("Could not parse XML Document: " + ex.getMessage()
106: + "\n" + xmlDocument);
107: } catch (IOException ex) {
108: fail("Could not read XML Document: " + ex.getMessage()
109: + "\n" + xmlDocument);
110: }
111: }
112:
113: public void testDefaultEncoding() {
114: ListDiffPrinter printer = new ListDiffPrinter();
115:
116: String xmlDocument = printer.toString();
117: assertTrue(xmlDocument + "Missing encoding", perl.match(
118: "/encoding=\"([^\"]*)\"/", xmlDocument));
119: assertEquals("Encoding", ListDiffPrinter.DEFAULT_ENCODING, perl
120: .group(1));
121:
122: try {
123: reader
124: .parse(new InputSource(
125: new StringReader(xmlDocument)));
126: } catch (SAXException ex) {
127: fail("Could not parse XML Document: " + ex.getMessage()
128: + "\n" + xmlDocument);
129: } catch (IOException ex) {
130: fail("Could not read XML Document: " + ex.getMessage()
131: + "\n" + xmlDocument);
132: }
133: }
134:
135: public void testSpecificEncoding() {
136: ListDiffPrinter printer = new ListDiffPrinter(
137: SPECIFIC_ENCODING, ListDiffPrinter.DEFAULT_DTD_PREFIX);
138:
139: String xmlDocument = printer.toString();
140: assertTrue(xmlDocument + "Missing encoding", perl.match(
141: "/encoding=\"([^\"]*)\"/", xmlDocument));
142: assertEquals("Encoding", SPECIFIC_ENCODING, perl.group(1));
143:
144: try {
145: reader
146: .parse(new InputSource(
147: new StringReader(xmlDocument)));
148: } catch (SAXException ex) {
149: fail("Could not parse XML Document: " + ex.getMessage()
150: + "\n" + xmlDocument);
151: } catch (IOException ex) {
152: fail("Could not read XML Document: " + ex.getMessage()
153: + "\n" + xmlDocument);
154: }
155: }
156:
157: public void testDefault() {
158: ListDiffPrinter printer = new ListDiffPrinter(
159: ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
160:
161: printer.remove("java.lang.Object");
162: printer.remove("java.lang.Object.Object()");
163: printer.remove("java.lang.String");
164: printer.remove("java.util");
165: printer.remove("java.util.Collection.add(java.lang.Object)");
166: printer
167: .remove("java.util.Collection.addAll(java.util.Collection)");
168:
169: printer.add("java.lang.Thread");
170: printer.add("java.lang.Thread.Thread()");
171: printer.add("java.lang.System");
172: printer.add("java.io");
173: printer.add("java.io.PrintStream.println(java.lang.Object)");
174: printer.add("java.io.PrintWriter.println(java.lang.Object)");
175:
176: String xmlDocument = printer.toString();
177:
178: try {
179: reader
180: .parse(new InputSource(
181: new StringReader(xmlDocument)));
182: } catch (SAXException ex) {
183: fail("Could not parse XML Document: " + ex.getMessage()
184: + "\n" + xmlDocument);
185: } catch (IOException ex) {
186: fail("Could not read XML Document: " + ex.getMessage()
187: + "\n" + xmlDocument);
188: }
189:
190: assertTrue(
191: "java.lang.Object not in " + xmlDocument,
192: xmlDocument.indexOf("<line>java.lang.Object</line>") != -1);
193: assertTrue(
194: "java.lang.Object.Object() not in " + xmlDocument,
195: xmlDocument
196: .indexOf("<line>java.lang.Object.Object()</line>") != -1);
197: assertTrue(
198: "java.lang.String not in " + xmlDocument,
199: xmlDocument.indexOf("<line>java.lang.String</line>") != -1);
200: assertTrue("java.util not in " + xmlDocument, xmlDocument
201: .indexOf("<line>java.util</line>") != -1);
202: assertTrue(
203: "java.util.Collection.add(java.lang.Object) not in "
204: + xmlDocument,
205: xmlDocument
206: .indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
207: assertTrue(
208: "java.util.Collection.addAll(java.util.Collection) not in "
209: + xmlDocument,
210: xmlDocument
211: .indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
212:
213: assertTrue(
214: "java.lang.Thread not in " + xmlDocument,
215: xmlDocument.indexOf("<line>java.lang.Thread</line>") != -1);
216: assertTrue(
217: "java.lang.Thread.Thread() not in " + xmlDocument,
218: xmlDocument
219: .indexOf("<line>java.lang.Thread.Thread()</line>") != -1);
220: assertTrue(
221: "java.lang.System not in " + xmlDocument,
222: xmlDocument.indexOf("<line>java.lang.System</line>") != -1);
223: assertTrue("java.io not in " + xmlDocument, xmlDocument
224: .indexOf("<line>java.io</line>") != -1);
225: assertTrue(
226: "java.io.PrintStream.println(java.lang.Object) not in "
227: + xmlDocument,
228: xmlDocument
229: .indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
230: assertTrue(
231: "java.io.PrintWriter.println(java.lang.Object) not in "
232: + xmlDocument,
233: xmlDocument
234: .indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
235: }
236:
237: public void testFullList() {
238: ListDiffPrinter printer = new ListDiffPrinter(false,
239: ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
240:
241: printer.remove("java.lang.Object");
242: printer.remove("java.lang.Object.Object()");
243: printer.remove("java.lang.String");
244: printer.remove("java.util");
245: printer.remove("java.util.Collection.add(java.lang.Object)");
246: printer
247: .remove("java.util.Collection.addAll(java.util.Collection)");
248:
249: printer.add("java.lang.Thread");
250: printer.add("java.lang.Thread.Thread()");
251: printer.add("java.lang.System");
252: printer.add("java.io");
253: printer.add("java.io.PrintStream.println(java.lang.Object)");
254: printer.add("java.io.PrintWriter.println(java.lang.Object)");
255:
256: String xmlDocument = printer.toString();
257:
258: try {
259: reader
260: .parse(new InputSource(
261: new StringReader(xmlDocument)));
262: } catch (SAXException ex) {
263: fail("Could not parse XML Document: " + ex.getMessage()
264: + "\n" + xmlDocument);
265: } catch (IOException ex) {
266: fail("Could not read XML Document: " + ex.getMessage()
267: + "\n" + xmlDocument);
268: }
269:
270: assertTrue(
271: "java.lang.Object not in " + xmlDocument,
272: xmlDocument.indexOf("<line>java.lang.Object</line>") != -1);
273: assertTrue(
274: "java.lang.Object.Object() not in " + xmlDocument,
275: xmlDocument
276: .indexOf("<line>java.lang.Object.Object()</line>") != -1);
277: assertTrue(
278: "java.lang.String not in " + xmlDocument,
279: xmlDocument.indexOf("<line>java.lang.String</line>") != -1);
280: assertTrue("java.util not in " + xmlDocument, xmlDocument
281: .indexOf("<line>java.util</line>") != -1);
282: assertTrue(
283: "java.util.Collection.add(java.lang.Object) not in "
284: + xmlDocument,
285: xmlDocument
286: .indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
287: assertTrue(
288: "java.util.Collection.addAll(java.util.Collection) not in "
289: + xmlDocument,
290: xmlDocument
291: .indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
292:
293: assertTrue(
294: "java.lang.Thread not in " + xmlDocument,
295: xmlDocument.indexOf("<line>java.lang.Thread</line>") != -1);
296: assertTrue(
297: "java.lang.Thread.Thread() not in " + xmlDocument,
298: xmlDocument
299: .indexOf("<line>java.lang.Thread.Thread()</line>") != -1);
300: assertTrue(
301: "java.lang.System not in " + xmlDocument,
302: xmlDocument.indexOf("<line>java.lang.System</line>") != -1);
303: assertTrue("java.io not in " + xmlDocument, xmlDocument
304: .indexOf("<line>java.io</line>") != -1);
305: assertTrue(
306: "java.io.PrintStream.println(java.lang.Object) not in "
307: + xmlDocument,
308: xmlDocument
309: .indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
310: assertTrue(
311: "java.io.PrintWriter.println(java.lang.Object) not in "
312: + xmlDocument,
313: xmlDocument
314: .indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
315: }
316:
317: public void testCompressedList() {
318: ListDiffPrinter printer = new ListDiffPrinter(true,
319: ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
320:
321: printer.remove("java.lang.Object [C]");
322: printer.remove("java.lang.Object.Object() [F]");
323: printer.remove("java.lang.String [C]");
324: printer.remove("java.util [P]");
325: printer
326: .remove("java.util.Collection.add(java.lang.Object) [F]");
327: printer
328: .remove("java.util.Collection.addAll(java.util.Collection) [F]");
329:
330: printer.add("java.lang.Thread [C]");
331: printer.add("java.lang.Thread.Thread() [F]");
332: printer.add("java.lang.System [C]");
333: printer.add("java.io [P]");
334: printer
335: .add("java.io.PrintStream.println(java.lang.Object) [F]");
336: printer
337: .add("java.io.PrintWriter.println(java.lang.Object) [F]");
338:
339: String xmlDocument = printer.toString();
340:
341: try {
342: reader
343: .parse(new InputSource(
344: new StringReader(xmlDocument)));
345: } catch (SAXException ex) {
346: fail("Could not parse XML Document: " + ex.getMessage()
347: + "\n" + xmlDocument);
348: } catch (IOException ex) {
349: fail("Could not read XML Document: " + ex.getMessage()
350: + "\n" + xmlDocument);
351: }
352:
353: assertTrue(
354: "java.lang.Object not in " + xmlDocument,
355: xmlDocument.indexOf("<line>java.lang.Object</line>") != -1);
356: assertTrue(
357: "java.lang.Object.Object() in " + xmlDocument,
358: xmlDocument
359: .indexOf("<line>java.lang.Object.Object()</line>") == -1);
360: assertTrue(
361: "java.lang.String not in " + xmlDocument,
362: xmlDocument.indexOf("<line>java.lang.String</line>") != -1);
363: assertTrue("java.util not in " + xmlDocument, xmlDocument
364: .indexOf("<line>java.util</line>") != -1);
365: assertTrue(
366: "java.util.Collection.add(java.lang.Object) in "
367: + xmlDocument,
368: xmlDocument
369: .indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") == -1);
370: assertTrue(
371: "java.util.Collection.addAll(java.util.Collection) in "
372: + xmlDocument,
373: xmlDocument
374: .indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") == -1);
375:
376: assertTrue(
377: "java.lang.Thread not in " + xmlDocument,
378: xmlDocument.indexOf("<line>java.lang.Thread</line>") != -1);
379: assertTrue(
380: "java.lang.Thread.Thread() in " + xmlDocument,
381: xmlDocument
382: .indexOf("<line>java.lang.Thread.Thread()</line>") == -1);
383: assertTrue(
384: "java.lang.System not in " + xmlDocument,
385: xmlDocument.indexOf("<line>java.lang.System</line>") != -1);
386: assertTrue("java.io not in " + xmlDocument, xmlDocument
387: .indexOf("<line>java.io</line>") != -1);
388: assertTrue(
389: "java.io.PrintStream.println(java.lang.Object) not in "
390: + xmlDocument,
391: xmlDocument
392: .indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") == -1);
393: assertTrue(
394: "java.io.PrintWriter.println(java.lang.Object) in "
395: + xmlDocument,
396: xmlDocument
397: .indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") == -1);
398: }
399:
400: public void testCompressedListWithoutSuffixes() {
401: ListDiffPrinter printer = new ListDiffPrinter(true,
402: ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
403:
404: printer.remove("java.lang.Object");
405: printer.remove("java.lang.Object.Object()");
406: printer.remove("java.lang.String");
407: printer.remove("java.util");
408: printer.remove("java.util.Collection.add(java.lang.Object)");
409: printer
410: .remove("java.util.Collection.addAll(java.util.Collection)");
411:
412: printer.add("java.lang.Thread");
413: printer.add("java.lang.Thread.Thread()");
414: printer.add("java.lang.System");
415: printer.add("java.io");
416: printer.add("java.io.PrintStream.println(java.lang.Object)");
417: printer.add("java.io.PrintWriter.println(java.lang.Object)");
418:
419: String xmlDocument = printer.toString();
420:
421: try {
422: reader
423: .parse(new InputSource(
424: new StringReader(xmlDocument)));
425: } catch (SAXException ex) {
426: fail("Could not parse XML Document: " + ex.getMessage()
427: + "\n" + xmlDocument);
428: } catch (IOException ex) {
429: fail("Could not read XML Document: " + ex.getMessage()
430: + "\n" + xmlDocument);
431: }
432:
433: assertTrue(
434: "java.lang.Object not in " + xmlDocument,
435: xmlDocument.indexOf("<line>java.lang.Object</line>") != -1);
436: assertTrue(
437: "java.lang.Object.Object() not in " + xmlDocument,
438: xmlDocument
439: .indexOf("<line>java.lang.Object.Object()</line>") != -1);
440: assertTrue(
441: "java.lang.String not in " + xmlDocument,
442: xmlDocument.indexOf("<line>java.lang.String</line>") != -1);
443: assertTrue("java.util not in " + xmlDocument, xmlDocument
444: .indexOf("<line>java.util</line>") != -1);
445: assertTrue(
446: "java.util.Collection.add(java.lang.Object) not in "
447: + xmlDocument,
448: xmlDocument
449: .indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
450: assertTrue(
451: "java.util.Collection.addAll(java.util.Collection) not in "
452: + xmlDocument,
453: xmlDocument
454: .indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
455:
456: assertTrue(
457: "java.lang.Thread not in " + xmlDocument,
458: xmlDocument.indexOf("<line>java.lang.Thread</line>") != -1);
459: assertTrue(
460: "java.lang.Thread.Thread() not in " + xmlDocument,
461: xmlDocument
462: .indexOf("<line>java.lang.Thread.Thread()</line>") != -1);
463: assertTrue(
464: "java.lang.System not in " + xmlDocument,
465: xmlDocument.indexOf("<line>java.lang.System</line>") != -1);
466: assertTrue("java.io not in " + xmlDocument, xmlDocument
467: .indexOf("<line>java.io</line>") != -1);
468: assertTrue(
469: "java.io.PrintStream.println(java.lang.Object) not in "
470: + xmlDocument,
471: xmlDocument
472: .indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
473: assertTrue(
474: "java.io.PrintWriter.println(java.lang.Object) not in "
475: + xmlDocument,
476: xmlDocument
477: .indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
478: }
479:
480: public void testLegitimateSuffixes() {
481: ListDiffPrinter printer = new ListDiffPrinter(true,
482: ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
483:
484: printer.remove("removed [P]"); // not compressed
485: printer.remove("removed.Removed [C]"); // compressed
486: printer.remove("removed.Removed.Removed() [F]"); // compressed
487: printer.remove("removed.Removed.removed [F]"); // compressed
488: printer.remove("removed.OtherRemoved.OtherRemoved() [F]"); // compressed
489: printer.remove("removed.OtherRemoved.other_removed [F]"); // compressed
490: printer.remove("removedpackage [P]"); // not compressed
491: printer.remove("removed.package.internal [P]"); // not compressed
492: printer.remove("other.removed.Removed [C]"); // not compressed
493: printer.remove("other.removed.Removed.Removed() [F]"); // compressed
494: printer.remove("other.removed.OtherRemoved.OtherRemoved() [F]"); // not compressed
495:
496: printer.add("add [P]"); // not compressed
497: printer.add("add.Add [C]"); // compressed
498: printer.add("add.Add.Add() [F]"); // compressed
499: printer.add("add.Add.add [F]"); // compressed
500: printer.add("add.OtherAdd.OtherAdd() [F]"); // compressed
501: printer.add("add.OtherAdd.add [F]"); // compressed
502: printer.add("addpackage [P]"); // not compressed
503: printer.add("add.package.internal [P]"); // not compressed
504: printer.add("other.add.Add [C]"); // not compressed
505: printer.add("other.add.Add.Add() [F]"); // compressed
506: printer.add("other.add.OtherAdd.OtherAdd() [F]"); // not compressed
507:
508: String xmlDocument = printer.toString();
509:
510: try {
511: reader
512: .parse(new InputSource(
513: new StringReader(xmlDocument)));
514: } catch (SAXException ex) {
515: fail("Could not parse XML Document: " + ex.getMessage()
516: + "\n" + xmlDocument);
517: } catch (IOException ex) {
518: fail("Could not read XML Document: " + ex.getMessage()
519: + "\n" + xmlDocument);
520: }
521:
522: assertTrue("removed not in " + xmlDocument, xmlDocument
523: .indexOf("<line>removed</line>") != -1);
524: assertTrue("removed.Removed in " + xmlDocument, xmlDocument
525: .indexOf("<line>removed.Removed</line>") == -1);
526: assertTrue(
527: "removed.Removed.Removed() in " + xmlDocument,
528: xmlDocument
529: .indexOf("<line>removed.Removed.Removed()</line>") == -1);
530: assertTrue(
531: "removed.Removed.removed in " + xmlDocument,
532: xmlDocument
533: .indexOf("<line>removed.Removed.removed</line>") == -1);
534: assertTrue(
535: "removed.OtherRemoved.OtherRemoved() in " + xmlDocument,
536: xmlDocument
537: .indexOf("<line>removed.OtherRemoved.OtherRemoved()</line>") == -1);
538: assertTrue(
539: "removed.OtherRemoved.other_removed in " + xmlDocument,
540: xmlDocument
541: .indexOf("<line>removed.OtherRemoved.other_removed</line>") == -1);
542: assertTrue("removedpackage not in " + xmlDocument, xmlDocument
543: .indexOf("<line>removedpackage</line>") != -1);
544: assertTrue(
545: "removed.package.internal not in " + xmlDocument,
546: xmlDocument
547: .indexOf("<line>removed.package.internal</line>") != -1);
548: assertTrue(
549: "other.removed.Removed not in " + xmlDocument,
550: xmlDocument
551: .indexOf("<line>other.removed.Removed</line>") != -1);
552: assertTrue(
553: "other.removed.Removed.Removed() in " + xmlDocument,
554: xmlDocument
555: .indexOf("<line>other.removed.Removed.Removed()</line>") == -1);
556: assertTrue(
557: "other.removed.OtherRemoved.OtherRemoved() not in "
558: + xmlDocument,
559: xmlDocument
560: .indexOf("<line>other.removed.OtherRemoved.OtherRemoved()</line>") != -1);
561:
562: assertTrue("add not in " + xmlDocument, xmlDocument
563: .indexOf("<line>add</line>") != -1);
564: assertTrue("add.Add in " + xmlDocument, xmlDocument
565: .indexOf("<line>add.Add</line>") == -1);
566: assertTrue("add.Add.Add() in " + xmlDocument, xmlDocument
567: .indexOf("<line>add.Add.Add()</line>") == -1);
568: assertTrue("add.Add.add in " + xmlDocument, xmlDocument
569: .indexOf("<line>add.Add.add</line>") == -1);
570: assertTrue(
571: "add.OtherAdd.OtherAdd() in " + xmlDocument,
572: xmlDocument
573: .indexOf("<line>add.OtherAdd.OtherAdd()</line>") == -1);
574: assertTrue(
575: "add.OtherAdd.other_add in " + xmlDocument,
576: xmlDocument
577: .indexOf("<line>add.OtherAdd.other_add</line>") == -1);
578: assertTrue("addpackage not in " + xmlDocument, xmlDocument
579: .indexOf("<line>addpackage</line>") != -1);
580: assertTrue(
581: "add.package.internal not in " + xmlDocument,
582: xmlDocument
583: .indexOf("<line>add.package.internal</line>") != -1);
584: assertTrue("other.add.Add not in " + xmlDocument, xmlDocument
585: .indexOf("<line>other.add.Add</line>") != -1);
586: assertTrue("other.add.Add.Add() in " + xmlDocument, xmlDocument
587: .indexOf("<line>other.add.Add.Add()</line>") == -1);
588: assertTrue(
589: "other.add.OtherAdd.OtherAdd() not in " + xmlDocument,
590: xmlDocument
591: .indexOf("<line>other.add.OtherAdd.OtherAdd()</line>") != -1);
592: }
593:
594: public void testNoSuffixes() {
595: ListDiffPrinter printer = new ListDiffPrinter(true,
596: ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
597:
598: printer.remove("removed"); // not compressed
599: printer.remove("removed.Removed"); // not compressed
600: printer.remove("removed.Removed.Removed()"); // not compressed
601: printer.remove("removed.Removed.removed"); // not compressed
602: printer.remove("removed.OtherRemoved.OtherRemoved()"); // not compressed
603: printer.remove("removed.OtherRemoved.other_removed"); // not compressed
604: printer.remove("removedpackage"); // not compressed
605: printer.remove("removed.package.internal"); // not compressed
606: printer.remove("other.removed.Removed"); // not compressed
607: printer.remove("other.removed.Removed.Removed()"); // not compressed
608: printer.remove("other.removed.OtherRemoved.OtherRemoved()"); // not compressed
609:
610: printer.add("add"); // not compressed
611: printer.add("add.Add"); // not compressed
612: printer.add("add.Add.Add()"); // not compressed
613: printer.add("add.Add.add"); // not compressed
614: printer.add("add.OtherAdd.OtherAdd()"); // not compressed
615: printer.add("add.OtherAdd.other_add"); // not compressed
616: printer.add("addpackage"); // not compressed
617: printer.add("add.package.internal"); // not compressed
618: printer.add("other.add.Add"); // not compressed
619: printer.add("other.add.Add.Add()"); // not compressed
620: printer.add("other.add.OtherAdd.OtherAdd()"); // not compressed
621:
622: String xmlDocument = printer.toString();
623:
624: try {
625: reader
626: .parse(new InputSource(
627: new StringReader(xmlDocument)));
628: } catch (SAXException ex) {
629: fail("Could not parse XML Document: " + ex.getMessage()
630: + "\n" + xmlDocument);
631: } catch (IOException ex) {
632: fail("Could not read XML Document: " + ex.getMessage()
633: + "\n" + xmlDocument);
634: }
635:
636: assertTrue("removed not in " + xmlDocument, xmlDocument
637: .indexOf("<line>removed</line>") != -1);
638: assertTrue("removed.Removed in " + xmlDocument, xmlDocument
639: .indexOf("<line>removed.Removed</line>") != -1);
640: assertTrue(
641: "removed.Removed.Removed() in " + xmlDocument,
642: xmlDocument
643: .indexOf("<line>removed.Removed.Removed()</line>") != -1);
644: assertTrue(
645: "removed.Removed.removed in " + xmlDocument,
646: xmlDocument
647: .indexOf("<line>removed.Removed.removed</line>") != -1);
648: assertTrue(
649: "removed.OtherRemoved.OtherRemoved() in " + xmlDocument,
650: xmlDocument
651: .indexOf("<line>removed.OtherRemoved.OtherRemoved()</line>") != -1);
652: assertTrue(
653: "removed.OtherRemoved.other_removed in " + xmlDocument,
654: xmlDocument
655: .indexOf("<line>removed.OtherRemoved.other_removed</line>") != -1);
656: assertTrue("removedpackage not in " + xmlDocument, xmlDocument
657: .indexOf("<line>removedpackage</line>") != -1);
658: assertTrue(
659: "removed.package.internal not in " + xmlDocument,
660: xmlDocument
661: .indexOf("<line>removed.package.internal</line>") != -1);
662: assertTrue(
663: "other.removed.Removed not in " + xmlDocument,
664: xmlDocument
665: .indexOf("<line>other.removed.Removed</line>") != -1);
666: assertTrue(
667: "other.removed.Removed.Removed() in " + xmlDocument,
668: xmlDocument
669: .indexOf("<line>other.removed.Removed.Removed()</line>") != -1);
670: assertTrue(
671: "other.removed.OtherRemoved.OtherRemoved() not in "
672: + xmlDocument,
673: xmlDocument
674: .indexOf("<line>other.removed.OtherRemoved.OtherRemoved()</line>") != -1);
675:
676: assertTrue("add not in " + xmlDocument, xmlDocument
677: .indexOf("<line>add</line>") != -1);
678: assertTrue("add.Add in " + xmlDocument, xmlDocument
679: .indexOf("<line>add.Add</line>") != -1);
680: assertTrue("add.Add.Add() in " + xmlDocument, xmlDocument
681: .indexOf("<line>add.Add.Add()</line>") != -1);
682: assertTrue("add.Add.add in " + xmlDocument, xmlDocument
683: .indexOf("<line>add.Add.add</line>") != -1);
684: assertTrue(
685: "add.OtherAdd.OtherAdd() in " + xmlDocument,
686: xmlDocument
687: .indexOf("<line>add.OtherAdd.OtherAdd()</line>") != -1);
688: assertTrue(
689: "add.OtherAdd.other_add in " + xmlDocument,
690: xmlDocument
691: .indexOf("<line>add.OtherAdd.other_add</line>") != -1);
692: assertTrue("addpackage not in " + xmlDocument, xmlDocument
693: .indexOf("<line>addpackage</line>") != -1);
694: assertTrue(
695: "add.package.internal not in " + xmlDocument,
696: xmlDocument
697: .indexOf("<line>add.package.internal</line>") != -1);
698: assertTrue("other.add.Add not in " + xmlDocument, xmlDocument
699: .indexOf("<line>other.add.Add</line>") != -1);
700: assertTrue("other.add.Add.Add() in " + xmlDocument, xmlDocument
701: .indexOf("<line>other.add.Add.Add()</line>") != -1);
702: assertTrue(
703: "other.add.OtherAdd.OtherAdd() not in " + xmlDocument,
704: xmlDocument
705: .indexOf("<line>other.add.OtherAdd.OtherAdd()</line>") != -1);
706: }
707:
708: public void error(SAXParseException ex) {
709: // Ignore
710: }
711:
712: public void fatalError(SAXParseException ex) {
713: // Ignore
714: }
715:
716: public void warning(SAXParseException ex) {
717: // Ignore
718: }
719: }
|