source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTest.java@ 9339

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

see #12282 - handle warnings for mappaint styles:

  • Log warnings that occur when loading style
  • Display them in Mappaint dialog (Info action)
  • Drop redundant error icon
  • Ignore XML styles in styles validation test
  • Make styles validation test fail if at least a warning occur
File size: 2.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.io.IOException;
8import java.util.Collection;
9import java.util.HashMap;
10import java.util.Map;
11
12import org.junit.BeforeClass;
13import org.junit.Test;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
16import org.openstreetmap.josm.gui.mappaint.StyleSource;
17import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
18import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
19
20/**
21 * Unit tests of {@link MapPaintPreference} class.
22 */
23public class MapPaintPreferenceTest {
24
25 /**
26 * Setup test.
27 */
28 @BeforeClass
29 public static void setUpBeforeClass() {
30 JOSMFixture.createUnitTestFixture().init();
31 }
32
33 /**
34 * Test that available map paint styles are valid.
35 * @throws IOException if any I/O error occurs
36 * @throws ParseException if the config file does not match MapCSS syntax
37 */
38 @Test(timeout = 10*60*1000)
39 public void testValidityOfAvailableStyles() throws ParseException, IOException {
40 Collection<ExtendedSourceEntry> sources = new MapPaintPreference.MapPaintSourceEditor()
41 .loadAndGetAvailableSources();
42 assertFalse(sources.isEmpty());
43 Map<String, Collection<Throwable>> allErrors = new HashMap<>();
44 Map<String, Collection<String>> allWarnings = new HashMap<>();
45 for (ExtendedSourceEntry source : sources) {
46 // Do not validate XML styles
47 if (!"xml".equalsIgnoreCase(source.styleType)) {
48 System.out.println(source.url);
49 StyleSource style = MapPaintStyles.addStyle(source);
50 System.out.println(style.isValid() ? " => OK" : " => KO");
51 Collection<Throwable> errors = style.getErrors();
52 Collection<String> warnings = style.getWarnings();
53 if (!errors.isEmpty()) {
54 allErrors.put(source.url, errors);
55 }
56 if (!warnings.isEmpty()) {
57 allWarnings.put(source.url, warnings);
58 }
59 }
60 }
61 assertTrue(allErrors.toString()+"\n"+allWarnings.toString(), allErrors.isEmpty() && allWarnings.isEmpty());
62 }
63}
Note: See TracBrowser for help on using the repository browser.