#16 board : main controller, test
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.example.board.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class MainController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String root() {
|
||||
return "forward:/articles";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.example.board.controller;
|
||||
|
||||
import com.example.board.config.SecurityConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
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.*;
|
||||
|
||||
@Import(SecurityConfig.class)
|
||||
@WebMvcTest(MainController.class)
|
||||
class MainControllerTest {
|
||||
|
||||
private final MockMvc mockMvc;
|
||||
|
||||
public MainControllerTest(@Autowired MockMvc mockMvc) {
|
||||
this.mockMvc = mockMvc;
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenNothing_whenRequestingRootPage_thenRedirectsToArticlesPage() throws Exception {
|
||||
// given
|
||||
|
||||
// when & then
|
||||
mockMvc.perform(get("/"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(view().name("forward:/articles"))
|
||||
.andExpect(forwardedUrl("/articles"))
|
||||
.andDo(print())
|
||||
;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user