Search in sources :

Example 11 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor 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(), anyObject());
    ExpressionVisitor expVisitor = spy(new DefaultExpressionVisitor() {
    });
    expressionArgument.getValue().getExpression1().accept(expVisitor, null);
    ArgumentCaptor<PropertyName> propertyNameArgument = ArgumentCaptor.forClass(PropertyName.class);
    verify(expVisitor).visit(propertyNameArgument.capture(), anyObject());
    assertEquals(FOO_ATTRIBUTE, propertyNameArgument.getValue().getPropertyName());
    expressionArgument.getValue().getExpression2().accept(expVisitor, null);
    ArgumentCaptor<Literal> literalArgument = ArgumentCaptor.forClass(Literal.class);
    verify(expVisitor).visit(literalArgument.capture(), anyObject());
    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)

Example 12 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method likeXPathInvalid.

@Test(expected = IllegalArgumentException.class)
public void likeXPathInvalid() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.xpath("foo").is().like().text("bar");
}
Also used : DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) 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) Test(org.junit.Test)

Example 13 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method beyond.

@Test
public void beyond() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.attribute(Metacard.GEOGRAPHY).beyond().wkt(POINT_WKT, 123.45d);
    filter.accept(visitor, null);
    filter = builder.attribute(Metacard.GEOGRAPHY).beyond().wkt(POINT_WKT);
    filter.accept(visitor, null);
    InOrder inOrder = inOrder(visitor);
    inOrder.verify(visitor, times(2)).visit(isA(Beyond.class), anyObject());
// TODO check arguments
}
Also used : InOrder(org.mockito.InOrder) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) 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) Beyond(org.opengis.filter.spatial.Beyond) Test(org.junit.Test)

Example 14 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method notNull.

@Test
public void notNull() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.not(builder.attribute(FOO_ATTRIBUTE).is().empty());
    filter.accept(visitor, null);
    InOrder inOrder = inOrder(visitor);
    inOrder.verify(visitor, times(1)).visit(isA(Not.class), anyObject());
    inOrder.verify(visitor).visit(isA(PropertyIsNull.class), anyObject());
}
Also used : Not(org.opengis.filter.Not) InOrder(org.mockito.InOrder) PropertyIsNull(org.opengis.filter.PropertyIsNull) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) 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) Test(org.junit.Test)

Example 15 with DefaultFilterVisitor

use of org.geotools.filter.visitor.DefaultFilterVisitor in project ddf by codice.

the class FilterBuilderTest method likeFuzzy.

@Test
public void likeFuzzy() {
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.attribute(FOO_ATTRIBUTE).is().like().fuzzyText("bar");
    filter.accept(visitor, null);
    InOrder inOrder = inOrder(visitor);
    inOrder.verify(visitor, times(1)).visit(isA(PropertyIsLike.class), anyObject());
// TODO check for fuzzy
}
Also used : PropertyIsLike(org.opengis.filter.PropertyIsLike) InOrder(org.mockito.InOrder) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) 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) Test(org.junit.Test)

Aggregations

FilterBuilder (ddf.catalog.filter.FilterBuilder)24 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)24 DefaultFilterVisitor (org.geotools.filter.visitor.DefaultFilterVisitor)24 Test (org.junit.Test)24 Filter (org.opengis.filter.Filter)24 FilterVisitor (org.opengis.filter.FilterVisitor)23 InOrder (org.mockito.InOrder)21 Date (java.util.Date)6 PropertyIsLike (org.opengis.filter.PropertyIsLike)6 PropertyIsNull (org.opengis.filter.PropertyIsNull)4 DWithin (org.opengis.filter.spatial.DWithin)3 DefaultExpressionVisitor (org.geotools.filter.visitor.DefaultExpressionVisitor)2 And (org.opengis.filter.And)2 Or (org.opengis.filter.Or)2 PropertyIsEqualTo (org.opengis.filter.PropertyIsEqualTo)2 ExpressionVisitor (org.opengis.filter.expression.ExpressionVisitor)2 Literal (org.opengis.filter.expression.Literal)2 PropertyName (org.opengis.filter.expression.PropertyName)2 Within (org.opengis.filter.spatial.Within)2 After (org.opengis.filter.temporal.After)2