From 4a78c425a1a02e7a1ccf122e5aa3833a48d6fd8d Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Wed, 24 Nov 2010 08:06:19 +0000
Subject: [PATCH] LMS-1888 tests written

SVN: 18891
---
 .../server/DssServiceRpcScreeningTest.java    | 41 +++++++++++--
 .../v1/ScreeningOpenbisServiceFacadeTest.java | 58 ++++++++++++++++++-
 2 files changed, 93 insertions(+), 6 deletions(-)

diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreeningTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreeningTest.java
index f6891d279b8..5a80fab3c06 100644
--- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreeningTest.java
+++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreeningTest.java
@@ -67,6 +67,7 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVector
 import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.IDatasetIdentifier;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.IFeatureVectorDatasetIdentifier;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageSize;
+import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.PlateImageReference;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellPosition;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.PlateImageParameters;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ScreeningConstants;
@@ -102,6 +103,8 @@ public class DssServiceRpcScreeningTest extends AssertJUnit
     
     private static final String EXPERIMENT_PERM_ID = "exp-123";
 
+    private static final String URL1 = "url1";
+    
     private static final String SESSION_TOKEN = "session";
 
     private Mockery context;
@@ -179,6 +182,25 @@ public class DssServiceRpcScreeningTest extends AssertJUnit
         // Otherwise one do not known which test failed.
         context.assertIsSatisfied();
     }
+    
+    @Test
+    public void testListPlateImageReferences()
+    {
+        final DatasetIdentifier ds = new DatasetIdentifier("ds1", URL1);
+        final List<WellPosition> wellPositions = Arrays.asList(new WellPosition(1, 3));
+        final String channel = "dapi";
+        prepareGetHomeDatabaseInstance();
+
+        List<PlateImageReference> plateImageReferences =
+                screeningService
+                        .listPlateImageReferences(SESSION_TOKEN, ds, wellPositions, channel);
+
+        assertEquals("[Image for [dataset ds1, well [1, 3], channel DAPI, tile 0], "
+                + "Image for [dataset ds1, well [1, 3], channel DAPI, tile 1]]",
+                plateImageReferences.toString());
+        
+        context.assertIsSatisfied();
+    }
 
     @Test
     public void testListAvailableFeatureNames()
@@ -258,14 +280,10 @@ public class DssServiceRpcScreeningTest extends AssertJUnit
     public void testLoadImages() throws IOException
     {
         final String channel = "GFP";
+        prepareGetHomeDatabaseInstance();
         context.checking(new Expectations()
             {
                 {
-                    one(service).getHomeDatabaseInstance();
-                    DatabaseInstance databaseInstance = new DatabaseInstance();
-                    databaseInstance.setUuid("12345");
-                    will(returnValue(databaseInstance));
-                    
                     Size thumbnailSize = new Size(2, 1);
                     one(imageLoader).tryGetImage(
                             channel,
@@ -449,6 +467,19 @@ public class DssServiceRpcScreeningTest extends AssertJUnit
         return list;
     }
 
+    private void prepareGetHomeDatabaseInstance()
+    {
+        context.checking(new Expectations()
+            {
+                {
+                    one(service).getHomeDatabaseInstance();
+                    DatabaseInstance databaseInstance = new DatabaseInstance();
+                    databaseInstance.setUuid("12345");
+                    will(returnValue(databaseInstance));
+                }
+            });
+    }
+
     private void prepareCreateFeatureVectorDataSet(final long dataSetID,
             final String... featureCodes)
     {
diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacadeTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacadeTest.java
index 16aef7ff3d9..5f0354180ed 100644
--- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacadeTest.java
+++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacadeTest.java
@@ -61,6 +61,23 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellPosition;
 @Friend(toClasses = DssServiceRpcScreeningHolder.class)
 public class ScreeningOpenbisServiceFacadeTest extends AssertJUnit
 {
+    private static final class MockPlateImageHandler implements IPlateImageHandler
+    {
+        private final StringBuilder recorder = new StringBuilder();
+
+        public void handlePlateImage(PlateImageReference plateImageReference, byte[] imageFileBytes)
+        {
+            recorder.append(plateImageReference).append(", ");
+            recorder.append(new String(imageFileBytes)).append('\n');
+        }
+
+        @Override
+        public String toString()
+        {
+            return recorder.toString();
+        }
+    }
+    
     private static final String DATA_SET1 = "ds1";
 
     private static final String DATA_SET2 = "ds2";
@@ -328,7 +345,46 @@ public class ScreeningOpenbisServiceFacadeTest extends AssertJUnit
         assertEquals("hello 1", new String(images.get(0)));
         assertEquals("hello 2", new String(images.get(1)));
         assertEquals(2, images.size());
-        
+
+        context.assertIsSatisfied();
+    }
+
+    @Test
+    public void testLoadImagesUsingPlateImageHandler() throws IOException
+    {
+        final DatasetIdentifier ds = new DatasetIdentifier("ds1", URL1);
+        final List<WellPosition> wellPositions = Arrays.asList(new WellPosition(1, 3));
+        final String channel = "dapi";
+        final ImageSize thumbnailSize = new ImageSize(10, 7);
+        context.checking(new Expectations()
+            {
+                {
+                    one(dssService1).listPlateImageReferences(SESSION_TOKEN, ds, wellPositions,
+                            channel);
+                    PlateImageReference r1 = new PlateImageReference(1, 3, 1, channel, ds);
+                    PlateImageReference r2 = new PlateImageReference(1, 3, 2, channel, ds);
+                    List<PlateImageReference> references = Arrays.asList(r1, r2);
+                    will(returnValue(references));
+
+                    one(dssService1).loadImages(SESSION_TOKEN, references, thumbnailSize);
+                    ByteArrayBasedContent content1 =
+                            new ByteArrayBasedContent("hello 1".getBytes(), "h1");
+                    ByteArrayBasedContent content2 =
+                            new ByteArrayBasedContent("hello 2".getBytes(), "h2");
+                    ConcatenatedContentInputStream stream =
+                            new ConcatenatedContentInputStream(true, Arrays.<IContent> asList(
+                                    content1, content2));
+                    will(returnValue(stream));
+                }
+            });
+
+        MockPlateImageHandler plateImageHandler = new MockPlateImageHandler();
+        facade.loadImages(ds, wellPositions, channel, thumbnailSize, plateImageHandler);
+
+        assertEquals("Image for [dataset ds1, well [1, 3], channel DAPI, tile 1], hello 1\n"
+                + "Image for [dataset ds1, well [1, 3], channel DAPI, tile 2], hello 2\n",
+                plateImageHandler.toString());
+
         context.assertIsSatisfied();
     }
     
-- 
GitLab