Files
spring-boot-rest/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java
Seun Matt 7719b2e30a example code for BAEL-1961 (#5781)
* 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
2018-11-26 08:20:11 -08:00

37 lines
912 B
Java

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.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
@RunWith(SpringRunner.class)
public class MongoDbAutoGeneratedFieldIntegrationTest {
@Autowired
private 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);
}
}