summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-fw
diff options
context:
space:
mode:
authorNaveen Kumar Pitchai <naveenk89@in.ibm.com>2018-06-26 15:12:08 -0400
committerNaveen Kumar Pitchai <naveenk89@in.ibm.com>2018-06-26 19:44:19 +0000
commit41660425f19da5aaa57f1ce2b6fe56fe6d741b3b (patch)
tree43059e5a5c5679bc1c4a0c71e54c5ca85d06e5a2 /ecomp-sdk/epsdk-fw
parenta1a07c762ce60ccaf0a6db26b1475e333a42c9d6 (diff)
Adding Junit test files
WizardSequenceTest.java ConfigLoaderTest.java PortalAPIResponseTest.java PortalRestAPIProxyTest.java PortalTimeoutBindingListenerTest.java PortalTimeoutHandlerTest.java UserContextListenerTest.java UserSessionListenerTest.java SessionCommunicationServiceTest.java RestWebServiceClientTest.java FavoritesClientTest.java FunctionalMenuClientTest.java ExternalAppConfigTest.java ExternalAppInitializerTest.java HibernateMappingLocationsTest.java SecurityXssFilterTest.java LoginStrategyImplTest.java RegisterTest.java RegistryAdapterTest.java AdminAuthExtensionTest.java Change-Id: If4c553aea9e7f3662d13e369d818073943fbaf54 Issue-ID: PORTAL-328 Signed-off-by: Naveen Kumar Pitchai <naveenk89@in.ibm.com>
Diffstat (limited to 'ecomp-sdk/epsdk-fw')
-rw-r--r--ecomp-sdk/epsdk-fw/pom.xml23
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalAPIResponseTest.java87
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationServiceTest.java81
-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
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FavoritesClientTest.java94
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClientTest.java85
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java173
10 files changed, 1067 insertions, 10 deletions
diff --git a/ecomp-sdk/epsdk-fw/pom.xml b/ecomp-sdk/epsdk-fw/pom.xml
index e1da0300..5b1f5d7b 100644
--- a/ecomp-sdk/epsdk-fw/pom.xml
+++ b/ecomp-sdk/epsdk-fw/pom.xml
@@ -18,6 +18,7 @@
<!-- properties are inherited from parent -->
<properties>
<resteasy.version>3.0.18.Final</resteasy.version>
+ <powermock.version>1.6.4</powermock.version>
</properties>
<!-- repositories are inherited from parent -->
@@ -193,16 +194,18 @@
<scope>test</scope>
<version>${jacoco.version}</version>
</dependency>
- <dependency>
- <groupId>commons-fileupload</groupId>
- <artifactId>commons-fileupload</artifactId>
- <version>1.3.3</version>
- </dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.9.3</version>
- </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalAPIResponseTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalAPIResponseTest.java
new file mode 100644
index 00000000..3b223e52
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalAPIResponseTest.java
@@ -0,0 +1,87 @@
+/*
+ * ============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.crossapi;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PortalAPIResponseTest {
+
+ PortalAPIResponse portalApi = new PortalAPIResponse(true,"Status ok");
+
+ String status = "ok Message";
+
+ String message = "Status ok";
+
+ @Before
+ public void init() {
+
+ //MockitoAnnotations.initMocks(this);
+
+ }
+
+ @Test
+ public void getStatus_test() {
+
+ portalApi.getStatus();
+ }
+
+ @Test
+ public void setStatus_test() {
+
+ portalApi.setStatus(status);
+ }
+
+
+ @Test
+ public void getMessage() {
+
+ portalApi.getMessage();
+ }
+
+ @Test
+ public void setMessage() {
+
+ portalApi.setMessage(message);
+ }
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationServiceTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationServiceTest.java
new file mode 100644
index 00000000..80728904
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationServiceTest.java
@@ -0,0 +1,81 @@
+/*
+ * ============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.crossapi;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class SessionCommunicationServiceTest {
+
+ @InjectMocks
+ SessionCommunicationService sessComm;
+
+ String ecompRestURL = "http://portal.onap.org:50580/ecompportal/auxapi";
+
+ String userName, password;
+
+ String sessionTimeoutMap = "test";
+
+ String uebKey = "REPLACE-ME-UEB-APP-KEY-EPSDK-APP-OS";
+
+
+ @Before
+ public void init() {
+
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void getSessionSlotCheckIntervalTest() {
+
+ SessionCommunicationService.getSessionSlotCheckInterval(ecompRestURL, userName, password, uebKey);
+ }
+
+
+ @Test
+ public void requestPortalSessionTimeoutExtensionTest() {
+
+ SessionCommunicationService.requestPortalSessionTimeoutExtension(ecompRestURL, userName, password, uebKey,sessionTimeoutMap);
+ }
+}
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);
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FavoritesClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FavoritesClientTest.java
new file mode 100644
index 00000000..9309b8f8
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FavoritesClientTest.java
@@ -0,0 +1,94 @@
+/*
+ * ============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.rest;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({RestWebServiceClient.class})
+public class FavoritesClientTest {
+
+ FavoritesClient favClient;
+
+ String userId, appName,requestId, appUserName, appPassword;
+
+ @Mock
+ HttpURLConnection con;
+
+ @Mock
+ RestWebServiceClient restClient;
+
+ int resCode;
+
+ @Before
+ public void init() throws Exception {
+
+ PowerMockito.mockStatic(RestWebServiceClient.class);
+
+ PowerMockito.when(RestWebServiceClient.getInstance()).thenReturn(restClient);
+
+ PowerMockito.when(restClient.getPortalContent("/getFavorites", userId, appName, requestId, appUserName,
+ appPassword,true)).thenReturn("test");
+
+ favClient = Mockito.spy(FavoritesClient.class);
+
+ }
+
+ @Test
+ public void getFavorites_test_notNull() throws IOException {
+
+ System.out.println(FavoritesClient.getFavorites(userId, appName, requestId, appUserName, appPassword));
+
+
+
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClientTest.java
new file mode 100644
index 00000000..29ab5e6e
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClientTest.java
@@ -0,0 +1,85 @@
+/*
+ * ============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.rest;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.net.SocketTimeoutException;
+
+import javax.servlet.ServletException;
+
+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;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.onap.portalsdk.core.onboarding.util.SSOFilter;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestAPIService;
+
+@RunWith(MockitoJUnitRunner.class)
+public class FunctionalMenuClientTest {
+
+ @InjectMocks
+ FunctionalMenuClient funcMenu;
+
+ String userId, appName, requestId, appUserName, appPassword;
+
+ @Before
+ public void init() throws ServletException {
+
+ MockitoAnnotations.initMocks(this);
+
+
+ }
+
+ @Test(expected=ConnectException.class)
+ public void getFunctionalMenu_test() throws IOException {
+
+ FunctionalMenuClient.getFunctionalMenu(userId, appName, requestId, appUserName, appPassword);
+ }
+
+
+
+
+}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java
new file mode 100644
index 00000000..eb2493e5
--- /dev/null
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java
@@ -0,0 +1,173 @@
+/*
+ * ============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.rest;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+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,PortalApiProperties.class})
+public class RestWebServiceClientTest {
+
+ String restPath, userId, appName, requestId, appUserName, appPassword, contentType,content ;
+
+ String url = "http://localhost:9000/";
+
+ String loginId;
+
+ String appUebKey;
+
+ Boolean isBasicAuth = true;
+
+ InputStream inputStream;
+
+ RestWebServiceClient restclient;
+
+ @Before
+ public void init() throws IOException {
+
+ restclient = RestWebServiceClient.getInstance();
+
+ PowerMockito.mockStatic(PortalApiProperties.class);
+
+ MockitoAnnotations.initMocks(this);
+ }
+
+
+
+ @Test(expected=ConnectException.class)
+ public void get_test_notNull() throws IOException {
+
+ RestWebServiceClient.getInstance().get(url, loginId, appName, requestId, appUebKey, appUserName, appPassword);
+
+ }
+
+ @Test(expected=ConnectException.class)
+ public void get_test_notNull_case1() throws IOException {
+
+ RestWebServiceClient.getInstance().get(url, loginId, appName, requestId, appUebKey, appUserName, appPassword);
+
+ }
+
+
+ @Test(expected=NumberFormatException.class)
+ public void postPortalContent_test_case1() throws IOException {
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc");
+
+ PowerMockito.when(PortalApiProperties.getProperty("ext_req_connection_timeout")).thenReturn("test");
+
+ RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth);
+
+ }
+
+ @Test(expected=IOException.class)
+ public void postPortalContent_test_case2() throws IOException {
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth);
+
+ }
+
+ @Test(expected=IOException.class)
+ public void postPortalContent_test_case3() throws IOException {
+
+ RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth);
+
+ }
+
+ @Test(expected=IOException.class)
+ public void getPortalContent_test_case1() throws IOException {
+
+ //Without the rest_url
+
+ RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth);
+ }
+
+ @Test(expected=IOException.class)
+ public void getPortalContent_test_case2() throws IOException {
+
+ //Without the Ueb_app_key
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth);
+ }
+
+ @Test(expected=ConnectException.class)
+ public void getPortalContent_test_case3() throws IOException {
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc");
+
+ RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth);
+ }
+
+ @Test(expected=ConnectException.class)
+ public void getPortalContent_test_case4() throws IOException {
+
+ //with BasicAuthentication = true
+
+ PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/");
+
+ PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc");
+
+ RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth);
+ }
+
+
+
+}