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.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.InputStream;
|
---|
8 | import java.util.stream.Collectors;
|
---|
9 |
|
---|
10 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
11 | import org.junit.jupiter.api.Test;
|
---|
12 | import org.openstreetmap.josm.TestUtils;
|
---|
13 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
14 | import org.openstreetmap.josm.io.OsmReader;
|
---|
15 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
16 |
|
---|
17 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * JUnit Test of Multipolygon validation test.
|
---|
21 | */
|
---|
22 | class MultipolygonTestTest {
|
---|
23 |
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup test.
|
---|
27 | */
|
---|
28 | @RegisterExtension
|
---|
29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
30 | public JOSMTestRules test = new JOSMTestRules().projection().mapStyles().presets().main().preferences();
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Test all error cases manually created in multipolygon.osm.
|
---|
34 | * @throws Exception in case of error
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | void testMultipolygonFile() throws Exception {
|
---|
38 | final MultipolygonTest MULTIPOLYGON_TEST = new MultipolygonTest();
|
---|
39 | final RelationChecker RELATION_TEST = new RelationChecker();
|
---|
40 | ValidatorTestUtils.testSampleFile("nodist/data/multipolygon.osm",
|
---|
41 | ds -> ds.getRelations().stream().filter(Relation::isMultipolygon).collect(Collectors.toList()),
|
---|
42 | name -> name.startsWith("06") || name.startsWith("07") || name.startsWith("08"), MULTIPOLYGON_TEST, RELATION_TEST);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Non-regression test for ticket #17768.
|
---|
47 | * @throws Exception if an error occurs
|
---|
48 | */
|
---|
49 | @Test
|
---|
50 | void testTicket17768TouchingInner() throws Exception {
|
---|
51 | try (InputStream is = TestUtils.getRegressionDataStream(17768, "touching-inner.osm")) {
|
---|
52 | MultipolygonTest mpTest = new MultipolygonTest();
|
---|
53 | mpTest.makeFromWays(OsmReader.parseDataSet(is, null).getWays());
|
---|
54 | // inner touches inner, is considered OK in OSM
|
---|
55 | assertTrue(mpTest.getErrors().isEmpty());
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Non-regression test for ticket #17768.
|
---|
61 | * @throws Exception if an error occurs
|
---|
62 | */
|
---|
63 | @Test
|
---|
64 | void testTicket17768TouchingInnerOuter() throws Exception {
|
---|
65 | try (InputStream is = TestUtils.getRegressionDataStream(17768, "touching-inner-outer.osm")) {
|
---|
66 | MultipolygonTest mpTest = new MultipolygonTest();
|
---|
67 | mpTest.makeFromWays(OsmReader.parseDataSet(is, null).getWays());
|
---|
68 | // inner touches outer, should return error
|
---|
69 | assertEquals(1, mpTest.getErrors().size());
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|