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

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

see #16567 - fix integration tests

  • Property svn:eol-style set to native
File size: 4.4 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.jupiter.api.BeforeAll;
13import org.junit.jupiter.api.extension.RegisterExtension;
14import org.junit.jupiter.params.ParameterizedTest;
15import org.junit.jupiter.params.provider.MethodSource;
16import org.openstreetmap.josm.TestUtils;
17import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
18import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
19import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
20import org.openstreetmap.josm.gui.mappaint.StyleKeys;
21import org.openstreetmap.josm.gui.mappaint.StyleSource;
22import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
23import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.AssignmentInstruction;
24import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule;
25import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
26import org.openstreetmap.josm.testutils.JOSMTestRules;
27import org.openstreetmap.josm.tools.ImageProvider;
28
29import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
30
31/**
32 * Integration tests of {@link MapPaintPreference} class.
33 */
34class 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}
Note: See TracBrowser for help on using the repository browser.