use of org.apache.ranger.common.SortField 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());
}
use of org.apache.ranger.common.SortField 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);
}
use of org.apache.ranger.common.SortField in project ranger by apache.
the class TestAssetREST method testSearchXCredentialStores.
@Test
public void testSearchXCredentialStores() {
VXCredentialStore vXCredentialStore = vXCredentialStore();
List<VXCredentialStore> vXCredentialStores = Arrays.asList(vXCredentialStore);
VXCredentialStoreList vXCredentialStoreList = new VXCredentialStoreList();
vXCredentialStoreList.setVXCredentialStores(vXCredentialStores);
SearchCriteria searchCriteria = new SearchCriteria();
List<SortField> sortFields = null;
Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria);
Mockito.when(assetMgr.searchXCredentialStores(searchCriteria)).thenReturn(vXCredentialStoreList);
VXCredentialStoreList actualvxCredentialStoreList = assetREST.searchXCredentialStores(request);
Assert.assertEquals(vXCredentialStoreList.getVXCredentialStores(), actualvxCredentialStoreList.getVXCredentialStores());
Mockito.verify(assetMgr).searchXCredentialStores(searchCriteria);
}
use of org.apache.ranger.common.SortField in project ranger by apache.
the class SolrUtil method setSortClause.
public void setSortClause(SearchCriteria searchCriteria, List<SortField> sortFields, SolrQuery query) {
// TODO: We are supporting single sort field only for now
String sortBy = searchCriteria.getSortBy();
String querySortBy = null;
if (!stringUtil.isEmpty(sortBy)) {
sortBy = sortBy.trim();
for (SortField sortField : sortFields) {
if (sortBy.equalsIgnoreCase(sortField.getParamName())) {
querySortBy = sortField.getFieldName();
// Override the sortBy using the normalized value
searchCriteria.setSortBy(sortField.getParamName());
break;
}
}
}
if (querySortBy == null) {
for (SortField sortField : sortFields) {
if (sortField.isDefault()) {
querySortBy = sortField.getFieldName();
// Override the sortBy using the default value
searchCriteria.setSortBy(sortField.getParamName());
searchCriteria.setSortType(sortField.getDefaultOrder().name());
break;
}
}
}
if (querySortBy != null) {
// Add sort type
String sortType = searchCriteria.getSortType();
ORDER order = ORDER.asc;
if (sortType != null && "desc".equalsIgnoreCase(sortType)) {
order = ORDER.desc;
}
query.addSort(querySortBy, order);
}
}
Aggregations