Added tests with save as insert and as update.

Fixed test with FindAll with Pageable
This commit is contained in:
coach88 2015-08-01 23:49:32 +03:00
parent ece3508dd6
commit 5e7f4ab84f
2 changed files with 22 additions and 5 deletions

View File

@ -41,6 +41,13 @@ public class MongoTemplateIntegrationTest {
mongoTemplate.insert(user);
}
@Test
public void whenSavingNewUser_thenUserIsInserted() {
final User user = new User();
user.setName("Aaron");
mongoTemplate.save(user);
}
@Test
public void givenUserExists_whenSavingExistUser_thenUserIsUpdated() {
User user = new User();

View File

@ -51,6 +51,15 @@ public class UserRepositoryIntegrationTest {
assertThat(mongoOps.findOne(Query.query(Criteria.where("name").is("Jon")), User.class).getName(), is("Jon"));
}
@Test
public void whenSavingNewUser_thenUserIsInserted() {
final User user = new User();
user.setName("Albert");
userRepository.save(user);
assertThat(mongoOps.findOne(Query.query(Criteria.where("name").is("Albert")), User.class).getName(), is("Albert"));
}
@Test
public void givenUserExists_whenSavingExistUser_thenUserIsUpdated() {
User user = new User();
@ -128,11 +137,12 @@ public class UserRepositoryIntegrationTest {
user.setName("Adam");
mongoOps.insert(user);
final Pageable pageableRequest = new PageRequest(0, 2);
final Pageable pageableRequest = new PageRequest(0, 1);
final Page<User> users = userRepository.findAll(pageableRequest);
final Page<User> page = userRepository.findAll(pageableRequest);
List<User> users = page.getContent();
assertThat(users.getTotalPages(), is(1));
assertThat(users.iterator().next().getName(), is("Brendan"));
assertThat(users.size(), is(1));
assertThat(page.getTotalPages(), is(2));
}
}