Changeset 17288 in josm for trunk/test/unit/org
- Timestamp:
- 2020-10-31T01:21:14+01:00 (4 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/AbstractExtendedSourceEntryTestCase.java
r15100 r17288 20 20 protected static final List<String> errorsToIgnore = new ArrayList<>(); 21 21 22 /** Entry to test */23 protected final ExtendedSourceEntry source;24 protected final List<String> ignoredErrors = new ArrayList<>();25 26 protected AbstractExtendedSourceEntryTestCase(ExtendedSourceEntry source) {27 this.source = source;28 }29 30 22 protected static List<Object[]> getTestParameters(Collection<ExtendedSourceEntry> entries) throws Exception { 31 23 return entries.stream().map(x -> new Object[] {x.getDisplayName(), cleanUrl(x.url), x}).collect(Collectors.toList()); … … 48 40 } 49 41 50 protected final void handleException(Ex ception e, Set<String> errors) {42 protected final void handleException(ExtendedSourceEntry source, Exception e, Set<String> errors, List<String> ignoredErrors) { 51 43 e.printStackTrace(); 52 44 String s = source.url + " => " + e.toString(); 53 if (isIgnoredSubstring(s )) {45 if (isIgnoredSubstring(source, s)) { 54 46 ignoredErrors.add(s); 55 47 } else { … … 58 50 } 59 51 60 protected boolean isIgnoredSubstring( String substring) {52 protected boolean isIgnoredSubstring(ExtendedSourceEntry source, String substring) { 61 53 return errorsToIgnore.parallelStream().anyMatch(x -> substring.contains(x) || source.url.contains(x)); 62 54 } -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java
r17275 r17288 10 10 import java.util.List; 11 11 12 import org.junit.ClassRule;13 12 import org.junit.jupiter.api.BeforeAll; 14 import org.junit.jupiter.api. Test;15 import org.junit. runner.RunWith;16 import org.junit. runners.Parameterized.Parameters;13 import org.junit.jupiter.api.extension.RegisterExtension; 14 import org.junit.jupiter.params.ParameterizedTest; 15 import org.junit.jupiter.params.provider.MethodSource; 17 16 import org.openstreetmap.josm.TestUtils; 18 17 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry; … … 26 25 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 27 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 28 import org.openstreetmap.josm.testutils.ParallelParameterized;29 27 import org.openstreetmap.josm.tools.ImageProvider; 30 28 … … 34 32 * Integration tests of {@link MapPaintPreference} class. 35 33 */ 36 @RunWith(ParallelParameterized.class)37 34 class MapPaintPreferenceTestIT extends AbstractExtendedSourceEntryTestCase { 38 35 … … 40 37 * Setup rule 41 38 */ 42 @ ClassRule39 @RegisterExtension 43 40 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 44 41 public static JOSMTestRules test = new JOSMTestRules().https().timeout(15000*60).parameters(); … … 58 55 * @throws Exception if an error occurs 59 56 */ 60 @Parameters(name = "{0} - {1}")61 57 public static List<Object[]> data() throws Exception { 62 58 ImageProvider.clearCache(); … … 65 61 66 62 /** 67 * Constructs a new {@code MapPaintPreferenceTestIT}63 * Test that map paint style is valid. 68 64 * @param displayName displayed name 69 65 * @param url URL 70 66 * @param source source entry to test 71 */72 MapPaintPreferenceTestIT(String displayName, String url, ExtendedSourceEntry source) {73 super(source);74 }75 76 /**77 * Test that map paint style is valid.78 67 * @throws Exception in case of error 79 68 */ 80 @Test 81 void testStyleValidity() throws Exception { 82 assumeFalse(isIgnoredSubstring(source.url)); 69 @ParameterizedTest(name = "{0} - {1}") 70 @MethodSource("data") 71 void testStyleValidity(String displayName, String url, ExtendedSourceEntry source) throws Exception { 72 assumeFalse(isIgnoredSubstring(source, source.url)); 83 73 StyleSource style = MapPaintStyles.addStyle(source); 84 74 if (style instanceof MapCSSStyleSource) { … … 100 90 } 101 91 92 List<String> ignoredErrors = new ArrayList<>(); 102 93 List<Throwable> errors = new ArrayList<>(style.getErrors()); 103 errors.stream().map(Throwable::getMessage).filter( this::isIgnoredSubstring).forEach(ignoredErrors::add);94 errors.stream().map(Throwable::getMessage).filter(s -> isIgnoredSubstring(source, s)).forEach(ignoredErrors::add); 104 95 errors.removeIf(e -> ignoredErrors.contains(e.getMessage())); 105 96 106 97 List<String> warnings = new ArrayList<>(style.getWarnings()); 107 warnings.stream().filter( this::isIgnoredSubstring).forEach(ignoredErrors::add);98 warnings.stream().filter(s -> isIgnoredSubstring(source, s)).forEach(ignoredErrors::add); 108 99 warnings.removeAll(ignoredErrors); 109 100 -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java
r17275 r17288 9 9 import java.io.IOException; 10 10 import java.net.URL; 11 import java.util.ArrayList; 11 12 import java.util.Collection; 12 13 import java.util.HashSet; … … 15 16 import java.util.Set; 16 17 17 import org.junit.ClassRule;18 18 import org.junit.jupiter.api.BeforeAll; 19 import org.junit.jupiter.api.Test; 20 import org.junit.runner.RunWith; 21 import org.junit.runners.Parameterized; 22 import org.junit.runners.Parameterized.Parameters; 19 import org.junit.jupiter.api.extension.RegisterExtension; 20 import org.junit.jupiter.params.ParameterizedTest; 21 import org.junit.jupiter.params.provider.MethodSource; 23 22 import org.openstreetmap.josm.TestUtils; 24 23 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry; … … 40 39 * Integration tests of {@link TaggingPresetPreference} class. 41 40 */ 42 @RunWith(Parameterized.class)43 41 class TaggingPresetPreferenceTestIT extends AbstractExtendedSourceEntryTestCase { 44 42 … … 46 44 * Setup rule 47 45 */ 48 @ ClassRule46 @RegisterExtension 49 47 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 50 48 public static JOSMTestRules test = new JOSMTestRules().https().timeout(10000*120).parameters(); … … 69 67 * @throws Exception if an error occurs 70 68 */ 71 @Parameters(name = "{0} - {1}")72 69 public static List<Object[]> data() throws Exception { 73 70 ImageProvider.clearCache(); … … 76 73 77 74 /** 78 * Constructs a new {@code TaggingPresetPreferenceTestIT}75 * Test that tagging presets are valid. 79 76 * @param displayName displayed name 80 77 * @param url URL 81 78 * @param source source entry to test 82 */83 TaggingPresetPreferenceTestIT(String displayName, String url, ExtendedSourceEntry source) {84 super(source);85 }86 87 /**88 * Test that tagging presets are valid.89 79 * @throws Exception in case of error 90 80 */ 91 @Test 92 void testPresetsValidity() throws Exception { 93 assumeFalse(isIgnoredSubstring(source.url)); 81 @ParameterizedTest(name = "{0} - {1}") 82 @MethodSource("data") 83 void testPresetsValidity(String displayName, String url, ExtendedSourceEntry source) throws Exception { 84 assumeFalse(isIgnoredSubstring(source, source.url)); 85 List<String> ignoredErrors = new ArrayList<>(); 94 86 Set<String> errors = new HashSet<>(); 95 87 try { 96 testPresets(errors, source );88 testPresets(errors, source, ignoredErrors); 97 89 } catch (IOException e) { 98 90 try { 99 91 Logging.warn(e); 100 92 // try again in case of temporary network error 101 testPresets(errors, source );93 testPresets(errors, source, ignoredErrors); 102 94 } catch (SAXException | IOException e1) { 103 handleException( e1, errors);95 handleException(source, e1, errors, ignoredErrors); 104 96 } 105 97 } catch (SAXException | IllegalArgumentException e) { 106 handleException( e, errors);98 handleException(source, e, errors, ignoredErrors); 107 99 } 108 100 assertTrue(errors.isEmpty(), errors::toString); … … 110 102 } 111 103 112 private void testPresets(Set<String> messages, ExtendedSourceEntry source) throws SAXException, IOException { 104 private void testPresets(Set<String> messages, ExtendedSourceEntry source, List<String> ignoredErrors) 105 throws SAXException, IOException { 113 106 Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true); 114 107 assertFalse(presets.isEmpty()); … … 120 113 final int code = cr.getResponseCode(); 121 114 if (HttpClient.isRedirect(code)) { 122 addOrIgnoreError(messages, "Found HTTP redirection for " + u + " -> " + code + " -> " + cr.getHeaderField("Location")); 115 addOrIgnoreError(source, messages, 116 "Found HTTP redirection for " + u + " -> " + code + " -> " + cr.getHeaderField("Location"), ignoredErrors); 123 117 } else if (code >= 400) { 124 addOrIgnoreError( messages, "Found HTTP error for " + u + " -> " + code);118 addOrIgnoreError(source, messages, "Found HTTP error for " + u + " -> " + code, ignoredErrors); 125 119 } 126 120 } catch (IOException e) { … … 133 127 if (message.contains(TaggingPreset.PRESET_ICON_ERROR_MSG_PREFIX)) { 134 128 error = true; 135 addOrIgnoreError( messages, message);129 addOrIgnoreError(source, messages, message, ignoredErrors); 136 130 } 137 131 } … … 141 135 } 142 136 143 void addOrIgnoreError( Set<String> messages, String message) {144 if (isIgnoredSubstring( message)) {137 void addOrIgnoreError(ExtendedSourceEntry source, Set<String> messages, String message, List<String> ignoredErrors) { 138 if (isIgnoredSubstring(source, message)) { 145 139 ignoredErrors.add(message); 146 140 } else { -
trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTestIT.java
r17275 r17288 21 21 import java.util.stream.Collectors; 22 22 23 import org.junit.ClassRule;24 23 import org.junit.jupiter.api.BeforeAll; 25 24 import org.junit.jupiter.api.Test; 25 import org.junit.jupiter.api.extension.RegisterExtension; 26 26 import org.openstreetmap.josm.TestUtils; 27 27 import org.openstreetmap.josm.data.Preferences; … … 49 49 * Setup test. 50 50 */ 51 @ ClassRule51 @RegisterExtension 52 52 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 53 53 public static JOSMTestRules test = new JOSMTestRules().main().projection().preferences().https()
Note:
See TracChangeset
for help on using the changeset viewer.