1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.validator;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.util.ArrayList;
|
---|
9 | import java.util.Collection;
|
---|
10 |
|
---|
11 | import org.junit.BeforeClass;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.JOSMFixture;
|
---|
14 | import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
|
---|
15 | import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.ParseResult;
|
---|
16 | import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
|
---|
17 | import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Integration tests of {@link ValidatorTagCheckerRulesPreference} class.
|
---|
21 | */
|
---|
22 | public class ValidatorTagCheckerRulesPreferenceTestIT {
|
---|
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 | try {
|
---|
47 | ParseResult result = tagChecker.addMapCSS(source.url);
|
---|
48 | assertFalse(result.parseChecks.isEmpty());
|
---|
49 | System.out.println(result.parseErrors.isEmpty() ? " => OK" : " => KO");
|
---|
50 | allErrors.addAll(result.parseErrors);
|
---|
51 | } catch (IOException e) {
|
---|
52 | System.out.println(" => KO");
|
---|
53 | allErrors.add(e);
|
---|
54 | e.printStackTrace();
|
---|
55 | }
|
---|
56 | }
|
---|
57 | assertTrue(allErrors.isEmpty());
|
---|
58 | }
|
---|
59 | }
|
---|