From 8af1bed1d1b44713a935686deaab59cc0642d6ab Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Fri, 26 Jun 2009 07:58:59 +0000
Subject: [PATCH] [LMS-980] fixed download attachment test; minor added
 download attachment button

SVN: 11577
---
 .../client/web/client/application/Dict.java   |  4 +++-
 .../ui/attachment/AttachmentBrowser.java      | 24 ++++++++++++++++++-
 .../cisd/openbis/public/common-dictionary.js  |  1 +
 .../cisd/openbis/generic/SystemTestSuite.java |  4 ++--
 ...ntCmdTest.java => DownloadAttachment.java} | 12 ++++++----
 ...nericExperimentAttachmentDownloadTest.java |  2 +-
 6 files changed, 38 insertions(+), 9 deletions(-)
 rename openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/{ClickDownloadAttachmentCmdTest.java => DownloadAttachment.java} (80%)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java
index bfee8e13e4d..508652335af 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java
@@ -330,6 +330,8 @@ public abstract class Dict
 
     public static final String SHOW_ALL_VERSIONS = "show_all_versions";
 
+    public static final String BUTTON_DOWNLOAD = "button_download";
+
     public static final String BUTTON_SHOW_ALL_VERSIONS = "button_show_all_versions";
 
     public static final String NO_ATTACHMENTS_FOUND = "no_attachments_found";
@@ -579,7 +581,7 @@ public abstract class Dict
     public static final String TITLE_CHOOSE_EXPERIMENT = "TITLE_CHOOSE_EXPERIMENT";
 
     public static final String INCORRECT_EXPERIMENT_SYNTAX = "incorrect_experiment_syntax";
-    
+
     public static final String TITLE_CHOOSE_SAMPLE = "title_choose_sample";
 
     //
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java
index 7465668c3c9..b030e5b598d 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/attachment/AttachmentBrowser.java
@@ -90,7 +90,9 @@ public class AttachmentBrowser extends AbstractSimpleBrowserGrid<AttachmentVersi
 
     private static final String ID_PREFIX = GenericConstants.ID_PREFIX + PREFIX;
 
