Search in sources :

Example 16 with XXGroupUserDao

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);
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) UserSessionBase(org.apache.ranger.common.UserSessionBase) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with XXGroupUserDao

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());
}
Also used : XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 18 with XXGroupUserDao

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);
}
Also used : XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) Test(org.junit.Test)

Example 19 with XXGroupUserDao

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());
}
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 20 with XXGroupUserDao

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();
}
Also used : XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) VXModuleDef(org.apache.ranger.view.VXModuleDef) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)21 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)15 XXGroupUser (org.apache.ranger.entity.XXGroupUser)8 UserSessionBase (org.apache.ranger.common.UserSessionBase)7 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)7 XXModuleDef (org.apache.ranger.entity.XXModuleDef)7 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)7 HashSet (java.util.HashSet)6 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)6 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)6 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)6 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)6 XXPolicy (org.apache.ranger.entity.XXPolicy)6 VXGroup (org.apache.ranger.view.VXGroup)6 VXGroupUser (org.apache.ranger.view.VXGroupUser)6 VXUser (org.apache.ranger.view.VXUser)6 XXGroupDao (org.apache.ranger.db.XXGroupDao)5 XXUserDao (org.apache.ranger.db.XXUserDao)5