use of org.apache.ranger.view.VXGroupUser in project ranger by apache.
the class XGroupUserService method readResourceWithOutLogin.
public VXGroupUser readResourceWithOutLogin(Long id) {
XXGroupUser resource = getDao().getById(id);
if (resource == null) {
// Returns code 400 with DATA_NOT_FOUND as the error message
throw restErrorUtil.createRESTException(getResourceName() + " not found", MessageEnums.DATA_NOT_FOUND, id, null, "preRead: " + id + " not found.");
}
VXGroupUser view = populateViewBean(resource);
return view;
}
use of org.apache.ranger.view.VXGroupUser in project ranger by apache.
the class XGroupUserServiceBase method searchXGroupUsers.
/**
* @param searchCriteria
* @return
*/
public VXGroupUserList searchXGroupUsers(SearchCriteria searchCriteria) {
VXGroupUserList returnList = new VXGroupUserList();
List<VXGroupUser> xGroupUserList = new ArrayList<VXGroupUser>();
List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
// Iterate over the result list and create the return list
for (T gjXGroupUser : resultList) {
VXGroupUser vXGroupUser = populateViewBean(gjXGroupUser);
xGroupUserList.add(vXGroupUser);
}
returnList.setVXGroupUsers(xGroupUserList);
return returnList;
}
use of org.apache.ranger.view.VXGroupUser in project ranger by apache.
the class TestXUserREST method test30searchXGroupUsers.
@SuppressWarnings("unchecked")
@Test
public void test30searchXGroupUsers() {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchCriteria testSearchCriteria = createsearchCriteria();
Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
VXGroupUserList testVXGroupUserList = new VXGroupUserList();
VXGroupUser vXGroupUser = createVXGroupUser();
List<VXGroupUser> vXGroupUsers = new ArrayList<VXGroupUser>();
vXGroupUsers.add(vXGroupUser);
testVXGroupUserList.setVXGroupUsers(vXGroupUsers);
Mockito.when(xUserMgr.searchXGroupUsers(testSearchCriteria)).thenReturn(testVXGroupUserList);
VXGroupUserList outputvXGroupList = xUserRest.searchXGroupUsers(request);
Mockito.verify(xUserMgr).searchXGroupUsers(testSearchCriteria);
Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
assertNotNull(outputvXGroupList);
assertEquals(outputvXGroupList.getClass(), testVXGroupUserList.getClass());
assertEquals(outputvXGroupList.getResultSize(), testVXGroupUserList.getResultSize());
}
use of org.apache.ranger.view.VXGroupUser in project ranger by apache.
the class TestXUserREST method test28updateXGroupUser.
@Test
public void test28updateXGroupUser() {
VXGroupUser testVXGroupUser = createVXGroupUser();
Mockito.when(xUserMgr.updateXGroupUser(testVXGroupUser)).thenReturn(testVXGroupUser);
VXGroupUser retVxGroupUser = xUserRest.updateXGroupUser(testVXGroupUser);
assertNotNull(retVxGroupUser);
assertEquals(testVXGroupUser.getClass(), retVxGroupUser.getClass());
assertEquals(testVXGroupUser.getId(), retVxGroupUser.getId());
Mockito.verify(xUserMgr).updateXGroupUser(testVXGroupUser);
}
use of org.apache.ranger.view.VXGroupUser 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());
}
Aggregations