KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xdm > diff > XDMUtilTest


1 /*
2  * XMLModelTest.java
3  * JUnit based test
4  *
5  * Created on August 5, 2005, 12:13 PM
6  */

7
8 package org.netbeans.modules.xml.xdm.diff;
9 import java.io.BufferedInputStream JavaDoc;
10 import java.io.FileNotFoundException JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.util.List JavaDoc;
14 import javax.swing.text.Document JavaDoc;
15 import junit.framework.*;
16 import org.netbeans.modules.xml.xdm.Util;
17 import org.netbeans.modules.xml.xdm.diff.Change.AttributeChange;
18 import org.netbeans.modules.xml.xdm.diff.Change.AttributeDiff;
19 import org.netbeans.modules.xml.xdm.nodes.Attribute;
20 import org.netbeans.modules.xml.xdm.nodes.Node;
21
22 /**
23  *
24  * @author Ayub Khan
25  */

26 public class XDMUtilTest extends TestCase {
27     
28     public XDMUtilTest(String JavaDoc testName) {
29         super(testName);
30     }
31     
32     public void testPrettyPrintXML() throws Exception JavaDoc {
33         XDMUtil util = new XDMUtil();
34         String JavaDoc indent = " ";
35         String JavaDoc xml = readXMLString("diff/xdu/prettyprint1_1.xml");
36         String JavaDoc expected = readXMLString("diff/xdu/prettyprint1_2.xml");
37         String JavaDoc changed = util.prettyPrintXML(xml, indent);
38         assertEquals("pretty print", expected, changed);
39     }
40     
41     public void testPrettyPrintXML2() throws Exception JavaDoc {
42         XDMUtil util = new XDMUtil();
43         String JavaDoc indent = " ";
44         String JavaDoc xml = readXMLString("diff/xdu/prettyprint2_1.xml");
45         String JavaDoc expected = readXMLString("diff/xdu/prettyprint2_2.xml");
46         String JavaDoc changed = util.prettyPrintXML(xml, indent);
47         assertEquals("pretty print", expected, changed);
48     }
49
50     public void testPrettyPrintAddNamespace() throws Exception JavaDoc {
51         XDMUtil util = new XDMUtil();
52         String JavaDoc xml1 = readXMLString("diff/xdu/pp-add-ns-decl-1.xml");
53         String JavaDoc xml1_pretty = util.prettyPrintXML(xml1, " ");
54         String JavaDoc xml2 = readXMLString("diff/xdu/pp-add-ns-decl-2.xml");
55         assertEquals(xml2, xml1_pretty);
56     }
57
58     public void testPrettyPrintXMLNegative() throws Exception JavaDoc {
59         XDMUtil util = new XDMUtil();
60         String JavaDoc indent = " ";
61         String JavaDoc expected = XDMUtil.XML_PROLOG;
62         String JavaDoc xml = XDMUtil.XML_PROLOG;
63         String JavaDoc changed = util.prettyPrintXML(xml, indent);
64         assertEquals("pretty print", expected, changed);
65     }
66     
67     public void testCompareXMLEquals() throws Exception JavaDoc {
68         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.EQUAL;
69         //Only Element and Attribute order change
70
String JavaDoc xml1 = readXMLString("diff/xdu/equals1_1.xml");
71         String JavaDoc xml2 = readXMLString("diff/xdu/equals1_2.xml");
72         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
73         assertEquals("pretty print", 0, diffs.size());
74         
75         //Attribute value change. Element and Attribute order change
76
xml1 = readXMLString("diff/xdu/equals1_3.xml");
77         xml2 = readXMLString("diff/xdu/equals1_4.xml");
78         diffs = compareXML(xml1, xml2, criteria);
79         assertEquals("pretty print size", 1, diffs.size());
80         
81         //Attribute added. Element and Attribute order change
82
xml1 = readXMLString("diff/xdu/equals1_5.xml");
83         xml2 = readXMLString("diff/xdu/equals1_6.xml");
84         diffs = compareXML(xml1, xml2, criteria);
85         assertEquals("pretty print size", 1, diffs.size());
86         assertTrue("pretty print attribute change", ((Change)diffs.get(0)).isAttributeChanged());
87         assertEquals("pretty print attribute change size", 1,
88                 ((Change)diffs.get(0)).getAttrChanges().size());
89     }
90     
91     public void testCompareXMLIdentical() throws Exception JavaDoc {
92         XDMUtil util = new XDMUtil();
93         String JavaDoc indent = " ";
94         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
95         //Only Element and Attribute order change
96
String JavaDoc xml1 = readXMLString("diff/xdu/identical1_1.xml");
97         String JavaDoc xml2 = readXMLString("diff/xdu/identical1_2.xml");
98         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
99         assertEquals("pretty print", 2, diffs.size());
100         
101         //Attribute value change. Element and Attribute order change
102
xml1 = readXMLString("diff/xdu/identical1_3.xml");
103         xml2 = readXMLString("diff/xdu/identical1_4.xml");
104         diffs = compareXML(xml1, xml2, criteria);
105         assertEquals("pretty print size", 2, diffs.size());//1 - Attr pos, value change, 1 - Element pos change
106
assertTrue("pretty print attribute change", ((Change)diffs.get(0)).isAttributeChanged());
107         assertTrue("pretty print element pos change", ((Change)diffs.get(1)).isPositionChanged());
108         
109         List JavaDoc<Change.AttributeDiff> attrDiffs = ((Change)diffs.get(0)).getAttrChanges();
110         assertEquals("pretty print attribute change size", 2, attrDiffs.size());
111         Change.AttributeChange change1 = (Change.AttributeChange) attrDiffs.get(0);
112         assertTrue("pretty print attribute pos & token change", change1.isPositionChanged());
113         assertTrue("pretty print attribute pos & token change", change1.isTokenChanged());
114         Change.AttributeChange change2 = (Change.AttributeChange) attrDiffs.get(1);
115         assertTrue("pretty print attribute pos only change", change2.isPositionChanged());
116         assertFalse("pretty print attribute no token change", change2.isTokenChanged());
117         
118         //Attribute added. Element and Attribute order change
119
xml1 = readXMLString("diff/xdu/identical1_5.xml");
120         xml2 = readXMLString("diff/xdu/identical1_6.xml");
121         diffs = compareXML(xml1, xml2, criteria);
122         assertEquals("pretty print size", 2, diffs.size()); //1 - Attr pos, value change + add, 1 - Element pos change
123
assertTrue("pretty print attribute change", ((Change)diffs.get(0)).isAttributeChanged());
124         assertTrue("pretty print element pos change", ((Change)diffs.get(1)).isPositionChanged());
125         
126         attrDiffs = ((Change)diffs.get(0)).getAttrChanges();
127         assertEquals("pretty print attribute change size", 3, attrDiffs.size());
128         change1 = (Change.AttributeChange) attrDiffs.get(0);
129         assertTrue("pretty print attribute pos & token change", change1.isPositionChanged());
130         assertTrue("pretty print attribute pos & token change", change1.isTokenChanged());
131         change2 = (Change.AttributeChange) attrDiffs.get(1);
132         assertTrue("pretty print attribute pos only change", change2.isPositionChanged());
133         assertFalse("pretty print attribute no token change", change2.isTokenChanged());
134         Change.AttributeAdd add = (Change.AttributeAdd) attrDiffs.get(2);
135         assertEquals("pretty print attribute pos only change", 2, add.getNewAttributePosition());
136         
137         //Attribute added. Element and Attribute order change + Ignore whitespaces
138
xml1 = readXMLString("diff/xdu/identical1_7.xml");
139         xml2 = readXMLString("diff/xdu/identical1_8.xml");
140         diffs = compareXML(xml1, xml2, criteria);
141         assertEquals("pretty print size", 2, diffs.size()); //1 - Attr pos, value change + add, 1 - Element pos change
142
assertTrue("pretty print attribute change", ((Change)diffs.get(0)).isAttributeChanged());
143         assertTrue("pretty print element pos change", ((Change)diffs.get(1)).isPositionChanged());
144        
145         attrDiffs = ((Change)diffs.get(0)).getAttrChanges();
146         assertEquals("pretty print attribute change size", 3, attrDiffs.size());
147         change1 = (Change.AttributeChange) attrDiffs.get(0);
148         assertTrue("pretty print attribute pos & token change", change1.isPositionChanged());
149         assertTrue("pretty print attribute pos & token change", change1.isTokenChanged());
150         change2 = (Change.AttributeChange) attrDiffs.get(1);
151         assertTrue("pretty print attribute pos only change", change2.isPositionChanged());
152         assertTrue("pretty print attribute no token change", change2.isTokenChanged());
153         add = (Change.AttributeAdd) attrDiffs.get(2);
154         assertEquals("pretty print attribute pos only change", 2, add.getNewAttributePosition());
155     }
156     
157     public void testCompareXMLIdentical2() throws Exception JavaDoc {
158         XDMUtil util = new XDMUtil();
159         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
160         //Only NS Attribute delete and add
161
String JavaDoc xml1 = readXMLString("diff/xdu/identical2_1.xml");
162         String JavaDoc xml2 = readXMLString("diff/xdu/identical2_2.xml");
163         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
164         assertEquals("compare identical XML", 0, diffs.size());
165     }
166     
167     /**
168      * Test the comparision of defaultnamespace and no defautl but element has namsespace
169      */

170     public void testComparePrefix() throws Exception JavaDoc {
171         String JavaDoc xml1 = readXMLString("diff/xdu/pfx1_1.xml");
172         String JavaDoc xml2 = readXMLString("diff/xdu/pfx1_2.xml");
173         
174         XDMUtil util = new XDMUtil();
175         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
176         
177         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
178         assertEquals("testComparePrefix is equal?", 0, diffs.size());
179     }
180     
181     
182     /**
183      * Test extra unused namespace
184      */

185     public void testCompareExtraNamespace() throws Exception JavaDoc {
186         String JavaDoc xml1 = readXMLString("diff/xdu/extrans1_1.xml");
187         String JavaDoc xml2 = readXMLString("diff/xdu/extrans1_2.xml");
188         
189         XDMUtil util = new XDMUtil();
190         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
191         
192         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
193         assertEquals("testCompareExtraNamespace is equal?", 0, diffs.size());
194     }
195     
196     
197 /* Test both xml has schemaLocation defined and there's extra space in one xml between elements.
198  */

199     public void testCompareWhitespaceOutofElement_SchemaLoc() throws Exception JavaDoc {
200         String JavaDoc xml1 = readXMLString("diff/xdu/wsschemaloc1_1.xml");
201         String JavaDoc xml2 = readXMLString("diff/xdu/wsschemaloc1_2.xml");
202         
203         XDMUtil util = new XDMUtil();
204         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
205         
206         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
207         assertEquals("testCompareWhitespaceOutofElement_SchemaLoc?", 0, diffs.size());
208     }
209     
210     
211 /* Test both xml with NO schemaLocation defined and there's extra space in one xml between elements.
212  */

213     public void testCompareWhitespaceOutofElement_NoSchemaLoc() throws Exception JavaDoc {
214         String JavaDoc xml1 = readXMLString("diff/xdu/wsnoschemaloc1_1.xml");
215         String JavaDoc xml2 = readXMLString("diff/xdu/wsnoschemaloc1_2.xml");
216         
217         XDMUtil util = new XDMUtil();
218         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
219         
220         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
221         assertEquals("testCompareWhitespaceOutofElement_NoSchemaLoc?", 0, diffs.size());
222     }
223     
224     /**
225      * Test extra whitespace betweeen attributes
226      */

227     public void testCompareExtraWhiteSpaceBetweenAttr() throws Exception JavaDoc {
228         String JavaDoc xml1 = readXMLString("diff/xdu/extrawsattr1_1.xml");
229         String JavaDoc xml2 = readXMLString("diff/xdu/extrawsattr1_2.xml");
230         
231         XDMUtil util = new XDMUtil();
232         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
233         
234         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
235         assertEquals("testCompareExtraWhiteSpaceBetweenAttr is equal?", 0, diffs.size());
236     }
237     
238     /**
239      * Test xml one has schema location and the other one does not
240      */

241     public void testCompareXMLWSchemaLocation() throws Exception JavaDoc {
242         String JavaDoc xml1 = readXMLString("diff/xdu/schemalocation1_1.xml");
243         String JavaDoc xml2 = readXMLString("diff/xdu/schemalocation1_2.xml");
244         
245         XDMUtil util = new XDMUtil();
246         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
247         
248         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
249         assertEquals("testCompareXMLWSchemaLocation is equal?", 0, diffs.size());
250     }
251     
252     /**
253      * Test the comparision of xml with different url for same prefix
254      */

255     public void testCompareXMLSamePrefixDifferentURL() throws Exception JavaDoc {
256         String JavaDoc xml1 = readXMLString("diff/xdu/samepfx1_1.xml");
257         String JavaDoc xml2 = readXMLString("diff/xdu/samepfx1_2.xml");
258         
259         XDMUtil util = new XDMUtil();
260         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
261         
262         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
263         assertEquals("testComparePrefix is equal?", 2, diffs.size());
264     }
265     
266     /**
267      * Test the comparision of xml with different url for same prefix
268      */

269     public void testCompareXMLSamePrefixDifferentURL2() throws Exception JavaDoc {
270         String JavaDoc xml1 = readXMLString("diff/xdu/samepfx2_1.xml");
271         String JavaDoc xml2 = readXMLString("diff/xdu/samepfx2_2.xml");
272         
273         XDMUtil util = new XDMUtil();
274         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
275         
276         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
277         assertEquals("testComparePrefix is equal?", 2, diffs.size());
278     }
279     
280     /**
281      * Test the comparision of xml with same url for different prefix
282      */

283     public void testCompareXMLDifferentPrefixSameURL() throws Exception JavaDoc {
284         String JavaDoc xml1 = readXMLString("diff/xdu/difpfx1_1.xml");
285         String JavaDoc xml2 = readXMLString("diff/xdu/difpfx1_2.xml");
286         
287         XDMUtil util = new XDMUtil();
288         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
289         
290         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
291         assertEquals("testComparePrefix is equal?", 0, diffs.size());
292     }
293     
294     /**
295      * Test xml one has schema location and the other one does not
296      */

297     public void testCompareXMLWithWhitespace() throws Exception JavaDoc {
298         String JavaDoc xml1 = readXMLString("diff/xdu/textchange2_1.xml");
299         String JavaDoc xml2 = readXMLString("diff/xdu/whitespace.xml");
300         
301         XDMUtil util = new XDMUtil();
302         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
303         
304         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
305         assertEquals("testCompareXMLWSchemaLocation is equal?", 0, diffs.size());
306     }
307     
308     /**
309      * Test xml one has schema location and the other one does not
310      */

311     public void testCompareXMLWithTextChange() throws Exception JavaDoc {
312         String JavaDoc xml1 = readXMLString("diff/xdu/textchange2_1.xml");
313         String JavaDoc xml2 = readXMLString("diff/xdu/textchange2_2.xml");
314         
315         XDMUtil util = new XDMUtil();
316         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
317         
318         List JavaDoc<Difference> diffs = compareXML(xml1, xml2 , criteria);
319         assertEquals("testCompareXMLWSchemaLocation is equal?", 1, diffs.size());
320     }
321     
322     public void testFilterAttributeOrderChange() throws Exception JavaDoc {
323         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
324         //Only Attribute order change
325
String JavaDoc xml1 = readXMLString("diff/xdu/attrorder1_1.xml");
326         String JavaDoc xml2 = readXMLString("diff/xdu/attrorder1_2.xml");
327         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
328         assertEquals("attr order & token change", 1, diffs.size());
329         assertEquals("attr order & token change", 2,
330                 ((Change)diffs.get(0)).getAttrChanges().size());//x and y changed positions
331
XDMUtil.filterAttributeOrderChange(diffs); //<- new filter for ignoring attr changes
332
assertEquals("attr order & token change", 0, diffs.size());
333         
334         //Only Attribute order and token change
335
xml1 = readXMLString("diff/xdu/attrorder2_1.xml");
336         xml2 = readXMLString("diff/xdu/attrorder2_2.xml");
337         diffs = compareXML(xml1, xml2, criteria);
338         assertEquals("attr order & token change", 1, diffs.size());
339         assertEquals("attr order & token change", 2,
340                 ((Change)diffs.get(0)).getAttrChanges().size());
341         XDMUtil.filterAttributeOrderChange(diffs); //<- new filter for ignoring attr changes
342
assertEquals("attr order & token change", 1, diffs.size());
343         assertEquals("attr token change", 1,
344                 ((Change)diffs.get(0)).getAttrChanges().size());
345     }
346     
347     public void testFindOffsets() throws Exception JavaDoc {
348         XDMUtil util = new XDMUtil();
349         String JavaDoc indent = " ";
350         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
351         //Only Element and Attribute order change
352
String JavaDoc xml1 = readXMLString("diff/xdu/findoffset1_1.xml");
353         String JavaDoc xml2 = readXMLString("diff/xdu/findoffset1_2.xml");
354         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
355         assertEquals("find Offsets", 2, diffs.size());
356         
357         Difference d = diffs.get(1);
358         assertTrue("diff: ", d instanceof Change);
359         NodeInfo oldInfo = d.getOldNodeInfo();
360         Node oldNode = oldInfo.getNode();
361         NodeInfo info = d.getNewNodeInfo();
362         Node node = info.getNode();
363         if(oldNode != null)
364             assertEquals("old change begin: ", 50, XDMUtil.findPosition(oldNode));
365         if(node != null)
366             assertEquals("new change begin: ", 45, XDMUtil.findPosition(node));
367
368         d = diffs.get(0);
369         assertTrue("diff: ", d instanceof Change);
370         oldInfo = d.getOldNodeInfo();
371         oldNode = oldInfo.getNode();
372         info = d.getNewNodeInfo();
373         node = info.getNode();
374         if(oldNode != null)
375             assertEquals("old change begin: ", 22, XDMUtil.findPosition(oldNode));
376         if(node != null)
377             assertEquals("new change begin: ", 22, XDMUtil.findPosition(node));
378         if(d instanceof Change) {
379             List JavaDoc<AttributeDiff> attrDiffs = ((Change)d).getAttrChanges();
380             AttributeDiff ad = attrDiffs.get(0);
381             assertTrue("attr diff: ", ad instanceof AttributeChange);
382             Attribute oldAttr = ad.getOldAttribute();
383             Attribute attr = ad.getNewAttribute();
384             if(oldAttr != null)
385                 assertEquals("old attr change begin: ", 28, XDMUtil.findPosition(oldAttr));
386             if(attr != null)
387                 assertEquals("new attr change begin: ", 35, XDMUtil.findPosition(attr));
388
389             ad = attrDiffs.get(1);
390             assertTrue("attr diff: ", ad instanceof AttributeChange);
391             oldAttr = ad.getOldAttribute();
392             attr = ad.getNewAttribute();
393             if(oldAttr != null)
394                 assertEquals("old attr change begin: ", 35, XDMUtil.findPosition(oldAttr));
395             if(attr != null)
396                 assertEquals("new attr change begin: ", 28, XDMUtil.findPosition(attr));
397         }
398     }
399     
400     public void testCompareXMLIdenticalExtraEmptyNS() throws Exception JavaDoc {
401         XDMUtil util = new XDMUtil();
402         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
403         String JavaDoc xml1 = readXMLString("diff/xdu/extraemptyns1_1.xml");
404         String JavaDoc xml2 = readXMLString("diff/xdu/extraemptyns1_2.xml");
405         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
406         assertEquals("compare identical XML", 0, diffs.size());
407     }
408     
409     public void testCompareXMLIdenticalExtraEmptyNS2() throws Exception JavaDoc {
410         XDMUtil util = new XDMUtil();
411         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
412         String JavaDoc xml1 = readXMLString("diff/xdu/extraemptyns2_1.xml");
413         String JavaDoc xml2 = readXMLString("diff/xdu/extraemptyns2_2.xml");
414         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
415         assertEquals("compare identical XML", 0, diffs.size());
416     }
417     
418     public void testCompareXMLIdenticalExtraEmptyNS3() throws Exception JavaDoc {
419         XDMUtil util = new XDMUtil();
420         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
421         String JavaDoc xml1 = readXMLString("diff/xdu/extraemptyns3_1.xml");
422         String JavaDoc xml2 = readXMLString("diff/xdu/extraemptyns3_2.xml");
423         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
424         assertEquals("compare identical XML", 0, diffs.size());
425     }
426     
427     public void testCompareXMLIdenticalExtraEmptyNS4() throws Exception JavaDoc {
428         XDMUtil util = new XDMUtil();
429         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
430         String JavaDoc xml1 = readXMLString("diff/xdu/extraemptyns4_1.xml");
431         String JavaDoc xml2 = readXMLString("diff/xdu/extraemptyns4_2.xml");
432         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
433         assertEquals("compare identical XML", 0, diffs.size());
434     }
435     
436     public void testCompareWithDiffInLeafNodes() throws Exception JavaDoc {
437         XDMUtil util = new XDMUtil();
438         XDMUtil.ComparisonCriteria criteria = XDMUtil.ComparisonCriteria.IDENTICAL;
439         String JavaDoc xml1 = readXMLString("diff/xdu/textchange1_1.xml");
440         String JavaDoc xml2 = readXMLString("diff/xdu/textchange1_2.xml");
441         List JavaDoc<Difference> diffs = compareXML(xml1, xml2, criteria);
442         assertEquals("compare identical XML", 2, diffs.size());
443     }
444
445     private String JavaDoc readXMLString(String JavaDoc path) throws Exception JavaDoc {
446         Document JavaDoc doc = Util.getResourceAsDocument(path);
447         return doc.getText(0, doc.getLength());
448     }
449     
450     public List JavaDoc<Difference> compareXML(String JavaDoc xml1, String JavaDoc xml2,
451             XDMUtil.ComparisonCriteria criteria)
452             throws Exception JavaDoc {
453         return new XDMUtil().compareXML(xml1, xml2, criteria);
454     }
455 }
456
Popular Tags