Search in sources :

Example 11 with VXUser

use of org.apache.ranger.view.VXUser in project ranger by apache.

the class TestXUserREST method test102deleteUsersByUserNameSetValueNull.

@Test
public void test102deleteUsersByUserNameSetValueNull() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    String TestforceDeleteStr = "false";
    boolean forceDelete = true;
    Mockito.when(request.getParameter("forceDelete")).thenReturn(TestforceDeleteStr);
    VXString testVXString = new VXString();
    testVXString.setValue("User1");
    VXUser testVXUser = createVXUser();
    VXStringList vxStringList = createVXStringList();
    Mockito.when(xUserService.getXUserByUserName(testVXString.getValue())).thenReturn(testVXUser);
    forceDelete = false;
    Mockito.doNothing().when(xUserMgr).deleteXUser(testVXUser.getId(), forceDelete);
    xUserRest.deleteUsersByUserName(request, vxStringList);
    Mockito.verify(xUserMgr).deleteXUser(testVXUser.getId(), forceDelete);
    Mockito.verify(xUserService).getXUserByUserName(testVXString.getValue());
    Mockito.verify(request).getParameter("forceDelete");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXString(org.apache.ranger.view.VXString) VXStringList(org.apache.ranger.view.VXStringList) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 12 with VXUser

use of org.apache.ranger.view.VXUser in project ranger by apache.

the class TestXUserREST method test64deleteXUserByUserName.

@Test
public void test64deleteXUserByUserName() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    String TestforceDeleteStr = "true";
    boolean forceDelete = false;
    Mockito.when(request.getParameter("forceDelete")).thenReturn(TestforceDeleteStr);
    VXUser testUser = createVXUser();
    Mockito.when(xUserService.getXUserByUserName(testUser.getName())).thenReturn(testUser);
    forceDelete = true;
    Mockito.doNothing().when(xUserMgr).deleteXUser(testUser.getId(), forceDelete);
    xUserRest.deleteXUserByUserName(testUser.getName(), request);
    Mockito.verify(xUserMgr).deleteXUser(testUser.getId(), forceDelete);
    Mockito.verify(xUserService).getXUserByUserName(testUser.getName());
    Mockito.verify(request).getParameter("forceDelete");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 13 with VXUser

use of org.apache.ranger.view.VXUser in project ranger by apache.

the class TestXUserREST method test62getXUserByUserName.

@Test
public void test62getXUserByUserName() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    VXUser compareTestVxUser = createVXUser();
    Mockito.when(xUserMgr.getXUserByUserName("User1")).thenReturn(compareTestVxUser);
    VXUser retVXUser = xUserRest.getXUserByUserName(request, "User1");
    assertNotNull(retVXUser);
    assertEquals(compareTestVxUser.getClass(), retVXUser.getClass());
    assertEquals(compareTestVxUser.getId(), retVXUser.getId());
    Mockito.verify(xUserMgr).getXUserByUserName("User1");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 14 with VXUser

use of org.apache.ranger.view.VXUser in project ranger by apache.

the class TestXUserREST method test66deleteXUserByUserNameNull.

@Test
public void test66deleteXUserByUserNameNull() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    String TestforceDeleteStr = null;
    boolean forceDelete = true;
    Mockito.when(request.getParameter("forceDelete")).thenReturn(TestforceDeleteStr);
    VXUser testUser = createVXUser();
    Mockito.when(xUserService.getXUserByUserName(testUser.getName())).thenReturn(testUser);
    forceDelete = false;
    Mockito.doNothing().when(xUserMgr).deleteXUser(testUser.getId(), forceDelete);
    xUserRest.deleteXUserByUserName(testUser.getName(), request);
    Mockito.verify(xUserMgr).deleteXUser(testUser.getId(), forceDelete);
    Mockito.verify(xUserService).getXUserByUserName(testUser.getName());
    Mockito.verify(request).getParameter("forceDelete");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 15 with VXUser

use of org.apache.ranger.view.VXUser in project ranger by apache.

the class TestXUserREST method test24searchXUsers.

@SuppressWarnings("unchecked")
@Test
public void test24searchXUsers() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchCriteria testSearchCriteria = createsearchCriteria();
    Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "name", "User name", null)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "emailAddress", "Email Address", null)).thenReturn("");
    Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "userSource", "User Source")).thenReturn(1);
    Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "isVisible", "User Visibility")).thenReturn(1);
    Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "status", "User Status")).thenReturn(1);
    Mockito.when(searchUtil.extractStringList(request, testSearchCriteria, "userRoleList", "User Role List", "userRoleList", null, null)).thenReturn(new ArrayList<String>());
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "userRole", "UserRole", null)).thenReturn("");
    List<VXUser> vXUsersList = new ArrayList<VXUser>();
    vXUsersList.add(vxUser);
    VXUserList testVXUserList = new VXUserList();
    testVXUserList.setVXUsers(vXUsersList);
    Mockito.when(xUserMgr.searchXUsers(testSearchCriteria)).thenReturn(testVXUserList);
    VXUserList gotVXUserList = xUserRest.searchXUsers(request);
    Mockito.verify(xUserMgr).searchXUsers(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "name", "User name", null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "emailAddress", "Email Address", null);
    Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "userSource", "User Source");
    Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "isVisible", "User Visibility");
    Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "status", "User Status");
    Mockito.verify(searchUtil).extractStringList(request, testSearchCriteria, "userRoleList", "User Role List", "userRoleList", null, null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "userRole", "UserRole", null);
    assertNotNull(gotVXUserList);
    assertEquals(testVXUserList.getTotalCount(), gotVXUserList.getTotalCount());
    assertEquals(testVXUserList.getClass(), gotVXUserList.getClass());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXUserList(org.apache.ranger.view.VXUserList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Aggregations

VXUser (org.apache.ranger.view.VXUser)42 Test (org.junit.Test)31 VXString (org.apache.ranger.view.VXString)21 ArrayList (java.util.ArrayList)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 XXUser (org.apache.ranger.entity.XXUser)8 XXPortalUser (org.apache.ranger.entity.XXPortalUser)6 VXStringList (org.apache.ranger.view.VXStringList)6 VXPortalUser (org.apache.ranger.view.VXPortalUser)5 HashMap (java.util.HashMap)4 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)4 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)4 XXUserDao (org.apache.ranger.db.XXUserDao)4 VXUserList (org.apache.ranger.view.VXUserList)4 Date (java.util.Date)3 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)3 VXGroup (org.apache.ranger.view.VXGroup)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 IOException (java.io.IOException)2 List (java.util.List)2