#139 - Switched to embedded MongoDB for integration tests.
Removed MongoDB dependency by adding Flapdoodle embedded MongoDB. That allows us to get rid of the utility module we had in place for the MongoDB samples guarding the tests to only run when a MongoDB instance is running. Tweaked Travis setup to not require the MongoDB service anymore.
This commit is contained in:
@@ -17,7 +17,6 @@ package example.springdata.mongodb.geojson;
|
||||
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.*;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -37,11 +36,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
public class ApplicationConfiguration {
|
||||
|
||||
/**
|
||||
* Read JSON data from disk and insert those stores.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package example.springdata.mongodb.geojson;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,17 +27,11 @@ import org.springframework.data.mongodb.core.geo.GeoJson;
|
||||
import org.springframework.data.mongodb.core.geo.GeoJsonPolygon;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.util.Version;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
|
||||
import example.springdata.mongodb.geojson.Application;
|
||||
import example.springdata.mongodb.geojson.Store;
|
||||
import example.springdata.mongodb.geojson.StoreRepository;
|
||||
import example.springdata.mongodb.util.RequiresMongoDB;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link StoreRepository}.
|
||||
*
|
||||
@@ -46,14 +39,12 @@ import example.springdata.mongodb.util.RequiresMongoDB;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = { Application.class })
|
||||
@SpringApplicationConfiguration(classes = { ApplicationConfiguration.class })
|
||||
public class StoreRepositoryTests {
|
||||
|
||||
private static final GeoJsonPolygon GEO_JSON_POLYGON = new GeoJsonPolygon(new Point(-73.992514, 40.758934),
|
||||
new Point(-73.961138, 40.760348), new Point(-73.991658, 40.730006), new Point(-73.992514, 40.758934));
|
||||
|
||||
public static @ClassRule RequiresMongoDB requiresMongoDB_2_6 = RequiresMongoDB.atLeast(new Version(2, 6, 0));
|
||||
|
||||
@Autowired StoreRepository repository;
|
||||
@Autowired MongoOperations operations;
|
||||
|
||||
@@ -114,9 +105,8 @@ public class StoreRepositoryTests {
|
||||
*/
|
||||
@Test
|
||||
public void findWithinLegacyPolygon() {
|
||||
repository.findByLocationWithin(
|
||||
new Polygon(new Point(-73.992514, 40.758934), new Point(-73.961138, 40.760348),
|
||||
new Point(-73.991658, 40.730006))).forEach(System.out::println);
|
||||
repository.findByLocationWithin(new Polygon(new Point(-73.992514, 40.758934), new Point(-73.961138, 40.760348),
|
||||
new Point(-73.991658, 40.730006))).forEach(System.out::println);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,8 +120,8 @@ public class StoreRepositoryTests {
|
||||
|
||||
operations.getConverter().write(GEO_JSON_POLYGON, geoJsonDbo);
|
||||
|
||||
BasicQuery bq = new BasicQuery(new BasicDBObject("location", new BasicDBObject("$geoIntersects", new BasicDBObject(
|
||||
"$geometry", geoJsonDbo))));
|
||||
BasicQuery bq = new BasicQuery(
|
||||
new BasicDBObject("location", new BasicDBObject("$geoIntersects", new BasicDBObject("$geometry", geoJsonDbo))));
|
||||
|
||||
operations.find(bq, Store.class).forEach(System.out::println);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# Random port for embedded MongoDB
|
||||
spring.data.mongodb.port=0
|
||||
Reference in New Issue
Block a user