1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.map;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
5 | import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
---|
6 | import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
---|
7 |
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.concurrent.TimeUnit;
|
---|
12 |
|
---|
13 | import org.junit.jupiter.api.BeforeAll;
|
---|
14 | import org.junit.jupiter.api.Timeout;
|
---|
15 | import org.junit.jupiter.params.ParameterizedTest;
|
---|
16 | import org.junit.jupiter.params.provider.MethodSource;
|
---|
17 | import org.openstreetmap.josm.TestUtils;
|
---|
18 | import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
|
---|
19 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
20 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
|
---|
21 | import org.openstreetmap.josm.gui.mappaint.StyleKeys;
|
---|
22 | import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
---|
23 | import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
|
---|
24 | import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.AssignmentInstruction;
|
---|
25 | import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
|
---|
26 | import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
|
---|
27 | import org.openstreetmap.josm.gui.preferences.AbstractExtendedSourceEntryTestCase;
|
---|
28 | import org.openstreetmap.josm.testutils.annotations.HTTPS;
|
---|
29 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Integration tests of {@link MapPaintPreference} class.
|
---|
33 | */
|
---|
34 | @HTTPS
|
---|
35 | @Timeout(value = 15, unit = TimeUnit.MINUTES)
|
---|
36 | class MapPaintPreferenceTestIT extends AbstractExtendedSourceEntryTestCase {
|
---|
37 | /**
|
---|
38 | * Setup test
|
---|
39 | * @throws IOException in case of I/O error
|
---|
40 | */
|
---|
41 | @BeforeAll
|
---|
42 | public static void beforeClass() throws IOException {
|
---|
43 | errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(MapPaintPreferenceTestIT.class));
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Returns list of map paint styles to test.
|
---|
48 | * @return list of map paint styles to test
|
---|
49 | * @throws Exception if an error occurs
|
---|
50 | */
|
---|
51 | public static List<Object[]> data() throws Exception {
|
---|
52 | ImageProvider.clearCache();
|
---|
53 | return getTestParameters(new MapPaintPreference.MapPaintSourceEditor().loadAndGetAvailableSources());
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Test that map paint style is valid.
|
---|
58 | * @param displayName displayed name
|
---|
59 | * @param url URL
|
---|
60 | * @param source source entry to test
|
---|
61 | */
|
---|
62 | @ParameterizedTest(name = "{0} - {1}")
|
---|
63 | @MethodSource("data")
|
---|
64 | void testStyleValidity(String displayName, String url, ExtendedSourceEntry source) {
|
---|
65 | assumeFalse(isIgnoredSubstring(source, source.url));
|
---|
66 | StyleSource style = MapPaintStyles.addStyle(source);
|
---|
67 | if (style instanceof MapCSSStyleSource) {
|
---|
68 | // Force loading of all icons to detect missing ones
|
---|
69 | for (MapCSSRule rule : ((MapCSSStyleSource) style).rules) {
|
---|
70 | for (Instruction instruction : rule.declaration.instructions) {
|
---|
71 | if (instruction instanceof AssignmentInstruction) {
|
---|
72 | AssignmentInstruction ai = (AssignmentInstruction) instruction;
|
---|
73 | if (StyleKeys.ICON_IMAGE.equals(ai.key)
|
---|
74 | || StyleKeys.FILL_IMAGE.equals(ai.key)
|
---|
75 | || StyleKeys.REPEAT_IMAGE.equals(ai.key)) {
|
---|
76 | if (ai.val instanceof String) {
|
---|
77 | MapPaintStyles.getIconProvider(new IconReference((String) ai.val, style), true);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | List<String> ignoredErrors = new ArrayList<>();
|
---|
86 | List<Throwable> errors = new ArrayList<>(style.getErrors());
|
---|
87 | errors.stream().map(Throwable::getMessage).filter(s -> isIgnoredSubstring(source, s)).forEach(ignoredErrors::add);
|
---|
88 | errors.removeIf(e -> ignoredErrors.contains(e.getMessage()));
|
---|
89 |
|
---|
90 | List<String> warnings = new ArrayList<>(style.getWarnings());
|
---|
91 | warnings.stream().filter(s -> isIgnoredSubstring(source, s)).forEach(ignoredErrors::add);
|
---|
92 | warnings.removeAll(ignoredErrors);
|
---|
93 |
|
---|
94 | // #16567 - Shouldn't be necessary to print displayName if Ant worked properly
|
---|
95 | // See https://josm.openstreetmap.de/ticket/16567#comment:53
|
---|
96 | // See https://bz.apache.org/bugzilla/show_bug.cgi?id=64564
|
---|
97 | // See https://github.com/apache/ant/pull/121
|
---|
98 | assertTrue(errors.isEmpty() && warnings.isEmpty(), displayName + " => " + errors + '\n' + warnings);
|
---|
99 | assumeTrue(ignoredErrors.isEmpty(), ignoredErrors.toString());
|
---|
100 | }
|
---|
101 | }
|
---|