001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * MergeDiffTest.java
044: * JUnit based test
045: *
046: * Created on February 2, 2006, 4:15 PM
047: */
048:
049: package org.netbeans.modules.xml.xdm.diff;
050:
051: import java.io.File;
052: import java.util.Iterator;
053: import java.util.List;
054: import junit.framework.*;
055: import org.netbeans.modules.xml.xdm.Util;
056: import org.netbeans.modules.xml.xdm.XDMModel;
057: import javax.swing.text.Document;
058: import org.netbeans.modules.xml.xam.ModelSource;
059: import org.openide.util.Lookup;
060: import org.openide.util.lookup.Lookups;
061:
062: /**
063: * class to test MergeDiff
064: * Make sure cover all these test cases:
065: * 1. just change tokens
066: * 2. just attribute
067: * 3. both token and attribute change
068: * 4. just children
069: * 5. just position change
070: * 6. both postion change and add or delete
071: * 7. all-in-one
072: *
073: * @author Ayub Khan
074: */
075: public class MergeDiffTest extends TestCase {
076:
077: public MergeDiffTest(String testName) {
078: super (testName);
079: }
080:
081: protected void setUp() throws Exception {
082: }
083:
084: static DefaultElementIdentity createEid() {
085: //Establish DOM element identities
086: DefaultElementIdentity eid = new DefaultElementIdentity();
087: //Following values are suitable for Schema and WSDL documents
088: eid.addIdentifier("id");
089: eid.addIdentifier("name");
090: eid.addIdentifier("ref");
091: return eid;
092: }
093:
094: protected void tearDown() throws Exception {
095: }
096:
097: public static Test suite() {
098: // TestSuite suite = new TestSuite(MergeDiffTest.class);
099: TestSuite suite = new TestSuite();
100: suite.addTest(new MergeDiffTest("testMerge1"));
101: suite.addTest(new MergeDiffTest("testMerge2"));
102: suite.addTest(new MergeDiffTest("testMerge3"));
103: suite.addTest(new MergeDiffTest("testMerge4"));
104: suite.addTest(new MergeDiffTest("testMerge5"));
105: suite.addTest(new MergeDiffTest("testMerge6"));
106: suite.addTest(new MergeDiffTest("testMerge7"));
107: suite.addTest(new MergeDiffTest("testMerge8"));
108: suite.addTest(new MergeDiffTest("testMerge9"));
109: suite.addTest(new MergeDiffTest("testMerge10"));
110: suite.addTest(new MergeDiffTest("testPrettyPrint"));
111: suite.addTest(new MergeDiffTest("testSelfClosing"));
112: suite.addTest(new MergeDiffTest(
113: "testAddChangeAttributeSameNode"));
114: suite.addTest(new MergeDiffTest(
115: "testElementAddedBeforeChildAttributeChange"));
116: suite.addTest(new MergeDiffTest("testPosChange"));
117: suite.addTest(new MergeDiffTest("testPosChange2"));
118: suite.addTest(new MergeDiffTest("testPosChange3"));
119: suite.addTest(new MergeDiffTest("testPosChange3_2"));
120: suite.addTest(new MergeDiffTest("testPosChange3_3"));
121: suite.addTest(new MergeDiffTest("testMergeVenetianBlindPO"));
122: suite.addTest(new MergeDiffTest(
123: "testForwardReorderNodeWithChangesOnChildren"));
124: suite.addTest(new MergeDiffTest("testMergeReformatDiff"));
125: return suite;
126: }
127:
128: public void testMerge1() throws Exception {
129:
130: String FILE1 = "diff/schema3.xsd";
131: Document originalDocument = Util.getResourceAsDocument(FILE1);
132: Lookup lookup = Lookups.singleton(originalDocument);
133: ModelSource ms = new ModelSource(lookup, true);
134: XDMModel originalModel = new XDMModel(ms);
135: originalModel.sync();
136:
137: String FILE2 = "diff/schema5.xsd";
138: Document d2 = Util.getResourceAsDocument(FILE2);
139: lookup = Lookups.singleton(d2);
140: ms = new ModelSource(lookup, true);
141: XDMModel m2 = new XDMModel(ms);
142: m2.sync();
143:
144: // long startTime=System.currentTimeMillis();
145:
146: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
147: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
148:
149: // long endTime=System.currentTimeMillis();
150: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
151: // "Total time to merge schema1.xsd to schema3.xsd: "+(endTime-startTime)+"ms");
152: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
153:
154: originalModel.flush();
155:
156: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
157: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
158: assertEquals(
159: "original document should be equivalent to merged document",
160: d2.getText(0, d2.getLength()), originalDocument
161: .getText(0, originalDocument.getLength()));
162: }
163:
164: public void testMerge2() throws Exception {
165:
166: String FILE1 = "diff/PurchaseOrder.xsd";
167: Document originalDocument = Util.getResourceAsDocument(FILE1);
168: Lookup lookup = Lookups.singleton(originalDocument);
169: ModelSource ms = new ModelSource(lookup, true);
170: XDMModel originalModel = new XDMModel(ms);
171: originalModel.sync();
172:
173: String FILE2 = "diff/PurchaseOrderSyncTest.xsd";
174: Document d2 = Util.getResourceAsDocument(FILE2);
175: lookup = Lookups.singleton(d2);
176: ms = new ModelSource(lookup, true);
177: XDMModel m2 = new XDMModel(ms);
178: m2.sync();
179:
180: // long startTime=System.currentTimeMillis();
181:
182: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
183: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
184:
185: // long endTime=System.currentTimeMillis();
186: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
187: // "Total time to merge PurchaseOrder.xsd: "+(endTime-startTime)+"ms");
188: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
189:
190: originalModel.flush();
191:
192: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
193: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
194: assertEquals(
195: "original document should be equivalent to merged document",
196: d2.getText(0, d2.getLength()), originalDocument
197: .getText(0, originalDocument.getLength()));
198: }
199:
200: public void testMerge3() throws Exception {
201:
202: String FILE1 = "diff/TravelItinerary1.xsd";
203: Document originalDocument = Util.getResourceAsDocument(FILE1);
204: Lookup lookup = Lookups.singleton(originalDocument);
205: ModelSource ms = new ModelSource(lookup, true);
206: XDMModel originalModel = new XDMModel(ms);
207: originalModel.sync();
208:
209: String FILE2 = "diff/TravelItinerary2.xsd";
210: Document d2 = Util.getResourceAsDocument(FILE2);
211: lookup = Lookups.singleton(d2);
212: ms = new ModelSource(lookup, true);
213: XDMModel m2 = new XDMModel(ms);
214: m2.sync();
215:
216: long startTime = System.currentTimeMillis();
217:
218: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
219: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
220:
221: long endTime = System.currentTimeMillis();
222: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
223: // "Total time to merge TravelItinerary: "+(endTime-startTime)+"ms");
224: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
225:
226: originalModel.flush();
227:
228: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
229: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
230: assertEquals(
231: "original document should be equivalent to merged document",
232: d2.getText(0, d2.getLength()), originalDocument
233: .getText(0, originalDocument.getLength()));
234: }
235:
236: public void testMerge4() throws Exception {
237:
238: String FILE1 = "diff/testaddshape.xml";
239: Document originalDocument = Util.getResourceAsDocument(FILE1);
240: Lookup lookup = Lookups.singleton(originalDocument);
241: ModelSource ms = new ModelSource(lookup, true);
242: XDMModel originalModel = new XDMModel(ms);
243: originalModel.sync();
244:
245: String FILE2 = "diff/addshape.xml";
246: Document d2 = Util.getResourceAsDocument(FILE2);
247: lookup = Lookups.singleton(d2);
248: ms = new ModelSource(lookup, true);
249: XDMModel m2 = new XDMModel(ms);
250: m2.sync();
251:
252: // long startTime=System.currentTimeMillis();
253:
254: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
255: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
256:
257: // long endTime=System.currentTimeMillis();
258: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
259: // "Total time to merge addshape.xml: "+(endTime-startTime)+"ms");
260: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
261:
262: originalModel.flush();
263:
264: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
265: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
266: assertEquals(
267: "original document should be equivalent to merged document",
268: d2.getText(0, d2.getLength()), originalDocument
269: .getText(0, originalDocument.getLength()));
270: }
271:
272: public void testMerge5() throws Exception {
273:
274: String FILE1 = "diff/testbase.xml";
275: Document originalDocument = Util.getResourceAsDocument(FILE1);
276: Lookup lookup = Lookups.singleton(originalDocument);
277: ModelSource ms = new ModelSource(lookup, true);
278: XDMModel originalModel = new XDMModel(ms);
279: originalModel.sync();
280:
281: String FILE2 = "diff/commentTextChanged.xml";
282: Document d2 = Util.getResourceAsDocument(FILE2);
283: lookup = Lookups.singleton(d2);
284: ms = new ModelSource(lookup, true);
285: XDMModel m2 = new XDMModel(ms);
286: m2.sync();
287:
288: // long startTime=System.currentTimeMillis();
289:
290: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
291: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
292:
293: // long endTime=System.currentTimeMillis();
294: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
295: // "Total time to merge textchange.xml: "+(endTime-startTime)+"ms");
296: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
297:
298: originalModel.flush();
299:
300: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
301: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
302: assertEquals(
303: "original document should be equivalent to merged document",
304: d2.getText(0, d2.getLength()), originalDocument
305: .getText(0, originalDocument.getLength()));
306: }
307:
308: public void testMerge6() throws Exception {
309:
310: String FILE1 = "diff/TestOperations.wsdl";
311: Document originalDocument = Util.getResourceAsDocument(FILE1);
312: Lookup lookup = Lookups.singleton(originalDocument);
313: ModelSource ms = new ModelSource(lookup, true);
314: XDMModel originalModel = new XDMModel(ms);
315: originalModel.sync();
316:
317: String FILE2 = "diff/TestOperations_after.wsdl";
318: Document d2 = Util.getResourceAsDocument(FILE2);
319: lookup = Lookups.singleton(d2);
320: ms = new ModelSource(lookup, true);
321: XDMModel m2 = new XDMModel(ms);
322: m2.sync();
323:
324: // long startTime=System.currentTimeMillis();
325:
326: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
327: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
328:
329: // long endTime=System.currentTimeMillis();
330: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
331: // "Total time to merge textchange.xml: "+(endTime-startTime)+"ms");
332: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
333:
334: originalModel.flush();
335:
336: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
337: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
338: assertEquals(
339: "original document should be equivalent to merged document",
340: d2.getText(0, d2.getLength()), originalDocument
341: .getText(0, originalDocument.getLength()));
342: }
343:
344: public void testMerge7() throws Exception {
345:
346: String FILE1 = "diff/VehicleReservationService.wsdl";
347: Document originalDocument = Util.getResourceAsDocument(FILE1);
348: Lookup lookup = Lookups.singleton(originalDocument);
349: ModelSource ms = new ModelSource(lookup, true);
350: XDMModel originalModel = new XDMModel(ms);
351: originalModel.sync();
352:
353: String FILE2 = "diff/Vehicle_PartnerLinkChanged2.wsdl";
354: Document d2 = Util.getResourceAsDocument(FILE2);
355: lookup = Lookups.singleton(d2);
356: ms = new ModelSource(lookup, true);
357: XDMModel m2 = new XDMModel(ms);
358: m2.sync();
359:
360: // long startTime=System.currentTimeMillis();
361:
362: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
363: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
364:
365: // long endTime=System.currentTimeMillis();
366: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
367: // "Total time to merge textchange.xml: "+(endTime-startTime)+"ms");
368: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
369:
370: originalModel.flush();
371:
372: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
373: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
374: assertEquals(
375: "original document should be equivalent to merged document",
376: d2.getText(0, d2.getLength()), originalDocument
377: .getText(0, originalDocument.getLength()));
378: }
379:
380: public void testMerge8() throws Exception {
381:
382: String FILE1 = "diff/UBL-CommonAggregateComponents-1.0.xsd";
383: Document originalDocument = Util.getResourceAsDocument(FILE1);
384: Lookup lookup = Lookups.singleton(originalDocument);
385: ModelSource ms = new ModelSource(lookup, true);
386: XDMModel originalModel = new XDMModel(ms);
387: originalModel.sync();
388:
389: String FILE2 = "diff/UBL-CommonAggregateComponents-1.0.xsd";
390: Document d2 = Util.getResourceAsDocument(FILE2);
391: lookup = Lookups.singleton(d2);
392: ms = new ModelSource(lookup, true);
393: XDMModel m2 = new XDMModel(ms);
394: m2.sync();
395:
396: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
397: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
398:
399: originalModel.flush();
400: assertEquals(
401: "original document should be equivalent to merged document",
402: d2.getText(0, d2.getLength()), originalDocument
403: .getText(0, originalDocument.getLength()));
404: }
405:
406: public void testMerge9() throws Exception {
407:
408: String FILE1 = "diff/schema3.xsd";
409: Document originalDocument = Util.getResourceAsDocument(FILE1);
410: Lookup lookup = Lookups.singleton(originalDocument);
411: ModelSource ms = new ModelSource(lookup, true);
412: XDMModel originalModel = new XDMModel(ms);
413: originalModel.sync();
414:
415: String FILE2 = "diff/schema4.xsd";
416: Document d2 = Util.getResourceAsDocument(FILE2);
417: lookup = Lookups.singleton(d2);
418: ms = new ModelSource(lookup, true);
419: XDMModel m2 = new XDMModel(ms);
420: m2.sync();
421:
422: // long startTime=System.currentTimeMillis();
423:
424: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
425: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
426:
427: // long endTime=System.currentTimeMillis();
428: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
429: // "Total time to merge schema1.xsd to schema3.xsd: "+(endTime-startTime)+"ms");
430: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
431:
432: originalModel.flush();
433:
434: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
435: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
436: assertEquals(
437: "original document should be equivalent to merged document",
438: d2.getText(0, d2.getLength()), originalDocument
439: .getText(0, originalDocument.getLength()));
440: }
441:
442: public void testMerge10() throws Exception {
443:
444: String FILE1 = "diff/schema4.xsd";
445: Document originalDocument = Util.getResourceAsDocument(FILE1);
446: Lookup lookup = Lookups.singleton(originalDocument);
447: ModelSource ms = new ModelSource(lookup, true);
448: XDMModel originalModel = new XDMModel(ms);
449: originalModel.sync();
450:
451: String FILE2 = "diff/schema5.xsd";
452: Document d2 = Util.getResourceAsDocument(FILE2);
453: lookup = Lookups.singleton(d2);
454: ms = new ModelSource(lookup, true);
455: XDMModel m2 = new XDMModel(ms);
456: m2.sync();
457:
458: // long startTime=System.currentTimeMillis();
459:
460: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
461: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
462:
463: // long endTime=System.currentTimeMillis();
464: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
465: // "Total time to merge schema1.xsd to schema3.xsd: "+(endTime-startTime)+"ms");
466: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
467:
468: originalModel.flush();
469:
470: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
471: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
472: assertEquals(
473: "original document should be equivalent to merged document",
474: d2.getText(0, d2.getLength()), originalDocument
475: .getText(0, originalDocument.getLength()));
476: }
477:
478: public void testPrettyPrint() throws Exception {
479:
480: String FILE1 = "diff/prettyprint1.xml";
481: Document originalDocument = Util.getResourceAsDocument(FILE1);
482: Lookup lookup = Lookups.singleton(originalDocument);
483: ModelSource ms = new ModelSource(lookup, true);
484: XDMModel originalModel = new XDMModel(ms);
485: originalModel.sync();
486:
487: String FILE2 = "diff/prettyprint2.xml";
488: Document d2 = Util.getResourceAsDocument(FILE2);
489: lookup = Lookups.singleton(d2);
490: ms = new ModelSource(lookup, true);
491: XDMModel m2 = new XDMModel(ms);
492: m2.sync();
493:
494: // long startTime=System.currentTimeMillis();
495:
496: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
497: treeDiff.performDiffAndMutate(originalModel, m2.getDocument());
498:
499: // long endTime=System.currentTimeMillis();
500: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::\n" +
501: // "Total time to merge schema1.xsd to schema3.xsd: "+(endTime-startTime)+"ms");
502: // System.out.println("::::::::::::::::::::::::::::::::::::::::::::");
503:
504: originalModel.flush();
505:
506: // System.out.println("original doc: \n["+originalDocument.getText(0,originalDocument.getLength())+"]");
507: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
508: assertEquals(
509: "original document should be equivalent to merged document",
510: d2.getText(0, d2.getLength()), originalDocument
511: .getText(0, originalDocument.getLength()));
512: }
513:
514: public static void merge(XDMModel model, List<Difference> diffs) {
515: model.mergeDiff(diffs);
516: model.flush();
517: }
518:
519: public void testSelfClosing() throws Exception {
520: XDMModel mod1 = Util.loadXDMModel("not_selfClosing.xml");
521: XDMModel mod2 = Util.loadXDMModel("selfClosing.xml");
522: List<Difference> diffs = Util.diff(mod1, mod2);
523: assertEquals(diffs.toString(), 2, diffs.size());
524: merge(mod1, diffs);
525: List<Difference> zeroDiffs = Util.diff(mod1, mod2);
526: assertTrue("before:" + diffs.toString() + " after:"
527: + zeroDiffs.toString(), zeroDiffs.isEmpty());
528: }
529:
530: public void testAddChangeAttributeSameNode() throws Exception {
531: XDMModel mod1 = Util.loadXDMModel("diff/PurchaseOrder2.xsd");
532: XDMModel mod2 = Util
533: .loadXDMModel("diff/PurchaseOrderSyncTest2.xsd");
534: List<Difference> diffs = Util.diff(mod1, mod2);
535: //assertEquals(diffs.toString(), 4, diffs.size());
536: merge(mod1, diffs);
537: List<Difference> zeroDiffs = Util.diff(mod1, mod2);
538: assertTrue("before:" + diffs.toString() + " after:"
539: + zeroDiffs.toString(), zeroDiffs.isEmpty());
540: }
541:
542: public void testElementAddedBeforeChildAttributeChange()
543: throws Exception {
544: String FILE1 = "diff/test2.xml";
545: Document d1 = Util.getResourceAsDocument(FILE1);
546: Lookup lookup = Lookups.singleton(d1);
547: ModelSource ms = new ModelSource(lookup, true);
548: XDMModel m1 = new XDMModel(ms);
549: m1.sync();
550:
551: String FILE2 = "diff/test2_1.xml";
552: Document d2 = Util.getResourceAsDocument(FILE2);
553: lookup = Lookups.singleton(d2);
554: ms = new ModelSource(lookup, true);
555: XDMModel m2 = new XDMModel(ms);
556: m2.sync();
557:
558: List<Difference> diffs = Util.diff(m1, m2);
559: assertEquals(diffs.toString(), 9, diffs.size());
560: assertTrue(((Change) diffs.get(3)).isAttributeChanged());
561: assertFalse(((Change) diffs.get(3)).isPositionChanged());
562: assertFalse(((Change) diffs.get(4)).isAttributeChanged());
563: assertTrue(((Change) diffs.get(4)).isPositionChanged());
564:
565: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
566: treeDiff.performDiffAndMutate(m1, m2.getDocument());
567:
568: m1.flush();
569:
570: // System.out.println("original doc: \n["+d1.getText(0,d1.getLength())+"]");
571: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
572: assertEquals(
573: "original document should be equivalent to merged document",
574: d2.getText(0, d2.getLength()), d1.getText(0, d1
575: .getLength()));
576:
577: List<Difference> zeroDiffs = Util.diff(m1, m2);
578: assertTrue("before:" + diffs.toString() + "\nafter:"
579: + zeroDiffs.toString(), zeroDiffs.isEmpty());
580: }
581:
582: public void testPosChange() throws Exception {
583: String FILE1 = "diff/posChange1.xml";
584: Document d1 = Util.getResourceAsDocument(FILE1);
585: Lookup lookup = Lookups.singleton(d1);
586: ModelSource ms = new ModelSource(lookup, true);
587: XDMModel m1 = new XDMModel(ms);
588: m1.sync();
589:
590: String FILE2 = "diff/posChange1_1.xml";
591: Document d2 = Util.getResourceAsDocument(FILE2);
592: lookup = Lookups.singleton(d2);
593: ms = new ModelSource(lookup, true);
594: XDMModel m2 = new XDMModel(ms);
595: m2.sync();
596:
597: List<Difference> diffs = Util.diff(m1, m2);
598: assertEquals(diffs.toString(), 4, diffs.size());
599: // assertFalse(((Change)diffs.get(2)).isAttributeChanged());
600: // assertTrue(((Change)diffs.get(2)).isPositionChanged());
601: // assertFalse(((Change)diffs.get(4)).isAttributeChanged());
602: // assertTrue(((Change)diffs.get(4)).isPositionChanged());
603:
604: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
605: treeDiff.performDiffAndMutate(m1, m2.getDocument());
606:
607: m1.flush();
608:
609: // System.out.println("diff: \n["+diffs.toString()+"]");
610: // System.out.println("resulting doc: \n["+d1.getText(0,d1.getLength())+"]");
611: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
612: assertEquals(
613: "original document should be equivalent to merged document",
614: d2.getText(0, d2.getLength()), d1.getText(0, d1
615: .getLength()));
616:
617: List<Difference> zeroDiffs = Util.diff(m1, m2);
618: assertTrue("before:" + diffs.toString() + "\nafter:"
619: + zeroDiffs.toString(), zeroDiffs.isEmpty());
620: }
621:
622: public void testPosChange2() throws Exception {
623: String FILE1 = "diff/posChange2.xml";
624: Document d1 = Util.getResourceAsDocument(FILE1);
625: Lookup lookup = Lookups.singleton(d1);
626: ModelSource ms = new ModelSource(lookup, true);
627: XDMModel m1 = new XDMModel(ms);
628: m1.sync();
629:
630: String FILE2 = "diff/posChange2_1.xml";
631: Document d2 = Util.getResourceAsDocument(FILE2);
632: lookup = Lookups.singleton(d2);
633: ms = new ModelSource(lookup, true);
634: XDMModel m2 = new XDMModel(ms);
635: m2.sync();
636:
637: List<Difference> diffs = Util.diff(m1, m2);
638: assertEquals(diffs.toString(), 5, diffs.size());
639: // assertFalse(((Change)diffs.get(2)).isAttributeChanged());
640: // assertTrue(((Change)diffs.get(2)).isPositionChanged());
641: // assertFalse(((Change)diffs.get(4)).isAttributeChanged());
642: // assertTrue(((Change)diffs.get(4)).isPositionChanged());
643:
644: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
645: treeDiff.performDiffAndMutate(m1, m2.getDocument());
646:
647: m1.flush();
648:
649: // System.out.println("original doc: \n["+d1.getText(0,d1.getLength())+"]");
650: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
651: assertEquals(
652: "original document should be equivalent to merged document",
653: d2.getText(0, d2.getLength()), d1.getText(0, d1
654: .getLength()));
655:
656: List<Difference> zeroDiffs = Util.diff(m1, m2);
657: assertTrue("before:" + diffs.toString() + "\nafter:"
658: + zeroDiffs.toString(), zeroDiffs.isEmpty());
659: }
660:
661: public void testPosChange3() throws Exception {
662: String FILE1 = "diff/posChange3.xml";
663: Document d1 = Util.getResourceAsDocument(FILE1);
664: Lookup lookup = Lookups.singleton(d1);
665: ModelSource ms = new ModelSource(lookup, true);
666: XDMModel m1 = new XDMModel(ms);
667: m1.sync();
668:
669: String FILE2 = "diff/posChange3_1.xml";
670: Document d2 = Util.getResourceAsDocument(FILE2);
671: lookup = Lookups.singleton(d2);
672: ms = new ModelSource(lookup, true);
673: XDMModel m2 = new XDMModel(ms);
674: m2.sync();
675:
676: List<Difference> diffs = Util.diff(m1, m2);
677: assertEquals(diffs.toString(), 4, diffs.size());
678: // assertFalse(((Change)diffs.get(2)).isAttributeChanged());
679: // assertTrue(((Change)diffs.get(2)).isPositionChanged());
680: // assertFalse(((Change)diffs.get(4)).isAttributeChanged());
681: // assertTrue(((Change)diffs.get(4)).isPositionChanged());
682:
683: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
684: treeDiff.performDiffAndMutate(m1, m2.getDocument());
685:
686: m1.flush();
687:
688: // System.out.println("diff: \n["+diffs.toString()+"]");
689: // System.out.println("resulting doc: \n["+d1.getText(0,d1.getLength())+"]");
690: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
691: assertEquals(
692: "original document should be equivalent to merged document",
693: d2.getText(0, d2.getLength()), d1.getText(0, d1
694: .getLength()));
695:
696: List<Difference> zeroDiffs = Util.diff(m1, m2);
697: assertTrue("before:" + diffs.toString() + "\nafter:"
698: + zeroDiffs.toString(), zeroDiffs.isEmpty());
699: }
700:
701: public void testPosChange3_2() throws Exception {
702: String FILE1 = "diff/posChange3.xml";
703: Document d1 = Util.getResourceAsDocument(FILE1);
704: Lookup lookup = Lookups.singleton(d1);
705: ModelSource ms = new ModelSource(lookup, true);
706: XDMModel m1 = new XDMModel(ms);
707: m1.sync();
708:
709: String FILE2 = "diff/posChange3_2.xml";
710: Document d2 = Util.getResourceAsDocument(FILE2);
711: lookup = Lookups.singleton(d2);
712: ms = new ModelSource(lookup, true);
713: XDMModel m2 = new XDMModel(ms);
714: m2.sync();
715:
716: List<Difference> diffs = Util.diff(m1, m2);
717: // assertEquals(diffs.toString(), 4, diffs.size());
718: // assertFalse(((Change)diffs.get(2)).isAttributeChanged());
719: // assertTrue(((Change)diffs.get(2)).isPositionChanged());
720: // assertFalse(((Change)diffs.get(4)).isAttributeChanged());
721: // assertTrue(((Change)diffs.get(4)).isPositionChanged());
722:
723: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
724: treeDiff.performDiffAndMutate(m1, m2.getDocument());
725:
726: m1.flush();
727:
728: // System.out.println("diff: \n["+diffs.toString()+"]");
729: // System.out.println("resulting doc: \n["+d1.getText(0,d1.getLength())+"]");
730: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
731: assertEquals(
732: "original document should be equivalent to merged document",
733: d2.getText(0, d2.getLength()), d1.getText(0, d1
734: .getLength()));
735:
736: List<Difference> zeroDiffs = Util.diff(m1, m2);
737: assertTrue("before:" + diffs.toString() + "\nafter:"
738: + zeroDiffs.toString(), zeroDiffs.isEmpty());
739: }
740:
741: public void testPosChange3_3() throws Exception {
742: String FILE1 = "diff/posChange3.xml";
743: Document d1 = Util.getResourceAsDocument(FILE1);
744: Lookup lookup = Lookups.singleton(d1);
745: ModelSource ms = new ModelSource(lookup, true);
746: XDMModel m1 = new XDMModel(ms);
747: m1.sync();
748:
749: String FILE2 = "diff/posChange3_3.xml";
750: Document d2 = Util.getResourceAsDocument(FILE2);
751: lookup = Lookups.singleton(d2);
752: ms = new ModelSource(lookup, true);
753: XDMModel m2 = new XDMModel(ms);
754: m2.sync();
755:
756: List<Difference> diffs = Util.diff(m1, m2);
757: // assertEquals(diffs.toString(), 4, diffs.size());
758: // assertFalse(((Change)diffs.get(2)).isAttributeChanged());
759: // assertTrue(((Change)diffs.get(2)).isPositionChanged());
760: // assertFalse(((Change)diffs.get(4)).isAttributeChanged());
761: // assertTrue(((Change)diffs.get(4)).isPositionChanged());
762:
763: XDMTreeDiff treeDiff = new XDMTreeDiff(eID);
764: treeDiff.performDiffAndMutate(m1, m2.getDocument());
765:
766: m1.flush();
767:
768: // System.out.println("diff: \n["+diffs.toString()+"]");
769: // System.out.println("resulting doc: \n["+d1.getText(0,d1.getLength())+"]");
770: // System.out.println("target doc: \n["+d2.getText(0,d2.getLength())+"]");
771: assertEquals(
772: "original document should be equivalent to merged document",
773: d2.getText(0, d2.getLength()), d1.getText(0, d1
774: .getLength()));
775:
776: List<Difference> zeroDiffs = Util.diff(m1, m2);
777: assertTrue("before:" + diffs.toString() + "\nafter:"
778: + zeroDiffs.toString(), zeroDiffs.isEmpty());
779: }
780:
781: public void testMergeVenetianBlindPO() throws Exception {
782: javax.swing.text.Document doc1 = Util
783: .getResourceAsDocument("resources/po_venetian.xsd");
784: XDMModel mod1 = Util.loadXDMModel(doc1);
785: javax.swing.text.Document doc2 = Util
786: .getResourceAsDocument("resources/po.xsd");
787: XDMModel mod2 = Util.loadXDMModel(doc2);
788: List<Difference> diffs = Util.diff(mod1, mod2);
789: for (Iterator<Difference> i = diffs.iterator(); i.hasNext();) {
790: Difference d = i.next();
791: if (d instanceof Change) {
792: Change c = (Change) d;
793: if (c.isPositionChanged()
794: && c.getOldNodeInfo().getParent().getId() == 1) {
795: //FIXME assertFalse("There should be no position changes", true);
796: i.remove();
797: }
798: }
799: }
800: merge(mod1, diffs);
801: String text1 = doc1.getText(0, doc1.getLength());
802: String text2 = doc2.getText(0, doc2.getLength());
803: //FIXME
804: //assertEquals(text2, text1);
805: }
806:
807: public void testForwardReorderNodeWithChangesOnChildren()
808: throws Exception {
809: javax.swing.text.Document doc1 = Util
810: .getResourceAsDocument("diff/posChange4.xml");
811: XDMModel mod1 = Util.loadXDMModel(doc1);
812: javax.swing.text.Document doc2 = Util
813: .getResourceAsDocument("diff/posChange4_WithChildrenChanges.xml");
814: XDMModel mod2 = Util.loadXDMModel(doc2);
815: List<Difference> diffs = Util.diff(mod1, mod2);
816:
817: merge(mod1, diffs);
818: String text1 = doc1.getText(0, doc1.getLength());
819: String text2 = doc2.getText(0, doc2.getLength());
820: assertEquals(text2, text1);
821: }
822:
823: public void testMergeReformatDiff() throws Exception {
824: javax.swing.text.Document doc1 = Util
825: .getResourceAsDocument("diff/newWSDL1.wsdl");
826: XDMModel mod1 = Util.loadXDMModel(doc1);
827: javax.swing.text.Document doc2 = Util
828: .getResourceAsDocument("diff/newWSDL1_reformat.wsdl");
829: XDMModel mod2 = Util.loadXDMModel(doc2);
830: List<Difference> diffs = Util.diff(mod1, mod2);
831: merge(mod1, diffs);
832: String text1 = doc1.getText(0, doc1.getLength());
833: String text2 = doc2.getText(0, doc2.getLength());
834: assertEquals(text2, text1);
835: }
836:
837: DefaultElementIdentity eID = createEid();
838: }
|