Skip to content

Commit 0c05b21

Browse files
committed
test: reading zipped crates with custom extraction paths
1 parent 4a2aa9b commit 0c05b21

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/test/java/edu/kit/datamanager/ro_crate/reader/ZipReaderTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,46 @@ void TestWithFileWithLocationAddEntity(@TempDir Path temp) throws IOException {
158158
assertFalse(HelpFunctions.compareTwoDir(locationSource.toFile(), destinationDir.toFile()));
159159
HelpFunctions.compareTwoMetadataJsonNotEqual(roCrate, res);
160160
}
161+
162+
@Test
163+
void testReadingBasicCrateWithCustomPath(@TempDir Path temp) throws IOException {
164+
RoCrate roCrate = new RoCrate.RoCrateBuilder(
165+
"minimal",
166+
"minimal RO_crate",
167+
"2024",
168+
"https://creativecommons.org/licenses/by-nc-sa/3.0/au/")
169+
.build();
170+
171+
Path zipPath = temp.resolve("result.zip");
172+
173+
RoCrateWriter roCrateZipWriter = new RoCrateWriter(new ZipWriter());
174+
roCrateZipWriter.save(roCrate, zipPath.toString());
175+
176+
File zipFile = zipPath.toFile();
177+
assertTrue(zipFile.isFile());
178+
179+
Path differentFolder = temp.resolve("differentFolder");
180+
ZipReader readerType = new ZipReader(differentFolder, true);
181+
assertFalse(readerType.isExtracted());
182+
assertEquals(readerType.getTemporaryFolder().getFileName().toString(), readerType.getID());
183+
assertTrue(readerType.getTemporaryFolder().startsWith(differentFolder));
184+
185+
RoCrateReader roCrateFolderReader = new RoCrateReader(readerType);
186+
Crate crate = roCrateFolderReader.readCrate(zipFile.getAbsolutePath());
187+
assertTrue(readerType.isExtracted());
188+
HelpFunctions.compareTwoCrateJson(roCrate, crate);
189+
190+
{
191+
// try it again without the UUID subfolder and test if the directory is being cleaned up (using coverage).
192+
ZipReader newReaderType = new ZipReader(differentFolder, false);
193+
assertFalse(newReaderType.isExtracted());
194+
assertNotEquals(newReaderType.getTemporaryFolder().getFileName().toString(), newReaderType.getID());
195+
assertTrue(newReaderType.getTemporaryFolder().startsWith(differentFolder));
196+
197+
RoCrateReader newRoCrateFolderReader = new RoCrateReader(newReaderType);
198+
Crate crate2 = newRoCrateFolderReader.readCrate(zipFile.getAbsolutePath());
199+
assertTrue(newReaderType.isExtracted());
200+
HelpFunctions.compareTwoCrateJson(roCrate, crate2);
201+
}
202+
}
161203
}

0 commit comments

Comments
 (0)