summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-BE-common/src/test/java/org/onap')
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java10
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java45
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java24
3 files changed, 78 insertions, 1 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
index ff37fd50..59b5a8ed 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
* under the Apache License, Version 2.0 (the "License");
@@ -733,6 +735,7 @@ public class AppsControllerTest extends MockitoTestSuite{
expectedFieldValidator.setErrorCode(null);
Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator);
+ Mockito.when(mockedResponse.getStatus()).thenReturn(200);
FieldsValidator actualFieldValidator = appsController.putOnboardingApp(mockedRequest, OnboardingApp,
mockedResponse);
assertEquals(expectedFieldValidator, actualFieldValidator);
@@ -758,6 +761,13 @@ public class AppsControllerTest extends MockitoTestSuite{
Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenThrow(nullPointerException);
assertNull(appsController.putOnboardingApp(mockedRequest, OnboardingApp, mockedResponse));
}
+
+ @Test
+ public void putOnboardingAppNullUserTest() {
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenThrow(nullPointerException);
+ Mockito.when(mockedResponse.getStatus()).thenReturn(200);
+ assertNull(appsController.putOnboardingApp(mockedRequest, new OnboardingApp(), mockedResponse));
+ }
@Test
public void postOnboardingAppTest() {
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java
index ff9fcffc..8bfa39c3 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
* under the Apache License, Version 2.0 (the "License");
@@ -76,6 +78,7 @@ import org.onap.portalapp.portal.domain.EPApp;
import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.onap.portalapp.portal.ecomp.model.UploadRoleFunctionExtSystem;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
import org.onap.portalapp.portal.service.AdminRolesService;
import org.onap.portalapp.portal.service.EPAppService;
@@ -474,6 +477,9 @@ public class RoleManageControllerTest {
@Test
public void syncRolesException() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isAccountAdminOfApplication(user, null)).thenReturn(true);
Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
PortalRestResponse<String> actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l);
PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
@@ -483,6 +489,18 @@ public class RoleManageControllerTest {
assertEquals(portalRestResponse, actual);
}
+ @Test
+ public void syncRolesUserNullException() throws Exception {
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null);
+ Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
+ PortalRestResponse<String> actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l);
+ PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
+ portalRestResponse.setMessage("Unauthorized User");
+ portalRestResponse.setResponse("Failure");
+ portalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ assertEquals(portalRestResponse, actual);
+ }
+
@Test
public void syncRolesFunctionsTest() throws Exception {
PowerMockito.mockStatic(EPUserUtils.class);
@@ -510,7 +528,10 @@ public class RoleManageControllerTest {
@Test
public void syncRolesFunctionsException() throws Exception {
- Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
+ EPUser user = mockUser.mockEPUser();
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(adminRolesService.isAccountAdminOfApplication(user, null)).thenReturn(true);
+ Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
PortalRestResponse<String> actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l);
PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
portalRestResponse.setMessage(null);
@@ -519,6 +540,18 @@ public class RoleManageControllerTest {
assertEquals(portalRestResponse, actual);
}
+ @Test
+ public void syncRolesFunctionsUserNullException() throws Exception {
+ Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null);
+ Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
+ PortalRestResponse<String> actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l);
+ PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
+ portalRestResponse.setMessage("Unauthorized User");
+ portalRestResponse.setResponse("Failure");
+ portalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
+ assertEquals(portalRestResponse, actual);
+ }
+
@Test
public void addChildRoleTest() throws Exception {
ModelAndView modelandView = new ModelAndView("login.htm");
@@ -890,6 +923,16 @@ public class RoleManageControllerTest {
List<CentralizedApp> actual = roleManageController.getCentralizedAppRoles(mockedRequest, mockedResponse, user.getOrgUserId());
assertNull(actual);
}
+
+ @Test
+ public void bulkUploadRoleFuncUserNullTest() {
+ UploadRoleFunctionExtSystem data = Mockito.mock(UploadRoleFunctionExtSystem.class);
+ Mockito.when(appService.getApp(127L)).thenReturn(null);
+ PortalRestResponse<String> response = roleManageController.bulkUploadRoleFunc(mockedRequest, mockedResponse, data, 127L);
+ assertEquals(PortalRestStatusEnum.ERROR, response.getStatus());
+ assertEquals("Unauthorized User", response.getMessage());
+ assertEquals("Failure", response.getResponse());
+ }
public CentralV2RoleFunction mockCentralRoleFunction() {
CentralV2RoleFunction roleFunction = new CentralV2RoleFunction();
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java
index 15f021c5..f14d3fd9 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
* under the Apache License, Version 2.0 (the "License");
@@ -93,6 +95,9 @@ public class AdminRolesServiceImplTest {
@Mock
DataAccessService dataAccessService = new DataAccessServiceImpl();
+ @Mock
+ ExternalAccessRolesService externalAccessRolesService;
+
@Mock
EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl();
@@ -370,6 +375,25 @@ public class AdminRolesServiceImplTest {
assertFalse(actual);
}
+ @Test
+ public void isAccountAdminUserNull() {
+ boolean actual = adminRolesServiceImpl.isAccountAdmin(null);
+ assertFalse(actual);
+ }
+
+ @Test
+ public void isRoleAdminTest() {
+ EPUser user = mockUser.mockEPUser();
+ List<String> roles = new ArrayList<>();
+ roles.add("approver\\|");
+ Mockito.when(dataAccessService.executeNamedQuery(
+ Matchers.eq("getRoleFunctionsOfUserforAlltheApplications"), Matchers.any(), Matchers.any()))
+ .thenReturn(roles);
+ Mockito.when(externalAccessRolesService.getFunctionCodeType(Matchers.anyString())).thenReturn("approver");
+ boolean actual = adminRolesServiceImpl.isRoleAdmin(user);
+ assertTrue(actual);
+ }
+
@Test
public void isUserTest() {
EPUser user = mockUser.mockEPUser();