summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java')
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java173
1 files changed, 173 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java
new file mode 100644
index 00000000..eb2493e5
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java
@@ -0,0 +1,173 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+package org.onap.portalsdk.core.onboarding.rest;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({URL.class,HttpURLConnection.class,PortalApiProperties.class})
+public class RestWebServiceClientTest {
+
+ String restPath, userId, appName, requestId, appUserName, appPassword, contentType,content ;
+
+ String url = "http://localhost:9000/";
+
+ String loginId;
+
+ String appUebKey;
+
+ Boolean isBasicAuth = true;
+
+ InputStream inputStream;
+
+ RestWebServiceClient restclient;
+
+ @Before
+ public void init() throws IOException {
+
+ restclient = RestWebServiceClient.getInstance();
+
+ PowerMockito.mockStatic(PortalApiProperties.class);
+
+ MockitoAnnotations.initMocks(this);
+ }
+
+
+
+ @Test(expected=ConnectException.class)
+ public void get_test_notNull() throws IOException {
+
+ RestWebServiceClient.getInstance().get(url, loginId, appName, requestId, appUebKey, appUserName, appPassword);
+
+ }
+
+ @Test(expected=ConnectException.class)
+ public void get_test_notNull_case1() throws IOException {
+
+ RestWebServiceClient.getInstance().get(url, loginId, appName, requestId, appUebKey, appUserName, appPassword);
+
+ }
+
+
+ @Test(expected=NumberFormatException.class)
+ public void postPortalContent_test_case1() throws IOException {
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc");
+
+ PowerMockito.when(PortalApiProperties.getProperty("ext_req_connection_timeout")).thenReturn("test");
+
+ RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth);
+
+ }
+
+ @Test(expected=IOException.class)
+ public void postPortalContent_test_case2() throws IOException {
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth);
+
+ }
+
+ @Test(expected=IOException.class)
+ public void postPortalContent_test_case3() throws IOException {
+
+ RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth);
+
+ }
+
+ @Test(expected=IOException.class)
+ public void getPortalContent_test_case1() throws IOException {
+
+ //Without the rest_url
+
+ RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth);
+ }
+
+ @Test(expected=IOException.class)
+ public void getPortalContent_test_case2() throws IOException {
+
+ //Without the Ueb_app_key
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth);
+ }
+
+ @Test(expected=ConnectException.class)
+ public void getPortalContent_test_case3() throws IOException {
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc");
+
+ RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth);
+ }
+
+ @Test(expected=ConnectException.class)
+ public void getPortalContent_test_case4() throws IOException {
+
+ //with BasicAuthentication = true
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc");
+
+ RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth);
+ }
+
+
+
+}