From 377e4f41fd685f41d1f7d78ab12a42bb97078e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A3=BC=EC=B0=AC?= <127003137+juchan204@users.noreply.github.com> Date: Tue, 3 Dec 2024 21:21:03 +0900 Subject: [PATCH] =?UTF-8?q?MATE-83=20:=20[FEAT]=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20@MockBean=20jwtUtil=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#73)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MATE-83 : [FEAT] 테스트 코드 @MockBean 추가 --- .../mate/domain/auth/controller/AuthControllerTest.java | 4 ++++ .../domain/auth/integration/NaverAuthIntegrationTest.java | 5 +++++ .../mate/domain/goods/integration/GoodsIntegrationTest.java | 5 +++++ .../domain/goodsChat/controller/GoodsChatControllerTest.java | 4 ++++ .../goodsChat/integration/GoodsChatIntegrationTest.java | 5 +++++ .../mate/domain/match/integration/MatchIntegrationTest.java | 5 +++++ .../domain/match/integration/TeamRecordIntegrationTest.java | 5 +++++ .../mate/domain/mate/controller/MateControllerTest.java | 4 ++++ .../mate/domain/mate/integration/MateIntegrationTest.java | 5 +++++ .../domain/mate/integration/MateStatusIntegrationTest.java | 5 +++++ .../domain/member/integration/FollowIntegrationTest.java | 5 +++++ .../domain/member/integration/MemberIntegrationTest.java | 5 +++++ .../domain/member/integration/ProfileIntegrationTest.java | 5 +++++ 13 files changed, 62 insertions(+) diff --git a/src/test/java/com/example/mate/domain/auth/controller/AuthControllerTest.java b/src/test/java/com/example/mate/domain/auth/controller/AuthControllerTest.java index d0dbf4c3..86ddd369 100644 --- a/src/test/java/com/example/mate/domain/auth/controller/AuthControllerTest.java +++ b/src/test/java/com/example/mate/domain/auth/controller/AuthControllerTest.java @@ -6,6 +6,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.auth.dto.response.LoginResponse; import com.example.mate.domain.auth.dto.response.NaverProfileResponse; import com.example.mate.domain.auth.service.NaverAuthService; @@ -30,6 +31,9 @@ public class AuthControllerTest { @MockBean private NaverAuthService naverAuthService; + @MockBean + private JwtUtil jwtUtil; + @Test @DisplayName("네이버 소셜 로그인 요청 시, 네이버 인증 페이지로 리다이렉트 성공") void connectNaver_Success() throws Exception { diff --git a/src/test/java/com/example/mate/domain/auth/integration/NaverAuthIntegrationTest.java b/src/test/java/com/example/mate/domain/auth/integration/NaverAuthIntegrationTest.java index 1a6c3880..aec259e4 100644 --- a/src/test/java/com/example/mate/domain/auth/integration/NaverAuthIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/auth/integration/NaverAuthIntegrationTest.java @@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.auth.config.OAuthConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -16,6 +17,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.test.web.client.MockRestServiceServer; @@ -37,6 +39,9 @@ public class NaverAuthIntegrationTest { @Autowired private RestTemplate restTemplate; + @MockBean + private JwtUtil jwtUtil; + @BeforeEach void setUp() { // Mock 서버 설정: 네이버 토큰 발급 API diff --git a/src/test/java/com/example/mate/domain/goods/integration/GoodsIntegrationTest.java b/src/test/java/com/example/mate/domain/goods/integration/GoodsIntegrationTest.java index a91e28db..846b6fef 100644 --- a/src/test/java/com/example/mate/domain/goods/integration/GoodsIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/goods/integration/GoodsIntegrationTest.java @@ -9,6 +9,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.mate.common.response.ApiResponse; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.constant.TeamInfo; @@ -39,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockMultipartFile; @@ -61,6 +63,9 @@ public class GoodsIntegrationTest { private Member member; private GoodsPost goodsPost; + @MockBean + private JwtUtil jwtUtil; + @BeforeEach void setUp() { member = createMember(); diff --git a/src/test/java/com/example/mate/domain/goodsChat/controller/GoodsChatControllerTest.java b/src/test/java/com/example/mate/domain/goodsChat/controller/GoodsChatControllerTest.java index 855d9f48..c87317d9 100644 --- a/src/test/java/com/example/mate/domain/goodsChat/controller/GoodsChatControllerTest.java +++ b/src/test/java/com/example/mate/domain/goodsChat/controller/GoodsChatControllerTest.java @@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.mate.common.response.PageResponse; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.goodsChat.dto.response.GoodsChatMsgResponse; import com.example.mate.domain.goodsChat.dto.response.GoodsChatRoomResponse; import com.example.mate.domain.goodsChat.service.GoodsChatService; @@ -36,6 +37,9 @@ class GoodsChatControllerTest { @MockBean private GoodsChatService goodsChatService; + @MockBean + private JwtUtil jwtUtil; + @Test @DisplayName("굿즈거래 채팅방 생성 성공 - 기존 채팅방이 있을 경우 해당 채팅방을 반환한다.") void returnExistingChatRoom() throws Exception { diff --git a/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java b/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java index 4bbfe150..e1aef9a3 100644 --- a/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java @@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.mate.common.response.ApiResponse; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.goods.dto.LocationInfo; import com.example.mate.domain.goods.entity.Category; @@ -35,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.mock.web.MockHttpServletResponse; @@ -53,6 +55,9 @@ public class GoodsChatIntegrationTest { @Autowired private GoodsChatMessageRepository messageRepository; @Autowired private ObjectMapper objectMapper; + @MockBean + private JwtUtil jwtUtil; + private Member seller; private Member buyer; private GoodsPost goodsPost; diff --git a/src/test/java/com/example/mate/domain/match/integration/MatchIntegrationTest.java b/src/test/java/com/example/mate/domain/match/integration/MatchIntegrationTest.java index 10f83bd8..e134fcae 100644 --- a/src/test/java/com/example/mate/domain/match/integration/MatchIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/match/integration/MatchIntegrationTest.java @@ -7,6 +7,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.mate.common.response.ApiResponse; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.StadiumInfo; import com.example.mate.domain.constant.TeamInfo; import com.example.mate.domain.match.dto.response.WeeklyMatchesResponse; @@ -25,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -64,6 +66,9 @@ class MatchIntegrationTest { @Autowired private ObjectMapper objectMapper; + @MockBean + private JwtUtil jwtUtil; + @BeforeEach void setUp() { this.mockMvc = MockMvcBuilders.webAppContextSetup(ctx) diff --git a/src/test/java/com/example/mate/domain/match/integration/TeamRecordIntegrationTest.java b/src/test/java/com/example/mate/domain/match/integration/TeamRecordIntegrationTest.java index b04f4251..a8dba765 100644 --- a/src/test/java/com/example/mate/domain/match/integration/TeamRecordIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/match/integration/TeamRecordIntegrationTest.java @@ -1,5 +1,6 @@ package com.example.mate.domain.match.integration; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.TeamInfo; import com.example.mate.domain.match.entity.TeamRecord; import com.example.mate.domain.match.repository.TeamRecordRepository; @@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; @@ -34,6 +36,9 @@ void setUp() { teamRecordRepository.deleteAll(); } + @MockBean + private JwtUtil jwtUtil; + @Nested @DisplayName("팀 순위 조회") class GetTeamRankings { diff --git a/src/test/java/com/example/mate/domain/mate/controller/MateControllerTest.java b/src/test/java/com/example/mate/domain/mate/controller/MateControllerTest.java index 27abe549..1b35612c 100644 --- a/src/test/java/com/example/mate/domain/mate/controller/MateControllerTest.java +++ b/src/test/java/com/example/mate/domain/mate/controller/MateControllerTest.java @@ -20,6 +20,7 @@ import com.example.mate.common.error.CustomException; import com.example.mate.common.error.ErrorCode; import com.example.mate.common.response.PageResponse; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.mate.dto.request.MatePostCreateRequest; import com.example.mate.domain.mate.dto.request.MatePostUpdateRequest; @@ -62,6 +63,9 @@ class MateControllerTest { @MockBean private MateService mateService; + @MockBean + private JwtUtil jwtUtil; + private MatePostSummaryResponse createMatePostSummaryResponse() { return MatePostSummaryResponse.builder() .imageUrl("test-image.jpg") diff --git a/src/test/java/com/example/mate/domain/mate/integration/MateIntegrationTest.java b/src/test/java/com/example/mate/domain/mate/integration/MateIntegrationTest.java index b15c0cd4..5cb219ff 100644 --- a/src/test/java/com/example/mate/domain/mate/integration/MateIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/mate/integration/MateIntegrationTest.java @@ -14,6 +14,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.match.entity.Match; import com.example.mate.domain.match.repository.MatchRepository; @@ -36,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.PageRequest; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; @@ -63,6 +65,9 @@ public class MateIntegrationTest { @Autowired private MateRepository mateRepository; + @MockBean + private JwtUtil jwtUtil; + // 테스트에서 공통으로 사용할 객체들 private Member testMember; private Match futureMatch; diff --git a/src/test/java/com/example/mate/domain/mate/integration/MateStatusIntegrationTest.java b/src/test/java/com/example/mate/domain/mate/integration/MateStatusIntegrationTest.java index daa80e24..a62c9faf 100644 --- a/src/test/java/com/example/mate/domain/mate/integration/MateStatusIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/mate/integration/MateStatusIntegrationTest.java @@ -17,6 +17,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.match.entity.Match; import com.example.mate.domain.match.repository.MatchRepository; @@ -41,6 +42,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.transaction.annotation.Transactional; @@ -75,6 +77,9 @@ public class MateStatusIntegrationTest { private MatePost completedPost; private MatePost closedPost; + @MockBean + private JwtUtil jwtUtil; + @BeforeEach void setUp() { // 기존 데이터 정리 diff --git a/src/test/java/com/example/mate/domain/member/integration/FollowIntegrationTest.java b/src/test/java/com/example/mate/domain/member/integration/FollowIntegrationTest.java index 3e7429aa..c761bf92 100644 --- a/src/test/java/com/example/mate/domain/member/integration/FollowIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/member/integration/FollowIntegrationTest.java @@ -9,6 +9,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.mate.common.error.ErrorCode; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.member.entity.Follow; import com.example.mate.domain.member.entity.Member; @@ -23,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; @@ -40,6 +42,9 @@ public class FollowIntegrationTest { @Autowired private MemberRepository memberRepository; + @MockBean + private JwtUtil jwtUtil; + private Member member1; private Member member2; private Follow follow; diff --git a/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java b/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java index 4faeaf41..e8bfd6ec 100644 --- a/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java @@ -10,6 +10,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.goods.dto.LocationInfo; @@ -49,6 +50,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; @@ -95,6 +97,9 @@ class MemberIntegrationTest { @Autowired private EntityManager entityManager; + @MockBean + private JwtUtil jwtUtil; + private Member member; private Member member2; private GoodsPost goodsPost; diff --git a/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java b/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java index 35ac2818..1a0bf618 100644 --- a/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java @@ -6,6 +6,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.example.mate.common.security.util.JwtUtil; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.goods.dto.LocationInfo; @@ -42,6 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.test.web.servlet.MockMvc; @@ -84,6 +86,9 @@ public class ProfileIntegrationTest { @Autowired private ObjectMapper objectMapper; + @MockBean + private JwtUtil jwtUtil; + private Member member1; private Member member2; private Member member3;