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.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
|
---|
14 | import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
|
---|
15 | import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.ParseResult;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 |
|
---|
18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Integration tests of {@link ValidatorTagCheckerRulesPreference} class.
|
---|
22 | */
|
---|
23 | public class ValidatorTagCheckerRulesPreferenceTestIT {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup rule
|
---|
27 | */
|
---|
28 | @Rule
|
---|
29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
30 | public JOSMTestRules test = new JOSMTestRules().https().timeout(20_000);
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Test that available tag checker rules are valid.
|
---|
34 | * @throws Exception in case of error
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | public void testValidityOfAvailableRules() throws Exception {
|
---|
38 | Collection<ExtendedSourceEntry> sources = new ValidatorTagCheckerRulesPreference.TagCheckerRulesSourceEditor()
|
---|
39 | .loadAndGetAvailableSources();
|
---|
40 | assertFalse(sources.isEmpty());
|
---|
41 | Collection<Throwable> allErrors = new ArrayList<>();
|
---|
42 | MapCSSTagChecker tagChecker = new MapCSSTagChecker();
|
---|
43 | for (ExtendedSourceEntry source : sources) {
|
---|
44 | System.out.print(source.url);
|
---|
45 | try {
|
---|
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 | } catch (IOException e) {
|
---|
51 | System.out.println(" => KO");
|
---|
52 | allErrors.add(e);
|
---|
53 | e.printStackTrace();
|
---|
54 | }
|
---|
55 | }
|
---|
56 | assertTrue(allErrors.isEmpty());
|
---|
57 | }
|
---|
58 | }
|
---|