Skip to content

Commit

Permalink
Skip WIWOSM test if WIWOSM server is down
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Jul 30, 2024
1 parent 013124a commit 83715e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/org/wikipedia/WikipediaApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@

public final class WikipediaApp {

/** The base URL for <a href="https://wiki.openstreetmap.org/wiki/WIWOSM">WIWOSM</a> **/
public static final String WIWOSM_APP = "https://wiwosm.toolforge.org";

private static final XPath X_PATH = XPath.getInstance();

private static final String STRING_URI_PIPE = Utils.encodeUrl("|");
Expand Down Expand Up @@ -222,7 +225,7 @@ public void updateWIWOSMStatus(List<WikipediaEntry> entries) {
}
Map<String, Boolean> status = new HashMap<>();
if (!entries.isEmpty()) {
final String url = "https://wiwosm.toolforge.org/osmjson/getGeoJSON.php?action=check&lang=" + wikipediaLang;
final String url = WIWOSM_APP + "/osmjson/getGeoJSON.php?action=check&lang=" + wikipediaLang;
try {
final String articles = entries.stream().map(i -> i.article).collect(Collectors.joining(","));
final String requestBody = "articles=" + Utils.encodeUrl(articles);
Expand Down
26 changes: 26 additions & 0 deletions test/unit/org/wikipedia/WikipediaAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -21,14 +24,36 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.DisabledIf;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.testutils.annotations.I18n;
import org.openstreetmap.josm.tools.HttpClient;
import org.openstreetmap.josm.tools.Logging;
import org.wikipedia.data.WikidataEntry;
import org.wikipedia.data.WikipediaEntry;

@Timeout(20)
@I18n
class WikipediaAppTest {
private static Boolean wiwosmup;

static synchronized boolean isWiwosmDown() throws MalformedURLException {
if (wiwosmup == null) {
final HttpClient client = HttpClient.create(URI.create(WikipediaApp.WIWOSM_APP).toURL());
try {
final HttpClient.Response response = client.connect();
// We only care if there are server error responses, as far as whether the server is up.
wiwosmup = (response.getResponseCode() < 500);
} catch (IOException e) {
Logging.trace(e);
wiwosmup = false;
} finally {
client.disconnect();
}
}
return !wiwosmup;
}

@Test
void testMediawikiLocale() {
assertThat(WikipediaApp.getMediawikiLocale(Locale.GERMANY), is("de-de"));
Expand Down Expand Up @@ -154,6 +179,7 @@ void testGetLabelForWikidataInvalidId() {
assertThrows(RuntimeException.class, () -> WikipediaApp.getLabelForWikidata("Qxyz", Locale.ENGLISH));
}

@DisabledIf(value = "isWiwosmDown", disabledReason = "The WIWOSM server is down")
@Test
void testWIWOSMStatus() {
final WikipediaEntry entry1 = new WikipediaEntry("en", "Vienna");
Expand Down

0 comments on commit 83715e5

Please sign in to comment.