1 7 8 package org.netbeans.modules.xml.xdm.diff; 9 10 import java.io.File ; 11 import java.util.Iterator ; 12 import java.util.List ; 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 ; 17 import org.netbeans.modules.xml.xam.ModelSource; 18 import org.openide.util.Lookup; 19 import org.openide.util.lookup.Lookups; 20 21 34 public class MergeDiffTest extends TestCase { 35 36 public MergeDiffTest(String testName) { 37 super(testName); 38 } 39 40 protected void setUp() throws Exception { 41 } 42 43 static DefaultElementIdentity createEid() { 44 DefaultElementIdentity eid = new DefaultElementIdentity(); 46 eid.addIdentifier( "id" ); 48 eid.addIdentifier( "name" ); 49 eid.addIdentifier( "ref" ); 50 return eid; 51 } 52 53 protected void tearDown() throws Exception { 54 } 55 56 public static Test suite() { 57 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 { 85 86 String FILE1 = "diff/schema3.xsd"; 87 Document 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 FILE2 = "diff/schema5.xsd"; 94 Document 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 102 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 103 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 104 105 110 originalModel.flush(); 111 112 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 { 119 120 String FILE1 = "diff/PurchaseOrder.xsd"; 121 Document 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 FILE2 = "diff/PurchaseOrderSyncTest.xsd"; 128 Document 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 136 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 137 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 138 139 144 originalModel.flush(); 145 146 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 { 154 155 String FILE1 = "diff/TravelItinerary1.xsd"; 156 Document 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 FILE2 = "diff/TravelItinerary2.xsd"; 163 Document 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 179 originalModel.flush(); 180 181 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 { 189 190 String FILE1 = "diff/testaddshape.xml"; 191 Document 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 FILE2 = "diff/addshape.xml"; 198 Document 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 206 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 207 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 208 209 214 originalModel.flush(); 215 216 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 { 224 225 String FILE1 = "diff/testbase.xml"; 226 Document 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 FILE2 = "diff/commentTextChanged.xml"; 233 Document 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 241 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 242 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 243 244 249 originalModel.flush(); 250 251 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 { 259 260 String FILE1 = "diff/TestOperations.wsdl"; 261 Document 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 FILE2 = "diff/TestOperations_after.wsdl"; 268 Document 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 276 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 277 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 278 279 284 originalModel.flush(); 285 286 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 { 294 295 String FILE1 = "diff/VehicleReservationService.wsdl"; 296 Document 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 FILE2 = "diff/Vehicle_PartnerLinkChanged2.wsdl"; 303 Document 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 311 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 312 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 313 314 319 originalModel.flush(); 320 321 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 { 329 330 String FILE1 = "diff/UBL-CommonAggregateComponents-1.0.xsd"; 331 Document 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 FILE2 = "diff/UBL-CommonAggregateComponents-1.0.xsd"; 338 Document 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 { 354 355 String FILE1 = "diff/schema3.xsd"; 356 Document 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 FILE2 = "diff/schema4.xsd"; 363 Document 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 371 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 372 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 373 374 379 originalModel.flush(); 380 381 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 { 388 389 String FILE1 = "diff/schema4.xsd"; 390 Document 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 FILE2 = "diff/schema5.xsd"; 397 Document 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 405 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 406 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 407 408 413 originalModel.flush(); 414 415 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 { 422 423 String FILE1 = "diff/prettyprint1.xml"; 424 Document 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 FILE2 = "diff/prettyprint2.xml"; 431 Document 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 439 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 440 treeDiff.performDiffAndMutate(originalModel, m2.getDocument()); 441 442 447 originalModel.flush(); 448 449 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 <Difference> diffs) { 456 model.mergeDiff(diffs); 457 model.flush(); 458 } 459 460 public void testSelfClosing() throws Exception { 461 XDMModel mod1 = Util.loadXDMModel("not_selfClosing.xml"); 462 XDMModel mod2 = Util.loadXDMModel("selfClosing.xml"); 463 List <Difference> diffs = Util.diff(mod1, mod2); 464 assertEquals(diffs.toString(), 2, diffs.size()); 465 merge(mod1, diffs); 466 List <Difference> zeroDiffs = Util.diff(mod1, mod2); 467 assertTrue("before:"+diffs.toString()+" after:"+zeroDiffs.toString(), zeroDiffs.isEmpty()); 468 } 469 470 public void testAddChangeAttributeSameNode() throws Exception { 471 XDMModel mod1 = Util.loadXDMModel("diff/PurchaseOrder2.xsd"); 472 XDMModel mod2 = Util.loadXDMModel("diff/PurchaseOrderSyncTest2.xsd"); 473 List <Difference> diffs = Util.diff(mod1, mod2); 474 merge(mod1, diffs); 476 List <Difference> zeroDiffs = Util.diff(mod1, mod2); 477 assertTrue("before:"+diffs.toString()+" after:"+zeroDiffs.toString(), zeroDiffs.isEmpty()); 478 } 479 480 public void testElementAddedBeforeChildAttributeChange() throws Exception { 481 String FILE1 = "diff/test2.xml"; 482 Document 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 FILE2 = "diff/test2_1.xml"; 489 Document 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 <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 assertEquals("original document should be equivalent to merged document", 510 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength())); 511 512 List <Difference> zeroDiffs = Util.diff(m1, m2); 513 assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty()); 514 } 515 516 public void testPosChange() throws Exception { 517 String FILE1 = "diff/posChange1.xml"; 518 Document 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 FILE2 = "diff/posChange1_1.xml"; 525 Document 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 <Difference> diffs = Util.diff(m1, m2); 532 assertEquals(diffs.toString(), 4, diffs.size()); 533 538 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 539 treeDiff.performDiffAndMutate(m1, m2.getDocument()); 540 541 m1.flush(); 542 543 assertEquals("original document should be equivalent to merged document", 547 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength())); 548 549 List <Difference> zeroDiffs = Util.diff(m1, m2); 550 assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty()); 551 } 552 553 public void testPosChange2() throws Exception { 554 String FILE1 = "diff/posChange2.xml"; 555 Document 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 FILE2 = "diff/posChange2_1.xml"; 562 Document 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 <Difference> diffs = Util.diff(m1, m2); 569 assertEquals(diffs.toString(), 5, diffs.size()); 570 575 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 576 treeDiff.performDiffAndMutate(m1, m2.getDocument()); 577 578 m1.flush(); 579 580 assertEquals("original document should be equivalent to merged document", 583 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength())); 584 585 List <Difference> zeroDiffs = Util.diff(m1, m2); 586 assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty()); 587 } 588 589 public void testPosChange3() throws Exception { 590 String FILE1 = "diff/posChange3.xml"; 591 Document 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 FILE2 = "diff/posChange3_1.xml"; 598 Document 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 <Difference> diffs = Util.diff(m1, m2); 605 assertEquals(diffs.toString(), 4, diffs.size()); 606 611 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 612 treeDiff.performDiffAndMutate(m1, m2.getDocument()); 613 614 m1.flush(); 615 616 assertEquals("original document should be equivalent to merged document", 620 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength())); 621 622 List <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 { 627 String FILE1 = "diff/posChange3.xml"; 628 Document 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 FILE2 = "diff/posChange3_2.xml"; 635 Document 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 <Difference> diffs = Util.diff(m1, m2); 642 648 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 649 treeDiff.performDiffAndMutate(m1, m2.getDocument()); 650 651 m1.flush(); 652 653 assertEquals("original document should be equivalent to merged document", 657 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength())); 658 659 List <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 { 664 String FILE1 = "diff/posChange3.xml"; 665 Document 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 FILE2 = "diff/posChange3_3.xml"; 672 Document 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 <Difference> diffs = Util.diff(m1, m2); 679 685 XDMTreeDiff treeDiff = new XDMTreeDiff(eID); 686 treeDiff.performDiffAndMutate(m1, m2.getDocument()); 687 688 m1.flush(); 689 690 assertEquals("original document should be equivalent to merged document", 694 d2.getText(0,d2.getLength()), d1.getText(0,d1.getLength())); 695 696 List <Difference> zeroDiffs = Util.diff(m1, m2); 697 assertTrue("before:"+diffs.toString()+"\nafter:"+zeroDiffs.toString(), zeroDiffs.isEmpty()); 698 } 699 700 public void testMergeVenetianBlindPO() throws Exception { 701 javax.swing.text.Document doc1 = Util.getResourceAsDocument("resources/po_venetian.xsd"); 702 XDMModel mod1 = Util.loadXDMModel(doc1); 703 javax.swing.text.Document doc2 = Util. getResourceAsDocument("resources/po.xsd"); 704 XDMModel mod2 = Util.loadXDMModel(doc2); 705 List <Difference> diffs = Util.diff(mod1, mod2); 706 for (Iterator <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 i.remove(); 713 } 714 } 715 } 716 merge(mod1, diffs); 717 String text1 = doc1.getText(0, doc1.getLength()); 718 String text2 = doc2.getText(0, doc2.getLength()); 719 } 722 723 public void testForwardReorderNodeWithChangesOnChildren() throws Exception { 724 javax.swing.text.Document doc1 = Util.getResourceAsDocument("diff/posChange4.xml"); 725 XDMModel mod1 = Util.loadXDMModel(doc1); 726 javax.swing.text.Document doc2 = Util.getResourceAsDocument("diff/posChange4_WithChildrenChanges.xml"); 727 XDMModel mod2 = Util.loadXDMModel(doc2); 728 List <Difference> diffs = Util.diff(mod1, mod2); 729 730 merge(mod1, diffs); 731 String text1 = doc1.getText(0, doc1.getLength()); 732 String text2 = doc2.getText(0, doc2.getLength()); 733 assertEquals(text2, text1); 734 } 735 736 public void testMergeReformatDiff() throws Exception { 737 javax.swing.text.Document doc1 = Util.getResourceAsDocument("diff/newWSDL1.wsdl"); 738 XDMModel mod1 = Util.loadXDMModel(doc1); 739 javax.swing.text.Document doc2 = Util.getResourceAsDocument("diff/newWSDL1_reformat.wsdl"); 740 XDMModel mod2 = Util.loadXDMModel(doc2); 741 List <Difference> diffs = Util.diff(mod1, mod2); 742 merge(mod1, diffs); 743 String text1 = doc1.getText(0, doc1.getLength()); 744 String text2 = doc2.getText(0, doc2.getLength()); 745 assertEquals(text2, text1); 746 } 747 748 DefaultElementIdentity eID = createEid(); 749 } 750 | Popular Tags |