Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: 테스트 컨텍스트를 개선한다. #148

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend-config
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;

import com.thirdparty.ticketing.domain.member.dto.request.LoginRequest;
import com.thirdparty.ticketing.domain.member.dto.response.LoginResponse;
import com.thirdparty.ticketing.domain.member.service.AuthService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(controllers = AuthController.class)
class AuthControllerTest extends BaseControllerTest {

@MockBean private AuthService authService;

@Test
@DisplayName("로그인 API 호출 시")
void login() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,16 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.member.dto.request.MemberCreationRequest;
import com.thirdparty.ticketing.domain.member.dto.response.CreateMemberResponse;
import com.thirdparty.ticketing.domain.member.service.MemberService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(controllers = MemberController.class)
class MemberControllerTest extends BaseControllerTest {

@Autowired private ObjectMapper objectMapper;

@MockBean private MemberService memberService;

@Test
@DisplayName("회원 생성 API 호출")
void createMember() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.thirdparty.ticketing.domain.performance.dto.request.PerformanceCreationRequest;
import com.thirdparty.ticketing.domain.performance.service.AdminPerformanceService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(AdminPerformanceController.class)
class AdminPerformanceControllerTest extends BaseControllerTest {

@MockBean private AdminPerformanceService adminPerformanceService;

@Test
@DisplayName("POST /api/performances")
void createPerformance() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.thirdparty.ticketing.domain.performance.controller;

import static org.mockito.BDDMockito.*;
import static org.mockito.BDDMockito.given;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
Expand All @@ -11,21 +11,15 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;

import com.thirdparty.ticketing.domain.ItemResult;
import com.thirdparty.ticketing.domain.performance.dto.PerformanceElement;
import com.thirdparty.ticketing.domain.performance.service.UserPerformanceService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(UserPerformanceController.class)
class UserPerformanceControllerTest extends BaseControllerTest {

@MockBean private UserPerformanceService userPerformanceService;

@Test
@DisplayName("GET /api/performances")
void getPerformances() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;
Expand All @@ -24,14 +22,10 @@
import com.thirdparty.ticketing.domain.seat.dto.request.SeatCreationRequest;
import com.thirdparty.ticketing.domain.seat.dto.request.SeatGradeCreationElement;
import com.thirdparty.ticketing.domain.seat.dto.request.SeatGradeCreationRequest;
import com.thirdparty.ticketing.domain.seat.service.AdminSeatService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(AdminSeatController.class)
public class AdminSeatControllerTest extends BaseControllerTest {

@MockBean private AdminSeatService adminSeatService;

@Test
@DisplayName("관리자 좌석 생성 API")
void createSeats() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;

import com.thirdparty.ticketing.domain.ItemResult;
import com.thirdparty.ticketing.domain.seat.dto.response.SeatElement;
import com.thirdparty.ticketing.domain.seat.dto.response.SeatGradeElement;
import com.thirdparty.ticketing.domain.seat.service.SeatService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(SeatController.class)
public class SeatControllerTest extends BaseControllerTest {

public static final String PERFORMANCE_ID = "performanceId";

@MockBean private SeatService seatService;

@Test
@DisplayName("구역의 좌석 목록을 조회한다.")
void getSeats() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;
Expand All @@ -30,17 +28,11 @@
import com.thirdparty.ticketing.domain.ticket.dto.request.TicketPaymentRequest;
import com.thirdparty.ticketing.domain.ticket.dto.response.TicketElement;
import com.thirdparty.ticketing.domain.ticket.dto.response.TicketSeatDetail;
import com.thirdparty.ticketing.domain.ticket.service.ReservationService;
import com.thirdparty.ticketing.domain.ticket.service.TicketService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(controllers = TicketController.class)
class TicketControllerTest extends BaseControllerTest {

public static final String PERFORMANCE_ID = "performanceId";
@MockBean private TicketService ticketService;

@MockBean private ReservationService reservationService;

@Test
@DisplayName("티켓 조회 API 호출 시")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;

import com.thirdparty.ticketing.domain.common.LettuceRepository;
import com.thirdparty.ticketing.domain.common.TicketingException;
Expand All @@ -33,10 +32,9 @@
import com.thirdparty.ticketing.domain.ticket.dto.request.SeatSelectionRequest;
import com.thirdparty.ticketing.domain.zone.Zone;
import com.thirdparty.ticketing.domain.zone.repository.ZoneRepository;
import com.thirdparty.ticketing.support.TestContainerStarter;
import com.thirdparty.ticketing.support.BaseIntegrationTest;

@SpringBootTest
public class CacheReservationTest extends TestContainerStarter {
public class CacheReservationTest extends BaseIntegrationTest {

@Autowired private SeatRepository seatRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
Expand All @@ -29,10 +28,9 @@
import com.thirdparty.ticketing.domain.common.TicketingException;
import com.thirdparty.ticketing.domain.ticket.dto.request.SeatSelectionRequest;
import com.thirdparty.ticketing.domain.ticket.dto.request.TicketPaymentRequest;
import com.thirdparty.ticketing.support.TestContainerStarter;
import com.thirdparty.ticketing.support.BaseIntegrationTest;

@SpringBootTest
public class PersistenceReservationTest extends TestContainerStarter {
public class PersistenceReservationTest extends BaseIntegrationTest {
private static final Logger log = LoggerFactory.getLogger(PersistenceReservationTest.class);

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,19 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
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.context.annotation.Import;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.thirdparty.ticketing.domain.member.Member;
import com.thirdparty.ticketing.domain.member.MemberRole;
import com.thirdparty.ticketing.domain.member.service.JwtProvider;
import com.thirdparty.ticketing.domain.waitingsystem.WaitingAspectTest.TestController;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingMember;
import com.thirdparty.ticketing.global.waitingsystem.redis.running.RedisRunningRoom;
import com.thirdparty.ticketing.global.waitingsystem.redis.waiting.RedisWaitingLine;
import com.thirdparty.ticketing.support.TestContainerStarter;
import com.thirdparty.ticketing.support.BaseIntegrationTest;

@SpringBootTest
@AutoConfigureMockMvc
@Import(TestController.class)
class WaitingAspectTest extends TestContainerStarter {
class WaitingAspectTest extends BaseIntegrationTest {

private static final String AUTHORIZATION_HEADER = "Authorization";

Expand All @@ -48,16 +38,6 @@ class WaitingAspectTest extends TestContainerStarter {

@Autowired private RedisWaitingLine waitingLine;

@RestController
static class TestController {

@Waiting
@GetMapping("/api/waiting/test")
public ResponseEntity<String> test() {
return ResponseEntity.ok("test");
}
}

@BeforeEach
void setUp() {
redisTemplate.getConnectionFactory().getConnection().commands().flushAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;

import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(controllers = WaitingController.class)
class WaitingControllerTest extends BaseControllerTest {

public static final String PERFORMANCE_ID = "performanceId";

@MockBean private WaitingSystem waitingSystem;

@Test
@DisplayName("남은 대기 순번 조회 API 호출 시")
void getRemainingCount() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
Expand All @@ -26,11 +25,10 @@
import com.thirdparty.ticketing.domain.waitingsystem.running.RunningManager;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingManager;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingMember;
import com.thirdparty.ticketing.support.BaseIntegrationTest;
import com.thirdparty.ticketing.support.SpyEventPublisher;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class WaitingSystemTest extends TestContainerStarter {
class WaitingSystemTest extends BaseIntegrationTest {

private WaitingSystem waitingSystem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,17 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.ResultActions;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.thirdparty.ticketing.domain.zone.contoller.AdminZoneController;
import com.thirdparty.ticketing.domain.zone.dto.ZoneCreationElement;
import com.thirdparty.ticketing.domain.zone.dto.ZoneCreationRequest;
import com.thirdparty.ticketing.domain.zone.service.AdminZoneService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(AdminZoneController.class)
public class AdminZoneControllerTest extends BaseControllerTest {

@MockBean private AdminZoneService adminZoneService;

@Test
@DisplayName("POST /api/performances/{performanceId}/zones")
void createZones() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
package com.thirdparty.ticketing.domain.zone.controller;

import static org.mockito.BDDMockito.*;
import static org.mockito.BDDMockito.given;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.List;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.ResultActions;

import com.thirdparty.ticketing.domain.ItemResult;
import com.thirdparty.ticketing.domain.zone.contoller.UserZoneController;
import com.thirdparty.ticketing.domain.zone.dto.ZoneElement;
import com.thirdparty.ticketing.domain.zone.service.UserZoneService;
import com.thirdparty.ticketing.support.BaseControllerTest;

@WebMvcTest(UserZoneController.class)
class UserZoneControllerTest extends BaseControllerTest {

@MockBean private UserZoneService userZoneService;

@Test
@DisplayName("GET /api/performances/{performanceId}/zones")
void getZones() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import org.junit.jupiter.api.Test;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;

import com.thirdparty.ticketing.support.TestContainerStarter;
import com.thirdparty.ticketing.support.BaseIntegrationTest;

@SpringBootTest
class ProductionRedisConfigTest extends TestContainerStarter {
class ProductionRedisConfigTest extends BaseIntegrationTest {

@Autowired private RedissonClient redissonClient;

Expand Down
Loading
Loading