X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fportalapp%2Fservice%2Fsessionmgt%2FSessionCommunicationTest.java;h=5cb61b26caaaed675fd987311784d3e22fdc3202;hb=230c71614b1d2fb71a8fb482c749ff5a6dad65d8;hp=4cd2205b91587d5bd04879b3e94949806cd14876;hpb=24608a9e1450c409dc3870440d29e91cc3a26bb9;p=portal.git 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 index 4cd2205b..5cb61b26 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -47,14 +47,21 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.service.AppsCacheService; +import org.onap.portalapp.portal.service.AppsCacheServiceImple; import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; 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}) +@PrepareForTest({URL.class, HttpURLConnection.class,CipherUtil.class}) public class SessionCommunicationTest { @Before @@ -65,6 +72,8 @@ public class SessionCommunicationTest { @InjectMocks SessionCommunication sessionCommunication = new SessionCommunication(); + @Mock + AppsCacheService appsCacheService = new AppsCacheServiceImple(); @Test public void sendGetConnectionRefusedTest() throws Exception { @@ -73,13 +82,43 @@ public class SessionCommunicationTest { 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"; + app.setRolesInAAF(true); + app.setIsEnabled(true); + app.setIsOpen(false); + app.setAppName("test"); + app.setRestUrl("http://localhost:1234"); + app.setAppBasicAuthUsername("test"); + app.setAppBasicAuthPassword("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 sendGetConnectionRefusedTest1() throws Exception { + OnboardingApp app = new OnboardingApp(); + app.setRestrictedApp(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setRolesInAAF(true); + app.setIsEnabled(true); + app.setIsOpen(false); + app.setAppName("test"); + app.setRestUrl("http://localhost:1234"); + app.setAppBasicAuthUsername("test"); + app.setAppBasicAuthPassword(""); + EPApp epApp = new EPApp(); + epApp.setAppBasicAuthUsername("test"); + epApp.setAppBasicAuthPassword("xyz1234"); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.when(CipherUtil.decryptPKC(Matchers.anyString(),Matchers.anyString())).thenReturn("test"); + Mockito.when(appsCacheService.getApp(1L)).thenReturn(epApp); URL u = PowerMockito.mock(URL.class); HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); String url = "http://localhost:1234/sessionTimeOuts"; @@ -97,13 +136,13 @@ public class SessionCommunicationTest { 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"; + app.setRolesInAAF(true); + app.setIsEnabled(true); + app.setIsOpen(false); + app.setAppName("test"); + app.setRestUrl("http://localhost:1234"); + app.setAppBasicAuthUsername("test"); + app.setAppBasicAuthPassword("xyz"); URL u = PowerMockito.mock(URL.class); HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); String url = "http://localhost:1234/sessionTimeOuts"; @@ -122,13 +161,13 @@ public class SessionCommunicationTest { 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"; + app.setRolesInAAF(true); + app.setIsEnabled(true); + app.setIsOpen(false); + app.setAppName("test"); + app.setRestUrl("http://localhost:1234"); + app.setAppBasicAuthUsername("test"); + app.setAppBasicAuthPassword("xyz"); URL u = PowerMockito.mock(URL.class); HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); String url = "http://localhost:1234/sessionTimeOuts"; @@ -137,5 +176,12 @@ public class SessionCommunicationTest { PowerMockito.when(huc.getResponseCode()).thenReturn(200); Boolean actual = sessionCommunication.timeoutSession(app, "test"); assertTrue(actual); - } -} + } + + @Test + public void clear() { + + sessionCommunication.clear(true); + + } +} \ No newline at end of file