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

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

nicer test names

  • 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.Assert.assertTrue;
5import static org.junit.Assume.assumeTrue;
6
7import java.io.IOException;
8import java.util.ArrayList;
9import java.util.List;
10
11import org.junit.BeforeClass;
12import org.junit.ClassRule;
13import org.junit.Test;
14import org.junit.runner.RunWith;
15import org.junit.runners.Parameterized.Parameters;
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.testutils.ParallelParameterized;
28import org.openstreetmap.josm.tools.ImageProvider;
29
30import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
31
32/**
33 * Integration tests of {@link MapPaintPreference} class.
34 */
35@RunWith(ParallelParameterized.class)
36public 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}
Note: See TracBrowser for help on using the repository browser.