Search in sources :

Example 26 with VXGroup

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);
}
Also used : VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 27 with VXGroup

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());
}
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 28 with VXGroup

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());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) VXUserGroupInfo(org.apache.ranger.view.VXUserGroupInfo) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 29 with VXGroup

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);
}
Also used : VXUserList(org.apache.ranger.view.VXUserList) VXGroup(org.apache.ranger.view.VXGroup) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 30 with VXGroup

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

VXGroup (org.apache.ranger.view.VXGroup)32 Test (org.junit.Test)26 VXString (org.apache.ranger.view.VXString)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 XXGroup (org.apache.ranger.entity.XXGroup)7 ArrayList (java.util.ArrayList)5 XXGroupDao (org.apache.ranger.db.XXGroupDao)5 VXStringList (org.apache.ranger.view.VXStringList)4 HashMap (java.util.HashMap)3 VXGroupUser (org.apache.ranger.view.VXGroupUser)3 VXUser (org.apache.ranger.view.VXUser)3 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)2 VXGroupList (org.apache.ranger.view.VXGroupList)2 VXGroupUserList (org.apache.ranger.view.VXGroupUserList)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 SearchCriteria (org.apache.ranger.common.SearchCriteria)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)1