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

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

see #15182 - code refactoring to avoid dependence on GUI packages from Preferences

  • 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.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.util.Collection;
8import java.util.Collections;
9import java.util.HashMap;
10import java.util.Map;
11
12import org.junit.BeforeClass;
13import org.junit.Rule;
14import org.junit.Test;
15import org.junit.rules.Timeout;
16import org.openstreetmap.josm.JOSMFixture;
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.tools.ImageProvider;
27
28import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
29
30/**
31 * Integration tests of {@link MapPaintPreference} class.
32 */
33public class MapPaintPreferenceTestIT {
34
35 /**
36 * Global timeout applied to all test methods.
37 */
38 @Rule
39 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
40 public Timeout globalTimeout = Timeout.seconds(10*60);
41
42 /**
43 * Setup test.
44 */
45 @BeforeClass
46 public static void setUpBeforeClass() {
47 JOSMFixture.createUnitTestFixture().init();
48 }
49
50 /**
51 * Test that available map paint styles are valid.
52 * @throws Exception in case of error
53 */
54 @Test
55 public void testValidityOfAvailableStyles() throws Exception {
56 ImageProvider.clearCache();
57 Collection<ExtendedSourceEntry> sources = new MapPaintPreference.MapPaintSourceEditor()
58 .loadAndGetAvailableSources();
59 // Drop everything from yopaseopor and www.freietonne.de, too many errors
60 sources.removeIf(x -> x.url.contains("yopaseopor/") || x.url.contains("www.freietonne.de"));
61 assertFalse(sources.isEmpty());
62 Map<String, Collection<Throwable>> allErrors = new HashMap<>();
63 Map<String, Collection<String>> allWarnings = new HashMap<>();
64 for (ExtendedSourceEntry source : sources) {
65 // Do not validate XML styles
66 if (!"xml".equalsIgnoreCase(source.styleType)) {
67 System.out.println(source.url);
68 StyleSource style = MapPaintStyles.addStyle(source);
69 if (style instanceof MapCSSStyleSource) {
70 // Force loading of all icons to detect missing ones
71 for (MapCSSRule rule : ((MapCSSStyleSource) style).rules) {
72 for (Instruction instruction : rule.declaration.instructions) {
73 if (instruction instanceof AssignmentInstruction) {
74 AssignmentInstruction ai = (AssignmentInstruction) instruction;
75 if (StyleKeys.ICON_IMAGE.equals(ai.key)
76 || StyleKeys.FILL_IMAGE.equals(ai.key)
77 || StyleKeys.REPEAT_IMAGE.equals(ai.key)) {
78 if (ai.val instanceof String) {
79 MapPaintStyles.getIconProvider(new IconReference((String) ai.val, style), true);
80 }
81 }
82 }
83 }
84 }
85 }
86 if (style != null) {
87 System.out.println(style.isValid() ? " => OK" : " => KO");
88 Collection<Throwable> errors = style.getErrors();
89 Collection<String> warnings = style.getWarnings();
90 if (!errors.isEmpty()) {
91 allErrors.put(source.url, errors);
92 }
93 if (!warnings.isEmpty()) {
94 allWarnings.put(source.url, warnings);
95 }
96 } else {
97 allWarnings.put(source.url, Collections.singleton("MapPaintStyles.addStyle() returned null"));
98 }
99 }
100 }
101 ImageProvider.clearCache();
102 assertTrue(allErrors.toString()+"\n"+allWarnings.toString(), allErrors.isEmpty() && allWarnings.isEmpty());
103 }
104}
Note: See TracBrowser for help on using the repository browser.