From f281c271508510e42f3a73d7245c46a4b20d2ef2 Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Wed, 12 May 2010 09:01:44 +0000
Subject: [PATCH] LMS-1527 Added factory to try different urls for connecting
 to OpenBIS.

SVN: 15929
---
 .../shared/OpenBisServiceFactoryTest.java     | 105 ++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/OpenBisServiceFactoryTest.java

diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/OpenBisServiceFactoryTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/OpenBisServiceFactoryTest.java
new file mode 100644
index 00000000000..99a8afb9c86
--- /dev/null
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/OpenBisServiceFactoryTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2010 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.generic.shared;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.testng.AssertJUnit;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService;
+import ch.systemsx.cisd.openbis.generic.shared.OpenBisServiceFactory;
+import ch.systemsx.cisd.openbis.generic.shared.OpenBisServiceFactory.ILimsServiceStubFactory;
+
+/**
+ * @author Chandrasekhar Ramakrishnan
+ */
+public class OpenBisServiceFactoryTest extends AssertJUnit
+{
+    private Mockery context;
+
+    private IETLLIMSService openBisService;
+
+    private ILimsServiceStubFactory stubFactory;
+
+    @BeforeMethod
+    public void setUp()
+    {
+        context = new Mockery();
+        openBisService = context.mock(IETLLIMSService.class);
+        stubFactory = context.mock(ILimsServiceStubFactory.class);
+    }
+
+    @Test
+    public void testBasicUse()
+    {
+        context.checking(new Expectations()
+            {
+                {
+                    one(stubFactory).createServiceStub(
+                            "http://localhost:8888/openbis/openbis/rmi-etl");
+                    will(returnValue(openBisService));
+                    one(openBisService).getVersion();
+                }
+            });
+        OpenBisServiceFactory factory =
+                new OpenBisServiceFactory("http://localhost:8888", stubFactory);
+        factory.createService();
+        context.assertIsSatisfied();
+    }
+
+    @Test
+    public void testAlternateLocation()
+    {
+        context.checking(new Expectations()
+            {
+                {
+                    one(stubFactory).createServiceStub(
+                            "http://localhost:8888/openbis/openbis/rmi-etl");
+                    will(returnValue(openBisService));
+                    one(openBisService).getVersion();
+                    will(throwException(new Exception()));
+                    one(stubFactory).createServiceStub("http://localhost:8888/openbis/rmi-etl");
+                    will(returnValue(openBisService));
+                    one(openBisService).getVersion();
+                }
+            });
+        OpenBisServiceFactory factory =
+                new OpenBisServiceFactory("http://localhost:8888", stubFactory);
+        factory.createService();
+        context.assertIsSatisfied();
+    }
+
+    @Test
+    public void testLocationAlreadySpecified()
+    {
+        context.checking(new Expectations()
+            {
+                {
+                    one(stubFactory).createServiceStub(
+                            "http://localhost:8888/openbis/openbis/rmi-etl");
+                    will(returnValue(openBisService));
+                    one(openBisService).getVersion();
+                }
+            });
+        OpenBisServiceFactory factory =
+                new OpenBisServiceFactory("http://localhost:8888/openbis/openbis", stubFactory);
+        factory.createService();
+        context.assertIsSatisfied();
+    }
+}
-- 
GitLab