summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common
diff options
context:
space:
mode:
authorKishore Reddy, Gujja (kg811t) <kg811t@research.att.com>2018-03-02 17:07:24 -0500
committerKishore Reddy, Gujja (kg811t) <kg811t@research.att.com>2018-03-02 17:07:24 -0500
commit753c866f2c89841b640d9e3762201705766e5c37 (patch)
tree738a9074e82e555538cd251391a63e21bd52fd87 /ecomp-portal-BE-common
parentfadf84a4a76f7501e7dad2f426cdf4603304baad (diff)
Added Junits
Issue-ID: PORTAL-136 Includes JUNITS Change-Id: I025eff3eb4f74940cd427767e4d1f376eabfe51f Signed-off-by:Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common')
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java141
1 files changed, 141 insertions, 0 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java
new file mode 100644
index 00000000..89af5263
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java
@@ -0,0 +1,141 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 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============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.service.sessionmgt;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.portal.transport.OnboardingApp;
+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})
+public class SessionCommunicationTest {
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @InjectMocks
+ SessionCommunication sessionCommunication = new SessionCommunication();
+
+
+ @Test
+ public void sendGetConnectionRefusedTest() throws Exception {
+ OnboardingApp app = new OnboardingApp();
+ app.setRestrictedApp(false);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.isCentralAuth = true;
+ app.isEnabled = true;
+ app.isOpen =false;
+ app.name = "test";
+ app.restUrl ="http://localhost:1234";
+ app.username = "test";
+ app.appPassword = "xyz";
+ URL u = PowerMockito.mock(URL.class);
+ HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
+ String url = "http://localhost:1234/sessionTimeOuts";
+ PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(u);
+ PowerMockito.whenNew(HttpURLConnection.class).withAnyArguments().thenReturn(huc);
+ PowerMockito.when(huc.getResponseCode()).thenReturn(200);
+ String actual = sessionCommunication.sendGet(app);
+ assertEquals("", actual);
+ }
+
+ @Test
+ public void pingSessionConnectionRefusedTest() throws Exception {
+ OnboardingApp app = new OnboardingApp();
+ app.setRestrictedApp(false);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.isCentralAuth = true;
+ app.isEnabled = true;
+ app.isOpen =false;
+ app.name = "test";
+ app.restUrl ="http://localhost:1234";
+ app.username = "test";
+ app.appPassword = "xyz";
+ URL u = PowerMockito.mock(URL.class);
+ HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
+ String url = "http://localhost:1234/sessionTimeOuts";
+ PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(u);
+ PowerMockito.whenNew(HttpURLConnection.class).withAnyArguments().thenReturn(huc);
+ PowerMockito.when(huc.getResponseCode()).thenReturn(200);
+ Boolean actual = sessionCommunication.pingSession(app, "test");
+ assertTrue(actual);
+ }
+
+
+ @Test
+ public void timeoutSessionConnectionRefusedTest() throws Exception {
+ OnboardingApp app = new OnboardingApp();
+ app.setRestrictedApp(false);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.isCentralAuth = true;
+ app.isEnabled = true;
+ app.isOpen =false;
+ app.name = "test";
+ app.restUrl ="http://localhost:1234";
+ app.username = "test";
+ app.appPassword = "xyz";
+ URL u = PowerMockito.mock(URL.class);
+ HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
+ String url = "http://localhost:1234/sessionTimeOuts";
+ PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(u);
+ PowerMockito.whenNew(HttpURLConnection.class).withAnyArguments().thenReturn(huc);
+ PowerMockito.when(huc.getResponseCode()).thenReturn(200);
+ Boolean actual = sessionCommunication.timeoutSession(app, "test");
+ assertTrue(actual);
+ }
+}