refactor the spring boot persistence mongodb module (#5829)

* added example code for BAEL-2366

* moved example code for BAEL-2366

* example code for BAEL-1961

* moved example code into integration test

* updated the test assertions

* refactor the spring boot persistence mongodb module

* remove redundant example code

* declared the spring boot persistence module in the root pom

* fixed issue with non-imported file
This commit is contained in:
Seun Matt
2018-12-03 17:03:41 +01:00
committed by maibin
parent 6b29e94a40
commit dcf28dd166
13 changed files with 137 additions and 22 deletions

View File

@@ -0,0 +1,37 @@
package com.baeldung.mongodb;
import com.baeldung.mongodb.daos.UserRepository;
import com.baeldung.mongodb.models.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest
public class MongoDbAutoGeneratedFieldIntegrationTest {
@Autowired
UserRepository userRepository;
@Test
public void contextLoads() {}
@Test
public void givenUserObject_whenSave_thenCreateNewUser() {
User user = new User();
user.setFirstName("John");
user.setLastName("Doe");
user.setEmail("john.doe@example.com");
userRepository.save(user);
assertThat(userRepository.findAll().size()).isGreaterThan(0);
}
}