improvement BAEL-2897 (#6795)
* added example code for BAEL-2083 * updated example code for BAEL-2083 * added example code for BAEL-2849 * updated the example code with data.sql * improvement BAEL-2897 * updated the persistence module * updated readme
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.baeldung;
|
||||
|
||||
import com.baeldung.h2db.springboot.SpringBootH2Application;
|
||||
import com.baeldung.h2db.springboot.daos.UserRepository;
|
||||
import com.baeldung.h2db.springboot.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 java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = SpringBootH2Application.class)
|
||||
public class SpringBootH2IntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Test
|
||||
public void contextLoads() { }
|
||||
|
||||
@Test
|
||||
public void givenUserProfile_whenAddUser_thenCreateNewUser() {
|
||||
User user = new User();
|
||||
user.setFirstName("John");
|
||||
user.setLastName("Doe");
|
||||
userRepository.save(user);
|
||||
List<User> users = (List<User>) userRepository.findAll();
|
||||
assertFalse(users.isEmpty());
|
||||
|
||||
String firstName = "Aliko";
|
||||
String lastName = "Dangote";
|
||||
User user1 = userRepository.findById(users.get(0).getId()).get();
|
||||
user1.setLastName(lastName);
|
||||
user1.setFirstName(firstName);
|
||||
userRepository.save(user1);
|
||||
|
||||
user = userRepository.findById(user.getId()).get();
|
||||
assertEquals(user.getFirstName(), firstName);
|
||||
assertEquals(user.getLastName(), lastName);
|
||||
|
||||
userRepository.deleteById(user.getId());
|
||||
assertTrue( ((List<User>) userRepository.findAll()).isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
@WebAppConfiguration
|
||||
public class SpringContextIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user