@@ -158,4 +158,46 @@ void TestWithFileWithLocationAddEntity(@TempDir Path temp) throws IOException {
158
158
assertFalse (HelpFunctions .compareTwoDir (locationSource .toFile (), destinationDir .toFile ()));
159
159
HelpFunctions .compareTwoMetadataJsonNotEqual (roCrate , res );
160
160
}
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
+ }
161
203
}
0 commit comments