1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data;
|
---|
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.Arrays;
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.Locale;
|
---|
11 | import java.util.stream.Collectors;
|
---|
12 |
|
---|
13 | import org.junit.jupiter.api.Test;
|
---|
14 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
15 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
17 | import org.openstreetmap.josm.data.osm.search.SearchCompiler;
|
---|
18 | import org.openstreetmap.josm.io.OsmReader;
|
---|
19 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
20 |
|
---|
21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Test of boundaries OSM file.
|
---|
25 | */
|
---|
26 | class BoundariesTestIT {
|
---|
27 |
|
---|
28 | private static final List<String> RETIRED_ISO3166_1_CODES = Arrays.asList(
|
---|
29 | "AN", "BU", "CS", "NT", "TP", "YU", "ZR");
|
---|
30 |
|
---|
31 | private static final List<String> EXCEPTIONNALY_RESERVED_ISO3166_1_CODES = Arrays.asList(
|
---|
32 | "AC", "CP", "DG", "EA", "EU", "EZ", "FX", "IC", "SU", "TA", "UK", "UN");
|
---|
33 |
|
---|
34 | private static final List<String> ISO3166_2_CODES = Arrays.asList(
|
---|
35 | "AU-ACT", "AU-NSW", "AU-NT", "AU-QLD", "AU-SA", "AU-TAS", "AU-VIC", "AU-WA",
|
---|
36 | "CA-AB", "CA-BC", "CA-MB", "CA-NB", "CA-NL", "CA-NS", "CA-NT", "CA-NU", "CA-ON", "CA-PE", "CA-QC", "CA-SK", "CA-YT",
|
---|
37 | "CN-AH", "CN-BJ", "CN-CQ", "CN-FJ", "CN-GD", "CN-GS", "CN-GX", "CN-GZ", "CN-HA", "CN-HB", "CN-HE", "CN-HI", "CN-HK", "CN-HL",
|
---|
38 | "CN-HN", "CN-JL", "CN-JS", "CN-JX", "CN-LN", "CN-MO", "CN-NM", "CN-NX", "CN-QH", "CN-SC", "CN-SD", "CN-SH", "CN-SN", "CN-SX",
|
---|
39 | "CN-TJ", "CN-TW", "CN-XJ", "CN-XZ", "CN-YN", "CN-ZJ",
|
---|
40 | "IN-AP", "IN-AR", "IN-AS", "IN-BR", "IN-CT", "IN-GA", "IN-GJ", "IN-HR", "IN-HP", "IN-JK", "IN-JH", "IN-KA", "IN-KL", "IN-MP",
|
---|
41 | "IN-MH", "IN-MN", "IN-ML", "IN-MZ", "IN-NL", "IN-OR", "IN-PB", "IN-RJ", "IN-SK", "IN-TN", "IN-TG", "IN-TR", "IN-UT", "IN-UP",
|
---|
42 | "IN-WB", "IN-AN", "IN-CH", "IN-DN", "IN-DD", "IN-DL", "IN-LD", "IN-PY",
|
---|
43 | "US-AL", "US-AK", "US-AS", "US-AZ", "US-AR", "US-CA", "US-CO", "US-CT", "US-DE", "US-DC", "US-FL", "US-GA", "US-GU", "US-HI",
|
---|
44 | "US-ID", "US-IL", "US-IN", "US-IA", "US-KS", "US-KY", "US-LA", "US-ME", "US-MD", "US-MA", "US-MI", "US-MN", "US-MS", "US-MO",
|
---|
45 | "US-MT", "US-NE", "US-NV", "US-NH", "US-NJ", "US-NM", "US-NY", "US-NC", "US-ND", "US-MP", "US-OH", "US-OK", "US-OR", "US-PA",
|
---|
46 | "US-PR", "US-RI", "US-SC", "US-SD", "US-TN", "US-TX", "US-UM", "US-UT", "US-VT", "US-VA", "US-VI", "US-WA", "US-WV", "US-WI",
|
---|
47 | "US-WY");
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Setup test.
|
---|
51 | */
|
---|
52 | @RegisterExtension
|
---|
53 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
54 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Test of boundaries OSM file.
|
---|
58 | * @throws Exception if an error occurs
|
---|
59 | */
|
---|
60 | @Test
|
---|
61 | void testBoundariesFile() throws Exception {
|
---|
62 | try (InputStream is = getClass().getResourceAsStream("/data/boundaries.osm")) {
|
---|
63 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
64 | List<OsmPrimitive> tagged = ds.allPrimitives().stream().filter(OsmPrimitive::isTagged).collect(Collectors.toList());
|
---|
65 | List<String> iso31661a2 = Arrays.asList(Locale.getISOCountries());
|
---|
66 | // Check presence of all ISO-3166-1 alpha 2 codes
|
---|
67 | for (String code : iso31661a2) {
|
---|
68 | if (!RETIRED_ISO3166_1_CODES.contains(code)) {
|
---|
69 | assertEquals(1, tagged.stream().filter(SearchCompiler.compile("ISO3166-1\\:alpha2="+code)).count(), code);
|
---|
70 | }
|
---|
71 | }
|
---|
72 | // Check for unknown ISO-3166-1 alpha 2 codes
|
---|
73 | for (OsmPrimitive p : tagged.stream().filter(SearchCompiler.compile("ISO3166-1\\:alpha2")).collect(Collectors.toList())) {
|
---|
74 | String code = p.get("ISO3166-1:alpha2");
|
---|
75 | assertTrue(iso31661a2.contains(code) || EXCEPTIONNALY_RESERVED_ISO3166_1_CODES.contains(code), code);
|
---|
76 | }
|
---|
77 | // Check presence of all ISO-3166-2 codes for USA, Canada, Australia (for speed limits)
|
---|
78 | for (String code : ISO3166_2_CODES) {
|
---|
79 | assertEquals(1, tagged.stream().filter(SearchCompiler.compile("ISO3166-2="+code)).count(), code);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|