Changed tests to use 'database' as the database name except for the repositories tests
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
<bean id="mongoDbFactory" class="org.springframework.data.document.mongodb.MongoDbFactoryBean">
|
||||
<constructor-arg name="mongo" ref="mongo"/>
|
||||
<constructor-arg name="databaseName" value="test"/>
|
||||
<constructor-arg name="databaseName" value="database"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
|
||||
|
||||
@@ -27,7 +27,7 @@ public class GeoSpatialAppConfig extends AbstractMongoConfiguration {
|
||||
|
||||
@Override
|
||||
public String defaultDatabaseName() {
|
||||
return "geospatial";
|
||||
return "database";
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -19,19 +19,18 @@ package org.springframework.data.document.mongodb;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.document.mongodb.geo.Box;
|
||||
import org.springframework.data.document.mongodb.geo.Circle;
|
||||
@@ -42,8 +41,6 @@ import org.springframework.data.document.mongodb.query.GeospatialIndex;
|
||||
import org.springframework.data.document.mongodb.query.Query;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.DBCollection;
|
||||
@@ -61,7 +58,7 @@ import com.mongodb.WriteConcern;
|
||||
public class GeoSpatialTests {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(GeoSpatialTests.class);
|
||||
private final String[] collectionsToDrop = new String[] { "newyork" };
|
||||
private final String[] collectionsToDrop = new String[] { "newyork", "Person" };
|
||||
|
||||
ApplicationContext applicationContext;
|
||||
MongoTemplate template;
|
||||
@@ -71,12 +68,7 @@ public class GeoSpatialTests {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Mongo mongo = new Mongo();
|
||||
serverInfo = new ServerInfo(mongo);
|
||||
DB db = mongo.getDB("geospatial");
|
||||
for (String coll : collectionsToDrop) {
|
||||
db.getCollection(coll).drop();
|
||||
}
|
||||
cleanDb();
|
||||
applicationContext = new AnnotationConfigApplicationContext(GeoSpatialAppConfig.class);
|
||||
template = applicationContext.getBean(MongoTemplate.class);
|
||||
template.setWriteConcern(WriteConcern.FSYNC_SAFE);
|
||||
@@ -86,6 +78,20 @@ public class GeoSpatialTests {
|
||||
parser = new SpelExpressionParser();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() throws Exception {
|
||||
cleanDb();
|
||||
}
|
||||
|
||||
private void cleanDb() throws UnknownHostException {
|
||||
Mongo mongo = new Mongo();
|
||||
serverInfo = new ServerInfo(mongo);
|
||||
DB db = mongo.getDB("database");
|
||||
for (String coll : collectionsToDrop) {
|
||||
db.getCollection(coll).drop();
|
||||
}
|
||||
}
|
||||
|
||||
private void addVenues() {
|
||||
|
||||
template.insert(new Venue("Penn Station", -73.99408, 40.75057));
|
||||
@@ -168,7 +174,7 @@ public class GeoSpatialTests {
|
||||
LOGGER.debug(indexInfo);
|
||||
assertThat(indexInfo.size(), equalTo(2));
|
||||
assertThat(indexInfo.get(1).get("name").toString(), equalTo("location_2d"));
|
||||
assertThat(indexInfo.get(1).get("ns").toString(), equalTo("geospatial.newyork"));
|
||||
assertThat(indexInfo.get(1).get("ns").toString(), equalTo("database.newyork"));
|
||||
}
|
||||
|
||||
// TODO move to MongoAdmin
|
||||
|
||||
@@ -113,7 +113,7 @@ public class MongoTemplateTests {
|
||||
@Test
|
||||
public void updateFailure() throws Exception {
|
||||
|
||||
MongoTemplate mongoTemplate = new MongoTemplate(template.getDb().getMongo(), "test");
|
||||
MongoTemplate mongoTemplate = new MongoTemplate(template.getDbFactory());
|
||||
mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION);
|
||||
|
||||
Person person = new Person("Oliver2");
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.data.document.mongodb.config.AbstractMongoConfigurati
|
||||
|
||||
public class GeoIndexedAppConfig extends AbstractMongoConfiguration {
|
||||
|
||||
public static String GEO_DB = "geodb";
|
||||
public static String GEO_DB = "database";
|
||||
public static String GEO_COLLECTION = "geolocation";
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.document.mongodb.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import com.mongodb.DB;
|
||||
@@ -25,6 +26,8 @@ import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -44,7 +47,7 @@ import org.springframework.data.document.mongodb.mapping.event.MongoMappingEvent
|
||||
*/
|
||||
public class GeoIndexedTests {
|
||||
|
||||
private final String[] collectionsToDrop = new String[] { GeoIndexedAppConfig.GEO_COLLECTION };
|
||||
private final String[] collectionsToDrop = new String[] { GeoIndexedAppConfig.GEO_COLLECTION, "Person"};
|
||||
|
||||
ApplicationContext applicationContext;
|
||||
MongoTemplate template;
|
||||
@@ -52,14 +55,23 @@ public class GeoIndexedTests {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cleanDb();
|
||||
applicationContext = new AnnotationConfigApplicationContext(GeoIndexedAppConfig.class);
|
||||
template = applicationContext.getBean(MongoTemplate.class);
|
||||
mappingContext = applicationContext.getBean(MongoMappingContext.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() throws Exception {
|
||||
cleanDb();
|
||||
}
|
||||
|
||||
private void cleanDb() throws UnknownHostException {
|
||||
Mongo mongo = new Mongo();
|
||||
DB db = mongo.getDB(GeoIndexedAppConfig.GEO_DB);
|
||||
for (String coll : collectionsToDrop) {
|
||||
db.getCollection(coll).drop();
|
||||
}
|
||||
applicationContext = new AnnotationConfigApplicationContext(GeoIndexedAppConfig.class);
|
||||
template = applicationContext.getBean(MongoTemplate.class);
|
||||
mappingContext = applicationContext.getBean(MongoMappingContext.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<bean id="mongoDbFactory" class="org.springframework.data.document.mongodb.MongoDbFactoryBean">
|
||||
<constructor-arg name="mongo" ref="mongo"/>
|
||||
<constructor-arg name="databaseName" value="geospatial"/>
|
||||
<constructor-arg name="databaseName" value="database"/>
|
||||
</bean>
|
||||
|
||||
<mongo:mapping-converter base-package="org.springframework.data.document.mongodb"/>
|
||||
|
||||
Reference in New Issue
Block a user