Search in sources :

Example 11 with XXGroupDao

use of org.apache.ranger.db.XXGroupDao in project ranger by apache.

the class TestXUserMgr method test122UpdateDeletedGroups.

@Test
public void test122UpdateDeletedGroups() {
    destroySession();
    setup();
    XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
    VXGroup vxGroup = vxGroup();
    XXGroup xxGroup = new XXGroup();
    xxGroup.setId(vxGroup.getId());
    xxGroup.setName(vxGroup.getName());
    xxGroup.setDescription(vxGroup.getDescription());
    xxGroup.setIsVisible(vxGroup.getIsVisible());
    Set<String> delGroups = new HashSet<String>();
    delGroups.add(vxGroup.getName());
    Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
    Mockito.when(xxGroupDao.findByGroupName(vxGroup.getName())).thenReturn(xxGroup);
    Mockito.when(xGroupService.populateViewBean(xxGroup)).thenReturn(vxGroup);
    Mockito.when(xGroupService.updateResource(vxGroup)).thenReturn(vxGroup);
    int count = xUserMgr.updateDeletedGroups(delGroups);
    Assert.assertNotNull(count);
    Assert.assertEquals(count, 1);
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup) VXString(org.apache.ranger.view.VXString) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with XXGroupDao

use of org.apache.ranger.db.XXGroupDao in project ranger by apache.

the class TestXUserMgr method test53getXGroupUserFromMap.

@Test
public void test53getXGroupUserFromMap() {
    setup();
    VXGroup vxGroup = vxGroup();
    VXUser vxUser = vxUser();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    vXUserList.add(vxUser);
    VXGroupUserInfo vxGUInfo = new VXGroupUserInfo();
    vxGUInfo.setXgroupInfo(vxGroup);
    vxGUInfo.setXuserInfo(vXUserList);
    XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
    XXGroup xxGroup = new XXGroup();
    xxGroup.setId(vxGroup.getId());
    xxGroup.setName(vxGroup.getName());
    xxGroup.setDescription(vxGroup.getDescription());
    xxGroup.setIsVisible(vxGroup.getIsVisible());
    VXPortalUser userProfile = userProfile();
    XXPortalUser xXPortalUser = xxPortalUser(userProfile);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    VXGroupUserList vxGroupUserList = new VXGroupUserList();
    List<VXGroupUser> vXGroupUsers = new ArrayList<VXGroupUser>();
    VXGroupUser vxGroupUser = vxGroupUser();
    vXGroupUsers.add(vxGroupUser);
    vxGroupUserList.setVXGroupUsers(vXGroupUsers);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_USER);
    Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
    SearchCriteria searchCriteria = createsearchCriteria();
    searchCriteria.addParam("xGroupId", xxGroup.getId());
    Mockito.when(xxGroupDao.findByGroupName("")).thenReturn(null);
    VXGroupUserInfo vxGUInfoObjNull = xUserMgr.getXGroupUserFromMap("");
    Assert.assertNull(vxGUInfoObjNull.getXgroupInfo());
    Mockito.when(xxGroupDao.findByGroupName(Mockito.anyString())).thenReturn(xxGroup);
    Mockito.when(xGroupService.populateViewBean(xxGroup)).thenReturn(vxGroup);
    Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
    XXUser xXUser = xxUser(vxUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.getById(userId)).thenReturn(xXUser);
    XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(xXPortalUserDao.findByLoginId(xXUser.getName().trim())).thenReturn(xXPortalUser);
    XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
    vxGUInfoObjNull = xUserMgr.getXGroupUserFromMap(xxGroup.getName());
}
Also used : XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) SearchCriteria(org.apache.ranger.common.SearchCriteria) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXGroup(org.apache.ranger.entity.XXGroup) VXGroupUserInfo(org.apache.ranger.view.VXGroupUserInfo) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) Test(org.junit.Test)

Example 13 with XXGroupDao

use of org.apache.ranger.db.XXGroupDao in project ranger by apache.

the class TestXUserMgr method test12ModifyGroupsVisibilitySetZero.

