DATADOC-74 Update to version 2.4 of mongo driver
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
<name>Spring Data MongoDB Support</name>
|
||||
|
||||
<properties>
|
||||
<mongo.version>2.3</mongo.version>
|
||||
<mongo.version>2.4</mongo.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -24,37 +24,51 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.document.mongodb.MongoDbUtils;
|
||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
||||
import org.springframework.data.document.mongodb.query.Criteria;
|
||||
import org.springframework.data.document.mongodb.query.Query;
|
||||
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
public class MappingTests {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(MongoDbUtils.class);
|
||||
|
||||
ApplicationContext applicationContext;
|
||||
MongoTemplate template;
|
||||
MongoMappingContext mappingContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setUp() throws Exception {
|
||||
Mongo mongo = new Mongo();
|
||||
mongo.getDB("database").getCollection("person").drop();
|
||||
applicationContext = new ClassPathXmlApplicationContext("/mapping.xml");
|
||||
template = applicationContext.getBean(MongoTemplate.class);
|
||||
mappingContext = applicationContext.getBean(MongoMappingContext.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersonPojo() {
|
||||
public void testPersonPojo() throws Exception {
|
||||
LOGGER.info("about to create new personpojo");
|
||||
PersonPojo p = new PersonPojo(12345, "Person", "Pojo");
|
||||
LOGGER.info("about to insert");
|
||||
template.insert(p);
|
||||
LOGGER.info("done inserting");
|
||||
assertNotNull(p.getId());
|
||||
|
||||
List<PersonPojo> result = template.find(new Query(Criteria.where("ssn").is(12345)), PersonPojo.class);
|
||||
List<PersonPojo> result = template.find(
|
||||
new Query(Criteria.where("ssn").is(12345)), PersonPojo.class);
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result.get(0).getSsn(), is(12345));
|
||||
}
|
||||
@@ -64,7 +78,8 @@ public class MappingTests {
|
||||
PersonCustomIdName p = new PersonCustomIdName(123456, "Custom", "Id");
|
||||
template.insert(p);
|
||||
|
||||
List<PersonCustomIdName> result = template.find(new Query(Criteria.where("ssn").is(123456)), PersonCustomIdName.class);
|
||||
List<PersonCustomIdName> result = template.find(
|
||||
new Query(Criteria.where("ssn").is(123456)), PersonCustomIdName.class);
|
||||
assertThat(result.size(), is(1));
|
||||
assertNotNull(result.get(0).getCustomId());
|
||||
}
|
||||
@@ -84,18 +99,20 @@ public class MappingTests {
|
||||
template.insert(p);
|
||||
assertNotNull(p.getId());
|
||||
|
||||
List<PersonMapProperty> result = template.find(new Query(Criteria.where("ssn").is(1234567)), PersonMapProperty.class);
|
||||
List<PersonMapProperty> result = template.find(
|
||||
new Query(Criteria.where("ssn").is(1234567)), PersonMapProperty.class);
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result.get(0).getAccounts().size(), is(2));
|
||||
assertThat(result.get(0).getAccounts().get("checking").getBalance(), is(1000.0f));
|
||||
assertThat(result.get(0).getAccounts().get("checking").getBalance(),
|
||||
is(1000.0f));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testWriteEntity() {
|
||||
|
||||
Address addr = new Address();
|
||||
addr.setLines(new String[]{"1234 W. 1st Street", "Apt. 12"});
|
||||
addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" });
|
||||
addr.setCity("Anytown");
|
||||
addr.setPostalCode(12345);
|
||||
addr.setCountry("USA");
|
||||
@@ -120,7 +137,8 @@ public class MappingTests {
|
||||
|
||||
assertNotNull(p.getId());
|
||||
|
||||
List<Person> result = template.find(new Query(Criteria.where("ssn").is(123456789)), Person.class);
|
||||
List<Person> result = template.find(
|
||||
new Query(Criteria.where("ssn").is(123456789)), Person.class);
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result.get(0).getAddress().getCountry(), is("USA"));
|
||||
assertThat(result.get(0).getAccounts(), notNullValue());
|
||||
@@ -129,7 +147,7 @@ public class MappingTests {
|
||||
@Test
|
||||
public void testUniqueIndex() {
|
||||
Address addr = new Address();
|
||||
addr.setLines(new String[]{"1234 W. 1st Street", "Apt. 12"});
|
||||
addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" });
|
||||
addr.setCity("Anytown");
|
||||
addr.setPostalCode(12345);
|
||||
addr.setCountry("USA");
|
||||
@@ -140,12 +158,13 @@ public class MappingTests {
|
||||
template.insert("person", p1);
|
||||
template.insert("person", p2);
|
||||
|
||||
List<Person> result = template.find(new Query(Criteria.where("ssn").is(1234567890)), Person.class);
|
||||
List<Person> result = template.find(
|
||||
new Query(Criteria.where("ssn").is(1234567890)), Person.class);
|
||||
assertThat(result.size(), is(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvents(){
|
||||
public void testEvents() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user