From 16aef1a7d7a5e7b458dfc0b7d8abf5b3d2ef4bab Mon Sep 17 00:00:00 2001 From: William Harrington Date: Wed, 12 Feb 2025 20:18:43 -0600 Subject: Rename test class and remove public modifiers. --- .../controllers/BuilddbPkgControllerTest.java | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/test/java/org/berzerkula/builddb/controllers/BuilddbPkgControllerTest.java (limited to 'src/test/java/org/berzerkula/builddb/controllers/BuilddbPkgControllerTest.java') diff --git a/src/test/java/org/berzerkula/builddb/controllers/BuilddbPkgControllerTest.java b/src/test/java/org/berzerkula/builddb/controllers/BuilddbPkgControllerTest.java new file mode 100644 index 0000000..6c0ad46 --- /dev/null +++ b/src/test/java/org/berzerkula/builddb/controllers/BuilddbPkgControllerTest.java @@ -0,0 +1,89 @@ +package org.berzerkula.builddb.controllers; + +import org.berzerkula.builddb.config.SecurityConfig; +import org.berzerkula.builddb.models.Pkg; +import org.berzerkula.builddb.repositories.TestH2PkgRepository; +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.context.annotation.Import; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.web.servlet.MockMvc; + +import java.util.List; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; + +@Import(SecurityConfig.class) +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) + +class BuilddbPkgControllerTest { + + @Autowired + private TestH2PkgRepository pkgRepository; + + @Autowired + private MockMvc mockMvc; + + @Test + @WithMockUser(roles="client") + void shouldReturnEmptyPackageListView() throws Exception { + this.mockMvc.perform(get("/pkgs")) + .andExpect(status().isOk()) + .andExpect(view().name("pkgs/index")) + .andDo(print()); + } + + @Test + @WithMockUser(roles="client") + void shouldReturnAddPackageView() throws Exception { + + this.mockMvc.perform(get("/pkgs/add")) + .andExpect(status().isOk()) + .andExpect(view().name("pkgs/add")) + .andDo(print()); + } + + @Test + @WithMockUser(roles="client") + void shouldReturnEditPackageView() throws Exception { + + Pkg pkg = new Pkg(); + pkg.setSequence(1); + pkg.setName("test"); + pkg.setVersion("1.2.3"); + pkgRepository.save(pkg); + List pkgs = pkgRepository.findAll(); + pkg = pkgs.get(0); + Integer id = pkg.getId(); + + this.mockMvc.perform(get("/pkgs/edit?id=" + id)) + .andExpect(status().isOk()) + .andExpect(view().name("pkgs/edit")) + .andDo(print()); + } + + @Test + @WithMockUser(roles="client") + void shouldGetPopupWhenDeletePackage() throws Exception { + + Pkg pkg = new Pkg(); + pkg.setSequence(1); + pkg.setName("test"); + pkg.setVersion("1.2.3"); + pkgRepository.save(pkg); + List pkgs = pkgRepository.findAll(); + pkg = pkgs.get(0); + Integer id = pkg.getId(); + + this.mockMvc.perform(get("/pkgs/delete?id=" + id)) + .andExpect(status().is3xxRedirection()) + .andExpect(view().name("redirect:/pkgs/")) + .andDo(print()); + } +} -- cgit v1.2.3-54-g00ecf