Skip to content

Commit ee92e27

Browse files
committed
test Zipped OME-Zarr requirements
1 parent 5b74372 commit ee92e27

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

src/test/java/dev/zarr/zarrjava/ZarrStoreTest.java

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.IOException;
2121
import java.nio.file.Files;
22+
import java.util.ArrayList;
2223
import java.util.Arrays;
2324
import java.util.Collections;
2425
import java.util.stream.Stream;
@@ -193,49 +194,54 @@ public void testZipStoreWithComment() throws ZarrException, IOException {
193194
/**
194195
* Test that ZipStore meets requirements for underlying store of Zipped OME-Zarr
195196
* @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."
203197
*/
204198
@Test
205199
public void testZipStoreRequirements() throws ZarrException, IOException {
206200
Path path = TESTOUTPUT.resolve("testZipStoreRequirements.zip");
207201
BufferedZipStore zipStore = new BufferedZipStore(path);
208-
writeTestGroupV3(zipStore, true);
209-
zipStore.flush();
210202

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();
220218

221219
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) {
234224
Assertions.assertEquals(ZipEntry.STORED, e.getMethod(), "Entry " + e.getName() + " is compressed");
235225
}
236-
}
237-
238226

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+
}
239245
}
240246

241247
static Stream<Store> localStores() {

0 commit comments

Comments
 (0)