added additional list test
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ public class PersonWithAList {
|
||||
|
||||
private List<String> wishList = new ArrayList<String>();
|
||||
|
||||
private List<Friend> friends = new ArrayList<Friend>();
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -64,6 +66,18 @@ public class PersonWithAList {
|
||||
this.wishList.add(wish);
|
||||
}
|
||||
|
||||
public List<Friend> getFriends() {
|
||||
return friends;
|
||||
}
|
||||
|
||||
public void setFriends(List<Friend> friends) {
|
||||
this.friends = friends;
|
||||
}
|
||||
|
||||
public void addFriend(Friend friend) {
|
||||
this.friends.add(friend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PersonWithAList [id=" + id + ", firstName=" + firstName
|
||||
|
||||
Reference in New Issue
Block a user