From 0fee7457a6d1c99904cd9aa08c7f4cb7f67d1d76 Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Thu, 21 Feb 2013 09:56:45 +0000
Subject: [PATCH] BIS-329 SP-500 : Added test of URL-retrieving method that
 limits validity duration.

SVN: 28403
---
 .../api/v1/DssServiceRpcGenericLogger.java    |  4 +-
 .../JsonDssServiceRpcGenericTest.java         | 40 +++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/DssServiceRpcGenericLogger.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/DssServiceRpcGenericLogger.java
index 5e0f726bc9a..e3a27c4f221 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/DssServiceRpcGenericLogger.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/api/v1/DssServiceRpcGenericLogger.java
@@ -230,7 +230,7 @@ public class DssServiceRpcGenericLogger extends AbstractServerLogger implements
             throws IOExceptionUnchecked, IllegalArgumentException
     {
         logAccess(sessionToken, "get_download_url_for_file_for_data_set",
-                "DATA_SET(%s) PATH(%s) VALIDITY(%i)", dataSetCode, path, validityDurationInSeconds);
+                "DATA_SET(%s) PATH(%s) VALIDITY(%s)", dataSetCode, path, validityDurationInSeconds);
         return null;
     }
 
@@ -242,7 +242,7 @@ public class DssServiceRpcGenericLogger extends AbstractServerLogger implements
             long validityDurationInSeconds) throws IOExceptionUnchecked, IllegalArgumentException
     {
         logAccess(sessionToken, "get_download_url_for_file_for_data_set",
-                "DATA_SET(%s) VALIDITY(%i)", fileOrFolder, validityDurationInSeconds);
+                "DATA_SET(%s) VALIDITY(%s)", fileOrFolder, validityDurationInSeconds);
         return null;
     }
 }
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/JsonDssServiceRpcGenericTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/JsonDssServiceRpcGenericTest.java
index b7fa01c5a57..66b43f03644 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/JsonDssServiceRpcGenericTest.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/JsonDssServiceRpcGenericTest.java
@@ -17,12 +17,15 @@
 package ch.systemsx.cisd.openbis.datastoreserver.systemtests;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.HashMap;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -30,6 +33,7 @@ import org.testng.annotations.Test;
 import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
 import com.googlecode.jsonrpc4j.ProxyUtil;
 
+import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.DataSetFileDTO;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.FileInfoDssDTO;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric;
 import ch.systemsx.cisd.openbis.generic.shared.api.json.GenericObjectMapper;
@@ -91,7 +95,43 @@ public class JsonDssServiceRpcGenericTest extends SystemTestCase
         {
             System.out.println(fileInfo);
         }
+    }
+
+    @Test
+    public void testGetDataSetContentsWithURL() throws MalformedURLException, IOException
+    {
+
+        FileInfoDssDTO[] result =
+                dssRpcService.listFilesForDataSet(sessionToken, "20081105092159111-1", "", true);
+        assertTrue("Did not find any files for the data set 20081105092159111-1", result.length > 0);
+
+        FileInfoDssDTO fileInfoToDownload = null;
+        for (FileInfoDssDTO fileInfo : result)
+        {
+            if (false == fileInfo.isDirectory())
+            {
+                fileInfoToDownload = fileInfo;
+                break;
+            }
+        }
 
+        assertNotNull("Could not find a file in the data set 20081105092159111-1 to download",
+                fileInfoToDownload);
+
+        @SuppressWarnings("null")
+        DataSetFileDTO fileToDownload =
+                new DataSetFileDTO("20081105092159111-1", fileInfoToDownload.getPathInDataSet(),
+                        false);
+        String url =
+                dssRpcService.getDownloadUrlForFileForDataSetWithTimeout(sessionToken,
+                        fileToDownload, -1);
+
+        // Download the data into a file
+        InputStream input = new URL(url).openStream();
+        File file = new File(workingDirectory, "output");
+        FileOutputStream output = new FileOutputStream(file);
+        IOUtils.copyLarge(input, output);
+        assertEquals(file.length(), fileInfoToDownload.getFileSize());
     }
 
     public static IGeneralInformationService createOpenbisService()
-- 
GitLab