use of org.apache.ranger.view.VXGroup in project ranger by apache.
the class TestXUserMgr method test16CreateXGroup.
@Test
public void test16CreateXGroup() {
setup();
VXGroup vXGroup = new VXGroup();
vXGroup.setId(userId);
vXGroup.setDescription("group test");
vXGroup.setName("grouptest");
Mockito.when(xGroupService.createResource(vXGroup)).thenReturn(vXGroup);
VXGroup dbXGroup = xUserMgr.createXGroup(vXGroup);
Assert.assertNotNull(dbXGroup);
userId = dbXGroup.getId();
Assert.assertEquals(userId, dbXGroup.getId());
Assert.assertEquals(vXGroup.getDescription(), dbXGroup.getDescription());
Assert.assertEquals(vXGroup.getName(), dbXGroup.getName());
Mockito.verify(xGroupService).createResource(vXGroup);
Mockito.when(xGroupService.readResourceWithOutLogin(userId)).thenReturn(vXGroup);
VXGroup dbxGroup = xUserMgr.getXGroup(userId);
Assert.assertNotNull(dbXGroup);
Assert.assertEquals(userId, dbxGroup.getId());
Assert.assertEquals(dbXGroup.getDescription(), dbxGroup.getDescription());
Assert.assertEquals(dbXGroup.getName(), dbxGroup.getName());
Mockito.verify(xGroupService).readResourceWithOutLogin(userId);
}
use of org.apache.ranger.view.VXGroup 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.view.VXGroup in project ranger by apache.
the class TestXUserMgr method test30CreateVXUserGroupInfo.
@Test
public void test30CreateVXUserGroupInfo() {
setup();
VXUserGroupInfo vXUserGroupInfo = new VXUserGroupInfo();
VXUser vXUser = new VXUser();
vXUser.setName("user1");
vXUser.setDescription("testuser1 -added for unit testing");
vXUser.setPassword("usertest123");
List<VXGroupUser> vXGroupUserList = new ArrayList<VXGroupUser>();
List<VXGroup> vXGroupList = new ArrayList<VXGroup>();
final VXGroup vXGroup1 = new VXGroup();
vXGroup1.setName("users");
vXGroup1.setDescription("users -added for unit testing");
vXGroupList.add(vXGroup1);
VXGroupUser vXGroupUser1 = new VXGroupUser();
vXGroupUser1.setName("users");
vXGroupUserList.add(vXGroupUser1);
final VXGroup vXGroup2 = new VXGroup();
vXGroup2.setName("user1");
vXGroup2.setDescription("user1 -added for unit testing");
vXGroupList.add(vXGroup2);
VXGroupUser vXGroupUser2 = new VXGroupUser();
vXGroupUser2.setName("user1");
vXGroupUserList.add(vXGroupUser2);
vXUserGroupInfo.setXuserInfo(vXUser);
vXUserGroupInfo.setXgroupInfo(vXGroupList);
Mockito.when(xUserService.createXUserWithOutLogin(vXUser)).thenReturn(vXUser);
Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup1)).thenReturn(vXGroup1);
Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup2)).thenReturn(vXGroup2);
XXPortalUserDao portalUser = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(portalUser);
XXPortalUser user = new XXPortalUser();
user.setId(1L);
user.setUserSource(RangerCommonEnums.USER_APP);
Mockito.when(portalUser.findByLoginId(vXUser.getName())).thenReturn(user);
XXPortalUserRoleDao userDao = Mockito.mock(XXPortalUserRoleDao.class);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userDao);
List<String> lstRole = new ArrayList<String>();
lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
Mockito.when(userDao.findXPortalUserRolebyXPortalUserId(Mockito.anyLong())).thenReturn(lstRole);
VXUserGroupInfo vxUserGroupTest = xUserMgr.createXUserGroupFromMap(vXUserGroupInfo);
Assert.assertEquals("user1", vxUserGroupTest.getXuserInfo().getName());
List<VXGroup> result = vxUserGroupTest.getXgroupInfo();
List<VXGroup> expected = new ArrayList<VXGroup>();
expected.add(vXGroup1);
expected.add(vXGroup2);
Assert.assertTrue(result.containsAll(expected));
// Mockito.verify(daoManager).getXXPortalUser();
Mockito.verify(portalUser).findByLoginId(vXUser.getName());
// Mockito.verify(daoManager).getXXPortalUserRole();
Mockito.verify(userDao).findXPortalUserRolebyXPortalUserId(Mockito.anyLong());
}
use of org.apache.ranger.view.VXGroup in project ranger by apache.
the class TestXUserMgr method test23GetXGroupUsers.
@Test
public void test23GetXGroupUsers() {
SearchCriteria testSearchCriteria = createsearchCriteria();
testSearchCriteria.addParam("xGroupId", userId);
VXUserList dbVXUserList = xUserMgr.getXGroupUsers(testSearchCriteria);
VXGroup vXGroup = new VXGroup();
vXGroup.setId(userId);
vXGroup.setDescription("group test");
vXGroup.setName("grouptest");
Assert.assertNotNull(dbVXUserList);
}
use of org.apache.ranger.view.VXGroup 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);
}
Aggregations