Changeset 17288 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2020-10-31T01:21:14+01:00 (4 years ago)
Author:
Don-vip
Message:

see #16567 - fix integration tests

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  
    2020    protected static final List<String> errorsToIgnore = new ArrayList<>();
    2121
    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 
    3022    protected static List<Object[]> getTestParameters(Collection<ExtendedSourceEntry> entries) throws Exception {
    3123        return entries.stream().map(x -> new Object[] {x.getDisplayName(), cleanUrl(x.url), x}).collect(Collectors.toList());
     
    4840    }
    4941
    50     protected final void handleException(Exception e, Set<String> errors) {
     42    protected final void handleException(ExtendedSourceEntry source, Exception e, Set<String> errors, List<String> ignoredErrors) {
    5143        e.printStackTrace();
    5244        String s = source.url + " => " + e.toString();
    53         if (isIgnoredSubstring(s)) {
     45        if (isIgnoredSubstring(source, s)) {
    5446            ignoredErrors.add(s);
    5547        } else {
     
    5850    }
    5951
    60     protected boolean isIgnoredSubstring(String substring) {
     52    protected boolean isIgnoredSubstring(ExtendedSourceEntry source, String substring) {
    6153        return errorsToIgnore.parallelStream().anyMatch(x -> substring.contains(x) || source.url.contains(x));
    6254    }
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java

    r17275 r17288  
    1010import java.util.List;
    1111
    12 import org.junit.ClassRule;
    1312import 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;
     13import org.junit.jupiter.api.extension.RegisterExtension;
     14import org.junit.jupiter.params.ParameterizedTest;
     15import org.junit.jupiter.params.provider.MethodSource;
    1716import org.openstreetmap.josm.TestUtils;
    1817import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
     
    2625import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    2726import org.openstreetmap.josm.testutils.JOSMTestRules;
    28 import org.openstreetmap.josm.testutils.ParallelParameterized;
    2927import org.openstreetmap.josm.tools.ImageProvider;
    3028
     
    3432 * Integration tests of {@link MapPaintPreference} class.
    3533 */
    36 @RunWith(ParallelParameterized.class)
    3734class MapPaintPreferenceTestIT extends AbstractExtendedSourceEntryTestCase {
    3835
     
    4037     * Setup rule
    4138     */
    42     @ClassRule
     39    @RegisterExtension
    4340    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    4441    public static JOSMTestRules test = new JOSMTestRules().https().timeout(15000*60).parameters();
     
    5855     * @throws Exception if an error occurs
    5956     */
    60     @Parameters(name = "{0} - {1}")
    6157    public static List<Object[]> data() throws Exception {
    6258        ImageProvider.clearCache();
     
    6561
    6662    /**
    67      * Constructs a new {@code MapPaintPreferenceTestIT}
     63     * Test that map paint style is valid.
    6864     * @param displayName displayed name
    6965     * @param url URL
    7066     * @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.
    7867     * @throws Exception in case of error
    7968     */
    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));
    8373        StyleSource style = MapPaintStyles.addStyle(source);
    8474        if (style instanceof MapCSSStyleSource) {
     
    10090        }
    10191
     92        List<String> ignoredErrors = new ArrayList<>();
    10293        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);
    10495        errors.removeIf(e -> ignoredErrors.contains(e.getMessage()));
    10596
    10697        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);
    10899        warnings.removeAll(ignoredErrors);
    109100
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java

    r17275 r17288  
    99import java.io.IOException;
    1010import java.net.URL;
     11import java.util.ArrayList;
    1112import java.util.Collection;
    1213import java.util.HashSet;
     
    1516import java.util.Set;
    1617
    17 import org.junit.ClassRule;
    1818import 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;
     19import org.junit.jupiter.api.extension.RegisterExtension;
     20import org.junit.jupiter.params.ParameterizedTest;
     21import org.junit.jupiter.params.provider.MethodSource;
    2322import org.openstreetmap.josm.TestUtils;
    2423import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
     
    4039 * Integration tests of {@link TaggingPresetPreference} class.
    4140 */
    42 @RunWith(Parameterized.class)
    4341class TaggingPresetPreferenceTestIT extends AbstractExtendedSourceEntryTestCase {
    4442
     
    4644     * Setup rule
    4745     */
    48     @ClassRule
     46    @RegisterExtension
    4947    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    5048    public static JOSMTestRules test = new JOSMTestRules().https().timeout(10000*120).parameters();
     
    6967     * @throws Exception if an error occurs
    7068     */
    71     @Parameters(name = "{0} - {1}")
    7269    public static List<Object[]> data() throws Exception {
    7370        ImageProvider.clearCache();
     
    7673
    7774    /**
    78      * Constructs a new {@code TaggingPresetPreferenceTestIT}
     75     * Test that tagging presets are valid.
    7976     * @param displayName displayed name
    8077     * @param url URL
    8178     * @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.
    8979     * @throws Exception in case of error
    9080     */
    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<>();
    9486        Set<String> errors = new HashSet<>();
    9587        try {
    96             testPresets(errors, source);
     88            testPresets(errors, source, ignoredErrors);
    9789        } catch (IOException e) {
    9890            try {
    9991                Logging.warn(e);
    10092                // try again in case of temporary network error
    101                 testPresets(errors, source);
     93                testPresets(errors, source, ignoredErrors);
    10294            } catch (SAXException | IOException e1) {
    103                 handleException(e1, errors);
     95                handleException(source, e1, errors, ignoredErrors);
    10496            }
    10597        } catch (SAXException | IllegalArgumentException e) {
    106             handleException(e, errors);
     98            handleException(source, e, errors, ignoredErrors);
    10799        }
    108100        assertTrue(errors.isEmpty(), errors::toString);
     
    110102    }
    111103
    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 {
    113106        Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true);
    114107        assertFalse(presets.isEmpty());
     
    120113                final int code = cr.getResponseCode();
    121114                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);
    123117                } else if (code >= 400) {
    124                     addOrIgnoreError(messages, "Found HTTP error for " + u + " -> " + code);
     118                    addOrIgnoreError(source, messages, "Found HTTP error for " + u + " -> " + code, ignoredErrors);
    125119                }
    126120            } catch (IOException e) {
     
    133127            if (message.contains(TaggingPreset.PRESET_ICON_ERROR_MSG_PREFIX)) {
    134128                error = true;
    135                 addOrIgnoreError(messages, message);
     129                addOrIgnoreError(source, messages, message, ignoredErrors);
    136130            }
    137131        }
     
    141135    }
    142136
    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)) {
    145139            ignoredErrors.add(message);
    146140        } else {
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTestIT.java

    r17275 r17288  
    2121import java.util.stream.Collectors;
    2222
    23 import org.junit.ClassRule;
    2423import org.junit.jupiter.api.BeforeAll;
    2524import org.junit.jupiter.api.Test;
     25import org.junit.jupiter.api.extension.RegisterExtension;
    2626import org.openstreetmap.josm.TestUtils;
    2727import org.openstreetmap.josm.data.Preferences;
     
    4949     * Setup test.
    5050     */
    51     @ClassRule
     51    @RegisterExtension
    5252    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    5353    public static JOSMTestRules test = new JOSMTestRules().main().projection().preferences().https()
Note: See TracChangeset for help on using the changeset viewer.