Search in sources :

Example 1 with ExpressionVisitor

use of org.opengis.filter.expression.ExpressionVisitor in project ddf by codice.

the class FilterBuilderTest method andOrNull.

@Test
public void andOrNull() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    // FilterBuilder builder = new GeotoolsFilterBuilder();
    // 
    // 
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.allOf(builder.anyOf(builder.attribute(FOO_ATTRIBUTE).is().empty()));
    filter.accept(visitor, null);
    InOrder inOrder = inOrder(visitor);
    inOrder.verify(visitor, times(1)).visit(isA(And.class), any());
    inOrder.verify(visitor).visit(isA(Or.class), any());
    ArgumentCaptor<PropertyIsNull> propertyIsNullArgument = ArgumentCaptor.forClass(PropertyIsNull.class);
    verify(visitor).visit(propertyIsNullArgument.capture(), any());
    ExpressionVisitor expVisitor = spy(new DefaultExpressionVisitor() {
    });
    propertyIsNullArgument.getValue().getExpression().accept(expVisitor, null);
    ArgumentCaptor<PropertyName> propertyNameArgument = ArgumentCaptor.forClass(PropertyName.class);
    verify(expVisitor).visit(propertyNameArgument.capture(), any());
    assertEquals(FOO_ATTRIBUTE, propertyNameArgument.getValue().getPropertyName());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) InOrder(org.mockito.InOrder) Or(org.opengis.filter.Or) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) DefaultExpressionVisitor(org.geotools.filter.visitor.DefaultExpressionVisitor) ExpressionVisitor(org.opengis.filter.expression.ExpressionVisitor) PropertyIsNull(org.opengis.filter.PropertyIsNull) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) FilterVisitor(org.opengis.filter.FilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) And(org.opengis.filter.And) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) DefaultExpressionVisitor(org.geotools.filter.visitor.DefaultExpressionVisitor) Test(org.junit.Test)

Example 2 with ExpressionVisitor

use of org.opengis.filter.expression.ExpressionVisitor in project ddf by codice.

the class FilterBuilderTest method afterDate.

@Test
public void afterDate() {
    final Date date = new Date();
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.attribute(FOO_ATTRIBUTE).is().after().date(date);
    filter.accept(visitor, null);
    ArgumentCaptor<After> expressionArgument = ArgumentCaptor.forClass(After.class);
    verify(visitor).visit(expressionArgument.capture(), any());
    ExpressionVisitor expVisitor = spy(new DefaultExpressionVisitor() {
    });
    expressionArgument.getValue().getExpression1().accept(expVisitor, null);
    ArgumentCaptor<PropertyName> propertyNameArgument = ArgumentCaptor.forClass(PropertyName.class);
    verify(expVisitor).visit(propertyNameArgument.capture(), any());
    assertEquals(FOO_ATTRIBUTE, propertyNameArgument.getValue().getPropertyName());
    expressionArgument.getValue().getExpression2().accept(expVisitor, null);
    ArgumentCaptor<Literal> literalArgument = ArgumentCaptor.forClass(Literal.class);
    verify(expVisitor).visit(literalArgument.capture(), any());
    assertEquals(date, ((Instant) literalArgument.getValue().getValue()).getPosition().getDate());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) Instant(org.opengis.temporal.Instant) DefaultExpressionVisitor(org.geotools.filter.visitor.DefaultExpressionVisitor) ExpressionVisitor(org.opengis.filter.expression.ExpressionVisitor) Date(java.util.Date) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) FilterVisitor(org.opengis.filter.FilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Literal(org.opengis.filter.expression.Literal) After(org.opengis.filter.temporal.After) DefaultExpressionVisitor(org.geotools.filter.visitor.DefaultExpressionVisitor) Test(org.junit.Test)

Aggregations

FilterBuilder (ddf.catalog.filter.FilterBuilder)2 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)2 DefaultExpressionVisitor (org.geotools.filter.visitor.DefaultExpressionVisitor)2 DefaultFilterVisitor (org.geotools.filter.visitor.DefaultFilterVisitor)2 Test (org.junit.Test)2 Filter (org.opengis.filter.Filter)2 FilterVisitor (org.opengis.filter.FilterVisitor)2 ExpressionVisitor (org.opengis.filter.expression.ExpressionVisitor)2 PropertyName (org.opengis.filter.expression.PropertyName)2 Date (java.util.Date)1 InOrder (org.mockito.InOrder)1 And (org.opengis.filter.And)1 Or (org.opengis.filter.Or)1 PropertyIsNull (org.opengis.filter.PropertyIsNull)1 Literal (org.opengis.filter.expression.Literal)1 After (org.opengis.filter.temporal.After)1 Instant (org.opengis.temporal.Instant)1