}
@Test
public void testOneRelationExistingMembersSelected() {
DataSet source = new DataSet();
Relation r1 = new Relation(1, 1);
Node n20 = new Node(20, 1);
n20.setCoor(new LatLon(0, 0));
r1.addMember(new RelationMember("node-20",n20));
Way w30 = new Way(30, 1);
Node n21 = new Node(21);
w30.addNode(n21);
Node n22 = new Node(22);
w30.addNode(n22);
r1.addMember(new RelationMember("way-30",w30));
Relation r40 = new Relation(40);
r1.addMember(new RelationMember("relation-40", r40));
source.addPrimitive(n20);
source.addPrimitive(n21);
source.addPrimitive(n22);
source.addPrimitive(w30);
source.addPrimitive(r40);
source.addPrimitive(r1);
source.setSelected(r1,n20,w30,r40);
MergeSourceBuildingVisitor builder = new MergeSourceBuildingVisitor(source);
DataSet hull = builder.build();
assertNotNull(hull);
assertEquals(1, hull.getWays().size());
assertEquals(3, hull.getNodes().size());
assertEquals(2, hull.getRelations().size());
OsmPrimitive p = hull.getPrimitiveById(1, OsmPrimitiveType.RELATION);
assertNotNull(p);
assertEquals(p.getClass(), Relation.class);
Way w = (Way)hull.getPrimitiveById(30,OsmPrimitiveType.WAY);
assertNotNull(w);
assertEquals(2, w.getNodesCount());
Node n = (Node)hull.getPrimitiveById(21, OsmPrimitiveType.NODE);
assertNotNull(n);
assertTrue(w.containsNode(n));
n = (Node)hull.getPrimitiveById(22,OsmPrimitiveType.NODE);
assertNotNull(n);
assertTrue(w.containsNode(n));
Relation r = (Relation)hull.getPrimitiveById(40,OsmPrimitiveType.RELATION);
assertNotNull(r);
r = (Relation)hull.getPrimitiveById(1, OsmPrimitiveType.RELATION);
assertNotNull(r);
assertEquals(3, r.getMembersCount());
RelationMember m = new RelationMember("node-20", hull.getPrimitiveById(20,OsmPrimitiveType.NODE));
assertTrue(r.getMembers().contains(m));
m = new RelationMember("way-30", hull.getPrimitiveById(30, OsmPrimitiveType.WAY));
assertTrue(r.getMembers().contains(m));
m = new RelationMember("relation-40", hull.getPrimitiveById(40, OsmPrimitiveType.RELATION));
assertTrue(r.getMembers().contains(m));
}