source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/validator/ValidatorTagCheckerRulesPreferenceTest.java@ 8937

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

add unit tests to check validity of all map paint styles and tagging presets

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.validator;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.io.IOException;
8import java.util.ArrayList;
9import java.util.Collection;
10
11import org.junit.BeforeClass;
12import org.junit.Test;
13import org.openstreetmap.josm.JOSMFixture;
14import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
15import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.ParseResult;
16import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
17import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
18
19/**
20 * Unit tests of {@link ValidatorTagCheckerRulesPreference} class.
21 */
22public class ValidatorTagCheckerRulesPreferenceTest {
23
24 /**
25 * Setup test.
26 */
27 @BeforeClass
28 public static void setUpBeforeClass() {
29 JOSMFixture.createUnitTestFixture().init();
30 }
31
32 /**
33 * Test that available tag checker rules are valid.
34 * @throws IOException if any I/O error occurs
35 * @throws ParseException if the config file does not match MapCSS syntax
36 */
37 @Test
38 public void testValidityOfAvailableRules() throws ParseException, IOException {
39 Collection<ExtendedSourceEntry> sources = new ValidatorTagCheckerRulesPreference.TagCheckerRulesSourceEditor()
40 .loadAndGetAvailableSources();
41 assertFalse(sources.isEmpty());
42 Collection<Throwable> allErrors = new ArrayList<>();
43 MapCSSTagChecker tagChecker = new MapCSSTagChecker();
44 for (ExtendedSourceEntry source : sources) {
45 System.out.print(source.url);
46 ParseResult result = tagChecker.addMapCSS(source.url);
47 assertFalse(result.parseChecks.isEmpty());
48 System.out.println(result.parseErrors.isEmpty() ? " => OK" : " => KO");
49 allErrors.addAll(result.parseErrors);
50 }
51 assertTrue(allErrors.isEmpty());
52 }
53}
Note: See TracBrowser for help on using the repository browser.