diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/Friend.java b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/Friend.java new file mode 100644 index 000000000..6f3b2ba9f --- /dev/null +++ b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/Friend.java @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2011 the original author or authors. + * + * Licensed 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.springframework.data.document.mongodb; + +import java.util.ArrayList; +import java.util.List; + +public class Friend { + + private String id; + + private String firstName; + + private int age; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + +} diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoTemplateTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoTemplateTests.java index 72d1a9c15..520005153 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoTemplateTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoTemplateTests.java @@ -343,7 +343,7 @@ public class MongoTemplateTests { } private void testAddingToList(MongoTemplate template) { - PersonWithAList p = new PersonWithAList(); + PersonWithAList p = new PersonWithAList(); p.setFirstName("Sven"); p.setAge(22); template.insert(p); @@ -360,6 +360,19 @@ public class MongoTemplateTests { PersonWithAList p3 = template.findOne(q1, PersonWithAList.class); assertThat(p3, notNullValue()); assertThat(p3.getWishList().size(), is(1)); + + Friend f = new Friend(); + p.setFirstName("Erik"); + p.setAge(21); + + p3.addFriend(f); + template.save(p3); + + PersonWithAList p4 = template.findOne(q1, PersonWithAList.class); + assertThat(p4, notNullValue()); + assertThat(p4.getWishList().size(), is(1)); + assertThat(p4.getFriends().size(), is(1)); + } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/PersonWithAList.java b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/PersonWithAList.java index bbba198fc..bb6f8992d 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/PersonWithAList.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/PersonWithAList.java @@ -28,6 +28,8 @@ public class PersonWithAList { private List wishList = new ArrayList(); + private List friends = new ArrayList(); + public String getId() { return id; } @@ -64,6 +66,18 @@ public class PersonWithAList { this.wishList.add(wish); } + public List getFriends() { + return friends; + } + + public void setFriends(List friends) { + this.friends = friends; + } + + public void addFriend(Friend friend) { + this.friends.add(friend); + } + @Override public String toString() { return "PersonWithAList [id=" + id + ", firstName=" + firstName