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.preferences.SourceEditor.ExtendedSourceEntry;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Integration tests of {@link ValidatorTagCheckerRulesPreference} class.
|
---|
20 | */
|
---|
21 | public class ValidatorTagCheckerRulesPreferenceTestIT {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Setup test.
|
---|
25 | */
|
---|
26 | @BeforeClass
|
---|
27 | public static void setUpBeforeClass() {
|
---|
28 | JOSMFixture.createUnitTestFixture().init();
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Test that available tag checker rules are valid.
|
---|
33 | * @throws Exception in case of error
|
---|
34 | */
|
---|
35 | @Test
|
---|
36 | public void testValidityOfAvailableRules() throws Exception {
|
---|
37 | Collection<ExtendedSourceEntry> sources = new ValidatorTagCheckerRulesPreference.TagCheckerRulesSourceEditor()
|
---|
38 | .loadAndGetAvailableSources();
|
---|
39 | assertFalse(sources.isEmpty());
|
---|
40 | Collection<Throwable> allErrors = new ArrayList<>();
|
---|
41 | MapCSSTagChecker tagChecker = new MapCSSTagChecker();
|
---|
42 | for (ExtendedSourceEntry source : sources) {
|
---|
43 | System.out.print(source.url);
|
---|
44 | try {
|
---|
45 | ParseResult result = tagChecker.addMapCSS(source.url);
|
---|
46 | assertFalse(result.parseChecks.isEmpty());
|
---|
47 | System.out.println(result.parseErrors.isEmpty() ? " => OK" : " => KO");
|
---|
48 | allErrors.addAll(result.parseErrors);
|
---|
49 | } catch (IOException e) {
|
---|
50 | System.out.println(" => KO");
|
---|
51 | allErrors.add(e);
|
---|
52 | e.printStackTrace();
|
---|
53 | }
|
---|
54 | }
|
---|
55 | assertTrue(allErrors.isEmpty());
|
---|
56 | }
|
---|
57 | }
|
---|