use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method toSearchParameters.
@Test
public void toSearchParameters() throws Exception {
SearchRequestContext searchRequest = SearchRequestContext.from(minimalQuery());
SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, minimalQuery(), searchRequest);
assertNotNull(searchParameters);
// Test defaults
assertEquals("There should be only 1 default store", 1, searchParameters.getStores().size());
assertEquals("workspaces store is the default", StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0));
assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
assertEquals(100, searchParameters.getLimit());
searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, helper.searchQueryFromJson(), searchRequest);
assertNotNull(searchParameters);
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromPaging.
@Test
public void fromPaging() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromPaging(searchParameters, null);
Paging paging = Paging.DEFAULT;
searchMapper.fromPaging(searchParameters, paging);
assertEquals(searchParameters.getLimit(), paging.getMaxItems());
assertEquals(searchParameters.getSkipCount(), paging.getSkipCount());
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromSort.
@Test
public void fromSort() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromSort(searchParameters, null);
try {
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("wrongenum", null, false)));
fail();
} catch (InvalidArgumentException iae) {
// wrongenum is illegal
assertNotNull(iae);
}
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", "my", true), new SortDef("SCORE", null, false), new SortDef("DOCUMENT", null, true)));
assertEquals(3, searchParameters.getSortDefinitions().size());
searchParameters.getSortDefinitions().forEach(sortDefinition -> {
switch(sortDefinition.getSortType()) {
case FIELD:
assertEquals("my", sortDefinition.getField());
assertEquals(true, sortDefinition.isAscending());
break;
case SCORE:
assertNull(sortDefinition.getField());
assertEquals(false, sortDefinition.isAscending());
break;
case DOCUMENT:
assertNull(sortDefinition.getField());
assertEquals(true, sortDefinition.isAscending());
break;
default:
fail("Invalid sortDefinition");
}
});
searchParameters = new SearchParameters();
searchParameters.setLanguage(SearchService.LANGUAGE_CMIS_ALFRESCO);
try {
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", null, false)));
fail();
} catch (InvalidArgumentException iae) {
// You can't specify SORT when using the CMIS language
assertNotNull(iae);
}
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromDefaults.
@Test
public void fromDefaults() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromDefault(searchParameters, null);
searchMapper.fromDefault(searchParameters, new Default(null, null, null, null, null));
searchMapper.fromDefault(searchParameters, new Default(null, "AND", null, null, null));
assertEquals("AND", searchParameters.getDefaultFTSOperator().toString());
searchMapper.fromDefault(searchParameters, new Default(null, null, "or", null, null));
assertEquals("OR", searchParameters.getDefaultFTSFieldOperator().toString());
try {
searchMapper.fromDefault(searchParameters, new Default(null, null, "ELSE", null, null));
fail();
} catch (IllegalArgumentException iae) {
// ELSE is illegal
assertNotNull(iae);
}
searchMapper.fromDefault(searchParameters, new Default(null, null, null, "nspa", "dfn"));
assertEquals("nspa", searchParameters.getNamespace());
assertEquals("dfn", searchParameters.getDefaultFieldName());
assertEquals(0, searchParameters.getTextAttributes().size());
searchMapper.fromDefault(searchParameters, new Default(Arrays.asList("sausage", "mash"), null, null, null, null));
assertEquals(2, searchParameters.getTextAttributes().size());
assertTrue(searchParameters.getTextAttributes().contains("sausage"));
assertTrue(searchParameters.getTextAttributes().contains("mash"));
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromLimits.
@Test
public void fromLimits() throws Exception {
SearchParameters searchParameters = new SearchParameters();
searchMapper.setDefaults(searchParameters);
// Doesn't error
searchMapper.fromLimits(searchParameters, null);
assertEquals(500, searchParameters.getLimit());
assertEquals(LimitBy.UNLIMITED, searchParameters.getLimitBy());
searchMapper.fromLimits(searchParameters, new Limits(null, null));
assertEquals(LimitBy.UNLIMITED, searchParameters.getLimitBy());
assertEquals(500, searchParameters.getLimit());
searchMapper.fromLimits(searchParameters, new Limits(null, 34));
assertEquals(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS, searchParameters.getLimitBy());
assertEquals(34, searchParameters.getMaxPermissionChecks());
assertEquals(-1, searchParameters.getLimit());
assertEquals(-1, searchParameters.getMaxPermissionCheckTimeMillis());
searchParameters = new SearchParameters();
searchMapper.setDefaults(searchParameters);
searchMapper.fromLimits(searchParameters, new Limits(1000, null));
assertEquals(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS, searchParameters.getLimitBy());
assertEquals(1000, searchParameters.getMaxPermissionCheckTimeMillis());
assertEquals(-1, searchParameters.getLimit());
assertEquals(-1, searchParameters.getMaxPermissionChecks());
}
Aggregations