summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common-test/src/main
diff options
context:
space:
mode:
authorChristopher Lott (Christopher) (cl778h) <clott@vm-ep-dev2.client.research.att.com>2017-06-12 09:49:00 -0400
committerChristopher Lott (cl778h) <clott@research.att.com>2017-06-12 13:42:43 -0400
commit627badaf69987c01811c477219fd943757a635f5 (patch)
tree97df9449a411d1ecf830cc76d8afd6f9b5677bda /ecomp-portal-BE-common-test/src/main
parentba838f2e13f1e8050c75e68bd3733d56d8f416d5 (diff)
[PORTAL-16 PORTAL-18] Widget ms; staging
Remove staging repositories from poms. Add widget microservice code base. Add portal unit tests. Repair defects. Normalize line endings. Change-Id: Ia5e48da2a3141b352439ecd548cddf918f4df585 Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
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.java527
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppContactUsControllerTest.java555
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerExternalRequestTest.java503
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerTest.java914
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BEPropertyReaderControllerTest.java73
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BasicAuthAccountControllerTest.java264
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/CommonWidgetControllerTest.java84
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ConsulClientControllerTest.java142
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/DashboardSearchResultControllerTest.java366
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ExternalAppsRestfulControllerTest.java174
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/FunctionalMenuControllerTest.java378
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/GetAccessControllerTest.java71
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ManifestControllerTest.java56
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceControllerTest.java233
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceProxyControllerTest.java106
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/PortalAdminControllerTest.java231
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RolesApprovalSystemControllerTest.java336
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/TicketEventControllerTest.java99
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserControllerTest.java141
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserNotificationControllerTest.java528
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRecommendationControllerTest.java69
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java261
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WebAnalyticsExtAppControllerTest.java131
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WidgetsCatalogMarkupControllerTest.java71
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/MockEPUser.java170
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/PopulateSampleTestData.java132
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RemoveSampleTestData.java131
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/core/RestURLsTestSuite.java662
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/ApplicationCommonContextTestSuite.java350
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/framework/MockitoTestSuite.java140
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/FunctionalMenuServiceImplTest.java161
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/test/framework/ApplicationCommonContextTestSuite.java175
-rw-r--r--ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/test/framework/MockitoTestSuite.java70
-rw-r--r--ecomp-portal-BE-common-test/src/main/resources/PopulateTestData.sql60
-rw-r--r--ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql58
35 files changed, 6356 insertions, 2066 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
index 4e2b842d..23cb7a45 100644
--- 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
@@ -1,264 +1,263 @@
-/*-
- * ================================================================================
- * 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);
-
- }
-
-}
+/*-
+ * ================================================================================
+ * 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.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.transport.AppCatalogPersonalization;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.transport.FieldsValidator.FieldName;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+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
index 9b2add8e..12334d87 100644
--- 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
@@ -1,281 +1,274 @@
-/*-
- * ================================================================================
- * 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");
- }
-
-}
+/*-
+ * ================================================================================
+ * 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.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+
+public class AppContactUsControllerTest extends MockitoTestSuite{
+
+ @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("ECOMP Portal");
+ appContactUsItem.setDescription("Test");
+ appContactUsItem.setContactName("Test");
+ appContactUsItem.setContactEmail("person@onap.org");
+ 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);
+ 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);
+ 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);
+ 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("Ecomp Portal");
+ contactUs.setDescription("Test");
+ contactUs.setContactName("Test");
+ contactUs.setContactEmail("person@onap.org");
+ 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("Ecomp Portal");
+ contactUs.setDescription("Test");
+ contactUs.setContactName("Test");
+ contactUs.setContactEmail("person@onap.org");
+ 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/AppsControllerExternalRequestTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerExternalRequestTest.java
new file mode 100644
index 00000000..ae761a14
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerExternalRequestTest.java
@@ -0,0 +1,503 @@
+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.AppsControllerExternalRequest;
+import org.openecomp.portalapp.portal.domain.EPApp;
+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.AdminRolesService;
+import org.openecomp.portalapp.portal.service.EPAppService;
+import org.openecomp.portalapp.portal.service.PortalAdminService;
+import org.openecomp.portalapp.portal.service.UserService;
+import org.openecomp.portalapp.portal.service.UserServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.transport.OnboardingApp;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+
+public class AppsControllerExternalRequestTest extends MockitoTestSuite {
+
+ @Mock
+ AdminRolesService adminRolesService;
+
+ @Mock
+ EPAppService appService;
+
+ @Mock
+ PortalAdminService portalAdminService;
+
+ @Mock
+ UserService userService = new UserServiceImpl();
+
+ @InjectMocks
+ AppsControllerExternalRequest appsControllerExternalRequest = new AppsControllerExternalRequest();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ MockEPUser mockUser = new MockEPUser();
+ @Mock
+ EPUserUtils ePUserUtils = new EPUserUtils();
+
+ @Test
+ public void postPortalAdminIfUSerNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Missing required field: email, loginId, or loginPwd");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@Research.att.com");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postPortalAdmin(mockedRequest, mockedResponse, user);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postPortalAdminTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("java.lang.NullPointerException");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@Research.att.com");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenThrow(nullPointerException);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postPortalAdmin(mockedRequest, mockedResponse, user);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postPortalAdminCreateUserIfNotFoundTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@Research.att.com");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList);
+ Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postPortalAdmin(mockedRequest, mockedResponse, user);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postPortalAdminCreateUserIfFoundTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@Research.att.com");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList);
+ Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postPortalAdmin(mockedRequest, mockedResponse, user);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postPortalAdminCreateUserIfNotSuperAdminTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@Research.att.com");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList);
+ Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postPortalAdmin(mockedRequest, mockedResponse, user);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postPortalAdminCreateUserIfFieldValidatorErrorTest() throws Exception {
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 500);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("FieldsValidator [httpStatusCode=500, errorCode=null, fields=null]");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ EPUser user = mockUser.mockEPUser();
+ user.setEmail("guestT@Research.att.com");
+ user.setLoginPwd("pwd");
+ user.setLoginId("Test");
+ List<EPUser> expectedList = new ArrayList<EPUser>();
+ expectedList.add(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList);
+ Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postPortalAdmin(mockedRequest, mockedResponse, user);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void getOnboardAppExternalTest() {
+ EPApp epApp = new EPApp();
+ Long appId = (long) 1;
+ Mockito.when(appService.getApp(appId)).thenReturn(epApp);
+ OnboardingApp expectedApp = new OnboardingApp();
+ Mockito.doNothing().when(appService).createOnboardingFromApp(epApp, expectedApp);
+ OnboardingApp actualApp = appsControllerExternalRequest.getOnboardAppExternal(mockedRequest, mockedResponse,
+ appId);
+ assertEquals(expectedApp.getClass(), actualApp.getClass());
+ }
+
+ @Test
+ public void postOnboardAppExternalExceptionTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Unexpected field: id");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = (long) 1;
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void postOnboardAppExternalTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(
+ "Missing required field: name, url, restUrl, restrictedApp, isOpen, isEnabled, myLoginsAppOwner");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = null;
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void postOnboardAppExternalNotNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Failed to find user: Test_Owener");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = null;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.myLoginsAppOwner = "Test_Owener";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ Mockito.when(userService.getUserByUserId(expectedOnboardingApp.myLoginsAppOwner)).thenReturn(null);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void postOnboardAppExternalIfUSerListNotNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("User lacks Portal admin role: null");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = null;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.myLoginsAppOwner = "Test_Owener";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ List<EPUser> userList = new ArrayList<EPUser>();
+ EPUser user = mockUser.mockEPUser();
+ userList.add(user);
+ Mockito.when(userService.getUserByUserId(expectedOnboardingApp.myLoginsAppOwner)).thenReturn(userList);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void postOnboardAppExternalIfSuperAdminTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = null;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.myLoginsAppOwner = "Test_Owener";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ List<EPUser> userList = new ArrayList<EPUser>();
+ EPUser user = mockUser.mockEPUser();
+ userList.add(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(userService.getUserByUserId(expectedOnboardingApp.myLoginsAppOwner)).thenReturn(userList);
+ Mockito.when(appService.addOnboardingApp(expectedOnboardingApp, user)).thenReturn(expectedFieldValidator);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void postOnboardAppExternalFieldValidatorTestTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("FieldsValidator [httpStatusCode=500, errorCode=null, fields=null]");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = null;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.myLoginsAppOwner = "Test_Owener";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ List<EPUser> userList = new ArrayList<EPUser>();
+ EPUser user = mockUser.mockEPUser();
+ userList.add(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 500);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(userService.getUserByUserId(expectedOnboardingApp.myLoginsAppOwner)).thenReturn(userList);
+ Mockito.when(appService.addOnboardingApp(expectedOnboardingApp, user)).thenReturn(expectedFieldValidator);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+
+ }
+
+ @Test
+ public void putOnboardAppExternalifAppNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Unexpected value for field: id");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Long appId = null;
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = null;
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void putOnboardAppExternalIfOnboardingAppDetailsNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(
+ "Missing required field: name, url, restUrl, restrictedApp, isOpen, isEnabled, myLoginsAppOwner");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Long appId = (long) 1;
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = (long) 1;
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void putOnboardAppExternalIfOnboardingIfUserListNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Failed to find user: Test_Owener");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Long appId = (long) 1;
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = (long) 1;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.myLoginsAppOwner = "Test_Owener";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ Mockito.when(userService.getUserByUserId(expectedOnboardingApp.myLoginsAppOwner)).thenReturn(null);
+
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void putOnboardAppExternalIfOnboardingIfUserListNotNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("User lacks Portal admin role: null");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Long appId = (long) 1;
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = (long) 1;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.myLoginsAppOwner = "Test_Owener";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ List<EPUser> userList = new ArrayList<EPUser>();
+ EPUser user = mockUser.mockEPUser();
+ userList.add(user);
+ Mockito.when(userService.getUserByUserId(expectedOnboardingApp.myLoginsAppOwner)).thenReturn(userList);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void putOnboardAppExternalIfOnboardingIfSuperAdminTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ Long appId = (long) 1;
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = (long) 1;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.myLoginsAppOwner = "Test_Owener";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ List<EPUser> userList = new ArrayList<EPUser>();
+ EPUser user = mockUser.mockEPUser();
+ userList.add(user);
+ Mockito.when(appService.modifyOnboardingApp(expectedOnboardingApp, user)).thenReturn(expectedFieldValidator);
+ Mockito.when(userService.getUserByUserId(expectedOnboardingApp.myLoginsAppOwner)).thenReturn(userList);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void putOnboardAppExternalIfOnboardingIfStatusNotSuccessTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("FieldsValidator [httpStatusCode=500, errorCode=null, fields=null]");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Long appId = (long) 1;
+ OnboardingApp expectedOnboardingApp = new OnboardingApp();
+ expectedOnboardingApp.id = (long) 1;
+ expectedOnboardingApp.name = "Test";
+ expectedOnboardingApp.url = "Test";
+ expectedOnboardingApp.restUrl = "Test";
+ expectedOnboardingApp.myLoginsAppOwner = "Test_Owener";
+ expectedOnboardingApp.restrictedApp = false;
+ expectedOnboardingApp.isOpen = false;
+ expectedOnboardingApp.isEnabled = false;
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 500);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+
+ List<EPUser> userList = new ArrayList<EPUser>();
+ EPUser user = mockUser.mockEPUser();
+ userList.add(user);
+ Mockito.when(appService.modifyOnboardingApp(expectedOnboardingApp, user)).thenReturn(expectedFieldValidator);
+ Mockito.when(userService.getUserByUserId(expectedOnboardingApp.myLoginsAppOwner)).thenReturn(userList);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> actualPortalRestResponse = appsControllerExternalRequest
+ .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp);
+ assertEquals(actualPortalRestResponse, expectedportalRestResponse);
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerTest.java
new file mode 100644
index 00000000..4b6849a6
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/AppsControllerTest.java
@@ -0,0 +1,914 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+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.AppsController;
+import org.openecomp.portalapp.portal.domain.AdminUserApplications;
+import org.openecomp.portalapp.portal.domain.AppIdAndNameTransportModel;
+import org.openecomp.portalapp.portal.domain.AppsResponse;
+import org.openecomp.portalapp.portal.domain.EPApp;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.domain.EcompApp;
+import org.openecomp.portalapp.portal.domain.UserRole;
+import org.openecomp.portalapp.portal.domain.UserRoles;
+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.EPLeftMenuService;
+import org.openecomp.portalapp.portal.service.EPLeftMenuServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.transport.EPAppsManualPreference;
+import org.openecomp.portalapp.portal.transport.EPAppsSortPreference;
+import org.openecomp.portalapp.portal.transport.EPDeleteAppsManualSortPref;
+import org.openecomp.portalapp.portal.transport.EPWidgetsSortPreference;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.transport.LocalRole;
+import org.openecomp.portalapp.portal.transport.OnboardingApp;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.openecomp.portalsdk.core.web.support.AppUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.MediaType;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({SystemProperties.class,AppUtils.class, EPUserUtils.class, MediaType.class})
+public class AppsControllerTest extends MockitoTestSuite{
+
+ @InjectMocks
+ AppsController appsController = new AppsController();
+
+ @Mock
+ AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @Mock
+ EPAppService appService = new EPAppCommonServiceImpl();
+
+ @Mock
+ EPLeftMenuService leftMenuService = new EPLeftMenuServiceImpl();
+
+ @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();
+
+ @Mock
+ AppUtils appUtils = new AppUtils();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void getUserAppsTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EcompApp> expectedEcompApps = new ArrayList<EcompApp>();
+
+ EcompApp ecompApp = new EcompApp();
+ ecompApp.setId((long) 1);
+ ecompApp.setName("Test_app");
+ ecompApp.setUrl("Test_URL");
+ ecompApp.setUebKey("Test_key");
+ ecompApp.setAlternateUrl("Test_alt_URL");
+ expectedEcompApps.add(ecompApp);
+ List<EcompApp> actualEcompApps = new ArrayList<EcompApp>();
+ Mockito.when(appService.transformAppsToEcompApps(appService.getUserApps(user))).thenReturn(expectedEcompApps);
+ actualEcompApps = appsController.getUserApps(mockedRequest, mockedResponse);
+ assertEquals(expectedEcompApps, actualEcompApps);
+ }
+
+ @Test
+ public void getUserAppsNoUserTest() {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(appService.transformAppsToEcompApps(appService.getUserApps(user))).thenReturn(null);
+ assertNull(appsController.getUserApps(mockedRequest, mockedResponse));
+
+ }
+
+ @Test
+ public void getUserAppsExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(appService.transformAppsToEcompApps(appService.getUserApps(user))).thenThrow(nullPointerException);
+ assertNull(appsController.getUserApps(mockedRequest, mockedResponse));
+
+ }
+
+ @Test
+ public void getPersUserAppsIfUserIsAdminTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EcompApp> expectedEcompApps = new ArrayList<EcompApp>();
+
+ EcompApp ecompApp = new EcompApp();
+ ecompApp.setId((long) 1);
+ ecompApp.setName("Test_app");
+ ecompApp.setUrl("Test_URL");
+ ecompApp.setUebKey("Test_key");
+ ecompApp.setAlternateUrl("Test_alt_URL");
+ expectedEcompApps.add(ecompApp);
+ List<EcompApp> actualEcompApps = new ArrayList<EcompApp>();
+
+ List<EPApp> expectedApps = new ArrayList<EPApp>();
+
+ 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);
+
+ expectedApps.add(app);
+
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getPersAdminApps(user)).thenReturn(expectedApps);
+
+ Mockito.when(appService.transformAppsToEcompApps(expectedApps)).thenReturn(expectedEcompApps);
+ actualEcompApps = appsController.getPersUserApps(mockedRequest, mockedResponse);
+ assertEquals(expectedEcompApps, actualEcompApps);
+ }
+
+ @Test
+ public void getPersUserAppsIfUserNotAdminTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EcompApp> expectedEcompApps = new ArrayList<EcompApp>();
+
+ EcompApp ecompApp = new EcompApp();
+ ecompApp.setId((long) 1);
+ ecompApp.setName("Test_app");
+ ecompApp.setUrl("Test_URL");
+ ecompApp.setUebKey("Test_key");
+ ecompApp.setAlternateUrl("Test_alt_URL");
+ expectedEcompApps.add(ecompApp);
+ List<EcompApp> actualEcompApps = new ArrayList<EcompApp>();
+
+ List<EPApp> expectedApps = new ArrayList<EPApp>();
+
+ 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);
+
+ expectedApps.add(app);
+
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(appService.getPersUserApps(user)).thenReturn(expectedApps);
+ Mockito.when(appService.transformAppsToEcompApps(expectedApps)).thenReturn(expectedEcompApps);
+ actualEcompApps = appsController.getPersUserApps(mockedRequest, mockedResponse);
+ assertEquals(expectedEcompApps, actualEcompApps);
+ }
+
+ @Test
+ public void getPersUserAppsIfUserNullTest() throws IOException {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ assertNull(appsController.getPersUserApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getPersUserAppsExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getPersAdminApps(user)).thenThrow(nullPointerException);
+ assertNull(appsController.getPersUserApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAdminAppsIfNotAdminTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false);
+ assertNull(appsController.getAdminApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAdminAppsTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<AppIdAndNameTransportModel> expectedAdminApps = new ArrayList<AppIdAndNameTransportModel>();
+ AppIdAndNameTransportModel appIdAndNameTransportModel = new AppIdAndNameTransportModel();
+ appIdAndNameTransportModel.setId((long) 1);
+ appIdAndNameTransportModel.setName("Test_app");
+ expectedAdminApps.add(appIdAndNameTransportModel);
+ List<AppIdAndNameTransportModel> actualAdminApps = new ArrayList<AppIdAndNameTransportModel>();
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAdminApps(user)).thenReturn(expectedAdminApps);
+ actualAdminApps = appsController.getAdminApps(mockedRequest, mockedResponse);
+ assertEquals(actualAdminApps, expectedAdminApps);
+
+ }
+
+ @Test
+ public void getAdminAppsExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAdminApps(user)).thenThrow(nullPointerException);
+ assertNull(appsController.getAdminApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppsForSuperAdminAndAccountAdminifOnlyAccountAdminTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false);
+ assertNull(appsController.getAppsForSuperAdminAndAccountAdmin(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppsForSuperAdminAndAccountAdminTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<AppIdAndNameTransportModel> expectedAdminApps = new ArrayList<AppIdAndNameTransportModel>();
+ AppIdAndNameTransportModel appIdAndNameTransportModel = new AppIdAndNameTransportModel();
+ appIdAndNameTransportModel.setId((long) 1);
+ appIdAndNameTransportModel.setName("Test_app");
+ expectedAdminApps.add(appIdAndNameTransportModel);
+ List<AppIdAndNameTransportModel> actualAdminApps = new ArrayList<AppIdAndNameTransportModel>();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAppsForSuperAdminAndAccountAdmin(user)).thenReturn(expectedAdminApps);
+ actualAdminApps = appsController.getAppsForSuperAdminAndAccountAdmin(mockedRequest, mockedResponse);
+ assertEquals(actualAdminApps, expectedAdminApps);
+
+ }
+
+ @Test
+ public void getAppsForSuperAdminExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false);
+ Mockito.when(appService.getAppsForSuperAdminAndAccountAdmin(user)).thenThrow(nullPointerException);
+ assertNull(appsController.getAppsForSuperAdminAndAccountAdmin(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void putUserAppsSortingManualTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPAppsManualPreference> ePAppsManualPreference = new ArrayList<EPAppsManualPreference>();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ Mockito.when(appService.saveAppsSortManual(ePAppsManualPreference, user)).thenReturn(expectedFieldValidator);
+ actualFieldValidator = appsController.putUserAppsSortingManual(mockedRequest, ePAppsManualPreference,
+ mockedResponse);
+ assertEquals(actualFieldValidator, expectedFieldValidator);
+ }
+
+ @Test
+ public void putUserAppsSortingManualExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPAppsManualPreference> ePAppsManualPreference = new ArrayList<EPAppsManualPreference>();
+ Mockito.when(appService.saveAppsSortManual(ePAppsManualPreference, user)).thenThrow(nullPointerException);
+ assertNull(appsController.putUserAppsSortingManual(mockedRequest, ePAppsManualPreference, mockedResponse));
+ }
+
+ @Test
+ public void putUserWidgetsSortManualTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPWidgetsSortPreference> ePWidgetsSortPreference = new ArrayList<EPWidgetsSortPreference>();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ Mockito.when(appService.saveWidgetsSortManual(ePWidgetsSortPreference, user))
+ .thenReturn(expectedFieldValidator);
+ actualFieldValidator = appsController.putUserWidgetsSortManual(mockedRequest, ePWidgetsSortPreference,
+ mockedResponse);
+ assertEquals(actualFieldValidator, expectedFieldValidator);
+ }
+
+ @Test
+ public void putUserWidgetsSortManualExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPAppsManualPreference> ePAppsManualPreference = new ArrayList<EPAppsManualPreference>();
+ Mockito.when(appService.saveAppsSortManual(ePAppsManualPreference, user)).thenThrow(nullPointerException);
+ assertNull(appsController.putUserAppsSortingManual(mockedRequest, ePAppsManualPreference, mockedResponse));
+ }
+
+ @Test
+ public void putUserWidgetsSortPrefTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPWidgetsSortPreference> ePWidgetsSortPreference = new ArrayList<EPWidgetsSortPreference>();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ Mockito.when(appService.deleteUserWidgetSortPref(ePWidgetsSortPreference, user))
+ .thenReturn(expectedFieldValidator);
+ actualFieldValidator = appsController.putUserWidgetsSortPref(mockedRequest, ePWidgetsSortPreference,
+ mockedResponse);
+ assertEquals(actualFieldValidator, expectedFieldValidator);
+ }
+
+ @Test
+ public void putUserWidgetsSortPrefExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPWidgetsSortPreference> ePWidgetsSortPreference = new ArrayList<EPWidgetsSortPreference>();
+ Mockito.when(appService.deleteUserWidgetSortPref(ePWidgetsSortPreference, user))
+ .thenThrow(nullPointerException);
+ assertNull(appsController.putUserWidgetsSortPref(mockedRequest, ePWidgetsSortPreference, mockedResponse));
+ }
+
+ @Test
+ public void deleteUserAppSortManualTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ EPDeleteAppsManualSortPref epDeleteAppsManualSortPref = new EPDeleteAppsManualSortPref();
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ Mockito.when(appService.deleteUserAppSortManual(epDeleteAppsManualSortPref, user))
+ .thenReturn(expectedFieldValidator);
+ actualFieldValidator = appsController.deleteUserAppSortManual(mockedRequest, epDeleteAppsManualSortPref,
+ mockedResponse);
+ assertEquals(actualFieldValidator, expectedFieldValidator);
+ }
+
+ @Test
+ public void deleteUserAppSortManualExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ EPDeleteAppsManualSortPref epDeleteAppsManualSortPref = new EPDeleteAppsManualSortPref();
+ Mockito.when(appService.deleteUserAppSortManual(epDeleteAppsManualSortPref, user))
+ .thenThrow(nullPointerException);
+ assertNull(appsController.deleteUserAppSortManual(mockedRequest, epDeleteAppsManualSortPref, mockedResponse));
+ }
+
+ @Test
+ public void putUserAppsSortingPreferenceTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ EPAppsSortPreference userAppsValue = new EPAppsSortPreference();
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ Mockito.when(appService.saveAppsSortPreference(userAppsValue, user)).thenReturn(expectedFieldValidator);
+ actualFieldValidator = appsController.putUserAppsSortingPreference(mockedRequest, userAppsValue,
+ mockedResponse);
+ assertEquals(actualFieldValidator, expectedFieldValidator);
+ }
+
+ @Test
+ public void putUserAppsSortingPreferenceExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ EPAppsSortPreference userAppsValue = new EPAppsSortPreference();
+ Mockito.when(appService.saveAppsSortPreference(userAppsValue, user)).thenThrow(nullPointerException);
+ assertNull(appsController.putUserAppsSortingPreference(mockedRequest, userAppsValue, mockedResponse));
+ }
+
+ @Test
+ public void getUserAppsSortTypePreferenceTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String expectedUserSortPreference = "TEST_DECE";
+ String actualUserSortPreference = new String();
+ Mockito.when(appService.getUserAppsSortTypePreference(user)).thenReturn(expectedUserSortPreference);
+ actualUserSortPreference = appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse);
+ assertEquals(actualUserSortPreference, expectedUserSortPreference);
+ }
+
+ @Test
+ public void getUserAppsSortTypePreferenceExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(appService.getUserAppsSortTypePreference(user)).thenThrow(nullPointerException);
+ assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getUserAppsSortTypePreferenceIfUserNullTest() throws IOException {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(appService.getUserAppsSortTypePreference(user)).thenThrow(nullPointerException);
+ assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppsAdministratorsTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<AdminUserApplications> expecteAdminUserApplications = new ArrayList<AdminUserApplications>();
+ List<AdminUserApplications> actualAdminUserApplications = new ArrayList<AdminUserApplications>();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAppsAdmins()).thenReturn(expecteAdminUserApplications);
+ actualAdminUserApplications = appsController.getAppsAdministrators(mockedRequest, mockedResponse);
+ assertEquals(expecteAdminUserApplications, actualAdminUserApplications);
+ }
+
+ @Test
+ public void getAppsAdministratorsIfUserNotSuperAdminTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppsAdministratorsExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAppsAdmins()).thenThrow(nullPointerException);
+ assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppsTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<AppsResponse> expectedApps = new ArrayList<AppsResponse>();
+ AppsResponse apps = new AppsResponse((long) 1, "test", true, true);
+ expectedApps.add(apps);
+
+ List<AppsResponse> atualApps = new ArrayList<AppsResponse>();
+
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAllApps(false)).thenReturn(expectedApps);
+ atualApps = appsController.getApps(mockedRequest, mockedResponse);
+ assertEquals(expectedApps, atualApps);
+ }
+
+ @Test
+ public void getAppsExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ assertNull(appsController.getApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppsIfUserNotSuperAdminTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAllApps(false)).thenThrow(nullPointerException);
+ assertNull(appsController.getApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAllAppsTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<AppsResponse> expectedApps = new ArrayList<AppsResponse>();
+ AppsResponse apps = new AppsResponse((long) 1, "test", true, true);
+ expectedApps.add(apps);
+ List<AppsResponse> atualApps = new ArrayList<AppsResponse>();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAllApps(true)).thenReturn(expectedApps);
+ atualApps = appsController.getAllApps(mockedRequest, mockedResponse);
+ assertEquals(expectedApps, atualApps);
+ }
+
+ @Test
+ public void getAllAppsExceptionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ assertNull(appsController.getAllApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAllAppsIfUserNotSuperAdminTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getAllApps(true)).thenThrow(nullPointerException);
+ assertNull(appsController.getAllApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppsFullListTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EcompApp> expectedEcompApps = new ArrayList<EcompApp>();
+
+ EcompApp ecompApp = new EcompApp();
+ ecompApp.setId((long) 1);
+ ecompApp.setName("Test_app");
+ ecompApp.setUrl("Test_URL");
+ ecompApp.setUebKey("Test_key");
+ ecompApp.setAlternateUrl("Test_alt_URL");
+ expectedEcompApps.add(ecompApp);
+ List<EcompApp> actualEcompApps = new ArrayList<EcompApp>();
+ Mockito.when(appService.getEcompAppAppsFullList()).thenReturn(expectedEcompApps);
+ actualEcompApps = appsController.getAppsFullList(mockedRequest, mockedResponse);
+ assertEquals(expectedEcompApps, actualEcompApps);
+ }
+
+// @Test
+// public void getAppsFullListNoUserTest() {
+// EPUser user = null;
+// Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+// Mockito.when(appService.getEcompAppAppsFullList()).thenReturn(null);
+// assertNull(appsController.getAppsFullList(mockedRequest, mockedResponse));
+//
+// }
+
+ @Test
+ public void getUserProfileTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ UserRole userRole = new UserRole();
+ userRole.setUser_Id((long) 1);
+ userRole.setOrgUserId("guest");
+ userRole.setFirstName("Test_User_FirstName");
+ userRole.setLastName("Test_User_LastName");
+ userRole.setRoleId((long) 1);
+ userRole.setRoleName("test");
+
+ UserRoles unexpectedserAndRoles = new UserRoles(userRole);
+ unexpectedserAndRoles.setFirstName("Test_User_FirstName");
+ unexpectedserAndRoles.setLastName("Test_User_LastName");
+ unexpectedserAndRoles.setGuestSession(false);
+ unexpectedserAndRoles.setOrgUserId("guest");
+ List<String> roles = new ArrayList<String>();
+ roles.add("Test");
+ unexpectedserAndRoles.setRoles(roles);
+ Mockito.when(appService.getUserProfileNormalized(user)).thenReturn(unexpectedserAndRoles);
+ UserRoles actualUserAndRoles = appsController.getUserProfile(mockedRequest, mockedResponse);
+ assertEquals(unexpectedserAndRoles, actualUserAndRoles);
+ }
+
+ @Test
+ public void getUserProfileIfUserNullTest() throws IOException {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(appService.getUserProfileNormalized(user)).thenReturn(null);
+ assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getUserProfileExcpetionTest() throws IOException {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(appService.getUserProfileNormalized(user)).thenThrow(nullPointerException);
+ assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppRolesTest() {
+ List<LocalRole> expectedRoleList = new ArrayList<LocalRole>();
+ LocalRole localRole = new LocalRole();
+ localRole.setRoleId(1);
+ localRole.setRolename("test");
+ expectedRoleList.add(localRole);
+ long appId = 1;
+ Mockito.when(appService.getAppRoles(appId)).thenReturn(expectedRoleList);
+ List<LocalRole> actualRoleList = appsController.getAppRoles(mockedRequest, appId);
+ assertEquals(actualRoleList, expectedRoleList);
+ }
+
+ @Test
+ public void getAppRolesExceptionTest() {
+ long appId = 1;
+ Mockito.when(appService.getAppRoles(appId)).thenThrow(nullPointerException);
+ assertNull(appsController.getAppRoles(mockedRequest, appId));
+ }
+
+ @Test
+ public void getOnboardingAppsTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<OnboardingApp> expectedOnboardingApps = new ArrayList<OnboardingApp>();
+ OnboardingApp onboardingApp = new OnboardingApp();
+ onboardingApp.setUebKey("test");
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getOnboardingApps()).thenReturn(expectedOnboardingApps);
+ List<OnboardingApp> actualOnboardingApps = appsController.getOnboardingApps(mockedRequest, mockedResponse);
+ assertEquals(expectedOnboardingApps, actualOnboardingApps);
+ }
+
+ @Test
+ public void getOnboardingAppsifSuperAdiminTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ assertNull(appsController.getOnboardingApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getOnboardingAppsExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(!adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.getOnboardingApps()).thenThrow(nullPointerException);
+ assertNull(appsController.getOnboardingApps(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void putOnboardingAppTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingApp OnboardingApp = new OnboardingApp();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator);
+ FieldsValidator actualFieldValidator = appsController.putOnboardingApp(mockedRequest, OnboardingApp,
+ mockedResponse);
+ assertEquals(expectedFieldValidator, actualFieldValidator);
+ }
+
+ @Test
+ public void putOnboardingAppIfSuperAdminTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator expectedFieldValidator = null;
+ OnboardingApp OnboardingApp = new OnboardingApp();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator);
+ assertNull(appsController.putOnboardingApp(mockedRequest, OnboardingApp, mockedResponse));
+ }
+
+ @Test
+ public void putOnboardingAppExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingApp OnboardingApp = new OnboardingApp();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenThrow(nullPointerException);
+ assertNull(appsController.putOnboardingApp(mockedRequest, OnboardingApp, mockedResponse));
+ }
+
+ @Test
+ public void postOnboardingAppTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingApp OnboardingApp = new OnboardingApp();
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.addOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator);
+ FieldsValidator actualFieldValidator = appsController.postOnboardingApp(mockedRequest, OnboardingApp,
+ mockedResponse);
+ assertEquals(expectedFieldValidator, actualFieldValidator);
+ }
+
+ @Test
+ public void postOnboardingAppIfSuperAdminTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator expectedFieldValidator = null;
+ OnboardingApp OnboardingApp = new OnboardingApp();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(appService.addOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator);
+ assertNull(appsController.postOnboardingApp(mockedRequest, OnboardingApp, mockedResponse));
+ }
+
+ @Test
+ public void postOnboardingAppExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ OnboardingApp OnboardingApp = new OnboardingApp();
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(appService.addOnboardingApp(OnboardingApp, user)).thenThrow(nullPointerException);
+ assertNull(appsController.postOnboardingApp(mockedRequest, OnboardingApp, mockedResponse));
+ }
+
+ @Test
+ public void deleteOnboardingAppTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ long appId = 1;
+ Mockito.when(appService.deleteOnboardingApp(user,appId )).thenReturn(expectedFieldValidator);
+ FieldsValidator actualFieldValidator = appsController.deleteOnboardingApp(mockedRequest,appId,
+ mockedResponse);
+ assertEquals(expectedFieldValidator, actualFieldValidator);
+ }
+
+ @Test
+ public void deleteOnboardingAppIfSuperAdminTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ FieldsValidator expectedFieldValidator = null;
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ long appId = 1;
+ Mockito.when(appService.deleteOnboardingApp(user,appId)).thenReturn(expectedFieldValidator);
+ assertNull(appsController.deleteOnboardingApp(mockedRequest,appId,mockedResponse));
+ }
+
+ @Test
+ public void deleteOnboardingAppExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ long appId = 1;
+ Mockito.when(appService.deleteOnboardingApp(user,appId)).thenThrow(nullPointerException);
+ assertNull(appsController.deleteOnboardingApp(mockedRequest,appId,mockedResponse));
+ }
+
+ @Test
+ public void getLeftMenuItemsTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ String menuList = "Test";
+ PowerMockito.mockStatic(EPUserUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Set menuSet = new HashSet<>();
+ menuSet.add(1);
+ Mockito.when(AppUtils.getSession(mockedRequest)
+ .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuSet);
+ Mockito.when(AppUtils.getSession(mockedRequest)
+ .getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME))).thenReturn(menuSet);
+ Mockito.when(leftMenuService.getLeftMenuItems(user, menuSet, menuSet)).thenReturn(menuList);
+ String response = appsController.getLeftMenuItems(mockedRequest, mockedResponse);
+ assertTrue(response.equals("Test"));
+ }
+
+ @Test
+ public void getLeftMenuItemsExceptionTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ String menuList = "Test";
+ PowerMockito.mockStatic(EPUserUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Set menuSet = new HashSet<>();
+ menuSet.add(1);
+ Mockito.when(AppUtils.getSession(mockedRequest)
+ .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuSet);
+ Mockito.when(AppUtils.getSession(mockedRequest)
+ .getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME))).thenReturn(menuSet);
+ Mockito.when(leftMenuService.getLeftMenuItems(user, menuSet, menuSet)).thenThrow(nullPointerException);
+ assertNull(appsController.getLeftMenuItems(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getAppThumbnailExceptionTest()
+ {
+ EPApp app = null;
+ assertNull(appsController.getAppThumbnail(mockedRequest, (long) 1, mockedResponse));
+ }
+
+ @Test
+ public void getAppThumbnailTest()
+ {
+ EPApp app = new EPApp();
+ app.setName("Test");
+ app.setImageUrl("test");
+ app.setDescription("test");
+ app.setNotes("test");
+ app.setUrl("test");
+ app.setId((long) 1);
+ app.setAppType(1);
+ app.setImageUrl("www.ecomp.com");
+ app.setThumbnail(new byte[] {1, 6, 3});
+ Mockito.when(appService.getApp((long) 1)).thenReturn(app);
+ HttpEntity<byte[]> response = appsController.getAppThumbnail(mockedRequest, (long) 1, mockedResponse);
+ assertEquals(response.getHeaders().getContentLength(), 3);
+ }
+
+ @Test
+ public void getAppThumbnailForMediaTypePngTest()
+ {
+
+ EPApp app = new EPApp();
+ app.setName("Test");
+ app.setImageUrl("test");
+ app.setDescription("test");
+ app.setNotes("test");
+ app.setUrl("test");
+ app.setId((long) 1);
+ app.setAppType(1);
+ app.setImageUrl("www.ecomp.png");
+ app.setThumbnail(new byte[] {1, 6, 3});
+ Mockito.when(appService.getApp((long) 1)).thenReturn(app);
+ PowerMockito.mockStatic(MediaType.class);
+ HttpEntity<byte[]> response = appsController.getAppThumbnail(mockedRequest, (long) 1, mockedResponse);
+ assertEquals(response.getHeaders().getContentLength(), 3);
+ }
+
+ @Test
+ public void getUserAppsOrderBySortPrefIfUSerNullTest(){
+ List<EcompApp> listOfApps = new ArrayList<EcompApp>();
+
+ EcompApp app = new EcompApp();
+ listOfApps.add(app);
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null);
+ assertNull(appsController.getUserAppsOrderBySortPref(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void getUserAppsOrderBySortPrefTest(){
+ List<EcompApp> listOfApps = new ArrayList<EcompApp>();
+
+ EcompApp app = new EcompApp();
+ listOfApps.add(app);
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("mparams")).thenReturn("");
+ Mockito.when(appService.transformAppsToEcompApps(appService.getAppsOrderByName(user))).thenReturn(listOfApps);
+ List<EcompApp> listOfActualApps = appsController.getUserAppsOrderBySortPref(mockedRequest, mockedResponse);
+ assertEquals(listOfActualApps.size(), 1);
+ }
+
+ @Test
+ public void getUserAppsOrderBySortPrefIfusrSortPrefIsMTest(){
+ List<EcompApp> listOfApps = new ArrayList<EcompApp>();
+
+ EcompApp app = new EcompApp();
+ listOfApps.add(app);
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("mparams")).thenReturn("M");
+ Mockito.when(appService.transformAppsToEcompApps(appService.getAppsOrderByName(user))).thenReturn(listOfApps);
+ List<EcompApp> listOfActualApps = appsController.getUserAppsOrderBySortPref(mockedRequest, mockedResponse);
+ assertEquals(listOfActualApps.size(), 1);
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BEPropertyReaderControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BEPropertyReaderControllerTest.java
new file mode 100644
index 00000000..b621d9ad
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BEPropertyReaderControllerTest.java
@@ -0,0 +1,73 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.portal.controller.BEPropertyReaderController;
+import org.openecomp.portalapp.portal.domain.BEProperty;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(SystemProperties.class)
+public class BEPropertyReaderControllerTest extends MockitoTestSuite {
+
+ @InjectMocks
+ BEPropertyReaderController bEPropertyReaderController = new BEPropertyReaderController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void readPropertyTest() {
+ String key = "DOMAIN_CLASS_LOCATION";
+ BEProperty beProperty = new BEProperty("DOMAIN_CLASS_LOCATION", "domain_class_location");
+ PortalRestResponse<BEProperty> ecpectedPortalRestResponse = new PortalRestResponse<BEProperty>();
+ ecpectedPortalRestResponse.setMessage("success");
+ ecpectedPortalRestResponse.setResponse(beProperty);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK);
+ PortalRestResponse<BEProperty> actualPortalRestResponse = null;
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(SystemProperties.getProperty("DOMAIN_CLASS_LOCATION")).thenReturn("domain_class_location");
+ actualPortalRestResponse = bEPropertyReaderController.readProperty(mockedRequest, key);
+ assertTrue(actualPortalRestResponse.equals(ecpectedPortalRestResponse));
+
+ }
+
+ @Test
+ public void readPropertyExceptionTest() {
+ String key =null;
+ //BEProperty beProperty = new BEProperty("DOMAIN_CLASS_LOCATION", "domain_class_location");
+ PortalRestResponse<BEProperty> ecpectedPortalRestResponse = new PortalRestResponse<BEProperty>();
+ ecpectedPortalRestResponse.setMessage("java.lang.NullPointerException");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ PortalRestResponse<BEProperty> actualPortalRestResponse = null;
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(new BEProperty(key, SystemProperties.getProperty(key))).thenThrow(nullPointerException);
+ actualPortalRestResponse = bEPropertyReaderController.readProperty(mockedRequest, key);
+ System.out.println(actualPortalRestResponse);
+ assertTrue(actualPortalRestResponse.equals(ecpectedPortalRestResponse));
+
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BasicAuthAccountControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BasicAuthAccountControllerTest.java
new file mode 100644
index 00000000..70505274
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/BasicAuthAccountControllerTest.java
@@ -0,0 +1,264 @@
+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.BasicAuthAccountController;
+import org.openecomp.portalapp.portal.domain.BasicAuthCredentials;
+import org.openecomp.portalapp.portal.domain.EPEndpoint;
+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.AdminRolesService;
+import org.openecomp.portalapp.portal.service.AdminRolesServiceImpl;
+import org.openecomp.portalapp.portal.service.BasicAuthAccountService;
+import org.openecomp.portalapp.portal.service.BasicAuthAccountServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+
+public class BasicAuthAccountControllerTest extends MockitoTestSuite {
+
+ @Mock
+ BasicAuthAccountService basicAuthAccountService = new BasicAuthAccountServiceImpl();
+
+ @Mock
+ AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @InjectMocks
+ BasicAuthAccountController basicAuthAccountController = new BasicAuthAccountController();
+
+ @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();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ public BasicAuthCredentials basicAuthCredentials() {
+ BasicAuthCredentials basicAuthCredentials = new BasicAuthCredentials();
+
+ basicAuthCredentials.setId((long) 1);
+ basicAuthCredentials.setApplicationName("test");
+ basicAuthCredentials.setUsername("Test");
+ basicAuthCredentials.setPassword("Password");
+ basicAuthCredentials.setIsActive("YES");
+
+ List<EPEndpoint> endpoints = new ArrayList<EPEndpoint>();
+
+ EPEndpoint ePEndpoint = new EPEndpoint();
+ ePEndpoint.setId((long) 1);
+ ePEndpoint.setName("Test");
+ endpoints.add(ePEndpoint);
+ basicAuthCredentials.setEndpoints(endpoints);
+
+ return basicAuthCredentials;
+
+ }
+
+ @Test
+ public void createBasicAuthAccountTest() throws Exception {
+ BasicAuthCredentials basicAuthCredentials = basicAuthCredentials();
+
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("SUCCESS");
+ expectedResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.OK);
+ long accountd = 1;
+
+ Mockito.when(basicAuthAccountService.saveBasicAuthAccount(basicAuthCredentials)).thenReturn(accountd);
+
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest,
+ mockedResponse, basicAuthCredentials);
+ assertEquals(actualResponse, expectedResponse);
+ }
+
+ @Test
+ public void createBasicAuthAccountAdminTest() throws Exception {
+ BasicAuthCredentials basicAuthCredentials = basicAuthCredentials();
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("Authorization Required");
+ expectedResponse.setResponse("Admin Only Operation! ");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.ERROR);
+
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest,
+ mockedResponse, basicAuthCredentials);
+ assertEquals(actualResponse, expectedResponse);
+ }
+
+ @Test
+ public void createBasicAuthAccountIfInputNullTest() throws Exception {
+ BasicAuthCredentials basicAuthCredentials = null;
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("FAILURE");
+ expectedResponse.setResponse("newBasicAuthAccount cannot be null or empty");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.ERROR);
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest,
+ mockedResponse, basicAuthCredentials);
+ assertEquals(actualResponse, expectedResponse);
+ }
+
+ @Test
+ public void getBasicAuthAccountTest() throws Exception {
+ PortalRestResponse<List<BasicAuthCredentials>> expectedPortalResponse = new PortalRestResponse<List<BasicAuthCredentials>>();
+ List<BasicAuthCredentials> basicAuthCredentialsList = new ArrayList<BasicAuthCredentials>();
+ BasicAuthCredentials basicAuthCredentials = basicAuthCredentials();
+ basicAuthCredentialsList.add(basicAuthCredentials);
+
+ expectedPortalResponse.setMessage("Success");
+ expectedPortalResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedPortalResponse.setStatus(portalRestStatusEnum.OK);
+
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(basicAuthAccountService.getAccountData()).thenReturn(null);
+ PortalRestResponse<List<BasicAuthCredentials>> actualResponse = basicAuthAccountController
+ .getBasicAuthAccount(mockedRequest, mockedResponse);
+ assertEquals(expectedPortalResponse, actualResponse);
+ }
+
+ @Test
+ public void getBasicAuthAccountIfSuperAdminTest() throws Exception {
+ PortalRestResponse<List<BasicAuthCredentials>> expectedPortalResponse = new PortalRestResponse<List<BasicAuthCredentials>>();
+ List<BasicAuthCredentials> basicAuthCredentialsList = new ArrayList<BasicAuthCredentials>();
+ BasicAuthCredentials basicAuthCredentials = basicAuthCredentials();
+ basicAuthCredentialsList.add(basicAuthCredentials);
+
+ expectedPortalResponse.setMessage("UnAuthorized! Admin Only Operation");
+ expectedPortalResponse.setResponse(new ArrayList<>());
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedPortalResponse.setStatus(portalRestStatusEnum.ERROR);
+
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ Mockito.when(basicAuthAccountService.getAccountData()).thenReturn(null);
+ PortalRestResponse<List<BasicAuthCredentials>> actualResponse = basicAuthAccountController
+ .getBasicAuthAccount(mockedRequest, mockedResponse);
+ assertEquals(expectedPortalResponse, actualResponse);
+ }
+
+ @Test
+ public void updateAccountTest() throws Exception {
+ BasicAuthCredentials basicAuthCredentials = basicAuthCredentials();
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("SUCCESS");
+ expectedResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.OK);
+ long accountd = 1;
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.updateAccount(mockedRequest,
+ mockedResponse, accountd, basicAuthCredentials);
+ assertEquals(actualResponse, expectedResponse);
+ }
+
+ @Test
+ public void updateAccountIfSuperAdminTest() throws Exception {
+ BasicAuthCredentials basicAuthCredentials = basicAuthCredentials();
+
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("Authorization Required");
+ expectedResponse.setResponse("Admin Only Operation! ");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.ERROR);
+ long accountd = 1;
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.updateAccount(mockedRequest,
+ mockedResponse, accountd, basicAuthCredentials);
+ assertEquals(actualResponse, expectedResponse);
+ }
+
+ @Test
+ public void updateAccountIfInputNullTest() throws Exception {
+ BasicAuthCredentials basicAuthCredentials = null;
+
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("FAILURE");
+ expectedResponse.setResponse("BasicAuthCredentials cannot be null or empty");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.ERROR);
+ long accountd = 1;
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.updateAccount(mockedRequest,
+ mockedResponse, accountd, basicAuthCredentials);
+ assertEquals(actualResponse, expectedResponse);
+ }
+
+ @Test
+ public void deleteAccountTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("SUCCESS");
+ expectedResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.OK);
+ long accountd = 1;
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.deleteAccount(mockedRequest,
+ mockedResponse, accountd);
+ assertEquals(actualResponse, expectedResponse);
+ }
+
+ @Test
+ public void deleteAccountIfNotSuperAdminTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("Authorization Required");
+ expectedResponse.setResponse("Admin Only Operation! ");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedResponse.setStatus(portalRestStatusEnum.ERROR);
+ long accountd = 1;
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ PortalRestResponse<String> actualResponse = basicAuthAccountController.deleteAccount(mockedRequest,
+ mockedResponse, accountd);
+ System.out.println(actualResponse);
+ assertEquals(actualResponse, expectedResponse);
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/CommonWidgetControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/CommonWidgetControllerTest.java
new file mode 100644
index 00000000..eae8ec07
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/CommonWidgetControllerTest.java
@@ -0,0 +1,84 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+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.MockitoAnnotations;
+import org.openecomp.portalapp.portal.controller.CommonWidgetController;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.DashboardSearchService;
+import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl;
+import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+
+public class CommonWidgetControllerTest {
+
+ @Mock
+ DashboardSearchService dashboardSearchService = new DashboardSearchServiceImpl();
+
+ @InjectMocks
+ CommonWidgetController commonWidgetController = new CommonWidgetController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getWidgetDataTest() {
+ String resourceType = "Test";
+ PortalRestResponse<CommonWidgetMeta> acutualPoratlRestResponse = null;
+ @SuppressWarnings("rawtypes")
+ PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse();
+ ecpectedPortalRestResponse.setMessage("Unexpected resource type Test");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ acutualPoratlRestResponse = commonWidgetController.getWidgetData(mockedRequest, resourceType);
+ assertTrue(acutualPoratlRestResponse.equals(ecpectedPortalRestResponse));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getWidgetDataTestNew() {
+ String resourceType = "EVENTS";
+ PortalRestResponse<CommonWidgetMeta> acutualPoratlRestResponse = null;
+ @SuppressWarnings("rawtypes")
+ PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse();
+ ecpectedPortalRestResponse.setMessage("success");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK);
+ acutualPoratlRestResponse = commonWidgetController.getWidgetData(mockedRequest, resourceType);
+ assertTrue(acutualPoratlRestResponse.equals(ecpectedPortalRestResponse));
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getWidgetDataExceptionTest() {
+ String resourceType = "null";
+ PortalRestResponse<CommonWidgetMeta> acutualPoratlRestResponse = null;
+ @SuppressWarnings("rawtypes")
+ PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse();
+ ecpectedPortalRestResponse.setMessage("Unexpected resource type null");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ acutualPoratlRestResponse = commonWidgetController.getWidgetData(mockedRequest, resourceType);
+ assertTrue(acutualPoratlRestResponse.equals(ecpectedPortalRestResponse));
+
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ConsulClientControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ConsulClientControllerTest.java
new file mode 100644
index 00000000..eda17409
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ConsulClientControllerTest.java
@@ -0,0 +1,142 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+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.ConsulClientController;
+import org.openecomp.portalapp.portal.domain.BEProperty;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.ConsulHealthService;
+import org.openecomp.portalapp.portal.service.ConsulHealthServiceImpl;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+
+import com.orbitz.consul.ConsulException;
+import com.orbitz.consul.model.health.ServiceHealth;
+
+import io.searchbox.client.config.exception.NoServerConfiguredException;
+
+public class ConsulClientControllerTest {
+
+ @Mock
+ ConsulHealthService consulHealthService = new ConsulHealthServiceImpl();
+
+ @InjectMocks
+ ConsulClientController consulClientController = new ConsulClientController();
+
+ NoServerConfiguredException noServerConfiguredException = new NoServerConfiguredException(null);
+
+ String service = "Test";
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+ ConsulException consulException = new ConsulException(nullPointerException);
+
+ @Test
+ public void getServiceLocationTest() {
+ PortalRestResponse<BEProperty> ecpectedPortalRestResponse = new PortalRestResponse<BEProperty>();
+ ecpectedPortalRestResponse.setMessage("Success!");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK);
+ PortalRestResponse<String> actualPortalRestRespone = new PortalRestResponse<String>();
+ actualPortalRestRespone = consulClientController.getServiceLocation(mockedRequest, mockedResponse, service);
+ assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse));
+ }
+
+ @Test
+ public void getServiceLocationExceptionTest() {
+ PortalRestResponse<BEProperty> ecpectedPortalRestResponse = new PortalRestResponse<BEProperty>();
+ ecpectedPortalRestResponse.setMessage("Warning!");
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.WARN);
+ PortalRestResponse<String> actualPortalRestRespone = new PortalRestResponse<String>();
+ Mockito.when(consulHealthService.getServiceLocation(service, null)).thenThrow(noServerConfiguredException);
+ actualPortalRestRespone = consulClientController.getServiceLocation(mockedRequest, mockedResponse, service);
+ assertTrue(actualPortalRestRespone.getMessage().equals(ecpectedPortalRestResponse.getMessage()));
+ assertTrue(actualPortalRestRespone.getStatus().equals(ecpectedPortalRestResponse.getStatus()));
+
+ }
+
+ @Test
+ public void getServiceLocationExceptionConsulExceptionTest() {
+ PortalRestResponse<BEProperty> ecpectedPortalRestResponse = new PortalRestResponse<BEProperty>();
+ ecpectedPortalRestResponse.setMessage("Error!");
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ PortalRestResponse<String> actualPortalRestRespone = new PortalRestResponse<String>();
+ Mockito.when(consulHealthService.getServiceLocation(service, null)).thenThrow(consulException);
+ actualPortalRestRespone = consulClientController.getServiceLocation(mockedRequest, mockedResponse, service);
+ assertTrue(actualPortalRestRespone.getMessage().equals(ecpectedPortalRestResponse.getMessage()));
+ assertTrue(actualPortalRestRespone.getStatus().equals(ecpectedPortalRestResponse.getStatus()));
+ }
+
+ public PortalRestResponse<List<ServiceHealth>> successResponse() {
+ PortalRestResponse<List<ServiceHealth>> ecpectedPortalRestResponse = new PortalRestResponse<List<ServiceHealth>>();
+ List<ServiceHealth> healths = new ArrayList<ServiceHealth>();
+ ecpectedPortalRestResponse.setMessage("Success!");
+ ecpectedPortalRestResponse.setResponse(healths);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK);
+ return ecpectedPortalRestResponse;
+ }
+
+ public PortalRestResponse<List<ServiceHealth>> errorResponse() {
+ PortalRestResponse<List<ServiceHealth>> ecpectedPortalRestResponse = new PortalRestResponse<List<ServiceHealth>>();
+ List<ServiceHealth> healths = new ArrayList<ServiceHealth>();
+ ecpectedPortalRestResponse.setMessage("Error!");
+ ecpectedPortalRestResponse.setResponse(healths);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ return ecpectedPortalRestResponse;
+ }
+
+ @Test
+ public void getAllHealthyNodesTest() {
+ PortalRestResponse<List<ServiceHealth>> ecpectedPortalRestResponse = successResponse();
+ PortalRestResponse<List<ServiceHealth>> actualPortalRestRespone = new PortalRestResponse<List<ServiceHealth>>();
+ actualPortalRestRespone = consulClientController.getAllHealthyNodes(mockedRequest, mockedResponse, service);
+ assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse));
+
+ }
+
+ @Test
+ public void getAllHealthyNodesExceptionTest() {
+ PortalRestResponse<List<ServiceHealth>> ecpectedPortalRestResponse = errorResponse();
+ PortalRestResponse<List<ServiceHealth>> actualPortalRestRespone = new PortalRestResponse<List<ServiceHealth>>();
+ Mockito.when(consulHealthService.getAllHealthyNodes(service)).thenThrow(consulException);
+ actualPortalRestRespone = consulClientController.getAllHealthyNodes(mockedRequest, mockedResponse, service);
+ assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse));
+ }
+
+ @Test
+ public void getAllNodesTest() {
+ PortalRestResponse<List<ServiceHealth>> ecpectedPortalRestResponse = successResponse();
+ PortalRestResponse<List<ServiceHealth>> actualPortalRestRespone = new PortalRestResponse<List<ServiceHealth>>();
+ actualPortalRestRespone = consulClientController.getAllNodes(mockedRequest, mockedResponse, service);
+ assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse));
+ }
+
+ @Test
+ public void getAllNodesExceptionTest() {
+ PortalRestResponse<List<ServiceHealth>> ecpectedPortalRestResponse = errorResponse();
+ PortalRestResponse<List<ServiceHealth>> actualPortalRestRespone = new PortalRestResponse<List<ServiceHealth>>();
+ Mockito.when(consulHealthService.getAllNodes(service)).thenThrow(consulException);
+ actualPortalRestRespone = consulClientController.getAllNodes(mockedRequest, mockedResponse, service);
+ assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse));
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/DashboardSearchResultControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/DashboardSearchResultControllerTest.java
new file mode 100644
index 00000000..6da95415
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/DashboardSearchResultControllerTest.java
@@ -0,0 +1,366 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.DashboardSearchResultController;
+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.ecomp.model.SearchResultItem;
+import org.openecomp.portalapp.portal.service.DashboardSearchService;
+import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.transport.CommonWidget;
+import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+
+public class DashboardSearchResultControllerTest {
+
+ @Mock
+ DashboardSearchService searchService = new DashboardSearchServiceImpl();
+
+ @InjectMocks
+ DashboardSearchResultController dashboardSearchResultController = new DashboardSearchResultController();
+
+ @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();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void getWidgetDataTest() {
+ String resourceType = "test";
+ PortalRestResponse<CommonWidgetMeta> ecpectedPortalRestResponse = new PortalRestResponse<CommonWidgetMeta>();
+ ecpectedPortalRestResponse.setMessage("success");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK);
+ Mockito.when(searchService.getWidgetData(resourceType)).thenReturn(null);
+ PortalRestResponse<CommonWidgetMeta> acutualPoratlRestResponse = dashboardSearchResultController
+ .getWidgetData(mockedRequest, resourceType);
+ assertEquals(acutualPoratlRestResponse, ecpectedPortalRestResponse);
+
+ }
+
+ @Test
+ public void saveWidgetDataBulkTest() {
+ PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<String>();
+ ecpectedPortalRestResponse.setMessage("success");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK);
+
+ CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta();
+ commonWidgetMeta.setCategory("test");
+
+ List<CommonWidget> commonWidgetList = new ArrayList<CommonWidget>();
+ CommonWidget commonWidget = new CommonWidget();
+ commonWidget.setId((long) 1);
+ commonWidget.setCategory("test");
+ commonWidget.setHref("test_href");
+ commonWidget.setTitle("test_title");
+ commonWidget.setContent("test_content");
+ commonWidget.setEventDate(null);
+ commonWidget.setSortOrder(1);
+
+ commonWidgetList.add(commonWidget);
+
+ commonWidgetMeta.setItems(commonWidgetList);
+
+ Mockito.when(searchService.saveWidgetDataBulk(commonWidgetMeta)).thenReturn(null);
+
+ PortalRestResponse<String> actualPortalRestResponse = dashboardSearchResultController
+ .saveWidgetDataBulk(commonWidgetMeta);
+ assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse);
+ }
+
+ @Test
+ public void saveWidgetDataBulkIfCategoryNullTest() {
+ PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<String>();
+ ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"1\"");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+
+ CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta();
+ commonWidgetMeta.setCategory("test");
+
+ List<CommonWidget> commonWidgetList = new ArrayList<CommonWidget>();
+ CommonWidget commonWidget = new CommonWidget();
+ commonWidget.setId(null);
+ commonWidget.setCategory(null);
+ commonWidget.setHref(null);
+ commonWidget.setTitle(null);
+ commonWidget.setContent("test_content");
+ commonWidget.setEventDate("1");
+ commonWidget.setSortOrder(1);
+ commonWidgetList.add(commonWidget);
+ commonWidgetMeta.setItems(commonWidgetList);
+
+ Mockito.when(searchService.saveWidgetDataBulk(commonWidgetMeta)).thenReturn(null);
+
+ PortalRestResponse<String> actualPortalRestResponse = dashboardSearchResultController
+ .saveWidgetDataBulk(commonWidgetMeta);
+ assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse);
+ }
+
+ @Test
+ public void saveWidgetDataTest() {
+ PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<String>();
+ ecpectedPortalRestResponse.setMessage("success");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK);
+ CommonWidget commonWidget = new CommonWidget();
+ commonWidget.setId((long) 1);
+ commonWidget.setCategory("test");
+ commonWidget.setHref("test_href");
+ commonWidget.setTitle("test_title");
+ commonWidget.setContent("test_content");
+ commonWidget.setEventDate(null);
+ commonWidget.setSortOrder(1);
+
+ Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn(null);
+
+ PortalRestResponse<String> actualPortalRestResponse = dashboardSearchResultController
+ .saveWidgetData(commonWidget);
+ assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse);
+
+ }
+
+ @Test
+ public void saveWidgetDataExceptionTest() {
+ PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<String>();
+ ecpectedPortalRestResponse.setMessage("ERROR");
+ ecpectedPortalRestResponse.setResponse("Cateogry cannot be null or empty");
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ CommonWidget commonWidget = new CommonWidget();
+ commonWidget.setId((long) 1);
+ commonWidget.setCategory("");
+ commonWidget.setHref("test_href");
+ commonWidget.setTitle("test_title");
+ commonWidget.setContent("test_content");
+ commonWidget.setEventDate(null);
+ commonWidget.setSortOrder(1);
+
+ Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn(null);
+
+ PortalRestResponse<String> actualPortalRestResponse = dashboardSearchResultController
+ .saveWidgetData(commonWidget);
+ assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse);
+
+ }
+
+ @Test
+ public void saveWidgetDataDateErrorTest() {
+ PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<String>();
+ ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"1\"");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ CommonWidget commonWidget = new CommonWidget();
+ commonWidget.setId((long) 1);
+ commonWidget.setCategory("test");
+ commonWidget.setHref("test_href");
+ commonWidget.setTitle("test_title");
+ commonWidget.setContent("test_content");
+ commonWidget.setEventDate("1");
+ commonWidget.setSortOrder(1);
+
+ Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn(null);
+
+ PortalRestResponse<String> actualPortalRestResponse = dashboardSearchResultController
+ .saveWidgetData(commonWidget);
+ assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse);
+
+ }
+
+ public void deleteWidgetDataTest() {
+ PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<String>();
+ ecpectedPortalRestResponse.setMessage("success");
+ ecpectedPortalRestResponse.setResponse(null);
+ ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK);
+ CommonWidget commonWidget = new CommonWidget();
+ commonWidget.setId((long) 1);
+ commonWidget.setCategory("test");
+ commonWidget.setHref("test_href");
+ commonWidget.setTitle("test_title");
+ commonWidget.setContent("test_content");
+ commonWidget.setEventDate(null);
+ commonWidget.setSortOrder(1);
+ Mockito.when(searchService.deleteWidgetData(commonWidget)).thenReturn(null);
+
+ PortalRestResponse<String> actualPortalRestResponse = dashboardSearchResultController
+ .deleteWidgetData(commonWidget);
+ System.out.println(actualPortalRestResponse);
+ assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse);
+ }
+
+ @Test
+ public void searchPortalIfUserIsNull() {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String searchString = "test";
+
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedResult.setMessage("searchPortal: User object is null? - check logs");
+ expectedResult.setResponse(new HashMap<String, List<SearchResultItem>>());
+ expectedResult.setStatus(PortalRestStatusEnum.ERROR);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualResult = dashboardSearchResultController
+ .searchPortal(mockedRequest, searchString);
+ assertEquals(expectedResult, actualResult);
+ }
+
+ @Test
+ public void searchPortalIfSearchStringNullTest() {
+ EPUser user = mockUser.mockEPUser();
+ ;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String searchString = null;
+
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedResult.setMessage("searchPortal: String string is null");
+ expectedResult.setResponse(new HashMap<String, List<SearchResultItem>>());
+ expectedResult.setStatus(PortalRestStatusEnum.ERROR);
+
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualResult = dashboardSearchResultController
+ .searchPortal(mockedRequest, searchString);
+ assertEquals(expectedResult, actualResult);
+ }
+
+ @Test
+ public void searchPortalIfSearchTest() {
+ EPUser user = mockUser.mockEPUser();
+ ;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String searchString = "test";
+ List<SearchResultItem> searchResultItemList = new ArrayList<SearchResultItem>();
+ SearchResultItem searchResultItem = new SearchResultItem();
+
+ searchResultItem.setId((long) 1);
+ searchResultItem.setCategory("test");
+ searchResultItem.setName("test_name");
+ searchResultItem.setTarget("test_target");
+ searchResultItem.setUuid("test_UUId");
+ searchResultItemList.add(searchResultItem);
+ Map<String, List<SearchResultItem>> expectedResultMap = new HashMap<String, List<SearchResultItem>>();
+ expectedResultMap.put(searchString, searchResultItemList);
+
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedResult.setMessage("success");
+ expectedResult.setResponse(expectedResultMap);
+ expectedResult.setStatus(PortalRestStatusEnum.OK);
+
+ Mockito.when(searchService.searchResults(user.getLoginId(), searchString)).thenReturn(expectedResultMap);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualResult = dashboardSearchResultController
+ .searchPortal(mockedRequest, searchString);
+ assertEquals(expectedResult, actualResult);
+
+ }
+
+ @Test
+ public void searchPortalIfSearchExcptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ ;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String searchString = "test";
+
+ PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
+ expectedResult.setMessage("null - check logs.");
+ expectedResult.setResponse(new HashMap<String, List<SearchResultItem>>());
+ expectedResult.setStatus(PortalRestStatusEnum.ERROR);
+
+ Mockito.when(searchService.searchResults(user.getLoginId(), searchString)).thenThrow(nullPointerException);
+ PortalRestResponse<Map<String, List<SearchResultItem>>> actualResult = dashboardSearchResultController
+ .searchPortal(mockedRequest, searchString);
+ assertEquals(expectedResult, actualResult);
+ }
+
+ @Test
+ public void getActiveUsersTest() {
+ List<String> expectedActiveUsers = new ArrayList<String>();
+ EPUser user = mockUser.mockEPUser();
+ ;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String userId = user.getOrgUserId();
+ Mockito.when(searchService.getRelatedUsers(userId)).thenReturn(expectedActiveUsers);
+ List<String> actualOnlineUsers = dashboardSearchResultController.getActiveUsers(mockedRequest);
+ assertEquals(expectedActiveUsers, actualOnlineUsers);
+
+ }
+
+ @Test
+ public void getActiveUsersExceptionTest() {
+ List<String> expectedActiveUsers = new ArrayList<String>();
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String userId = user.getOrgUserId();
+ Mockito.when(searchService.getRelatedUsers(userId)).thenThrow(nullPointerException);
+ List<String> actualOnlineUsers = dashboardSearchResultController.getActiveUsers(mockedRequest);
+ assertEquals(expectedActiveUsers, actualOnlineUsers);
+
+ }
+
+ @Test
+ public void activeUsersTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<List<String>> expectedResult = new PortalRestResponse<List<String>>();
+ expectedResult.setMessage("success");
+ expectedResult.setResponse(new ArrayList<>());
+ expectedResult.setStatus(PortalRestStatusEnum.OK);
+ PortalRestResponse<List<String>> actualResult = dashboardSearchResultController.activeUsers(mockedRequest);
+
+ assertEquals(actualResult, expectedResult);
+
+ }
+
+ @Test
+ public void activeUsersIfUserNullTest() {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<List<String>> expectedResult = new PortalRestResponse<List<String>>();
+ expectedResult.setMessage("User object is null? - check logs");
+ expectedResult.setResponse(new ArrayList<>());
+ expectedResult.setStatus(PortalRestStatusEnum.ERROR);
+ PortalRestResponse<List<String>> actualResult = dashboardSearchResultController.activeUsers(mockedRequest);
+ assertEquals(actualResult, expectedResult);
+
+ }
+
+ @Test
+ public void activeUsersExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ PortalRestResponse<List<String>> expectedResult = new PortalRestResponse<List<String>>();
+ expectedResult.setMessage("null - check logs.");
+ expectedResult.setResponse(new ArrayList<>());
+ expectedResult.setStatus(PortalRestStatusEnum.ERROR);
+ Mockito.when(searchService.getRelatedUsers(user.getLoginId())).thenThrow(nullPointerException);
+ PortalRestResponse<List<String>> actualResult = dashboardSearchResultController.activeUsers(mockedRequest);
+ assertEquals(actualResult, expectedResult);
+
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ExternalAppsRestfulControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ExternalAppsRestfulControllerTest.java
new file mode 100644
index 00000000..43860d45
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ExternalAppsRestfulControllerTest.java
@@ -0,0 +1,174 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+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.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.ExternalAppsRestfulController;
+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.EPLoginService;
+import org.openecomp.portalapp.portal.service.EPLoginServiceImpl;
+import org.openecomp.portalapp.portal.service.EPRoleService;
+import org.openecomp.portalapp.portal.service.EPRoleServiceImpl;
+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.transport.FavoritesFunctionalMenuItemJson;
+import org.openecomp.portalapp.portal.transport.FunctionalMenuItem;
+import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.openecomp.portalsdk.core.service.DataAccessServiceImpl;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.MDC;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ MDC.class, EPCommonSystemProperties.class })
+public class ExternalAppsRestfulControllerTest {
+
+ @InjectMocks
+ ExternalAppsRestfulController externalAppsRestfulController = new ExternalAppsRestfulController();
+ @Mock
+ FunctionalMenuService functionalMenuService = new FunctionalMenuServiceImpl();
+
+ @Mock
+ EPLoginService epLoginService = new EPLoginServiceImpl();
+
+ @Mock
+ AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @Mock
+ UserNotificationService userNotificationService = new UserNotificationServiceImpl();
+
+ @Mock
+ EPRoleService epRoleService = new EPRoleServiceImpl();
+
+ @Mock
+ EcompPortalUtils EcompPortalUtils = new EcompPortalUtils();
+
+ @Mock
+ DataAccessService DataAccessService = new DataAccessServiceImpl();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test(expected = Exception.class)
+ public void getFunctionalMenuItemsForUserIfUSerNullTest() throws
+ Exception
+ {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(MDC.class);
+ EPUser epUser = null;
+ String loginId = "guestT";
+ Mockito.when(MDC.get(EPCommonSystemProperties.PARTNER_NAME)).thenReturn("Test");
+ Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser);
+ externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest,
+ mockedResponse);
+ }
+
+ @Test
+ public void getFunctionalMenuItemsForUserIfSuperAdminTest() throws Exception {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(MDC.class);
+ EPUser epUser = mockUser.mockEPUser();
+ epUser.setId((long) 1);
+ epUser.setLoginId("guestT");
+ String loginId = "guestT";
+ Mockito.when(MDC.get(EPCommonSystemProperties.PARTNER_NAME)).thenReturn("Test");
+ Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser);
+ List<FunctionalMenuItem> expectedList = new ArrayList<FunctionalMenuItem>();
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ expectedList.add(functionalMenuItem);
+ Mockito.when(mockedRequest.getHeader("LoginId")).thenReturn("guestT");
+ Mockito.when(adminRolesService.isSuperAdmin(epUser)).thenReturn(true);
+ Mockito.when(functionalMenuService.getFunctionalMenuItems()).thenReturn(expectedList);
+ List<FunctionalMenuItem> actualList = externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest,
+ mockedResponse);
+ assertNull(actualList.get(0).menuId);
+ }
+
+ @Test
+ public void getFunctionalMenuItemsForUserTest() throws Exception {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(MDC.class);
+ EPUser epUser = mockUser.mockEPUser();
+ epUser.setId((long) 1);
+ epUser.setLoginId("guestT");
+ String loginId = "guestT";
+ Mockito.when(MDC.get(EPCommonSystemProperties.PARTNER_NAME)).thenReturn("Test");
+ Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser);
+ List<FunctionalMenuItem> expectedList = new ArrayList<FunctionalMenuItem>();
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ expectedList.add(functionalMenuItem);
+ Mockito.when(mockedRequest.getHeader("LoginId")).thenReturn("guestT");
+ Mockito.when(adminRolesService.isSuperAdmin(epUser)).thenReturn(false);
+ Mockito.when(functionalMenuService.getFunctionalMenuItemsForUser(epUser.getOrgUserId()))
+ .thenReturn(expectedList);
+ List<FunctionalMenuItem> actualList = externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest,
+ mockedResponse);
+ assertNull(actualList.get(0).menuId);
+ }
+
+ @Test(expected = Exception.class)
+ public void getFavoritesForUserIfUserNullTest() throws Exception {
+ List<FavoritesFunctionalMenuItemJson> favorites = new ArrayList<FavoritesFunctionalMenuItemJson>();
+ FavoritesFunctionalMenuItemJson favoritesFunctionalMenuItemJson = new FavoritesFunctionalMenuItemJson();
+ favorites.add(favoritesFunctionalMenuItemJson);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(MDC.class);
+ Mockito.when(mockedRequest.getHeader(EPCommonSystemProperties.MDC_LOGIN_ID)).thenReturn("Login_URL");
+ Mockito.when(MDC.get(EPCommonSystemProperties.PARTNER_NAME)).thenReturn("Test");
+ EPUser epUser = null;
+ externalAppsRestfulController.getFavoritesForUser(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void getFavoritesForUserTest() throws Exception {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(MDC.class);
+ EPUser epUser = mockUser.mockEPUser();
+ epUser.setId((long) 1);
+ epUser.setLoginId("guestT");
+ String loginId = "guestT";
+ Mockito.when(MDC.get(EPCommonSystemProperties.PARTNER_NAME)).thenReturn("Test");
+ List<FavoritesFunctionalMenuItemJson> favorites = new ArrayList<FavoritesFunctionalMenuItemJson>();
+ FavoritesFunctionalMenuItemJson favoritesFunctionalMenuItemJson = new FavoritesFunctionalMenuItemJson();
+ favorites.add(favoritesFunctionalMenuItemJson);
+ Mockito.when(mockedRequest.getHeader(EPCommonSystemProperties.MDC_LOGIN_ID)).thenReturn("Login_URL");
+ Mockito.when(MDC.get(EPCommonSystemProperties.PARTNER_NAME)).thenReturn("Test");
+ Mockito.when(epLoginService.findUserWithoutPwd("Login_URL")).thenReturn(epUser);
+ Mockito.when(functionalMenuService.getFavoriteItems(epUser.getId())).thenReturn(favorites);
+ List<FavoritesFunctionalMenuItemJson> actaulFavorites = externalAppsRestfulController
+ .getFavoritesForUser(mockedRequest, mockedResponse);
+ assertEquals(actaulFavorites.size(), 1);
+ }
+}
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
index b9f11eeb..6e1b5d1c 100644
--- 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
@@ -1,190 +1,188 @@
-/*-
- * ================================================================================
- * 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));
- }
-
-}
+/*-
+ * ================================================================================
+ * 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.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+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.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.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 = "ab1234";
+
+ @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/GetAccessControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/GetAccessControllerTest.java
new file mode 100644
index 00000000..b9ab249e
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/GetAccessControllerTest.java
@@ -0,0 +1,71 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+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.GetAccessController;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.domain.GetAccessResult;
+import org.openecomp.portalapp.portal.service.GetAccessService;
+import org.openecomp.portalapp.portal.service.GetAccessServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+
+public class GetAccessControllerTest {
+
+ @Mock
+ GetAccessService getAccessService = new GetAccessServiceImpl();
+
+ @InjectMocks
+ GetAccessController getAccessController = new GetAccessController();
+
+ @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 getAppList() throws IOException
+ {
+ List<GetAccessResult> expectedAppsList = new ArrayList<GetAccessResult>();
+ EPUser user = mockUser.mockEPUser();
+ GetAccessResult getAccessResult = new GetAccessResult();
+ getAccessResult.setRowId("1");
+ getAccessResult.setRoleId((long) 1);
+ getAccessResult.setEcompFunction("test");
+ getAccessResult.setAppName("Test_App");
+ getAccessResult.setAppMotsId(1);
+ getAccessResult.setRoleName("Test_role");
+ getAccessResult.setRoleActive("N");
+ getAccessResult.setReqType("test");
+
+ expectedAppsList.add(getAccessResult);
+
+ List<GetAccessResult> actualAppsList = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(getAccessService.getAppAccessList(user)).thenReturn(expectedAppsList);
+ actualAppsList = getAccessController.getAppList(mockedRequest);
+ assertTrue(actualAppsList.contains(getAccessResult));
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ManifestControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ManifestControllerTest.java
new file mode 100644
index 00000000..ceaceaac
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/ManifestControllerTest.java
@@ -0,0 +1,56 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.Attributes;
+
+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.ManifestController;
+import org.openecomp.portalapp.portal.service.ManifestService;
+import org.openecomp.portalapp.portal.service.ManifestServiceImpl;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+
+public class ManifestControllerTest extends MockitoTestSuite{
+
+
+ @Mock
+ ManifestService manifestService = new ManifestServiceImpl();
+
+ @InjectMocks
+ ManifestController manifestController = new ManifestController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void getManifestTest() throws IOException
+ {
+ Map<String, Object> expectedResponse = new HashMap<String, Object>();
+ Attributes attributes = new Attributes();
+ expectedResponse.put("test", attributes);
+ Mockito.when(manifestService.getWebappManifest()).thenReturn(attributes);
+ Map<String, Object> actualResponse = manifestController.getManifest(mockedRequest);
+ assertTrue((actualResponse.keySet().toArray().length) == 1);
+
+ }
+
+ @Test
+ public void getManifestExceptionTest() throws IOException
+ {
+ Mockito.when(manifestService.getWebappManifest()).thenThrow(nullPointerException);
+ Map<String, Object> actualResponse = manifestController.getManifest(mockedRequest);
+ assertTrue((actualResponse.keySet().toArray().length) == 1);
+ assertTrue(actualResponse.get("error").equals("failed to get manifest: java.lang.NullPointerException"));
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceControllerTest.java
new file mode 100644
index 00000000..4c14d8a0
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceControllerTest.java
@@ -0,0 +1,233 @@
+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.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.MicroserviceController;
+import org.openecomp.portalapp.portal.domain.MicroserviceData;
+import org.openecomp.portalapp.portal.domain.WidgetCatalog;
+import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.ConsulHealthService;
+import org.openecomp.portalapp.portal.service.ConsulHealthServiceImpl;
+import org.openecomp.portalapp.portal.service.MicroserviceService;
+import org.openecomp.portalapp.portal.service.MicroserviceServiceImpl;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(WidgetServiceHeaders.class)
+public class MicroserviceControllerTest extends MockitoTestSuite{
+
+ @InjectMocks
+ MicroserviceController microserviceController = new MicroserviceController();
+
+ @Mock
+ ConsulHealthService consulHealthService = new ConsulHealthServiceImpl();
+
+ @Mock
+ MicroserviceService microserviceService = new MicroserviceServiceImpl();
+
+ @Mock
+ RestTemplate template = new RestTemplate();
+
+ @Mock
+ MicroserviceData microserviceData = new MicroserviceData();
+
+ @SuppressWarnings("rawtypes")
+ @Mock
+ ResponseEntity<List<WidgetCatalog>> ans = new ResponseEntity<List<WidgetCatalog>>(HttpStatus.OK);
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Mock
+ EcompPortalUtils EcompPortalUtils = new EcompPortalUtils();
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test
+ public void createMicroserviceIfServiceDataNullTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("FAILURE");
+ expectedportalRestResponse.setResponse("MicroserviceData cannot be null or empty");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ MicroserviceData microserviceData = null;
+ PortalRestResponse<String> actualportalRestResponse = microserviceController.createMicroservice(mockedRequest,
+ mockedResponse, microserviceData);
+ assertEquals(actualportalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void createMicroserviceTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("SUCCESS");
+ expectedportalRestResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ PortalRestResponse<String> actualportalRestResponse = microserviceController.createMicroservice(mockedRequest,
+ mockedResponse, microserviceData);
+ assertEquals(actualportalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void createMicroserviceExceptionTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("FAILURE");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Mockito.when(microserviceService.saveMicroservice(microserviceData)).thenReturn((long) 1);
+ Mockito.when(microserviceData.getParameterList()).thenThrow(nullPointerException);
+ PortalRestResponse<String> actualportalRestResponse = microserviceController.createMicroservice(mockedRequest,
+ mockedResponse, microserviceData);
+ assertEquals(actualportalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void getMicroserviceTest() throws Exception {
+ Mockito.when(microserviceService.getMicroserviceData()).thenReturn(null);
+ List<MicroserviceData> list = microserviceController.getMicroservice(mockedRequest, mockedResponse);
+ assertEquals(list, null);
+ }
+
+ @Test
+ public void updateMicroserviceIfServiceISNullTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("FAILURE");
+ expectedportalRestResponse.setResponse("MicroserviceData cannot be null or empty");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ MicroserviceData microserviceData = null;
+ PortalRestResponse<String> actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest,
+ mockedResponse, 1, microserviceData);
+ assertEquals(actualportalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void updateMicroserviceTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("SUCCESS");
+ expectedportalRestResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ PortalRestResponse<String> actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest,
+ mockedResponse, 1, microserviceData);
+ assertEquals(actualportalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void updateMicroserviceExceptionTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("FAILURE");
+ expectedportalRestResponse.setResponse(null);
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ Mockito.when(microserviceController.updateMicroservice(mockedRequest, mockedResponse, 1, microserviceData))
+ .thenThrow(nullPointerException);
+ PortalRestResponse<String> actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest,
+ mockedResponse, 1, microserviceData);
+ assertEquals(actualportalRestResponse, expectedportalRestResponse);
+ }
+
+ @Test
+ public void deleteMicroserviceExceptionTest() throws Exception {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("FAILURE");
+ expectedportalRestResponse.setResponse(
+ "I/O error on GET request for \"https://null/widget/microservices/widgetCatalog/service/1\":null; nested exception is java.net.UnknownHostException: null");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ PowerMockito.mockStatic(WidgetServiceHeaders.class);
+ PortalRestResponse<String> actuaPportalRestResponse = microserviceController.deleteMicroservice(mockedRequest,
+ mockedResponse, 1);
+ assertEquals(actuaPportalRestResponse.getStatus(), expectedportalRestResponse.getStatus());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void deleteMicroserviceTest() throws Exception {
+ String HTTPS = "https://";
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("SOME WIDGETS ASSOICATE WITH THIS SERVICE");
+ expectedportalRestResponse.setResponse("'null' ,'null' ");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.WARN);
+ List<WidgetCatalog> List = new ArrayList<WidgetCatalog>();
+ WidgetCatalog widgetCatalog = new WidgetCatalog();
+ widgetCatalog.setId(1);
+ WidgetCatalog widgetCatalog1 = new WidgetCatalog();
+ widgetCatalog.setId(2);
+ List.add(widgetCatalog);
+ List.add(widgetCatalog1);
+ PowerMockito.mockStatic(WidgetServiceHeaders.class);
+ String whatService = "widgets-service";
+ Mockito.when(consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))).thenReturn("Test");
+ Mockito.when(ans.getBody()).thenReturn(List);
+ ParameterizedTypeReference<List<WidgetCatalog>> typeRef = new ParameterizedTypeReference<List<WidgetCatalog>>() {
+ };
+ Mockito.when(template.exchange(
+ HTTPS + consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))
+ + "/widget/microservices/widgetCatalog/service/" + 1,
+ HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), typeRef)).thenReturn(ans);
+
+ PortalRestResponse<String> actuaPportalRestResponse = microserviceController.deleteMicroservice(mockedRequest,
+ mockedResponse, 1);
+ assertEquals(actuaPportalRestResponse, expectedportalRestResponse);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void deleteMicroserviceWhenNoWidgetsAssociatedTest() throws Exception {
+ String HTTPS = "https://";
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("SUCCESS");
+ expectedportalRestResponse.setResponse("");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ List<WidgetCatalog> List = new ArrayList<WidgetCatalog>();
+ PowerMockito.mockStatic(WidgetServiceHeaders.class);
+ String whatService = "widgets-service";
+ Mockito.when(consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))).thenReturn("Test");
+ Mockito.when(ans.getBody()).thenReturn(List);
+ ParameterizedTypeReference<List<WidgetCatalog>> typeRef = new ParameterizedTypeReference<List<WidgetCatalog>>() {
+ };
+ Mockito.when(template.exchange(
+ HTTPS + consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))
+ + "/widget/microservices/widgetCatalog/service/" + 1,
+ HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), typeRef)).thenReturn(ans);
+ PortalRestResponse<String> actuaPportalRestResponse = microserviceController.deleteMicroservice(mockedRequest,
+ mockedResponse, 1);
+ assertEquals(actuaPportalRestResponse, expectedportalRestResponse);
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceProxyControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceProxyControllerTest.java
new file mode 100644
index 00000000..0d5aee15
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/MicroserviceProxyControllerTest.java
@@ -0,0 +1,106 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.openecomp.portalapp.portal.controller.MicroserviceProxyController;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.service.MicroserviceProxyService;
+import org.openecomp.portalapp.portal.service.MicroserviceProxyServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpClientErrorException;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+
+
+public class MicroserviceProxyControllerTest extends MockitoTestSuite {
+
+ @Mock
+ MicroserviceProxyService microserviceProxyService = new MicroserviceProxyServiceImpl();
+
+ @InjectMocks
+ MicroserviceProxyController microserviceProxyController = new MicroserviceProxyController();
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Mock
+ EPUserUtils ePUserUtils = new EPUserUtils();
+ @Mock
+ ObjectMapper objectMapper = new ObjectMapper();
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void getMicroserviceProxyTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(microserviceProxyService.proxyToDestination(1, user, mockedRequest)).thenReturn("Success");
+ String acutualString = microserviceProxyController.getMicroserviceProxy(mockedRequest, getMockedResponse(), 1);
+ assertTrue(acutualString.equals("Success"));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getMicroserviceProxyNullPoniterExceptionTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(microserviceProxyService.proxyToDestination(1, user, mockedRequest))
+ .thenThrow(nullPointerException);
+ microserviceProxyController.getMicroserviceProxy(mockedRequest, getMockedResponse(), 1);
+ }
+
+ @Test
+ public void getMicroserviceProxyExceptionTest() throws Exception {
+ HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.OK, "Success");
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(microserviceProxyService.proxyToDestination(1, user, mockedRequest))
+ .thenThrow(httpClientErrorException);
+ String acutualString = microserviceProxyController.getMicroserviceProxy(mockedRequest, getMockedResponse(), 1);
+ assertTrue(acutualString.equals("{\"error\":\"\"}"));
+ }
+
+ @Test
+ public void getMicroserviceProxyByWidgetIdTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(microserviceProxyService.proxyToDestinationByWidgetId(1, user, mockedRequest))
+ .thenReturn("Success");
+ String acutualString = microserviceProxyController.getMicroserviceProxyByWidgetId(mockedRequest,
+ getMockedResponse(), 1);
+ assertTrue(acutualString.equals("Success"));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getMicroserviceProxyByWidgetIdNullPointerExceptionTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(microserviceProxyService.proxyToDestinationByWidgetId(1, user, mockedRequest))
+ .thenThrow(nullPointerException);
+ microserviceProxyController.getMicroserviceProxyByWidgetId(mockedRequest, getMockedResponse(), 1);
+ }
+
+ @Test
+ public void getMicroserviceProxyByWidgetIdExceptionTest() throws Exception {
+ HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.OK, "Success");
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(microserviceProxyService.proxyToDestinationByWidgetId(1, user, mockedRequest))
+ .thenThrow(httpClientErrorException);
+ String acutualString = microserviceProxyController.getMicroserviceProxyByWidgetId(mockedRequest,
+ getMockedResponse(), 1);
+ assertTrue(acutualString.equals("{\"error\":\"\"}"));
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/PortalAdminControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/PortalAdminControllerTest.java
new file mode 100644
index 00000000..20542729
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/PortalAdminControllerTest.java
@@ -0,0 +1,231 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+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.PortalAdminController;
+import org.openecomp.portalapp.portal.domain.EPRole;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.exceptions.NoHealthyServiceException;
+import org.openecomp.portalapp.portal.service.AdminRolesService;
+import org.openecomp.portalapp.portal.service.AdminRolesServiceImpl;
+import org.openecomp.portalapp.portal.service.PortalAdminService;
+import org.openecomp.portalapp.portal.service.PortalAdminServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.transport.FieldsValidator;
+import org.openecomp.portalapp.portal.transport.PortalAdmin;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.service.AuditService;
+import org.openecomp.portalsdk.core.service.AuditServiceImpl;
+
+public class PortalAdminControllerTest extends MockitoTestSuite{
+
+ @InjectMocks
+ PortalAdminController portalAdminController = new PortalAdminController();
+
+ @Mock
+ AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @Mock
+ PortalAdminService portalAdminService = new PortalAdminServiceImpl();
+
+ @Mock
+ AuditService auditService = new AuditServiceImpl();
+
+
+ @Mock
+ EcompPortalUtils ecompPortalUtils = new EcompPortalUtils();
+
+ @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();
+
+ MockEPUser mockUser = new MockEPUser();
+
+
+ @Test
+ public void getPortalAdminsTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<PortalAdmin> expectedPortalAdminsList = new ArrayList<PortalAdmin>();
+ PortalAdmin portalAdmin= new PortalAdmin();
+
+ portalAdmin.setUserId((long) 1);
+ portalAdmin.setLoginId("guestT");
+ portalAdmin.setFirstName("Test_FirstName");
+ portalAdmin.setLastName("Test_LastName");
+
+ expectedPortalAdminsList.add(portalAdmin);
+
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+
+ Mockito.when(portalAdminService.getPortalAdmins()).thenReturn(expectedPortalAdminsList);
+ List<PortalAdmin> actualPortalAdminsList = portalAdminController.getPortalAdmins(mockedRequest, mockedResponse);
+ assertEquals(actualPortalAdminsList,expectedPortalAdminsList);
+
+ }
+// @Test
+// public void getPortalAdminsIfUserIsNullTest()
+// {
+// EPUser user = null;
+// Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+//
+// assertNull(portalAdminController.getPortalAdmins(mockedRequest, mockedResponse));
+//
+// }
+
+ @Test
+ public void getPortalAdminsIfUserIsSuperAdminTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ assertNull(portalAdminController.getPortalAdmins(mockedRequest, mockedResponse));
+
+ }
+
+
+
+ @Test
+ public void createPortalAdminTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ String sbcid = "Test";
+
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(portalAdminService.createPortalAdmin(sbcid)).thenReturn(expectedFieldValidator);
+ actualFieldValidator = portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse);
+ assertEquals(actualFieldValidator,expectedFieldValidator);
+
+ }
+
+// @Test
+// public void createPortalAdminIfUserIsNullTest()
+// {
+// //EPUser user = null;
+// Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null);
+// String sbcid = "null";
+// assertNull(portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse));
+//
+// }
+
+ @Test
+ public void createPortalAdminIfUserIsSuperAdminTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ String sbcid = "Test";
+ assertNull(portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse));
+
+ }
+
+ @Test
+ public void deletePortalAdminTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+
+ FieldsValidator expectedFieldValidator = new FieldsValidator();
+ expectedFieldValidator.setHttpStatusCode((long) 200);
+ expectedFieldValidator.setFields(null);
+ expectedFieldValidator.setErrorCode(null);
+ FieldsValidator actualFieldValidator = new FieldsValidator();
+ String userInfo = "1-test";
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
+ Mockito.when(portalAdminService.deletePortalAdmin((long) 1)).thenReturn(expectedFieldValidator);
+ actualFieldValidator = portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse);
+ assertEquals(actualFieldValidator,expectedFieldValidator);
+
+ }
+
+ @Test
+ public void deletePortalAdminIfUserIsSuperAdminTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ String userInfo = "1-test";
+ assertNull(portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse));
+
+ }
+
+ @Test
+ public void deletePortalAdminWithNoUserInfoTest()
+ {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
+ String userInfo = "";
+ assertNull(portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse));
+ }
+
+ @Test
+ public void getRolesByAppIfUserNullTest()
+ {
+ EPUser user = null;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Long appId = (long) 1;
+ assertNull(portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse));
+ }
+
+ @Test
+ public void getRolesByAppTest()
+ {
+ EPUser user = mockUser.mockEPUser();;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPRole> expectedRoleList = new ArrayList<EPRole>();
+ EPRole ePRole = new EPRole();
+ expectedRoleList.add(ePRole);
+ Long appId = (long) 1;
+ Mockito.when(adminRolesService.getRolesByApp(user, appId)).thenReturn(expectedRoleList);
+ List<EPRole> actualRoleList = portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse);
+ assertEquals(actualRoleList,expectedRoleList);
+ }
+
+ @Test
+ public void getRolesByAppExceptionTest()
+ {
+ EPUser user = mockUser.mockEPUser();;
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<EPRole> expectedRoleList = new ArrayList<EPRole>();
+ EPRole ePRole = new EPRole();
+ expectedRoleList.add(ePRole);
+ Long appId = (long) 1;
+ Mockito.when(adminRolesService.getRolesByApp(user, appId)).thenThrow(nullPointerException);
+ assertNull(portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse));
+ }
+
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RolesApprovalSystemControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RolesApprovalSystemControllerTest.java
new file mode 100644
index 00000000..6286245f
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/RolesApprovalSystemControllerTest.java
@@ -0,0 +1,336 @@
+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.externalsystemapproval.model.ExternalSystemRoleApproval;
+import org.openecomp.portalapp.externalsystemapproval.model.ExternalSystemUser;
+import org.openecomp.portalapp.portal.controller.RolesApprovalSystemController;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.UserRolesService;
+import org.openecomp.portalapp.portal.transport.ExternalRequestFieldsValidator;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+
+public class RolesApprovalSystemControllerTest extends MockitoTestSuite {
+
+ @Mock
+ UserRolesService userRolesService;
+
+ @InjectMocks
+ RolesApprovalSystemController rolesApprovalSystemController = new RolesApprovalSystemController();
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void postUserProfileIfRolesNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Request has no roles");
+ expectedportalRestResponse.setResponse("save user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = null;
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .postUserProfile(mockedRequest, extSysUser, mockedResponse);
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void postUserProfileTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Saved Successfully");
+ expectedportalRestResponse.setResponse("Success");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true,
+ "Saved Successfully");
+
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "POST"))
+ .thenReturn(externalRequestFieldsValidator);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .postUserProfile(mockedRequest, extSysUser, mockedResponse);
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void postUserProfileFailureTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Received Bad String");
+ expectedportalRestResponse.setResponse("save user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false,
+ "Received Bad String");
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "POST"))
+ .thenReturn(externalRequestFieldsValidator);
+
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .postUserProfile(mockedRequest, extSysUser, mockedResponse);
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void postUserProfileExceptionTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse("save user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "POST")).thenThrow(nullPointerException);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .postUserProfile(mockedRequest, extSysUser, mockedResponse);
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void putUserProfileIfLoginIdNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Request has no login ID");
+ expectedportalRestResponse.setResponse("save user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId(null);
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .putUserProfile(mockedRequest, extSysUser, mockedResponse);
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void putUserProfileTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Updated Successfully");
+ expectedportalRestResponse.setResponse("Success");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true,
+ "Updated Successfully");
+
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "PUT"))
+ .thenReturn(externalRequestFieldsValidator);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .putUserProfile(mockedRequest, extSysUser, mockedResponse);
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void putUserProfileFailureTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Received Bad String");
+ expectedportalRestResponse.setResponse("save user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false,
+ "Received Bad String");
+
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "PUT"))
+ .thenReturn(externalRequestFieldsValidator);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .putUserProfile(mockedRequest, extSysUser, mockedResponse);
+
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void putUserProfileExceptionTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse("save user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "PUT")).thenThrow(nullPointerException);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .putUserProfile(mockedRequest, extSysUser, mockedResponse);
+
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void deleteUserProfileIfApplicationNameNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Request has no application name");
+ expectedportalRestResponse.setResponse("delete user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName(null);
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .deleteUserProfile(mockedRequest, extSysUser, mockedResponse);
+
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void deleteUserProfileIfMyloginrequestIdNullTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Request has no request ID");
+ expectedportalRestResponse.setResponse("delete user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId(null);
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .deleteUserProfile(mockedRequest, extSysUser, mockedResponse);
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void deleteUserProfileTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("Deleted Successfully");
+ expectedportalRestResponse.setResponse("Success");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.OK);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true,
+ "Success");
+
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "DELETE"))
+ .thenReturn(externalRequestFieldsValidator);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .deleteUserProfile(mockedRequest, extSysUser, mockedResponse);
+
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void deleteUserProfileFailureTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage("failed");
+ expectedportalRestResponse.setResponse("delete user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false,
+ "failed");
+
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "DELETE"))
+ .thenReturn(externalRequestFieldsValidator);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .deleteUserProfile(mockedRequest, extSysUser, mockedResponse);
+
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+
+ @Test
+ public void deleteUserProfileExceptionTest() {
+ PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<String>();
+ expectedportalRestResponse.setMessage(null);
+ expectedportalRestResponse.setResponse("delete user profile failed");
+ PortalRestStatusEnum portalRestStatusEnum = null;
+ expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR);
+ ExternalSystemUser extSysUser = new ExternalSystemUser();
+ extSysUser.setApplicationName("Test_App");
+ extSysUser.setLoginId("1");
+ extSysUser.setMyloginrequestId("Test");
+ List<ExternalSystemRoleApproval> externalSystemRoleApprovalList = new ArrayList<ExternalSystemRoleApproval>();
+ ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval();
+ externalSystemRoleApprovalList.add(externalSystemRoleApproval);
+ extSysUser.setRoles(externalSystemRoleApprovalList);
+ Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "DELETE")).thenThrow(nullPointerException);
+ PortalRestResponse<String> actualportalRestResponse = rolesApprovalSystemController
+ .deleteUserProfile(mockedRequest, extSysUser, mockedResponse);
+
+ assertEquals(expectedportalRestResponse, actualportalRestResponse);
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/TicketEventControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/TicketEventControllerTest.java
new file mode 100644
index 00000000..1eda356a
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/TicketEventControllerTest.java
@@ -0,0 +1,99 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.portal.controller.TicketEventController;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.service.UserNotificationService;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalsdk.core.web.support.UserUtils;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(UserUtils.class)
+public class TicketEventControllerTest {
+
+ @Mock
+ UserNotificationService userNotificationService;
+
+ @InjectMocks
+ TicketEventController ticketEventController = new TicketEventController();
+
+ @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 saveTest() throws Exception {
+ String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}";
+ PortalRestResponse<String> actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest,
+ mockedResponse, ticketEventJson);
+ assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.OK) == 0);
+ }
+
+ @Test
+ public void saveTestForException() throws Exception {
+ String ticketEventJson = "\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}";
+ PortalRestResponse<String> actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest,
+ mockedResponse, ticketEventJson);
+ assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
+ }
+
+ @Test
+ public void saveTestForApplicationValid() throws Exception {
+ String ticketEventJson = "{\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}";
+ PortalRestResponse<String> actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest,
+ mockedResponse, ticketEventJson);
+ assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
+ assertEquals(actualPortalRestResponse.getMessage(), "application is mandatory");
+
+ }
+
+ @Test
+ public void saveTestForBodyValid() throws Exception {
+ String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\",\"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}";
+ PortalRestResponse<String> actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest,
+ mockedResponse, ticketEventJson);
+ assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
+ assertEquals(actualPortalRestResponse.getMessage(), "body is mandatory");
+ }
+
+ @Test
+ public void saveTestForEventSourceValid() throws Exception {
+ String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}";
+ PortalRestResponse<String> actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest,
+ mockedResponse, ticketEventJson);
+ assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
+ assertEquals(actualPortalRestResponse.getMessage(), "Message Source is mandatory");
+ }
+
+ @Test
+ public void saveTestForUserListValid() throws Exception {
+ String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {}}";
+ PortalRestResponse<String> actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest,
+ mockedResponse, ticketEventJson);
+ assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
+ assertEquals(actualPortalRestResponse.getMessage(), "At least one user Id is mandatory");
+ }
+} \ No newline at end of file
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserControllerTest.java
new file mode 100644
index 00000000..9e4d635d
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserControllerTest.java
@@ -0,0 +1,141 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+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.UserController;
+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.UserService;
+import org.openecomp.portalapp.portal.service.UserServiceImpl;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.portal.transport.ProfileDetail;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(CipherUtil.class)
+public class UserControllerTest extends MockitoTestSuite {
+
+ @InjectMocks
+ UserController userController = new UserController();
+
+ @Mock
+ UserService userService = new UserServiceImpl();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Mock
+ EPUserUtils ePUserUtils = new EPUserUtils();
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void getLoggedinUserExceptionTest() {
+ EPUser epUser = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(epUser);
+ PortalRestResponse<ProfileDetail> expectedResponse = new PortalRestResponse<ProfileDetail>();
+ expectedResponse.setMessage(null);
+ expectedResponse.setResponse(null);
+ PortalRestStatusEnum enu = null;
+ expectedResponse.setStatus(enu.ERROR);
+ PortalRestResponse<ProfileDetail> response = userController.getLoggedinUser(mockedRequest);
+ assertEquals(response, expectedResponse);
+ }
+
+ @Test
+ public void getLoggedinUserTest() throws Exception {
+ EPUser epUser = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(epUser);
+ PortalRestResponse<ProfileDetail> expectedResponse = new PortalRestResponse<ProfileDetail>();
+ expectedResponse.setMessage("success");
+ ProfileDetail profileDetail = new ProfileDetail();
+ expectedResponse.setResponse(profileDetail);
+ PortalRestStatusEnum enu = null;
+ expectedResponse.setStatus(enu.OK);
+ PowerMockito.mockStatic(CipherUtil.class);
+ Mockito.when(CipherUtil.decrypt(epUser.getLoginPwd())).thenReturn("Password");
+ PortalRestResponse<ProfileDetail> response = userController.getLoggedinUser(mockedRequest);
+ assertEquals(response.getMessage(), expectedResponse.getMessage());
+ assertEquals(response.getStatus(), expectedResponse.getStatus());
+ }
+
+ @Test
+ public void modifyLoggedinUserIfProfileNullTest() {
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("java.lang.NullPointerException");
+ expectedResponse.setResponse(null);
+ PortalRestStatusEnum enu = null;
+ expectedResponse.setStatus(enu.ERROR);
+ ProfileDetail profileDetail = null;
+ PortalRestResponse<String> actualResponse = userController.modifyLoggedinUser(mockedRequest, profileDetail);
+ assertEquals(actualResponse, expectedResponse);
+ assertEquals(actualResponse.getStatus(), expectedResponse.getStatus());
+ }
+
+ @Test
+ public void modifyLoggedinUserExceptionTest() {
+ EPUser epUser = mockUser.mockEPUser();
+
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage(
+ "java.lang.ClassCastException: com.sun.crypto.provider.AESCipher$General cannot be cast to javax.crypto.CipherSpi");
+ expectedResponse.setResponse(null);
+ PortalRestStatusEnum enu = null;
+ expectedResponse.setStatus(enu.ERROR);
+ ProfileDetail profileDetail = new ProfileDetail();
+ profileDetail.setFirstName("Test_FirstName");
+ profileDetail.setLastName("Test_LastName");
+ profileDetail.setEmail("Test_Email");
+ profileDetail.setLoginId("Test_LoginId");
+ profileDetail.setLoginPassword("Test_LoginPassword");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(epUser);
+ PortalRestResponse<String> actualResponse = userController.modifyLoggedinUser(mockedRequest, profileDetail);
+ assertEquals(actualResponse, expectedResponse);
+
+ }
+
+ @Test
+ public void modifyLoggedinUserTest() throws Exception {
+ EPUser epUser = mockUser.mockEPUser();
+ PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
+ expectedResponse.setMessage("success");
+ expectedResponse.setResponse(null);
+ PortalRestStatusEnum enu = null;
+ expectedResponse.setStatus(enu.OK);
+ ProfileDetail profileDetail = new ProfileDetail();
+ profileDetail.setFirstName("Test_FirstName");
+ profileDetail.setLastName("Test_LastName");
+ profileDetail.setEmail("Test_Email");
+ profileDetail.setLoginId("Test_LoginId");
+ profileDetail.setLoginPassword("Test_LoginPassword");
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(epUser);
+ PowerMockito.mockStatic(CipherUtil.class);
+ Mockito.when(CipherUtil.decrypt(epUser.getLoginPwd())).thenReturn("Password");
+ PortalRestResponse<String> actualResponse = userController.modifyLoggedinUser(mockedRequest, profileDetail);
+ System.out.println(actualResponse);
+ }
+}
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
index 628f52a1..2bc6977d 100644
--- 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
@@ -1,265 +1,263 @@
-/*-
- * ================================================================================
- * 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));
- }
-
-}
+/*-
+ * ================================================================================
+ * 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.Matchers;
+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.transport.EpNotificationItem;
+import org.openecomp.portalapp.portal.transport.EpNotificationItemVO;
+import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+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);
+ 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);
+ 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() {
+ 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<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(Matchers.anyLong())).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");
+ 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");
+ 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");
+ 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("");
+ 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/UserRecommendationControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRecommendationControllerTest.java
new file mode 100644
index 00000000..8c0a5cd3
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRecommendationControllerTest.java
@@ -0,0 +1,69 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.portal.controller.UserRecommendationController;
+import org.openecomp.portalapp.portal.test.core.MockEPUser;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalsdk.core.web.support.UserUtils;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(UserUtils.class)
+public class UserRecommendationControllerTest {
+
+ /*
+ * @Mock FunctionalMenuService functionalMenuService = new
+ * FunctionalMenuServiceImpl();
+ *
+ * @Mock UserNotificationService userNotificationService = new
+ * UserNotificationServiceImpl();
+ */
+
+ @InjectMocks
+ UserRecommendationController userRecommendationController = new UserRecommendationController();
+
+ @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 getRecommendationsTest() throws Exception {
+ String recommendations = "{\"id\": \"USERID\", \"timestamp\": \"TIMESTAMP\", \"count\": \"count of recommendations returned\",\"recommendations\": [\"recommended action 1\",\"recommended action 2\"] }";
+ // String actualPortalRestResponse = null;
+ String actualPortalRestResponse = recommendations;
+ actualPortalRestResponse = userRecommendationController.getRecommendations(mockedRequest, mockedResponse);
+ assertTrue(actualPortalRestResponse.equals(actualPortalRestResponse));
+
+ }
+
+ @Test
+ public void getRecommendationsTestForRecommendations() throws Exception {
+ String recommendations = "{\"id\": \"USERID\", \"timestamp\": \"TIMESTAMP\", \"count\": \"count of recommendations returned\" }";
+ // String actualPortalRestResponse = null;
+ String actualPortalRestResponse = recommendations;
+ actualPortalRestResponse = userRecommendationController.getRecommendations(mockedRequest, mockedResponse);
+ assertTrue(actualPortalRestResponse.equals(actualPortalRestResponse));
+
+ }
+
+
+}
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
index 093ca585..1459caa4 100644
--- 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
@@ -1,131 +1,130 @@
-/*-
- * ================================================================================
- * 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());
-
- }
-}
+/*-
+ * ================================================================================
+ * 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 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.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.test.framework.MockitoTestSuite;
+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 = "ab1234";
+
+ @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/controller/WebAnalyticsExtAppControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WebAnalyticsExtAppControllerTest.java
new file mode 100644
index 00000000..84ee4b10
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WebAnalyticsExtAppControllerTest.java
@@ -0,0 +1,131 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.io.IOUtils;
+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.WebAnalyticsExtAppController;
+import org.openecomp.portalapp.portal.domain.EPApp;
+import org.openecomp.portalapp.portal.service.AdminRolesService;
+import org.openecomp.portalapp.portal.service.AdminRolesServiceImpl;
+import org.openecomp.portalapp.portal.service.AppsCacheService;
+import org.openecomp.portalapp.portal.service.AppsCacheServiceImple;
+import org.openecomp.portalapp.portal.transport.Analytics;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
+import org.openecomp.portalsdk.core.service.AuditService;
+import org.openecomp.portalsdk.core.service.AuditServiceImpl;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({SystemProperties.class,IOUtils.class,Object.class})
+public class WebAnalyticsExtAppControllerTest {
+
+
+
+ @InjectMocks
+ WebAnalyticsExtAppController webAnalyticsExtAppController = new WebAnalyticsExtAppController();
+
+ @Mock
+ AdminRolesService adminRolesService = new AdminRolesServiceImpl();
+
+ @Mock
+ AppsCacheService appCacheService = new AppsCacheServiceImple();
+
+ @Mock
+ AuditService auditService = new AuditServiceImpl();
+
+// @Mock
+// InputStream analyticsFileStream;
+
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test(expected= NullPointerException.class)
+ public void getAnalyticsScriptTest() throws Exception
+ {
+ String expectedResponse = "http://www.ecomp.com";
+
+ InputStream analyticsFileStream = null;
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(IOUtils.class);
+ Mockito.when(IOUtils.toString(analyticsFileStream, StandardCharsets.UTF_8.name())).thenReturn("PORTAL_ENV_URL");
+ Mockito.when(SystemProperties.getProperty("frontend_url")).thenReturn("http://www.ecomp.com/test");
+ //String actualResponse = webAnalyticsExtAppController.getAnalyticsScript(mockedRequest);
+ webAnalyticsExtAppController.getAnalyticsScript(mockedRequest);
+ //assertTrue(actualResponse.equals(expectedResponse));
+ }
+
+ @Test(expected= NullPointerException.class)
+ public void getAnalyticsScriptExceptionTest() throws Exception
+ {
+ String expectedResponse = "";
+ InputStream analyticsFileStream = null;
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(IOUtils.class);
+ Mockito.when(IOUtils.toString(analyticsFileStream, StandardCharsets.UTF_8.name())).thenThrow(nullPointerException);
+ Mockito.when(SystemProperties.getProperty("frontend_url")).thenReturn("http://www.ecomp.com/test");
+ webAnalyticsExtAppController.getAnalyticsScript(mockedRequest);
+
+ }
+
+ @Test
+ public void storeAnalyticsScriptIfAnalyticsNullTest() throws Exception
+ {
+ PortalAPIResponse expectedPortalAPIResponse = new PortalAPIResponse(true, "error");
+ Analytics analytics= null;
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null);
+ PortalAPIResponse actualPortalAPIResponse = webAnalyticsExtAppController.storeAnalyticsScript(mockedRequest, analytics);
+ assertTrue(expectedPortalAPIResponse.getMessage().equals(actualPortalAPIResponse.getMessage()));
+ assertTrue(expectedPortalAPIResponse.getStatus().equals(actualPortalAPIResponse.getStatus()));
+ }
+
+ @Test
+ public void storeAnalyticsScriptTest() throws Exception
+ {
+ PortalAPIResponse expectedPortalAPIResponse = new PortalAPIResponse(true, "success");
+ Analytics analytics= new Analytics();
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn("Test_Key");
+ EPApp app = new EPApp();
+ Mockito.when(appCacheService.getAppForAnalytics("Test_Key")).thenReturn(app);
+ PortalAPIResponse actualPortalAPIResponse = webAnalyticsExtAppController.storeAnalyticsScript(mockedRequest, analytics);
+ assertTrue(expectedPortalAPIResponse.getMessage().equals(actualPortalAPIResponse.getMessage()));
+ assertTrue(expectedPortalAPIResponse.getStatus().equals(actualPortalAPIResponse.getStatus()));
+ }
+ @Test
+ public void storeAnalyticsScriptIfAppNullTest() throws Exception
+ {
+ PortalAPIResponse expectedPortalAPIResponse = new PortalAPIResponse(true, "success");
+ Analytics analytics= new Analytics();
+ Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn("Test_Key");
+ Mockito.when(appCacheService.getAppForAnalytics("Test_Key")).thenReturn(null);
+ PortalAPIResponse actualPortalAPIResponse = webAnalyticsExtAppController.storeAnalyticsScript(mockedRequest, analytics);
+ assertTrue(expectedPortalAPIResponse.getMessage().equals(actualPortalAPIResponse.getMessage()));
+ assertTrue(expectedPortalAPIResponse.getStatus().equals(actualPortalAPIResponse.getStatus()));
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WidgetsCatalogMarkupControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WidgetsCatalogMarkupControllerTest.java
new file mode 100644
index 00000000..1ba4c784
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/WidgetsCatalogMarkupControllerTest.java
@@ -0,0 +1,71 @@
+package org.openecomp.portalapp.portal.test.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+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.WidgetsCatalogMarkupController;
+import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders;
+import org.openecomp.portalapp.portal.service.ConsulHealthService;
+import org.openecomp.portalapp.portal.service.ConsulHealthServiceImpl;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+import org.openecomp.portalapp.test.framework.MockitoTestSuite;
+import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(WidgetServiceHeaders.class)
+public class WidgetsCatalogMarkupControllerTest extends MockitoTestSuite {
+
+ @InjectMocks
+ WidgetsCatalogMarkupController widgetsCatalogMarkupController = new WidgetsCatalogMarkupController();
+
+ @Mock
+ ConsulHealthService consulHealthService = new ConsulHealthServiceImpl();
+
+ @Mock
+ RestTemplate template = new RestTemplate();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+ @Mock
+ CipherUtil cipherUtil= new CipherUtil();
+
+ @Mock
+ EcompPortalUtils EcompPortalUtils =new EcompPortalUtils();
+
+ @Mock
+ WidgetServiceHeaders WidgetServiceHeaders ;
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ @SuppressWarnings("static-access")
+ @Test
+ public void getWidgetMarkupTest() throws RestClientException, Exception
+ {
+ String whatService = "widgets-service";
+ PowerMockito.mockStatic(WidgetServiceHeaders.class);
+ Mockito.when(template.getForObject("https://" + consulHealthService.getServiceLocation(whatService, null) + "/widget/microservices/markup/" + 1, String.class,
+ WidgetServiceHeaders.getInstance())).thenReturn("Success");
+ String response = widgetsCatalogMarkupController.getWidgetMarkup(mockedRequest, mockedResponse, 1);
+ assertTrue(response.equals("Success"));
+ }
+
+}
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
index aa3c00d2..344350e0 100644
--- 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
@@ -1,86 +1,84 @@
-/*-
- * ================================================================================
- * 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;
-
- }
-}
+/*-
+ * ================================================================================
+ * 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("guestT");
+ 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) -1);
+ 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
index b04d200e..8f99f442 100644
--- 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
@@ -1,66 +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);
- }
-
-}
+/*-
+ * ================================================================================
+ * 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.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
index db9663fd..c9954a69 100644
--- 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
@@ -1,66 +1,65 @@
-/*-
- * ================================================================================
- * 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);
- }
-}
+/*-
+ * ================================================================================
+ * 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.Test;
+import org.openecomp.portalapp.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
index f90b27e5..10108cde 100644
--- 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
@@ -1,329 +1,333 @@
-/*-
- * ================================================================================
- * 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);
- }
-
-}
+/*-
+ * ================================================================================
+ * 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 static org.junit.Assert.assertTrue;
+
+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.transport.AppNameIdIsAdmin;
+import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole;
+import org.openecomp.portalapp.test.framework.ApplicationCommonContextTestSuite;
+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;
+
+/**
+ *
+ * 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);
+ }
+
+ @Test
+ public void ticketEventControllerForExternalSystem() throws Exception {
+ String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}";
+ MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/auxapi/ticketevent")
+ .contentType(APPLICATION_JSON_UTF8).content(ticketEventJson);
+ ResultActions ra = getMockMvc().perform(requestBuilder);
+ assertTrue(ra.andReturn().getResponse().getContentType().contains("application/json"));
+ }
+}
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
index 8030dcad..d7930c14 100644
--- 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
@@ -1,175 +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" };
- }
-
-}
+/*-
+ * ================================================================================
+ * 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
index 614e2ac3..44019aa6 100644
--- 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
@@ -1,70 +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;
- }
-
- }
-
-}
+/*-
+ * ================================================================================
+ * 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
index 7aa2029c..2ca02ba6 100644
--- 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
@@ -1,88 +1,73 @@
-/*-
- * ================================================================================
- * 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());
-
- }
-
-}
-
-
+/*-
+ * ================================================================================
+ * 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.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.transport.BusinessCardApplicationRole;
+import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
+import org.openecomp.portalapp.test.framework.ApplicationCommonContextTestSuite;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class FunctionalMenuServiceImplTest extends ApplicationCommonContextTestSuite {
+
+ @Autowired
+ FunctionalMenuService functionalMenuService;
+
+ @Test
+ public void getAppListTestService() throws Exception {
+
+ String userId = "guestT";
+ 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(-1));
+
+ expectedFunctionalMenuRole.setMenuId((long) 137);
+ expectedFunctionalMenuRole.setAppId(new Integer(456));
+ expectedFunctionalMenuRole.setRoleId(new Integer(6214));
+ List<FunctionalMenuRole> actualFunctionalMenuRoleList = null;
+ actualFunctionalMenuRoleList = functionalMenuService.getFunctionalMenuRole();
+ assertTrue(actualFunctionalMenuRoleList.contains(expectedFunctionalMenuRole));
+
+ }
+}
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/test/framework/ApplicationCommonContextTestSuite.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/test/framework/ApplicationCommonContextTestSuite.java
new file mode 100644
index 00000000..cba7c57b
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/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.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/test/framework/MockitoTestSuite.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/test/framework/MockitoTestSuite.java
new file mode 100644
index 00000000..8c5d3d21
--- /dev/null
+++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/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.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/resources/PopulateTestData.sql b/ecomp-portal-BE-common-test/src/main/resources/PopulateTestData.sql
index 6972ec95..116ba757 100644
--- a/ecomp-portal-BE-common-test/src/main/resources/PopulateTestData.sql
+++ b/ecomp-portal-BE-common-test/src/main/resources/PopulateTestData.sql
@@ -1,28 +1,32 @@
----
--- ================================================================================
--- 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);
+---
+-- ================================================================================
+-- 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(-1,null,null,'test',null,'test',null,null,null,null,null,null,null,'guestT',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(-1,1, null,1);
+insert into fn_user_role values(-1,16, null,1);
+insert into fn_user_role values(-1,999, null,1);
+insert into fn_user_role values(-1,1010, null,1);
+insert into fn_menu_functional values(-1,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(-1, 137,456, 6214);
+insert into fn_menu_favorites values(-1, 141);
+insert into ep_web_analytics_source values(-1,1,'test_url','test');
+INSERT INTO ep_notification (notification_ID, is_for_online_users, is_for_all_roles, active_YN, msg_header, msg_description,msg_source,start_time,end_time,priority,creator_ID,created_date)
+VALUES ('-1', 'Y', 'N', 'Y', 'CISCO_1921C1_ISR_G2', '{}','aotstm','2017-03-26 12:18:55.0','2017-04-25 12:18:55.0','2',NULL,'2017-04-25 21:18:11.0');
+INSERT INTO ep_role_notification (ID,notification_ID,role_ID,recv_user_id ) VALUES (0,-1,NULL,10)
diff --git a/ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql b/ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql
index 158508f7..5a3000a4 100644
--- a/ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql
+++ b/ecomp-portal-BE-common-test/src/main/resources/RemoveTestData.sql
@@ -1,27 +1,31 @@
----
--- ================================================================================
--- 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;
+---
+-- ================================================================================
+-- 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 =-1;
+delete from ep_user_notification where user_id=-1;
+delete from fn_audit_log where user_id=-1;
+delete from fn_menu_favorites where user_id=-1 and menu_id=141;
+delete from fn_user where user_id=-1;
+delete from fn_menu_functional_roles where id=-1;
+delete from fn_menu_functional_ancestors where menu_id=-1;
+delete from fn_menu_functional where menu_id=-1;
+delete from fn_menu_favorites where user_id=-1 and menu_id=141;
+delete from ep_web_analytics_source where resource_id=-1;
+delete from ep_role_notification where notification_ID='-1';
+delete from ep_notification where notification_ID='-1';