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