Skip to content

Commit

Permalink
[J2KB-3rd-Season#14]test: 게시글 삭제 테스트 케이스 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
enjay27 committed Jun 11, 2021
1 parent 1867da2 commit bf9639c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/test/java/com/devin/dev/mvc/PostControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

Expand All @@ -15,6 +16,7 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
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.status;
Expand Down Expand Up @@ -43,7 +45,14 @@ void requestPostSucceeded() throws Exception {
@WithMockUser
void requestPostFailed() throws Exception {
mvc.perform(get("/postlist/0"))
.andExpect(status().is4xxClientError())
.andDo(print());
}

@Test
@WithMockUser
void requestDeleteSucceeded() throws Exception {
List<Post> posts = postRepository.findByTitle("title_2");
mvc.perform(delete("/postlist/" + posts.get(0).getId()))
.andDo(print());
}
}
18 changes: 17 additions & 1 deletion src/test/java/com/devin/dev/service/PostServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ void getPostSucceeded() {

ReplyOrderCondition replyOrderCondition = new ReplyOrderCondition();
replyOrderCondition.setLatestDate(true);
// replyOrderCondition.setLikeCount(true);

DefaultResponse<PostDetailsDto> response = postService.getPost(post1.getId(), replyOrderCondition);
assertThat(response.getStatusCode()).isEqualTo(StatusCode.OK);
Expand All @@ -137,4 +136,21 @@ void getPostSucceeded() {
assertThat(postDto.getPublisher_name()).isEqualTo("D");
assertThat(postDto.getPost_images()).containsExactly("p1","p2","p3");
}

@Test
void deleteSucceeded() {
Post post1 = new Post(postUser, "PostC1", "ContentC1");
List<PostTag> postTags = PostTag.createPostTags(List.of(subject1, subject2));
post1.setPostTags(postTags);
List<PostImage> postImages = PostImage.createPostImages(List.of("p1", "p2", "p3"));
post1.setPostImages(postImages);
postTags.forEach(em::persist);
postImages.forEach(em::persist);
em.persist(post1);

postService.deletePost(post1.getId());

Post post = em.find(Post.class, post1.getId());
assertThat(post).isNull();
}
}

0 comments on commit bf9639c

Please sign in to comment.