Search in sources :

Example 56 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class TestXUserREST method test48searchXPermMaps.

@SuppressWarnings("unchecked")
@Test
public void test48searchXPermMaps() {
    VXPermMap permMap = testcreateXPermMap();
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchCriteria testSearchCriteria = createsearchCriteria();
    Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
    List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
    vXPermMaps.add(permMap);
    VXPermMapList testvXGroupList = new VXPermMapList();
    testvXGroupList.setTotalCount(1);
    testvXGroupList.setVXPermMaps(vXPermMaps);
    Mockito.when(xUserMgr.searchXPermMaps(testSearchCriteria)).thenReturn(testvXGroupList);
    VXPermMapList outputvXGroupList = xUserRest.searchXPermMaps(request);
    Mockito.verify(xUserMgr).searchXPermMaps(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    assertNotNull(outputvXGroupList);
    assertEquals(outputvXGroupList.getClass(), testvXGroupList.getClass());
    assertEquals(outputvXGroupList.getTotalCount(), testvXGroupList.getTotalCount());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXPermMap(org.apache.ranger.view.VXPermMap) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXPermMapList(org.apache.ranger.view.VXPermMapList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 57 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class TestUserMgr method test25searchUsers.

@Test
public void test25searchUsers() {
    Query query = Mockito.mock(Query.class);
    EntityManager entityManager = Mockito.mock(EntityManager.class);
    SearchCriteria searchCriteria = new SearchCriteria();
    searchCriteria.setDistinct(true);
    searchCriteria.setGetChildren(true);
    searchCriteria.setGetCount(true);
    searchCriteria.setMaxRows(12);
    searchCriteria.setOwnerId(userId);
    searchCriteria.setStartIndex(1);
    searchCriteria.setSortBy("asc");
    Long count = 1l;
    Mockito.when(daoManager.getEntityManager()).thenReturn(entityManager);
    Mockito.when(entityManager.createQuery(Mockito.anyString())).thenReturn(query);
    Mockito.when(query.getSingleResult()).thenReturn(count);
    VXPortalUserList dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
    Assert.assertNotNull(dbVXPortalUserList);
    Mockito.verify(query).getSingleResult();
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) VXPortalUserList(org.apache.ranger.view.VXPortalUserList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 58 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria 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 59 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class TestAssetREST method testGetAccessLogs.

@Test
public void testGetAccessLogs() {
    SearchCriteria searchCriteria = new SearchCriteria();
    List<SortField> sortFields = null;
    List<VXAccessAudit> vXAccessAudits = new ArrayList<VXAccessAudit>();
    VXAccessAuditList vXAccessAuditList = new VXAccessAuditList();
    vXAccessAuditList.setVXAccessAudits(vXAccessAudits);
    Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria);
    Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn("test");
    Mockito.when(searchUtil.extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Integer) 8);
    Mockito.when(searchUtil.extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(new Date());
    Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l);
    Mockito.when(msBizUtil.isKeyAdmin()).thenReturn(false);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xxServiceDefDao);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setId(Id);
    Mockito.when(xxServiceDefDao.findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME)).thenReturn(xServiceDef);
    Mockito.when(assetMgr.getAccessLogs(searchCriteria)).thenReturn(vXAccessAuditList);
    VXAccessAuditList expectedVXAccessAuditList = assetREST.getAccessLogs(request);
    Assert.assertEquals(vXAccessAuditList, expectedVXAccessAuditList);
    Mockito.verify(msBizUtil).isKeyAdmin();
    Mockito.verify(assetMgr).getAccessLogs(searchCriteria);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(searchUtil, Mockito.times(12)).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.nullable(String.class));
    Mockito.verify(searchUtil, Mockito.times(4)).extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil, Mockito.times(2)).extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil).extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXAccessAudit(org.apache.ranger.view.VXAccessAudit) VXAccessAuditList(org.apache.ranger.view.VXAccessAuditList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date) Test(org.junit.Test)

Example 60 with SearchCriteria

use of org.apache.ranger.common.SearchCriteria in project ranger by apache.

the class TestAssetREST method testSearchXPolicyExportAudits.

@Test
public void testSearchXPolicyExportAudits() {
    SearchCriteria searchCriteria = new SearchCriteria();
    List<SortField> sortFields = null;
    List<VXPolicyExportAudit> vXPolicyExportAudits = new ArrayList<VXPolicyExportAudit>();
    VXPolicyExportAuditList vXPolicyExportAuditList = new VXPolicyExportAuditList();
    vXPolicyExportAuditList.setVXPolicyExportAudits(vXPolicyExportAudits);
    Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria);
    Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn("test");
    Mockito.when(searchUtil.extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Integer) 8);
    Mockito.when(assetMgr.searchXPolicyExportAudits(searchCriteria)).thenReturn(vXPolicyExportAuditList);
    VXPolicyExportAuditList expectedVXPolicyExportAuditList = assetREST.searchXPolicyExportAudits(request);
    Assert.assertEquals(vXPolicyExportAuditList, expectedVXPolicyExportAuditList);
    Mockito.verify(searchUtil).extractCommonCriterias(request, sortFields);
    Mockito.verify(searchUtil, Mockito.times(4)).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil).extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil, Mockito.times(2)).extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), (String) Mockito.isNull());
    Mockito.verify(searchUtil).extractCommonCriterias(request, sortFields);
    Mockito.verify(assetMgr).searchXPolicyExportAudits(searchCriteria);
}
Also used : VXPolicyExportAuditList(org.apache.ranger.view.VXPolicyExportAuditList) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXPolicyExportAudit(org.apache.ranger.view.VXPolicyExportAudit) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Aggregations

SearchCriteria (org.apache.ranger.common.SearchCriteria)61 Test (org.junit.Test)29 SortField (org.apache.ranger.common.SortField)27 ArrayList (java.util.ArrayList)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)20 GET (javax.ws.rs.GET)13 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 VXLong (org.apache.ranger.view.VXLong)10 Date (java.util.Date)9 DateUtil (org.apache.ranger.common.DateUtil)6 HashMap (java.util.HashMap)4 XXPortalUser (org.apache.ranger.entity.XXPortalUser)4 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)4 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)4 VXPermMap (org.apache.ranger.view.VXPermMap)4 VXUserList (org.apache.ranger.view.VXUserList)4 List (java.util.List)3 XXServiceDef (org.apache.ranger.entity.XXServiceDef)3