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

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

see #13036 - fix TagInfo integration test

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