Changeset 15095 in josm for trunk/test
- Timestamp:
- 2019-05-19T17:11:38+02:00 (5 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r14795 r15095 28 28 import org.junit.ClassRule; 29 29 import org.junit.Test; 30 import org.junit.runner.Description;31 30 import org.junit.runner.RunWith; 32 31 import org.junit.runners.Parameterized.Parameters; 33 import org.junit.runners.model.Statement;34 32 import org.openstreetmap.gui.jmapviewer.Coordinate; 35 33 import org.openstreetmap.gui.jmapviewer.TileXY; … … 85 83 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 86 84 public static JOSMTestRules test = new JOSMTestRules().https().i18n().preferences().projection().projectionNadGrids() 87 .timeout((int) TimeUnit.MINUTES.toMillis(40)); 88 89 static { 90 try { 91 test.apply(new Statement() { 92 @Override 93 public void evaluate() throws Throwable { 94 // Do nothing. Hack needed because @Parameters are computed before anything else 95 } 96 }, Description.createSuiteDescription(ImageryPreferenceTestIT.class)).evaluate(); 97 } catch (Throwable e) { 98 Logging.error(e); 99 } 100 } 85 .timeout((int) TimeUnit.MINUTES.toMillis(40)).parameters(); 101 86 102 87 /** Entry to test */ -
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 } -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java
r14464 r15095 4 4 import static org.junit.Assert.assertFalse; 5 5 import static org.junit.Assert.assertTrue; 6 import static org.junit.Assume.assumeTrue; 6 7 7 8 import java.io.IOException; 9 import java.util.ArrayList; 8 10 import java.util.Collection; 9 import java.util.HashMap; 10 import java.util.Map; 11 import java.util.HashSet; 12 import java.util.List; 13 import java.util.Locale; 11 14 import java.util.Objects; 12 15 import java.util.Set; 13 import java.util.TreeSet;14 16 import java.util.concurrent.ExecutionException; 15 17 import java.util.concurrent.TimeUnit; 16 18 import java.util.concurrent.TimeoutException; 19 import java.util.stream.Collectors; 17 20 18 import org.junit.Rule; 21 import org.junit.BeforeClass; 22 import org.junit.ClassRule; 19 23 import org.junit.Test; 24 import org.junit.runner.RunWith; 25 import org.junit.runners.Parameterized.Parameters; 26 import org.openstreetmap.josm.TestUtils; 20 27 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry; 21 28 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; … … 23 30 import org.openstreetmap.josm.spi.preferences.Config; 24 31 import org.openstreetmap.josm.testutils.JOSMTestRules; 32 import org.openstreetmap.josm.testutils.ParallelParameterized; 25 33 import org.openstreetmap.josm.tools.ImageProvider; 26 34 import org.openstreetmap.josm.tools.Logging; … … 32 40 * Integration tests of {@link TaggingPresetPreference} class. 33 41 */ 42 @RunWith(ParallelParameterized.class) 34 43 public class TaggingPresetPreferenceTestIT { 35 44 … … 37 46 * Setup rule 38 47 */ 39 @ Rule48 @ClassRule 40 49 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 41 public JOSMTestRules test = new JOSMTestRules().https().timeout(10000*60); 50 public static JOSMTestRules test = new JOSMTestRules().https().timeout(10000*60).parameters(); 51 52 /** Entry to test */ 53 private final ExtendedSourceEntry source; 54 private final List<String> ignoredErrors = new ArrayList<>(); 55 private static final List<String> errorsToIgnore = new ArrayList<>(); 42 56 43 57 /** 44 * Test that available tagging presets are valid. 58 * Setup test 59 * @throws IOException in case of I/O error 60 */ 61 @BeforeClass 62 public static void beforeClass() throws IOException { 63 errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(TaggingPresetPreferenceTestIT.class)); 64 // Double traditional timeouts to avoid random problems 65 Config.getPref().putInt("socket.timeout.connect", 30); 66 Config.getPref().putInt("socket.timeout.read", 60); 67 // Make sure error messages are in english 68 Locale.setDefault(Locale.ENGLISH); 69 } 70 71 /** 72 * Returns list of tagging presets to test. 73 * @return list of tagging presets to test 74 * @throws Exception if an error occurs 75 */ 76 @Parameters(name = "{0} - {1}") 77 public static List<Object[]> data() throws Exception { 78 ImageProvider.clearCache(); 79 return new TaggingPresetPreference.TaggingPresetSourceEditor().loadAndGetAvailableSources().stream() 80 .map(x -> new Object[] {x.getDisplayName(), x.url, x}).collect(Collectors.toList()); 81 } 82 83 /** 84 * Constructs a new {@code TaggingPresetPreferenceTestIT} 85 * @param displayName displayed name 86 * @param url URL 87 * @param source source entry to test 88 */ 89 public TaggingPresetPreferenceTestIT(String displayName, String url, ExtendedSourceEntry source) { 90 this.source = source; 91 } 92 93 /** 94 * Test that tagging presets are valid. 45 95 * @throws Exception in case of error 46 96 */ 47 97 @Test 48 public void testValidityOfAvailablePresets() throws Exception { 49 ImageProvider.clearCache(); 50 Collection<ExtendedSourceEntry> sources = new TaggingPresetPreference.TaggingPresetSourceEditor() 51 .loadAndGetAvailableSources(); 52 assertFalse(sources.isEmpty()); 53 // Double traditional timeouts to avoid random problems 54 Config.getPref().putInt("socket.timeout.connect", 30); 55 Config.getPref().putInt("socket.timeout.read", 60); 56 Map<String, Throwable> allErrors = new HashMap<>(); 57 Map<String, Set<String>> allMessages = new HashMap<>(); 58 for (ExtendedSourceEntry source : sources) { 59 System.out.println(source.url); 98 public void testPresetsValidity() throws Exception { 99 Set<String> errors = new HashSet<>(); 100 try { 101 testPresets(errors, source); 102 } catch (IOException e) { 60 103 try { 61 testPresets(allMessages, source); 62 } catch (IOException e) { 63 try { 64 Logging.warn(e); 65 // try again in case of temporary network error 66 testPresets(allMessages, source); 67 } catch (SAXException | IOException e1) { 68 e.printStackTrace(); 69 // ignore frequent network errors with www.freietonne.de causing too much Jenkins failures 70 if (!source.url.contains("www.freietonne.de")) { 71 allErrors.put(source.url, e1); 72 } 73 System.out.println(" => KO"); 74 } 75 } catch (SAXException | IllegalArgumentException e) { 76 e.printStackTrace(); 77 if (!source.url.contains("yopaseopor/")) { 78 // ignore https://raw.githubusercontent.com/yopaseopor/traffic_signs_preset_JOSM cause too much errors 79 allErrors.put(source.url, e); 80 } 81 System.out.println(" => KO"); 104 Logging.warn(e); 105 // try again in case of temporary network error 106 testPresets(errors, source); 107 } catch (SAXException | IOException e1) { 108 handleException(e1, errors); 82 109 } 110 } catch (SAXException | IllegalArgumentException e) { 111 handleException(e, errors); 83 112 } 84 ImageProvider.clearCache(); 85 assertTrue(allErrors.toString(), allErrors.isEmpty()); 86 assertTrue(allMessages.toString(), allMessages.isEmpty()); 113 assertTrue(errors.toString(), errors.isEmpty()); 114 assumeTrue(ignoredErrors.toString(), ignoredErrors.isEmpty()); 87 115 } 88 116 89 private static void testPresets(Map<String, Set<String>> allMessages, ExtendedSourceEntry source) throws SAXException, IOException { 117 private void handleException(Exception e, Set<String> errors) { 118 e.printStackTrace(); 119 String s = source.url + " => " + e.toString(); 120 if (isIgnoredSubstring(s)) { 121 ignoredErrors.add(s); 122 } else { 123 errors.add(s); 124 } 125 } 126 127 private void testPresets(Set<String> messages, ExtendedSourceEntry source) throws SAXException, IOException { 90 128 Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true); 91 129 assertFalse(presets.isEmpty()); … … 103 141 if (message.contains(TaggingPreset.PRESET_ICON_ERROR_MSG_PREFIX)) { 104 142 error = true; 105 // ignore https://github.com/yopaseopor/traffic_signs_preset_JOSM because of far too frequent missing icons errors106 // ignore https://github.com/ruosm-presets because of frequent missing icons errors and no response107 if (!source.url.contains("yopaseopor/traffic_signs") && !source.url.contains("ruosm-presets/literan-moscow")){108 allMessages.computeIfAbsent(source.url, x -> new TreeSet<>()).add(message);143 if (isIgnoredSubstring(message)) { 144 ignoredErrors.add(message); 145 } else { 146 messages.add(message); 109 147 } 110 148 } 111 149 } 112 System.out.println(error ? " => KO" : " => OK");113 150 if (error) { 114 151 Logging.clearLastErrorAndWarnings(); 115 152 } 116 153 } 154 155 private static boolean isIgnoredSubstring(String substring) { 156 return errorsToIgnore.parallelStream().anyMatch(x -> substring.contains(x)); 157 } 117 158 } -
trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
r14380 r15095 45 45 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 46 46 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard; 47 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreferenceTestIT; 47 48 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 48 49 import org.openstreetmap.josm.gui.util.GuiHelper; … … 366 367 } 367 368 369 /** 370 * Must be called if test run with Junit parameters 371 * @return this instance, for easy chaining 372 */ 373 public JOSMTestRules parameters() { 374 try { 375 apply(new Statement() { 376 @Override 377 public void evaluate() throws Throwable { 378 // Do nothing. Hack needed because @Parameters are computed before anything else 379 } 380 }, Description.createSuiteDescription(ImageryPreferenceTestIT.class)).evaluate(); 381 } catch (Throwable e) { 382 Logging.error(e); 383 } 384 return this; 385 } 386 368 387 private static class MockVersion extends Version { 369 388 MockVersion(final String propertiesString) {
Note:
See TracChangeset
for help on using the changeset viewer.