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