source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java@ 17275

Last change on this file since 17275 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.map;
3
4import static org.junit.Assume.assumeFalse;
5import static org.junit.Assume.assumeTrue;
6import static org.junit.jupiter.api.Assertions.assertTrue;
7
8import java.io.IOException;
9import java.util.ArrayList;
10import java.util.List;
11
12import org.junit.ClassRule;
13import org.junit.jupiter.api.BeforeAll;
14import org.junit.jupiter.api.Test;
15import org.junit.runner.RunWith;
16import org.junit.runners.Parameterized.Parameters;
17import org.openstreetmap.josm.TestUtils;
18import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
19import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
20import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
21import org.openstreetmap.josm.gui.mappaint.StyleKeys;
22import org.openstreetmap.josm.gui.mappaint.StyleSource;
23import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
24import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.AssignmentInstruction;
25import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
26import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
27import org.openstreetmap.josm.testutils.JOSMTestRules;
28import org.openstreetmap.josm.testutils.ParallelParameterized;
29import org.openstreetmap.josm.tools.ImageProvider;
30
31import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
32
33/**
34 * Integration tests of {@link MapPaintPreference} class.
35 */
36@RunWith(ParallelParameterized.class)
37class 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}
Note: See TracBrowser for help on using the repository browser.