use of org.opengis.filter.And in project ddf by codice.
the class CatalogFeatureQueryableTest method testQuery.
@Test
public void testQuery() throws UnsupportedQueryException, SourceUnavailableException, FederationException, FeatureQueryException {
final ArgumentCaptor<QueryRequest> requestArgument = ArgumentCaptor.forClass(QueryRequest.class);
QueryResponse queryResponse = getMockQueryResponse();
when(catalogFramework.query(any())).thenReturn(queryResponse);
List<SimpleFeature> results = catalogFeatureQueryable.query(COUNTRY_CODE, "PCL1", 1);
verify(catalogFramework, atLeastOnce()).query(requestArgument.capture());
SimpleFeature result = results.get(0);
Geometry geometry = (Geometry) result.getDefaultGeometry();
assertThat(geometry.getNumPoints(), is(WKT_NUM_POINTS));
assertThat(geometry.getGeometryType(), is(WKT_TYPE));
QueryImpl query = (QueryImpl) requestArgument.getValue().getQuery();
Filter filter = query.getFilter();
And and = (And) filter;
List<Filter> filters = and.getChildren();
assertThat(filters, hasSize(3));
List<String> attributes = new ArrayList<>();
List<String> values = new ArrayList<>();
for (Filter compFilter : filters) {
String attribute;
String value;
if (compFilter instanceof IsEqualsToImpl) {
IsEqualsToImpl equals = (IsEqualsToImpl) compFilter;
AttributeExpressionImpl attributeExpression = (AttributeExpressionImpl) equals.getExpression1();
attribute = attributeExpression.getPropertyName();
LiteralExpressionImpl literalExpression = (LiteralExpressionImpl) equals.getExpression2();
value = (String) literalExpression.getValue();
} else {
LikeFilterImpl likeFilter = (LikeFilterImpl) compFilter;
AttributeExpressionImpl literalExpression = (AttributeExpressionImpl) likeFilter.getExpression();
attribute = literalExpression.getPropertyName();
value = likeFilter.getLiteral();
}
attributes.add(attribute);
values.add(value);
}
assertThat(attributes, hasSize(3));
assertThat(attributes, hasItems(Location.COUNTRY_CODE, Core.METACARD_TAGS, Core.METACARD_TAGS));
assertThat(values, hasSize(3));
assertThat(values, hasItems(COUNTRY_CODE, GAZETTEER_METACARD_TAG, GeoCodingConstants.COUNTRY_TAG));
}
use of org.opengis.filter.And in project ddf by codice.
the class TestWorkspaceServiceImpl method testGetWorkspaceMetacardsByWorkspaceIdWithException.
@SuppressWarnings("unchecked")
@Test
public void testGetWorkspaceMetacardsByWorkspaceIdWithException() throws UnsupportedQueryException, SourceUnavailableException, FederationException {
String id = "123";
when(catalogFramework.query(any())).thenThrow(UnsupportedQueryException.class);
Filter workspaceTagFilter = mockWorkspaceTagFilter();
Filter metacardIdFilter = mock(Filter.class);
when(filterService.buildMetacardIdFilter(id)).thenReturn(metacardIdFilter);
And andFilter = mock(And.class);
when(filterBuilder.allOf(metacardIdFilter, workspaceTagFilter)).thenReturn(andFilter);
Or orFilter = mock(Or.class);
when(filterBuilder.anyOf(Collections.singletonList(andFilter))).thenReturn(orFilter);
List<WorkspaceMetacardImpl> workspaceMetacards = workspaceService.getWorkspaceMetacards(Collections.singleton(id));
assertThat(workspaceMetacards, hasSize(0));
}
use of org.opengis.filter.And in project ddf by codice.
the class OpenSearchFilterVisitorTest method testAndFilter.
@Test
public void testAndFilter() {
Filter textLikeFilter = geotoolsFilterBuilder.attribute(SOME_ATTRIBUTE_NAME).is().like().text(TEST_STRING);
And andFilter = geotoolsFilterBuilder.allOf(textLikeFilter, textLikeFilter);
OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(andFilter, openSearchFilterVisitorObject);
assertThat(openSearchFilterVisitorObject, is(result));
}
use of org.opengis.filter.And in project ddf by codice.
the class OpenSearchFilterVisitorTest method testMultipleFilters.
/**
* Test that the {@link OpenSearchFilterVisitorObject} is populated with multiple filters.
* Combines the {@link Filter}s from {@link #testDuringDates} and {@link #testContains()}.
*/
@Test
public void testMultipleFilters() {
During duringFilter = (During) geotoolsFilterBuilder.attribute(TEMPORAL_ATTRIBUTE_NAME).during().dates(START_DATE, END_DATE);
Contains containsFilter = (Contains) geotoolsFilterBuilder.attribute(SPATIAL_ATTRIBUTE_NAME).containing().wkt(WKT_POLYGON);
And andFilter = geotoolsFilterBuilder.allOf(duringFilter, containsFilter);
OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
openSearchFilterVisitorObject.setCurrentNest(NestedTypes.AND);
OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(andFilter, openSearchFilterVisitorObject);
assertThat(result.getTemporalSearch(), allOf(is(notNullValue()), hasProperty("startDate", is(START_DATE)), hasProperty("endDate", is(END_DATE))));
assertThat(result.getGeometrySearches(), contains(hasToString(is(WKT_POLYGON))));
}
Aggregations