source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/AbstractExtendedSourceEntryTestCase.java@ 17288

Last change on this file since 17288 was 17288, checked in by Don-vip, 3 years ago

see #16567 - fix integration tests

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.map;
3
4import java.util.ArrayList;
5import java.util.Collection;
6import java.util.List;
7import java.util.Set;
8import java.util.regex.Matcher;
9import java.util.regex.Pattern;
10import java.util.stream.Collectors;
11
12import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
13
14abstract class AbstractExtendedSourceEntryTestCase {
15
16 private static final Pattern RESOURCE_PATTERN = Pattern.compile("resource://(.+)");
17 private static final Pattern JOSM_WIKI_PATTERN = Pattern.compile("https://josm.openstreetmap.de/josmfile\\?page=(.+)&zip=1");
18 private static final Pattern GITHUB_PATTERN = Pattern.compile("https://raw.githubusercontent.com/([^/]+)/([^/]+)/([^/]+)/(.+)");
19
20 protected static final List<String> errorsToIgnore = new ArrayList<>();
21
22 protected static List<Object[]> getTestParameters(Collection<ExtendedSourceEntry> entries) throws Exception {
23 return entries.stream().map(x -> new Object[] {x.getDisplayName(), cleanUrl(x.url), x}).collect(Collectors.toList());
24 }
25
26 private static String cleanUrl(String url) {
27 Matcher wiki = JOSM_WIKI_PATTERN.matcher(url);
28 if (wiki.matches()) {
29 return "https://josm.openstreetmap.de/wiki/" + wiki.group(1);
30 }
31 Matcher github = GITHUB_PATTERN.matcher(url);
32 if (github.matches()) {
33 return String.format("https://github.com/%s/%s/blob/%s/%s", github.group(1), github.group(2), github.group(3), github.group(4));
34 }
35 Matcher resource = RESOURCE_PATTERN.matcher(url);
36 if (resource.matches()) {
37 return "https://josm.openstreetmap.de/browser/trunk/" + resource.group(1);
38 }
39 return url;
40 }
41
42 protected final void handleException(ExtendedSourceEntry source, Exception e, Set<String> errors, List<String> ignoredErrors) {
43 e.printStackTrace();
44 String s = source.url + " => " + e.toString();
45 if (isIgnoredSubstring(source, s)) {
46 ignoredErrors.add(s);
47 } else {
48 errors.add(s);
49 }
50 }
51
52 protected boolean isIgnoredSubstring(ExtendedSourceEntry source, String substring) {
53 return errorsToIgnore.parallelStream().anyMatch(x -> substring.contains(x) || source.url.contains(x));
54 }
55}
Note: See TracBrowser for help on using the repository browser.