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.ClassRule;
|
---|
13 | import org.junit.jupiter.api.BeforeAll;
|
---|
14 | import org.junit.jupiter.api.Test;
|
---|
15 | import org.junit.runner.RunWith;
|
---|
16 | import org.junit.runners.Parameterized.Parameters;
|
---|
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.testutils.JOSMTestRules;
|
---|
28 | import org.openstreetmap.josm.testutils.ParallelParameterized;
|
---|
29 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
30 |
|
---|
31 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Integration tests of {@link MapPaintPreference} class.
|
---|
35 | */
|
---|
36 | @RunWith(ParallelParameterized.class)
|
---|
37 | class MapPaintPreferenceTestIT extends AbstractExtendedSourceEntryTestCase {
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Setup rule
|
---|
41 | */
|
---|
42 | @ClassRule
|
---|
43 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
44 | public static JOSMTestRules test = new JOSMTestRules().https().timeout(15000*60).parameters();
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Setup test
|
---|
48 | * @throws IOException in case of I/O error
|
---|
49 | */
|
---|
50 | @BeforeAll
|
---|
51 | public static void beforeClass() throws IOException {
|
---|
52 | errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(MapPaintPreferenceTestIT.class));
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Returns list of map paint styles to test.
|
---|
57 | * @return list of map paint styles to test
|
---|
58 | * @throws Exception if an error occurs
|
---|
59 | */
|
---|
60 | @Parameters(name = "{0} - {1}")
|
---|
61 | public static List<Object[]> data() throws Exception {
|
---|
62 | ImageProvider.clearCache();
|
---|
63 | return getTestParameters(new MapPaintPreference.MapPaintSourceEditor().loadAndGetAvailableSources());
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Constructs a new {@code MapPaintPreferenceTestIT}
|
---|
68 | * @param displayName displayed name
|
---|
69 | * @param url URL
|
---|
70 | * @param source source entry to test
|
---|
71 | */
|
---|
72 | MapPaintPreferenceTestIT(String displayName, String url, ExtendedSourceEntry source) {
|
---|
73 | super(source);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Test that map paint style is valid.
|
---|
78 | * @throws Exception in case of error
|
---|
79 | */
|
---|
80 | @Test
|
---|
81 | void testStyleValidity() throws Exception {
|
---|
82 | assumeFalse(isIgnoredSubstring(source.url));
|
---|
83 | StyleSource style = MapPaintStyles.addStyle(source);
|
---|
84 | if (style instanceof MapCSSStyleSource) {
|
---|
85 | // Force loading of all icons to detect missing ones
|
---|
86 | for (MapCSSRule rule : ((MapCSSStyleSource) style).rules) {
|
---|
87 | for (Instruction instruction : rule.declaration.instructions) {
|
---|
88 | if (instruction instanceof AssignmentInstruction) {
|
---|
89 | AssignmentInstruction ai = (AssignmentInstruction) instruction;
|
---|
90 | if (StyleKeys.ICON_IMAGE.equals(ai.key)
|
---|
91 | || StyleKeys.FILL_IMAGE.equals(ai.key)
|
---|
92 | || StyleKeys.REPEAT_IMAGE.equals(ai.key)) {
|
---|
93 | if (ai.val instanceof String) {
|
---|
94 | MapPaintStyles.getIconProvider(new IconReference((String) ai.val, style), true);
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | List<Throwable> errors = new ArrayList<>(style.getErrors());
|
---|
103 | errors.stream().map(Throwable::getMessage).filter(this::isIgnoredSubstring).forEach(ignoredErrors::add);
|
---|
104 | errors.removeIf(e -> ignoredErrors.contains(e.getMessage()));
|
---|
105 |
|
---|
106 | List<String> warnings = new ArrayList<>(style.getWarnings());
|
---|
107 | warnings.stream().filter(this::isIgnoredSubstring).forEach(ignoredErrors::add);
|
---|
108 | warnings.removeAll(ignoredErrors);
|
---|
109 |
|
---|
110 | assertTrue(errors.isEmpty() && warnings.isEmpty(), errors.toString() + '\n' + warnings.toString());
|
---|
111 | assumeTrue(ignoredErrors.toString(), ignoredErrors.isEmpty());
|
---|
112 | }
|
---|
113 | }
|
---|