Changes made to upgrade pom version
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / UserRolesCommonServiceImplTest.java
index 4d07c79..736f834 100644 (file)
@@ -82,18 +82,7 @@ import org.onap.portalapp.portal.domain.EPUserAppRoles;
 import org.onap.portalapp.portal.domain.EPUserAppRolesRequest;
 import org.onap.portalapp.portal.domain.EPUserAppRolesRequestDetail;
 import org.onap.portalapp.portal.domain.ExternalSystemAccess;
-import org.onap.portalapp.portal.transport.AppWithRolesForUser;
-import org.onap.portalapp.portal.transport.CentralV2Role;
-import org.onap.portalapp.portal.transport.EPUserAppCurrentRoles;
-import org.onap.portalapp.portal.transport.EcompUserAppRoles;
-import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
-import org.onap.portalapp.portal.transport.FieldsValidator;
-import org.onap.portalapp.portal.transport.FunctionalMenuItem;
-import org.onap.portalapp.portal.transport.FunctionalMenuRole;
-import org.onap.portalapp.portal.transport.RemoteRole;
-import org.onap.portalapp.portal.transport.RemoteUserWithRoles;
-import org.onap.portalapp.portal.transport.RoleInAppForUser;
-import org.onap.portalapp.portal.transport.UserApplicationRoles;
+import org.onap.portalapp.portal.transport.*;
 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
 import org.onap.portalapp.portal.utils.EcompPortalUtils;
 import org.onap.portalapp.portal.utils.PortalConstants;
@@ -106,6 +95,7 @@ import org.onap.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.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
@@ -153,6 +143,9 @@ public class UserRolesCommonServiceImplTest {
 
        @Mock
        Transaction transaction;
+       
+       @Mock
+       AdminRolesService adminRolesService;
 
        @InjectMocks
        UserRolesCommonServiceImpl userRolesCommonServiceImpl = new UserRolesCommonServiceImpl();
@@ -204,10 +197,14 @@ public class UserRolesCommonServiceImplTest {
                Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
                List<RoleInAppForUser> mockRoleInAppForUserList = getMockedRoleInAppUserList();
                List<CentralV2Role> mockCenV2Role = new ArrayList<>();
-               CentralV2Role cenV2Role = new CentralV2Role(1l, null, null, null, null, null, "test1", true, null,
-                               new TreeSet<>(), new TreeSet<>(), new TreeSet<>());
-               CentralV2Role cenV2Role2 = new CentralV2Role(16l, null, null, null, null, null, "test2", true, null,
-                               new TreeSet<>(), new TreeSet<>(), new TreeSet<>());
+        CentralV2Role cenV2Role = new CentralV2Role.CentralV2RoleBuilder().setId(1l).setCreated(null).setModified(null)
+                .setCreatedId(null).setModifiedId(null).setRowNum(null).setName("test1").setActive(true)
+                .setPriority(null).setRoleFunctions(new TreeSet<>()).setChildRoles(new TreeSet<>())
+                .setParentRoles(new TreeSet<>()).createCentralV2Role();
+        CentralV2Role cenV2Role2 = new CentralV2Role.CentralV2RoleBuilder().setId(16l).setCreated(null)
+                .setModified(null).setCreatedId(null).setModifiedId(null).setRowNum(null).setName("test2")
+                .setActive(true).setPriority(null).setRoleFunctions(new TreeSet<>()).setChildRoles(new TreeSet<>())
+                .setParentRoles(new TreeSet<>()).createCentralV2Role();
                mockCenV2Role.add(cenV2Role);
                mockCenV2Role.add(cenV2Role2);
                Mockito.when(externalAccessRolesServiceImpl.getRolesForApp(mockApp.getUebKey())).thenReturn(mockCenV2Role);
@@ -363,11 +360,11 @@ public class UserRolesCommonServiceImplTest {
                Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
                List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
                RoleInAppForUser mockRoleInAppForUser = new RoleInAppForUser();
-               mockRoleInAppForUser.setIsApplied(false);
+           mockRoleInAppForUser.setIsApplied(true);
                mockRoleInAppForUser.setRoleId(333l);
                mockRoleInAppForUser.setRoleName("test1");
                RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
-               mockRoleInAppForUser2.setIsApplied(false);
+           mockRoleInAppForUser2.setIsApplied(true);
                mockRoleInAppForUser2.setRoleId(777l);
                mockRoleInAppForUser2.setRoleName("test2");
                RoleInAppForUser mockRoleInAppForUser3 = new RoleInAppForUser();
@@ -673,7 +670,7 @@ public class UserRolesCommonServiceImplTest {
                Mockito.when(session.createSQLQuery("update fn_role set app_id = null where app_id = 1 "))
                                .thenReturn(epsetAppWithUserRoleUpdateEPRoleQuery);
                ExternalRequestFieldsValidator actual = userRolesCommonServiceImpl.setAppWithUserRoleStateForUser(user, mockWithRolesForUser);
-               assertFalse(actual.isResult());
+               assertTrue(actual.isResult());
        }
 
        private List<EcompUserAppRoles> getCurrentUserRoles(EPUser user, EPApp mockApp) {
@@ -1252,7 +1249,10 @@ public class UserRolesCommonServiceImplTest {
                mockUserApplicationRoles2.setRoles(mockRemoteRoleList2);
                mockUserApplicationRolesList.add(mockUserApplicationRoles);
                mockUserApplicationRolesList.add(mockUserApplicationRoles2);
-               Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsers", null, null))
+               Map<String, Object> params = new HashMap<>();
+               params.put("id", 1l);
+               params.put("active", true);
+               Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsersForApp", params, null))
                                .thenReturn(mockEpUserList);
                assertEquals(userRolesCommonServiceImpl.getUsersFromAppEndpoint(1l).size(),
                                mockUserApplicationRolesList.size());