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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user