Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1565 from newmanw/mongodb-min-max-visitor
[GEOT-5716] MongoFeatureSource to handle Min/Max Visitor
- Loading branch information
Showing
8 changed files
with
210 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...ported/mongodb/src/test/java/org/geotools/data/mongodb/MongoFeatureSourceVisitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* GeoTools - The Open Source Java GIS Toolkit | ||
* http://geotools.org | ||
* | ||
* (C) 2015, Open Source Geospatial Foundation (OSGeo) | ||
* (C) 2014-2015, Boundless | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; | ||
* version 2.1 of the License. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
*/ | ||
package org.geotools.data.mongodb; | ||
|
||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Date; | ||
|
||
import org.geotools.data.Query; | ||
import org.geotools.data.mongodb.geojson.GeoJSONMongoTestSetup; | ||
import org.geotools.feature.visitor.MaxVisitor; | ||
import org.geotools.feature.visitor.MinVisitor; | ||
import org.geotools.filter.IllegalFilterException; | ||
import org.junit.Test; | ||
import org.opengis.feature.Feature; | ||
import org.opengis.feature.simple.SimpleFeature; | ||
import org.opengis.filter.FilterFactory; | ||
import org.opengis.filter.expression.Expression; | ||
import org.opengis.filter.expression.PropertyName; | ||
|
||
public class MongoFeatureSourceVisitorTest extends MongoTestSupport { | ||
|
||
public MongoFeatureSourceVisitorTest() { | ||
super(new GeoJSONMongoTestSetup()); | ||
} | ||
|
||
boolean visited = false; | ||
boolean valueSet = false; | ||
|
||
class TestMinVisitor extends MinVisitor { | ||
|
||
public TestMinVisitor(Expression expr) throws IllegalFilterException { | ||
super(expr); | ||
} | ||
|
||
public void visit(Feature feature) { | ||
super.visit(feature); | ||
visited = true; | ||
} | ||
public void visit(SimpleFeature feature) { | ||
super.visit(feature); | ||
visited = true; | ||
} | ||
|
||
public void setValue(Object result) { | ||
super.setValue(result); | ||
valueSet = true; | ||
} | ||
} | ||
|
||
@Override | ||
protected void setUpInternal() throws Exception { | ||
super.setUpInternal(); | ||
visited = false; | ||
valueSet = false; | ||
} | ||
|
||
@Test | ||
public void testMinVisitor() throws Exception { | ||
FilterFactory ff = dataStore.getFilterFactory(); | ||
PropertyName p = ff.property("properties.dateProperty"); | ||
|
||
MinVisitor v = new TestMinVisitor(p); | ||
|
||
dataStore.getFeatureSource("ft1").accepts(Query.ALL, v, null); | ||
|
||
Date minDate = Date.from(Instant.from(DateTimeFormatter.ISO_DATE_TIME.parse("2015-01-01T00:00:00Z"))); | ||
assertEquals(minDate, v.getResult().getValue()); | ||
|
||
assertFalse(visited); | ||
assertTrue(valueSet); | ||
} | ||
|
||
class TestMaxVisitor extends MaxVisitor { | ||
|
||
public TestMaxVisitor(Expression expr) throws IllegalFilterException { | ||
super(expr); | ||
} | ||
|
||
public void visit(Feature feature) { | ||
super.visit(feature); | ||
visited = true; | ||
} | ||
public void visit(SimpleFeature feature) { | ||
super.visit(feature); | ||
visited = true; | ||
} | ||
|
||
public void setValue(Object result) { | ||
super.setValue(result); | ||
valueSet = true; | ||
} | ||
} | ||
|
||
@Test | ||
public void testMaxVisitor() throws Exception { | ||
FilterFactory ff = dataStore.getFilterFactory(); | ||
PropertyName p = ff.property("properties.dateProperty"); | ||
|
||
MaxVisitor v = new TestMaxVisitor(p); | ||
|
||
dataStore.getFeatureSource("ft1").accepts(Query.ALL, v, null); | ||
|
||
Date minDate = Date.from(Instant.from(DateTimeFormatter.ISO_DATE_TIME.parse("2015-01-01T21:30:00Z"))); | ||
assertEquals(minDate, v.getResult().getValue()); | ||
|
||
assertFalse(visited); | ||
assertTrue(valueSet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters