Skip to content

Commit

Permalink
create github tool test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Dec 26, 2024
1 parent 10d0301 commit 80a5f05
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/eol/globi/service/GitHubUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.lang3.tuple.Pair;
import org.globalbioticinteractions.dataset.Dataset;
Expand Down Expand Up @@ -42,7 +42,7 @@ public static URI getGitHubAPIEndpoint(String path, String query) throws URISynt

private static boolean hasInteractionData(URI gloBIConfigURI, ResourceService resourceService) throws IOException {
try (InputStream is = resourceService.retrieve(gloBIConfigURI)) {
IOUtils.copy(is, NullOutputStream.NULL_OUTPUT_STREAM);
IOUtils.copy(is, NullOutputStream.INSTANCE);
return true;
} catch (Throwable th) {
return false;
Expand Down
34 changes: 26 additions & 8 deletions src/test/java/org/eol/globi/service/GitHubUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
package org.eol.globi.service;

import org.eol.globi.util.InputStreamFactoryNoop;
import org.eol.globi.util.ResourceServiceHTTP;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
import java.util.TreeMap;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class GitHubUtilTest {

@Rule

public TemporaryFolder folder = new TemporaryFolder();

@Test
public void isGloBIRepo() throws IOException {
String repo = GitHubUtilIT.TEMPLATE_DATA_REPOSITORY_TSV;

ResourceService resourceService = getResourceService();

String lastCommitSHA = GitHubUtil.lastCommitSHA(
repo,
resourceService
);

assertThat(GitHubUtil.isGloBIRepository(repo,
lastCommitSHA,
resourceService),
is(true));
assertThat(
GitHubUtil.isGloBIRepository(repo, lastCommitSHA, resourceService),
is(true)
);
}

@Test
public void nonGloBIRepo() throws IOException {
String repo = "ropensci/rgbif";

ResourceService resourceService = getResourceService();

String lastCommitSHA = GitHubUtil.lastCommitSHA(
Expand All @@ -47,7 +51,21 @@ public void nonGloBIRepo() throws IOException {
}

private ResourceService getResourceService() throws IOException {
return new ResourceServiceHTTP(new InputStreamFactoryNoop(), folder.newFolder());


Map<String, String> lookup = new TreeMap<String, String>() {{
put("https://raw.githubusercontent.com/globalbioticinteractions/template-dataset/b92cd44dcba945c760229a14d3b9becb2dd0c147/globi.json", "template-dataset-globi.json");
put("https://github.com/globalbioticinteractions/template-dataset/info/refs?service=git-upload-pack", "template-dataset-git-upload-pack.bin");
put("https://github.com/ropensci/rgbif/info/refs?service=git-upload-pack", "ropensci-rgbif-git-upload-pack.bin");
}};

return new ResourceService() {
@Override
public InputStream retrieve(URI uri) throws IOException {
String resourceName = lookup.get(uri.toString());
return getClass().getResourceAsStream(resourceName);
}
};
}

}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"_comment": "Sample GloBI dataset descriptor. See http://github.com/globalbioticinteractions for more information.",
"citation": "Jorrit H. Poelen. 2014. Species associations manually extracted from literature.",
"deprecated": false
}

0 comments on commit 80a5f05

Please sign in to comment.