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 |
|
---|
6 | import org.junit.Rule;
|
---|
7 | import org.junit.Test;
|
---|
8 | import org.openstreetmap.josm.TestUtils;
|
---|
9 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
10 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
11 | import org.openstreetmap.josm.data.osm.Node;
|
---|
12 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
13 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
14 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
15 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
16 |
|
---|
17 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * JUnit Test of "Duplicate relation" validation test.
|
---|
21 | */
|
---|
22 | public class DuplicateRelationTest {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Setup test by initializing JOSM preferences and projection.
|
---|
26 | */
|
---|
27 | @Rule
|
---|
28 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
29 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
30 |
|
---|
31 | static class ExpectedResult {
|
---|
32 | final int code;
|
---|
33 | final boolean fixable;
|
---|
34 | ExpectedResult(int code, boolean fixable) {
|
---|
35 | this.code = code;
|
---|
36 | this.fixable = fixable;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | private void doTest(String tags1, String tags2, ExpectedResult... expectations) {
|
---|
41 | performTest(buildDataSet(tags1, tags2), expectations);
|
---|
42 | }
|
---|
43 |
|
---|
44 | private void performTest(DataSet ds, ExpectedResult... expectations) {
|
---|
45 | final DuplicateRelation TEST = new DuplicateRelation();
|
---|
46 | TEST.startTest(NullProgressMonitor.INSTANCE);
|
---|
47 | TEST.visit(ds.allPrimitives());
|
---|
48 | TEST.endTest();
|
---|
49 |
|
---|
50 | assertEquals(expectations.length, TEST.getErrors().size());
|
---|
51 | int i = 0;
|
---|
52 | for (TestError error : TEST.getErrors()) {
|
---|
53 | ExpectedResult expected = expectations[i++];
|
---|
54 | assertEquals(expected.code, error.getCode());
|
---|
55 | assertEquals(expected.fixable, error.isFixable());
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | private static DataSet buildDataSet(String tags1, String tags2) {
|
---|
60 | DataSet ds = new DataSet();
|
---|
61 |
|
---|
62 | Node a = new Node(new LatLon(10.0, 5.0));
|
---|
63 | ds.addPrimitive(a);
|
---|
64 | ds.addPrimitive(TestUtils.newRelation(tags1, new RelationMember(null, a)));
|
---|
65 | ds.addPrimitive(TestUtils.newRelation(tags2, new RelationMember(null, a)));
|
---|
66 | return ds;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Test of "Duplicate relation" validation test - no tags.
|
---|
71 | */
|
---|
72 | @Test
|
---|
73 | public void testDuplicateRelationNoTags() {
|
---|
74 | doTest("", "",
|
---|
75 | new ExpectedResult(DuplicateRelation.DUPLICATE_RELATION, true),
|
---|
76 | new ExpectedResult(DuplicateRelation.SAME_RELATION, false));
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Test of "Duplicate relation" validation test - same tags.
|
---|
81 | */
|
---|
82 | @Test
|
---|
83 | public void testDuplicateRelationSameTags() {
|
---|
84 | doTest("type=boundary", "type=boundary",
|
---|
85 | new ExpectedResult(DuplicateRelation.DUPLICATE_RELATION, true),
|
---|
86 | new ExpectedResult(DuplicateRelation.SAME_RELATION, false));
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Test of "Duplicate relation" validation test - different tags.
|
---|
91 | */
|
---|
92 | @Test
|
---|
93 | public void testDuplicateRelationDifferentTags() {
|
---|
94 | doTest("type=boundary", "type=multipolygon",
|
---|
95 | new ExpectedResult(DuplicateRelation.SAME_RELATION, false));
|
---|
96 | }
|
---|
97 | }
|
---|