source: josm/trunk/test/functional/org/openstreetmap/josm/data/BoundariesTestIT.java@ 12858

Last change on this file since 12858 was 12858, checked in by Don-vip, 7 years ago

see #15229 - fix integration tests

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.io.InputStream;
8import java.util.Arrays;
9import java.util.List;
10import java.util.Locale;
11import java.util.stream.Collectors;
12
13import org.junit.Rule;
14import org.junit.Test;
15import org.openstreetmap.josm.data.osm.DataSet;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.search.SearchCompiler;
18import org.openstreetmap.josm.io.OsmReader;
19import org.openstreetmap.josm.testutils.JOSMTestRules;
20
21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22
23/**
24 * Test of boundaries OSM file.
25 */
26public 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}
Note: See TracBrowser for help on using the repository browser.