Skip to content

Commit 3211d39

Browse files
committed
testZarrJsonFormat
1 parent 3005f2e commit 3211d39

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.zarr.zarrjava;
22

3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
35
import dev.zarr.zarrjava.v3.codec.Codec;
46
import dev.zarr.zarrjava.v3.codec.core.BloscCodec;
57
import dev.zarr.zarrjava.v3.codec.core.ShardingIndexedCodec;
@@ -30,6 +32,7 @@
3032
import java.util.HashMap;
3133
import java.util.Map;
3234
import java.util.function.Function;
35+
import java.util.stream.Collectors;
3336
import java.util.stream.Stream;
3437

3538
import static dev.zarr.zarrjava.core.ArrayMetadata.parseFillValue;
@@ -549,6 +552,23 @@ public void testCreateArray() throws ZarrException, IOException {
549552
Assertions.assertTrue(Files.exists(Paths.get(storeHandleString).resolve("zarr.json")));
550553
}
551554

555+
@Test
556+
public void testZarrJsonFormat() throws ZarrException, IOException {
557+
// regression test: ensure that 'name' keyword of named configurations (e.g. codecs) are only written once.
558+
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testZarrJsonFormatV3");
559+
Array.create(storeHandle, Array.metadataBuilder()
560+
.withShape(10, 10)
561+
.withDataType(DataType.UINT8)
562+
.withChunkShape(5, 5)
563+
.build());
564+
565+
try (BufferedReader reader = Files.newBufferedReader(storeHandle.resolve("zarr.json").toPath())) {
566+
String jsonInString = reader.lines().collect(Collectors.joining(System.lineSeparator()));
567+
JsonNode JSON = new ObjectMapper().readTree(jsonInString);
568+
Assertions.assertEquals(JSON.toPrettyString(), jsonInString);
569+
}
570+
}
571+
552572
@Test
553573
public void testCreateGroup() throws ZarrException, IOException {
554574
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testCreateGroupV3");
@@ -585,5 +605,12 @@ public void testCodecWithoutConfiguration() throws ZarrException, IOException {
585605
Assertions.assertInstanceOf(BytesCodec.class, bytesCodec);
586606
Assertions.assertNull(((BytesCodec) bytesCodec).configuration);
587607
// further todo: remove redundant "name" attribute from codec metadata serialization
608+
}
609+
610+
@Test
611+
public void testParseZarrJson(){
612+
613+
614+
588615
}
589616
}

0 commit comments

Comments
 (0)