-    private IDelegatedAction postRegistrationCallback;
+    public static final String DOWNLOAD_BUTTON_ID_SUFFIX = "_download-button";
+
+    private final IDelegatedAction postRegistrationCallback;
 
     public static IDisposableComponent create(
             final IViewContext<ICommonClientServiceAsync> viewContext,
@@ -169,6 +171,12 @@ public class AttachmentBrowser extends AbstractSimpleBrowserGrid<AttachmentVersi
     {
         addEntityOperationsLabel();
 
+        String downloadTitle = viewContext.getMessage(Dict.BUTTON_DOWNLOAD);
+        Button downloadButton =
+                createSelectedItemButton(downloadTitle, asDownloadAttachmentInvoker());
+        downloadButton.setId(createBrowserId(attachmentHolder) + DOWNLOAD_BUTTON_ID_SUFFIX);
+        addButton(downloadButton);
+
         String showAllVersionsTitle = viewContext.getMessage(Dict.BUTTON_SHOW_ALL_VERSIONS);
         Button showAllVersionsButton =
                 createSelectedItemButton(showAllVersionsTitle, asShowEntityInvoker(false));
@@ -202,6 +210,20 @@ public class AttachmentBrowser extends AbstractSimpleBrowserGrid<AttachmentVersi
         addEntityOperationsSeparator();
     }
 
+    protected final ISelectedEntityInvoker<BaseEntityModel<AttachmentVersions>> asDownloadAttachmentInvoker()
+    {
+        return new ISelectedEntityInvoker<BaseEntityModel<AttachmentVersions>>()
+            {
+                public void invoke(BaseEntityModel<AttachmentVersions> selectedItem)
+                {
+                    AttachmentVersions versions = selectedItem.getBaseObject();
+                    final String fileName = versions.getCurrent().getFileName();
+                    final int version = versions.getCurrent().getVersion();
+                    downloadAttachment(fileName, version, attachmentHolder);
+                }
+            };
+    }
+
     private Window createEditAttachmentDialog(final AttachmentVersions versions)
     {
         final Attachment current = versions.getCurrent();
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js
index 6a9c012f22c..10ed80df450 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js
@@ -410,6 +410,7 @@ incorrect_experiment_syntax: "Incorrect experiment specification. Please provide
  version: "Version",
  show_all_versions: "show all versions",
  button_show_all_versions: "Show All Versions",
+ button_download: "Download",
  
 //
 // Grid Column Chooser
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/SystemTestSuite.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/SystemTestSuite.java
index 92aa4b79fd4..f1a528a3054 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/SystemTestSuite.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/SystemTestSuite.java
@@ -37,6 +37,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.SampleBrow
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.SearchTest;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.VocabularyBrowserTest;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.VocabularyRegistrationTest;
+import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.application.experiment.GenericExperimentAttachmentDownloadTest;
 import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.application.experiment.GenericExperimentEditorTest;
 import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.application.experiment.GenericExperimentViewerTest;
 import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.application.sample.GenericSampleRegistrationTest;
@@ -71,8 +72,7 @@ public class SystemTestSuite extends GWTTestSuite
         testSuite.addTestSuite(EntityTypePropertyTypeAssignmentTest.class);
         testSuite.addTestSuite(VocabularyRegistrationTest.class);
         testSuite.addTestSuite(PropertyTypeRegistrationTest.class);
-        // TODO 2009-06-24, Piotr Buczek: fix clicking on cell with anchor or add a download button
-        // testSuite.addTestSuite(GenericExperimentAttachmentDownloadTest.class);
+        testSuite.addTestSuite(GenericExperimentAttachmentDownloadTest.class);
         testSuite.addTestSuite(ProjectRegistrationTest.class);
         testSuite.addTestSuite(EntityTypeBrowserTest.class);
         return testSuite;
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ClickDownloadAttachmentCmdTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/DownloadAttachment.java
similarity index 80%
rename from openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ClickDownloadAttachmentCmdTest.java
rename to openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/DownloadAttachment.java
index 29b3de6b026..171ed8b0374 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ClickDownloadAttachmentCmdTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/DownloadAttachment.java
@@ -30,17 +30,17 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.GWTTestU
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 
 /**
- * Simulates clicking on the specified attachment in the experiment info window.
+ * Simulates downloading of the specified attachment in the experiment detail view.
  * 
  * @author Tomasz Pylak
  */
-public class ClickDownloadAttachmentCmdTest extends AbstractDefaultTestCommand
+public class DownloadAttachment extends AbstractDefaultTestCommand
 {
     private final String fileName;
 
     private final TechId experimentId;
 
-    public ClickDownloadAttachmentCmdTest(final String fileName, final TechId experimentId)
+    public DownloadAttachment(final String fileName, final TechId experimentId)
     {
         this.fileName = fileName;
         this.experimentId = experimentId;
@@ -56,6 +56,10 @@ public class ClickDownloadAttachmentCmdTest extends AbstractDefaultTestCommand
         final Widget widget = GWTTestUtil.getWidgetWithID(attachmentGridId);
         final Grid<BaseEntityModel<AttachmentVersions>> table =
                 (Grid<BaseEntityModel<AttachmentVersions>>) widget;
-        GridTestUtils.fireSingleClick(table, AttachmentColDefKind.FILE_NAME.id(), fileName);
+        GridTestUtils.fireSelectRow(table, AttachmentColDefKind.FILE_NAME.id(), fileName);
+        String downloadButtonId =
+                AttachmentBrowser.createBrowserId(experimentId, AttachmentHolderKind.EXPERIMENT)
+                        + AttachmentBrowser.DOWNLOAD_BUTTON_ID_SUFFIX;
+        GWTTestUtil.clickButtonWithID(downloadButtonId);
     }
 }
\ No newline at end of file
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/GenericExperimentAttachmentDownloadTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/GenericExperimentAttachmentDownloadTest.java
index 9c03d02edad..c4564f54b26 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/GenericExperimentAttachmentDownloadTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/GenericExperimentAttachmentDownloadTest.java
@@ -59,7 +59,7 @@ public class GenericExperimentAttachmentDownloadTest extends AbstractGWTTestCase
         //
         // Assumption: technicalId(CISD:/CISD/DEFAULT/EXP_REUSE) = 8
         //
-        remoteConsole.prepare(new ClickDownloadAttachmentCmdTest("cellPlates.txt", new TechId(8L)));
+        remoteConsole.prepare(new DownloadAttachment("cellPlates.txt", new TechId(8L)));
 
         // this callback will be used when the attempt to open an URL will occur
         OpenedUrlCallback openedUrlCallback = new OpenedUrlCallback(client.tryToGetViewContext());
-- 
GitLab