summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener')
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutBindingListenerTest.java111
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java227
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserContextListenerTest.java82
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserSessionListenerTest.java114
4 files changed, 534 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutBindingListenerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutBindingListenerTest.java
new file mode 100644
index 00000000..e26b6086
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutBindingListenerTest.java
@@ -0,0 +1,111 @@
+/*
+ * ============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 javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSession;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class PortalTimeoutBindingListenerTest {
+
+ PortalTimeoutBindingListener port;
+
+ @Mock
+ HttpSessionBindingEvent event;
+
+ @Mock
+ HttpSession session;
+
+ @Before
+ public void init() {
+
+ port = Mockito.spy(PortalTimeoutBindingListener.class);
+
+ Mockito.when(event.getSession()).thenReturn(session);
+
+
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void valueBound_Test_null() {
+
+ port.valueBound(event);
+ Mockito.verify(port, Mockito.times(1)).valueBound(event);
+
+
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void valueUnBound_Test_null() {
+
+ port.valueBound(event);
+ Mockito.verify(port, Mockito.times(1)).valueBound(event);
+ }
+
+ @Test
+ public void valueBound_Test_Notnull() {
+
+ Mockito.when(session.getAttribute(PortalApiConstants.PORTAL_JSESSION_ID)).thenReturn("test");
+
+ port.valueBound(event);
+ Mockito.verify(port, Mockito.times(1)).valueBound(event);
+
+ }
+
+ @Test
+ public void valueUnBound_Test_Notnull() {
+
+ Mockito.when(session.getAttribute(PortalApiConstants.PORTAL_JSESSION_ID)).thenReturn("test");
+ port.valueUnbound(event);
+ Mockito.verify(port, Mockito.times(1)).valueUnbound(event);
+
+
+ }
+
+
+} \ No newline at end of file
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);
+
+ }
+
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserContextListenerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserContextListenerTest.java
new file mode 100644
index 00000000..2b350e9d
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserContextListenerTest.java
@@ -0,0 +1,82 @@
+/*
+ * ============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 javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class UserContextListenerTest {
+
+
+ @InjectMocks
+ UserContextListener Ulist;
+
+ @Mock
+ ServletContextEvent event;
+
+ @Mock
+ ServletContext context;
+
+ @Before
+ public void init() {
+
+ MockitoAnnotations.initMocks(this);
+
+ Mockito.when(event.getServletContext()).thenReturn(context);
+
+ }
+
+ @Test
+ public void contextInitialized_test() {
+
+ Ulist.contextInitialized(event);
+
+ }
+
+} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserSessionListenerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserSessionListenerTest.java
new file mode 100644
index 00000000..e371ebd9
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserSessionListenerTest.java
@@ -0,0 +1,114 @@
+/*
+ * ============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 java.util.HashMap;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+
+@RunWith(MockitoJUnitRunner.class)
+public class UserSessionListenerTest {
+
+ @InjectMocks
+ UserSessionListener Ulist;
+
+ @Mock
+ HttpSessionEvent event;
+
+ @Mock
+ HttpSession session;
+
+ @Mock
+ ServletContext context;
+
+ @Mock
+ HashMap<String, HttpSession> activeUsers;
+
+ @Before
+ public void init() {
+
+ MockitoAnnotations.initMocks(this);
+
+ Mockito.when(event.getSession()).thenReturn(session);
+
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void sessionCreated_test_null() {
+
+ Ulist.sessionCreated(event);
+
+ }
+
+ @Test
+ public void sessionCreated_test_notNull_case1() {
+
+ Mockito.when(session.getServletContext()).thenReturn(context);
+
+ Mockito.when(context.getAttribute(PortalApiConstants.ACTIVE_USERS_NAME)).thenReturn(activeUsers);
+
+ Mockito.when(session.getId()).thenReturn("id1");
+
+ Ulist.sessionCreated(event);
+
+ }
+
+ @Test
+ public void sessionDestroyed_test_null() {
+
+ Mockito.when(session.getServletContext()).thenReturn(context);
+
+ Mockito.when(context.getAttribute(PortalApiConstants.ACTIVE_USERS_NAME)).thenReturn(activeUsers);
+
+ Ulist.sessionDestroyed(event);
+ }
+
+}