33import com .fasterxml .jackson .databind .ObjectMapper ;
44import dev .zarr .zarrjava .core .Attributes ;
55import dev .zarr .zarrjava .store .*;
6- import dev .zarr .zarrjava .v3 .*;
6+ import dev .zarr .zarrjava .core .*;
77import org .apache .commons .compress .archivers .zip .*;
88
99import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
@@ -39,7 +39,7 @@ public void testFileSystemStores() throws IOException, ZarrException {
3939
4040 GroupMetadata groupMetadata = objectMapper .readValue (
4141 Files .readAllBytes (TESTDATA .resolve ("l4_sample" ).resolve ("zarr.json" )),
42- GroupMetadata .class
42+ dev . zarr . zarrjava . v3 . GroupMetadata .class
4343 );
4444
4545 String groupMetadataString = objectMapper .writeValueAsString (groupMetadata );
@@ -48,7 +48,7 @@ public void testFileSystemStores() throws IOException, ZarrException {
4848
4949 ArrayMetadata arrayMetadata = objectMapper .readValue (Files .readAllBytes (TESTDATA .resolve (
5050 "l4_sample" ).resolve ("color" ).resolve ("1" ).resolve ("zarr.json" )),
51- ArrayMetadata .class );
51+ dev . zarr . zarrjava . v3 . ArrayMetadata .class );
5252
5353 String arrayMetadataString = objectMapper .writeValueAsString (arrayMetadata );
5454 Assertions .assertTrue (arrayMetadataString .contains ("\" zarr_format\" :3" ));
@@ -100,10 +100,10 @@ public void testMemoryStoreV3(boolean useParallel) throws ZarrException, IOExcep
100100 int [] testData = new int [1024 * 1024 ];
101101 Arrays .setAll (testData , p -> p );
102102
103- Group group = Group .create (new MemoryStore ().resolve ());
103+ dev . zarr . zarrjava . v3 . Group group = dev . zarr . zarrjava . v3 . Group .create (new MemoryStore ().resolve ());
104104 Array array = group .createArray ("array" , b -> b
105105 .withShape (1024 , 1024 )
106- .withDataType (DataType .UINT32 )
106+ .withDataType (dev . zarr . zarrjava . v3 . DataType .UINT32 )
107107 .withChunkShape (5 , 5 )
108108 );
109109 array .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1024 , 1024 }, testData ), useParallel );
@@ -200,15 +200,15 @@ public void testZipStoreRequirements() throws ZarrException, IOException {
200200 Path path = TESTOUTPUT .resolve ("testZipStoreRequirements.zip" );
201201 BufferedZipStore zipStore = new BufferedZipStore (path );
202202
203- Group group = Group .create (zipStore .resolve ());
203+ dev . zarr . zarrjava . v3 . Group group = dev . zarr . zarrjava . v3 . Group .create (zipStore .resolve ());
204204 Array array = group .createArray ("a1" , b -> b
205205 .withShape (1024 , 1024 )
206- .withDataType (DataType .UINT32 )
206+ .withDataType (dev . zarr . zarrjava . v3 . DataType .UINT32 )
207207 .withChunkShape (512 , 512 )
208208 );
209209 array .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1024 , 1024 }, testData ()), true );
210210
211- Group g1 = group .createGroup ("g1" );
211+ dev . zarr . zarrjava . v3 . Group g1 = group .createGroup ("g1" );
212212 g1 .createGroup ("g1_1" ).createGroup ("g1_1_1" );
213213 g1 .createGroup ("g1_2" );
214214 group .createGroup ("g2" ).createGroup ("g2_1" );
@@ -245,6 +245,25 @@ public void testZipStoreRequirements() throws ZarrException, IOException {
245245 }
246246 }
247247
248+
249+ @ Test
250+ public void testZipStoreV2 () throws ZarrException , IOException {
251+ Path path = TESTOUTPUT .resolve ("testZipStoreV2.zip" );
252+ BufferedZipStore zipStore = new BufferedZipStore (path );
253+ writeTestGroupV2 (zipStore , true );
254+ zipStore .flush ();
255+
256+ BufferedZipStore zipStoreRead = new BufferedZipStore (path );
257+ assertIsTestGroupV2 (dev .zarr .zarrjava .core .Group .open (zipStoreRead .resolve ()), true );
258+
259+ Path unzippedPath = TESTOUTPUT .resolve ("testZipStoreV2Unzipped" );
260+
261+ unzipFile (path , unzippedPath );
262+ FilesystemStore fsStore = new FilesystemStore (unzippedPath );
263+ assertIsTestGroupV2 (dev .zarr .zarrjava .core .Group .open (fsStore .resolve ()), true );
264+ }
265+
266+
248267 static Stream <Store > localStores () {
249268 return Stream .of (
250269 new MemoryStore (),
@@ -261,6 +280,7 @@ public void testLocalStores(Store store) throws IOException, ZarrException {
261280 assertIsTestGroupV3 (group , useParallel );
262281 }
263282
283+
264284 int [] testData (){
265285 int [] testData = new int [1024 * 1024 ];
266286 Arrays .setAll (testData , p -> p );
@@ -270,10 +290,10 @@ int[] testData(){
270290 Group writeTestGroupV3 (Store store , boolean useParallel ) throws ZarrException , IOException {
271291 StoreHandle storeHandle = store .resolve ();
272292
273- Group group = Group .create (storeHandle );
274- Array array = group .createArray ("array" , b -> b
293+ dev . zarr . zarrjava . v3 . Group group = dev . zarr . zarrjava . v3 . Group .create (storeHandle );
294+ dev . zarr . zarrjava . v3 . Array array = group .createArray ("array" , b -> b
275295 .withShape (1024 , 1024 )
276- .withDataType (DataType .UINT32 )
296+ .withDataType (dev . zarr . zarrjava . v3 . DataType .UINT32 )
277297 .withChunkShape (512 , 512 )
278298 );
279299 array .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1024 , 1024 }, testData ()), useParallel );
@@ -289,7 +309,35 @@ void assertIsTestGroupV3(Group group, boolean useParallel) throws ZarrException,
289309 Assertions .assertNotNull (array );
290310 ucar .ma2 .Array result = array .read (useParallel );
291311 Assertions .assertArrayEquals (testData (), (int []) result .get1DJavaArray (ucar .ma2 .DataType .UINT ));
292- Attributes attrs = group .metadata ().attributes ;
312+ Attributes attrs = group .metadata ().attributes ();
313+ Assertions .assertNotNull (attrs );
314+ Assertions .assertEquals ("value" , attrs .getString ("some" ));
315+ }
316+
317+
318+ dev .zarr .zarrjava .v2 .Group writeTestGroupV2 (Store store , boolean useParallel ) throws ZarrException , IOException {
319+ StoreHandle storeHandle = store .resolve ();
320+
321+ dev .zarr .zarrjava .v2 .Group group = dev .zarr .zarrjava .v2 .Group .create (storeHandle );
322+ dev .zarr .zarrjava .v2 .Array array = group .createArray ("array" , b -> b
323+ .withShape (1024 , 1024 )
324+ .withDataType (dev .zarr .zarrjava .v2 .DataType .UINT32 )
325+ .withChunks (512 , 512 )
326+ );
327+ array .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1024 , 1024 }, testData ()), useParallel );
328+ group .createGroup ("subgroup" );
329+ group .setAttributes (new Attributes ().set ("some" , "value" ));
330+ return group ;
331+ }
332+
333+ void assertIsTestGroupV2 (dev .zarr .zarrjava .core .Group group , boolean useParallel ) throws ZarrException , IOException {
334+ Stream <dev .zarr .zarrjava .core .Node > nodes = group .list ();
335+ Assertions .assertEquals (2 , nodes .count ());
336+ dev .zarr .zarrjava .v2 .Array array = (dev .zarr .zarrjava .v2 .Array ) group .get ("array" );
337+ Assertions .assertNotNull (array );
338+ ucar .ma2 .Array result = array .read (useParallel );
339+ Assertions .assertArrayEquals (testData (), (int []) result .get1DJavaArray (ucar .ma2 .DataType .UINT ));
340+ Attributes attrs = group .metadata ().attributes ();
293341 Assertions .assertNotNull (attrs );
294342 Assertions .assertEquals ("value" , attrs .getString ("some" ));
295343 }
0 commit comments