Skip to content

Commit 72393a9

Browse files
committed
Refactor ZarrV2 and ZarrV3 tests to improve readability and structure; add new tests for array and group creation
1 parent fbdccd0 commit 72393a9

File tree

5 files changed

+427
-382
lines changed

5 files changed

+427
-382
lines changed

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

Lines changed: 0 additions & 261 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package dev.zarr.zarrjava;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import dev.zarr.zarrjava.store.FilesystemStore;
5+
import dev.zarr.zarrjava.store.HttpStore;
6+
import dev.zarr.zarrjava.store.S3Store;
7+
import dev.zarr.zarrjava.v3.*;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Test;
10+
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
11+
import software.amazon.awssdk.regions.Region;
12+
import software.amazon.awssdk.services.s3.S3Client;
13+
14+
import java.io.IOException;
15+
import java.nio.file.Files;
16+
17+
import static dev.zarr.zarrjava.v3.Node.makeObjectMapper;
18+
19+
public class ZarrStoreTest extends ZarrTest {
20+
@Test
21+
public void testFileSystemStores() throws IOException, ZarrException {
22+
FilesystemStore fsStore = new FilesystemStore(TESTDATA);
23+
ObjectMapper objectMapper = makeObjectMapper();
24+
25+
GroupMetadata groupMetadata = objectMapper.readValue(
26+
Files.readAllBytes(TESTDATA.resolve("l4_sample").resolve("zarr.json")),
27+
GroupMetadata.class
28+
);
29+
30+
String groupMetadataString = objectMapper.writeValueAsString(groupMetadata);
31+
Assertions.assertTrue(groupMetadataString.contains("\"zarr_format\":3"));
32+
Assertions.assertTrue(groupMetadataString.contains("\"node_type\":\"group\""));
33+
34+
ArrayMetadata arrayMetadata = objectMapper.readValue(Files.readAllBytes(TESTDATA.resolve(
35+
"l4_sample").resolve("color").resolve("1").resolve("zarr.json")),
36+
ArrayMetadata.class);
37+
38+
String arrayMetadataString = objectMapper.writeValueAsString(arrayMetadata);
39+
Assertions.assertTrue(arrayMetadataString.contains("\"zarr_format\":3"));
40+
Assertions.assertTrue(arrayMetadataString.contains("\"node_type\":\"array\""));
41+
Assertions.assertTrue(arrayMetadataString.contains("\"shape\":[1,4096,4096,2048]"));
42+
43+
Assertions.assertInstanceOf(Array.class, Array.open(fsStore.resolve("l4_sample", "color", "1")));
44+
45+
Node[] subNodes = Group.open(fsStore.resolve("l4_sample")).list().toArray(Node[]::new);
46+
Assertions.assertEquals(2, subNodes.length);
47+
Assertions.assertInstanceOf(Group.class, subNodes[0]);
48+
49+
Array[] colorSubNodes = ((Group) Group.open(fsStore.resolve("l4_sample")).get("color")).list().toArray(Array[]::new);
50+
51+
Assertions.assertEquals(5, colorSubNodes.length);
52+
Assertions.assertInstanceOf(Array.class, colorSubNodes[0]);
53+
54+
Array array = (Array) ((Group) Group.open(fsStore.resolve("l4_sample")).get("color")).get("1");
55+
Assertions.assertArrayEquals(new long[]{1, 4096, 4096, 2048}, array.metadata.shape);
56+
}
57+
58+
@Test
59+
public void testS3Store() throws IOException, ZarrException {
60+
S3Store s3Store = new S3Store(S3Client.builder()
61+
.region(Region.of("eu-west-1"))
62+
.credentialsProvider(AnonymousCredentialsProvider.create())
63+
.build(), "static.webknossos.org", "data");
64+
Array array = Array.open(s3Store.resolve("zarr_v3", "l4_sample", "color", "1"));
65+
66+
Assertions.assertArrayEquals(new long[]{1, 4096, 4096, 2048}, array.metadata.shape);
67+
}
68+
69+
@Test
70+
public void testHttpStore() throws IOException, ZarrException {
71+
HttpStore httpStore = new dev.zarr.zarrjava.store.HttpStore("https://static.webknossos.org/data/zarr_v3/l4_sample");
72+
Array array = Array.open(httpStore.resolve("color", "1"));
73+
74+
Assertions.assertArrayEquals(new long[]{1, 4096, 4096, 2048}, array.metadata.shape);
75+
}
76+
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package dev.zarr.zarrjava;
22

3-
import dev.zarr.zarrjava.store.S3Store;
4-
import dev.zarr.zarrjava.v3.Array;
53
import org.junit.jupiter.api.BeforeAll;
6-
import org.junit.jupiter.api.Test;
74

85
import java.io.File;
96
import java.io.IOException;
@@ -15,18 +12,22 @@
1512

1613
public class ZarrTest {
1714

18-
final static Path TESTDATA = Paths.get("testdata");
19-
final static Path TESTOUTPUT = Paths.get("testoutput");
15+
public static final Path TESTDATA = Paths.get("testdata");
16+
public static final Path TESTOUTPUT = Paths.get("testoutput");
2017

2118
@BeforeAll
2219
public static void clearTestoutputFolder() throws IOException {
2320
if (Files.exists(TESTOUTPUT)) {
2421
try (Stream<Path> walk = Files.walk(TESTOUTPUT)) {
25-
walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
22+
walk.sorted(Comparator.reverseOrder())
23+
.map(Path::toFile)
24+
.forEach(file -> {
25+
if (!file.delete()) {
26+
throw new RuntimeException("Failed to delete file: " + file.getAbsolutePath());
27+
}
28+
});
2629
}
2730
}
2831
Files.createDirectory(TESTOUTPUT);
2932
}
30-
31-
3233
}

0 commit comments

Comments
 (0)