1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.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.Rule;
|
---|
14 | import org.junit.Test;
|
---|
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 | public 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 | "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",
|
---|
38 | "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",
|
---|
39 | "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",
|
---|
40 | "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",
|
---|
41 | "US-WY");
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Setup test.
|
---|
45 | */
|
---|
46 | @Rule
|
---|
47 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
48 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Test of boundaries OSM file.
|
---|
52 | * @throws Exception if an error occurs
|
---|
53 | */
|
---|
54 | @Test
|
---|
55 | public void testBoundariesFile() throws Exception {
|
---|
56 | try (InputStream is = getClass().getResourceAsStream("/data/boundaries.osm")) {
|
---|
57 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
58 | List<OsmPrimitive> tagged = ds.allPrimitives().stream().filter(OsmPrimitive::isTagged).collect(Collectors.toList());
|
---|
59 | List<String> iso31661a2 = Arrays.asList(Locale.getISOCountries());
|
---|
60 | // Check presence of all ISO-3166-1 alpha 2 codes
|
---|
61 | for (String code : iso31661a2) {
|
---|
62 | if (!RETIRED_ISO3166_1_CODES.contains(code)) {
|
---|
63 | assertEquals(code, 1, tagged.stream().filter(SearchCompiler.compile("ISO3166-1\\:alpha2="+code)).count());
|
---|
64 | }
|
---|
65 | }
|
---|
66 | // Check for unknown ISO-3166-1 alpha 2 codes
|
---|
67 | for (OsmPrimitive p : tagged.stream().filter(SearchCompiler.compile("ISO3166-1\\:alpha2")).collect(Collectors.toList())) {
|
---|
68 | String code = p.get("ISO3166-1:alpha2");
|
---|
69 | assertTrue(code, iso31661a2.contains(code) || EXCEPTIONNALY_RESERVED_ISO3166_1_CODES.contains(code));
|
---|
70 | }
|
---|
71 | // Check presence of all ISO-3166-2 codes for USA, Canada, Australia (for speed limits)
|
---|
72 | for (String code : ISO3166_2_CODES) {
|
---|
73 | assertEquals(code, 1, tagged.stream().filter(SearchCompiler.compile("ISO3166-2="+code)).count());
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|