From 86f03e7ae3ff81695cb1f7d95f299f4085eae266 Mon Sep 17 00:00:00 2001 From: Jorrit Poelen Date: Fri, 29 Sep 2023 06:16:16 -0500 Subject: [PATCH] add testcase to help reproduce https://github.com/globalbioticinteractions/globalbioticinteractions/issues/923#issuecomment-1740698215 ; fyi @tkuhn --- .../elton/cmd/CmdUpdateIT.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/globalbioticinteractions/elton/cmd/CmdUpdateIT.java b/src/test/java/org/globalbioticinteractions/elton/cmd/CmdUpdateIT.java index ebd091e..6e9f104 100644 --- a/src/test/java/org/globalbioticinteractions/elton/cmd/CmdUpdateIT.java +++ b/src/test/java/org/globalbioticinteractions/elton/cmd/CmdUpdateIT.java @@ -20,7 +20,7 @@ public class CmdUpdateIT { @Rule - private TemporaryFolder tmpDir = new TemporaryFolder(); + public TemporaryFolder tmpDir = new TemporaryFolder(); @Test @@ -51,6 +51,34 @@ public void runUpdate() throws IOException { assertThat("number of cached files should not have changed after update", numberOfCacheFiles, is(getNumberOfCacheFiles())); } + @Test + public void updateKnowledgePixels() throws IOException { + + CmdUpdate cmd = new CmdUpdate(); + File file1 = tmpDir.newFolder(); + String absolutePath = file1.getAbsolutePath(); + cmd.setCacheDir(absolutePath); + cmd.setNamespaces(Collections.singletonList("globalbioticinteractions/knowledgepixels")); + + cmd.run(); + + File file = new File(file1,"globalbioticinteractions/knowledgepixels/access.tsv"); + assertThat(file.exists(), is(true)); + String[] jarUrls = FileUtils.readFileToString(file, StandardCharsets.UTF_8).split("jar:file:"); + assertTrue(jarUrls.length > 1); + String localJarUrl = jarUrls[1].split("\t")[0]; + assertNotNull(new URL("jar:file:" + localJarUrl).openStream()); + + int numberOfLogEntries = getNumberOfLogEntries(); + assertThat(getNumberOfLogEntries() > 3, is(true)); + int numberOfCacheFiles = getNumberOfCacheFiles(); + + // rerun + cmd.run(); + assertThat("should update regardless or preexisting entries in cache", getNumberOfLogEntries() + 3 > numberOfLogEntries, is(true)); + assertThat("number of cached files should not have changed after update", numberOfCacheFiles, is(getNumberOfCacheFiles())); + } + private int getNumberOfCacheFiles() { return FileUtils.listFiles(new File(getDatasetCacheDir()), null, false).size(); }