use of org.apache.ranger.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test32createXGroupPermission.
@Test
public void test32createXGroupPermission() {
VXGroupPermission vXGroupPermission = vxGroupPermission();
XXGroupUserDao xGrpUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGrpUserDao);
Mockito.when(xGroupPermissionService.createResource(vXGroupPermission)).thenReturn(vXGroupPermission);
List<XXGroupUser> xXGroupUserList = new ArrayList<XXGroupUser>();
VXGroupUser vxGroupUser = vxGroupUser();
XXGroupUser xXGroupUser = new XXGroupUser();
xXGroupUser.setId(vxGroupUser.getId());
xXGroupUser.setName(vxGroupUser.getName());
xXGroupUser.setParentGroupId(vxGroupUser.getParentGroupId());
xXGroupUser.setUserId(vxGroupUser.getUserId());
xXGroupUserList.add(xXGroupUser);
Mockito.when(xGrpUserDao.findByGroupId(vXGroupPermission.getGroupId())).thenReturn(xXGroupUserList);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
Mockito.when(sessionMgr.getActiveUserSessionsForXUserId(xXGroupUser.getUserId())).thenReturn(userSessions);
VXGroupPermission dbGroupPermission = xUserMgr.createXGroupPermission(vXGroupPermission);
Assert.assertNotNull(dbGroupPermission);
Assert.assertEquals(dbGroupPermission, vXGroupPermission);
Assert.assertEquals(dbGroupPermission.getId(), vXGroupPermission.getId());
Assert.assertEquals(dbGroupPermission.getGroupName(), vXGroupPermission.getGroupName());
Assert.assertEquals(dbGroupPermission.getOwner(), vXGroupPermission.getOwner());
Assert.assertEquals(dbGroupPermission.getUpdatedBy(), vXGroupPermission.getUpdatedBy());
Assert.assertEquals(dbGroupPermission.getCreateDate(), vXGroupPermission.getCreateDate());
Assert.assertEquals(dbGroupPermission.getGroupId(), vXGroupPermission.getGroupId());
Assert.assertEquals(dbGroupPermission.getIsAllowed(), vXGroupPermission.getIsAllowed());
Assert.assertEquals(dbGroupPermission.getModuleId(), vXGroupPermission.getModuleId());
Assert.assertEquals(dbGroupPermission.getUpdateDate(), vXGroupPermission.getUpdateDate());
Mockito.verify(xGroupPermissionService).createResource(vXGroupPermission);
}
use of org.apache.ranger.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test22DeleteXGroupAndXUser.
@Test
public void test22DeleteXGroupAndXUser() {
setup();
VXUser vxUser = vxUser();
VXGroup vxGroup = vxGroup();
VXGroupUserList vxGroupUserList = new VXGroupUserList();
List<VXGroupUser> vXGroupUsers = new ArrayList<VXGroupUser>();
VXGroupUser vxGroupUser = vxGroupUser();
vXGroupUsers.add(vxGroupUser);
vxGroupUserList.setVXGroupUsers(vXGroupUsers);
Mockito.when(xGroupService.getGroupByGroupName(Mockito.anyString())).thenReturn(vxGroup);
Mockito.when(xUserService.getXUserByUserName(Mockito.anyString())).thenReturn(vxUser);
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
XXGroupUserDao xGrpUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGrpUserDao);
Mockito.when(xGrpUserDao.remove(vxGroupUser.getId())).thenReturn(true);
xUserMgr.deleteXGroupAndXUser(groupName, userLoginID);
Mockito.verify(xGroupService).getGroupByGroupName(Mockito.anyString());
Mockito.verify(xUserService).getXUserByUserName(Mockito.anyString());
Mockito.verify(xGroupUserService).searchXGroupUsers((SearchCriteria) Mockito.any());
}
use of org.apache.ranger.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test42deleteXGroupPermission.
@Test
public void test42deleteXGroupPermission() {
XXGroupPermissionDao xGrpPermDao = Mockito.mock(XXGroupPermissionDao.class);
XXGroupPermission xGrpPerm = Mockito.mock(XXGroupPermission.class);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGrpPermDao);
Mockito.when(daoManager.getXXGroupPermission().getById(1L)).thenReturn(xGrpPerm);
XXGroupUserDao xGrpUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGrpUserDao);
Mockito.when(xGroupPermissionService.deleteResource(1L)).thenReturn(true);
xUserMgr.deleteXGroupPermission(1L, true);
Mockito.verify(xGroupPermissionService).deleteResource(1L);
}
use of org.apache.ranger.db.XXGroupUserDao 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.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test33updateXModuleDefPermission.
@Test
public void test33updateXModuleDefPermission() {
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXModuleDef xModuleDef = Mockito.mock(XXModuleDef.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
VXUserPermission vXUserPermission = vXUserPermission();
VXGroupPermission vXGroupPermission = vXGroupPermission();
VXModuleDef vXModuleDef = vXModuleDef();
Mockito.when(xModuleDefService.updateResource(vXModuleDef)).thenReturn(vXModuleDef);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.getById(userId)).thenReturn(xModuleDef);
Mockito.when(xModuleDefService.populateViewBean(xModuleDef)).thenReturn(vXModuleDef);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
XXGroupUserDao xGrpUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGrpUserDao);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
Mockito.when(xGroupPermissionService.createResource((VXGroupPermission) Mockito.any())).thenReturn(vXGroupPermission);
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vXUserPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
VXModuleDef dbMuduleDef = xUserMgr.updateXModuleDefPermission(vXModuleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertNotNull(dbMuduleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
Mockito.verify(xModuleDefService).updateResource(vXModuleDef);
Mockito.verify(daoManager).getXXModuleDef();
Mockito.verify(xModuleDefService).populateViewBean(xModuleDef);
Mockito.verify(daoManager).getXXUserPermission();
Mockito.verify(daoManager).getXXGroupPermission();
}
Aggregations