|
19 | 19 |
|
20 | 20 | import java.io.IOException; |
21 | 21 | import java.nio.file.Files; |
| 22 | +import java.util.ArrayList; |
22 | 23 | import java.util.Arrays; |
23 | 24 | import java.util.Collections; |
24 | 25 | import java.util.stream.Stream; |
@@ -193,49 +194,54 @@ public void testZipStoreWithComment() throws ZarrException, IOException { |
193 | 194 | /** |
194 | 195 | * Test that ZipStore meets requirements for underlying store of Zipped OME-Zarr |
195 | 196 | * @see <a href="https://ngff.openmicroscopy.org/rfc/9/index.html">RFC-9: Zipped OME-Zarr</a> |
196 | | - * |
197 | | - * Features to test: |
198 | | - * - ZIP64 format |
199 | | - * - No ZIP-level compression |
200 | | - * - Option to add archive comments in the ZIP file header |
201 | | - * - Prohibit nested or multi-part ZIP archives |
202 | | - * - "The root-level zarr.json file SHOULD be the first ZIP file entry and the first entry in the central directory header; other zarr.json files SHOULD follow immediately afterwards, in breadth-first order." |
203 | 197 | */ |
204 | 198 | @Test |
205 | 199 | public void testZipStoreRequirements() throws ZarrException, IOException { |
206 | 200 | Path path = TESTOUTPUT.resolve("testZipStoreRequirements.zip"); |
207 | 201 | BufferedZipStore zipStore = new BufferedZipStore(path); |
208 | | - writeTestGroupV3(zipStore, true); |
209 | | - zipStore.flush(); |
210 | 202 |
|
211 | | - // test for ZIP64 |
212 | | -// List<FileHeader> fileHeaders = new ZipFile(path.toFile()).getFileHeaders(); |
213 | | -// |
214 | | -// HeaderReader headerReader = new HeaderReader(); |
215 | | -// ZipModel zipModel = headerReader.readAllHeaders(new RandomAccessFile(generatedZipFile, |
216 | | -// RandomAccessFileMode.READ.getValue()), buildDefaultConfig()); |
217 | | -// assertThat(zipModel.getZip64EndOfCentralDirectoryLocator()).isNotNull(); |
218 | | -// assertThat(zipModel.getZip64EndOfCentralDirectoryRecord()).isNotNull(); |
219 | | -// assertThat(zipModel.isZip64Format()).isTrue(); |
| 203 | + Group group = Group.create(zipStore.resolve()); |
| 204 | + Array array = group.createArray("a1", b -> b |
| 205 | + .withShape(1024, 1024) |
| 206 | + .withDataType(DataType.UINT32) |
| 207 | + .withChunkShape(512, 512) |
| 208 | + ); |
| 209 | + array.write(ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{1024, 1024}, testData()), true); |
| 210 | + |
| 211 | + Group g1 = group.createGroup("g1"); |
| 212 | + g1.createGroup("g1_1").createGroup("g1_1_1"); |
| 213 | + g1.createGroup("g1_2"); |
| 214 | + group.createGroup("g2").createGroup("g2_1"); |
| 215 | + group.createGroup("g3"); |
| 216 | + |
| 217 | + zipStore.flush(); |
220 | 218 |
|
221 | 219 | try (ZipFile zip = new ZipFile(path.toFile())) { |
222 | | - for (ZipArchiveEntry e : Collections.list(zip.getEntries())) { |
223 | | - System.out.println(e.getName()); |
224 | | - ZipExtraField[] extraFields = e.getExtraFields(); |
225 | | - System.out.println(extraFields.length); |
226 | | - Assertions.assertNotNull(extraFields, "Entry " + e.getName() + " has no extra fields"); |
227 | | - Assertions.assertTrue(Arrays.stream(extraFields).anyMatch(xf -> xf instanceof Zip64ExtendedInformationExtraField), |
228 | | - "Entry " + e.getName() + " is missing ZIP64 extra field"); |
229 | | - } |
230 | | - } |
231 | | - // no compression |
232 | | - try (ZipFile zip = new ZipFile(path.toFile())) { |
233 | | - for (ZipArchiveEntry e : Collections.list(zip.getEntries())) { |
| 220 | + ArrayList<ZipArchiveEntry> entries = Collections.list(zip.getEntries()); |
| 221 | + |
| 222 | + // no compression |
| 223 | + for (ZipArchiveEntry e : entries) { |
234 | 224 | Assertions.assertEquals(ZipEntry.STORED, e.getMethod(), "Entry " + e.getName() + " is compressed"); |
235 | 225 | } |
236 | | - } |
237 | | - |
238 | 226 |
|
| 227 | + // correct order of zarr.json files |
| 228 | + String[] expectedZarrJsonOrder = new String[]{ |
| 229 | + "zarr.json", |
| 230 | + "a1/zarr.json", |
| 231 | + "g1/zarr.json", |
| 232 | + "g2/zarr.json", |
| 233 | + "g3/zarr.json", |
| 234 | + "g1/g1_1/zarr.json", |
| 235 | + "g1/g1_2/zarr.json", |
| 236 | + "g2/g2_1/zarr.json", |
| 237 | + "g1/g1_1/g1_1_1/zarr.json" |
| 238 | + }; |
| 239 | + String[] actualZarrJsonOrder = entries.stream() |
| 240 | + .map(ZipArchiveEntry::getName) |
| 241 | + .limit(expectedZarrJsonOrder.length) |
| 242 | + .toArray(String[]::new); |
| 243 | + Assertions.assertArrayEquals(expectedZarrJsonOrder, actualZarrJsonOrder, "zarr.json files are not in the expected breadth-first order"); |
| 244 | + } |
239 | 245 | } |
240 | 246 |
|
241 | 247 | static Stream<Store> localStores() { |
|
0 commit comments