diff options
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java')
-rw-r--r-- | ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java new file mode 100644 index 00000000..3027cbee --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java @@ -0,0 +1,227 @@ +/* + * ============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.listener; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.*; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler.SessionCommInf; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; + + +import com.fasterxml.jackson.core.JsonProcessingException; + +@RunWith(MockitoJUnitRunner.class) +public class PortalTimeoutHandlerTest { + + + @InjectMocks + PortalTimeoutHandler port; + + String portalJSessionId = "phrase"; + + String jSessionId = "test"; + + String ecompRestURL,userName,pwd,uebKey; + + @Mock + HttpServletRequest request; + + @Mock + ServletContext servCont; + + @Mock + Object servlettest; + + @Mock + SessionCommInf _sessionComm; + + @Mock + HttpSession session; + + String jSessionKey; + + + String sessionTimeoutMapStr; + + @Mock (name="sessionMap") + Map<String, HttpSession> sessionMap; + + @Mock + Set<String> test_set = new HashSet<String>(Arrays.asList("test1", "test2")); + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + //port = Mockito.spy(PortalTimeoutHandler.class); + + Mockito.when(session.getAttribute(PortalApiConstants.PORTAL_JSESSION_ID)).thenReturn("test-Phrase"); + + session.setAttribute("test1","test2"); + + Mockito.when(request.getSession()).thenReturn(session); + + Mockito.when(request.getSession(false)).thenReturn(session); + + Mockito.when(sessionMap.get(jSessionKey)).thenReturn(session); + + Mockito.when(sessionMap.keySet()).thenReturn(test_set); + + long lastAccessedTimeMilliSec = 200; + long previousToLastAccessTime = 256; + + Mockito.when(session.getAttribute(PortalApiConstants.SESSION_PREVIOUS_ACCESS_TIME)).thenReturn(previousToLastAccessTime); + Mockito.when(session.getLastAccessedTime()).thenReturn(lastAccessedTimeMilliSec); + Mockito.when(session.getMaxInactiveInterval()).thenReturn(1); + + + } + + @Test + public void getInstance_test() { + + port.getInstance(); + + } + + @Test + public void sessionCreated_test() { + + PortalTimeoutHandler.sessionCreated(portalJSessionId, jSessionId, session); + } + + @Test + public void sessionDestroyed_test() { + + port.sessionDestroyed(session); + } + + @Test + public void invalidateSession_test() { + + assertEquals(false,port.invalidateSession(portalJSessionId)); + } + + @Test + public void gatherSessionExtensions_test() { + + port.gatherSessionExtensions(); + + + } + + @Test + public void updateSessionExtensions_test() { + + PortalTimeoutHandler.updateSessionExtensions(sessionTimeoutMapStr); + } + + @Test(expected=NullPointerException.class) + public void synchronizeSessionForLastMinuteRequests_test_null() throws JsonProcessingException { + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + } + + @Test(expected=NumberFormatException.class) + public void synchronizeSessionForLastMinuteRequests_test_notnull() throws JsonProcessingException { + Mockito.when(session.getServletContext()).thenReturn(servCont); + + Mockito.when(session.getServletContext().getAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK)).thenReturn(servlettest); + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + + } + + @Test + public void synchronizeSessionForLastMinuteRequests_test_notnull_case2() throws JsonProcessingException { + Mockito.when(session.getServletContext()).thenReturn(servCont); + + Mockito.when(session.getServletContext().getAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK)).thenReturn(null); + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + + } + + @Test + public void synchronizeSessionForLastMinuteRequests_test_notnull_case3() throws JsonProcessingException { + Mockito.when(session.getServletContext()).thenReturn(servCont); + + + //Mockito.when(session.getAttribute(PortalApiConstants.SESSION_PREVIOUS_ACCESS_TIME)).thenReturn(previousToLastAccessTime); + + Mockito.when(session.getServletContext().getAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK)).thenReturn(null); + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + + } + + @Test + public void synchronizeSessionForLastMinuteRequests_test_notnull_case4() throws JsonProcessingException { + Mockito.when(session.getServletContext()).thenReturn(servCont); + + + + + + + Mockito.when(session.getServletContext().getAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK)).thenReturn(2000); + + //session.setAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK,2000); + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + + } + + +} |