1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.map;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.util.Collection;
|
---|
9 | import java.util.HashMap;
|
---|
10 | import java.util.Map;
|
---|
11 |
|
---|
12 | import org.junit.BeforeClass;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.JOSMFixture;
|
---|
15 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
16 | import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
---|
17 | import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
|
---|
18 | import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests of {@link MapPaintPreference} class.
|
---|
22 | */
|
---|
23 | public 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 | }
|
---|