http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageIT.java new file mode 100644 index 0000000..c7d8a81 --- /dev/null +++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageIT.java @@ -0,0 +1,198 @@ +/** + * 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 static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Optional; + +import org.apache.rya.api.domain.RyaURI; +import org.apache.rya.indexing.TemporalInstant; +import org.apache.rya.indexing.TemporalInstantRfc3339; +import org.apache.rya.indexing.geotemporal.model.Event; +import org.apache.rya.indexing.geotemporal.storage.EventStorage; +import org.apache.rya.indexing.geotemporal.storage.EventStorage.EventAlreadyExistsException; +import org.apache.rya.indexing.geotemporal.storage.EventStorage.EventStorageException; +import org.apache.rya.mongodb.MongoITBase; +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; + +/** + * Integration tests the methods of {@link MongoEventStorage}. + */ +public class MongoEventStorageIT extends MongoITBase { + + private static final String RYA_INSTANCE_NAME = "testInstance"; + private static final GeometryFactory GF = new GeometryFactory(new PrecisionModel(), 4326); + + @Test + public void create_and_get() throws Exception { + 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(); + + // Create it. + final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); + storage.create(event); + + // Get it. + final Optional<Event> storedEvent = storage.get(new RyaURI("urn:event/001")); + + // Verify the correct value was returned. + assertEquals(event, storedEvent.get()); + } + + @Test + public void can_not_create_with_same_subject() throws Exception { + 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(); + + // Create it. + final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); + storage.create(event); + + // Try to create it again. This will fail. + boolean failed = false; + try { + storage.create(event); + } catch(final EventAlreadyExistsException e) { + failed = true; + } + assertTrue(failed); + } + + @Test + public void get_noneExisting() throws Exception { + // Get a Type that hasn't been created. + final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); + final Optional<Event> storedEvent = storage.get(new RyaURI("urn:event/000")); + + // Verify nothing was returned. + assertFalse(storedEvent.isPresent()); + } + + @Test + public void delete() throws Exception { + 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/002")) + .setGeometry(geo) + .setTemporalInstant(instant) + .build(); + + // Create it. + final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); + storage.create(event); + + // Delete it. + final boolean deleted = storage.delete( new RyaURI("urn:event/002") ); + + // Verify a document was deleted. + assertTrue( deleted ); + } + + @Test + public void delete_nonExisting() throws Exception { + // Delete an Event that has not been created. + final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); + final boolean deleted = storage.delete( new RyaURI("urn:event/003") ); + + // Verify no document was deleted. + assertFalse( deleted ); + } + + @Test + public void update() throws Exception { + final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); + final Geometry geo = GF.createPoint(new Coordinate(10, 10)); + TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now()); + + // An Event that will be stored. + final Event event = Event.builder() + .setSubject(new RyaURI("urn:event/004")) + .setGeometry(geo) + .setTemporalInstant(instant) + .build(); + + storage.create(event); + + // Show Alice was stored. + Optional<Event> latest = storage.get(new RyaURI("urn:event/004")); + assertEquals(event, latest.get()); + + instant = new TemporalInstantRfc3339(DateTime.now()); + // Change Alice's eye color to brown. + final Event updated = Event.builder(event) + .setTemporalInstant(instant) + .build(); + + storage.update(event, updated); + + // Fetch the Alice object and ensure it has the new value. + latest = storage.get(new RyaURI("urn:event/004")); + + assertEquals(updated, latest.get()); + } + + @Test(expected = EventStorageException.class) + public void update_differentSubjects() throws Exception { + final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); + final Geometry geo = GF.createPoint(new Coordinate(10, 10)); + final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now()); + + // Two objects that do not have the same Subjects. + final Event old = Event.builder() + .setSubject(new RyaURI("urn:event/001")) + .setGeometry(geo) + .setTemporalInstant(instant) + .build(); + + final Event updated = Event.builder() + .setSubject(new RyaURI("urn:event/002")) + .setGeometry(geo) + .setTemporalInstant(instant) + .build(); + + // The update will fail. + storage.update(old, updated); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java deleted file mode 100644 index 6bd0b6d..0000000 --- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoEventStorageTest.java +++ /dev/null @@ -1,198 +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 static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Optional; - -import org.apache.rya.api.domain.RyaURI; -import org.apache.rya.indexing.TemporalInstant; -import org.apache.rya.indexing.TemporalInstantRfc3339; -import org.apache.rya.indexing.geotemporal.model.Event; -import org.apache.rya.indexing.geotemporal.storage.EventStorage; -import org.apache.rya.indexing.geotemporal.storage.EventStorage.EventAlreadyExistsException; -import org.apache.rya.indexing.geotemporal.storage.EventStorage.EventStorageException; -import org.apache.rya.mongodb.MongoTestBase; -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; - -/** - * Integration tests the methods of {@link MongoEventStorage}. - */ -public class MongoEventStorageTest extends MongoTestBase { - - private static final String RYA_INSTANCE_NAME = "testInstance"; - private static final GeometryFactory GF = new GeometryFactory(new PrecisionModel(), 4326); - - @Test - public void create_and_get() throws Exception { - 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(); - - // Create it. - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); - storage.create(event); - - // Get it. - final Optional<Event> storedEvent = storage.get(new RyaURI("urn:event/001")); - - // Verify the correct value was returned. - assertEquals(event, storedEvent.get()); - } - - @Test - public void can_not_create_with_same_subject() throws Exception { - 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(); - - // Create it. - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); - storage.create(event); - - // Try to create it again. This will fail. - boolean failed = false; - try { - storage.create(event); - } catch(final EventAlreadyExistsException e) { - failed = true; - } - assertTrue(failed); - } - - @Test - public void get_noneExisting() throws Exception { - // Get a Type that hasn't been created. - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); - final Optional<Event> storedEvent = storage.get(new RyaURI("urn:event/000")); - - // Verify nothing was returned. - assertFalse(storedEvent.isPresent()); - } - - @Test - public void delete() throws Exception { - 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/002")) - .setGeometry(geo) - .setTemporalInstant(instant) - .build(); - - // Create it. - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); - storage.create(event); - - // Delete it. - final boolean deleted = storage.delete( new RyaURI("urn:event/002") ); - - // Verify a document was deleted. - assertTrue( deleted ); - } - - @Test - public void delete_nonExisting() throws Exception { - // Delete an Event that has not been created. - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); - final boolean deleted = storage.delete( new RyaURI("urn:event/003") ); - - // Verify no document was deleted. - assertFalse( deleted ); - } - - @Test - public void update() throws Exception { - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); - final Geometry geo = GF.createPoint(new Coordinate(10, 10)); - TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now()); - - // An Event that will be stored. - final Event event = Event.builder() - .setSubject(new RyaURI("urn:event/004")) - .setGeometry(geo) - .setTemporalInstant(instant) - .build(); - - storage.create(event); - - // Show Alice was stored. - Optional<Event> latest = storage.get(new RyaURI("urn:event/004")); - assertEquals(event, latest.get()); - - instant = new TemporalInstantRfc3339(DateTime.now()); - // Change Alice's eye color to brown. - final Event updated = Event.builder(event) - .setTemporalInstant(instant) - .build(); - - storage.update(event, updated); - - // Fetch the Alice object and ensure it has the new value. - latest = storage.get(new RyaURI("urn:event/004")); - - assertEquals(updated, latest.get()); - } - - @Test(expected = EventStorageException.class) - public void update_differentSubjects() throws Exception { - final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME); - final Geometry geo = GF.createPoint(new Coordinate(10, 10)); - final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now()); - - // Two objects that do not have the same Subjects. - final Event old = Event.builder() - .setSubject(new RyaURI("urn:event/001")) - .setGeometry(geo) - .setTemporalInstant(instant) - .build(); - - final Event updated = Event.builder() - .setSubject(new RyaURI("urn:event/002")) - .setGeometry(geo) - .setTemporalInstant(instant) - .build(); - - // The update will fail. - storage.update(old, updated); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java index 9bfe148..881289a 100644 --- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java +++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/geotemporal/mongo/MongoGeoTemporalIndexerIT.java @@ -31,7 +31,7 @@ import org.apache.rya.indexing.GeoConstants; import org.apache.rya.indexing.TemporalInstant; import org.apache.rya.indexing.geotemporal.model.Event; import org.apache.rya.indexing.geotemporal.storage.EventStorage; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.junit.Before; import org.junit.Test; import org.openrdf.model.Resource; @@ -46,7 +46,7 @@ import com.vividsolutions.jts.geom.Geometry; /** * Integration tests the methods of {@link MongoGeoTemporalIndexer}. */ -public class MongoGeoTemporalIndexerIT extends MongoTestBase { +public class MongoGeoTemporalIndexerIT extends MongoITBase { private MongoGeoTemporalIndexer indexer; @Before http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java index 11c1d21..f38fc06 100644 --- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java +++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerFilterIT.java @@ -31,7 +31,7 @@ import org.apache.rya.indexing.GeoRyaSailFactory; import org.apache.rya.indexing.accumulo.ConfigUtils; import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils; import org.apache.rya.mongodb.MongoDBRdfConfiguration; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.junit.Test; import org.openrdf.model.Resource; import org.openrdf.model.Statement; @@ -56,7 +56,7 @@ import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; import com.vividsolutions.jts.io.WKTWriter; -public class MongoGeoIndexerFilterIT extends MongoTestBase { +public class MongoGeoIndexerFilterIT extends MongoITBase { private static final GeometryFactory GF = new GeometryFactory(); private static final Geometry WASHINGTON_MONUMENT = GF.createPoint(new Coordinate(38.8895, 77.0353)); private static final Geometry LINCOLN_MEMORIAL = GF.createPoint(new Coordinate(38.8893, 77.0502)); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerIT.java new file mode 100644 index 0000000..40751ae --- /dev/null +++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerIT.java @@ -0,0 +1,377 @@ +/** + * 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.mongo; + +import static org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement; +import static org.apache.rya.indexing.GeoIndexingTestUtils.getSet; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Collections; +import java.util.Set; + +import org.apache.rya.indexing.GeoConstants; +import org.apache.rya.indexing.StatementConstraints; +import org.apache.rya.indexing.accumulo.ConfigUtils; +import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils; +import org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer; +import org.apache.rya.mongodb.MongoDBRdfConfiguration; +import org.apache.rya.mongodb.MongoITBase; +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.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; + +public class MongoGeoIndexerIT extends MongoITBase { + private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints(); + GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326); + + @Override + public void updateConfiguration(final MongoDBRdfConfiguration conf) { + conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT"); + conf.set(OptionalConfigUtils.USE_GEO, "true"); + } + + @Test + public void testRestrictPredicatesSearch() throws Exception { + try (final MongoGeoIndexer f = new MongoGeoIndexer()) { + conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2"); + f.setConf(conf); + f.init(); + + 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)); + assertEquals(2, actual.size()); + assertTrue(actual.contains(s3)); + assertTrue(actual.contains(s4)); + } + } + + @Test + public void testPrimeMeridianSearch() throws Exception { + try (final MongoGeoIndexer f = new MongoGeoIndexer()) { + f.setConf(conf); + f.init(); + + 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[] {}); + + assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); + assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS))); + 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 }); + 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[] {}); + assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); + } + } + + @Test + public void testDcSearch() throws Exception { + // test a ring around dc + try (final MongoGeoIndexer f = new MongoGeoIndexer()) { + f.setConf(conf); + f.init(); + + 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[] {}); + 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[] {}); + assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); + } + } + + @Test + public void testDeleteSearch() throws Exception { + // test a ring around dc + try (final MongoGeoIndexer f = new MongoGeoIndexer()) { + f.setConf(conf); + f.init(); + + 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[] {}); + 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[] {}); + assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); + + // test a ring for the whole world and make sure the point is gone + // Geomesa is a little sensitive around lon 180, so we only go to 179 + final double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 }; + final LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2)); + final Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {}); + assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS))); + } + } + + @Test + public void testDcSearchWithContext() throws Exception { + // test a ring around dc + try (final MongoGeoIndexer f = new MongoGeoIndexer()) { + f.setConf(conf); + f.init(); + + 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 + assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context)))); + + // query with wrong context + 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 MongoGeoIndexer f = new MongoGeoIndexer()) { + f.setConf(conf); + f.init(); + + 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 + assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject)))); + + // query with wrong subject + 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 MongoGeoIndexer f = new MongoGeoIndexer()) { + f.setConf(conf); + f.init(); + + 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 + assertEquals(Sets.newHashSet(statement), + getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject)))); + + // query with wrong context + assertEquals(Sets.newHashSet(), + getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2"))))); + + // query with wrong subject + 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 MongoGeoIndexer f = new MongoGeoIndexer()) { + f.setConf(conf); + f.init(); + + 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 + assertEquals(Sets.newHashSet(statement), + getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate))))); + + // query with wrong predicate + 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 MongoGeoIndexer f = new MongoGeoIndexer()) { + f.setConf(conf); + f.init(); + + 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[] {}); + + assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfIT.java new file mode 100644 index 0000000..a544a78 --- /dev/null +++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfIT.java @@ -0,0 +1,262 @@ +package org.apache.rya.indexing.mongo; +/* + * 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. + */ + +import static org.apache.rya.indexing.GeoIndexingTestUtils.getSet; +import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.bbox; +import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.line; +import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.point; +import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.poly; + +import java.util.Map; +import java.util.Set; + +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.resolver.RdfToRyaConversions; +import org.apache.rya.api.resolver.RyaToRdfConversions; +import org.apache.rya.indexing.GeoConstants; +import org.apache.rya.indexing.StatementConstraints; +import org.apache.rya.indexing.accumulo.ConfigUtils; +import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils; +import org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer; +import org.apache.rya.mongodb.MongoDBRdfConfiguration; +import org.apache.rya.mongodb.MongoITBase; +import org.junit.Assert; +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.StatementImpl; +import org.openrdf.model.impl.ValueFactoryImpl; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.Polygon; + +import info.aduna.iteration.CloseableIteration; + +/** + * Tests all of the "simple functions" of the geoindexer. + */ +public class MongoGeoIndexerSfIT extends MongoITBase { + private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints(); + + // Here is the landscape: + /** + * <pre> + * +---+---+---+---+---+---+---+ + * | F | | + * + A + + C + + * | | | + * +---+---+ E +---+---+ + * | | / | + * + B + /+---+---+ + * | | / | | + * +---+---+/--+---+---+ + * / | D | + * / +---+---+ + * </pre> + **/ + + private static final Polygon A = poly(bbox(0, 1, 4, 5)); + private static final Polygon B = poly(bbox(0, 1, 2, 3)); + private static final Polygon C = poly(bbox(4, 3, 6, 5)); + private static final Polygon D = poly(bbox(3, 0, 5, 2)); + + private static final Point F = point(2, 4); + + private static final LineString E = line(2, 0, 3, 3); + + private static final Map<Geometry, String> names = Maps.newHashMap(); + static { + names.put(A, "A"); + names.put(B, "B"); + names.put(C, "C"); + names.put(D, "D"); + names.put(E, "E"); + names.put(F, "F"); + } + + @Override + public void updateConfiguration(final MongoDBRdfConfiguration conf) { + conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT"); + conf.set(OptionalConfigUtils.USE_GEO, "true"); + } + + private static RyaStatement statement(final Geometry geo) { + final ValueFactory vf = new ValueFactoryImpl(); + final Resource subject = vf.createURI("uri:" + names.get(geo)); + final URI predicate = GeoConstants.GEO_AS_WKT; + final Value object = vf.createLiteral(geo.toString(), GeoConstants.XMLSCHEMA_OGC_WKT); + return RdfToRyaConversions.convertStatement(new StatementImpl(subject, predicate, object)); + + } + + public void compare(final CloseableIteration<Statement, ?> actual, final Geometry... expected) throws Exception { + final Set<Statement> expectedSet = Sets.newHashSet(); + for (final Geometry geo : expected) { + expectedSet.add(RyaToRdfConversions.convertStatement(statement(geo))); + } + + Assert.assertEquals(expectedSet, getSet(actual)); + } + + private static Geometry[] EMPTY_RESULTS = {}; + + @Test + public void testEquals() throws Exception { + try(final MongoGeoIndexer g = new MongoGeoIndexer()) { + g.setConf(conf); + g.init(); + + g.storeStatement(statement(A)); + g.storeStatement(statement(B)); + g.storeStatement(statement(C)); + g.storeStatement(statement(D)); + g.storeStatement(statement(F)); + g.storeStatement(statement(E)); + // point + compare(g.queryEquals(F, EMPTY_CONSTRAINTS), F); + compare(g.queryEquals(point(2, 2), EMPTY_CONSTRAINTS), EMPTY_RESULTS); + + // line + compare(g.queryEquals(E, EMPTY_CONSTRAINTS), E); + compare(g.queryEquals(line(2, 2, 3, 3), EMPTY_CONSTRAINTS), EMPTY_RESULTS); + + // poly + compare(g.queryEquals(A, EMPTY_CONSTRAINTS), A); + compare(g.queryEquals(poly(bbox(1, 1, 4, 5)), EMPTY_CONSTRAINTS), EMPTY_RESULTS); + } + } + +// @Test +// public void testDisjoint() throws Exception { +// // point +// compare(g.queryDisjoint(F, EMPTY_CONSTRAINTS), B, C, D, E); +// +// // line +// compare(g.queryDisjoint(E, EMPTY_CONSTRAINTS), B, C, D, F); +// +// // poly +// compare(g.queryDisjoint(A, EMPTY_CONSTRAINTS), EMPTY_RESULTS); +// compare(g.queryDisjoint(B, EMPTY_CONSTRAINTS), C, D, F, E); +// } + +// @Test +// public void testIntersectsPoint() throws Exception { + // This seems like a bug + // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), A, F); + // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS); +// } +// +// @Test +// public void testIntersectsLine() throws Exception { + // This seems like a bug + // compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), A, E); + // compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS); +// } + +// @Test +// public void testIntersectsPoly() throws Exception { +// compare(g.queryIntersects(A, EMPTY_CONSTRAINTS), A, B, C, D, F, E); +// } + +// @Test +// public void testTouchesPoint() throws Exception { +// compare(g.queryTouches(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS); +// } +// +// @Test +// public void testTouchesLine() throws Exception { +// compare(g.queryTouches(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS); +// } + +// @Test +// public void testTouchesPoly() throws Exception { +// compare(g.queryTouches(A, EMPTY_CONSTRAINTS), C); +// } + +// @Test +// public void testCrossesPoint() throws Exception { +// compare(g.queryCrosses(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS); +// } + +// @Test +// public void testCrossesLine() throws Exception { + // compare(g.queryCrosses(E, EMPTY_CONSTRAINTS), A); +// } + +// @Test +// public void testCrossesPoly() throws Exception { +// compare(g.queryCrosses(A, EMPTY_CONSTRAINTS), E); +// } + +// @Test +// public void testWithin() throws Exception { +// // point +// // compare(g.queryWithin(F, EMPTY_CONSTRAINTS), F); +// +// // line +//// compare(g.queryWithin(E, EMPTY_CONSTRAINTS), E); +// +// // poly +// compare(g.queryWithin(A, EMPTY_CONSTRAINTS), A, B, F); +// } + +// @Test +// public void testContainsPoint() throws Exception { +// compare(g.queryContains(F, EMPTY_CONSTRAINTS), A, F); +// } + +// @Test +// public void testContainsLine() throws Exception { + // compare(g.queryContains(E, EMPTY_CONSTRAINTS), E); +// } + +// @Test +// public void testContainsPoly() throws Exception { +// compare(g.queryContains(A, EMPTY_CONSTRAINTS), A); +// compare(g.queryContains(B, EMPTY_CONSTRAINTS), A, B); +// } +// +// @Test +// public void testOverlapsPoint() throws Exception { + // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), F); + // You cannot have overlapping points + // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS); +// } + +// @Test +// public void testOverlapsLine() throws Exception { + // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), A, E); + // You cannot have overlapping lines + // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS); +// } + +// @Test +// public void testOverlapsPoly() throws Exception { +// compare(g.queryOverlaps(A, EMPTY_CONSTRAINTS), D); +// } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java deleted file mode 100644 index bc4d870..0000000 --- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java +++ /dev/null @@ -1,262 +0,0 @@ -package org.apache.rya.indexing.mongo; -/* - * 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. - */ - -import static org.apache.rya.indexing.GeoIndexingTestUtils.getSet; -import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.bbox; -import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.line; -import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.point; -import static org.apache.rya.indexing.geotemporal.GeoTemporalTestUtils.poly; - -import java.util.Map; -import java.util.Set; - -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.resolver.RdfToRyaConversions; -import org.apache.rya.api.resolver.RyaToRdfConversions; -import org.apache.rya.indexing.GeoConstants; -import org.apache.rya.indexing.StatementConstraints; -import org.apache.rya.indexing.accumulo.ConfigUtils; -import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils; -import org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer; -import org.apache.rya.mongodb.MongoDBRdfConfiguration; -import org.apache.rya.mongodb.MongoTestBase; -import org.junit.Assert; -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.StatementImpl; -import org.openrdf.model.impl.ValueFactoryImpl; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; - -import info.aduna.iteration.CloseableIteration; - -/** - * Tests all of the "simple functions" of the geoindexer. - */ -public class MongoGeoIndexerSfTest extends MongoTestBase { - private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints(); - - // Here is the landscape: - /** - * <pre> - * +---+---+---+---+---+---+---+ - * | F | | - * + A + + C + - * | | | - * +---+---+ E +---+---+ - * | | / | - * + B + /+---+---+ - * | | / | | - * +---+---+/--+---+---+ - * / | D | - * / +---+---+ - * </pre> - **/ - - private static final Polygon A = poly(bbox(0, 1, 4, 5)); - private static final Polygon B = poly(bbox(0, 1, 2, 3)); - private static final Polygon C = poly(bbox(4, 3, 6, 5)); - private static final Polygon D = poly(bbox(3, 0, 5, 2)); - - private static final Point F = point(2, 4); - - private static final LineString E = line(2, 0, 3, 3); - - private static final Map<Geometry, String> names = Maps.newHashMap(); - static { - names.put(A, "A"); - names.put(B, "B"); - names.put(C, "C"); - names.put(D, "D"); - names.put(E, "E"); - names.put(F, "F"); - } - - @Override - public void updateConfiguration(final MongoDBRdfConfiguration conf) { - conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT"); - conf.set(OptionalConfigUtils.USE_GEO, "true"); - } - - private static RyaStatement statement(final Geometry geo) { - final ValueFactory vf = new ValueFactoryImpl(); - final Resource subject = vf.createURI("uri:" + names.get(geo)); - final URI predicate = GeoConstants.GEO_AS_WKT; - final Value object = vf.createLiteral(geo.toString(), GeoConstants.XMLSCHEMA_OGC_WKT); - return RdfToRyaConversions.convertStatement(new StatementImpl(subject, predicate, object)); - - } - - public void compare(final CloseableIteration<Statement, ?> actual, final Geometry... expected) throws Exception { - final Set<Statement> expectedSet = Sets.newHashSet(); - for (final Geometry geo : expected) { - expectedSet.add(RyaToRdfConversions.convertStatement(statement(geo))); - } - - Assert.assertEquals(expectedSet, getSet(actual)); - } - - private static Geometry[] EMPTY_RESULTS = {}; - - @Test - public void testEquals() throws Exception { - try(final MongoGeoIndexer g = new MongoGeoIndexer()) { - g.setConf(conf); - g.init(); - - g.storeStatement(statement(A)); - g.storeStatement(statement(B)); - g.storeStatement(statement(C)); - g.storeStatement(statement(D)); - g.storeStatement(statement(F)); - g.storeStatement(statement(E)); - // point - compare(g.queryEquals(F, EMPTY_CONSTRAINTS), F); - compare(g.queryEquals(point(2, 2), EMPTY_CONSTRAINTS), EMPTY_RESULTS); - - // line - compare(g.queryEquals(E, EMPTY_CONSTRAINTS), E); - compare(g.queryEquals(line(2, 2, 3, 3), EMPTY_CONSTRAINTS), EMPTY_RESULTS); - - // poly - compare(g.queryEquals(A, EMPTY_CONSTRAINTS), A); - compare(g.queryEquals(poly(bbox(1, 1, 4, 5)), EMPTY_CONSTRAINTS), EMPTY_RESULTS); - } - } - -// @Test -// public void testDisjoint() throws Exception { -// // point -// compare(g.queryDisjoint(F, EMPTY_CONSTRAINTS), B, C, D, E); -// -// // line -// compare(g.queryDisjoint(E, EMPTY_CONSTRAINTS), B, C, D, F); -// -// // poly -// compare(g.queryDisjoint(A, EMPTY_CONSTRAINTS), EMPTY_RESULTS); -// compare(g.queryDisjoint(B, EMPTY_CONSTRAINTS), C, D, F, E); -// } - -// @Test -// public void testIntersectsPoint() throws Exception { - // This seems like a bug - // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), A, F); - // compare(g.queryIntersects(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS); -// } -// -// @Test -// public void testIntersectsLine() throws Exception { - // This seems like a bug - // compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), A, E); - // compare(g.queryIntersects(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS); -// } - -// @Test -// public void testIntersectsPoly() throws Exception { -// compare(g.queryIntersects(A, EMPTY_CONSTRAINTS), A, B, C, D, F, E); -// } - -// @Test -// public void testTouchesPoint() throws Exception { -// compare(g.queryTouches(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS); -// } -// -// @Test -// public void testTouchesLine() throws Exception { -// compare(g.queryTouches(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS); -// } - -// @Test -// public void testTouchesPoly() throws Exception { -// compare(g.queryTouches(A, EMPTY_CONSTRAINTS), C); -// } - -// @Test -// public void testCrossesPoint() throws Exception { -// compare(g.queryCrosses(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS); -// } - -// @Test -// public void testCrossesLine() throws Exception { - // compare(g.queryCrosses(E, EMPTY_CONSTRAINTS), A); -// } - -// @Test -// public void testCrossesPoly() throws Exception { -// compare(g.queryCrosses(A, EMPTY_CONSTRAINTS), E); -// } - -// @Test -// public void testWithin() throws Exception { -// // point -// // compare(g.queryWithin(F, EMPTY_CONSTRAINTS), F); -// -// // line -//// compare(g.queryWithin(E, EMPTY_CONSTRAINTS), E); -// -// // poly -// compare(g.queryWithin(A, EMPTY_CONSTRAINTS), A, B, F); -// } - -// @Test -// public void testContainsPoint() throws Exception { -// compare(g.queryContains(F, EMPTY_CONSTRAINTS), A, F); -// } - -// @Test -// public void testContainsLine() throws Exception { - // compare(g.queryContains(E, EMPTY_CONSTRAINTS), E); -// } - -// @Test -// public void testContainsPoly() throws Exception { -// compare(g.queryContains(A, EMPTY_CONSTRAINTS), A); -// compare(g.queryContains(B, EMPTY_CONSTRAINTS), A, B); -// } -// -// @Test -// public void testOverlapsPoint() throws Exception { - // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), F); - // You cannot have overlapping points - // compare(g.queryOverlaps(F, EMPTY_CONSTRAINTS), EMPTY_RESULTS); -// } - -// @Test -// public void testOverlapsLine() throws Exception { - // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), A, E); - // You cannot have overlapping lines - // compare(g.queryOverlaps(E, EMPTY_CONSTRAINTS), EMPTY_RESULTS); -// } - -// @Test -// public void testOverlapsPoly() throws Exception { -// compare(g.queryOverlaps(A, EMPTY_CONSTRAINTS), D); -// } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java deleted file mode 100644 index 5953132..0000000 --- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java +++ /dev/null @@ -1,377 +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.mongo; - -import static org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement; -import static org.apache.rya.indexing.GeoIndexingTestUtils.getSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Collections; -import java.util.Set; - -import org.apache.rya.indexing.GeoConstants; -import org.apache.rya.indexing.StatementConstraints; -import org.apache.rya.indexing.accumulo.ConfigUtils; -import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils; -import org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer; -import org.apache.rya.mongodb.MongoDBRdfConfiguration; -import org.apache.rya.mongodb.MongoTestBase; -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.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; - -public class MongoGeoIndexerTest extends MongoTestBase { - private static final StatementConstraints EMPTY_CONSTRAINTS = new StatementConstraints(); - GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326); - - @Override - public void updateConfiguration(final MongoDBRdfConfiguration conf) { - conf.set(ConfigUtils.GEO_PREDICATES_LIST, "http://www.opengis.net/ont/geosparql#asWKT"); - conf.set(OptionalConfigUtils.USE_GEO, "true"); - } - - @Test - public void testRestrictPredicatesSearch() throws Exception { - try (final MongoGeoIndexer f = new MongoGeoIndexer()) { - conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2"); - f.setConf(conf); - f.init(); - - 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)); - assertEquals(2, actual.size()); - assertTrue(actual.contains(s3)); - assertTrue(actual.contains(s4)); - } - } - - @Test - public void testPrimeMeridianSearch() throws Exception { - try (final MongoGeoIndexer f = new MongoGeoIndexer()) { - f.setConf(conf); - f.init(); - - 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[] {}); - - assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS))); - 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 }); - 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[] {}); - assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); - } - } - - @Test - public void testDcSearch() throws Exception { - // test a ring around dc - try (final MongoGeoIndexer f = new MongoGeoIndexer()) { - f.setConf(conf); - f.init(); - - 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[] {}); - 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[] {}); - assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); - } - } - - @Test - public void testDeleteSearch() throws Exception { - // test a ring around dc - try (final MongoGeoIndexer f = new MongoGeoIndexer()) { - f.setConf(conf); - f.init(); - - 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[] {}); - 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[] {}); - assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); - - // test a ring for the whole world and make sure the point is gone - // Geomesa is a little sensitive around lon 180, so we only go to 179 - final double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 }; - final LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2)); - final Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {}); - assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS))); - } - } - - @Test - public void testDcSearchWithContext() throws Exception { - // test a ring around dc - try (final MongoGeoIndexer f = new MongoGeoIndexer()) { - f.setConf(conf); - f.init(); - - 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 - assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context)))); - - // query with wrong context - 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 MongoGeoIndexer f = new MongoGeoIndexer()) { - f.setConf(conf); - f.init(); - - 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 - assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject)))); - - // query with wrong subject - 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 MongoGeoIndexer f = new MongoGeoIndexer()) { - f.setConf(conf); - f.init(); - - 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 - assertEquals(Sets.newHashSet(statement), - getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject)))); - - // query with wrong context - assertEquals(Sets.newHashSet(), - getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2"))))); - - // query with wrong subject - 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 MongoGeoIndexer f = new MongoGeoIndexer()) { - f.setConf(conf); - f.init(); - - 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 - assertEquals(Sets.newHashSet(statement), - getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate))))); - - // query with wrong predicate - 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 MongoGeoIndexer f = new MongoGeoIndexer()) { - f.setConf(conf); - f.init(); - - 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[] {}); - - assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java index 1c2a339..6acc998 100644 --- a/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java +++ b/extras/rya.geoindexing/geo.mongo/src/test/java/org/apache/rya/indexing/mongo/MongoIndexerDeleteIT.java @@ -30,7 +30,7 @@ import org.apache.rya.indexing.TemporalInstantRfc3339; import org.apache.rya.indexing.accumulo.ConfigUtils; import org.apache.rya.indexing.accumulo.geo.OptionalConfigUtils; import org.apache.rya.mongodb.MongoDBRdfConfiguration; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.junit.Test; import org.openrdf.model.Resource; import org.openrdf.model.Statement; @@ -53,7 +53,7 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.io.WKTWriter; -public class MongoIndexerDeleteIT extends MongoTestBase { +public class MongoIndexerDeleteIT extends MongoITBase { @Override public void updateConfiguration(final MongoDBRdfConfiguration conf) { conf.setStrings(ConfigUtils.FREETEXT_PREDICATES_LIST, new String[] {RDFS.LABEL.stringValue()}); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4576f556/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java ---------------------------------------------------------------------- diff --git a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java index e401589..341cb15 100644 --- a/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java +++ b/sail/src/main/java/org/apache/rya/rdftriplestore/RdfCloudTripleStore.java @@ -1,7 +1,3 @@ -package org.apache.rya.rdftriplestore; - -import static com.google.common.base.Preconditions.checkNotNull; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -20,8 +16,9 @@ import static com.google.common.base.Preconditions.checkNotNull; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.rdftriplestore; - +import static com.google.common.base.Preconditions.checkNotNull; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.persist.RdfEvalStatsDAO;
