Skip to content

Commit

Permalink
MATE-83 : [FEAT] 테스트 코드 @MockBean jwtUtil 추가 (#73)
Browse files Browse the repository at this point in the history
MATE-83 : [FEAT] 테스트 코드 @MockBean 추가
  • Loading branch information
juchan204 authored Dec 3, 2024
1 parent e6979a7 commit 377e4f4
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,9 @@ public class AuthControllerTest {
@MockBean
private NaverAuthService naverAuthService;

@MockBean
private JwtUtil jwtUtil;

@Test
@DisplayName("네이버 소셜 로그인 요청 시, 네이버 인증 페이지로 리다이렉트 성공")
void connectNaver_Success() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -37,6 +39,9 @@ public class NaverAuthIntegrationTest {
@Autowired
private RestTemplate restTemplate;

@MockBean
private JwtUtil jwtUtil;

@BeforeEach
void setUp() {
// Mock 서버 설정: 네이버 토큰 발급 API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -61,6 +63,9 @@ public class GoodsIntegrationTest {
private Member member;
private GoodsPost goodsPost;

@MockBean
private JwtUtil jwtUtil;

@BeforeEach
void setUp() {
member = createMember();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,6 +37,9 @@ class GoodsChatControllerTest {
@MockBean
private GoodsChatService goodsChatService;

@MockBean
private JwtUtil jwtUtil;

@Test
@DisplayName("굿즈거래 채팅방 생성 성공 - 기존 채팅방이 있을 경우 해당 채팅방을 반환한다.")
void returnExistingChatRoom() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -64,6 +66,9 @@ class MatchIntegrationTest {
@Autowired
private ObjectMapper objectMapper;

@MockBean
private JwtUtil jwtUtil;

@BeforeEach
void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(ctx)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -34,6 +36,9 @@ void setUp() {
teamRecordRepository.deleteAll();
}

@MockBean
private JwtUtil jwtUtil;

@Nested
@DisplayName("팀 순위 조회")
class GetTeamRankings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +63,9 @@ class MateControllerTest {
@MockBean
private MateService mateService;

@MockBean
private JwtUtil jwtUtil;

private MatePostSummaryResponse createMatePostSummaryResponse() {
return MatePostSummaryResponse.builder()
.imageUrl("test-image.jpg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -63,6 +65,9 @@ public class MateIntegrationTest {
@Autowired
private MateRepository mateRepository;

@MockBean
private JwtUtil jwtUtil;

// 테스트에서 공통으로 사용할 객체들
private Member testMember;
private Match futureMatch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -75,6 +77,9 @@ public class MateStatusIntegrationTest {
private MatePost completedPost;
private MatePost closedPost;

@MockBean
private JwtUtil jwtUtil;

@BeforeEach
void setUp() {
// 기존 데이터 정리
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -40,6 +42,9 @@ public class FollowIntegrationTest {
@Autowired
private MemberRepository memberRepository;

@MockBean
private JwtUtil jwtUtil;

private Member member1;
private Member member2;
private Follow follow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -95,6 +97,9 @@ class MemberIntegrationTest {
@Autowired
private EntityManager entityManager;

@MockBean
private JwtUtil jwtUtil;

private Member member;
private Member member2;
private GoodsPost goodsPost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +86,9 @@ public class ProfileIntegrationTest {
@Autowired
private ObjectMapper objectMapper;

@MockBean
private JwtUtil jwtUtil;

private Member member1;
private Member member2;
private Member member3;
Expand Down

0 comments on commit 377e4f4

Please sign in to comment.