1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 |
|
---|
8 | import org.junit.Assert;
|
---|
9 | import org.junit.Rule;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
12 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
13 |
|
---|
14 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
15 |
|
---|
16 | public class RelationTest {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Setup test.
|
---|
20 | */
|
---|
21 | @Rule
|
---|
22 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
23 | public JOSMTestRules test = new JOSMTestRules();
|
---|
24 |
|
---|
25 | @Test(expected = NullPointerException.class)
|
---|
26 | public void testCreateNewRelation() {
|
---|
27 | new Relation(null);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Test
|
---|
31 | public void testEqualSemanticsToNull() {
|
---|
32 | Relation relation = new Relation();
|
---|
33 | assertFalse(relation.hasEqualTechnicalAttributes(null));
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Test
|
---|
37 | public void testBbox() {
|
---|
38 | DataSet ds = new DataSet();
|
---|
39 |
|
---|
40 | Node n1 = new Node(new LatLon(10, 10));
|
---|
41 | Node n2 = new Node(new LatLon(20, 20));
|
---|
42 | Node n3 = new Node(new LatLon(30, 30));
|
---|
43 | Way w1 = new Way();
|
---|
44 | w1.addNode(n1);
|
---|
45 | w1.addNode(n2);
|
---|
46 | Relation r1 = new Relation();
|
---|
47 | Relation r2 = new Relation();
|
---|
48 | ds.addPrimitive(r1);
|
---|
49 | ds.addPrimitive(r2);
|
---|
50 | ds.addPrimitive(n1);
|
---|
51 | ds.addPrimitive(n2);
|
---|
52 | ds.addPrimitive(n3);
|
---|
53 | ds.addPrimitive(w1);
|
---|
54 | r1.addMember(new RelationMember("", n1));
|
---|
55 | r1.addMember(new RelationMember("", w1));
|
---|
56 | r1.addMember(new RelationMember("", r1));
|
---|
57 | r1.addMember(new RelationMember("", r2));
|
---|
58 | r2.addMember(new RelationMember("", r1));
|
---|
59 | r2.addMember(new RelationMember("", n3));
|
---|
60 |
|
---|
61 | BBox bbox = new BBox(w1);
|
---|
62 | bbox.add(n3.getBBox());
|
---|
63 | Assert.assertEquals(bbox, r1.getBBox());
|
---|
64 | Assert.assertEquals(bbox, r2.getBBox());
|
---|
65 |
|
---|
66 | n3.setCoor(new LatLon(40, 40));
|
---|
67 | bbox.add(n3.getBBox());
|
---|
68 | Assert.assertEquals(bbox, r1.getBBox());
|
---|
69 | Assert.assertEquals(bbox, r2.getBBox());
|
---|
70 |
|
---|
71 | r1.removeMembersFor(r2);
|
---|
72 | Assert.assertEquals(w1.getBBox(), r1.getBBox());
|
---|
73 | Assert.assertEquals(bbox, r2.getBBox());
|
---|
74 |
|
---|
75 | w1.addNode(n3);
|
---|
76 | Assert.assertEquals(w1.getBBox(), r1.getBBox());
|
---|
77 | Assert.assertEquals(w1.getBBox(), r2.getBBox());
|
---|
78 |
|
---|
79 | // create incomplete node and add it to the relation, this must not change the bbox
|
---|
80 | BBox oldBBox = r2.getBBox();
|
---|
81 | Node n4 = new Node();
|
---|
82 | n4.setIncomplete(true);
|
---|
83 | ds.addPrimitive(n4);
|
---|
84 | r2.addMember(new RelationMember("", n4));
|
---|
85 |
|
---|
86 | Assert.assertEquals(oldBBox, r2.getBBox());
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Test
|
---|
90 | public void testBBoxNotInDataset() {
|
---|
91 | Node n1 = new Node(new LatLon(10, 10));
|
---|
92 | Node n2 = new Node(new LatLon(20, 20));
|
---|
93 | Way w1 = new Way();
|
---|
94 | w1.addNode(n1);
|
---|
95 | w1.addNode(n2);
|
---|
96 | Relation r1 = new Relation();
|
---|
97 | r1.getBBox();
|
---|
98 | r1.addMember(new RelationMember("", w1));
|
---|
99 |
|
---|
100 | Assert.assertEquals(new BBox(w1), r1.getBBox());
|
---|
101 |
|
---|
102 | DataSet ds = new DataSet();
|
---|
103 | ds.addPrimitive(n1);
|
---|
104 | ds.addPrimitive(n2);
|
---|
105 | ds.addPrimitive(w1);
|
---|
106 | ds.addPrimitive(r1);
|
---|
107 |
|
---|
108 | Assert.assertEquals(new BBox(w1), r1.getBBox());
|
---|
109 |
|
---|
110 | ds.removePrimitive(r1);
|
---|
111 |
|
---|
112 | n1.setCoor(new LatLon(30, 40));
|
---|
113 | Assert.assertEquals(new BBox(w1), r1.getBBox());
|
---|
114 |
|
---|
115 | ds.addPrimitive(r1);
|
---|
116 | Assert.assertEquals(new BBox(w1), r1.getBBox());
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/12467">Bug #12467</a>.
|
---|
121 | * @throws Exception if any error occurs
|
---|
122 | */
|
---|
123 | @Test
|
---|
124 | public void testTicket12467() throws Exception {
|
---|
125 | Relation r = new Relation();
|
---|
126 | r.put("type", "boundary");
|
---|
127 | assertTrue(r.isBoundary());
|
---|
128 | assertTrue(r.isMultipolygon());
|
---|
129 | assertEquals(OsmPrimitiveType.RELATION, r.getDisplayType());
|
---|
130 |
|
---|
131 | r.put("type", "multipolygon");
|
---|
132 | assertFalse(r.isBoundary());
|
---|
133 | assertTrue(r.isMultipolygon());
|
---|
134 | assertEquals(OsmPrimitiveType.MULTIPOLYGON, r.getDisplayType());
|
---|
135 |
|
---|
136 | r.put("type", "something_else");
|
---|
137 | assertFalse(r.isBoundary());
|
---|
138 | assertFalse(r.isMultipolygon());
|
---|
139 | assertEquals(OsmPrimitiveType.RELATION, r.getDisplayType());
|
---|
140 | }
|
---|
141 | }
|
---|