1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.validator;
|
---|
3 |
|
---|
4 | import static org.junit.Assume.assumeFalse;
|
---|
5 | import static org.junit.Assume.assumeTrue;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
7 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
8 |
|
---|
9 | import java.io.IOException;
|
---|
10 | import java.util.ArrayList;
|
---|
11 | import java.util.HashSet;
|
---|
12 | import java.util.List;
|
---|
13 | import java.util.Set;
|
---|
14 |
|
---|
15 | import org.junit.jupiter.api.BeforeAll;
|
---|
16 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
17 | import org.junit.jupiter.api.parallel.Execution;
|
---|
18 | import org.junit.jupiter.api.parallel.ExecutionMode;
|
---|
19 | import org.junit.jupiter.params.ParameterizedTest;
|
---|
20 | import org.junit.jupiter.params.provider.MethodSource;
|
---|
21 | import org.openstreetmap.josm.TestUtils;
|
---|
22 | import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
|
---|
23 | import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
|
---|
24 | import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.ParseResult;
|
---|
25 | import org.openstreetmap.josm.gui.preferences.AbstractExtendedSourceEntryTestCase;
|
---|
26 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
27 |
|
---|
28 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Integration tests of {@link ValidatorTagCheckerRulesPreference} class.
|
---|
32 | */
|
---|
33 | class ValidatorTagCheckerRulesPreferenceTestIT extends AbstractExtendedSourceEntryTestCase {
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Setup rule
|
---|
37 | */
|
---|
38 | @RegisterExtension
|
---|
39 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
40 | static JOSMTestRules test = new JOSMTestRules().https().timeout(20_000);
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Setup test
|
---|
44 | * @throws IOException in case of I/O error
|
---|
45 | */
|
---|
46 | @BeforeAll
|
---|
47 | public static void beforeClass() throws IOException {
|
---|
48 | errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(ValidatorTagCheckerRulesPreferenceTestIT.class));
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Returns list of entries to test.
|
---|
53 | * @return list of entries to test
|
---|
54 | * @throws Exception in case of error
|
---|
55 | */
|
---|
56 | public static List<Object[]> data() throws Exception {
|
---|
57 | return getTestParameters(new ValidatorTagCheckerRulesPreference.TagCheckerRulesSourceEditor()
|
---|
58 | .loadAndGetAvailableSources());
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Test that available tag checker rule is valid.
|
---|
63 | * @param displayName displayed name
|
---|
64 | * @param url URL
|
---|
65 | * @param source source entry to test
|
---|
66 | * @throws Exception in case of error
|
---|
67 | */
|
---|
68 | @Execution(ExecutionMode.CONCURRENT)
|
---|
69 | @ParameterizedTest(name = "{0} - {1}")
|
---|
70 | @MethodSource("data")
|
---|
71 | void testValidityOfAvailableRule(String displayName, String url, ExtendedSourceEntry source) throws Exception {
|
---|
72 | assumeFalse(isIgnoredSubstring(source, source.url));
|
---|
73 | List<String> ignoredErrors = new ArrayList<>();
|
---|
74 | Set<String> errors = new HashSet<>();
|
---|
75 | System.out.print(source.url);
|
---|
76 | try {
|
---|
77 | ParseResult result = new MapCSSTagChecker().addMapCSS(source.url);
|
---|
78 | assertFalse(result.parseChecks.isEmpty(), result::toString);
|
---|
79 | System.out.println(result.parseErrors.isEmpty() ? " => OK" : " => KO");
|
---|
80 | result.parseErrors.forEach(e -> handleException(source, e, errors, ignoredErrors));
|
---|
81 | } catch (IOException e) {
|
---|
82 | System.out.println(" => KO");
|
---|
83 | e.printStackTrace();
|
---|
84 | handleException(source, e, errors, ignoredErrors);
|
---|
85 | }
|
---|
86 | // #16567 - Shouldn't be necessary to print displayName if Ant worked properly
|
---|
87 | // See https://josm.openstreetmap.de/ticket/16567#comment:53
|
---|
88 | // See https://bz.apache.org/bugzilla/show_bug.cgi?id=64564
|
---|
89 | // See https://github.com/apache/ant/pull/121
|
---|
90 | assertTrue(errors.isEmpty(), displayName + " => " + errors);
|
---|
91 | assumeTrue(ignoredErrors.toString(), ignoredErrors.isEmpty());
|
---|
92 | }
|
---|
93 | }
|
---|