Changeset 15095 in josm for trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java
- Timestamp:
- 2019-05-19T17:11:38+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java
r14235 r15095 2 2 package org.openstreetmap.josm.gui.preferences.map; 3 3 4 import static org.junit.Assert.assertFalse;5 4 import static org.junit.Assert.assertTrue; 5 import static org.junit.Assume.assumeTrue; 6 6 7 import java.util.Collection; 8 import java.util.HashMap; 9 import java.util.Map; 7 import java.io.IOException; 8 import java.util.ArrayList; 9 import java.util.List; 10 import java.util.stream.Collectors; 10 11 11 import org.junit.Rule; 12 import org.junit.BeforeClass; 13 import org.junit.ClassRule; 12 14 import org.junit.Test; 15 import org.junit.runner.RunWith; 16 import org.junit.runners.Parameterized.Parameters; 17 import org.openstreetmap.josm.TestUtils; 13 18 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry; 14 19 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; … … 21 26 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 22 27 import org.openstreetmap.josm.testutils.JOSMTestRules; 28 import org.openstreetmap.josm.testutils.ParallelParameterized; 23 29 import org.openstreetmap.josm.tools.ImageProvider; 24 30 … … 28 34 * Integration tests of {@link MapPaintPreference} class. 29 35 */ 36 @RunWith(ParallelParameterized.class) 30 37 public class MapPaintPreferenceTestIT { 31 38 … … 33 40 * Setup rule 34 41 */ 35 @ Rule42 @ClassRule 36 43 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 public JOSMTestRules test = new JOSMTestRules().https().timeout(15000*60); 44 public static JOSMTestRules test = new JOSMTestRules().https().timeout(15000*60).parameters(); 45 46 /** Entry to test */ 47 private final ExtendedSourceEntry source; 48 private final List<String> ignoredErrors = new ArrayList<>(); 49 private static final List<String> errorsToIgnore = new ArrayList<>(); 38 50 39 51 /** 40 * Test that available map paint styles are valid. 52 * Setup test 53 * @throws IOException in case of I/O error 54 */ 55 @BeforeClass 56 public static void beforeClass() throws IOException { 57 errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(MapPaintPreferenceTestIT.class)); 58 } 59 60 /** 61 * Returns list of map paint styles to test. 62 * @return list of map paint styles to test 63 * @throws Exception if an error occurs 64 */ 65 @Parameters(name = "{0} - {1}") 66 public static List<Object[]> data() throws Exception { 67 ImageProvider.clearCache(); 68 return new MapPaintPreference.MapPaintSourceEditor().loadAndGetAvailableSources().stream() 69 .map(x -> new Object[] {x.getDisplayName(), x.url, x}).collect(Collectors.toList()); 70 } 71 72 /** 73 * Constructs a new {@code MapPaintPreferenceTestIT} 74 * @param displayName displayed name 75 * @param url URL 76 * @param source source entry to test 77 */ 78 public MapPaintPreferenceTestIT(String displayName, String url, ExtendedSourceEntry source) { 79 this.source = source; 80 } 81 82 /** 83 * Test that map paint style is valid. 41 84 * @throws Exception in case of error 42 85 */ 43 86 @Test 44 public void testValidityOfAvailableStyles() throws Exception { 45 ImageProvider.clearCache(); 46 Collection<ExtendedSourceEntry> sources = new MapPaintPreference.MapPaintSourceEditor() 47 .loadAndGetAvailableSources(); 48 // Drop everything from yopaseopor, pasharm and www.freietonne.de, too many errors 49 sources.removeIf(x -> x.url.contains("yopaseopor/") || x.url.contains("/pasharm") || x.url.contains("www.freietonne.de")); 50 assertFalse(sources.isEmpty()); 51 Map<String, Collection<Throwable>> allErrors = new HashMap<>(); 52 Map<String, Collection<String>> allWarnings = new HashMap<>(); 53 for (ExtendedSourceEntry source : sources) { 54 // Do not validate XML styles 55 if (!"xml".equalsIgnoreCase(source.styleType)) { 56 System.out.println(source.url); 57 StyleSource style = MapPaintStyles.addStyle(source); 58 if (style instanceof MapCSSStyleSource) { 59 // Force loading of all icons to detect missing ones 60 for (MapCSSRule rule : ((MapCSSStyleSource) style).rules) { 61 for (Instruction instruction : rule.declaration.instructions) { 62 if (instruction instanceof AssignmentInstruction) { 63 AssignmentInstruction ai = (AssignmentInstruction) instruction; 64 if (StyleKeys.ICON_IMAGE.equals(ai.key) 65 || StyleKeys.FILL_IMAGE.equals(ai.key) 66 || StyleKeys.REPEAT_IMAGE.equals(ai.key)) { 67 if (ai.val instanceof String) { 68 MapPaintStyles.getIconProvider(new IconReference((String) ai.val, style), true); 69 } 70 } 87 public void testStyleValidity() throws Exception { 88 StyleSource style = MapPaintStyles.addStyle(source); 89 if (style instanceof MapCSSStyleSource) { 90 // Force loading of all icons to detect missing ones 91 for (MapCSSRule rule : ((MapCSSStyleSource) style).rules) { 92 for (Instruction instruction : rule.declaration.instructions) { 93 if (instruction instanceof AssignmentInstruction) { 94 AssignmentInstruction ai = (AssignmentInstruction) instruction; 95 if (StyleKeys.ICON_IMAGE.equals(ai.key) 96 || StyleKeys.FILL_IMAGE.equals(ai.key) 97 || StyleKeys.REPEAT_IMAGE.equals(ai.key)) { 98 if (ai.val instanceof String) { 99 MapPaintStyles.getIconProvider(new IconReference((String) ai.val, style), true); 71 100 } 72 101 } 73 102 } 74 103 } 75 System.out.println(style.isValid() ? " => OK" : " => KO");76 Collection<Throwable> errors = style.getErrors();77 Collection<String> warnings = style.getWarnings();78 if (!errors.isEmpty()) {79 allErrors.put(source.url, errors);80 }81 if (!warnings.isEmpty()) {82 allWarnings.put(source.url, warnings);83 }84 104 } 85 105 } 86 ImageProvider.clearCache(); 87 assertTrue(allErrors.toString()+"\n"+allWarnings.toString(), allErrors.isEmpty() && allWarnings.isEmpty()); 106 107 List<Throwable> errors = new ArrayList<>(style.getErrors()); 108 errors.stream().map(Throwable::getMessage).filter(MapPaintPreferenceTestIT::isIgnoredSubstring).forEach(ignoredErrors::add); 109 errors.removeIf(e -> ignoredErrors.contains(e.getMessage())); 110 111 List<String> warnings = new ArrayList<>(style.getWarnings()); 112 warnings.stream().filter(MapPaintPreferenceTestIT::isIgnoredSubstring).forEach(ignoredErrors::add); 113 warnings.removeAll(ignoredErrors); 114 115 assertTrue(errors.toString() + '\n' + warnings.toString(), errors.isEmpty() && warnings.isEmpty()); 116 assumeTrue(ignoredErrors.toString(), ignoredErrors.isEmpty()); 117 } 118 119 private static boolean isIgnoredSubstring(String substring) { 120 return errorsToIgnore.parallelStream().anyMatch(x -> substring.contains(x)); 88 121 } 89 122 }
Note:
See TracChangeset
for help on using the changeset viewer.