Skip to content

Commit

Permalink
Merge pull request lmw7414#49 from lmw7414/feature/lmw7414#48
Browse files Browse the repository at this point in the history
원인을 알 수 없는 소스코드 유실 확인하기
  • Loading branch information
lmw7414 authored Aug 14, 2022
2 parents ab8bc6f + 3c59cd8 commit b1b8a71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package com.fastcampus.projectboard.controller;

import com.fastcampus.projectboard.config.SecurityConfig;
import com.fastcampus.projectboard.config.TestSecurityConfig;
import com.fastcampus.projectboard.service.ArticleService;
import com.fastcampus.projectboard.service.PaginationService;
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.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import static org.mockito.BDDMockito.then;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@DisplayName("View 컨트롤러 - 인증")
@AutoConfigureMockMvc
@SpringBootTest
@Import(TestSecurityConfig.class)
@WebMvcTest(Void.class)
public class AuthControllerTest {

private final MockMvc mvc;

@MockBean private ArticleService articleService;
@MockBean private PaginationService paginationService;

public AuthControllerTest(@Autowired MockMvc mvc) {
this.mvc = mvc;
}
Expand All @@ -30,11 +35,14 @@ public AuthControllerTest(@Autowired MockMvc mvc) {
@DisplayName("[view][GET] 로그인 페이지 - 정상 호출")
@Test
public void givenNothing_whenTryingToLogIn_thenReturnsLogInView() throws Exception {
//Given
// Given

//When & Then
// When & Then
mvc.perform(get("/login"))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML));
then(articleService).shouldHaveNoInteractions();
then(paginationService).shouldHaveNoInteractions();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.fastcampus.projectboard.controller;

import com.fastcampus.projectboard.config.TestSecurityConfig;
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.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

//@DisplayName("View 컨트롤러 - 게시글")
@DisplayName("View 루트 컨트롤러")
@Import(TestSecurityConfig.class)
@WebMvcTest(MainController.class)
class MainControllerTest {
Expand All @@ -22,15 +22,16 @@ public MainControllerTest(@Autowired MockMvc mvc) {
this.mvc = mvc;
}

@DisplayName("[view][GET] 루트 페이지 -> 게시글 리스트 (게시판) 페이지 Redirection")
@Test
void givenNothing_whenRequestingRootPage_thenRedirectsToArticlesPage() throws Exception {
//Given
// Given

//When & Then
// When & Then
mvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(view().name("forward:/articles"))
.andExpect(forwardedUrl("/articles"))
.andDo(MockMvcResultHandlers.print());
.andExpect(forwardedUrl("/articles"));
}
}

}

0 comments on commit b1b8a71

Please sign in to comment.