@Test
public void test12ModifyGroupsVisibilitySetZero() {
    setup();
    XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
    VXGroup vXGroup = vxGroup();
    XXGroup xxGroup = new XXGroup();
    HashMap<Long, Integer> groupVisibilityMap = new HashMap<Long, Integer>();
    Integer value = 0;
    groupVisibilityMap.put(userId, value);
    Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
    Mockito.when(xxGroupDao.getById(vXGroup.getId())).thenReturn(xxGroup);
    Mockito.when(xGroupService.populateViewBean(xxGroup)).thenReturn(vXGroup);
    Mockito.when(xGroupService.updateResource(vXGroup)).thenReturn(vXGroup);
    xUserMgr.modifyGroupsVisibility(groupVisibilityMap);
    Assert.assertEquals(value, vXGroup.getIsVisible());
    Assert.assertEquals(userId, vXGroup.getId());
    Mockito.verify(daoManager).getXXGroup();
    Mockito.verify(xGroupService).populateViewBean(xxGroup);
    Mockito.verify(xGroupService).updateResource(vXGroup);
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup) HashMap(java.util.HashMap) VXLong(org.apache.ranger.view.VXLong) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) Test(org.junit.Test)

Example 14 with XXGroupDao

use of org.apache.ranger.db.XXGroupDao in project ranger by apache.

the class TestXUserMgr method test17UpdateXGroup.

@Test
public void test17UpdateXGroup() {
    XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
    XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
    List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
    setup();
    VXGroup vXGroup = new VXGroup();
    vXGroup.setId(userId);
    vXGroup.setDescription("group test");
    vXGroup.setName("grouptest");
    XXGroup xxGroup = new XXGroup();
    Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
    Mockito.when(xxGroupDao.getById(vXGroup.getId())).thenReturn(xxGroup);
    Mockito.when(xGroupService.updateResource(vXGroup)).thenReturn(vXGroup);
    Mockito.when(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
    Mockito.when(xxGroupUserDao.findByGroupId(vXGroup.getId())).thenReturn(grpUsers);
    VXGroup dbvxGroup = xUserMgr.updateXGroup(vXGroup);
    Assert.assertNotNull(dbvxGroup);
    userId = dbvxGroup.getId();
    Assert.assertEquals(userId, dbvxGroup.getId());
    Assert.assertEquals(vXGroup.getDescription(), dbvxGroup.getDescription());
    Assert.assertEquals(vXGroup.getName(), dbvxGroup.getName());
    Mockito.verify(daoManager).getXXGroup();
    Mockito.verify(daoManager).getXXGroupUser();
    Mockito.verify(xGroupService).updateResource(vXGroup);
    Mockito.verify(xxGroupUserDao).findByGroupId(vXGroup.getId());
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXGroup(org.apache.ranger.entity.XXGroup) ArrayList(java.util.ArrayList) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) Test(org.junit.Test)

Example 15 with XXGroupDao

use of org.apache.ranger.db.XXGroupDao in project ranger by apache.

the class TestXUserMgr method test19ModifyGroupsVisibilitySetZero.

@Test
public void test19ModifyGroupsVisibilitySetZero() {
    XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
    VXGroup vXGroup = new VXGroup();
    vXGroup.setId(userId);
    vXGroup.setDescription("group test");
    vXGroup.setName("grouptest");
    XXGroup xxGroup = new XXGroup();
    HashMap<Long, Integer> groupVisibilityMap = new HashMap<Long, Integer>();
    Integer value = 0;
    groupVisibilityMap.put(userId, value);
    Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
    Mockito.when(xxGroupDao.getById(vXGroup.getId())).thenReturn(xxGroup);
    Mockito.when(xGroupService.populateViewBean(xxGroup)).thenReturn(vXGroup);
    Mockito.when(xGroupService.updateResource(vXGroup)).thenReturn(vXGroup);
    xUserMgr.modifyGroupsVisibility(groupVisibilityMap);
    Assert.assertEquals(value, vXGroup.getIsVisible());
    Assert.assertEquals(userId, vXGroup.getId());
    Mockito.verify(daoManager).getXXGroup();
    Mockito.verify(xGroupService).populateViewBean(xxGroup);
    Mockito.verify(xGroupService).updateResource(vXGroup);
}
Also used : XXGroup(org.apache.ranger.entity.XXGroup) HashMap(java.util.HashMap) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) Test(org.junit.Test)

Aggregations

XXGroupDao (org.apache.ranger.db.XXGroupDao)16 XXGroup (org.apache.ranger.entity.XXGroup)16 VXGroup (org.apache.ranger.view.VXGroup)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)5 XXGroupGroupDao (org.apache.ranger.db.XXGroupGroupDao)4 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)4 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)4 XXGroupGroup (org.apache.ranger.entity.XXGroupGroup)4 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)4 XXPolicy (org.apache.ranger.entity.XXPolicy)4 VXGroupUserList (org.apache.ranger.view.VXGroupUserList)4 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)3 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)3 XXUserDao (org.apache.ranger.db.XXUserDao)3 XXResource (org.apache.ranger.entity.XXResource)3 XXUser (org.apache.ranger.entity.XXUser)3 VXLong (org.apache.ranger.view.VXLong)3