@Test public void testFindOneWithSort() { PersonWithAList p = new PersonWithAList(); p.setFirstName("Sven"); p.setAge(22); template.insert(p); PersonWithAList p2 = new PersonWithAList(); p2.setFirstName("Erik"); p2.setAge(21); template.insert(p2); PersonWithAList p3 = new PersonWithAList(); p3.setFirstName("Mark"); p3.setAge(40); template.insert(p3); // test query with a sort Query q2 = new Query(Criteria.where("age").gt(10)); q2.sort().on("age", Order.DESCENDING); PersonWithAList p5 = template.findOne(q2, PersonWithAList.class); assertThat(p5.getFirstName(), is("Mark")); }
@Test public void testAddingToList() { PersonWithAList p = new PersonWithAList(); p.setFirstName("Sven"); p.setAge(22); template.insert(p); Query q1 = new Query(Criteria.where("id").is(p.getId())); PersonWithAList p2 = template.findOne(q1, PersonWithAList.class); assertThat(p2, notNullValue()); assertThat(p2.getWishList().size(), is(0)); p2.addToWishList("please work!"); template.save(p2); 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)); }