Skip to content

Commit c67d8a9

Browse files
authored
test: 뉴스 Controller 테스트코드 수정 (#112)
1 parent bdfbe60 commit c67d8a9

File tree

7 files changed

+58
-50
lines changed

7 files changed

+58
-50
lines changed

src/main/java/org/myteam/server/board/controller/BoardController.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,24 @@ public ResponseEntity<ResponseDto<BoardResponse>> getBoard(@PathVariable final L
7474
return ResponseEntity.ok(new ResponseDto<>(SUCCESS.name(), "게시글 조회 성공", response));
7575
}
7676

77-
/**
78-
* 게시글 목록 조회
79-
*/
80-
@GetMapping
81-
public ResponseEntity<ResponseDto<BoardListResponse>> getBoardList(@ModelAttribute @Valid BoardRequest request) {
82-
return ResponseEntity.ok(new ResponseDto<>(SUCCESS.name(), "게시글 목록 조회",
83-
boardReadService.getBoardList(request.toServiceRequest())));
84-
}
85-
86-
/**
87-
* 내가 쓴 게시글 목록 조회 (테스트용입니다)
88-
*/
89-
@GetMapping("/my")
90-
public ResponseEntity<ResponseDto<BoardListResponse>> getMyBoardList(
91-
@ModelAttribute @Valid BoardRequest request,
92-
@AuthenticationPrincipal final CustomUserDetails userDetails) {
93-
94-
return ResponseEntity.ok(new ResponseDto<>(SUCCESS.name(), "내가 쓴 게시글 목록 조회",
95-
boardReadService.getMyBoardList(request.toServiceRequest(), userDetails.getPublicId())));
96-
}
97-
}
77+
// /**
78+
// * 게시글 목록 조회
79+
// */
80+
// @GetMapping
81+
// public ResponseEntity<ResponseDto<BoardListResponse>> getBoardList(@ModelAttribute @Valid BoardRequest request) {
82+
// return ResponseEntity.ok(new ResponseDto<>(SUCCESS.name(), "게시글 목록 조회",
83+
// boardReadService.getBoardList(request.toServiceRequest())));
84+
// }
85+
//
86+
// /**
87+
// * 내가 쓴 게시글 목록 조회 (테스트용입니다)
88+
// */
89+
// @GetMapping("/my")
90+
// public ResponseEntity<ResponseDto<BoardListResponse>> getMyBoardList(
91+
// @ModelAttribute @Valid BoardRequest request,
92+
// @AuthenticationPrincipal final CustomUserDetails userDetails) {
93+
//
94+
// return ResponseEntity.ok(new ResponseDto<>(SUCCESS.name(), "내가 쓴 게시글 목록 조회",
95+
// boardReadService.getMyBoardList(request.toServiceRequest(), userDetails.getPublicId())));
96+
// }
97+
}

src/main/java/org/myteam/server/news/news/dto/controller/request/NewsRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import lombok.Builder;
1010
import lombok.Getter;
1111
import lombok.NoArgsConstructor;
12+
import lombok.Setter;
1213

