Search in sources :

Example 21 with XXGroup

use of org.apache.ranger.entity.XXGroup in project ranger by apache.

the class XGroupUserService method createXGroupUserWithOutLogin.

public VXGroupUser createXGroupUserWithOutLogin(VXGroupUser vxGroupUser) {
    boolean groupUserMappingExists = true;
    XXGroupUser xxGroupUser = daoManager.getXXGroupUser().findByGroupNameAndUserId(vxGroupUser.getName(), vxGroupUser.getUserId());
    if (xxGroupUser == null) {
        xxGroupUser = new XXGroupUser();
        groupUserMappingExists = false;
    }
    XXGroup xGroup = daoManager.getXXGroup().findByGroupName(vxGroupUser.getName());
    vxGroupUser.setParentGroupId(xGroup.getId());
    xxGroupUser = mapViewToEntityBean(vxGroupUser, xxGroupUser, 0);
    XXPortalUser xXPortalUser = daoManager.getXXPortalUser().getById(createdByUserId);
    if (xXPortalUser != null) {
        xxGroupUser.setAddedByUserId(createdByUserId);
        xxGroupUser.setUpdatedByUserId(createdByUserId);
    }
    if (groupUserMappingExists) {
        xxGroupUser = getDao().update(xxGroupUser);
    } else {
        xxGroupUser = getDao().create(xxGroupUser);
    }
    vxGroupUser = postCreate(xxGroupUser);
    return vxGroupUser;
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXGroup(org.apache.ranger.entity.XXGroup)

Example 22 with XXGroup

use of org.apache.ranger.entity.XXGroup 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 23 with XXGroup

use of org.apache.ranger.entity.XXGroup 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)

Example 24 with XXGroup

use of org.apache.ranger.entity.XXGroup in project ranger by apache.

the class TestXUserMgr method test20ModifyGroupsVisibilitySetEmpty.

@Test
public void test20ModifyGroupsVisibilitySetEmpty() {
    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>();
    groupVisibilityMap.put(userId, emptyValue);
    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(emptyValue, 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

XXGroup (org.apache.ranger.entity.XXGroup)24 ArrayList (java.util.ArrayList)11 XXUser (org.apache.ranger.entity.XXUser)10 VXGroup (org.apache.ranger.view.VXGroup)7 XXGroupDao (org.apache.ranger.db.XXGroupDao)6 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 XXTrxLog (org.apache.ranger.entity.XXTrxLog)4 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)3 XXPermMap (org.apache.ranger.entity.XXPermMap)3 XXPortalUser (org.apache.ranger.entity.XXPortalUser)3 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)3 Field (java.lang.reflect.Field)2 Date (java.util.Date)2 Random (java.util.Random)2 SearchCriteria (org.apache.ranger.common.SearchCriteria)2 SearchField (org.apache.ranger.common.SearchField)2 VTrxLogAttr (org.apache.ranger.common.view.VTrxLogAttr)2 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)2