-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from Gongjakso/test/post-pagination
test: 스크랩 관련 Domain, Service 유닛 테스트 코드 작성
- Loading branch information
Showing
15 changed files
with
564 additions
and
45 deletions.
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -20,6 +20,22 @@ public static Member buildMember() { | |
.build(); | ||
} | ||
|
||
public static Member buildMemberAndId(Long id) { | ||
return new Member( | ||
id, | ||
"[email protected]", | ||
"password123", | ||
"공작소", | ||
"010-1234-5678", | ||
"http://example.com", | ||
MemberType.GENERAL.toString(), | ||
LoginType.KAKAO.toString(), | ||
"상태", | ||
"전공", | ||
"직업" | ||
); | ||
} | ||
|
||
public static MemberReq buildMemberReq() { | ||
return MemberReq.builder() | ||
.name("변경 공작소") | ||
|
68 changes: 68 additions & 0 deletions
68
src/test/java/com/gongjakso/server/domain/post/controller/PaginationControllerTest.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,68 @@ | ||
package com.gongjakso.server.domain.post.controller; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
|
||
@AutoConfigureMockMvc | ||
@ExtendWith(MockitoExtension.class) | ||
public class PaginationControllerTest { | ||
/* | ||
MockMvc mockMvc; | ||
private ObjectMapper objectMapper = new ObjectMapper(); | ||
@MockBean | ||
private PostService postService; | ||
@MockBean | ||
private PostRepository postRepository; | ||
@MockBean | ||
private MemberRepository memberRepository; | ||
@MockBean | ||
private ApplyService applyService; | ||
@MockBean | ||
private TokenProvider tokenProvider; | ||
@MockBean | ||
private RedisClient redisClient; | ||
@MockBean | ||
private JwtFilter jwtFilter; | ||
private Member member; | ||
private PrincipalDetails principalDetails; | ||
@BeforeEach | ||
void setUp() { | ||
member = MemberUtilTest.buildMemberAndId(1L); | ||
principalDetails = new PrincipalDetails(member); | ||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( | ||
principalDetails, null, principalDetails.getAuthorities()); | ||
SecurityContextHolder.getContext().setAuthentication(authentication); | ||
} | ||
@Test | ||
@DisplayName("공고 스크랩 저장 및 취소 기능") | ||
void scrapPost() throws Exception { | ||
//given | ||
Post post = PostUtilTest.builderPost(1L, member); | ||
PostScrapRes postScrapRes = PostScrapUtilTest.ScrapPostRes(post.getPostId(), member.getMemberId(), true); | ||
given(postService.scrapPost(any(Member.class), anyLong())).willReturn(postScrapRes); | ||
String resJson = objectMapper.writeValueAsString(postScrapRes); | ||
mockMvc.perform(post("/api/v1/post/{id}", post.getPostId()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.principal((Principal) principalDetails)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().json(resJson)) | ||
.andDo(print()); | ||
verify(postService).scrapPost(any(Member.class), any(Long.class)); | ||
} | ||
*/ | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/com/gongjakso/server/domain/post/domain/ScrapDomainTest.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,55 @@ | ||
package com.gongjakso.server.domain.post.domain; | ||
|
||
|
||
import com.gongjakso.server.domain.member.entity.Member; | ||
import com.gongjakso.server.domain.member.util.MemberUtilTest; | ||
import com.gongjakso.server.domain.post.entity.Post; | ||
import com.gongjakso.server.domain.post.entity.PostScrap; | ||
import com.gongjakso.server.domain.post.util.PostScrapUtilTest; | ||
import com.gongjakso.server.domain.post.util.PostUtilTest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DisplayName("PostScrap 도메인 테스트") | ||
public class ScrapDomainTest{ | ||
|
||
private Post post; | ||
private Member member; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
member = MemberUtilTest.buildMemberAndId(1L); | ||
post = PostUtilTest.builderPost(1L, member); | ||
} | ||
|
||
@Nested | ||
@DisplayName("Builder테스트") | ||
class BuilderTests { | ||
|
||
@Test | ||
@DisplayName("Id없이 빌드 되어야 함") | ||
public void testPostScrapBuilder() { | ||
PostScrap postScrap = PostScrapUtilTest.builderPostScrap(post, post.getMember()); | ||
System.out.println(postScrap.getMember()); | ||
System.out.println(member); | ||
assertThat(postScrap.getPost()).isEqualTo(post); | ||
assertThat(postScrap.getMember()).isEqualTo(member); | ||
assertThat(postScrap.getScrapStatus()).isTrue(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Id와 함께 빌드 되어야 함") | ||
public void testPostScrapBuilderWithId() { | ||
Long postScrapId = 1L; | ||
PostScrap postScrap = PostScrapUtilTest.builderPostScrapWithPostAndMember(postScrapId, post, post.getMember()); | ||
assertThat(postScrap.getPostScrapId()).isEqualTo(postScrapId); | ||
assertThat(postScrap.getPost()).isEqualTo(post); | ||
assertThat(postScrap.getMember()).isEqualTo(member); | ||
assertThat(postScrap.getScrapStatus()).isTrue(); | ||
} | ||
} | ||
} |
Oops, something went wrong.