package mil.nga.giat.geowave.adapter.vector.plugin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.text.ParseException; import java.util.UUID; import org.geotools.data.DataStore; import org.geotools.data.DataUtilities; import org.geotools.data.DefaultTransaction; import org.geotools.data.FeatureReader; import org.geotools.data.FeatureWriter; import org.geotools.data.Query; import org.geotools.data.Transaction; import org.geotools.feature.SchemaException; import org.geotools.filter.text.cql2.CQL; import org.geotools.filter.text.cql2.CQLException; import org.junit.Before; import org.junit.Test; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.PrecisionModel; import mil.nga.giat.geowave.adapter.vector.BaseDataStoreTest; import mil.nga.giat.geowave.adapter.vector.utils.DateUtilities; public class WFSSpatialTest extends BaseDataStoreTest { DataStore dataStore; SimpleFeatureType schema; SimpleFeatureType type; final GeometryFactory factory = new GeometryFactory( new PrecisionModel( PrecisionModel.FIXED)); Query query = null; @Before public void setup() throws SchemaException, CQLException, IOException, GeoWavePluginException { dataStore = createDataStore(); type = DataUtilities.createType( "geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,pid:String"); dataStore.createSchema(type); query = new Query( "geostuff", CQL .toFilter("BBOX(geometry,27.20,41.30,27.30,41.20) and when during 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z"), new String[] { "geometry", "pid" }); } @Test public void test() throws IOException, CQLException, ParseException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter( type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute( "pop", Long.valueOf(100)); newFeature.setAttribute( "pid", UUID.randomUUID().toString()); newFeature.setAttribute( "when", DateUtilities.parseISO("2005-05-19T18:33:55Z")); newFeature.setAttribute( "geometry", factory.createPoint(new Coordinate( 27.25, 41.25))); newFeature = writer.next(); newFeature.setAttribute( "pop", Long.valueOf(100)); newFeature.setAttribute( "pid", UUID.randomUUID().toString()); newFeature.setAttribute( "when", DateUtilities.parseISO("2005-05-19T20:33:55Z")); newFeature.setAttribute( "geometry", factory.createPoint(new Coordinate( 27.25, 41.25))); writer.write(); writer.close(); final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader( query, transaction1); assertTrue(reader.hasNext()); final SimpleFeature priorFeature = reader.next(); assertEquals( newFeature.getAttribute("pid"), priorFeature.getAttribute("pid")); assertFalse(reader.hasNext()); reader.close(); transaction1.commit(); transaction1.close(); } }