1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
7 |
|
---|
8 | import java.util.ArrayList;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
12 | import org.junit.jupiter.api.Test;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmUtils;
|
---|
17 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
18 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
19 | import org.openstreetmap.josm.data.osm.Way;
|
---|
20 | import org.openstreetmap.josm.gui.mappaint.ElemStyles;
|
---|
21 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
22 |
|
---|
23 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * JUnit Test of unclosed ways validation test.
|
---|
27 | */
|
---|
28 | class UnclosedWaysTest {
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Setup test.
|
---|
32 | */
|
---|
33 | @RegisterExtension
|
---|
34 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
35 | public JOSMTestRules test = new JOSMTestRules().projection().mapStyles().presets();
|
---|
36 |
|
---|
37 | private static Way createUnclosedWay(String tags, DataSet ds) {
|
---|
38 | List<Node> nodes = new ArrayList<>();
|
---|
39 | nodes.add(new Node(new LatLon(0, 1)));
|
---|
40 | nodes.add(new Node(new LatLon(0, 2)));
|
---|
41 |
|
---|
42 | Way w = (Way) OsmUtils.createPrimitive("way "+tags);
|
---|
43 | nodes.forEach(ds::addPrimitive);
|
---|
44 | w.setNodes(nodes);
|
---|
45 | ds.addPrimitive(w);
|
---|
46 | return w;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Non-regression test for bug #10469. Was in {@code MultipolygonTestTest}
|
---|
51 | * @throws Exception if an exception occurs
|
---|
52 | */
|
---|
53 | @Test
|
---|
54 | void testTicket10469() throws Exception {
|
---|
55 | UnclosedWays uwTest = new UnclosedWays();
|
---|
56 | uwTest.initialize();
|
---|
57 | uwTest.startTest(null);
|
---|
58 | DataSet ds = new DataSet();
|
---|
59 |
|
---|
60 | // Erroneous tag
|
---|
61 | Way w = createUnclosedWay("amenity=parking", ds);
|
---|
62 | uwTest.visit(w);
|
---|
63 | assertTrue(ElemStyles.hasAreaElemStyle(w, false));
|
---|
64 | assertEquals(1, uwTest.getErrors().size());
|
---|
65 |
|
---|
66 | w = createUnclosedWay("building=yes", ds);
|
---|
67 | uwTest.visit(w);
|
---|
68 | assertTrue(ElemStyles.hasAreaElemStyle(w, false));
|
---|
69 | assertEquals(2, uwTest.getErrors().size());
|
---|
70 |
|
---|
71 | // Correct tag, without area style since #10601 (r7603)
|
---|
72 | w = createUnclosedWay("aeroway=taxiway", ds);
|
---|
73 | uwTest.visit(w);
|
---|
74 | assertFalse(ElemStyles.hasAreaElemStyle(w, false));
|
---|
75 | assertEquals(2, uwTest.getErrors().size());
|
---|
76 |
|
---|
77 | uwTest.endTest();
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Test to make sure the multipolygon ways are not ignored
|
---|
82 | * See #19136, #19145
|
---|
83 | * @throws Exception if an exception occurs
|
---|
84 | */
|
---|
85 | @Test
|
---|
86 | void testWayInMultiPolygon() throws Exception {
|
---|
87 | UnclosedWays uwTest = new UnclosedWays();
|
---|
88 | uwTest.initialize();
|
---|
89 | uwTest.startTest(null);
|
---|
90 | DataSet ds = new DataSet();
|
---|
91 |
|
---|
92 | // Erroneous tag
|
---|
93 | Way w = createUnclosedWay("natural=water", ds);
|
---|
94 | Relation r = (Relation) OsmUtils.createPrimitive("relation type=multipolygon natural=wood");
|
---|
95 | r.addMember(new RelationMember("inner", w));
|
---|
96 | ds.addPrimitive(r);
|
---|
97 | uwTest.visit(w);
|
---|
98 | assertTrue(ElemStyles.hasAreaElemStyle(w, false));
|
---|
99 | assertEquals(1, uwTest.getErrors().size());
|
---|
100 |
|
---|
101 | uwTest.endTest();
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Test to make sure the boundary ways are ignored when member of a boundary relation
|
---|
106 | * See #19136, #19145
|
---|
107 | * @throws Exception if an exception occurs
|
---|
108 | */
|
---|
109 | @Test
|
---|
110 | void testWayInBoundary() throws Exception {
|
---|
111 | UnclosedWays uwTest = new UnclosedWays();
|
---|
112 | uwTest.initialize();
|
---|
113 | uwTest.startTest(null);
|
---|
114 | DataSet ds = new DataSet();
|
---|
115 |
|
---|
116 | // Erroneous tag
|
---|
117 | Way w = createUnclosedWay("boundary=administrative", ds);
|
---|
118 | Relation r = (Relation) OsmUtils.createPrimitive("relation type=boundary");
|
---|
119 | r.addMember(new RelationMember("inner", w));
|
---|
120 | ds.addPrimitive(r);
|
---|
121 | uwTest.visit(w);
|
---|
122 | assertFalse(ElemStyles.hasAreaElemStyle(w, false));
|
---|
123 | assertEquals(0, uwTest.getErrors().size());
|
---|
124 |
|
---|
125 | uwTest.endTest();
|
---|
126 | }
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Test to make sure that amenity=* is closed.
|
---|
130 | * See #19145
|
---|
131 | * @throws Exception if an exception occurs
|
---|
132 | */
|
---|
133 | @Test
|
---|
134 | void testAmenity() throws Exception {
|
---|
135 | UnclosedWays uwTest = new UnclosedWays();
|
---|
136 | uwTest.initialize();
|
---|
137 | uwTest.startTest(null);
|
---|
138 | DataSet ds = new DataSet();
|
---|
139 |
|
---|
140 | // Erroneous tag
|
---|
141 | Way w = createUnclosedWay("amenity=school", ds);
|
---|
142 | uwTest.visit(w);
|
---|
143 | assertTrue(ElemStyles.hasAreaElemStyle(w, false));
|
---|
144 | assertEquals(1, uwTest.getErrors().size());
|
---|
145 | assertEquals(1103, uwTest.getErrors().iterator().next().getCode());
|
---|
146 |
|
---|
147 | uwTest.endTest();
|
---|
148 | }
|
---|
149 |
|
---|
150 | }
|
---|