moved OSIV examples from spring-data-jpa-3 to spring-data-jpa-4

This commit is contained in:
fejera
2019-11-29 14:00:35 +01:00
parent e1dfff0c68
commit 41b17f7d61
16 changed files with 95 additions and 17 deletions
@@ -0,0 +1,57 @@
package com.baeldung.osiv;
import com.baeldung.Application;
import com.baeldung.model.BasicUser;
import com.baeldung.repository.BasicUserRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import java.util.Arrays;
import java.util.HashSet;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
@ContextConfiguration(classes = Application.class)
@ActiveProfiles("test")
class UserControllerIntegrationTest {
@Autowired
private BasicUserRepository userRepository;
@Autowired
private MockMvc mockMvc;
@BeforeEach
void setUp() {
BasicUser user = new BasicUser();
user.setUsername("root");
user.setPermissions(new HashSet<>(Arrays.asList("PERM_READ", "PERM_WRITE")));
userRepository.save(user);
}
@Test
void givenTheUserExists_WhenOsivIsEnabled_ThenLazyInitWorkEverywhere() throws Exception {
mockMvc.perform(get("/users/root"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.username").value("root"))
.andExpect(jsonPath("$.permissions", containsInAnyOrder("PERM_READ", "PERM_WRITE")));
}
@AfterEach
void flushDb() {
userRepository.deleteAll();
}
}