use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.
the class WfsSourceTest method testSortingNoSortMapping.
@Test
public void testSortingNoSortMapping() throws Exception {
// if sorting is enabled but there is no sort mapping, throw an UnsupportedQueryException
expectedEx.expect(UnsupportedQueryException.class);
expectedEx.expectMessage("Source WFS_ID does not support specified sort property title");
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
setupMapper(null, null, null);
source.setMetacardMappers(metacardMappers);
source.setDisableSorting(false);
propertyIsLikeQuery.setSortBy(new SortByImpl("title", SortOrder.ASCENDING));
source.query(new QueryRequestImpl(propertyIsLikeQuery));
}
use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.
the class WfsSourceTest method testSortingSortOrderDescending.
@Test
public void testSortingSortOrderDescending() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
setupMapper(MOCK_TEMPORAL_SORT_PROPERTY, MOCK_RELEVANCE_SORT_PROPERTY, MOCK_DISTANCE_SORT_PROPERTY);
source.setMetacardMappers(metacardMappers);
propertyIsLikeQuery.setSortBy(new SortByImpl(Result.TEMPORAL, SortOrder.DESCENDING));
final ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
for (final ExtendedGetFeatureType getFeatureType : captor.getAllValues()) {
assertFeature(getFeatureType, true, MOCK_TEMPORAL_SORT_PROPERTY, "DESC");
}
}
use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.
the class WfsSourceTest method testSortingSortOrderAscending.
/**
* WFS 1.1.0 Sorting uses the following format: Valid sort orders are "ASC" and "DESC". Ref:
* http://schemas.opengis.net/filter/1.1.0/sort.xsd <wfs:Query typeName="QName QName">
* <wfs:PropertyName>QName</wfs:PropertyName> <ogc:Filter> <ogc:Equals> <ogc:PropertyName/>
* <gml:Point>... </gml:Point> </ogc:Equals> </ogc:Filter> <ogc:SortBy> <ogc:SortProperty>
* <ogc:PropertyName>property</ogc:PropertyName> <ogc:SortOrder>ASC</ogc:SortOrder>
* </ogc:SortProperty> </ogc:SortBy> </wfs:Query>
*/
@Test
public void testSortingSortOrderAscending() throws Exception {
// Setup
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
setupMapper(MOCK_TEMPORAL_SORT_PROPERTY, MOCK_RELEVANCE_SORT_PROPERTY, MOCK_DISTANCE_SORT_PROPERTY);
source.setMetacardMappers(metacardMappers);
propertyIsLikeQuery.setSortBy(new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING));
final ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
for (final ExtendedGetFeatureType getFeatureType : captor.getAllValues()) {
assertFeature(getFeatureType, true, MOCK_TEMPORAL_SORT_PROPERTY, "ASC");
}
}
use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.
the class WfsSourceTest method testNullSortProperty.
@Test
public void testNullSortProperty() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
setupMapper(MOCK_TEMPORAL_SORT_PROPERTY, MOCK_RELEVANCE_SORT_PROPERTY, MOCK_DISTANCE_SORT_PROPERTY);
source.setMetacardMappers(metacardMappers);
propertyIsLikeQuery.setSortBy(new SortByImpl(new PropertyNameImpl(null), null));
source.query(new QueryRequestImpl(propertyIsLikeQuery));
}
use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.
the class CswSourceTest method testQueryWithSortByDistance.
@Test
public void testQueryWithSortByDistance() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
// Setup
final String searchPhrase = "*";
final int pageSize = 1;
final int numRecordsReturned = 1;
final long numRecordsMatched = 1;
setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
try {
configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
} catch (CswException e) {
fail("Could not configure Mock Remote CSW: " + e.getMessage());
}
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(Result.DISTANCE, SortOrder.DESCENDING);
query.setSortBy(sortBy);
AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
cswSource.setCswUrl(URL);
cswSource.setId(ID);
// Perform test
SourceResponse response = cswSource.query(getQueryRequestWithSubject(query));
// Verify
Assert.assertNotNull(response);
assertThat(response.getResults().size(), is(numRecordsReturned));
assertThat(response.getHits(), is(numRecordsMatched));
ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
try {
verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
} catch (CswException e) {
fail("Could not verify mock CSW record count: " + e.getMessage());
}
GetRecordsType getRecordsType = captor.getValue();
QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
assertThat(cswQuery.getSortBy(), nullValue());
}
Aggregations