1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
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 java.util.ArrayList;
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.stream.Collectors;
|
---|
11 |
|
---|
12 | import org.junit.Rule;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
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.Way;
|
---|
19 | import org.openstreetmap.josm.gui.mappaint.ElemStyles;
|
---|
20 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
21 |
|
---|
22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * JUnit Test of Multipolygon validation test.
|
---|
26 | */
|
---|
27 | public class MultipolygonTestTest {
|
---|
28 |
|
---|
29 | private static final MultipolygonTest MULTIPOLYGON_TEST = new MultipolygonTest();
|
---|
30 | private static final RelationChecker RELATION_TEST = new RelationChecker();
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Setup test.
|
---|
34 | */
|
---|
35 | @Rule
|
---|
36 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
37 | public JOSMTestRules test = new JOSMTestRules().commands();
|
---|
38 |
|
---|
39 | private static Way createUnclosedWay(String tags) {
|
---|
40 | List<Node> nodes = new ArrayList<>();
|
---|
41 | nodes.add(new Node(new LatLon(0, 1)));
|
---|
42 | nodes.add(new Node(new LatLon(0, 2)));
|
---|
43 |
|
---|
44 | Way w = (Way) OsmUtils.createPrimitive("way "+tags);
|
---|
45 | w.setNodes(nodes);
|
---|
46 | return w;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Non-regression test for bug #10469.
|
---|
51 | */
|
---|
52 | @Test
|
---|
53 | public void testTicket10469() {
|
---|
54 | MULTIPOLYGON_TEST.initialize();
|
---|
55 | MULTIPOLYGON_TEST.startTest(null);
|
---|
56 |
|
---|
57 | // Erroneous tag
|
---|
58 | Way w = createUnclosedWay("amenity=parking");
|
---|
59 | MULTIPOLYGON_TEST.visit(w);
|
---|
60 | assertTrue(ElemStyles.hasAreaElemStyle(w, false));
|
---|
61 | assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
|
---|
62 |
|
---|
63 | // Erroneous tag, but managed by another test
|
---|
64 | w = createUnclosedWay("building=yes");
|
---|
65 | MULTIPOLYGON_TEST.visit(w);
|
---|
66 | assertTrue(ElemStyles.hasAreaElemStyle(w, false));
|
---|
67 | assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
|
---|
68 |
|
---|
69 | // Correct tag, without area style since #10601 (r7603)
|
---|
70 | w = createUnclosedWay("aeroway=taxiway");
|
---|
71 | MULTIPOLYGON_TEST.visit(w);
|
---|
72 | assertFalse(ElemStyles.hasAreaElemStyle(w, false));
|
---|
73 | assertEquals(1, MULTIPOLYGON_TEST.getErrors().size());
|
---|
74 |
|
---|
75 | MULTIPOLYGON_TEST.endTest();
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Test all error cases manually created in multipolygon.osm.
|
---|
80 | * @throws Exception in case of error
|
---|
81 | */
|
---|
82 | @Test
|
---|
83 | public void testMultipolygonFile() throws Exception {
|
---|
84 | ValidatorTestUtils.testSampleFile("data_nodist/multipolygon.osm",
|
---|
85 | ds -> ds.getRelations().stream().filter(Relation::isMultipolygon).collect(Collectors.toList()),
|
---|
86 | name -> name.startsWith("06") || name.startsWith("07"), MULTIPOLYGON_TEST, RELATION_TEST);
|
---|
87 | }
|
---|
88 | }
|
---|