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;
}
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());
}
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);
}
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);
}
Aggregations