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

Last change on this file since 10703 was 10333, checked in by Don-vip, 8 years ago

fix ignore rules in mappaint styles integration test

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