aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-fe/src/test/java/org
diff options
context:
space:
mode:
authorIdan Amit <ia096e@intl.att.com>2017-12-29 09:40:43 +0200
committerMichael Lando <ml636r@att.com>2017-12-31 08:51:03 +0000
commit2c285722c35d8ee7fd6c9085c8e60f0fa87d5761 (patch)
treeb99164f8030c843091088a68a5638f9d9d1d80dc /catalog-fe/src/test/java/org
parent0195e726cae3f5267dd3be69e089bbbeb4ad5f09 (diff)
SDC Designers Integration - Part 1
Finished first part of designers integration Added templated configuration file Added tests Change-Id: I76e8b413063b939e1eb58da4a5502c4b526168f2 Issue-ID: SDC-687 Signed-off-by: Idan Amit <ia096e@intl.att.com>
Diffstat (limited to 'catalog-fe/src/test/java/org')
-rw-r--r--catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/DesignerStatusBLTest.java110
1 files changed, 110 insertions, 0 deletions
diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/DesignerStatusBLTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/DesignerStatusBLTest.java
new file mode 100644
index 0000000000..0ad233fd6d
--- /dev/null
+++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/DesignerStatusBLTest.java
@@ -0,0 +1,110 @@
+package org.openecomp.sdc.fe.servlets;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.sdc.fe.config.ConfigurationManager;
+import org.openecomp.sdc.fe.config.DesignersConfiguration;
+import org.openecomp.sdc.fe.config.DesignersConfiguration.Designer;
+import org.openecomp.sdc.fe.impl.DesignerStatusBL;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class DesignerStatusBLTest {
+
+ final static CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class);
+ DesignerStatusBL designerStatusBL = new DesignerStatusBL(httpClient);
+ private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ final static ConfigurationManager configurationManager = Mockito.mock(ConfigurationManager.class);
+ final static DesignersConfiguration designersConfiguraiton = Mockito.mock(DesignersConfiguration.class);
+ final static Designer offlineDesigner = new Designer();
+ final static Designer onlineDesinger = new Designer();
+ final static CloseableHttpResponse httpResponse = Mockito.mock(CloseableHttpResponse.class);
+ final static StatusLine statusLine = Mockito.mock(StatusLine.class);
+ final static Map<String, Designer> testDesignersList = new HashMap<String, Designer>();
+
+ final static String offlineDesignerDisplayName = "offlineDesigner";
+ final static String offlineDesignerHost = "192.168.10.1";
+ final static int offlineDesignerPort = 1000;
+ final static String offlineDesignerPath = "/offline";
+ final static String offlineDesignerProtocol = "http";
+
+ final static String onlineDesignerDisplayName = "onlineDesigner";
+ final static String onlineDesignerHost = "192.168.20.2";
+ final static int onlineDesignerPort = 2000;
+ final static String onlineDesignerPath = "/online";
+ final static String onlineDesignerProtocol = "http";
+
+ StringBuilder offlineRequestString = new StringBuilder();
+ StringBuilder onlineRequestString = new StringBuilder();
+
+ @BeforeClass
+ public static void beforeClass() {
+ ConfigurationManager.setTestInstance(configurationManager);
+ when(configurationManager.getDesignersConfiguration()).thenReturn(designersConfiguraiton);
+
+ offlineDesigner.setDisplayName(offlineDesignerDisplayName);
+ offlineDesigner.setDesignerHost(offlineDesignerHost);
+ offlineDesigner.setDesignerPort(offlineDesignerPort);
+ offlineDesigner.setDesignerPath(offlineDesignerPath);
+ offlineDesigner.setDesignerProtocol(offlineDesignerProtocol);
+
+ StringBuilder offlineRequestString = new StringBuilder();
+ offlineRequestString.append(offlineDesignerProtocol).append("://").append(onlineDesignerHost).append(":")
+ .append(offlineDesignerPort).append(offlineDesignerPath);
+
+ onlineDesinger.setDisplayName(onlineDesignerDisplayName);
+ onlineDesinger.setDesignerHost(onlineDesignerHost);
+ onlineDesinger.setDesignerPort(onlineDesignerPort);
+ onlineDesinger.setDesignerPath(onlineDesignerPath);
+ onlineDesinger.setDesignerProtocol(onlineDesignerProtocol);
+
+ StringBuilder onlineRequestString = new StringBuilder();
+ onlineRequestString.append(onlineDesignerProtocol).append("://").append(onlineDesignerHost).append(":")
+ .append(offlineDesignerPort).append(offlineDesignerPath);
+
+ }
+
+ @Test
+ public void TestOfflineDesignerNotBeingReturnedWhenCallingCheckDesinerListAvailability() throws ClientProtocolException, IOException {
+ testDesignersList.put("offlineDesigner", offlineDesigner);
+ when(designersConfiguraiton.getDesignersList()).thenReturn(testDesignersList);
+
+ when(statusLine.getStatusCode()).thenReturn(404);
+ when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ when(httpClient.execute(Mockito.any(HttpHead.class))).thenReturn(httpResponse);
+
+ assertTrue(designerStatusBL.checkDesinerListAvailability().equals("{}"));
+
+ }
+
+ @Test
+ public void TestOnlineDesignerNotBeingReturnedWhenCallingCheckDesinerListAvailability() throws ClientProtocolException, IOException {
+ testDesignersList.put("onlineDesigner", onlineDesinger);
+ when(designersConfiguraiton.getDesignersList()).thenReturn(testDesignersList);
+
+ when(statusLine.getStatusCode()).thenReturn(200);
+ when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ when(httpClient.execute(Mockito.any())).thenReturn(httpResponse);
+
+ String result = gson.toJson(testDesignersList);
+
+ assertTrue(designerStatusBL.checkDesinerListAvailability().equals(result));
+
+ }
+
+}