Ticket #17055: TaginfoTestIT.patch

File TaginfoTestIT.patch, 3.4 KB (added by GerdP, 5 years ago)
  • test/functional/org/openstreetmap/josm/data/osm/TaginfoTestIT.java

     
    33
    44import static org.junit.Assert.assertTrue;
    55
     6import java.io.BufferedReader;
    67import java.io.IOException;
    78import java.io.InputStream;
    89import java.net.URL;
     
    1718import org.junit.Rule;
    1819import org.junit.Test;
    1920import org.openstreetmap.josm.data.coor.LatLon;
     21import org.openstreetmap.josm.data.validation.TestError;
    2022import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
    2123import org.openstreetmap.josm.data.validation.tests.TagChecker;
    2224import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
    2325import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
     26import org.openstreetmap.josm.io.CachedFile;
    2427import org.openstreetmap.josm.testutils.JOSMTestRules;
    2528import org.openstreetmap.josm.tools.HttpClient;
    2629import org.xml.sax.SAXException;
     
    9194        }
    9295        assertTrue(errors.toString(), errors.isEmpty());
    9396    }
     97
     98    /**
     99     * Checks that tags with a count > 1000 are not reported as false positives.
     100     * @throws SAXException if any XML parsing error occurs
     101     * @throws IOException if any I/O error occurs
     102     * @throws ParseException if any MapCSS parsing error occurs
     103     */
     104    @Test
     105    public void testCheckLessPopularTags() throws SAXException, IOException, ParseException {
     106        TaggingPresets.readFromPreferences();
     107        TagChecker tc = new TagChecker();
     108        tc.initialize();
     109        tc.startTest(null);
     110
     111        List<String> errors = new ArrayList<>();
     112        try (
     113                CachedFile cf = new CachedFile("nodist/data/frequent-tags.cfg");
     114                BufferedReader reader = cf.getContentReader()
     115            ) {
     116            String line;
     117            while ((line = reader.readLine()) != null && (!line.isEmpty())) {
     118                if (!line.startsWith("#")) {
     119                    String[] parts = line.split("\\|");
     120                    // select key, value, count_nodes, count_ways, count_relations from tags
     121                    if (parts.length >= 2) {
     122                        String key = parts[0];
     123                        String value = parts[1];
     124
     125                        if (!TagChecker.isTagInPresets(key, value) && !TagChecker.isTagIgnored(key, value)) {
     126                            Node n = new Node(LatLon.NORTH_POLE);
     127                            n.put(key, value);
     128                            new DataSet(n);
     129                            tc.check(n);
     130                            if (!tc.getErrors().isEmpty()) {
     131                                for (TestError e : tc.getErrors()) {
     132                                    if (e.getDescription() != null && e.getDescription().contains("is meant?")) {
     133                                        errors.add(key+"="+value+ " " + e.getDescription() + " " + line);
     134                                    }
     135                                }
     136
     137                            }
     138                            tc.clear();
     139                        }
     140                    }
     141                }
     142            }
     143        }
     144        for (String error : errors) {
     145            System.err.println("false positive? " + error);
     146        }
     147        assertTrue(errors.toString(), errors.isEmpty());
     148    }
    94149}