http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e76b8d7/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/accumulo/geo/GeoWaveIndexerTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/accumulo/geo/GeoWaveIndexerTest.java b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/accumulo/geo/GeoWaveIndexerTest.java deleted file mode 100644 index 7c4fa47..0000000 --- a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/accumulo/geo/GeoWaveIndexerTest.java +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rya.indexing.accumulo.geo; - -import static org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement; -import static org.apache.rya.indexing.GeoIndexingTestUtils.getSet; - -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.Set; - -import org.apache.accumulo.core.client.AccumuloException; -import org.apache.accumulo.core.client.AccumuloSecurityException; -import org.apache.accumulo.core.client.admin.TableOperations; -import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl; -import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl; -import org.apache.commons.io.FileUtils; -import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.indexing.GeoConstants; -import org.apache.rya.indexing.GeoIndexerType; -import org.apache.rya.indexing.OptionalConfigUtils; -import org.apache.rya.indexing.StatementConstraints; -import org.apache.rya.indexing.accumulo.ConfigUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ContextStatementImpl; -import org.openrdf.model.impl.StatementImpl; -import org.openrdf.model.impl.ValueFactoryImpl; - -import com.google.common.collect.Sets; -import com.google.common.io.Files; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.LinearRing; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; -import com.vividsolutions.jts.geom.PrecisionModel; -import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence; - -import mil.nga.giat.geowave.datastore.accumulo.minicluster.MiniAccumuloClusterFactory; - -/** - * Tests higher level functioning of the geoindexer parse WKT, predicate list, - * prime and anti meridian, delete, search, context, search with Statement Constraints. - */ -public class GeoWaveIndexerTest { - - private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints(); - - private AccumuloRdfConfiguration conf; - private final GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326); - - private static File tempAccumuloDir; - private static MiniAccumuloClusterImpl accumulo; - - private static final boolean IS_MOCK = true; - - private static final String ACCUMULO_USER = IS_MOCK ? "username" : "root"; - private static final String ACCUMULO_PASSWORD = "password"; - - @BeforeClass - public static void setup() throws AccumuloException, AccumuloSecurityException, IOException, InterruptedException { - if (!IS_MOCK) { - tempAccumuloDir = Files.createTempDir(); - - accumulo = MiniAccumuloClusterFactory.newAccumuloCluster( - new MiniAccumuloConfigImpl(tempAccumuloDir, ACCUMULO_PASSWORD), - GeoWaveIndexerTest.class); - - accumulo.start(); - } - } - - @AfterClass - public static void cleanup() throws IOException, InterruptedException { - if (!IS_MOCK) { - try { - accumulo.stop(); - } finally { - FileUtils.deleteDirectory(tempAccumuloDir); - } - } - } - - @Before - public void before() throws Exception { - conf = new AccumuloRdfConfiguration(); - conf.setTablePrefix("triplestore_"); - final String tableName = GeoWaveGeoIndexer.getTableName(conf); - conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, IS_MOCK); - conf.set(ConfigUtils.CLOUDBASE_USER, ACCUMULO_USER); - conf.set(ConfigUtils.CLOUDBASE_PASSWORD, ACCUMULO_PASSWORD); - conf.set(ConfigUtils.CLOUDBASE_INSTANCE, IS_MOCK ? "INSTANCE" : accumulo.getInstanceName()); - conf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, IS_MOCK ? "localhost" : accumulo.getZooKeepers()); - conf.set(ConfigUtils.CLOUDBASE_AUTHS, "U"); - conf.set(OptionalConfigUtils.USE_GEO, "true"); - conf.set(OptionalConfigUtils.GEO_INDEXER_TYPE, GeoIndexerType.GEO_WAVE.toString()); - - final TableOperations tops = ConfigUtils.getConnector(conf).tableOperations(); - // get all of the table names with the prefix - final Set<String> toDel = Sets.newHashSet(); - for (final String t : tops.list()){ - if (t.startsWith(tableName)){ - toDel.add(t); - } - } - for (final String t : toDel) { - tops.delete(t); - } - } - - @Test - public void testRestrictPredicatesSearch() throws Exception { - conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2"); - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - - final Point point = gf.createPoint(new Coordinate(10, 10)); - final Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT); - final URI invalidPredicate = GeoConstants.GEO_AS_WKT; - - // These should not be stored because they are not in the predicate list - f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), invalidPredicate, pointValue))); - f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), invalidPredicate, pointValue))); - - final URI pred1 = vf.createURI("pred:1"); - final URI pred2 = vf.createURI("pred:2"); - - // These should be stored because they are in the predicate list - final Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1, pointValue); - final Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), pred2, pointValue); - f.storeStatement(convertStatement(s3)); - f.storeStatement(convertStatement(s4)); - - // This should not be stored because the object is not valid wkt - f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)")))); - - // This should not be stored because the object is not a literal - f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj6"), pred1, vf.createURI("p:Point(10 10)")))); - - f.flush(); - - final Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS)); - Assert.assertEquals(2, actual.size()); - Assert.assertTrue(actual.contains(s3)); - Assert.assertTrue(actual.contains(s4)); - } - } - - @Test - public void testPrimeMeridianSearch() throws Exception { - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - final Resource subject = vf.createURI("foo:subj"); - final URI predicate = GeoConstants.GEO_AS_WKT; - final Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Resource context = vf.createURI("foo:context"); - - final Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - final double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 }; - final double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 }; - final double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 }; - - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2)); - final LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2)); - final LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2)); - - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - final Polygon p2 = gf.createPolygon(r2, new LinearRing[] {}); - final Polygon p3 = gf.createPolygon(r3, new LinearRing[] {}); - - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS))); - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS))); - - // Test a ring with a hole in it - final Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 }); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS))); - - // test a ring outside the point - final double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 }; - final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2)); - final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); - } - } - - @Test - public void testDcSearch() throws Exception { - // test a ring around dc - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - final Resource subject = vf.createURI("foo:subj"); - final URI predicate = GeoConstants.GEO_AS_WKT; - final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Resource context = vf.createURI("foo:context"); - - final Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - - // test a ring outside the point - final double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 }; - final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2)); - final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); - } - } - - @Test - public void testDeleteSearch() throws Exception { - // test a ring around dc - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - final Resource subject = vf.createURI("foo:subj"); - final URI predicate = GeoConstants.GEO_AS_WKT; - final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Resource context = vf.createURI("foo:context"); - - final Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - f.deleteStatement(convertStatement(statement)); - - // test a ring that the point would be inside of if not deleted - final double[] in = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(in, 2)); - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - - // test a ring that the point would be outside of if not deleted - final double[] out = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 }; - final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(out, 2)); - final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); - - // test a ring for the whole world and make sure the point is gone - final double[] world = { -180, 90, 180, 90, 180, -90, -180, -90, -180, 90 }; - final LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2)); - final Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS))); - } - } - - @Test - public void testDcSearchWithContext() throws Exception { - // test a ring around dc - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - final Resource subject = vf.createURI("foo:subj"); - final URI predicate = GeoConstants.GEO_AS_WKT; - final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Resource context = vf.createURI("foo:context"); - - final Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - - // query with correct context - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context)))); - - // query with wrong context - Assert.assertEquals(Sets.newHashSet(), - getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2"))))); - } - } - - @Test - public void testDcSearchWithSubject() throws Exception { - // test a ring around dc - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - final Resource subject = vf.createURI("foo:subj"); - final URI predicate = GeoConstants.GEO_AS_WKT; - final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Resource context = vf.createURI("foo:context"); - - final Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - - // query with correct subject - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject)))); - - // query with wrong subject - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2"))))); - } - } - - @Test - public void testDcSearchWithSubjectAndContext() throws Exception { - // test a ring around dc - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - final Resource subject = vf.createURI("foo:subj"); - final URI predicate = GeoConstants.GEO_AS_WKT; - final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Resource context = vf.createURI("foo:context"); - - final Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - - // query with correct context subject - Assert.assertEquals(Sets.newHashSet(statement), - getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject)))); - - // query with wrong context - Assert.assertEquals(Sets.newHashSet(), - getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2"))))); - - // query with wrong subject - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2"))))); - } - } - - @Test - public void testDcSearchWithPredicate() throws Exception { - // test a ring around dc - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - final Resource subject = vf.createURI("foo:subj"); - final URI predicate = GeoConstants.GEO_AS_WKT; - final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Resource context = vf.createURI("foo:context"); - - final Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - - // query with correct Predicate - Assert.assertEquals(Sets.newHashSet(statement), - getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate))))); - - // query with wrong predicate - Assert.assertEquals(Sets.newHashSet(), - getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred")))))); - } - } - - // @Test - public void testAntiMeridianSearch() throws Exception { - // verify that a search works if the bounding box crosses the anti meridian - try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) { - f.setConf(conf); - f.purge(conf); - - final ValueFactory vf = new ValueFactoryImpl(); - final Resource context = vf.createURI("foo:context"); - - final Resource subjectEast = vf.createURI("foo:subj:east"); - final URI predicateEast = GeoConstants.GEO_AS_WKT; - final Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Statement statementEast = new ContextStatementImpl(subjectEast, predicateEast, objectEast, context); - f.storeStatement(convertStatement(statementEast)); - - final Resource subjectWest = vf.createURI("foo:subj:west"); - final URI predicateWest = GeoConstants.GEO_AS_WKT; - final Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Statement statementWest = new ContextStatementImpl(subjectWest, predicateWest, objectWest, context); - f.storeStatement(convertStatement(statementWest)); - - f.flush(); - - final double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 }; - - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2)); - - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - - Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e76b8d7/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/GeoTemporalProviderTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/GeoTemporalProviderTest.java b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/GeoTemporalProviderTest.java deleted file mode 100644 index 7151b56..0000000 --- a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/GeoTemporalProviderTest.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rya.indexing.geotemporal; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; - -import java.util.List; - -import org.apache.rya.indexing.GeoConstants; -import org.apache.rya.indexing.TemporalInstantRfc3339; -import org.apache.rya.indexing.external.matching.QuerySegment; -import org.apache.rya.indexing.geotemporal.GeoTemporalIndexSetProvider; -import org.apache.rya.indexing.geotemporal.model.EventQueryNode; -import org.apache.rya.indexing.geotemporal.storage.EventStorage; -import org.junit.Before; -import org.junit.Test; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; - -public class GeoTemporalProviderTest extends GeoTemporalTestBase { - private static final String URI_PROPERTY_AT_TIME = "Property:atTime"; - private GeoTemporalIndexSetProvider provider; - private EventStorage events; - @Before - public void setup() { - events = mock(EventStorage.class); - provider = new GeoTemporalIndexSetProvider(events); - } - - /* - * Simplest Happy Path test - */ - @Test - public void twoPatternsTwoFilters_test() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); - final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME); - final String query = - "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + - "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + - "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" + - "SELECT * WHERE { " + - "?subj <" + tempPred + "> ?time ."+ - "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " + - " FILTER(geos:sfContains(?loc, " + geo + ")) . " + - " FILTER(time:equals(?time, " + temp + ")) . " + - "}"; - final QuerySegment<EventQueryNode> node = getQueryNode(query); - final List<EventQueryNode> nodes = provider.getExternalSets(node); - assertEquals(1, nodes.size()); - } - - @Test - public void onePatternTwoFilters_test() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); - final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME); - final String query = - "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + - "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + - "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" + - "SELECT * WHERE { " + - "?subj <" + tempPred + "> ?time ."+ - " FILTER(geos:sfContains(?loc, " + geo + ")) . " + - " FILTER(time:equals(?time, " + temp + ")) . " + - "}"; - final QuerySegment<EventQueryNode> node = getQueryNode(query); - final List<EventQueryNode> nodes = provider.getExternalSets(node); - assertEquals(0, nodes.size()); - } - - @Test - public void twoPatternsOneFilter_test() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); - final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME); - final String query = - "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + - "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + - "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" + - "SELECT * WHERE { " + - "?subj <" + tempPred + "> ?time ."+ - "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " + - " FILTER(geos:sfContains(?loc, " + geo + ")) . " + - "}"; - final QuerySegment<EventQueryNode> node = getQueryNode(query); - final List<EventQueryNode> nodes = provider.getExternalSets(node); - assertEquals(0, nodes.size()); - } - - @Test - public void twoPatternsNoFilter_test() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); - final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME); - final String query = - "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + - "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + - "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" + - "SELECT * WHERE { " + - "?subj <" + tempPred + "> ?time ."+ - "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " + - "}"; - final QuerySegment<EventQueryNode> node = getQueryNode(query); - final List<EventQueryNode> nodes = provider.getExternalSets(node); - assertEquals(0, nodes.size()); - } - - @Test - public void twoPatternsTwoFiltersNotValid_test() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); - final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME); - //Only handles geo and temporal filters - final String query = - "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + - "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + - "PREFIX text: <http://rdf.useekm.com/fts#text>" + - "SELECT * WHERE { " + - "?subj <" + tempPred + "> ?time ."+ - "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " + - " FILTER(geos:sfContains(?loc, " + geo + ")) . " + - " FILTER(text:equals(?time, " + temp + ")) . " + - "}"; - final QuerySegment<EventQueryNode> node = getQueryNode(query); - final List<EventQueryNode> nodes = provider.getExternalSets(node); - assertEquals(0, nodes.size()); - } - - @Test - public void twoSubjOneFilter_test() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); - final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME); - final String query = - "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + - "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + - "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" + - "SELECT * WHERE { " + - "?subj <" + tempPred + "> ?time ."+ - "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " + - "?subj2 <" + tempPred + "> ?time2 ."+ - "?subj2 <" + GeoConstants.GEO_AS_WKT + "> ?loc2 . " + - " FILTER(geos:sfContains(?loc, " + geo + ")) . " + - " FILTER(time:equals(?time, " + temp + ")) . " + - "}"; - final QuerySegment<EventQueryNode> node = getQueryNode(query); - final List<EventQueryNode> nodes = provider.getExternalSets(node); - assertEquals(1, nodes.size()); - } - - @Test - public void twoNode_test() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); - final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME); - final String query = - "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + - "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + - "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" + - "SELECT * WHERE { " + - "?subj <" + tempPred + "> ?time ."+ - "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " + - "?subj2 <" + tempPred + "> ?time2 ."+ - "?subj2 <" + GeoConstants.GEO_AS_WKT + "> ?loc2 . " + - " FILTER(geos:sfContains(?loc, " + geo + ")) . " + - " FILTER(time:equals(?time, " + temp + ")) . " + - " FILTER(geos:sfContains(?loc2, " + geo + ")) . " + - " FILTER(time:equals(?time2, " + temp + ")) . " + - "}"; - final QuerySegment<EventQueryNode> node = getQueryNode(query); - final List<EventQueryNode> nodes = provider.getExternalSets(node); - assertEquals(2, nodes.size()); - } - - @Test - public void twoSubjectMultiFilter_test() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); - final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - final URI tempPred = vf.createURI(URI_PROPERTY_AT_TIME); - final String query = - "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + - "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" + - "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" + - "SELECT * WHERE { " + - "?subj <" + tempPred + "> ?time ."+ - "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " + - " FILTER(geos:sfContains(?loc, " + geo + ")) . " + - " FILTER(time:equals(?time, " + temp + ")) . " + - " FILTER(geos:sfWithin(?loc, " + geo + ")) . " + - " FILTER(time:before(?time, " + temp + ")) . " + - "}"; - final QuerySegment<EventQueryNode> node = getQueryNode(query); - final List<EventQueryNode> nodes = provider.getExternalSets(node); - assertEquals(1, nodes.size()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e76b8d7/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/GeoTemporalTestBase.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/GeoTemporalTestBase.java b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/GeoTemporalTestBase.java deleted file mode 100644 index 6b6bf15..0000000 --- a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/GeoTemporalTestBase.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rya.indexing.geotemporal; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.rya.indexing.TemporalInstant; -import org.apache.rya.indexing.TemporalInstantRfc3339; -import org.apache.rya.indexing.external.matching.QuerySegment; -import org.apache.rya.indexing.geotemporal.model.EventQueryNode; -import org.junit.ComparisonFailure; -import org.mockito.Mockito; -import org.openrdf.query.algebra.FunctionCall; -import org.openrdf.query.algebra.QueryModelNode; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; -import org.openrdf.query.algebra.helpers.StatementPatternCollector; -import org.openrdf.query.parser.sparql.SPARQLParser; - -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.geom.LinearRing; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; -import com.vividsolutions.jts.geom.PrecisionModel; -import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence; - -public class GeoTemporalTestBase { - private static final GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326); - - /** - * Make an uniform instant with given seconds. - */ - protected static TemporalInstant makeInstant(final int secondsMakeMeUnique) { - return new TemporalInstantRfc3339(2015, 12, 30, 12, 00, secondsMakeMeUnique); - } - - protected static Polygon poly(final double[] arr) { - final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(arr, 2)); - final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - return p1; - } - - protected static Point point(final double x, final double y) { - return gf.createPoint(new Coordinate(x, y)); - } - - protected static LineString line(final double x1, final double y1, final double x2, final double y2) { - return new LineString(new PackedCoordinateSequence.Double(new double[] { x1, y1, x2, y2 }, 2), gf); - } - - protected static double[] bbox(final double x1, final double y1, final double x2, final double y2) { - return new double[] { x1, y1, x1, y2, x2, y2, x2, y1, x1, y1 }; - } - - protected void assertEqualMongo(final Object expected, final Object actual) throws ComparisonFailure { - try { - assertEquals(expected, actual); - } catch(final Throwable e) { - throw new ComparisonFailure(e.getMessage(), expected.toString(), actual.toString()); - } - } - - public List<FunctionCall> getFilters(final String query) throws Exception { - final FunctionCallCollector collector = new FunctionCallCollector(); - new SPARQLParser().parseQuery(query, null).getTupleExpr().visit(collector); - return collector.getTupleExpr(); - } - - public List<StatementPattern> getSps(final String query) throws Exception { - final StatementPatternCollector collector = new StatementPatternCollector(); - new SPARQLParser().parseQuery(query, null).getTupleExpr().visit(collector); - return collector.getStatementPatterns(); - } - - public QuerySegment<EventQueryNode> getQueryNode(final String query) throws Exception { - final List<QueryModelNode> exprs = getNodes(query); - final QuerySegment<EventQueryNode> node = Mockito.mock(QuerySegment.class); - //provider only cares about Ordered nodes. - Mockito.when(node.getOrderedNodes()).thenReturn(exprs); - return node; - } - - private static List<QueryModelNode> getNodes(final String sparql) throws Exception { - final NodeCollector collector = new NodeCollector(); - new SPARQLParser().parseQuery(sparql, null).getTupleExpr().visit(collector); - return collector.getTupleExpr(); - } - - private static class NodeCollector extends QueryModelVisitorBase<RuntimeException> { - private final List<QueryModelNode> stPatterns = new ArrayList<>(); - - public List<QueryModelNode> getTupleExpr() { - return stPatterns; - } - - @Override - public void meet(final FunctionCall node) { - stPatterns.add(node); - } - - @Override - public void meet(final StatementPattern node) { - stPatterns.add(node); - } - } - - private static class FunctionCallCollector extends QueryModelVisitorBase<RuntimeException> { - private final List<FunctionCall> filters = new ArrayList<>(); - - public List<FunctionCall> getTupleExpr() { - return filters; - } - - @Override - public void meet(final FunctionCall node) { - filters.add(node); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e76b8d7/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java deleted file mode 100644 index e0209e8..0000000 --- a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/MongoGeoTemporalIndexIT.java +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rya.indexing.geotemporal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.domain.RyaURI; -import org.apache.rya.indexing.GeoConstants; -import org.apache.rya.indexing.GeoRyaSailFactory; -import org.apache.rya.indexing.OptionalConfigUtils; -import org.apache.rya.indexing.TemporalInstantRfc3339; -import org.apache.rya.indexing.accumulo.ConfigUtils; -import org.apache.rya.indexing.geotemporal.model.Event; -import org.apache.rya.indexing.geotemporal.mongo.MongoGeoTemporalIndexer; -import org.apache.rya.indexing.geotemporal.mongo.MongoITBase; -import org.apache.rya.indexing.geotemporal.storage.EventStorage; -import org.apache.rya.mongodb.MongoDBRdfConfiguration; -import org.junit.Before; -import org.junit.Test; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.TupleQueryResult; -import org.openrdf.query.impl.MapBindingSet; -import org.openrdf.repository.sail.SailRepository; -import org.openrdf.repository.sail.SailRepositoryConnection; -import org.openrdf.sail.Sail; - -import com.mongodb.MongoClient; - -public class MongoGeoTemporalIndexIT extends MongoITBase { - private static final String URI_PROPERTY_AT_TIME = "Property:atTime"; - - private static final ValueFactory VF = ValueFactoryImpl.getInstance(); - private MongoDBRdfConfiguration conf; - private SailRepositoryConnection conn; - private MongoClient mongoClient; - private static final AtomicInteger COUNTER = new AtomicInteger(1); - - @Before - public void setUp() throws Exception{ - mongoClient = super.getMongoClient(); - conf = new MongoDBRdfConfiguration(); - conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, MongoGeoTemporalIndexIT.class.getSimpleName() + "_" + COUNTER.getAndIncrement()); - conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya"); - conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya"); - conf.setBoolean(ConfigUtils.USE_MONGO, true); - conf.setBoolean(OptionalConfigUtils.USE_GEOTEMPORAL, true); - conf.setMongoClient(mongoClient); - - final Sail sail = GeoRyaSailFactory.getInstance(conf); - conn = new SailRepository(sail).getConnection(); - conn.begin(); - - addStatements(); - } - - @Test - public void ensureInEventStore_Test() throws Exception { - final MongoGeoTemporalIndexer indexer = new MongoGeoTemporalIndexer(); - indexer.initIndexer(conf, mongoClient); - - final EventStorage events = indexer.getEventStorage(conf); - final RyaURI subject = new RyaURI("urn:event1"); - final Optional<Event> event = events.get(subject); - assertTrue(event.isPresent()); - } - - @Test - public void constantSubjQuery_Test() throws Exception { - final String query = - "PREFIX time: <http://www.w3.org/2006/time#> \n" - + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" - + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" - + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" - + "SELECT * " - + "WHERE { " - + " <urn:event1> time:atTime ?time . " - + " <urn:event1> geo:asWKT ?point . " - + " FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " - + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " - + "}"; - - final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(); - final Set<BindingSet> results = new HashSet<>(); - while(rez.hasNext()) { - final BindingSet bs = rez.next(); - results.add(bs); - } - final MapBindingSet expected = new MapBindingSet(); - expected.addBinding("point", VF.createLiteral("POINT (0 0)")); - expected.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z")); - - assertEquals(1, results.size()); - assertEquals(expected, results.iterator().next()); - } - - @Test - public void variableSubjQuery_Test() throws Exception { - final String query = - "PREFIX time: <http://www.w3.org/2006/time#> \n" - + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" - + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" - + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" - + "SELECT * " - + "WHERE { " - + " ?subj time:atTime ?time . " - + " ?subj geo:asWKT ?point . " - + " FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " - + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " - + "}"; - - final TupleQueryResult rez = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(); - final List<BindingSet> results = new ArrayList<>(); - while(rez.hasNext()) { - final BindingSet bs = rez.next(); - results.add(bs); - } - final MapBindingSet expected1 = new MapBindingSet(); - expected1.addBinding("point", VF.createLiteral("POINT (0 0)")); - expected1.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z")); - - final MapBindingSet expected2 = new MapBindingSet(); - expected2.addBinding("point", VF.createLiteral("POINT (1 1)")); - expected2.addBinding("time", VF.createLiteral("2015-12-30T12:00:00Z")); - - assertEquals(2, results.size()); - assertEquals(expected1, results.get(0)); - assertEquals(expected2, results.get(1)); - } - - private void addStatements() throws Exception { - URI subject = VF.createURI("urn:event1"); - final URI predicate = VF.createURI(URI_PROPERTY_AT_TIME); - Value object = VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - conn.add(VF.createStatement(subject, predicate, object)); - - object = VF.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - conn.add(VF.createStatement(subject, GeoConstants.GEO_AS_WKT, object)); - - subject = VF.createURI("urn:event2"); - object = VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()); - conn.add(VF.createStatement(subject, predicate, object)); - - object = VF.createLiteral("Point(1 1)", GeoConstants.XMLSCHEMA_OGC_WKT); - conn.add(VF.createStatement(subject, GeoConstants.GEO_AS_WKT, object)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e76b8d7/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java deleted file mode 100644 index f35eeb7..0000000 --- a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/model/EventQueryNodeTest.java +++ /dev/null @@ -1,362 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rya.indexing.geotemporal.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.rya.api.domain.RyaURI; -import org.apache.rya.indexing.IndexingExpr; -import org.apache.rya.indexing.IndexingFunctionRegistry; -import org.apache.rya.indexing.IndexingFunctionRegistry.FUNCTION_TYPE; -import org.apache.rya.indexing.TemporalInstant; -import org.apache.rya.indexing.TemporalInstantRfc3339; -import org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage; -import org.apache.rya.indexing.geotemporal.mongo.MongoITBase; -import org.apache.rya.indexing.geotemporal.storage.EventStorage; -import org.junit.Test; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.URIImpl; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.algebra.FunctionCall; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.ValueConstant; -import org.openrdf.query.algebra.ValueExpr; -import org.openrdf.query.algebra.Var; -import org.openrdf.query.impl.MapBindingSet; - -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.PrecisionModel; - -import info.aduna.iteration.CloseableIteration; - -/** - * Unit tests the methods of {@link EventQueryNode}. - */ -public class EventQueryNodeTest extends MongoITBase { - private static final GeometryFactory GF = new GeometryFactory(new PrecisionModel(), 4326); - private static final ValueFactory VF = ValueFactoryImpl.getInstance(); - - @Test(expected = IllegalStateException.class) - public void constructor_differentSubjects() throws Exception { - final Var geoSubj = new Var("point"); - final Var geoPred = new Var("-const-http://www.opengis.net/ont/geosparql#asWKT", ValueFactoryImpl.getInstance().createURI("http://www.opengis.net/ont/geosparql#asWKT")); - final Var geoObj = new Var("wkt"); - final StatementPattern geoSP = new StatementPattern(geoSubj, geoPred, geoObj); - - final Var timeSubj = new Var("time"); - final Var timePred = new Var("-const-http://www.w3.org/2006/time#inXSDDateTime", ValueFactoryImpl.getInstance().createURI("-const-http://www.w3.org/2006/time#inXSDDateTime")); - final Var timeObj = new Var("time"); - final StatementPattern timeSP = new StatementPattern(timeSubj, timePred, timeObj); - // This will fail. - new EventQueryNode.EventQueryNodeBuilder() - .setStorage(mock(EventStorage.class)) - .setGeoPattern(geoSP) - .setTemporalPattern(timeSP) - .setGeoFilters(new ArrayList<IndexingExpr>()) - .setTemporalFilters(new ArrayList<IndexingExpr>()) - .setUsedFilters(new ArrayList<>()) - .build(); - } - - @Test(expected = IllegalStateException.class) - public void constructor_variablePredicate() throws Exception { - // A pattern that has a variable for its predicate. - final Var geoSubj = new Var("point"); - final Var geoPred = new Var("geo"); - final Var geoObj = new Var("wkt"); - final StatementPattern geoSP = new StatementPattern(geoSubj, geoPred, geoObj); - - final Var timeSubj = new Var("time"); - final Var timePred = new Var("-const-http://www.w3.org/2006/time#inXSDDateTime", ValueFactoryImpl.getInstance().createURI("-const-http://www.w3.org/2006/time#inXSDDateTime")); - final Var timeObj = new Var("time"); - final StatementPattern timeSP = new StatementPattern(timeSubj, timePred, timeObj); - // This will fail. - new EventQueryNode.EventQueryNodeBuilder() - .setStorage(mock(EventStorage.class)) - .setGeoPattern(geoSP) - .setTemporalPattern(timeSP) - .setGeoFilters(new ArrayList<IndexingExpr>()) - .setTemporalFilters(new ArrayList<IndexingExpr>()) - .setUsedFilters(new ArrayList<>()) - .build(); - } - - @Test - public void evaluate_constantSubject() throws Exception { - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), "testDB"); - RyaURI subject = new RyaURI("urn:event-1111"); - final Geometry geo = GF.createPoint(new Coordinate(1, 1)); - final TemporalInstant temp = new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0); - final Event event = Event.builder() - .setSubject(subject) - .setGeometry(geo) - .setTemporalInstant(temp) - .build(); - - subject = new RyaURI("urn:event-2222"); - final Event otherEvent = Event.builder() - .setSubject(subject) - .setGeometry(geo) - .setTemporalInstant(temp) - .build(); - - storage.create(event); - storage.create(otherEvent); - - final String query = - "PREFIX time: <http://www.w3.org/2006/time#> \n" - + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" - + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" - + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" - + "SELECT ?event ?time ?point ?wkt " - + "WHERE { " - + " <urn:event-1111> time:atTime ?time . " - + " <urn:event-1111> geo:asWKT ?wkt . " - + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " - + " FILTER(tempo:equals(?time, \"" + temp.toString() + "\")) " - + "}"; - - final EventQueryNode node = buildNode(storage, query); - final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(new MapBindingSet()); - final MapBindingSet expected = new MapBindingSet(); - expected.addBinding("wkt", VF.createLiteral("POINT (1 1)")); - expected.addBinding("time", VF.createLiteral(temp.toString())); - int count = 0; - assertTrue(rez.hasNext()); - while(rez.hasNext()) { - assertEquals(expected, rez.next()); - count++; - } - assertEquals(1, count); - } - - @Test - public void evaluate_variableSubject() throws Exception { - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), "testDB"); - RyaURI subject = new RyaURI("urn:event-1111"); - Geometry geo = GF.createPoint(new Coordinate(1, 1)); - final TemporalInstant temp = new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0); - final Event event = Event.builder() - .setSubject(subject) - .setGeometry(geo) - .setTemporalInstant(temp) - .build(); - - subject = new RyaURI("urn:event-2222"); - geo = GF.createPoint(new Coordinate(-1, -1)); - final Event otherEvent = Event.builder() - .setSubject(subject) - .setGeometry(geo) - .setTemporalInstant(temp) - .build(); - - storage.create(event); - storage.create(otherEvent); - - final String query = - "PREFIX time: <http://www.w3.org/2006/time#> \n" - + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" - + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" - + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" - + "SELECT ?event ?time ?point ?wkt " - + "WHERE { " - + " ?event time:atTime ?time . " - + " ?event geo:asWKT ?wkt . " - + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " - + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " - + "}"; - - final EventQueryNode node = buildNode(storage, query); - final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(new MapBindingSet()); - final MapBindingSet expected1 = new MapBindingSet(); - expected1.addBinding("wkt", VF.createLiteral("POINT (1 1)")); - expected1.addBinding("time", VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString())); - final MapBindingSet expected2 = new MapBindingSet(); - expected2.addBinding("wkt", VF.createLiteral("POINT (-1 -1)")); - expected2.addBinding("time", VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString())); - - final List<BindingSet> actual = new ArrayList<>(); - while(rez.hasNext()) { - actual.add(rez.next()); - } - assertEquals(expected1, actual.get(0)); - assertEquals(expected2, actual.get(1)); - assertEquals(2, actual.size()); - } - - @Test - public void evaluate_variableSubject_existingBindingset() throws Exception { - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), "testDB"); - RyaURI subject = new RyaURI("urn:event-1111"); - Geometry geo = GF.createPoint(new Coordinate(1, 1)); - final TemporalInstant temp = new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0); - final Event event = Event.builder() - .setSubject(subject) - .setGeometry(geo) - .setTemporalInstant(temp) - .build(); - - subject = new RyaURI("urn:event-2222"); - geo = GF.createPoint(new Coordinate(-1, -1)); - final Event otherEvent = Event.builder() - .setSubject(subject) - .setGeometry(geo) - .setTemporalInstant(temp) - .build(); - - storage.create(event); - storage.create(otherEvent); - - final String query = - "PREFIX time: <http://www.w3.org/2006/time#> \n" - + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" - + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" - + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" - + "SELECT ?event ?time ?point ?wkt " - + "WHERE { " - + " ?event time:atTime ?time . " - + " ?event geo:asWKT ?wkt . " - + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " - + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " - + "}"; - - final EventQueryNode node = buildNode(storage, query); - final MapBindingSet existingBindings = new MapBindingSet(); - existingBindings.addBinding("event", VF.createURI("urn:event-2222")); - final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(existingBindings); - final MapBindingSet expected = new MapBindingSet(); - expected.addBinding("wkt", VF.createLiteral("POINT (-1 -1)")); - expected.addBinding("time", VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString())); - - final List<BindingSet> actual = new ArrayList<>(); - while(rez.hasNext()) { - actual.add(rez.next()); - } - assertEquals(1, actual.size()); - assertEquals(expected, actual.get(0)); - } - - @Test - public void evaluate_variableSubject_existingBindingsetWrongFilters() throws Exception { - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), "testDB"); - RyaURI subject = new RyaURI("urn:event-1111"); - Geometry geo = GF.createPoint(new Coordinate(1, 1)); - final TemporalInstant temp = new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0); - final Event event = Event.builder() - .setSubject(subject) - .setGeometry(geo) - .setTemporalInstant(temp) - .build(); - - subject = new RyaURI("urn:event-2222"); - geo = GF.createPoint(new Coordinate(-10, -10)); - final Event otherEvent = Event.builder() - .setSubject(subject) - .setGeometry(geo) - .setTemporalInstant(temp) - .build(); - - storage.create(event); - storage.create(otherEvent); - - final String query = - "PREFIX time: <http://www.w3.org/2006/time#> \n" - + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" - + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" - + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" - + "SELECT ?event ?time ?point ?wkt " - + "WHERE { " - + " ?event time:atTime ?time . " - + " ?event geo:asWKT ?wkt . " - + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " - + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " - + "}"; - - final EventQueryNode node = buildNode(storage, query); - final MapBindingSet existingBindings = new MapBindingSet(); - existingBindings.addBinding("event", VF.createURI("urn:event-2222")); - final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(existingBindings); - final MapBindingSet expected = new MapBindingSet(); - expected.addBinding("wkt", VF.createLiteral("POINT (-1 -1)")); - expected.addBinding("time", VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString())); - - assertFalse(rez.hasNext()); - } - - private EventQueryNode buildNode(final EventStorage store, final String query) throws Exception { - final List<IndexingExpr> geoFilters = new ArrayList<>(); - final List<IndexingExpr> temporalFilters = new ArrayList<>(); - final List<StatementPattern> sps = getSps(query); - final List<FunctionCall> filters = getFilters(query); - for(final FunctionCall filter : filters) { - final URI filterURI = new URIImpl(filter.getURI()); - final Var objVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(filterURI, filter.getArgs()); - final IndexingExpr expr = new IndexingExpr(filterURI, sps.get(0), extractArguments(objVar.getName(), filter)); - if(IndexingFunctionRegistry.getFunctionType(filterURI) == FUNCTION_TYPE.GEO) { - geoFilters.add(expr); - } else { - temporalFilters.add(expr); - } - } - - final StatementPattern geoPattern = sps.get(1); - final StatementPattern temporalPattern = sps.get(0); - - return new EventQueryNode.EventQueryNodeBuilder() - .setStorage(store) - .setGeoPattern(geoPattern) - .setTemporalPattern(temporalPattern) - .setGeoFilters(geoFilters) - .setTemporalFilters(temporalFilters) - .setUsedFilters(filters) - .build(); - } - - private Value[] extractArguments(final String matchName, final FunctionCall call) { - final Value args[] = new Value[call.getArgs().size() - 1]; - int argI = 0; - for (int i = 0; i != call.getArgs().size(); ++i) { - final ValueExpr arg = call.getArgs().get(i); - if (argI == i && arg instanceof Var && matchName.equals(((Var)arg).getName())) { - continue; - } - if (arg instanceof ValueConstant) { - args[argI] = ((ValueConstant)arg).getValue(); - } else if (arg instanceof Var && ((Var)arg).hasValue()) { - args[argI] = ((Var)arg).getValue(); - } else { - throw new IllegalArgumentException("Query error: Found " + arg + ", expected a Literal, BNode or URI"); - } - ++argI; - } - return args; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e76b8d7/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/mongo/EventDocumentConverterTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/mongo/EventDocumentConverterTest.java b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/mongo/EventDocumentConverterTest.java deleted file mode 100644 index 3f2f9d5..0000000 --- a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/geotemporal/mongo/EventDocumentConverterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rya.indexing.geotemporal.mongo; - -import static org.junit.Assert.assertEquals; - -import org.apache.rya.api.domain.RyaURI; -import org.apache.rya.indexing.TemporalInstant; -import org.apache.rya.indexing.TemporalInstantRfc3339; -import org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException; -import org.apache.rya.indexing.geotemporal.model.Event; -import org.apache.rya.indexing.geotemporal.mongo.EventDocumentConverter; -import org.bson.Document; -import org.joda.time.DateTime; -import org.junit.Test; - -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.PrecisionModel; - -/** - * Tests the methods of {@link EventDocumentConverter}. - */ -public class EventDocumentConverterTest { - private static final GeometryFactory GF = new GeometryFactory(new PrecisionModel(), 4326); - - @Test - public void to_and_from_document() throws DocumentConverterException { - final Geometry geo = GF.createPoint(new Coordinate(10, 10)); - final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now()); - - // An Event that will be stored. - final Event event = Event.builder() - .setSubject(new RyaURI("urn:event/001")) - .setGeometry(geo) - .setTemporalInstant(instant) - .build(); - - final Document document = new EventDocumentConverter().toDocument(event); - - // Convert the Document back into an Event. - final Event converted = new EventDocumentConverter().fromDocument(document); - - // Ensure the original matches the round trip converted Event. - assertEquals(event, converted); - } -} \ No newline at end of file