mirror of
https://github.com/spring-projects/spring-data-mongodb.git
synced 2026-05-03 03:34:23 +01:00
expand on test to test retrieval of subelements. add-remove spring .xsd in STS to remove tooling releated error
This commit is contained in:
+11
-1
@@ -19,6 +19,7 @@ package org.springframework.data.document.mongodb;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -39,6 +40,8 @@ import org.springframework.data.document.mongodb.monitor.ServerInfo;
|
||||
import org.springframework.data.document.mongodb.query.Criteria;
|
||||
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;
|
||||
|
||||
@@ -61,6 +64,8 @@ public class GeoSpatialTests {
|
||||
ApplicationContext applicationContext;
|
||||
MongoTemplate template;
|
||||
ServerInfo serverInfo;
|
||||
|
||||
ExpressionParser parser;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -76,6 +81,7 @@ public class GeoSpatialTests {
|
||||
template.ensureIndex(new GeospatialIndex("location"));
|
||||
indexCreated();
|
||||
addVenues();
|
||||
parser = new SpelExpressionParser();
|
||||
}
|
||||
|
||||
private void addVenues() {
|
||||
@@ -149,8 +155,12 @@ public class GeoSpatialTests {
|
||||
Venue foundVenue = template.findOne(
|
||||
new Query(Criteria.where("name").is("Penn Station")), Venue.class);
|
||||
assertThat(foundVenue, notNullValue());
|
||||
List<Venue> venues = template.getCollection(Venue.class);
|
||||
List<Venue> venues = template.getCollection(Venue.class);
|
||||
assertThat(venues.size(), equalTo(12));
|
||||
Collection names = (Collection)parser.parseExpression("![name]").getValue(venues);
|
||||
assertThat(names.size(), equalTo(12));
|
||||
org.springframework.util.Assert.notEmpty(names);
|
||||
|
||||
}
|
||||
|
||||
public void indexCreated() {
|
||||
|
||||
+18
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.document.mongodb;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -49,6 +50,15 @@ public class PersonExample {
|
||||
p.setAge(22);
|
||||
|
||||
mongoOps.save(p);
|
||||
|
||||
|
||||
PersonWithIdPropertyOfTypeString p2 = new PersonWithIdPropertyOfTypeString();
|
||||
p2.setFirstName("Jon");
|
||||
p2.setAge(23);
|
||||
|
||||
mongoOps.save(p2);
|
||||
|
||||
|
||||
log.debug("Saved: " + p);
|
||||
|
||||
p = mongoOps.findOne(query(whereId().is(p.getId())), PersonWithIdPropertyOfTypeString.class);
|
||||
@@ -64,6 +74,14 @@ public class PersonExample {
|
||||
log.debug("Updated: " + p);
|
||||
|
||||
|
||||
List<PersonWithIdPropertyOfTypeString> folks = mongoOps.getCollection(PersonWithIdPropertyOfTypeString.class);
|
||||
log.debug("Querying for all people...");
|
||||
for (Iterator iterator = folks.iterator(); iterator.hasNext();) {
|
||||
PersonWithIdPropertyOfTypeString personWithIdPropertyOfTypeString = (PersonWithIdPropertyOfTypeString) iterator
|
||||
.next();
|
||||
log.debug(personWithIdPropertyOfTypeString);
|
||||
}
|
||||
|
||||
//mongoOps.remove( query(whereId().is(p.getId())), p.getClass());
|
||||
|
||||
mongoOps.remove(p);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user