Search in sources :

Example 6 with XXPortalUserDao

use of org.apache.ranger.db.XXPortalUserDao in project ranger by apache.

the class TestUserREST method test16ChangePassword.

@Test
public void test16ChangePassword() {
    XXPortalUser xxPUser = new XXPortalUser();
    VXResponse vxResponseExp = new VXResponse();
    vxResponseExp.setStatusCode(10);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(restErrorUtil.createRESTException("serverMsg.userRestUser", MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    VXResponse vxResponseAct = userREST.changePassword(userId, changePassword);
    Assert.assertNotNull(vxResponseAct);
    Assert.assertEquals(vxResponseExp, vxResponseAct);
    Assert.assertEquals(vxResponseExp.getStatusCode(), vxResponseAct.getStatusCode());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(userId);
    Mockito.verify(userManager).checkAccessForUpdate(xxPUser);
    Mockito.verify(changePassword).setId(userId);
    Mockito.verify(userManager).changePassword(changePassword);
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 7 with XXPortalUserDao

use of org.apache.ranger.db.XXPortalUserDao in project ranger by apache.

the class TestUserREST method test8Update.

@Test
public void test8Update() {
    VXPortalUser vxPUserExp = CreateVXPortalUser();
    vxPUserExp.setLoginId(loginId);
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp.setLoginId(loginId);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPUserExp);
    Mockito.doNothing().when(userManager).checkAccess(xxPUserExp);
    Mockito.doNothing().when(msRestUtil).validateVUserProfileForUpdate(xxPUserExp, vxPUserExp);
    Mockito.when(userManager.updateUser(vxPUserExp)).thenReturn(xxPUserExp);
    Mockito.when(userManager.mapXXPortalUserVXPortalUser(xxPUserExp)).thenReturn(vxPUserExp);
    VXPortalUser vxPUserAct = userREST.update(vxPUserExp, request);
    Assert.assertNotNull(vxPUserAct);
    Assert.assertEquals(xxPUserExp.getLoginId(), vxPUserAct.getLoginId());
    Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
    Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(userManager).checkAccess(xxPUserExp);
    Mockito.verify(msRestUtil).validateVUserProfileForUpdate(xxPUserExp, vxPUserExp);
    Mockito.verify(userManager).updateUser(vxPUserExp);
    Mockito.verify(userManager).mapXXPortalUserVXPortalUser(xxPUserExp);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 8 with XXPortalUserDao

use of org.apache.ranger.db.XXPortalUserDao in project ranger by apache.

the class TestUserREST method test17ChangePassword.

@Test
public void test17ChangePassword() {
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.nullable(Long.class), Mockito.nullable(String.class), Mockito.nullable(String.class))).thenReturn(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userREST.changePassword(userId, changePassword);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(userId);
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 9 with XXPortalUserDao

use of org.apache.ranger.db.XXPortalUserDao in project ranger by apache.

the class TestUserREST method test9Update.

@Test
public void test9Update() {
    VXPortalUser vxPUserExp = new VXPortalUser();
    XXPortalUser xxPUserExp = new XXPortalUser();
    xxPUserExp = null;
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.doNothing().when(userManager).checkAccess(xxPUserExp);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.nullable(Long.class), Mockito.nullable(String.class), Mockito.anyString())).thenReturn(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    userREST.update(vxPUserExp, request);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(userManager).checkAccess(xxPUserExp);
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) WebApplicationException(javax.ws.rs.WebApplicationException) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) Test(org.junit.Test)

Example 10 with XXPortalUserDao

use of org.apache.ranger.db.XXPortalUserDao in project ranger by apache.

the class TestRangerBizUtil method testHasPermission_emptyResourceName.

@Test
public void testHasPermission_emptyResourceName() {
    VXResource vXResource = new VXResource();
    vXResource.setAssetId(12345L);
    XXPortalUser portalUser = new XXPortalUser();
    portalUser.setId(id);
    portalUser.setLoginId("12121");
    RangerContextHolder.getSecurityContext().getUserSession().setXXPortalUser(portalUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXUser xxUser = new XXUser();
    XXAsset xxAsset = new XXAsset();
    List<XXResource> lst = new ArrayList<XXResource>();
    XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
    XXAssetDao xxAssetDao = Mockito.mock(XXAssetDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.getById(Mockito.anyLong())).thenReturn(portalUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
    Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
    Mockito.when(xxResourceDao.findByAssetIdAndResourceStatus(Mockito.anyLong(), Mockito.anyInt())).thenReturn(lst);
    Mockito.when(daoManager.getXXAsset()).thenReturn(xxAssetDao);
    Mockito.when(xxAssetDao.getById(Mockito.anyLong())).thenReturn(xxAsset);
    VXResponse resp = rangerBizUtil.hasPermission(vXResource, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(userDao).getById(Mockito.anyLong());
    Mockito.verify(daoManager).getXXUser();
    Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
    Assert.assertNotNull(resp);
    Assert.assertEquals(VXResponse.STATUS_ERROR, resp.getStatusCode());
    Assert.assertEquals("Permission Denied !", resp.getMsgDesc());
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXUser(org.apache.ranger.entity.XXUser) XXAssetDao(org.apache.ranger.db.XXAssetDao) XXResource(org.apache.ranger.entity.XXResource) XXUserDao(org.apache.ranger.db.XXUserDao) VXResource(org.apache.ranger.view.VXResource) XXAsset(org.apache.ranger.entity.XXAsset) ArrayList(java.util.ArrayList) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) Test(org.junit.Test)

Aggregations

XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)35 Test (org.junit.Test)34 XXPortalUser (org.apache.ranger.entity.XXPortalUser)32 VXPortalUser (org.apache.ranger.view.VXPortalUser)21 ArrayList (java.util.ArrayList)16 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)13 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)12 VXString (org.apache.ranger.view.VXString)11 Date (java.util.Date)10 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)9 XXUserPermission (org.apache.ranger.entity.XXUserPermission)9 WebApplicationException (javax.ws.rs.WebApplicationException)7 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)7 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)7 XXModuleDef (org.apache.ranger.entity.XXModuleDef)6 VXPasswordChange (org.apache.ranger.view.VXPasswordChange)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)5 XXUserDao (org.apache.ranger.db.XXUserDao)5 XXUser (org.apache.ranger.entity.XXUser)5 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)4