1314
@Getter
15+
@Setter
1416
@NoArgsConstructor
1517
public class NewsRequest extends PageInfoRequest {
1618

src/main/java/org/myteam/server/news/newsComment/dto/controller/request/NewsCommentRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import lombok.Builder;
88
import lombok.Getter;
99
import lombok.NoArgsConstructor;
10+
import lombok.Setter;
1011

1112
@Getter
13+
@Setter
1214
@NoArgsConstructor
1315
public class NewsCommentRequest extends PageInfoRequest {
1416

src/main/java/org/myteam/server/news/newsReply/dto/controller/request/NewsReplyRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import lombok.Builder;
88
import lombok.Getter;
99
import lombok.NoArgsConstructor;
10+
import lombok.Setter;
1011

1112
@Getter
13+
@Setter
1214
@NoArgsConstructor
1315
public class NewsReplyRequest extends PageInfoRequest {
1416

src/test/java/org/myteam/server/news/news/controller/NewsControllerTest.java

100644100755
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ void findAllTest() throws Exception {
3333
// when // then
3434
mockMvc.perform(
3535
get("/api/news")
36-
.content(objectMapper.writeValueAsString(newsRequest))
37-
.contentType(APPLICATION_JSON)
38-
.accept(APPLICATION_JSON)
36+
.param("content", "테스트")
37+
.param("orderType", newsRequest.getOrderType().name())
38+
.param("category", newsRequest.getCategory().name())
39+
.param("page", String.valueOf(newsRequest.getPage()))
40+
.param("size", String.valueOf(newsRequest.getSize()))
3941
.with(csrf())
4042
)
4143
.andDo(print())
@@ -59,9 +61,10 @@ void findAllWithoutOrderTypeTest() throws Exception {
5961
// when // then
6062
mockMvc.perform(
6163
get("/api/news")
62-
.content(objectMapper.writeValueAsString(newsRequest))
63-
.contentType(APPLICATION_JSON)
64-
.accept(APPLICATION_JSON)
64+
.param("page", String.valueOf(newsRequest.getPage()))
65+
.param("size", String.valueOf(newsRequest.getSize()))
66+
.param("content", newsRequest.getContent())
67+
.param("category", newsRequest.getCategory().name())
6568
.with(csrf())
6669
)
6770
.andDo(print())
@@ -85,9 +88,10 @@ void findAllWithoutCategoryTest() throws Exception {
8588
// when // then
8689
mockMvc.perform(
8790
get("/api/news")
88-
.content(objectMapper.writeValueAsString(newsRequest))
89-
.contentType(APPLICATION_JSON)
90-
.accept(APPLICATION_JSON)
91+
.param("page", String.valueOf(newsRequest.getPage()))
92+
.param("size", String.valueOf(newsRequest.getSize()))
93+
.param("content", newsRequest.getContent())
94+
.param("orderType", newsRequest.getOrderType().name())
9195
.with(csrf())
9296
)
9397
.andDo(print())

src/test/java/org/myteam/server/news/newsComment/controller/NewsCommentControllerTest.java

100644100755
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ void findAllTest() throws Exception {
101101
// when // then
102102
mockMvc.perform(
103103
get("/api/news/comment")
104-
.content(objectMapper.writeValueAsString(newsCommentRequest))
105-
.contentType(APPLICATION_JSON)
106-
.accept(APPLICATION_JSON)
104+
.param("page", String.valueOf(newsCommentRequest.getPage()))
105+
.param("size", String.valueOf(newsCommentRequest.getSize()))
106+
.param("newsId", String.valueOf(newsCommentRequest.getNewsId()))
107107
.with(csrf())
108108
)
109109
.andDo(print())
@@ -125,9 +125,8 @@ void findAllWithoutOrderTypeTest() throws Exception {
125125
// when // then
126126
mockMvc.perform(
127127
get("/api/news/comment")
128-
.content(objectMapper.writeValueAsString(newsRequest))
129-
.contentType(APPLICATION_JSON)
130-
.accept(APPLICATION_JSON)
128+
.param("page", String.valueOf(newsRequest.getPage()))
129+
.param("size", String.valueOf(newsRequest.getSize()))
131130
.with(csrf())
132131
)
133132
.andDo(print())

src/test/java/org/myteam/server/news/newsReply/controller/NewsReplyControllerTest.java

100644100755
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class NewsReplyControllerTest extends ControllerTestSupport {
2222
@WithMockUser
2323
void saveTest() throws Exception {
2424
// given
25-
NewsReplySaveRequest newsCommentSaveRequest = NewsReplySaveRequest.builder()
25+
NewsReplySaveRequest newsReplySaveRequest = NewsReplySaveRequest.builder()
2626
.newsCommentId(1L)
2727
.comment("대댓글 테스트")
2828
.build();
2929

3030
// when // then
3131
mockMvc.perform(
3232
post("/api/news/reply")
33-
.content(objectMapper.writeValueAsString(newsCommentSaveRequest))
33+
.content(objectMapper.writeValueAsString(newsReplySaveRequest))
3434
.contentType(APPLICATION_JSON)
3535
.accept(APPLICATION_JSON)
3636
.with(csrf())
@@ -46,14 +46,14 @@ void saveTest() throws Exception {
4646
@WithMockUser
4747
void saveWithoutNewsIdTest() throws Exception {
4848
// given
49-
NewsReplySaveRequest newsCommentSaveRequest = NewsReplySaveRequest.builder()
49+
NewsReplySaveRequest newsReplySaveRequest = NewsReplySaveRequest.builder()
5050
.comment("대댓글 테스트")
5151
.build();
5252

5353
// when // then
5454
mockMvc.perform(
5555
post("/api/news/reply")
56-
.content(objectMapper.writeValueAsString(newsCommentSaveRequest))
56+
.content(objectMapper.writeValueAsString(newsReplySaveRequest))
5757
.contentType(APPLICATION_JSON)
5858
.accept(APPLICATION_JSON)
5959
.with(csrf())
@@ -69,14 +69,14 @@ void saveWithoutNewsIdTest() throws Exception {
6969
@WithMockUser
7070
void saveWithoutCommentTest() throws Exception {
7171
// given
72-
NewsReplySaveRequest newsCommentSaveRequest = NewsReplySaveRequest.builder()
72+
NewsReplySaveRequest newsReplySaveRequest = NewsReplySaveRequest.builder()
7373
.newsCommentId(1L)
7474
.build();
7575

7676
// when // then
7777
mockMvc.perform(
7878
post("/api/news/reply")
79-
.content(objectMapper.writeValueAsString(newsCommentSaveRequest))
79+
.content(objectMapper.writeValueAsString(newsReplySaveRequest))
8080
.contentType(APPLICATION_JSON)
8181
.accept(APPLICATION_JSON)
8282
.with(csrf())
@@ -92,7 +92,7 @@ void saveWithoutCommentTest() throws Exception {
9292
@WithMockUser
9393
void findAllTest() throws Exception {
9494
// given
95-
NewsReplyRequest newsCommentRequest = NewsReplyRequest.builder()
95+
NewsReplyRequest newsReplyRequest = NewsReplyRequest.builder()
9696
.page(1)
9797
.size(10)
9898
.newsCommentId(1L)
@@ -101,9 +101,9 @@ void findAllTest() throws Exception {
101101
// when // then
102102
mockMvc.perform(
103103
get("/api/news/reply")
104-
.content(objectMapper.writeValueAsString(newsCommentRequest))
105-
.contentType(APPLICATION_JSON)
106-
.accept(APPLICATION_JSON)
104+
.param("page", String.valueOf(newsReplyRequest.getPage()))
105+
.param("size", String.valueOf(newsReplyRequest.getSize()))
106+
.param("newsCommentId", String.valueOf(newsReplyRequest.getNewsCommentId()))
107107
.with(csrf())
108108
)
109109
.andDo(print())
@@ -112,7 +112,7 @@ void findAllTest() throws Exception {
112112
.andExpect(jsonPath("$.msg").value("뉴스 대댓글 조회 성공"));
113113
}
114114

115-
@DisplayName("뉴스목록을 조회시 뉴스ID는 필수이다.")
115+
@DisplayName("대댓글 조회시 뉴스 대댓글 ID는 필수이다.")
116116
@Test
117117
@WithMockUser
118118
void findAllWithoutOrderTypeTest() throws Exception {
@@ -125,9 +125,8 @@ void findAllWithoutOrderTypeTest() throws Exception {
125125
// when // then
126126
mockMvc.perform(
127127
get("/api/news/reply")
128-
.content(objectMapper.writeValueAsString(newsRequest))
129-
.contentType(APPLICATION_JSON)
130-
.accept(APPLICATION_JSON)
128+
.param("page", String.valueOf(newsRequest.getPage()))
129+
.param("size", String.valueOf(newsRequest.getSize()))
131130
.with(csrf())
132131
)
133132
.andDo(print())

0 commit comments

Comments
 (0)