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

Last change on this file since 18870 was 18870, checked in by taylor.smock, 8 months ago

See #16567: Update to JUnit 5

This converts most tests to use @Annotations. There are also some performance
improvements as it relates to 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.osm;
3
4import static org.junit.jupiter.api.Assertions.assertTrue;
5
6import java.io.IOException;
7import java.io.InputStream;
8import java.net.URL;
9import java.util.ArrayList;
10import java.util.List;
11
12import org.junit.jupiter.api.Test;
13import org.junit.jupiter.api.Timeout;
14import org.openstreetmap.josm.data.coor.LatLon;
15import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
16import org.openstreetmap.josm.data.validation.tests.TagChecker;
17import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
18import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
19import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
20import org.openstreetmap.josm.tools.HttpClient;
21
22import jakarta.json.Json;
23import jakarta.json.JsonObject;
24import jakarta.json.JsonReader;
25import jakarta.json.JsonValue;
26
27/**
28 * Various integration tests with Taginfo.
29 */
30@BasicPreferences
31@Timeout(20)
32class TaginfoTestIT {
33 /**
34 * Checks that popular tags are known (i.e included in internal presets, or deprecated, or explicitely ignored)
35 * @throws IOException if any I/O error occurs
36 * @throws ParseException if any MapCSS parsing error occurs
37 */
38 @Test
39 void testCheckPopularTags() throws IOException, ParseException {
40 TaggingPresets.readFromPreferences();
41 new TagChecker().initialize();
42 MapCSSTagChecker mapCssTagChecker = new MapCSSTagChecker();
43 mapCssTagChecker.addMapCSS("resource://data/validator/deprecated.mapcss");
44
45 List<String> errors = new ArrayList<>();
46 try (InputStream in = HttpClient.create(new URL("https://taginfo.openstreetmap.org/api/4/tags/popular")).connect().getContent();
47 JsonReader reader = Json.createReader(in)) {
48 for (JsonValue item : reader.readObject().getJsonArray("data")) {
49 JsonObject obj = (JsonObject) item;
50 // Only consider tags with wiki pages
51 if (obj.getInt("in_wiki") == 1) {
52 String key = obj.getString("key");
53 String value = obj.getString("value");
54 System.out.print("Checking "+key+"="+value+" ... ");
55 boolean ok = true;
56 // Check if tag is in internal presets
57 if (!TagChecker.isTagInPresets(key, value)) {
58 // If not, check if we have either a deprecated mapcss test for it
59 Node n = new Node(LatLon.NORTH_POLE);
60 Way w = new Way();
61 Relation r = new Relation();
62 n.put(key, value);
63 w.put(key, value);
64 r.put(key, value);
65 new DataSet(n, w, r);
66 if (mapCssTagChecker.getErrorsForPrimitive(n, false).isEmpty()
67 && mapCssTagChecker.getErrorsForPrimitive(w, false).isEmpty()
68 && mapCssTagChecker.getErrorsForPrimitive(r, false).isEmpty()) {
69 // Or a legacy tagchecker ignore rule
70 if (!TagChecker.isTagIgnored(key, value)) {
71 ok = !errors.add(key +"="+ value + " - " + obj.getInt("count_all"));
72 }
73 }
74 }
75 System.out.println(ok ? "OK" : "KO");
76 }
77 }
78 }
79 for (String error : errors) {
80 System.err.println(error);
81 }
82 assertTrue(errors.isEmpty(), errors::toString);
83 }
84}
Note: See TracBrowser for help on using the repository browser.