source: josm/trunk/test/functional/org/openstreetmap/josm/data/osm/TaginfoTestIT.java@ 13103

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

see #15560 - repair coverage, fix typo, increase integration test timeout

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.junit.Assert.assertTrue;
5
6import java.io.IOException;
7import java.io.InputStream;
8import java.net.URL;
9import java.util.ArrayList;
10import java.util.List;
11
12import javax.json.Json;
13import javax.json.JsonObject;
14import javax.json.JsonReader;
15import javax.json.JsonValue;
16
17import org.junit.Rule;
18import org.junit.Test;
19import org.openstreetmap.josm.data.coor.LatLon;
20import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
21import org.openstreetmap.josm.data.validation.tests.TagChecker;
22import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
23import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
24import org.openstreetmap.josm.testutils.JOSMTestRules;
25import org.openstreetmap.josm.tools.HttpClient;
26import org.xml.sax.SAXException;
27
28import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
29
30/**
31 * Various integration tests with Taginfo.
32 */
33public class TaginfoTestIT {
34
35 /**
36 * Setup test.
37 */
38 @Rule
39 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
40 public JOSMTestRules test = new JOSMTestRules().preferences().timeout(20000);
41
42 /**
43 * Checks that popular tags are known (i.e included in internal presets, or deprecated, or explicitely ignored)
44 * @throws SAXException if any XML parsing error occurs
45 * @throws IOException if any I/O error occurs
46 * @throws ParseException if any MapCSS parsing error occurs
47 */
48 @Test
49 public void testCheckPopularTags() throws SAXException, IOException, ParseException {
50 TaggingPresets.readFromPreferences();
51 new TagChecker().initialize();
52 MapCSSTagChecker mapCssTagChecker = new MapCSSTagChecker();
53 mapCssTagChecker.addMapCSS("resource://data/validator/deprecated.mapcss");
54
55 List<String> errors = new ArrayList<>();
56 try (InputStream in = HttpClient.create(new URL("https://taginfo.openstreetmap.org/api/4/tags/popular")).connect().getContent();
57 JsonReader reader = Json.createReader(in)) {
58 for (JsonValue item : reader.readObject().getJsonArray("data")) {
59 JsonObject obj = (JsonObject) item;
60 // Only consider tags with wiki pages
61 if (obj.getInt("in_wiki") == 1) {
62 String key = obj.getString("key");
63 String value = obj.getString("value");
64 System.out.print("Checking "+key+"="+value+" ... ");
65 boolean ok = true;
66 // Check if tag is in internal presets
67 if (!TagChecker.isTagInPresets(key, value)) {
68 // If not, check if we have either a deprecated mapcss test for it
69 Node n = new Node(LatLon.NORTH_POLE);
70 Way w = new Way();
71 Relation r = new Relation();
72 n.put(key, value);
73 w.put(key, value);
74 r.put(key, value);
75 new DataSet(n, w, r);
76 if (mapCssTagChecker.getErrorsForPrimitive(n, false).isEmpty()
77 && mapCssTagChecker.getErrorsForPrimitive(w, false).isEmpty()
78 && mapCssTagChecker.getErrorsForPrimitive(r, false).isEmpty()) {
79 // Or a legacy tagchecker ignore rule
80 if (!TagChecker.isTagIgnored(key, value)) {
81 ok = !errors.add(key +"="+ value + " - " + obj.getInt("count_all"));
82 }
83 }
84 }
85 System.out.println(ok ? "OK" : "KO");
86 }
87 }
88 }
89 for (String error : errors) {
90 System.err.println(error);
91 }
92 assertTrue(errors.toString(), errors.isEmpty());
93 }
94}
Note: See TracBrowser for help on using the repository browser.