Changeset 2443 in josm for trunk/test/unit
- Timestamp:
- 2009-11-13T10:24:58+01:00 (15 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java
r2435 r2443 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.osm .visitor;2 package org.openstreetmap.josm.data.osm; 3 3 4 4 import static org.junit.Assert.assertEquals; … … 21 21 import org.openstreetmap.josm.Main; 22 22 import org.openstreetmap.josm.data.coor.LatLon; 23 import org.openstreetmap.josm.data.osm.DataSet;24 import org.openstreetmap.josm.data.osm.DataSetMerger;25 import org.openstreetmap.josm.data.osm.Node;26 import org.openstreetmap.josm.data.osm.OsmPrimitive;27 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;28 import org.openstreetmap.josm.data.osm.Relation;29 import org.openstreetmap.josm.data.osm.RelationMember;30 import org.openstreetmap.josm.data.osm.User;31 import org.openstreetmap.josm.data.osm.Way;32 23 import org.openstreetmap.josm.data.projection.Mercator; 33 24 34 public class MergeVisitorTest {35 private static Logger logger = Logger.getLogger( MergeVisitorTest.class.getName());25 public class DataSetMergerTest { 26 private static Logger logger = Logger.getLogger(DataSetMergerTest.class.getName()); 36 27 37 28 static Properties testProperties; … … 46 37 // 47 38 try { 48 testProperties.load( MergeVisitorTest.class.getResourceAsStream("/test-unit-env.properties"));39 testProperties.load(DataSetMergerTest.class.getResourceAsStream("/test-unit-env.properties")); 49 40 } catch(Exception e){ 50 41 logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", "/test-unit-env.properties")); … … 106 97 assertEquals(false, n2.isModified()); 107 98 assertEquals("value1", n2.get("key1")); 99 100 // merge target not modified after merging 101 assertTrue(!n2.isModified()); 108 102 } 109 103 … … 145 139 assertEquals("value1-new", n2.get("key1")); 146 140 assertEquals("value2", n2.get("key2")); 141 142 // the merge target should not be modified 143 assertTrue(!n2.isModified()); 147 144 } 148 145 … … 479 476 public void waySimple_IdenicalNodesDifferentTags() { 480 477 481 482 DataSet my= new DataSet();483 my.setVersion("0.6");478 // -- the target dataset 479 DataSet target = new DataSet(); 480 target.setVersion("0.6"); 484 481 485 482 Node n1 = new Node(); 486 483 n1.setCoor(new LatLon(0,0)); 487 484 n1.setOsmId(1,1); 488 my.addPrimitive(n1); 489 485 target.addPrimitive(n1); 490 486 491 487 Node n2 = new Node(); … … 493 489 n2.setOsmId(2,1); 494 490 495 my.addPrimitive(n2);491 target.addPrimitive(n2); 496 492 497 493 Way myWay = new Way(); … … 500 496 myWay.addNode(n1); 501 497 myWay.addNode(n2); 502 my.addPrimitive(myWay); 503 504 DataSet their = new DataSet(); 505 their.setVersion("0.6"); 498 target.addPrimitive(myWay); 499 500 // -- the source data set 501 DataSet source = new DataSet(); 502 source.setVersion("0.6"); 506 503 507 504 Node n3 = new Node(new LatLon(0,0)); 508 505 n3.setOsmId(1,1); 509 their.addPrimitive(n3);506 source.addPrimitive(n3); 510 507 511 508 Node n4 = new Node(new LatLon(1,1)); 512 509 n4.setOsmId(2,1); 513 their.addPrimitive(n4);510 source.addPrimitive(n4); 514 511 515 512 Way theirWay = new Way(); … … 519 516 theirWay.addNode(n3); 520 517 theirWay.addNode(n4); 521 their.addPrimitive(theirWay); 522 523 524 DataSetMerger visitor = new DataSetMerger(my,their); 525 visitor.merge(); 526 527 Way merged = (Way)my.getPrimitiveById(3, OsmPrimitiveType.WAY); 518 source.addPrimitive(theirWay); 519 520 521 DataSetMerger visitor = new DataSetMerger(target,source); 522 visitor.merge(); 523 524 // -- tests 525 Way merged = (Way)target.getPrimitiveById(3, OsmPrimitiveType.WAY); 528 526 assertEquals(0,visitor.getConflicts().size()); 529 527 assertEquals("value1",merged.get("key1")); … … 535 533 assertEquals(2,merged.getNode(1).getId()); 536 534 assertTrue(merged == myWay); 537 assertTrue(merged.getDataSet() == my);538 539 Node mergedNode = (Node) my.getPrimitiveById(1, OsmPrimitiveType.NODE);535 assertTrue(merged.getDataSet() == target); 536 537 Node mergedNode = (Node)target.getPrimitiveById(1, OsmPrimitiveType.NODE); 540 538 assertTrue(mergedNode == n1); 541 mergedNode = (Node) my.getPrimitiveById(2, OsmPrimitiveType.NODE);539 mergedNode = (Node)target.getPrimitiveById(2, OsmPrimitiveType.NODE); 542 540 assertTrue(mergedNode == n2); 541 542 assertTrue(!merged.isModified()); 543 543 } 544 544 … … 572 572 573 573 // --- their data set 574 575 574 DataSet their = new DataSet(); 576 575 their.setVersion("0.6"); … … 601 600 visitor.merge(); 602 601 602 // -- tests 603 603 Way merged = (Way)my.getPrimitiveById(3, OsmPrimitiveType.WAY); 604 604 assertEquals(0,visitor.getConflicts().size()); … … 614 614 assertTrue(merged.getNode(1) != n5); // must be clone of the original node in their 615 615 assertTrue(merged.getNode(2) == n2); 616 617 assertTrue(!merged.isModified()); // the target wasn't modified before merging, it 618 // mustn't be after merging 616 619 } 617 620 … … 625 628 public void waySimple_DifferentNodesAndMyIsModified() { 626 629 627 DataSet my = new DataSet(); 628 my.setVersion("0.6"); 630 // -- the target dataset 631 DataSet target = new DataSet(); 632 target.setVersion("0.6"); 629 633 630 634 Node n1 = new Node(new LatLon(0,0)); 631 635 n1.setOsmId(1,1); 632 my.addPrimitive(n1);636 target.addPrimitive(n1); 633 637 634 638 Node n2 = new Node(new LatLon(1,1)); 635 639 n2.setOsmId(2,1); 636 my.addPrimitive(n2);640 target.addPrimitive(n2); 637 641 638 642 Way myWay = new Way(); … … 643 647 myWay.setModified(true); 644 648 myWay.put("key1", "value1"); 645 my.addPrimitive(myWay); 646 647 DataSet their = new DataSet(); 648 their.setVersion("0.6"); 649 target.addPrimitive(myWay); 650 651 // -- the source dataset 652 DataSet source = new DataSet(); 653 source.setVersion("0.6"); 649 654 650 655 Node n3 = new Node(new LatLon(0,0)); 651 656 n3.setOsmId(1,1); 652 their.addPrimitive(n3);657 source.addPrimitive(n3); 653 658 654 659 Node n5 = new Node(new LatLon(1,1)); 655 660 n5.setOsmId(4,1); 656 their.addPrimitive(n5);661 source.addPrimitive(n5); 657 662 658 663 Node n4 = new Node(new LatLon(2,2)); 659 664 n4.setOsmId(2,1); 660 665 n4.put("key1", "value1"); 661 their.addPrimitive(n4);666 source.addPrimitive(n4); 662 667 663 668 … … 668 673 theirWay.addNode(n5); // insert a node 669 674 theirWay.addNode(n4); // this one is updated 670 their.addPrimitive(theirWay);671 672 673 DataSetMerger visitor = new DataSetMerger( my,their);674 visitor.merge(); 675 676 Way merged = (Way) my.getPrimitiveById(3, OsmPrimitiveType.WAY);675 source.addPrimitive(theirWay); 676 677 678 DataSetMerger visitor = new DataSetMerger(target,source); 679 visitor.merge(); 680 681 Way merged = (Way)target.getPrimitiveById(3, OsmPrimitiveType.WAY); 677 682 assertEquals(1,visitor.getConflicts().size()); 678 683 assertEquals(3,merged.getId()); … … 786 791 assertTrue(merged.getNode(0) == n1); 787 792 assertTrue(merged.getNode(1) == n2); 793 794 assertTrue(!merged.isModified()); 788 795 } 789 796 … … 842 849 assertTrue(merged.getNode(0) == n1); 843 850 assertTrue(merged.getNode(1) == n2); 851 852 assertTrue(!merged.isModified()); 844 853 } 845 854 … … 901 910 assertTrue(!myWay.getNodes().contains(n)); 902 911 assertTrue(n != null); 912 913 //a node was removed from the way,it should thus be modified 914 assertTrue(myWay.isModified()); 903 915 } 904 916 … … 956 968 Node n = (Node)my.getPrimitiveById(1,OsmPrimitiveType.NODE); 957 969 assertTrue(n != null); 970 971 assertTrue(r.isModified()); 958 972 } 959 973
Note:
See TracChangeset
for help on using the changeset viewer.