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