summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-BE-common')
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java2
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java2
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAuditServiceImplTest.java88
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java141
4 files changed, 231 insertions, 2 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java
index 1b54ebb4..5a5892fb 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/FunctionalMenuController.java
@@ -553,7 +553,7 @@ public class FunctionalMenuController extends EPRestrictedBaseController {
EPUser userResult = searchService.searchUserByUserId(orgUserIdStr);
emailStr = userResult.getEmail();
}
- SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ssZ");
+ SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss Z a");
Date lastLoginDate = user.getLastLoginDate();
if (lastLoginDate == null) {
// should never happen
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java
index 488717ca..dcbbd951 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java
@@ -247,7 +247,7 @@ public class FunctionalMenuControllerTest extends MockitoTestSuite {
@Test
public void getFunctionalMenuStaticInfoTest(){
String fnMenuStaticactualResponse = null;
- String fnMenuStaticexpectedResponse = "{\"firstName\":\"test\",\"lastName\":\"test\",\"last_login\":\"09/08/2017 03:48:13-0400\",\"userId\":\"guestT\",\"email\":\"test\"}";
+ String fnMenuStaticexpectedResponse = "{\"firstName\":\"test\",\"lastName\":\"test\",\"last_login\":\"09/08/2017 03:48:13 -0400 am\",\"userId\":\"guestT\",\"email\":\"test\"}";
String orgUserIdStr = null;
EPUser user = mockUser.mockEPUser();
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAuditServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAuditServiceImplTest.java
new file mode 100644
index 00000000..4ebb5ac7
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAuditServiceImplTest.java
@@ -0,0 +1,88 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : PORTAL
+* ================================================================================
+* Copyright (C) 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file 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.
+* ============LICENSE_END=========================================================
+*/
+package org.onap.portalapp.portal.service;
+
+import static org.junit.Assert.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.onap.portalapp.portal.core.MockEPUser;
+import java.util.Date;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.portal.framework.MockitoTestSuite;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalapp.portal.domain.EPUser;
+
+public class EPAuditServiceImplTest {
+
+ @Mock
+ DataAccessService dataAccessService;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @InjectMocks
+ EPAuditServiceImpl ePAuditServiceImpl = new EPAuditServiceImpl ();
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void getDataAccessServiceTest() {
+ dataAccessService=ePAuditServiceImpl.getDataAccessService();
+ assertNotNull(dataAccessService);
+ }
+
+ @Test
+ public void getNullUserLastLoginTest() {
+ String id=null;
+ Date dt=null;
+ Date date = ePAuditServiceImpl.getGuestLastLogin(id);
+ assertNull(date);
+ }
+
+ @Test
+ public void getGuestLastLoginTest() {
+ EPUser epUser=null;
+ epUser=mockUser.mockEPUser();
+ String id = epUser.getOrgUserId();
+ Date date = ePAuditServiceImpl.getGuestLastLogin(id);
+ assertNull(date);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void delAuditLogFromDayTest() {
+ dataAccessService=ePAuditServiceImpl.getDataAccessService();
+ ePAuditServiceImpl.delAuditLogFromDay();
+ }
+
+}
+
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);
+ }
+}