moved OSIV examples from spring-data-jpa-3 to spring-data-jpa-4
This commit is contained in:
+57
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user