From 753c866f2c89841b640d9e3762201705766e5c37 Mon Sep 17 00:00:00 2001 From: "Kishore Reddy, Gujja (kg811t)" Date: Fri, 2 Mar 2018 17:07:24 -0500 Subject: [PATCH] Added Junits Issue-ID: PORTAL-136 Includes JUNITS Change-Id: I025eff3eb4f74940cd427767e4d1f376eabfe51f Signed-off-by:Kishore Reddy, Gujja (kg811t) --- .../sessionmgt/SessionCommunicationTest.java | 141 +++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java 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); + } +} -- 2.16.6