X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Fservice%2FAdminRolesServiceImplTest.java;h=f14d3fd91a57700b6533b02eb44a3d5d98ef7ae1;hb=2a462c99939b19f972813b64c7a4d6e33b9aaa5a;hp=ef9bda0cce75490f9fddf8f53e47015f08729eb3;hpb=1376951553a11ed93a9fde45b7f26b51c0b31e9c;p=portal.git 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 ef9bda0c..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"); @@ -33,12 +35,13 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalapp.portal.service; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -92,6 +95,9 @@ public class AdminRolesServiceImplTest { @Mock DataAccessService dataAccessService = new DataAccessServiceImpl(); + @Mock + ExternalAccessRolesService externalAccessRolesService; + @Mock EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl(); @@ -127,6 +133,8 @@ public class AdminRolesServiceImplTest { private Long ACCOUNT_ADMIN_ROLE_ID = 999L; + private Long ECOMP_APP_ID = 1L; + public EPApp mockApp() { EPApp app = new EPApp(); app.setName("Test"); @@ -178,7 +186,27 @@ public class AdminRolesServiceImplTest { userAppList.add(epUserApp); Mockito.when(dataAccessService.getList(EPUserApp.class, " where userId = " + user.getId() + " and role.id = " + 999, null, null)).thenReturn(userAppList); - adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId()); + List appsList = new ArrayList<>(); + appsList.add(app); + Mockito.when(dataAccessService.getList(EPApp.class, + " where ( enabled = 'Y' or id = " + ECOMP_APP_ID + ")", null, null)).thenReturn(appsList); + AppsListWithAdminRole actual = adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId()); + assertNotNull(actual); + } + + @Test + public void getAppsWithAdminRoleStateForUserTestWithException() { + EPUser user = mockUser.mockEPUser(); + EPApp app = mockApp(); + app.setId(1l); + List users = new ArrayList<>(); + users.add(user); + Map userParams = new HashMap<>(); + userParams.put("org_user_id", user.getOrgUserId()); + Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null)).thenReturn(users); + AppsListWithAdminRole actual = adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId()); + + } @SuppressWarnings({ "deprecation", "unchecked" }) @@ -347,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 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(); @@ -409,8 +456,11 @@ public class AdminRolesServiceImplTest { epUserApp.setUserId(1l); userApps.add(epUserApp); user.setUserApps(userApps); - Mockito.when((EPUser) dataAccessService.getDomainObject(Matchers.any(), Matchers.anyLong(), Matchers.anyMap())) - .thenReturn(user); + List userAdminApps = new ArrayList<>(); + userAdminApps.add(1); + userAdminApps.add(2); + Mockito.when(dataAccessService.executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap())) + .thenReturn(userAdminApps); boolean actual = adminRolesServiceImpl.isAccountAdminOfApplication(user, app); assertTrue(actual); }