summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common-test/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-BE-common-test/src/main')
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppCatalogControllerTest.java264
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppContactUsControllerTest.java281
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java190
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserNotificationControllerTest.java265
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java131
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/MockEPUser.java86
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/PopulateSampleTestData.java66
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RemoveSampleTestData.java66
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RestURLsTestSuite.java329
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/ApplicationCommonContextTestSuite.java175
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/MockitoTestSuite.java70
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/FunctionalMenuServiceImplTest.java88
-rw-r--r--ecomp-portal-BE-common-test/src/main/resources/PopulateTestData.sql28
-rw-r--r--ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql27
14 files changed, 2066 insertions, 0 deletions
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppCatalogControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppCatalogControllerTest.java
new file mode 100644
index 00000000..4e2b842d
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppCatalogControllerTest.java
@@ -0,0 +1,264 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+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.openecomp.portalapp.portal.controller.AppCatalogController;
+import org.openecomp.portalapp.portal.domain.EPApp;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.ecomp.model.AppCatalogItem;
+import org.openecomp.portalapp.portal.service.AdminRolesService;
+import org.openecomp.portalapp.portal.service.AdminRolesServiceImpl;
+import org.openecomp.portalapp.portal.service.EPAppCommonServiceImpl;
+import org.openecomp.portalapp.portal.service.EPAppService;
+import org.openecomp.portalapp.portal.service.PersUserAppService;
+import org.openecomp.portalapp.portal.service.PersUserAppServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.transport.AppCatalogPersonalization;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.transport.FieldsValidator.FieldName;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+
+public class AppCatalogControllerTest extends MockitoTestSuite {
+
+ @Mock
+ AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @Mock
+ EPAppService appService = new EPAppCommonServiceImpl();
+
+ @InjectMocks
+ AppCatalogController appCatalogController = new AppCatalogController();
+
+ PersUserAppService persUserAppService = Mockito.spy(new PersUserAppServiceImpl());
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ @Mock
+ EPUserUtils ePUserUtils = new EPUserUtils();
+
+ @Mock
+ EPUser epuser;
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ public AppCatalogItem mockAppCatalogItem() {
+ AppCatalogItem appCatalogItem = new AppCatalogItem();
+ appCatalogItem.setId((long) 1);
+ appCatalogItem.setName("Ecomp Portal");
+ appCatalogItem.setImageUrl("Test_URL");
+ appCatalogItem.setDescription("Testing");
+ appCatalogItem.setNotes("Test");
+ appCatalogItem.setUrl("test");
+ appCatalogItem.setAlternateUrl("test");
+ appCatalogItem.setRestricted(false);
+ appCatalogItem.setOpen(false);
+ appCatalogItem.setAccess(true);
+ appCatalogItem.setSelect(true);
+ appCatalogItem.setPending(false);
+
+ return appCatalogItem;
+ }
+
+ @Test
+ public void getAppCatalogTestIfUserNotAdmin() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<AppCatalogItem> actualAppCatalogList = null;
+
+ List<AppCatalogItem> expectedAppCatalog = new ArrayList<>();
+
+ AppCatalogItem appCatalogItem = mockAppCatalogItem();
+ expectedAppCatalog.add(appCatalogItem);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(appService.getUserAppCatalog(user)).thenReturn(expectedAppCatalog);
+ actualAppCatalogList = appCatalogController.getAppCatalog(mockedRequest, mockedResponse);
+
+ assertTrue(actualAppCatalogList.contains(appCatalogItem));
+
+ }
+
+ @Test
+ public void getAppCatalogTestIfUserIsAdmin() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<AppCatalogItem> actualAppCatalogList = null;
+
+ List<AppCatalogItem> expectedAppCatalog = new ArrayList<>();
+
+ AppCatalogItem appCatalogItem = mockAppCatalogItem();
+
+ expectedAppCatalog.add(appCatalogItem);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAdminAppCatalog(user)).thenReturn(expectedAppCatalog);
+ actualAppCatalogList = appCatalogController.getAppCatalog(mockedRequest, mockedResponse);
+
+ assertTrue(actualAppCatalogList.contains(appCatalogItem));
+
+ }
+
+ @Test
+ public void getAppCatalogTestIfUserisNull() throws IOException {
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null);
+ List<AppCatalogItem> actualAppCatalogList = new ArrayList<>();
+ ;
+ actualAppCatalogList = appCatalogController.getAppCatalog(mockedRequest, mockedResponse);
+ assertNull(actualAppCatalogList);
+
+ }
+
+ @Test
+ public void getAppCatalogTestIfUserThrowsExceptionTest() throws IOException {
+ EPUser user = new EPUser();
+ user.setFirstName("test");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<AppCatalogItem> actualAppCatalogList = new ArrayList<>();
+ ;
+
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+
+ Mockito.when(appCatalogController.getAppCatalog(mockedRequest, mockedResponse)).thenThrow(nullPointerException);
+
+ actualAppCatalogList = appCatalogController.getAppCatalog(mockedRequest, mockedResponse);
+ assertNull(actualAppCatalogList);
+
+ }
+
+ @Test
+ public void putAppCatalogSelectionTestWhenAppIsNull() throws IOException {
+
+ AppCatalogPersonalization persRequest = new AppCatalogPersonalization();
+ persRequest.setAppId((long) 1);
+ persRequest.setPending(false);
+ persRequest.setSelect(false);
+
+ EPUser user = mockUser.mockEPUser();
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+ ;
+
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+
+ EPApp app = null;
+
+ Mockito.when(appService.getApp(persRequest.getAppId())).thenReturn(app);
+
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ actualFieldValidator = appCatalogController.putAppCatalogSelection(mockedRequest, persRequest, mockedResponse);
+ assertEquals(expectedFieldValidator, actualFieldValidator);
+
+ }
+
+ @Test
+ public void putAppCatalogSelectionTest() throws IOException {
+
+ AppCatalogPersonalization persRequest = new AppCatalogPersonalization();
+ persRequest.setAppId((long) 1);
+ persRequest.setPending(false);
+ persRequest.setSelect(false);
+
+ EPUser user = mockUser.mockEPUser();
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+ ;
+
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+
+ EPApp app = new EPApp();
+
+ app.setName("Test");
+ app.setImageUrl("test");
+ app.setDescription("test");
+ app.setNotes("test");
+ app.setUrl("test");
+ app.setId((long) 1);
+ app.setAppRestEndpoint("test");
+ app.setAlternateUrl("test");
+ app.setName("test");
+ app.setMlAppName("test");
+ app.setMlAppAdminId("test");
+ app.setUsername("test");
+ app.setAppPassword("test");
+ app.setOpen(false);
+ app.setEnabled(false);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.setAppType(1);
+
+ Mockito.when(appService.getApp(persRequest.getAppId())).thenReturn(app);
+
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.doNothing().when(persUserAppService).setPersUserAppValue(user, app, persRequest.getSelect(),
+ persRequest.getPending());
+
+ actualFieldValidator = appCatalogController.putAppCatalogSelection(mockedRequest, persRequest, mockedResponse);
+
+ assertEquals(expectedFieldValidator, actualFieldValidator);
+
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppContactUsControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppContactUsControllerTest.java
new file mode 100644
index 00000000..9b2add8e
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppContactUsControllerTest.java
@@ -0,0 +1,281 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+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.openecomp.portalapp.portal.controller.AppContactUsController;
+import org.openecomp.portalapp.portal.ecomp.model.AppCategoryFunctionsItem;
+import org.openecomp.portalapp.portal.ecomp.model.AppContactUsItem;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.AppContactUsService;
+import org.openecomp.portalapp.portal.service.AppContactUsServiceImpl;
+import org.openecomp.portalapp.portal.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+public class AppContactUsControllerTest {
+
+ @Mock
+ AppContactUsService contactUsService = new AppContactUsServiceImpl();
+
+ @InjectMocks
+ AppContactUsController appContactUsController = new AppContactUsController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Mock
+ EPUserUtils ePUserUtils = new EPUserUtils();
+
+ public List<AppContactUsItem> mockResponse() {
+ List<AppContactUsItem> appContactUsItemList = new ArrayList<AppContactUsItem>();
+ AppContactUsItem appContactUsItem = new AppContactUsItem();
+ appContactUsItem.setAppId((long) 1);
+ appContactUsItem.setAppName("Ecmop Portal");
+ appContactUsItem.setDescription("Test");
+ appContactUsItem.setContactName("Test");
+ appContactUsItem.setContactEmail("Test@att.com");
+ appContactUsItem.setUrl("Test_URL");
+ appContactUsItem.setActiveYN("Y");
+ appContactUsItemList.add(appContactUsItem);
+
+ return appContactUsItemList;
+
+ }
+
+ public PortalRestResponse<List<AppContactUsItem>> successPortalRestResponse() {
+ PortalRestResponse<List<AppContactUsItem>> expectedportalRestResponse = new PortalRestResponse<List<AppContactUsItem>>();
+ List<AppContactUsItem> appContactUsItemList = mockResponse();
+ expectedportalRestResponse.setMessage("success");
+ expectedportalRestResponse.setResponse(appContactUsItemList);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ return expectedportalRestResponse;
+
+ }
+
+ public PortalRestResponse<List<AppContactUsItem>> exceptionPortalRestResponse() {
+ PortalRestResponse<List<AppContactUsItem>> expectedportalRestResponse = new PortalRestResponse<List<AppContactUsItem>>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ return expectedportalRestResponse;
+
+ }
+
+ @Test
+ public void getAppContactUsList() throws Exception {
+ PortalRestResponse<List<AppContactUsItem>> expectedportalRestResponse = successPortalRestResponse();
+ List<AppContactUsItem> appContactUsItemList = mockResponse();
+ PortalRestResponse<List<AppContactUsItem>> actualPortalRestResponse = new PortalRestResponse<List<AppContactUsItem>>();
+ Mockito.when(contactUsService.getAppContactUs()).thenReturn(appContactUsItemList);
+ actualPortalRestResponse = appContactUsController.getAppContactUsList(mockedRequest);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void getAppContactUsListCatchesExeptionTest() throws Exception {
+
+ PortalRestResponse<List<AppContactUsItem>> expectedportalRestResponse = exceptionPortalRestResponse();
+ PortalRestResponse<List<AppContactUsItem>> actualPortalRestResponse = new PortalRestResponse<List<AppContactUsItem>>();
+ Mockito.when(contactUsService.getAppContactUs()).thenThrow(nullPointerException);
+ actualPortalRestResponse = appContactUsController.getAppContactUsList(mockedRequest);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void getAppsAndContactsTest() throws Exception {
+ PortalRestResponse<List<AppContactUsItem>> expectedportalRestResponse = successPortalRestResponse();
+ List<AppContactUsItem> appContactUsItemList = mockResponse();
+ PortalRestResponse<List<AppContactUsItem>> actualPortalRestResponse = new PortalRestResponse<List<AppContactUsItem>>();
+ Mockito.when(contactUsService.getAppsAndContacts()).thenReturn(appContactUsItemList);
+ actualPortalRestResponse = appContactUsController.getAppsAndContacts(mockedRequest);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void getAppsAndContactsCatchesExceptionTest() throws Exception {
+ PortalRestResponse<List<AppContactUsItem>> expectedportalRestResponse = exceptionPortalRestResponse();
+ PortalRestResponse<List<AppContactUsItem>> actualPortalRestResponse = new PortalRestResponse<List<AppContactUsItem>>();
+ Mockito.when(contactUsService.getAppsAndContacts()).thenThrow(nullPointerException);
+ actualPortalRestResponse = appContactUsController.getAppsAndContacts(mockedRequest);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void getAppCategoryFunctionsTest() throws Exception {
+ PortalRestResponse<List<AppCategoryFunctionsItem>> actualportalRestResponse = null;
+
+ List<AppCategoryFunctionsItem> contents = new ArrayList<AppCategoryFunctionsItem>();
+
+ AppCategoryFunctionsItem appCategoryFunctionsItem = new AppCategoryFunctionsItem();
+ AppCategoryFunctionsItem appCategoryFunctionsItem1 = new AppCategoryFunctionsItem();
+
+ appCategoryFunctionsItem.setRowId("1");
+ appCategoryFunctionsItem.setAppId("1");
+ appCategoryFunctionsItem.setApplication("Ecomp-portal");
+ appCategoryFunctionsItem.setCategory("test");
+ appCategoryFunctionsItem.setFunctions("test");
+
+ appCategoryFunctionsItem1.setRowId("2");
+ appCategoryFunctionsItem1.setAppId("2");
+ appCategoryFunctionsItem1.setApplication("Ecomp-portal-test");
+ appCategoryFunctionsItem1.setCategory("test");
+ appCategoryFunctionsItem1.setFunctions("test");
+ contents.add(appCategoryFunctionsItem);
+ contents.add(appCategoryFunctionsItem1);
+
+ PortalRestResponse<List<AppCategoryFunctionsItem>> expectedportalRestResponse = new PortalRestResponse<List<AppCategoryFunctionsItem>>();
+ expectedportalRestResponse.setMessage("success");
+ expectedportalRestResponse.setResponse(contents);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+
+ Mockito.when(contactUsService.getAppCategoryFunctions()).thenReturn(contents);
+ actualportalRestResponse = appContactUsController.getAppCategoryFunctions(mockedRequest);
+ assertEquals(actualportalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void getAppCategoryFunctionsCatchesExceptionTest() throws Exception {
+ PortalRestResponse<List<AppCategoryFunctionsItem>> actualportalRestResponse = null;
+ PortalRestResponse<List<AppContactUsItem>> expectedportalRestResponse = exceptionPortalRestResponse();
+ Mockito.when(contactUsService.getAppCategoryFunctions()).thenThrow(nullPointerException);
+ actualportalRestResponse = appContactUsController.getAppCategoryFunctions(mockedRequest);
+ assertEquals(actualportalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void saveTest() throws Exception {
+ PortalRestResponse<String> actualSaveAppContactUS = null;
+
+ AppContactUsItem contactUs = new AppContactUsItem();
+ contactUs.setAppId((long) 1);
+ contactUs.setAppName("Ecmop Portal");
+ contactUs.setDescription("Test");
+ contactUs.setContactName("Test");
+ contactUs.setContactEmail("Test@att.com");
+ contactUs.setUrl("Test_URL");
+ contactUs.setActiveYN("Y");
+
+ Mockito.when(contactUsService.saveAppContactUs(contactUs)).thenReturn("SUCCESS");
+ actualSaveAppContactUS = appContactUsController.save(contactUs);
+ assertEquals(actualSaveAppContactUS.getMessage(), "SUCCESS");
+ }
+
+ @Test
+ public void saveExceptionTest() throws Exception {
+ PortalRestResponse<String> actualSaveAppContactUS = null;
+
+ AppContactUsItem contactUs = new AppContactUsItem();
+ contactUs.setAppId((long) 1);
+ contactUs.setAppName("Ecmop Portal");
+ contactUs.setDescription("Test");
+ contactUs.setContactName("Test");
+ contactUs.setContactEmail("Test@att.com");
+ contactUs.setUrl("Test_URL");
+ contactUs.setActiveYN("Y");
+
+ Mockito.when(contactUsService.saveAppContactUs(contactUs)).thenThrow(new Exception());
+ actualSaveAppContactUS = appContactUsController.save(contactUs);
+ assertEquals(actualSaveAppContactUS.getMessage(), "failure");
+ }
+
+ @Test
+ public void saveWhenAppContactUsItemNullTest() throws Exception {
+ PortalRestResponse<String> actualSaveAppContactUS = null;
+ AppContactUsItem contactUs = null;
+ actualSaveAppContactUS = appContactUsController.save(contactUs);
+ assertEquals(actualSaveAppContactUS.getMessage(), "failure");
+
+ }
+
+ @Test
+ public void saveAllTest() throws Exception {
+
+ List<AppContactUsItem> contactUs = mockResponse();
+ PortalRestResponse<String> actualSaveAppContactUS = null;
+ Mockito.when(contactUsService.saveAppContactUs(contactUs)).thenReturn("SUCCESS");
+ actualSaveAppContactUS = appContactUsController.save(contactUs);
+ assertEquals(actualSaveAppContactUS.getMessage(), "SUCCESS");
+ }
+
+ @Test
+ public void saveAllExceptionTest() throws Exception {
+
+ List<AppContactUsItem> contactUs = mockResponse();
+ PortalRestResponse<String> actualSaveAppContactUS = null;
+ Mockito.when(contactUsService.saveAppContactUs(contactUs)).thenThrow(new Exception());
+ actualSaveAppContactUS = appContactUsController.save(contactUs);
+ assertEquals(actualSaveAppContactUS.getMessage(), "failure");
+ }
+
+ @Test
+ public void deleteTest() throws Exception {
+
+ PortalRestResponse<String> actualSaveAppContactUS = null;
+ Long id = (long) 1;
+ String saveAppContactUs = "SUCCESS";
+ Mockito.when(contactUsService.deleteContactUs(id)).thenReturn(saveAppContactUs);
+ actualSaveAppContactUS = appContactUsController.delete(id);
+ assertEquals(actualSaveAppContactUS.getMessage(), "SUCCESS");
+ }
+
+ @Test
+ public void deleteExceptionTest() throws Exception {
+
+ PortalRestResponse<String> actualSaveAppContactUS = null;
+ Long id = (long) 1;
+ Mockito.when(contactUsService.deleteContactUs(id)).thenThrow(new Exception());
+ actualSaveAppContactUS = appContactUsController.delete(id);
+ assertEquals(actualSaveAppContactUS.getMessage(), "failure");
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java
new file mode 100644
index 00000000..b9f11eeb
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java
@@ -0,0 +1,190 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.validation.constraints.AssertTrue;
+
+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.openecomp.portalapp.portal.controller.FunctionalMenuController;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.service.AdminRolesService;
+import org.openecomp.portalapp.portal.service.AdminRolesServiceImpl;
+import org.openecomp.portalapp.portal.service.FunctionalMenuService;
+import org.openecomp.portalapp.portal.service.FunctionalMenuServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.transport.BusinessCardApplicationRole;
+import org.openecomp.portalapp.portal.transport.BusinessCardApplicationRolesList;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.transport.FieldsValidator.FieldName;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+
+@RunWith(MockitoJUnitRunner.class)
+public class FunctionalMenuControllerTest extends MockitoTestSuite {
+
+ String userid = "sk434m";
+
+ @Mock
+ FunctionalMenuService functionalMenuService = new FunctionalMenuServiceImpl();
+
+ @InjectMocks
+ FunctionalMenuController functionalMenuController = new FunctionalMenuController();
+
+ @Mock
+ private DataAccessService dataAccessService;
+
+ @Mock
+ AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ @InjectMocks
+ EPUserUtils ePUserUtils = new EPUserUtils();
+
+ @Mock
+ EPUser epuser;
+
+ MockEPUser mockUser = new MockEPUser();
+
+ List<BusinessCardApplicationRolesList> appRoles = new ArrayList<BusinessCardApplicationRolesList>();
+ List<BusinessCardApplicationRolesList> appRolesActual = new ArrayList<BusinessCardApplicationRolesList>();
+
+ List<BusinessCardApplicationRole> userAppRoleList = new ArrayList<BusinessCardApplicationRole>();
+
+ public List<BusinessCardApplicationRole> mockBusinessCardApplicationRole() {
+ List<BusinessCardApplicationRole> userAppRoleList = new ArrayList<BusinessCardApplicationRole>();
+
+ BusinessCardApplicationRole businessCardApplicationRole = new BusinessCardApplicationRole();
+ businessCardApplicationRole.setRoleName("ADMIN");
+ businessCardApplicationRole.setAppName("ASDC");
+
+ BusinessCardApplicationRole businessCardApplicationRole1 = new BusinessCardApplicationRole();
+ businessCardApplicationRole1.setAppName("ASDC");
+ businessCardApplicationRole1.setRoleName("Tester");
+
+ userAppRoleList.add(businessCardApplicationRole);
+ userAppRoleList.add(businessCardApplicationRole1);
+ return userAppRoleList;
+ }
+
+ public List<BusinessCardApplicationRolesList> mockBusinessCardApplicationRolesList() {
+ List<BusinessCardApplicationRolesList> appRolesActual = new ArrayList<BusinessCardApplicationRolesList>();
+
+ BusinessCardApplicationRolesList businessCardApplicationRolesList = new BusinessCardApplicationRolesList();
+ businessCardApplicationRolesList.setAppName("ASDC");
+
+ List<String> roleNames = new ArrayList<String>();
+ roleNames.add("ADMIN");
+ roleNames.add("Tester");
+ businessCardApplicationRolesList.setRoleNames(roleNames);
+
+ appRolesActual.add(businessCardApplicationRolesList);
+ return appRolesActual;
+ }
+
+ @Test
+ public void getAppListTestIfAppAlredyExistsBusinessCardApplicationRolesList() throws IOException {
+
+ userAppRoleList = mockBusinessCardApplicationRole();
+ appRolesActual = mockBusinessCardApplicationRolesList();
+
+ Mockito.when(functionalMenuService.getUserAppRolesList(userid)).thenReturn(userAppRoleList);
+
+ appRoles = functionalMenuController.getAppList(mockedRequest, userid);
+
+ assertEquals(appRolesActual.size(), appRoles.size());
+ assertEquals(appRolesActual.get(0).getAppName(), appRoles.get(0).getAppName());
+ assertEquals(appRolesActual.get(0).getRoleNames(), appRoles.get(0).getRoleNames());
+
+ }
+
+ @Test
+ public void getAppListTestIfAppDoesnotExistsInBusinessCardApplicationRolesList() throws IOException {
+
+ userAppRoleList = mockBusinessCardApplicationRole();
+ BusinessCardApplicationRole businessCardApplicationRole = new BusinessCardApplicationRole();
+ businessCardApplicationRole.setAppName("CCD");
+ businessCardApplicationRole.setRoleName("ADMIN");
+ userAppRoleList.add(businessCardApplicationRole);
+ appRolesActual = mockBusinessCardApplicationRolesList();
+ BusinessCardApplicationRolesList businessCardApplicationRolesList = new BusinessCardApplicationRolesList();
+ businessCardApplicationRolesList.setAppName("CCD");
+ List<String> roleNames1 = new ArrayList<String>();
+ roleNames1.add("ADMIN");
+ businessCardApplicationRolesList.setRoleNames(roleNames1);
+ appRolesActual.add(businessCardApplicationRolesList);
+ Mockito.when(functionalMenuService.getUserAppRolesList(userid)).thenReturn(userAppRoleList);
+ appRoles = functionalMenuController.getAppList(mockedRequest, userid);
+ assertEquals(appRolesActual.size(), appRoles.size());
+ assertEquals(appRolesActual.get(0).getAppName(), appRoles.get(0).getAppName());
+ assertEquals(appRolesActual.get(0).getRoleNames(), appRoles.get(0).getRoleNames());
+ assertEquals(appRolesActual.get(1).getAppName(), appRoles.get(1).getAppName());
+ assertEquals(appRolesActual.get(1).getRoleNames(), appRoles.get(1).getRoleNames());
+
+ }
+
+ @Test
+ public void regenerateAncestorTableTest() {
+ EPUser user = mockUser.mockEPUser();
+
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator acutualFieldValidator = null;
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(!adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(functionalMenuService.regenerateAncestorTable()).thenReturn(expectedFieldValidator);
+ acutualFieldValidator = functionalMenuController.regenerateAncestorTable(mockedRequest, mockedResponse);
+ assertTrue(acutualFieldValidator.equals(expectedFieldValidator));
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserNotificationControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserNotificationControllerTest.java
new file mode 100644
index 00000000..628f52a1
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserNotificationControllerTest.java
@@ -0,0 +1,265 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+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.openecomp.portalapp.portal.controller.UserNotificationController;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.FunctionalMenuService;
+import org.openecomp.portalapp.portal.service.FunctionalMenuServiceImpl;
+import org.openecomp.portalapp.portal.service.UserNotificationService;
+import org.openecomp.portalapp.portal.service.UserNotificationServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.transport.EpNotificationItem;
+import org.openecomp.portalapp.portal.transport.EpNotificationItemVO;
+import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.openecomp.portalsdk.core.web.support.UserUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(UserUtils.class)
+public class UserNotificationControllerTest {
+
+ @Mock
+ FunctionalMenuService functionalMenuService = new FunctionalMenuServiceImpl();
+
+ @Mock
+ UserNotificationService userNotificationService = new UserNotificationServiceImpl();
+
+ @InjectMocks
+ UserNotificationController userNotificationController = new UserNotificationController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockEPUser mockUser = new MockEPUser();
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void getMenuIdRoleIdTest() {
+ List<FunctionalMenuRole> expectedMenuRoleList = new ArrayList<FunctionalMenuRole>();
+ FunctionalMenuRole functionalMenuRole = new FunctionalMenuRole();
+ functionalMenuRole.setId(new Integer(99999999));
+ functionalMenuRole.setMenuId((long) 137);
+ functionalMenuRole.setAppId(new Integer(456));
+ functionalMenuRole.setRoleId(new Integer(6214));
+ expectedMenuRoleList.add(functionalMenuRole);
+ List<FunctionalMenuRole> actualFunctionalMenuRoleList = null;
+ Mockito.when(functionalMenuService.getFunctionalMenuRole()).thenReturn(expectedMenuRoleList);
+ actualFunctionalMenuRoleList = userNotificationController.getMenuIdRoleId(mockedRequest, mockedResponse);
+ assertTrue(actualFunctionalMenuRoleList.equals(expectedMenuRoleList));
+
+ }
+
+ @Test
+ public void getNotificationsTest() {
+ EPUser user = mockUser.mockEPUser();
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EpNotificationItem> expectedEpNotificationList = new ArrayList<EpNotificationItem>();
+ EpNotificationItem epNotificationItem = new EpNotificationItem();
+ epNotificationItem.setNotificationId((long) 200);
+ expectedEpNotificationList.add(epNotificationItem);
+ PortalRestResponse<List<EpNotificationItem>> expectedportalRestResponse = new PortalRestResponse<List<EpNotificationItem>>();
+ expectedportalRestResponse.setMessage("success");
+ expectedportalRestResponse.setResponse(expectedEpNotificationList);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ PortalRestResponse<List<EpNotificationItem>> actualPortalRestResponse = null;
+ Mockito.when(userNotificationService.getNotifications(user.getId())).thenReturn(expectedEpNotificationList);
+ actualPortalRestResponse = userNotificationController.getNotifications(mockedRequest, mockedResponse);
+ assertTrue(expectedportalRestResponse.equals(actualPortalRestResponse));
+
+ }
+
+ @Test
+ public void getNotificationsCatchesExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EpNotificationItem> expectedEpNotificationList = null;
+ PortalRestResponse<List<EpNotificationItem>> expectedportalRestResponse = new PortalRestResponse<List<EpNotificationItem>>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(expectedEpNotificationList);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ PortalRestResponse<List<EpNotificationItem>> actualPortalRestResponse = null;
+ Mockito.when(userNotificationService.getNotifications(user.getId())).thenThrow(new NullPointerException());
+ actualPortalRestResponse = userNotificationController.getNotifications(mockedRequest, mockedResponse);
+ assertTrue(expectedportalRestResponse.equals(actualPortalRestResponse));
+
+ }
+
+ @Test
+ public void getAdminNotificationsTest() {
+ List<EpNotificationItemVO> actualEpNotificationsList = new ArrayList<EpNotificationItemVO>();
+ List<EpNotificationItemVO> expectedEpNotificationsList = new ArrayList<EpNotificationItemVO>();
+ EpNotificationItemVO epNotificationItemVO = new EpNotificationItemVO();
+ epNotificationItemVO.setId((long) 1);
+ expectedEpNotificationsList.add(epNotificationItemVO);
+ Mockito.when(userNotificationService.getAdminNotificationVOS()).thenReturn(expectedEpNotificationsList);
+ actualEpNotificationsList = userNotificationController.getAdminNotifications(mockedRequest, mockedResponse);
+ assertTrue(actualEpNotificationsList.equals(expectedEpNotificationsList));
+ }
+
+ @Test
+ public void saveTestWhenNotificationIsNull() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ PortalRestResponse<String> actualPortalRestResponse = new PortalRestResponse<String>();
+ PortalRestResponse<String> expectedPortalRestResponse = new PortalRestResponse<String>();
+ expectedPortalRestResponse.setMessage("FAILURE");
+ expectedPortalRestResponse.setResponse("Notification Header cannot be null or empty");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedPortalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+
+ EpNotificationItem notificationItem = null;
+ actualPortalRestResponse = userNotificationController.save(mockedRequest, mockedResponse, notificationItem);
+ assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse));
+ }
+
+ @Test
+ public void saveTestWhenEndTimeIsGreater() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<String> actualPortalRestResponse = new PortalRestResponse<String>();
+ PortalRestResponse<String> expectedPortalRestResponse = new PortalRestResponse<String>();
+ expectedPortalRestResponse.setMessage("FAILURE");
+ expectedPortalRestResponse.setResponse("End Time should be greater than start time");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedPortalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EpNotificationItem notificationItem = new EpNotificationItem();
+ notificationItem.setNotificationId((long) 1);
+ notificationItem.setMsgHeader("Test");
+ Date currentDate = new Date();
+ Calendar c = Calendar.getInstance();
+ c.setTime(currentDate);
+ c.add(Calendar.DATE, 1);
+ Date currentDatePlusOne = c.getTime();
+ notificationItem.setStartTime(currentDatePlusOne);
+ notificationItem.setEndTime(currentDate);
+
+ actualPortalRestResponse = userNotificationController.save(mockedRequest, mockedResponse, notificationItem);
+ assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse));
+
+ }
+
+ @Test
+ public void saveTestWhenNoRoleIDExists() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<String> actualPortalRestResponse = new PortalRestResponse<String>();
+ PortalRestResponse<String> expectedPortalRestResponse = new PortalRestResponse<String>();
+ expectedPortalRestResponse.setMessage("FAILURE");
+ expectedPortalRestResponse.setResponse("No Roles Ids Exist for the selected Roles");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedPortalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EpNotificationItem notificationItem = new EpNotificationItem();
+ notificationItem.setNotificationId((long) 1);
+ notificationItem.setMsgHeader("Test");
+ notificationItem.setIsForAllRoles("N");
+ Date currentDate = new Date();
+ Calendar c = Calendar.getInstance();
+ c.setTime(currentDate);
+ c.add(Calendar.DATE, 1);
+ Date currentDatePlusOne = c.getTime();
+ notificationItem.setStartTime(currentDate);
+ notificationItem.setEndTime(currentDatePlusOne);
+ List<Long> roleList = new ArrayList<Long>();
+ notificationItem.setRoleIds(roleList);
+ actualPortalRestResponse = userNotificationController.save(mockedRequest, mockedResponse, notificationItem);
+ assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse));
+ }
+
+ @Test
+ public void saveTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute("user", user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<String> actualPortalRestResponse = new PortalRestResponse<String>();
+ PortalRestResponse<String> expectedPortalRestResponse = new PortalRestResponse<String>();
+ expectedPortalRestResponse.setMessage("SUCCESS");
+ expectedPortalRestResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedPortalRestResponse.setStatus(portalRestStatusEnum.OK);
+ EpNotificationItem notificationItem = new EpNotificationItem();
+ notificationItem.setNotificationId((long) 1);
+ notificationItem.setMsgHeader("Test");
+ notificationItem.setIsForAllRoles("Y");
+ Date currentDate = new Date();
+ Calendar c = Calendar.getInstance();
+ c.setTime(currentDate);
+ c.add(Calendar.DATE, 1);
+ Date currentDatePlusOne = c.getTime();
+ notificationItem.setStartTime(currentDate);
+ notificationItem.setEndTime(currentDatePlusOne);
+ List<Long> roleList = new ArrayList<Long>();
+ Long role1 = (long) 1;
+ roleList.add(role1);
+ notificationItem.setRoleIds(roleList);
+ HttpServletRequest request = mockitoTestSuite.getMockedRequest();
+ PowerMockito.mockStatic(UserUtils.class);
+ Mockito.when(UserUtils.getUserIdAsLong(request)).thenReturn((long) 1);
+ Mockito.when(userNotificationService.saveNotification(notificationItem)).thenReturn("Test");
+ actualPortalRestResponse = userNotificationController.save(mockedRequest, mockedResponse, notificationItem);
+ assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse));
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java
new file mode 100644
index 00000000..093ca585
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java
@@ -0,0 +1,131 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+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.openecomp.portalapp.portal.controller.UserRolesController;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.service.UserRolesService;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.transport.AppWithRolesForUser;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.transport.FieldsValidator.FieldName;
+import org.openecomp.portalapp.portal.transport.RoleInAppForUser;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+
+public class UserRolesControllerTest extends MockitoTestSuite {
+
+ String userid = "sk434m";
+
+ @Mock
+ UserRolesService userRolesService;
+
+ @Mock
+ FieldsValidator fieldsValidator;
+
+ @InjectMocks
+ UserRolesController userRolesController = new UserRolesController();
+
+ @Mock
+ private DataAccessService dataAccessService;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ @Mock
+ EPUserUtils ePUserUtils = new EPUserUtils();
+
+ @Mock
+ EPUser epuser;
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void putAppWithUserRoleRequestTest() {
+
+ FieldsValidator actualFieldsValidator = null;
+
+ AppWithRolesForUser appWithRolesForUser = new AppWithRolesForUser();
+ List<RoleInAppForUser> listofRoles = new ArrayList<RoleInAppForUser>();
+
+ appWithRolesForUser.setOrgUserId("guest");
+ appWithRolesForUser.setAppId((long) 550);
+ appWithRolesForUser.setAppName("D2 Services Analytics Dashboard");
+ appWithRolesForUser.setAppRoles(listofRoles);
+
+ RoleInAppForUser roleInAppForUser = new RoleInAppForUser();
+ roleInAppForUser.setIsApplied(false);
+ roleInAppForUser.setRoleId((long) 1);
+ roleInAppForUser.setRoleName("System Administrator");
+
+ RoleInAppForUser roleInAppForUser1 = new RoleInAppForUser();
+ roleInAppForUser1.setIsApplied(true);
+ roleInAppForUser1.setRoleId((long) 16);
+ roleInAppForUser1.setRoleName("Standard User");
+
+ listofRoles.add(roleInAppForUser);
+ listofRoles.add(roleInAppForUser1);
+ EPUser user = mockUser.mockEPUser();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ List<FieldName> fields = new ArrayList<>();
+
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(fields);
+ expectedFieldValidator.setErrorCode(null);
+ HttpSession session = mockedRequest.getSession();
+ session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userRolesService.putUserAppRolesRequest(appWithRolesForUser, user))
+ .thenReturn(expectedFieldValidator);
+
+ actualFieldsValidator = userRolesController.putAppWithUserRoleRequest(mockedRequest, appWithRolesForUser,
+ mockedResponse);
+ assertEquals(expectedFieldValidator.getHttpStatusCode(), actualFieldsValidator.getHttpStatusCode());
+ assertEquals(expectedFieldValidator.getErrorCode(), actualFieldsValidator.getErrorCode());
+ assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields());
+
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/MockEPUser.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/MockEPUser.java
new file mode 100644
index 00000000..aa3c00d2
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/MockEPUser.java
@@ -0,0 +1,86 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.core;
+
+import java.util.Date;
+
+import org.openecomp.portalapp.portal.domain.EPUser;
+
+public class MockEPUser {
+
+ public EPUser mockEPUser() {
+
+ EPUser ePUser = new EPUser();
+ ePUser.setOrgId(null);
+ ePUser.setManagerId(null);
+ ePUser.setFirstName("test");
+ ePUser.setLastName("test");
+ ePUser.setMiddleInitial(null);
+ ePUser.setPhone(null);
+ ePUser.setFax(null);
+ ePUser.setCellular(null);
+ ePUser.setEmail(null);
+ ePUser.setAddressId(null);
+ ePUser.setAlertMethodCd(null);
+ ePUser.setHrid(null);
+ ePUser.setOrgUserId("guest");
+ ePUser.setOrgCode(null);
+ ePUser.setAddress1(null);
+ ePUser.setAddress2(null);
+ ePUser.setCity(null);
+ ePUser.setState(null);
+ ePUser.setZipCode(null);
+ ePUser.setCountry(null);
+ ePUser.setOrgManagerUserId(null);
+ ePUser.setLocationClli(null);
+ ePUser.setBusinessCountryCode(null);
+ ePUser.setBusinessCountryName(null);
+ ePUser.setBusinessUnit(null);
+ ePUser.setBusinessUnitName(null);
+ ePUser.setDepartment(null);
+ ePUser.setDepartmentName(null);
+ ePUser.setCompanyCode(null);
+ ePUser.setCompany(null);
+ ePUser.setZipCodeSuffix(null);
+ ePUser.setJobTitle(null);
+ ePUser.setCommandChain(null);
+ ePUser.setSiloStatus(null);
+ ePUser.setCostCenter(null);
+ ePUser.setFinancialLocCode(null);
+
+ ePUser.setLoginId(null);
+ ePUser.setLoginPwd(null);
+ Date date = new Date();
+ ePUser.setLastLoginDate(date);
+ ePUser.setActive(true);
+ ePUser.setInternal(false);
+ ePUser.setSelectedProfileId(null);
+ ePUser.setTimeZoneId(null);
+ ePUser.setOnline(true);
+ ePUser.setChatId(null);
+ ePUser.setUserApps(null);
+ ePUser.setPseudoRoles(null);
+
+ ePUser.setId((long) 99999999);
+
+ return ePUser;
+
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/PopulateSampleTestData.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/PopulateSampleTestData.java
new file mode 100644
index 00000000..b04d200e
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/PopulateSampleTestData.java
@@ -0,0 +1,66 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.core;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.portalapp.portal.test.framework.ApplicationCommonContextTestSuite;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.jdbc.datasource.DataSourceUtils;
+import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
+
+public class PopulateSampleTestData extends ApplicationCommonContextTestSuite {
+
+ @Autowired
+ DataSource dataSource;
+
+ @Before
+ public void populateTestData() throws SQLException {
+
+ String sql = "PopulateTestData.sql";
+ createConnection(sql);
+ }
+
+ public void createConnection(String sql) {
+ Connection connection = null;
+ ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
+ populator.addScript(new ClassPathResource(sql));
+ try {
+ connection = DataSourceUtils.getConnection(dataSource);
+ populator.populate(connection);
+ } finally {
+ if (connection != null) {
+ DataSourceUtils.releaseConnection(connection, dataSource);
+ }
+ }
+ }
+
+ @Test
+ public void populateTest() {
+ assert (true);
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RemoveSampleTestData.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RemoveSampleTestData.java
new file mode 100644
index 00000000..db9663fd
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RemoveSampleTestData.java
@@ -0,0 +1,66 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.core;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.portalapp.portal.test.framework.ApplicationCommonContextTestSuite;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.jdbc.datasource.DataSourceUtils;
+import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
+
+public class RemoveSampleTestData extends ApplicationCommonContextTestSuite {
+ @Autowired
+ DataSource dataSource;
+
+ public static int count = 0;
+
+ @After
+ public void removeTestData() throws SQLException {
+ String sql = "RemoveTestData.sql";
+ createConnection(sql);
+ }
+
+ public void createConnection(String sql) {
+ Connection connection = null;
+ ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
+ populator.addScript(new ClassPathResource(sql));
+ try {
+ connection = DataSourceUtils.getConnection(dataSource);
+ populator.populate(connection);
+ } finally {
+ if (connection != null) {
+ DataSourceUtils.releaseConnection(connection, dataSource);
+ }
+ }
+ }
+
+ @Test
+ public void removeTest() {
+ assert (true);
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RestURLsTestSuite.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RestURLsTestSuite.java
new file mode 100644
index 00000000..f90b27e5
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RestURLsTestSuite.java
@@ -0,0 +1,329 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.test.framework.ApplicationCommonContextTestSuite;
+import org.openecomp.portalapp.portal.transport.AppNameIdIsAdmin;
+import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.ResultActions;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ *
+ * @author sk434m Use RestURLsTestSuite to test Rest API URL's
+ */
+public class RestURLsTestSuite extends ApplicationCommonContextTestSuite {
+
+ public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
+ MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
+
+ String url = null;
+
+ MockEPUser mockUser = new MockEPUser();
+
+ public byte[] convertObjectToJsonBytes(Object object) throws IOException {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ return mapper.writeValueAsBytes(object);
+ }
+
+ public void requestBuilder(String url) throws Exception {
+ EPUser user = mockUser.mockEPUser();
+
+ MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get(url);
+ requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ ResultActions ra = getMockMvc().perform(requestBuilder);
+ assertData(ra);
+ }
+
+ public void assertData(ResultActions ra) {
+ Assert.assertEquals("application/json", ra.andReturn().getResponse().getContentType());
+ Assert.assertEquals(200, ra.andReturn().getResponse().getStatus());
+
+ }
+
+ @Test
+ public void getMenuItemsTest() throws Exception {
+
+ url = "/portalApi/functionalMenu";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getMenuItemsForNotificationsTest() throws Exception {
+ url = "/portalApi/functionalMenuForNotificationTree";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getUserAppsTestnew() throws Exception {
+
+ url = "/portalApi/userApps";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getPersUserAppsTest() throws Exception {
+
+ url = "/portalApi/persUserApps";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getAppCatalogTest() throws Exception {
+
+ url = "/portalApi/appCatalog";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getAppListNewTest() throws Exception {
+ ResultActions ra = getMockMvc()
+ .perform(MockMvcRequestBuilders.get("/portalApi/userApplicationRoles").param("userId", "guest"));
+ assertData(ra);
+ }
+
+ @Test
+ public void getAvailableAppListTest() throws Exception {
+ url = "/portalApi/availableApps";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getAllAppsTest() throws Exception {
+ url = "/portalApi/allAvailableApps";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getUserProfileTest() throws Exception {
+ url = "/portalApi/userProfile";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getRolesByAppTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/adminAppsRoles/550");
+ requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ ResultActions ra = getMockMvc().perform(requestBuilder);
+ assertData(ra);
+ }
+
+ @Test
+ public void getAppsWithAdminRoleStateForUserTest() throws Exception {
+ url = "/portalApi/adminAppsRoles?user=guest";
+ requestBuilder(url);
+
+ }
+
+ @Test
+ public void getUsersFromAppEndpointTest() throws Exception {
+ url = "/portalApi/app/550/users";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getOnboardingAppsTest() throws Exception {
+ url = "/portalApi/onboardingApps";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getMenuItemsForAuthUserTest() throws Exception {
+ url = "/portalApi/functionalMenuForAuthUser";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getMenuItemsForEditingTest() throws Exception {
+ url = "/portalApi/functionalMenuForEditing";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getAppRolesTest() throws Exception {
+ url = "/portalApi/appRoles/455";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void regenerateAncestorTableTest() throws Exception {
+
+ EPUser user = mockUser.mockEPUser();
+
+ MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders
+ .get("/portalApi/regenerateFunctionalMenuAncestors");
+ requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ ResultActions ra = getMockMvc().perform(requestBuilder);
+ assertEquals("application/json;charset=UTF-8", ra.andReturn().getResponse().getContentType());
+ Assert.assertEquals(200, ra.andReturn().getResponse().getStatus());
+
+ }
+
+ @Test
+ public void getAppListTest() throws Exception {
+ url = "/portalApi/getAppList";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getFavoritesForUserTest() throws Exception {
+ url = "/portalApi/getFavoriteItems";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getManifestTest() throws Exception {
+ url = "/portalApi/manifest";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getActiveUsersTest() throws Exception {
+ url = "/portalApi/dashboard/activeUsers";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void searchPortalTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/dashboard/search")
+ .param("searchString", "guest");
+ requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ ResultActions ra = getMockMvc().perform(requestBuilder);
+ assertData(ra);
+ }
+
+ @Test
+ public void getWidgetDataTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/dashboard/widgetData")
+ .param("resourceType", "guest");
+ requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ ResultActions ra = getMockMvc().perform(requestBuilder);
+ assertData(ra);
+ }
+
+ @Test
+ public void getAppsAndContactsTest() throws Exception {
+ url = "/portalApi/contactus/allapps";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getPortalDetailsTest() throws Exception {
+ url = "/portalApi/contactus/feedback";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getAppCategoryFunctionsTest() throws Exception {
+ url = "/portalApi/contactus/functions";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getOnlineUserUpdateRateTest() throws Exception {
+ url = "/portalApi/dashboard/onlineUserUpdateRate";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getMenuIdRoleIdTest() throws Exception {
+ url = "/portalApi/getFunctionalMenuRole";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getNotificationsTest() throws Exception {
+ url = "/portalApi/getNotifications";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getAdminNotificationsTest() throws Exception {
+ url = "/portalApi/getAdminNotifications";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getNotificationAppRolesTest() throws Exception {
+ url = "/portalApi/getNotificationAppRoles";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void getNotificationUpdateRateTest() throws Exception {
+ url = "/portalApi/notificationUpdateRate";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void notificationReadTest() throws Exception {
+ url = "/portalApi/notificationRead?notificationId=262";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void testGetRolesTest() throws Exception {
+ url = "/portalApi/notificationRole/248/roles";
+ requestBuilder(url);
+ }
+
+ @Test
+ public void putAppsWithAdminRoleStateForUserTest() throws Exception {
+
+ AppsListWithAdminRole appsListWithAdminRole = new AppsListWithAdminRole();
+ appsListWithAdminRole.setOrgUserId("guest");
+ ArrayList<AppNameIdIsAdmin> appsRoles = new ArrayList<AppNameIdIsAdmin>();
+ AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin();
+ appNameIdIsAdmin.setId((long) 455);
+ appNameIdIsAdmin.setAppName("CCD");
+ appNameIdIsAdmin.setIsAdmin(true);
+ appNameIdIsAdmin.setRestrictedApp(false);
+ appsRoles.add(appNameIdIsAdmin);
+ appsListWithAdminRole.setAppsRoles(appsRoles);
+ EPUser user = mockUser.mockEPUser();
+ MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/portalApi/adminAppsRoles")
+ .contentType(APPLICATION_JSON_UTF8).content(convertObjectToJsonBytes(appsListWithAdminRole));
+
+ requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
+ ResultActions ra = getMockMvc().perform(requestBuilder);
+ assertData(ra);
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/ApplicationCommonContextTestSuite.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/ApplicationCommonContextTestSuite.java
new file mode 100644
index 00000000..8030dcad
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/ApplicationCommonContextTestSuite.java
@@ -0,0 +1,175 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.framework;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.portalsdk.core.conf.AppConfig;
+//import org.openecomp.portalapp.conf.ExternalAppConfig;
+//import org.openecomp.portalapp.conf.HibernateMappingLocations;
+import org.openecomp.portalsdk.core.conf.HibernateConfiguration;
+import org.openecomp.portalsdk.core.conf.HibernateMappingLocatable;
+import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
+import org.openecomp.portalsdk.core.util.CacheManager;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.transaction.TransactionConfiguration;
+import org.springframework.test.context.web.AnnotationConfigWebContextLoader;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+
+/**
+ *
+ * In order to write a unit test, 1. inherit this class 2. place the "war"
+ * folder on your test class's classpath 3. run the test with the following VM
+ * argument; This is important because when starting the application from
+ * Container, the System Properties file (SystemProperties.java) can have the
+ * direct path but, when running from the Mock Junit container, the path should
+ * be prefixed with "classpath" to enable the mock container to search for the
+ * file in the classpath -Dcontainer.classpath="classpath:"
+ */
+
+@SuppressWarnings("deprecation")
+@RunWith(SpringJUnit4ClassRunner.class)
+@WebAppConfiguration
+@ContextConfiguration(loader = AnnotationConfigWebContextLoader.class, classes = { MockAppConfig.class })
+@ActiveProfiles(value = "test")
+public class ApplicationCommonContextTestSuite {
+
+ @Autowired
+ public WebApplicationContext wac;
+
+ private MockMvc mockMvc;
+
+ @Before
+ public void setup() {
+ if (mockMvc == null) {
+ this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
+
+ }
+ }
+
+ public Object getBean(String name) {
+ return this.wac.getBean(name);
+ }
+
+ public MockMvc getMockMvc() {
+ return mockMvc;
+ }
+
+ public void setMockMvc(MockMvc mockMvc) {
+ this.mockMvc = mockMvc;
+ }
+
+ public WebApplicationContext getWebApplicationContext() {
+ return wac;
+ }
+
+}
+
+@Configuration
+@ComponentScan(basePackages = "org.openecomp", excludeFilters = {
+ // the following source configurations should not be scanned; instead of
+ // using Exclusion filter, we can use the @Profile annotation to exclude
+ // them
+ @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.controller.LogoutController*"),
+ @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.controller.SDKLoginController*"),
+ @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalapp.conf.ExternalAppConfig*"),
+ @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.*.*InitUebHandler*") })
+@Profile("test")
+class MockAppConfig extends AppConfig {
+
+ @Bean
+ HibernateMappingLocatable locatable() {
+ return new MockHibernateMappingLocations();
+ }
+
+ @Bean
+ HibernateConfiguration hibConfiguration() {
+ return new HibernateConfiguration();
+ }
+
+ @Bean
+ public SystemProperties systemProperties() {
+ return new MockSystemProperties();
+ }
+
+ @Bean
+ public AbstractCacheManager cacheManager() {
+ return new CacheManager() {
+
+ public void configure() throws IOException {
+
+ }
+ };
+ }
+
+ public String[] tileDefinitions() {
+ return new String[] { "classpath:/WEB-INF/fusion/defs/definitions.xml",
+ "classpath:/WEB-INF/defs/definitions.xml" };
+ }
+
+ public void addInterceptors(InterceptorRegistry registry) {
+ // registry.addInterceptor(new
+ // SessionTimeoutInterceptor()).excludePathPatterns(getExcludeUrlPathsForSessionTimeout());
+ // registry.addInterceptor(resourceInterceptor());
+ }
+
+ public static class MockSystemProperties extends SystemProperties {
+
+ public MockSystemProperties() {
+ }
+
+ }
+
+}
+
+@Profile("test")
+class MockHibernateMappingLocations implements HibernateMappingLocatable {
+
+ public Resource[] getMappingLocations() {
+ return new Resource[] { new ClassPathResource("WEB-INF/fusion/orm/Fusion.hbm.xml"),
+ new ClassPathResource("WEB-INF/fusion/orm/EP.hbm.xml"),
+ new ClassPathResource("WEB-INF/fusion/orm/Workflow.hbm.xml") };
+
+ }
+
+ public String[] getPackagesToScan() {
+ return new String[] { "org.openecomp", "src" };
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/MockitoTestSuite.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/MockitoTestSuite.java
new file mode 100644
index 00000000..614e2ac3
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/MockitoTestSuite.java
@@ -0,0 +1,70 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.framework;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MockitoTestSuite {
+
+
+ public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper(
+ Mockito.mock(HttpServletRequest.class));
+ public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class);
+
+ public MockHttpServletRequestWrapper getMockedRequest() {
+ return mockedRequest;
+ }
+
+ public HttpServletResponse getMockedResponse() {
+ return mockedResponse;
+ }
+
+ public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper {
+
+ HttpSession session = Mockito.mock(HttpSession.class);
+
+ public MockHttpServletRequestWrapper(HttpServletRequest request) {
+ super(request);
+
+ }
+
+ @Override
+ public HttpSession getSession() {
+
+ return session;
+ }
+
+ @Override
+ public HttpSession getSession(boolean create) {
+
+ return session;
+ }
+
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/FunctionalMenuServiceImplTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/FunctionalMenuServiceImplTest.java
new file mode 100644
index 00000000..7aa2029c
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/FunctionalMenuServiceImplTest.java
@@ -0,0 +1,88 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.test.service;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openecomp.portalapp.portal.service.FunctionalMenuService;
+import org.openecomp.portalapp.portal.test.framework.ApplicationCommonContextTestSuite;
+import org.openecomp.portalapp.portal.transport.BusinessCardApplicationRole;
+import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
+import org.springframework.beans.factory.annotation.Autowired;
+
+
+
+
+public class FunctionalMenuServiceImplTest extends ApplicationCommonContextTestSuite{
+
+
+ @Autowired
+ FunctionalMenuService functionalMenuService;
+
+
+
+ @Test
+ public void getAppListTestService() throws Exception {
+
+ String userId ="guest";
+ List<BusinessCardApplicationRole> userAppRolesActualResult = null;
+
+ List<BusinessCardApplicationRole> userAppRolesExpectedResult = new ArrayList<BusinessCardApplicationRole>();
+ BusinessCardApplicationRole businessCardApplicationRole= new BusinessCardApplicationRole();
+ businessCardApplicationRole.setAppName("ECOMP Portal");
+ businessCardApplicationRole.setRoleName("System Administrator");
+ userAppRolesExpectedResult.add(businessCardApplicationRole);
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("userId", userId);
+ userAppRolesActualResult =functionalMenuService.getUserAppRolesList(userId);
+ assertTrue(userAppRolesActualResult.contains(businessCardApplicationRole));
+
+
+ }
+
+
+ @Test
+ public void getFunctionalMenuRoleTest() throws Exception {
+
+ FunctionalMenuRole expectedFunctionalMenuRole = new FunctionalMenuRole();
+
+ expectedFunctionalMenuRole.setId(new Integer(99999999)) ;
+ expectedFunctionalMenuRole.setMenuId((long) 137);
+ expectedFunctionalMenuRole.setAppId(new Integer(456));
+ expectedFunctionalMenuRole.setRoleId(new Integer(6214));
+ List<FunctionalMenuRole> actualFunctionalMenuRoleList = null;
+ actualFunctionalMenuRoleList = functionalMenuService.getFunctionalMenuRole();
+ assertEquals(expectedFunctionalMenuRole.getAppId(),actualFunctionalMenuRoleList.get(actualFunctionalMenuRoleList.size()-1).getAppId());
+ assertEquals(expectedFunctionalMenuRole.getMenuId(),actualFunctionalMenuRoleList.get(actualFunctionalMenuRoleList.size()-1).getMenuId());
+ assertEquals(expectedFunctionalMenuRole.getId(),actualFunctionalMenuRoleList.get(actualFunctionalMenuRoleList.size()-1).getId());
+ assertEquals(expectedFunctionalMenuRole.getRoleId(),actualFunctionalMenuRoleList.get(actualFunctionalMenuRoleList.size()-1).getRoleId());
+
+ }
+
+}
+
+
diff --git a/ecomp-portal-BE-common-test/src/main/resources/PopulateTestData.sql b/ecomp-portal-BE-common-test/src/main/resources/PopulateTestData.sql
new file mode 100644
index 00000000..6972ec95
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/resources/PopulateTestData.sql
@@ -0,0 +1,28 @@
+---
+-- ================================================================================
+-- ECOMP Portal
+-- ================================================================================
+-- Copyright (C) 2017 AT&T Intellectual Property
+-- ================================================================================
+-- 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.
+-- ================================================================================
+---
+insert into fn_user values(99999999,null,null,'test',null,'test',null,null,null,null,null,null,null,'guest',null,null,null,null,true,null,null,null,null,false,null,null,null,
+null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
+insert into fn_user_role values(99999999,1, null,1);
+insert into fn_user_role values(99999999,16, null,1);
+insert into fn_user_role values(99999999,999, null,1);
+insert into fn_user_role values(99999999,1010, null,1);
+insert into fn_menu_functional values(99999999,3,'Network Analytics',5,'http://vm-d2novasdn3.client.research.att.com:8080/d2novasdn-1/welcome.htm','Y',null);
+insert into fn_menu_functional_roles values(99999999, 137,456, 6214);
+insert into fn_menu_favorites values(3, 141);
diff --git a/ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql b/ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql
new file mode 100644
index 00000000..158508f7
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql
@@ -0,0 +1,27 @@
+---
+-- ================================================================================
+-- ECOMP Portal
+-- ================================================================================
+-- Copyright (C) 2017 AT&T Intellectual Property
+-- ================================================================================
+-- 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.
+-- ================================================================================
+---
+delete from fn_user_role where user_id ='99999999';
+delete from ep_user_notification where user_id='99999999';
+delete from fn_audit_log where user_id='99999999';
+delete from fn_user where user_id='99999999';
+delete from fn_menu_functional_roles where id='99999999';
+delete from fn_menu_functional_ancestors where menu_id=99999999;
+delete from fn_menu_functional where menu_id='99999999';
+delete from fn_menu_favorites where user_id=3 and menu_id=141;