From a56f61368d63792d28e967dfdba2b1f1252c1371 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Thu, 19 May 2011 16:21:43 +0000
Subject: [PATCH] [LMS-2104] cleaned up DataSetDownloadServlet tests

SVN: 21397
---
 .../server/DatasetDownloadServletTest.java    | 80 +++++++------------
 1 file changed, 27 insertions(+), 53 deletions(-)

diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java
index 4f1feed2ac4..2c349d9b4e5 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java
@@ -204,10 +204,9 @@ public class DatasetDownloadServletTest
         final StringWriter writer = new StringWriter();
         final ExternalData externalData = createExternalData();
         prepareParseRequestURL();
-        prepareCheckDatasetAccess();
         prepareForObtainingDataSetFromServer(externalData);
-        prepareLocking();
         prepareForGettingDataSetFromSession(externalData, "");
+        prepareLocking();
         prepareForCreatingHTML(writer);
 
         DatasetDownloadServlet servlet = createServlet();
@@ -241,12 +240,8 @@ public class DatasetDownloadServletTest
                         + OSUtilities.LINE_SEPARATOR + "", writer.toString());
 
         String normalizedLogContent = getNormalizedLogContent();
-        // assertContains(getSessionCreationLogMessage() + OSUtilities.LINE_SEPARATOR + LOG_INFO
-        // + "Data set '1234-1' obtained from openBIS server.", normalizedLogContent);
-        // FIXME
-        // assertContains(getSessionCreationLogMessage() + OSUtilities.LINE_SEPARATOR + LOG_INFO
-        // + "Check access to the data set '1234-1' at openBIS server.", normalizedLogContent);
-        assertContains(LOG_INFO + "For data set '1234-1' show directory '/'", normalizedLogContent);
+        assertContains(getSessionCreationLogMessage() + OSUtilities.LINE_SEPARATOR + LOG_INFO
+                + "For data set '1234-1' show directory '/'", normalizedLogContent);
 
         context.assertIsSatisfied();
     }
@@ -358,8 +353,8 @@ public class DatasetDownloadServletTest
     {
         final StringWriter writer = new StringWriter();
         final ExternalData externalData = createExternalData();
-        prepareCheckDatasetAccess();
         prepareForObtainingDataSetFromServer(externalData);
+        prepareForGettingDataSetFromSession(externalData, ESCAPED_EXAMPLE_DATA_SET_SUB_FOLDER_NAME);
         prepareLocking();
         context.checking(new Expectations()
             {
@@ -368,9 +363,6 @@ public class DatasetDownloadServletTest
 
                     allowing(request).getSession(false);
                     will(returnValue(httpSession));
-
-                    prepareForGettingDataSetFromSession(this, externalData,
-                            ESCAPED_EXAMPLE_DATA_SET_SUB_FOLDER_NAME);
                 }
             });
         prepareForCreatingHTML(writer);
@@ -397,7 +389,7 @@ public class DatasetDownloadServletTest
 
         final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         prepareParseRequestURL();
-        prepareFullCheckDatasetAccess();
+        prepareCheckDatasetAccess();
         prepareForObtainingDataSetFromServer(externalData);
         prepareLocking();
 
@@ -442,7 +434,7 @@ public class DatasetDownloadServletTest
         ImageIO.write(image, "png", EXAMPLE_FILE);
         prepareParseRequestURLForThumbnail(100, 50);
         final ExternalData externalData = createExternalData();
-        prepareFullCheckDatasetAccess();
+        prepareCheckDatasetAccess();
         prepareForObtainingDataSetFromServer(externalData);
         prepareLocking();
         final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@@ -601,31 +593,30 @@ public class DatasetDownloadServletTest
         context.checking(new Expectations()
             {
                 {
-                    prepareForGettingDataSetFromSession(this, externalData, path);
+                    Map<String, Boolean> accessMap = new HashMap<String, Boolean>();
+                    checkAndSetAttribute(this, DatasetDownloadServlet.DATA_SET_ACCESS_SESSION_KEY,
+                            accessMap);
+
+                    one(httpSession).getAttribute(DatasetDownloadServlet.DATA_SET_SESSION_KEY);
+                    Map<String, ExternalData> map = new HashMap<String, ExternalData>();
+                    map.put(externalData.getCode(), externalData);
+                    will(Expectations.returnValue(map));
+
+                    prepareGetRequestURI(this, externalData, path);
+
+                    oneOf(response).setHeader("Pragma", "no-cache");
+                    oneOf(response).setHeader("Cache-control",
+                            "no-cache, no-store, must-revalidate");
+                    allowing(response).setDateHeader(with(Expectations.any(String.class)),
+                            with(Expectations.any(long.class)));
+                    // oneOf(response).addDateHeader(with("Date"),
+                    // with(Expectations.any(long.class)));
+                    // oneOf(response).addDateHeader(with("Expires"),
+                    // with(Expectations.any(long.class))); }
                 }
             });
     }
 
-    private void prepareForGettingDataSetFromSession(Expectations exp,
-            final ExternalData externalData, final String path)
-    {
-        exp.one(httpSession).getAttribute(DatasetDownloadServlet.DATA_SET_SESSION_KEY);
-        Map<String, ExternalData> map = new HashMap<String, ExternalData>();
-        map.put(externalData.getCode(), externalData);
-        exp.will(Expectations.returnValue(map));
-
-        prepareGetRequestURI(exp, externalData, path);
-
-        exp.oneOf(response).setHeader("Pragma", "no-cache");
-        exp.oneOf(response).setHeader("Cache-control", "no-cache, no-store, must-revalidate");
-        exp.allowing(response).setDateHeader(exp.with(Expectations.any(String.class)),
-                exp.with(Expectations.any(long.class)));
-        // exp.oneOf(response).addDateHeader(exp.with("Date"),
-        // exp.with(Expectations.any(long.class)));
-        // exp.oneOf(response).addDateHeader(exp.with("Expires"),
-        // exp.with(Expectations.any(long.class)));
-    }
-
     private void prepareGetRequestURI(Expectations exp, final ExternalData externalData,
             final String path)
     {
@@ -719,10 +710,6 @@ public class DatasetDownloadServletTest
         context.checking(new Expectations()
             {
                 {
-                    // FIXME temporary
-                    // HashMap<String, ExternalDataPE> map = new HashMap<String, ExternalDataPE>();
-                    // checkAndSetAttribute(this, DatasetDownloadServlet.DATA_SET_SESSION_KEY, map);
-
                     one(openbisService).tryGetDataSet(EXAMPLE_DATA_SET_CODE);
                     will(returnValue(externalData));
                 }
@@ -740,7 +727,7 @@ public class DatasetDownloadServletTest
             });
     }
 
-    private void prepareFullCheckDatasetAccess()
+    private void prepareCheckDatasetAccess()
     {
         context.checking(new Expectations()
             {
@@ -761,19 +748,6 @@ public class DatasetDownloadServletTest
             });
     }
 
-    private void prepareCheckDatasetAccess()
-    {
-        context.checking(new Expectations()
-            {
-                {
-                    // FIXME
-                    Map<String, Boolean> map = new HashMap<String, Boolean>();
-                    checkAndSetAttribute(this, DatasetDownloadServlet.DATA_SET_ACCESS_SESSION_KEY,
-                            map);
-                }
-            });
-    }
-
     private void checkAndSetAttribute(Expectations exp, String attributeKey, Object newValue)
     {
         getSessionAttribute(exp, attributeKey, null);
-- 
GitLab