2121import java .io .ByteArrayOutputStream ;
2222import java .io .InputStream ;
2323import java .util .HashMap ;
24+ import java .util .regex .Matcher ;
25+ import java .util .regex .Pattern ;
2426
2527import org .hamcrest .collection .IsMapContaining ;
2628
@@ -43,7 +45,8 @@ public class AccessIT {
4345 public static String apiToken ;
4446 public static String dataverseAlias ;
4547 public static Integer datasetId ;
46-
48+ public static String persistentId ;
49+
4750 public static Integer basicFileId ;
4851 public static Integer tabFile1Id ;
4952 public static Integer tabFile2Id ;
@@ -78,7 +81,6 @@ public class AccessIT {
7881 private static String testFileFromZipUploadWithFoldersChecksum1 = "8f326944be21361ad8219bc3269bc9eb" ;
7982 private static String testFileFromZipUploadWithFoldersChecksum2 = "0fe4efd85229bad6e587fd3f1a6c8e05" ;
8083 private static String testFileFromZipUploadWithFoldersChecksum3 = "00433ccb20111f9d40f0e5ab6fa8396f" ;
81-
8284
8385 @ BeforeAll
8486 public static void setUp () throws InterruptedException {
@@ -101,6 +103,7 @@ public static void setUp() throws InterruptedException {
101103 Response createDatasetResponse = UtilIT .createDatasetViaNativeApi (dataverseAlias , pathToJsonFile , apiToken );
102104 createDatasetResponse .prettyPrint ();
103105 datasetId = JsonPath .from (createDatasetResponse .body ().asString ()).getInt ("data.id" );
106+ persistentId = JsonPath .from (createDatasetResponse .body ().asString ()).getString ("data.persistentId" );
104107
105108 Response allowAccessRequests = UtilIT .allowAccessRequests (datasetId .toString (), true , apiToken );
106109 allowAccessRequests .prettyPrint ();
@@ -285,7 +288,27 @@ public void testDownloadMultipleFiles_NonLoggedInOpen() throws IOException {
285288 assertThat (files2 , IsMapContaining .hasKey (tabFile2NameConvert ));
286289
287290 System .out .println ("origSize: " + origSizeAnon + " | convertSize: " + convertSizeAnon );
288- assertThat (origSizeAnon , is (not (convertSizeAnon )));
291+ assertThat (origSizeAnon , is (not (convertSizeAnon )));
292+
293+ // Finally, verify that the multi-file bundle produced by the API
294+ // is properly named (as of v6.7 this should be a pretty name based on
295+ // the persistent Id of the dataset).
296+
297+ String contentDispositionHeader = anonDownloadConverted .getHeader ("Content-disposition" );
298+ System .out .println ("Response header: " +contentDispositionHeader );
299+
300+ Pattern regexPattern = Pattern .compile ("attachment; filename=\" ([a-z0-9\\ .-]*\\ .zip)\" " );
301+ Matcher regexMatcher = regexPattern .matcher (contentDispositionHeader );
302+ boolean regexMatch = regexMatcher .find ();
303+ assertTrue (regexMatch );
304+
305+ String expectedPrettyName = persistentId .replaceAll ("[:/]" , "-" ).toLowerCase () + ".zip" ;
306+ System .out .println ("expected \" pretty\" file name of the zipped multi-file bundle: " + expectedPrettyName );
307+
308+ String fileBundleName = regexMatcher .group (1 );
309+ System .out .println ("file name found in the header: " +fileBundleName );
310+
311+ assertEquals (fileBundleName , expectedPrettyName );
289312 }
290313
291314 @ Test
0 commit comments