KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * MergeDiffTest.java
3  * JUnit based test
4  *
5  * Created on February 2, 2006, 4:15 PM
6  */

7
8 package org.netbeans.modules.xml.xdm.diff;
9
10 import java.io.File JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13 import junit.framework.*;
14 import org.netbeans.modules.xml.xdm.Util;
15 import org.netbeans.modules.xml.xdm.XDMModel;
16 import javax.swing.text.Document JavaDoc;
17 import org.netbeans.modules.xml.xam.ModelSource;
18 import org.openide.util.Lookup;
19 import org.openide.util.lookup.Lookups;
20
21 /**
22  * class to test MergeDiff
23  * Make sure cover all these test cases:
24  * 1. just change tokens
25  * 2. just attribute
26  * 3. both token and attribute change
27  * 4. just children
28  * 5. just position change
29  * 6. both postion change and add or delete
30  * 7. all-in-one
31  *
32  * @author Ayub Khan
33  */

34 public class MergeDiffTest extends TestCase {
35     
36     public MergeDiffTest(String JavaDoc testName) {
37         super(testName);
38     }
39     
40     protected void setUp() throws Exception JavaDoc {
41     }
42     
43     static DefaultElementIdentity createEid() {
44         //Establish DOM element identities
45
DefaultElementIdentity eid = new DefaultElementIdentity();
46         //Following values are suitable for Schema and WSDL documents
47
eid.addIdentifier( "id" );
48         eid.addIdentifier( "name" );
49         eid.addIdentifier( "ref" );
50         return eid;
51     }
52     
53     protected void tearDown() throws Exception JavaDoc {
54     }
55     
56     public static Test suite() {
57 // TestSuite suite = new TestSuite(MergeDiffTest.class);
58
TestSuite suite = new TestSuite();
59         suite.addTest(new MergeDiffTest("testMerge1"));
60         suite.addTest(new MergeDiffTest("testMerge2"));
61         suite.addTest(new MergeDiffTest("testMerge3"));
62         suite.addTest(new MergeDiffTest("testMerge4"));
63         suite.addTest(new MergeDiffTest("testMerge5"));
64         suite.addTest(new MergeDiffTest("testMerge6"));
65         suite.addTest(new MergeDiffTest("testMerge7"));
66         suite.addTest(new MergeDiffTest("testMerge8"));
67         suite.addTest(new MergeDiffTest("testMerge9"));
68         suite.addTest(new MergeDiffTest("testMerge10"));
69         suite.addTest(new MergeDiffTest("testPrettyPrint"));
70         suite.addTest(new MergeDiffTest("testSelfClosing"));
71         suite.addTest(new MergeDiffTest("testAddChangeAttributeSameNode"));
72         suite.addTest(new MergeDiffTest("testElementAddedBeforeChildAttributeChange"));
73         suite.addTest(new MergeDiffTest("testPosChange"));
74         suite.addTest(new MergeDiffTest("testPosChange2"));
75         suite.addTest(new MergeDiffTest("testPosChange3"));
76         suite.addTest(new MergeDiffTest("testPosChange3_2"));
77         suite.addTest(new MergeDiffTest("testPosChange3_3"));
78         suite.addTest(new MergeDiffTest("testMergeVenetianBlindPO"));
79         suite.addTest(new MergeDiffTest("testForwardReorderNodeWithChangesOnChildren"));
80         suite.addTest(new MergeDiffTest("testMergeReformatDiff"));
81         return suite;
82     }
83     
84     public void testMerge1() throws Exception JavaDoc {
85         
86         String JavaDoc FILE1 = "diff/schema3.xsd";
87         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
88         Lookup lookup = Lookups.singleton(originalDocument);
89         ModelSource ms = new ModelSource(lookup, true);
90         XDMModel originalModel = new XDMModel(ms);
91         originalModel.sync();
92         
93         String JavaDoc FILE2 = "diff/schema5.xsd";
94         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
95         lookup = Lookups.singleton(d2);
96         ms = new ModelSource(lookup, true);
97         XDMModel m2 = new XDMModel(ms);
98         m2.sync();
99         
100 // long startTime=System.currentTimeMillis();
101

102         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
103         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
104         
105 // long endTime=System.currentTimeMillis();
106
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
107
// "Total time to merge schema1.xsd to schema3.xsd: "+(endTime-startTime)+"ms");
108
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
109

110         originalModel.flush();
111         
112 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
113
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
114
assertEquals("original document should be equivalent to merged document",
115                 d2.getText(0,d2.getLength()), originalDocument.getText(0,originalDocument.getLength()));
116     }
117     
118     public void testMerge2() throws Exception JavaDoc {
119         
120         String JavaDoc FILE1 = "diff/PurchaseOrder.xsd";
121         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
122         Lookup lookup = Lookups.singleton(originalDocument);
123         ModelSource ms = new ModelSource(lookup, true);
124         XDMModel originalModel = new XDMModel(ms);
125         originalModel.sync();
126         
127         String JavaDoc FILE2 = "diff/PurchaseOrderSyncTest.xsd";
128         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
129         lookup = Lookups.singleton(d2);
130         ms = new ModelSource(lookup, true);
131         XDMModel m2 = new XDMModel(ms);
132         m2.sync();
133         
134 // long startTime=System.currentTimeMillis();
135

136         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
137         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
138         
139 // long endTime=System.currentTimeMillis();
140
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
141
// "Total time to merge PurchaseOrder.xsd: "+(endTime-startTime)+"ms");
142
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
143

144         originalModel.flush();
145         
146 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
147
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
148
assertEquals("original document should be equivalent to merged document",
149                 d2.getText(0,d2.getLength()),
150                 originalDocument.getText(0,originalDocument.getLength()));
151     }
152     
153     public void testMerge3() throws Exception JavaDoc {
154         
155         String JavaDoc FILE1 = "diff/TravelItinerary1.xsd";
156         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
157         Lookup lookup = Lookups.singleton(originalDocument);
158         ModelSource ms = new ModelSource(lookup, true);
159         XDMModel originalModel = new XDMModel(ms);
160         originalModel.sync();
161         
162         String JavaDoc FILE2 = "diff/TravelItinerary2.xsd";
163         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
164         lookup = Lookups.singleton(d2);
165         ms = new ModelSource(lookup, true);
166         XDMModel m2 = new XDMModel(ms);
167         m2.sync();
168         
169         long startTime=System.currentTimeMillis();
170         
171         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
172         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
173         
174         long endTime=System.currentTimeMillis();
175 // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
176
// "Total time to merge TravelItinerary: "+(endTime-startTime)+"ms");
177
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
178

179         originalModel.flush();
180         
181 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
182
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
183
assertEquals("original document should be equivalent to merged document",
184                 d2.getText(0,d2.getLength()),
185                 originalDocument.getText(0,originalDocument.getLength()));
186     }
187     
188     public void testMerge4() throws Exception JavaDoc {
189         
190         String JavaDoc FILE1 = "diff/testaddshape.xml";
191         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
192         Lookup lookup = Lookups.singleton(originalDocument);
193         ModelSource ms = new ModelSource(lookup, true);
194         XDMModel originalModel = new XDMModel(ms);
195         originalModel.sync();
196         
197         String JavaDoc FILE2 = "diff/addshape.xml";
198         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
199         lookup = Lookups.singleton(d2);
200         ms = new ModelSource(lookup, true);
201         XDMModel m2 = new XDMModel(ms);
202         m2.sync();
203         
204 // long startTime=System.currentTimeMillis();
205

206         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
207         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
208         
209 // long endTime=System.currentTimeMillis();
210
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
211
// "Total time to merge addshape.xml: "+(endTime-startTime)+"ms");
212
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
213

214         originalModel.flush();
215         
216 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
217
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
218
assertEquals("original document should be equivalent to merged document",
219                 d2.getText(0,d2.getLength()),
220                 originalDocument.getText(0,originalDocument.getLength()));
221     }
222     
223     public void testMerge5() throws Exception JavaDoc {
224         
225         String JavaDoc FILE1 = "diff/testbase.xml";
226         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
227         Lookup lookup = Lookups.singleton(originalDocument);
228         ModelSource ms = new ModelSource(lookup, true);
229         XDMModel originalModel = new XDMModel(ms);
230         originalModel.sync();
231         
232         String JavaDoc FILE2 = "diff/commentTextChanged.xml";
233         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
234         lookup = Lookups.singleton(d2);
235         ms = new ModelSource(lookup, true);
236         XDMModel m2 = new XDMModel(ms);
237         m2.sync();
238         
239 // long startTime=System.currentTimeMillis();
240

241         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
242         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
243         
244 // long endTime=System.currentTimeMillis();
245
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
246
// "Total time to merge textchange.xml: "+(endTime-startTime)+"ms");
247
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
248

249         originalModel.flush();
250         
251 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
252
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
253
assertEquals("original document should be equivalent to merged document",
254                 d2.getText(0,d2.getLength()),
255                 originalDocument.getText(0,originalDocument.getLength()));
256     }
257     
258     public void testMerge6() throws Exception JavaDoc {
259         
260         String JavaDoc FILE1 = "diff/TestOperations.wsdl";
261         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
262         Lookup lookup = Lookups.singleton(originalDocument);
263         ModelSource ms = new ModelSource(lookup, true);
264         XDMModel originalModel = new XDMModel(ms);
265         originalModel.sync();
266         
267         String JavaDoc FILE2 = "diff/TestOperations_after.wsdl";
268         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
269         lookup = Lookups.singleton(d2);
270         ms = new ModelSource(lookup, true);
271         XDMModel m2 = new XDMModel(ms);
272         m2.sync();
273         
274 // long startTime=System.currentTimeMillis();
275

276         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
277         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
278         
279 // long endTime=System.currentTimeMillis();
280
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
281
// "Total time to merge textchange.xml: "+(endTime-startTime)+"ms");
282
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
283

284         originalModel.flush();
285         
286 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
287
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
288
assertEquals("original document should be equivalent to merged document",
289                 d2.getText(0,d2.getLength()),
290                 originalDocument.getText(0,originalDocument.getLength()));
291     }
292     
293     public void testMerge7() throws Exception JavaDoc {
294         
295         String JavaDoc FILE1 = "diff/VehicleReservationService.wsdl";
296         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
297         Lookup lookup = Lookups.singleton(originalDocument);
298         ModelSource ms = new ModelSource(lookup, true);
299         XDMModel originalModel = new XDMModel(ms);
300         originalModel.sync();
301         
302         String JavaDoc FILE2 = "diff/Vehicle_PartnerLinkChanged2.wsdl";
303         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
304         lookup = Lookups.singleton(d2);
305         ms = new ModelSource(lookup, true);
306         XDMModel m2 = new XDMModel(ms);
307         m2.sync();
308         
309 // long startTime=System.currentTimeMillis();
310

311         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
312         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
313         
314 // long endTime=System.currentTimeMillis();
315
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
316
// "Total time to merge textchange.xml: "+(endTime-startTime)+"ms");
317
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
318

319         originalModel.flush();
320         
321 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
322
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
323
assertEquals("original document should be equivalent to merged document",
324                 d2.getText(0,d2.getLength()),
325                 originalDocument.getText(0,originalDocument.getLength()));
326     }
327     
328     public void testMerge8() throws Exception JavaDoc {
329         
330         String JavaDoc FILE1 = "diff/UBL-CommonAggregateComponents-1.0.xsd";
331         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
332         Lookup lookup = Lookups.singleton(originalDocument);
333         ModelSource ms = new ModelSource(lookup, true);
334         XDMModel originalModel = new XDMModel(ms);
335         originalModel.sync();
336         
337         String JavaDoc FILE2 = "diff/UBL-CommonAggregateComponents-1.0.xsd";
338         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
339         lookup = Lookups.singleton(d2);
340         ms = new ModelSource(lookup, true);
341         XDMModel m2 = new XDMModel(ms);
342         m2.sync();
343         
344         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
345         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
346         
347         originalModel.flush();
348         assertEquals("original document should be equivalent to merged document",
349                 d2.getText(0,d2.getLength()),
350                 originalDocument.getText(0,originalDocument.getLength()));
351     }
352     
353     public void testMerge9() throws Exception JavaDoc {
354         
355         String JavaDoc FILE1 = "diff/schema3.xsd";
356         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
357         Lookup lookup = Lookups.singleton(originalDocument);
358         ModelSource ms = new ModelSource(lookup, true);
359         XDMModel originalModel = new XDMModel(ms);
360         originalModel.sync();
361         
362         String JavaDoc FILE2 = "diff/schema4.xsd";
363         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
364         lookup = Lookups.singleton(d2);
365         ms = new ModelSource(lookup, true);
366         XDMModel m2 = new XDMModel(ms);
367         m2.sync();
368         
369 // long startTime=System.currentTimeMillis();
370

371         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
372         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
373         
374 // long endTime=System.currentTimeMillis();
375
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
376
// "Total time to merge schema1.xsd to schema3.xsd: "+(endTime-startTime)+"ms");
377
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
378

379         originalModel.flush();
380         
381 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
382
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
383
assertEquals("original document should be equivalent to merged document",
384                 d2.getText(0,d2.getLength()), originalDocument.getText(0,originalDocument.getLength()));
385     }
386     
387     public void testMerge10() throws Exception JavaDoc {
388         
389         String JavaDoc FILE1 = "diff/schema4.xsd";
390         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
391         Lookup lookup = Lookups.singleton(originalDocument);
392         ModelSource ms = new ModelSource(lookup, true);
393         XDMModel originalModel = new XDMModel(ms);
394         originalModel.sync();
395         
396         String JavaDoc FILE2 = "diff/schema5.xsd";
397         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
398         lookup = Lookups.singleton(d2);
399         ms = new ModelSource(lookup, true);
400         XDMModel m2 = new XDMModel(ms);
401         m2.sync();
402         
403 // long startTime=System.currentTimeMillis();
404

405         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
406         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
407         
408 // long endTime=System.currentTimeMillis();
409
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
410
// "Total time to merge schema1.xsd to schema3.xsd: "+(endTime-startTime)+"ms");
411
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
412

413         originalModel.flush();
414         
415 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
416
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
417
assertEquals("original document should be equivalent to merged document",
418                 d2.getText(0,d2.getLength()), originalDocument.getText(0,originalDocument.getLength()));
419     }
420     
421     public void testPrettyPrint() throws Exception JavaDoc {
422         
423         String JavaDoc FILE1 = "diff/prettyprint1.xml";
424         Document JavaDoc originalDocument = Util.getResourceAsDocument(FILE1);
425         Lookup lookup = Lookups.singleton(originalDocument);
426         ModelSource ms = new ModelSource(lookup, true);
427         XDMModel originalModel = new XDMModel(ms);
428         originalModel.sync();
429         
430         String JavaDoc FILE2 = "diff/prettyprint2.xml";
431         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
432         lookup = Lookups.singleton(d2);
433         ms = new ModelSource(lookup, true);
434         XDMModel m2 = new XDMModel(ms);
435         m2.sync();
436         
437 // long startTime=System.currentTimeMillis();
438

439         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
440         treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
441         
442 // long endTime=System.currentTimeMillis();
443
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
444
// "Total time to merge schema1.xsd to schema3.xsd: "+(endTime-startTime)+"ms");
445
// System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
446

447         originalModel.flush();
448         
449 // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
450
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
451
assertEquals("original document should be equivalent to merged document",
452                 d2.getText(0,d2.getLength()), originalDocument.getText(0,originalDocument.getLength()));
453     }
454     
455     public static void merge(XDMModel model, List JavaDoc<Difference> diffs) {
456         model.mergeDiff(diffs);
457         model.flush();
458     }
459     
460     public void testSelfClosing() throws Exception JavaDoc {
461         XDMModel mod1 = Util.loadXDMModel("not_selfClosing.xml");
462         XDMModel mod2 = Util.loadXDMModel("selfClosing.xml");
463         List JavaDoc<Difference> diffs = Util.diff(mod1, mod2);
464         assertEquals(diffs.toString(), 2, diffs.size());
465         merge(mod1, diffs);
466         List JavaDoc<Difference> zeroDiffs = Util.diff(mod1, mod2);
467         assertTrue("before:"+diffs.toString()+" after:"+zeroDiffs.toString(), zeroDiffs.isEmpty());
468     }
469     
470     public void testAddChangeAttributeSameNode() throws Exception JavaDoc {
471         XDMModel mod1 = Util.loadXDMModel("diff/PurchaseOrder2.xsd");
472         XDMModel mod2 = Util.loadXDMModel("diff/PurchaseOrderSyncTest2.xsd");
473         List JavaDoc<Difference> diffs = Util.diff(mod1, mod2);
474         //assertEquals(diffs.toString(), 4, diffs.size());
475
merge(mod1, diffs);
476         List JavaDoc<Difference> zeroDiffs = Util.diff(mod1, mod2);
477         assertTrue("before:"+diffs.toString()+" after:"+zeroDiffs.toString(), zeroDiffs.isEmpty());
478     }
479     
480     public void testElementAddedBeforeChildAttributeChange() throws Exception JavaDoc {
481         String JavaDoc FILE1 = "diff/test2.xml";
482         Document JavaDoc d1 = Util.getResourceAsDocument(FILE1);
483         Lookup lookup = Lookups.singleton(d1);
484         ModelSource ms = new ModelSource(lookup, true);
485         XDMModel m1 = new XDMModel(ms);
486         m1.sync();
487         
488         String JavaDoc FILE2 = "diff/test2_1.xml";
489         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
490         lookup = Lookups.singleton(d2);
491         ms = new ModelSource(lookup, true);
492         XDMModel m2 = new XDMModel(ms);
493         m2.sync();
494         
495         List JavaDoc<Difference> diffs = Util.diff(m1, m2);
496         assertEquals(diffs.toString(), 9, diffs.size());
497         assertTrue(((Change)diffs.get(3)).isAttributeChanged());
498         assertFalse(((Change)diffs.get(3)).isPositionChanged());
499         assertFalse(((Change)diffs.get(4)).isAttributeChanged());
500         assertTrue(((Change)diffs.get(4)).isPositionChanged());
501         
502         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
503         treeDiff.performDiffAndMutate(m1, m2.getDocument());
504         
505         m1.flush();
506         
507 // System.out.println("original doc: \n["+d1.getText(0,d1.getLength())+"]");
508
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
509
assertEquals("original document should be equivalent to merged document",
510                 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength()));
511         
512         List JavaDoc<Difference> zeroDiffs = Util.diff(m1, m2);
513         assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty());
514     }
515     
516     public void testPosChange() throws Exception JavaDoc {
517         String JavaDoc FILE1 = "diff/posChange1.xml";
518         Document JavaDoc d1 = Util.getResourceAsDocument(FILE1);
519         Lookup lookup = Lookups.singleton(d1);
520         ModelSource ms = new ModelSource(lookup, true);
521         XDMModel m1 = new XDMModel(ms);
522         m1.sync();
523         
524         String JavaDoc FILE2 = "diff/posChange1_1.xml";
525         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
526         lookup = Lookups.singleton(d2);
527         ms = new ModelSource(lookup, true);
528         XDMModel m2 = new XDMModel(ms);
529         m2.sync();
530         
531         List JavaDoc<Difference> diffs = Util.diff(m1, m2);
532         assertEquals(diffs.toString(), 4, diffs.size());
533 // assertFalse(((Change)diffs.get(2)).isAttributeChanged());
534
// assertTrue(((Change)diffs.get(2)).isPositionChanged());
535
// assertFalse(((Change)diffs.get(4)).isAttributeChanged());
536
// assertTrue(((Change)diffs.get(4)).isPositionChanged());
537

538         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
539         treeDiff.performDiffAndMutate(m1, m2.getDocument());
540         
541         m1.flush();
542         
543 // System.out.println("diff: \n["+diffs.toString()+"]");
544
// System.out.println("resulting doc: \n["+d1.getText(0,d1.getLength())+"]");
545
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
546
assertEquals("original document should be equivalent to merged document",
547                 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength()));
548         
549         List JavaDoc<Difference> zeroDiffs = Util.diff(m1, m2);
550         assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty());
551     }
552     
553     public void testPosChange2() throws Exception JavaDoc {
554         String JavaDoc FILE1 = "diff/posChange2.xml";
555         Document JavaDoc d1 = Util.getResourceAsDocument(FILE1);
556         Lookup lookup = Lookups.singleton(d1);
557         ModelSource ms = new ModelSource(lookup, true);
558         XDMModel m1 = new XDMModel(ms);
559         m1.sync();
560         
561         String JavaDoc FILE2 = "diff/posChange2_1.xml";
562         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
563         lookup = Lookups.singleton(d2);
564         ms = new ModelSource(lookup, true);
565         XDMModel m2 = new XDMModel(ms);
566         m2.sync();
567         
568         List JavaDoc<Difference> diffs = Util.diff(m1, m2);
569         assertEquals(diffs.toString(), 5, diffs.size());
570 // assertFalse(((Change)diffs.get(2)).isAttributeChanged());
571
// assertTrue(((Change)diffs.get(2)).isPositionChanged());
572
// assertFalse(((Change)diffs.get(4)).isAttributeChanged());
573
// assertTrue(((Change)diffs.get(4)).isPositionChanged());
574

575         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
576         treeDiff.performDiffAndMutate(m1, m2.getDocument());
577         
578         m1.flush();
579         
580 // System.out.println("original doc: \n["+d1.getText(0,d1.getLength())+"]");
581
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
582
assertEquals("original document should be equivalent to merged document",
583                 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength()));
584         
585         List JavaDoc<Difference> zeroDiffs = Util.diff(m1, m2);
586         assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty());
587     }
588         
589     public void testPosChange3() throws Exception JavaDoc {
590         String JavaDoc FILE1 = "diff/posChange3.xml";
591         Document JavaDoc d1 = Util.getResourceAsDocument(FILE1);
592         Lookup lookup = Lookups.singleton(d1);
593         ModelSource ms = new ModelSource(lookup, true);
594         XDMModel m1 = new XDMModel(ms);
595         m1.sync();
596         
597         String JavaDoc FILE2 = "diff/posChange3_1.xml";
598         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
599         lookup = Lookups.singleton(d2);
600         ms = new ModelSource(lookup, true);
601         XDMModel m2 = new XDMModel(ms);
602         m2.sync();
603         
604         List JavaDoc<Difference> diffs = Util.diff(m1, m2);
605         assertEquals(diffs.toString(), 4, diffs.size());
606 // assertFalse(((Change)diffs.get(2)).isAttributeChanged());
607
// assertTrue(((Change)diffs.get(2)).isPositionChanged());
608
// assertFalse(((Change)diffs.get(4)).isAttributeChanged());
609
// assertTrue(((Change)diffs.get(4)).isPositionChanged());
610

611         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
612         treeDiff.performDiffAndMutate(m1, m2.getDocument());
613         
614         m1.flush();
615         
616 // System.out.println("diff: \n["+diffs.toString()+"]");
617
// System.out.println("resulting doc: \n["+d1.getText(0,d1.getLength())+"]");
618
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
619
assertEquals("original document should be equivalent to merged document",
620                 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength()));
621         
622         List JavaDoc<Difference> zeroDiffs = Util.diff(m1, m2);
623         assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty());
624     }
625         
626     public void testPosChange3_2() throws Exception JavaDoc {
627         String JavaDoc FILE1 = "diff/posChange3.xml";
628         Document JavaDoc d1 = Util.getResourceAsDocument(FILE1);
629         Lookup lookup = Lookups.singleton(d1);
630         ModelSource ms = new ModelSource(lookup, true);
631         XDMModel m1 = new XDMModel(ms);
632         m1.sync();
633         
634         String JavaDoc FILE2 = "diff/posChange3_2.xml";
635         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
636         lookup = Lookups.singleton(d2);
637         ms = new ModelSource(lookup, true);
638         XDMModel m2 = new XDMModel(ms);
639         m2.sync();
640         
641         List JavaDoc<Difference> diffs = Util.diff(m1, m2);
642 // assertEquals(diffs.toString(), 4, diffs.size());
643
// assertFalse(((Change)diffs.get(2)).isAttributeChanged());
644
// assertTrue(((Change)diffs.get(2)).isPositionChanged());
645
// assertFalse(((Change)diffs.get(4)).isAttributeChanged());
646
// assertTrue(((Change)diffs.get(4)).isPositionChanged());
647

648         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
649         treeDiff.performDiffAndMutate(m1, m2.getDocument());
650         
651         m1.flush();
652         
653 // System.out.println("diff: \n["+diffs.toString()+"]");
654
// System.out.println("resulting doc: \n["+d1.getText(0,d1.getLength())+"]");
655
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
656
assertEquals("original document should be equivalent to merged document",
657                 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength()));
658         
659         List JavaDoc<Difference> zeroDiffs = Util.diff(m1, m2);
660         assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty());
661     }
662     
663     public void testPosChange3_3() throws Exception JavaDoc {
664         String JavaDoc FILE1 = "diff/posChange3.xml";
665         Document JavaDoc d1 = Util.getResourceAsDocument(FILE1);
666         Lookup lookup = Lookups.singleton(d1);
667         ModelSource ms = new ModelSource(lookup, true);
668         XDMModel m1 = new XDMModel(ms);
669         m1.sync();
670         
671         String JavaDoc FILE2 = "diff/posChange3_3.xml";
672         Document JavaDoc d2 = Util.getResourceAsDocument(FILE2);
673         lookup = Lookups.singleton(d2);
674         ms = new ModelSource(lookup, true);
675         XDMModel m2 = new XDMModel(ms);
676         m2.sync();
677         
678         List JavaDoc<Difference> diffs = Util.diff(m1, m2);
679 // assertEquals(diffs.toString(), 4, diffs.size());
680
// assertFalse(((Change)diffs.get(2)).isAttributeChanged());
681
// assertTrue(((Change)diffs.get(2)).isPositionChanged());
682
// assertFalse(((Change)diffs.get(4)).isAttributeChanged());
683
// assertTrue(((Change)diffs.get(4)).isPositionChanged());
684

685         XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
686         treeDiff.performDiffAndMutate(m1, m2.getDocument());
687         
688         m1.flush();
689         
690 // System.out.println("diff: \n["+diffs.toString()+"]");
691
// System.out.println("resulting doc: \n["+d1.getText(0,d1.getLength())+"]");
692
// System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
693
assertEquals("original document should be equivalent to merged document",
694                 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength()));
695         
696         List JavaDoc<Difference> zeroDiffs = Util.diff(m1, m2);
697         assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty());
698     }
699
700     public void testMergeVenetianBlindPO() throws Exception JavaDoc {
701         javax.swing.text.Document JavaDoc doc1 = Util.getResourceAsDocument("resources/po_venetian.xsd");
702         XDMModel mod1 = Util.loadXDMModel(doc1);
703         javax.swing.text.Document JavaDoc doc2 = Util. getResourceAsDocument("resources/po.xsd");
704         XDMModel mod2 = Util.loadXDMModel(doc2);
705         List JavaDoc<Difference> diffs = Util.diff(mod1, mod2);
706         for (Iterator JavaDoc<Difference> i = diffs.iterator(); i.hasNext();) {
707             Difference d = i.next();
708             if (d instanceof Change) {
709                 Change c = (Change) d;
710                 if (c.isPositionChanged() && c.getOldNodeInfo().getParent().getId() == 1) {
711                     //FIXME assertFalse("There should be no position changes", true);
712
i.remove();
713                 }
714             }
715         }
716         merge(mod1, diffs);
717         String JavaDoc text1 = doc1.getText(0, doc1.getLength());
718         String JavaDoc text2 = doc2.getText(0, doc2.getLength());
719         //FIXME
720
//assertEquals(text2, text1);
721
}
722     
723     public void testForwardReorderNodeWithChangesOnChildren() throws Exception JavaDoc {
724         javax.swing.text.Document JavaDoc doc1 = Util.getResourceAsDocument("diff/posChange4.xml");
725         XDMModel mod1 = Util.loadXDMModel(doc1);
726         javax.swing.text.Document JavaDoc doc2 = Util.getResourceAsDocument("diff/posChange4_WithChildrenChanges.xml");
727         XDMModel mod2 = Util.loadXDMModel(doc2);
728         List JavaDoc<Difference> diffs = Util.diff(mod1, mod2);
729         
730         merge(mod1, diffs);
731         String JavaDoc text1 = doc1.getText(0, doc1.getLength());
732         String JavaDoc text2 = doc2.getText(0, doc2.getLength());
733         assertEquals(text2, text1);
734     }
735     
736     public void testMergeReformatDiff() throws Exception JavaDoc {
737         javax.swing.text.Document JavaDoc doc1 = Util.getResourceAsDocument("diff/newWSDL1.wsdl");
738         XDMModel mod1 = Util.loadXDMModel(doc1);
739         javax.swing.text.Document JavaDoc doc2 = Util.getResourceAsDocument("diff/newWSDL1_reformat.wsdl");
740         XDMModel mod2 = Util.loadXDMModel(doc2);
741         List JavaDoc<Difference> diffs = Util.diff(mod1, mod2);
742         merge(mod1, diffs);
743         String JavaDoc text1 = doc1.getText(0, doc1.getLength());
744         String JavaDoc text2 = doc2.getText(0, doc2.getLength());
745         assertEquals(text2, text1);
746     }
747     
748     DefaultElementIdentity eID = createEid();
749 }
750
Popular Tags