Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#16 - 로그인 컨트롤러 테스트 + 시큐리티 설정을 컨트롤러 테스트에 반영
스프링 시큐리티가 자동 생성해준 `/login` 컨트롤러 테스트, 그리고 시큐리티 설정을 부를 수 있도록 `@import` 추가
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/java/com/example/boardproject/controller/AuthControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.example.boardproject.controller; | ||
|
||
import com.example.boardproject.config.SecurityConfig; | ||
import org.junit.jupiter.api.DisplayName; | ||
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.http.MediaType; | ||
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.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@DisplayName("View 컨트롤러 - 인증") | ||
@Import(SecurityConfig.class) | ||
@WebMvcTest | ||
public class AuthControllerTest { | ||
|
||
private final MockMvc mvc; | ||
|
||
// 슬라이스 테스트에서는 생성자를 통한 주입이여도 @Autowired 해줘야함 | ||
// 즉, spring 이 생성자 주입할 때도 저절로 해주는 것 | ||
public AuthControllerTest(@Autowired MockMvc mvc) { | ||
this.mvc = mvc; | ||
} | ||
|
||
@DisplayName("[view][GET] 로그인 페이지 - 정상 호출") | ||
@Test | ||
void givenNothing_whenTryingToLogin_thenReturnsLoginView() throws Exception { | ||
// Given | ||
|
||
// When & Then | ||
mvc.perform(get("/login")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)); | ||
} | ||
|
||
} |