Skip to content

Commit 3f51510

Browse files
committed
test: all writers write decoded ids as filenames
1 parent 14d9f10 commit 3f51510

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/test/java/edu/kit/datamanager/ro_crate/writer/CommonWriterTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import edu.kit.datamanager.ro_crate.RoCrate;
55
import edu.kit.datamanager.ro_crate.entities.data.DataSetEntity;
66

7+
import edu.kit.datamanager.ro_crate.entities.data.FileEntity;
78
import org.apache.commons.io.FileUtils;
89
import org.junit.jupiter.api.Test;
910
import org.junit.jupiter.api.io.TempDir;
@@ -34,6 +35,7 @@ default void testFilesBeingAdjusted(@TempDir Path tempDir) throws IOException {
3435

3536
Path writtenCrate = tempDir.resolve("written-crate");
3637
Path extractionPath = tempDir.resolve("checkMe");
38+
String id = "id will be encoded";
3739
{
3840
RoCrate builtCrate = getCrateWithFileAndDir(pathToFile, pathToDir)
3941
.addDataEntity(new DataSetEntity.DataSetBuilder()
@@ -43,6 +45,11 @@ default void testFilesBeingAdjusted(@TempDir Path tempDir) throws IOException {
4345
.setId("lots_of_little_files/subdir-renamed/")
4446
.build()
4547
)
48+
.addDataEntity(new FileEntity.FileEntityBuilder()
49+
.setId(id)
50+
.setLocation(pathToFile)
51+
.build()
52+
)
4653
.build();
4754
this.saveCrate(builtCrate, writtenCrate);
4855
ensureCrateIsExtractedIn(writtenCrate, extractionPath);
@@ -51,6 +58,12 @@ default void testFilesBeingAdjusted(@TempDir Path tempDir) throws IOException {
5158
HelpFunctions.printFileTree(correctCrate);
5259
HelpFunctions.printFileTree(extractionPath);
5360

61+
// Ensure the file uses the id, not the encoded id as a file name
62+
assertTrue(
63+
Files.exists(extractionPath.resolve(id)),
64+
"The file '%s' should exist, because this is the ID of the entity".formatted(id)
65+
);
66+
5467
// The actual file name should **not** appear in the crate
5568
String fileName = pathToFile.getFileName().toString();
5669
assertFalse(

0 commit comments

Comments
 (0)