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

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

make the distinction between unit tests (*Test.java) and integration tests (*TestIT.java)

File size: 4.3 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.io.IOException;
8import java.util.Collection;
9import java.util.Collections;
10import java.util.HashMap;
11import java.util.Map;
12
13import org.junit.BeforeClass;
14import org.junit.Rule;
15import org.junit.Test;
16import org.junit.rules.Timeout;
17import org.openstreetmap.josm.JOSMFixture;
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.gui.mappaint.mapcss.parsergen.ParseException;
27import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
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 public Timeout globalTimeout = Timeout.seconds(10*60);
39
40 /**
41 * Setup test.
42 */
43 @BeforeClass
44 public static void setUpBeforeClass() {
45 JOSMFixture.createUnitTestFixture().init();
46 }
47
48 /**
49 * Test that available map paint styles are valid.
50 * @throws IOException if any I/O error occurs
51 * @throws ParseException if the config file does not match MapCSS syntax
52 */
53 @Test
54 public void testValidityOfAvailableStyles() throws ParseException, IOException {
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()) {
90 allWarnings.put(source.url, warnings);
91 }
92 } else {
93 allWarnings.put(source.url, Collections.singleton("MapPaintStyles.addStyle() returned null"));
94 }
95 }
96 }
97 assertTrue(allErrors.toString()+"\n"+allWarnings.toString(), allErrors.isEmpty() && allWarnings.isEmpty());
98 }
99}
Note: See TracBrowser for help on using the repository browser.