#16 board : view - endpoint test

This commit is contained in:
haerong22
2022-08-09 00:32:01 +09:00
parent 50ef4dd8ec
commit 7ac0d164f5
3 changed files with 93 additions and 0 deletions

View File

@@ -26,6 +26,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.data:spring-data-rest-hal-explorer'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'
compileOnly 'org.projectlombok:lombok'

View File

@@ -0,0 +1,9 @@
package com.example.board.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/articles")
@Controller
public class ArticleController {
}

View File

@@ -0,0 +1,82 @@
package com.example.board.controller;
import org.junit.jupiter.api.Disabled;
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.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.*;
@DisplayName("View 컨트롤러 - 게시글")
@WebMvcTest(ArticleController.class)
class ArticleControllerTest {
private final MockMvc mockMvc;
public ArticleControllerTest(@Autowired MockMvc mockMvc) {
this.mockMvc = mockMvc;
}
@Disabled("구현 중")
@DisplayName("[view][GET] 게시글 리스트(게시판) 페이지 - 정상 호출")
@Test
public void givenNothing_whenRequestingArticlesView_thenReturnsArticlesView() throws Exception {
// given
// when & then
mockMvc.perform(get("/articles"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_HTML))
.andExpect(view().name("articles/index"))
.andExpect(model().attributeExists("articles"))
;
}
@Disabled("구현 중")
@DisplayName("[view][GET] 게시글 상세 페이지 - 정상 호출")
@Test
public void givenNothing_whenRequestingArticleView_thenReturnsArticleView() throws Exception {
// given
// when & then
mockMvc.perform(get("/articles/1"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_HTML))
.andExpect(view().name("articles/detail"))
.andExpect(model().attributeExists("article"))
.andExpect(model().attributeExists("articleComments"))
;
}
@Disabled("구현 중")
@DisplayName("[view][GET] 게시글 검색 전용 페이지 - 정상 호출")
@Test
public void givenNothing_whenRequestingArticleSearchView_thenReturnsArticleSearchView() throws Exception {
// given
// when & then
mockMvc.perform(get("/articles/search"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_HTML))
.andExpect(view().name("articles/search"))
;
}
@Disabled("구현 중")
@DisplayName("[view][GET] 게시글 해시태그 검색 페이지 - 정상 호출")
@Test
public void givenNothing_whenRequestingArticleHashtagSearchView_thenReturnsArticleHashtagSearchView() throws Exception {
// given
// when & then
mockMvc.perform(get("/articles/search-hashtag"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_HTML))
.andExpect(view().name("articles/search-hashtag"))
;
}
}