1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import org.junit.Assert;
|
---|
5 | import org.junit.jupiter.api.BeforeEach;
|
---|
6 | import org.junit.jupiter.api.Test;
|
---|
7 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
8 | import org.openstreetmap.josm.TestUtils;
|
---|
9 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
10 | import org.openstreetmap.josm.data.osm.Node;
|
---|
11 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
12 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
13 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
14 |
|
---|
15 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Test the ConnectivityRelations validation test
|
---|
19 | *
|
---|
20 | * @author Taylor Smock
|
---|
21 | */
|
---|
22 | class ConnectivityRelationsTest {
|
---|
23 | private ConnectivityRelations check;
|
---|
24 | private static final String CONNECTIVITY = "connectivity";
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup test.
|
---|
28 | */
|
---|
29 | @RegisterExtension
|
---|
30 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
31 | public JOSMTestRules rule = new JOSMTestRules();
|
---|
32 |
|
---|
33 | @BeforeEach
|
---|
34 | public void setUpCheck() throws Exception {
|
---|
35 | check = new ConnectivityRelations();
|
---|
36 | }
|
---|
37 |
|
---|
38 | private Relation createDefaultTestRelation() {
|
---|
39 | Node connection = new Node(new LatLon(0, 0));
|
---|
40 | return TestUtils.newRelation("type=connectivity connectivity=1:1",
|
---|
41 | new RelationMember("from", TestUtils.newWay("lanes=4", new Node(new LatLon(-0.1, -0.1)), connection)),
|
---|
42 | new RelationMember("via", connection),
|
---|
43 | new RelationMember("to", TestUtils.newWay("lanes=4", connection, new Node(new LatLon(0.1, 0.1)))));
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Test for connectivity relations without a connectivity tag
|
---|
48 | */
|
---|
49 | @Test
|
---|
50 | void testNoConnectivityTag() {
|
---|
51 | Relation relation = createDefaultTestRelation();
|
---|
52 | check.visit(relation);
|
---|
53 |
|
---|
54 | Assert.assertEquals(0, check.getErrors().size());
|
---|
55 |
|
---|
56 | relation.remove(CONNECTIVITY);
|
---|
57 | check.visit(relation);
|
---|
58 | Assert.assertEquals(1, check.getErrors().size());
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Check for lanes that don't make sense
|
---|
63 | */
|
---|
64 | @Test
|
---|
65 | void testMisMatchedLanes() {
|
---|
66 | Relation relation = createDefaultTestRelation();
|
---|
67 | check.visit(relation);
|
---|
68 | int expectedFailures = 0;
|
---|
69 |
|
---|
70 | Assert.assertEquals(expectedFailures, check.getErrors().size());
|
---|
71 |
|
---|
72 | relation.put(CONNECTIVITY, "45000:1");
|
---|
73 | check.visit(relation);
|
---|
74 | Assert.assertEquals(++expectedFailures, check.getErrors().size());
|
---|
75 |
|
---|
76 | relation.put(CONNECTIVITY, "1:45000");
|
---|
77 | check.visit(relation);
|
---|
78 | Assert.assertEquals(++expectedFailures, check.getErrors().size());
|
---|
79 |
|
---|
80 | relation.put(CONNECTIVITY, "1:1,2");
|
---|
81 | check.visit(relation);
|
---|
82 | Assert.assertEquals(expectedFailures, check.getErrors().size());
|
---|
83 |
|
---|
84 | relation.put(CONNECTIVITY, "1:1,(2)");
|
---|
85 | check.visit(relation);
|
---|
86 | Assert.assertEquals(expectedFailures, check.getErrors().size());
|
---|
87 |
|
---|
88 | relation.put(CONNECTIVITY, "1:1,(20000)");
|
---|
89 | check.visit(relation);
|
---|
90 | Assert.assertEquals(++expectedFailures, check.getErrors().size());
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/201821">Bug #20182</a>.
|
---|
95 | * @throws Exception if an error occurs
|
---|
96 | */
|
---|
97 | @Test
|
---|
98 | void testTicket20182() throws Exception {
|
---|
99 | Relation relation = createDefaultTestRelation();
|
---|
100 | check.visit(relation);
|
---|
101 | int expectedFailures = 0;
|
---|
102 |
|
---|
103 | Assert.assertEquals(expectedFailures, check.getErrors().size());
|
---|
104 |
|
---|
105 | relation.put(CONNECTIVITY, "left_turn");
|
---|
106 | check.visit(relation);
|
---|
107 | Assert.assertEquals(++expectedFailures, check.getErrors().size());
|
---|
108 |
|
---|
109 | relation.put(CONNECTIVITY, "1");
|
---|
110 | check.visit(relation);
|
---|
111 | Assert.assertEquals(++expectedFailures, check.getErrors().size());
|
---|
112 | }
|
---|
113 | }
|
---|