diff --git a/backend/src/test/java/kr/touroot/authentication/controller/LoginControllerTest.java b/backend/src/test/java/kr/touroot/authentication/controller/LoginControllerTest.java index 8c7eca51..cc7d4b4e 100644 --- a/backend/src/test/java/kr/touroot/authentication/controller/LoginControllerTest.java +++ b/backend/src/test/java/kr/touroot/authentication/controller/LoginControllerTest.java @@ -12,39 +12,21 @@ import kr.touroot.authentication.dto.response.TokenResponse; import kr.touroot.authentication.fixture.OauthUserFixture; import kr.touroot.authentication.helper.LoginTestHelper; -import kr.touroot.authentication.infrastructure.JwtTokenProvider; import kr.touroot.authentication.infrastructure.KakaoOauthProvider; -import kr.touroot.global.AcceptanceTest; -import kr.touroot.global.IntegrationTest; +import kr.touroot.global.AbstractControllerIntegrationTest; import kr.touroot.member.domain.Member; -import kr.touroot.utils.DatabaseCleaner; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.web.server.LocalServerPort; @DisplayName("로그인 컨트롤러") -@AcceptanceTest -class LoginControllerTest extends IntegrationTest { +class LoginControllerTest extends AbstractControllerIntegrationTest { - @Autowired - private JwtTokenProvider jwtTokenProvider; - @Autowired - private DatabaseCleaner databaseCleaner; @Autowired private LoginTestHelper testHelper; @MockBean private KakaoOauthProvider oauthProvider; - @LocalServerPort - private int port; - - @BeforeEach - void setUp() { - RestAssured.port = port; - databaseCleaner.executeTruncate(); - } @DisplayName("카카오 로그인 요청을 처리할 수 있다") @Test diff --git a/backend/src/test/java/kr/touroot/authentication/service/LoginServiceTest.java b/backend/src/test/java/kr/touroot/authentication/service/LoginServiceTest.java index df3f8177..46707ec9 100644 --- a/backend/src/test/java/kr/touroot/authentication/service/LoginServiceTest.java +++ b/backend/src/test/java/kr/touroot/authentication/service/LoginServiceTest.java @@ -12,32 +12,29 @@ import kr.touroot.authentication.fixture.OauthUserFixture; import kr.touroot.authentication.infrastructure.JwtTokenProvider; import kr.touroot.authentication.infrastructure.KakaoOauthProvider; -import kr.touroot.global.IntegrationTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.member.domain.Member; import kr.touroot.member.fixture.MemberFixture; import kr.touroot.member.repository.MemberRepository; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; @DisplayName("로그인 서비스") -@ExtendWith(MockitoExtension.class) -class LoginServiceTest extends IntegrationTest { +class LoginServiceTest extends AbstractServiceIntegrationTest { private static final String AUTHENTICATION_CODE = "test-authentication-code"; private static final String REDIRECT_URI = "http%3A%2F%2Flocalhost%3A8080%2Fapi%2Fv1%2Flogin%2Foauth%2Fkakao"; private static final Member MEMBER = MemberFixture.KAKAO_MEMBER.getMember(); - @InjectMocks + @Autowired private LoginService loginService; - @Mock + @MockBean private MemberRepository memberRepository; - @Mock + @MockBean private KakaoOauthProvider kakaoOauthProvider; - @Mock + @MockBean private JwtTokenProvider jwtTokenProvider; @DisplayName("투룻 회원가입이 되어 있는 회원의 카카오 소셜 로그인을 처리할 수 있다") diff --git a/backend/src/test/java/kr/touroot/global/AbstractControllerIntegrationTest.java b/backend/src/test/java/kr/touroot/global/AbstractControllerIntegrationTest.java new file mode 100644 index 00000000..32ba323b --- /dev/null +++ b/backend/src/test/java/kr/touroot/global/AbstractControllerIntegrationTest.java @@ -0,0 +1,30 @@ +package kr.touroot.global; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.restassured.RestAssured; +import kr.touroot.authentication.infrastructure.JwtTokenProvider; +import kr.touroot.utils.DatabaseCleaner; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.server.LocalServerPort; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +public abstract class AbstractControllerIntegrationTest extends AbstractIntegrationTest { + + @Autowired + protected DatabaseCleaner databaseCleaner; + @Autowired + protected ObjectMapper objectMapper; + @Autowired + protected JwtTokenProvider jwtTokenProvider; + @LocalServerPort + protected int port; + + @BeforeEach + protected void baseSetUp() { + RestAssured.port = port; + databaseCleaner.executeTruncate(); + } +} diff --git a/backend/src/test/java/kr/touroot/global/IntegrationTest.java b/backend/src/test/java/kr/touroot/global/AbstractIntegrationTest.java similarity index 88% rename from backend/src/test/java/kr/touroot/global/IntegrationTest.java rename to backend/src/test/java/kr/touroot/global/AbstractIntegrationTest.java index 5a18e6aa..946a0fea 100644 --- a/backend/src/test/java/kr/touroot/global/IntegrationTest.java +++ b/backend/src/test/java/kr/touroot/global/AbstractIntegrationTest.java @@ -1,14 +1,18 @@ package kr.touroot.global; import java.io.IOException; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; +import org.springframework.test.context.TestPropertySource; import org.testcontainers.containers.MySQLContainer; import org.testcontainers.containers.localstack.LocalStackContainer; import org.testcontainers.containers.localstack.LocalStackContainer.Service; import org.testcontainers.utility.DockerImageName; -public abstract class IntegrationTest { +@TestPropertySource(properties = {"spring.config.location = classpath:application-test.yml"}) +@ActiveProfiles("test") +public abstract class AbstractIntegrationTest { private static final DockerImageName MYSQL_IMAGE_NAME = DockerImageName.parse("mysql:8"); private static final DockerImageName LOCALSTACK_IMAGE_NAME = DockerImageName.parse("localstack/localstack"); diff --git a/backend/src/test/java/kr/touroot/global/AbstractServiceIntegrationTest.java b/backend/src/test/java/kr/touroot/global/AbstractServiceIntegrationTest.java new file mode 100644 index 00000000..f1cd630b --- /dev/null +++ b/backend/src/test/java/kr/touroot/global/AbstractServiceIntegrationTest.java @@ -0,0 +1,19 @@ +package kr.touroot.global; + +import kr.touroot.utils.DatabaseCleaner; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; + +@SpringBootTest(webEnvironment = WebEnvironment.NONE) +public abstract class AbstractServiceIntegrationTest extends AbstractIntegrationTest { + + @Autowired + protected DatabaseCleaner databaseCleaner; + + @BeforeEach + protected void baseSetUp() { + databaseCleaner.executeTruncate(); + } +} diff --git a/backend/src/test/java/kr/touroot/global/AcceptanceTest.java b/backend/src/test/java/kr/touroot/global/AcceptanceTest.java deleted file mode 100644 index b1faa108..00000000 --- a/backend/src/test/java/kr/touroot/global/AcceptanceTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package kr.touroot.global; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@Retention(RetentionPolicy.RUNTIME) -@TestPropertySource(properties = {"spring.config.location = classpath:application-test.yml"}) -@ActiveProfiles("test") -public @interface AcceptanceTest { -} diff --git a/backend/src/test/java/kr/touroot/global/ServiceTest.java b/backend/src/test/java/kr/touroot/global/ServiceTest.java deleted file mode 100644 index 626cd9a7..00000000 --- a/backend/src/test/java/kr/touroot/global/ServiceTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package kr.touroot.global; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import kr.touroot.utils.DatabaseCleaner; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -@DataJpaTest -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -@Transactional(propagation = Propagation.NOT_SUPPORTED) -@Import(value = {DatabaseCleaner.class}) -@Retention(RetentionPolicy.RUNTIME) -@TestPropertySource(properties = {"spring.config.location = classpath:application-test.yml"}) -@ActiveProfiles("test") -public @interface ServiceTest { -} diff --git a/backend/src/test/java/kr/touroot/image/infrastructure/AwsS3ProviderTest.java b/backend/src/test/java/kr/touroot/image/infrastructure/AwsS3ProviderTest.java index 0d5192b8..9ae7ccf5 100644 --- a/backend/src/test/java/kr/touroot/image/infrastructure/AwsS3ProviderTest.java +++ b/backend/src/test/java/kr/touroot/image/infrastructure/AwsS3ProviderTest.java @@ -4,8 +4,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.List; -import kr.touroot.global.AcceptanceTest; -import kr.touroot.global.IntegrationTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.global.exception.S3UploadException; import kr.touroot.image.domain.ImageFile; import org.junit.jupiter.api.DisplayName; @@ -16,22 +15,14 @@ import org.springframework.web.multipart.MultipartFile; @DisplayName("Aws S3 프로바이더") -@AcceptanceTest -class AwsS3ProviderTest extends IntegrationTest { - - private final AwsS3Provider s3Provider; - private final String temporaryStoragePath; - private final String imageStoragePath; - - public AwsS3ProviderTest( - @Autowired AwsS3Provider s3Provider, - @Value("${cloud.aws.s3.temporary-storage-path}") String temporaryStoragePath, - @Value("${cloud.aws.s3.image-storage-path}") String imageStoragePath - ) { - this.s3Provider = s3Provider; - this.temporaryStoragePath = temporaryStoragePath; - this.imageStoragePath = imageStoragePath; - } +class AwsS3ProviderTest extends AbstractServiceIntegrationTest { + + @Autowired + private AwsS3Provider s3Provider; + @Value("${cloud.aws.s3.temporary-storage-path}") + private String temporaryStoragePath; + @Value("${cloud.aws.s3.image-storage-path}") + private String imageStoragePath; @DisplayName("유효한 url을 통해 이미지를 영구 폴더로 복사하면 새로운 url을 반환한다.") @Test diff --git a/backend/src/test/java/kr/touroot/member/controller/MemberControllerTest.java b/backend/src/test/java/kr/touroot/member/controller/MemberControllerTest.java index 6310a831..2c222db8 100644 --- a/backend/src/test/java/kr/touroot/member/controller/MemberControllerTest.java +++ b/backend/src/test/java/kr/touroot/member/controller/MemberControllerTest.java @@ -4,39 +4,16 @@ import io.restassured.RestAssured; import io.restassured.http.ContentType; -import kr.touroot.global.AcceptanceTest; -import kr.touroot.global.IntegrationTest; +import kr.touroot.global.AbstractControllerIntegrationTest; import kr.touroot.member.dto.request.MemberRequest; import kr.touroot.member.fixture.MemberFixture; -import kr.touroot.utils.DatabaseCleaner; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.web.server.LocalServerPort; @DisplayName("사용자 컨트롤러") -@AcceptanceTest -class MemberControllerTest extends IntegrationTest { - - private final DatabaseCleaner databaseCleaner; - - @LocalServerPort - private int port; - - @Autowired - public MemberControllerTest(DatabaseCleaner databaseCleaner) { - this.databaseCleaner = databaseCleaner; - } - - @BeforeEach - void setUp() { - RestAssured.port = port; - - databaseCleaner.executeTruncate(); - } +class MemberControllerTest extends AbstractControllerIntegrationTest { @DisplayName("회원 가입을 한다.") @Test diff --git a/backend/src/test/java/kr/touroot/member/controller/MyPageControllerTest.java b/backend/src/test/java/kr/touroot/member/controller/MyPageControllerTest.java index 3182effa..c11ba4ef 100644 --- a/backend/src/test/java/kr/touroot/member/controller/MyPageControllerTest.java +++ b/backend/src/test/java/kr/touroot/member/controller/MyPageControllerTest.java @@ -5,60 +5,36 @@ import io.restassured.RestAssured; import io.restassured.http.ContentType; import java.util.List; -import kr.touroot.authentication.infrastructure.JwtTokenProvider; -import kr.touroot.global.AcceptanceTest; -import kr.touroot.global.IntegrationTest; +import kr.touroot.global.AbstractControllerIntegrationTest; import kr.touroot.image.domain.ImageFile; import kr.touroot.image.infrastructure.AwsS3Provider; import kr.touroot.member.domain.Member; import kr.touroot.member.dto.request.ProfileUpdateRequest; import kr.touroot.travelogue.helper.TravelogueTestHelper; import kr.touroot.travelplan.helper.TravelPlanTestHelper; -import kr.touroot.utils.DatabaseCleaner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; @DisplayName("마이 페이지 컨트롤러") -@AcceptanceTest -class MyPageControllerTest extends IntegrationTest { +class MyPageControllerTest extends AbstractControllerIntegrationTest { - private final DatabaseCleaner databaseCleaner; - private final JwtTokenProvider jwtTokenProvider; - private final TravelogueTestHelper travelogueTestHelper; - private final TravelPlanTestHelper travelPlanTestHelper; + @Autowired + private TravelogueTestHelper travelogueTestHelper; + @Autowired + private TravelPlanTestHelper travelPlanTestHelper; + @Autowired + private AwsS3Provider s3Provider; - @LocalServerPort - private int port; private String accessToken; private Member member; - private final AwsS3Provider s3Provider; - - @Autowired - public MyPageControllerTest( - DatabaseCleaner databaseCleaner, - JwtTokenProvider jwtTokenProvider, - TravelogueTestHelper travelogueTestHelper, - TravelPlanTestHelper travelPlanTestHelper, - AwsS3Provider s3Provider - ) { - this.databaseCleaner = databaseCleaner; - this.jwtTokenProvider = jwtTokenProvider; - this.travelogueTestHelper = travelogueTestHelper; - this.travelPlanTestHelper = travelPlanTestHelper; - this.s3Provider = s3Provider; - } @BeforeEach void setUp() { - RestAssured.port = port; - databaseCleaner.executeTruncate(); - member = travelogueTestHelper.initKakaoMemberTestData(); accessToken = jwtTokenProvider.createToken(member.getId()) .accessToken(); diff --git a/backend/src/test/java/kr/touroot/member/service/MemberServiceTest.java b/backend/src/test/java/kr/touroot/member/service/MemberServiceTest.java index b01481f0..a69f0355 100644 --- a/backend/src/test/java/kr/touroot/member/service/MemberServiceTest.java +++ b/backend/src/test/java/kr/touroot/member/service/MemberServiceTest.java @@ -5,11 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertAll; import java.util.List; -import kr.touroot.authentication.infrastructure.PasswordEncryptor; -import kr.touroot.global.IntegrationTest; -import kr.touroot.global.ServiceTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.global.auth.dto.MemberAuth; -import kr.touroot.global.config.S3TestConfig; import kr.touroot.global.exception.BadRequestException; import kr.touroot.image.domain.ImageFile; import kr.touroot.image.infrastructure.AwsS3Provider; @@ -18,49 +15,22 @@ import kr.touroot.member.dto.request.ProfileUpdateRequest; import kr.touroot.member.fixture.MemberFixture; import kr.touroot.member.helper.MemberTestHelper; -import kr.touroot.utils.DatabaseCleaner; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; @DisplayName("사용자 서비스") -@Import(value = { - MemberService.class, - MemberTestHelper.class, - PasswordEncryptor.class, - AwsS3Provider.class, - S3TestConfig.class -}) -@ServiceTest -class MemberServiceTest extends IntegrationTest { - - private final MemberService memberService; - private final MemberTestHelper testHelper; - private final DatabaseCleaner databaseCleaner; - private final AwsS3Provider s3Provider; +class MemberServiceTest extends AbstractServiceIntegrationTest { @Autowired - public MemberServiceTest( - MemberService memberService, - MemberTestHelper testHelper, - DatabaseCleaner databaseCleaner, - AwsS3Provider s3Provider - ) { - this.memberService = memberService; - this.testHelper = testHelper; - this.databaseCleaner = databaseCleaner; - this.s3Provider = s3Provider; - } - - @BeforeEach - void setUp() { - databaseCleaner.executeTruncate(); - } + private MemberService memberService; + @Autowired + private MemberTestHelper testHelper; + @Autowired + private AwsS3Provider s3Provider; @DisplayName("ID를 기준으로 회원을 조회한다.") @Test diff --git a/backend/src/test/java/kr/touroot/travelogue/controller/TravelogueControllerTest.java b/backend/src/test/java/kr/touroot/travelogue/controller/TravelogueControllerTest.java index c0f32e6b..856d6dd7 100644 --- a/backend/src/test/java/kr/touroot/travelogue/controller/TravelogueControllerTest.java +++ b/backend/src/test/java/kr/touroot/travelogue/controller/TravelogueControllerTest.java @@ -20,14 +20,12 @@ import static org.hamcrest.Matchers.is; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import io.restassured.RestAssured; import io.restassured.http.ContentType; import java.util.Collections; import java.util.List; -import kr.touroot.authentication.infrastructure.JwtTokenProvider; -import kr.touroot.global.AcceptanceTest; -import kr.touroot.global.IntegrationTest; +import kr.touroot.authentication.dto.response.TokenResponse; +import kr.touroot.global.AbstractControllerIntegrationTest; import kr.touroot.global.exception.dto.ExceptionResponse; import kr.touroot.member.domain.Member; import kr.touroot.tag.domain.Tag; @@ -44,7 +42,6 @@ import kr.touroot.travelogue.fixture.TravelogueResponseFixture; import kr.touroot.travelogue.helper.TravelogueRequestBuilder; import kr.touroot.travelogue.helper.TravelogueTestHelper; -import kr.touroot.utils.DatabaseCleaner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; @@ -53,48 +50,25 @@ import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.data.domain.Page; import org.springframework.http.HttpHeaders; @DisplayName("여행기 컨트롤러") -@AcceptanceTest -class TravelogueControllerTest extends IntegrationTest { +class TravelogueControllerTest extends AbstractControllerIntegrationTest { - private final DatabaseCleaner databaseCleaner; - private final TravelogueTestHelper testHelper; - private final ObjectMapper objectMapper; - private final JwtTokenProvider jwtTokenProvider; + @Autowired + private TravelogueTestHelper testHelper; - @LocalServerPort - private int port; private Member travelogueWriter; private Tag tag; private String travelogueWriterAccessToken; - @Autowired - public TravelogueControllerTest( - DatabaseCleaner databaseCleaner, - TravelogueTestHelper testHelper, - ObjectMapper objectMapper, - JwtTokenProvider jwtTokenProvider - ) { - this.databaseCleaner = databaseCleaner; - this.testHelper = testHelper; - this.objectMapper = objectMapper; - this.jwtTokenProvider = jwtTokenProvider; - } - @BeforeEach - void setUp() { - RestAssured.port = port; - - databaseCleaner.executeTruncate(); - + public void setUp() { travelogueWriter = testHelper.initKakaoMemberTestData(); tag = testHelper.initTagTestData(); - travelogueWriterAccessToken = jwtTokenProvider.createToken(travelogueWriter.getId()) - .accessToken(); + TokenResponse travelogueWriterToken = jwtTokenProvider.createToken(travelogueWriter.getId()); + travelogueWriterAccessToken = travelogueWriterToken.accessToken(); } @DisplayName("태그가 없는 여행기를 작성한다.") diff --git a/backend/src/test/java/kr/touroot/travelogue/service/TravelogueCountryServiceTest.java b/backend/src/test/java/kr/touroot/travelogue/service/TravelogueCountryServiceTest.java index b68a494c..ed5ab01e 100644 --- a/backend/src/test/java/kr/touroot/travelogue/service/TravelogueCountryServiceTest.java +++ b/backend/src/test/java/kr/touroot/travelogue/service/TravelogueCountryServiceTest.java @@ -4,8 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import java.util.List; -import kr.touroot.global.IntegrationTest; -import kr.touroot.global.ServiceTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.travelogue.domain.Travelogue; import kr.touroot.travelogue.domain.TravelogueCountry; import kr.touroot.travelogue.domain.search.CountryCode; @@ -15,37 +14,17 @@ import kr.touroot.travelogue.dto.request.TravelogueRequest; import kr.touroot.travelogue.fixture.TravelogueRequestFixture; import kr.touroot.travelogue.helper.TravelogueTestHelper; -import kr.touroot.utils.DatabaseCleaner; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; @DisplayName("여행기 국가 서비스") -@Import(value = {TravelogueCountryService.class, TravelogueTestHelper.class}) -@ServiceTest -class TravelogueCountryServiceTest extends IntegrationTest { - - private final TravelogueCountryService travelogueCountryService; - private final DatabaseCleaner databaseCleaner; - private final TravelogueTestHelper testHelper; +class TravelogueCountryServiceTest extends AbstractServiceIntegrationTest { @Autowired - public TravelogueCountryServiceTest( - TravelogueCountryService travelogueCountryService, - DatabaseCleaner databaseCleaner, - TravelogueTestHelper testHelper - ) { - this.travelogueCountryService = travelogueCountryService; - this.databaseCleaner = databaseCleaner; - this.testHelper = testHelper; - } - - @BeforeEach - void setUp() { - databaseCleaner.executeTruncate(); - } + private TravelogueCountryService travelogueCountryService; + @Autowired + private TravelogueTestHelper testHelper; @DisplayName("여행기 국가들을 생성할 수 있다.") @Test diff --git a/backend/src/test/java/kr/touroot/travelogue/service/TravelogueFacadeServiceTest.java b/backend/src/test/java/kr/touroot/travelogue/service/TravelogueFacadeServiceTest.java index 54302365..d2d32b60 100644 --- a/backend/src/test/java/kr/touroot/travelogue/service/TravelogueFacadeServiceTest.java +++ b/backend/src/test/java/kr/touroot/travelogue/service/TravelogueFacadeServiceTest.java @@ -4,17 +4,11 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.List; -import kr.touroot.authentication.infrastructure.PasswordEncryptor; -import kr.touroot.global.IntegrationTest; -import kr.touroot.global.ServiceTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.global.auth.dto.MemberAuth; -import kr.touroot.global.config.S3TestConfig; -import kr.touroot.global.config.TestQueryDslConfig; import kr.touroot.global.exception.BadRequestException; import kr.touroot.global.exception.ForbiddenException; -import kr.touroot.image.infrastructure.AwsS3Provider; import kr.touroot.member.domain.Member; -import kr.touroot.member.service.MemberService; import kr.touroot.travelogue.domain.Travelogue; import kr.touroot.travelogue.dto.request.TravelogueDayRequest; import kr.touroot.travelogue.dto.request.TravelogueFilterRequest; @@ -28,53 +22,20 @@ import kr.touroot.travelogue.fixture.TravelogueRequestFixture; import kr.touroot.travelogue.fixture.TravelogueResponseFixture; import kr.touroot.travelogue.helper.TravelogueTestHelper; -import kr.touroot.utils.DatabaseCleaner; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @DisplayName("여행기 Facade 서비스") -@Import(value = { - TravelogueFacadeService.class, - TravelogueService.class, - S3TestConfig.class, - AwsS3Provider.class, - TravelogueImagePerpetuationService.class, - TravelogueTagService.class, - TravelogueLikeService.class, - TravelogueCountryService.class, - MemberService.class, - TravelogueTestHelper.class, - PasswordEncryptor.class, - TestQueryDslConfig.class -}) -@ServiceTest -class TravelogueFacadeServiceTest extends IntegrationTest { - - private final TravelogueFacadeService service; - private final TravelogueTestHelper testHelper; - private final DatabaseCleaner databaseCleaner; +class TravelogueFacadeServiceTest extends AbstractServiceIntegrationTest { @Autowired - public TravelogueFacadeServiceTest( - TravelogueFacadeService travelogueFacadeService, - TravelogueTestHelper travelogueTestHelper, - DatabaseCleaner databaseCleaner - ) { - this.service = travelogueFacadeService; - this.testHelper = travelogueTestHelper; - this.databaseCleaner = databaseCleaner; - } - - @BeforeEach - void setUp() { - databaseCleaner.executeTruncate(); - } + private TravelogueFacadeService service; + @Autowired + private TravelogueTestHelper testHelper; @DisplayName("여행기를 생성할 수 있다.") @Test diff --git a/backend/src/test/java/kr/touroot/travelogue/service/TravelogueLikeServiceTest.java b/backend/src/test/java/kr/touroot/travelogue/service/TravelogueLikeServiceTest.java index 4aba2e39..b238c0d3 100644 --- a/backend/src/test/java/kr/touroot/travelogue/service/TravelogueLikeServiceTest.java +++ b/backend/src/test/java/kr/touroot/travelogue/service/TravelogueLikeServiceTest.java @@ -2,45 +2,27 @@ import static org.assertj.core.api.Assertions.assertThat; -import kr.touroot.global.IntegrationTest; -import kr.touroot.global.ServiceTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.member.domain.Member; import kr.touroot.travelogue.domain.Travelogue; import kr.touroot.travelogue.helper.TravelogueTestHelper; import kr.touroot.utils.DatabaseCleaner; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; import org.springframework.data.domain.Pageable; @DisplayName("여행기 좋아요 서비스") -@Import(value = {TravelogueLikeService.class, TravelogueTestHelper.class}) -@ServiceTest -class TravelogueLikeServiceTest extends IntegrationTest { +class TravelogueLikeServiceTest extends AbstractServiceIntegrationTest { public static final int BASIC_PAGE_SIZE = 5; - private final TravelogueLikeService travelogueLikeService; - private final DatabaseCleaner databaseCleaner; - private final TravelogueTestHelper testHelper; - @Autowired - public TravelogueLikeServiceTest( - TravelogueLikeService travelogueLikeService, - DatabaseCleaner databaseCleaner, - TravelogueTestHelper testHelper - ) { - this.travelogueLikeService = travelogueLikeService; - this.databaseCleaner = databaseCleaner; - this.testHelper = testHelper; - } - - @BeforeEach - void setUp() { - databaseCleaner.executeTruncate(); - } + private TravelogueLikeService travelogueLikeService; + @Autowired + private DatabaseCleaner databaseCleaner; + @Autowired + private TravelogueTestHelper testHelper; @DisplayName("특정 멤버가 좋아요 한 여행기를 조회할 수 있다.") @Test diff --git a/backend/src/test/java/kr/touroot/travelogue/service/TravelogueServiceTest.java b/backend/src/test/java/kr/touroot/travelogue/service/TravelogueServiceTest.java index aafb49fe..2d6b5e02 100644 --- a/backend/src/test/java/kr/touroot/travelogue/service/TravelogueServiceTest.java +++ b/backend/src/test/java/kr/touroot/travelogue/service/TravelogueServiceTest.java @@ -6,9 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import java.util.List; -import kr.touroot.global.IntegrationTest; -import kr.touroot.global.ServiceTest; -import kr.touroot.global.config.TestQueryDslConfig; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.global.exception.BadRequestException; import kr.touroot.global.exception.ForbiddenException; import kr.touroot.member.domain.Member; @@ -23,40 +21,20 @@ import kr.touroot.travelogue.fixture.TravelogueFixture; import kr.touroot.travelogue.fixture.TravelogueRequestFixture; import kr.touroot.travelogue.helper.TravelogueTestHelper; -import kr.touroot.utils.DatabaseCleaner; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @DisplayName("여행기 서비스") -@Import(value = {TravelogueService.class, TravelogueTestHelper.class, TestQueryDslConfig.class}) -@ServiceTest -class TravelogueServiceTest extends IntegrationTest { - - private final TravelogueService travelogueService; - private final DatabaseCleaner databaseCleaner; - private final TravelogueTestHelper testHelper; +class TravelogueServiceTest extends AbstractServiceIntegrationTest { @Autowired - public TravelogueServiceTest( - TravelogueService travelogueService, - DatabaseCleaner databaseCleaner, - TravelogueTestHelper testHelper - ) { - this.travelogueService = travelogueService; - this.databaseCleaner = databaseCleaner; - this.testHelper = testHelper; - } - - @BeforeEach - void setUp() { - databaseCleaner.executeTruncate(); - } + private TravelogueService travelogueService; + @Autowired + private TravelogueTestHelper testHelper; private static List getTravelogueDayRequests() { List photos = TravelogueRequestFixture.getTraveloguePhotoRequests(); diff --git a/backend/src/test/java/kr/touroot/travelplan/controller/PlaceTodoControllerTest.java b/backend/src/test/java/kr/touroot/travelplan/controller/PlaceTodoControllerTest.java index 2cd16552..ab23c71c 100644 --- a/backend/src/test/java/kr/touroot/travelplan/controller/PlaceTodoControllerTest.java +++ b/backend/src/test/java/kr/touroot/travelplan/controller/PlaceTodoControllerTest.java @@ -5,45 +5,27 @@ import io.restassured.RestAssured; import io.restassured.http.ContentType; -import kr.touroot.authentication.infrastructure.JwtTokenProvider; -import kr.touroot.global.AcceptanceTest; -import kr.touroot.global.IntegrationTest; +import kr.touroot.global.AbstractControllerIntegrationTest; import kr.touroot.member.domain.Member; import kr.touroot.travelplan.dto.request.TodoStatusUpdateRequest; import kr.touroot.travelplan.helper.TravelPlanTestHelper; -import kr.touroot.utils.DatabaseCleaner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpHeaders; @DisplayName("여행 계획 장소에 대한 TODO 컨트롤러") -@AcceptanceTest -class PlaceTodoControllerTest extends IntegrationTest { +class PlaceTodoControllerTest extends AbstractControllerIntegrationTest { + + @Autowired + private TravelPlanTestHelper testHelper; - private final DatabaseCleaner databaseCleaner; - private final JwtTokenProvider jwtTokenProvider; - private final TravelPlanTestHelper testHelper; - @LocalServerPort - private int port; private String accessToken; private Member member; - @Autowired - public PlaceTodoControllerTest(DatabaseCleaner databaseCleaner, JwtTokenProvider jwtTokenProvider, - TravelPlanTestHelper testHelper) { - this.databaseCleaner = databaseCleaner; - this.jwtTokenProvider = jwtTokenProvider; - this.testHelper = testHelper; - } - @BeforeEach void setUp() { - RestAssured.port = port; - databaseCleaner.executeTruncate(); - member = testHelper.initMemberTestData(); accessToken = jwtTokenProvider.createToken(member.getId()).accessToken(); } diff --git a/backend/src/test/java/kr/touroot/travelplan/controller/TravelPlanControllerTest.java b/backend/src/test/java/kr/touroot/travelplan/controller/TravelPlanControllerTest.java index a69b0383..da7c2335 100644 --- a/backend/src/test/java/kr/touroot/travelplan/controller/TravelPlanControllerTest.java +++ b/backend/src/test/java/kr/touroot/travelplan/controller/TravelPlanControllerTest.java @@ -19,50 +19,29 @@ import io.restassured.http.ContentType; import java.util.List; import java.util.UUID; -import kr.touroot.authentication.infrastructure.JwtTokenProvider; -import kr.touroot.global.AcceptanceTest; -import kr.touroot.global.IntegrationTest; +import kr.touroot.global.AbstractControllerIntegrationTest; import kr.touroot.member.domain.Member; import kr.touroot.travelplan.domain.TravelPlan; import kr.touroot.travelplan.dto.request.PlanRequest; import kr.touroot.travelplan.helper.TravelPlanRequestBuilder; import kr.touroot.travelplan.helper.TravelPlanTestHelper; -import kr.touroot.utils.DatabaseCleaner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpHeaders; @DisplayName("여행 계획 컨트롤러") -@AcceptanceTest -class TravelPlanControllerTest extends IntegrationTest { - - private final DatabaseCleaner databaseCleaner; - private final JwtTokenProvider jwtTokenProvider; - private final TravelPlanTestHelper testHelper; - @LocalServerPort - private int port; - private String accessToken; - private Member planWriter; +class TravelPlanControllerTest extends AbstractControllerIntegrationTest { @Autowired - public TravelPlanControllerTest( - DatabaseCleaner databaseCleaner, - TravelPlanTestHelper testHelper, - JwtTokenProvider jwtTokenProvider - ) { - this.databaseCleaner = databaseCleaner; - this.testHelper = testHelper; - this.jwtTokenProvider = jwtTokenProvider; - } + private TravelPlanTestHelper testHelper; + + private String accessToken; + private Member planWriter; @BeforeEach void setUp() { - RestAssured.port = port; - databaseCleaner.executeTruncate(); - planWriter = testHelper.initMemberTestData(); accessToken = jwtTokenProvider.createToken(planWriter.getId()).accessToken(); } diff --git a/backend/src/test/java/kr/touroot/travelplan/service/PlaceTodoServiceTest.java b/backend/src/test/java/kr/touroot/travelplan/service/PlaceTodoServiceTest.java index a783a862..2ed9795d 100644 --- a/backend/src/test/java/kr/touroot/travelplan/service/PlaceTodoServiceTest.java +++ b/backend/src/test/java/kr/touroot/travelplan/service/PlaceTodoServiceTest.java @@ -3,49 +3,32 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import kr.touroot.global.IntegrationTest; -import kr.touroot.global.ServiceTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.global.auth.dto.MemberAuth; -import kr.touroot.global.config.TestQueryDslConfig; import kr.touroot.global.exception.BadRequestException; import kr.touroot.global.exception.ForbiddenException; import kr.touroot.member.domain.Member; import kr.touroot.travelplan.dto.request.TodoStatusUpdateRequest; import kr.touroot.travelplan.dto.response.PlanPlaceTodoResponse; import kr.touroot.travelplan.helper.TravelPlanTestHelper; -import kr.touroot.utils.DatabaseCleaner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; @DisplayName("TODO 서비스") -@Import({PlaceTodoService.class, TravelPlanTestHelper.class, TestQueryDslConfig.class}) -@ServiceTest -class PlaceTodoServiceTest extends IntegrationTest { +class PlaceTodoServiceTest extends AbstractServiceIntegrationTest { - private final PlaceTodoService placeTodoService; - private final DatabaseCleaner databaseCleaner; - private final TravelPlanTestHelper testHelper; + @Autowired + private PlaceTodoService placeTodoService; + @Autowired + private TravelPlanTestHelper testHelper; private MemberAuth memberAuth; private Member author; - @Autowired - public PlaceTodoServiceTest( - PlaceTodoService placeTodoService, - DatabaseCleaner databaseCleaner, - TravelPlanTestHelper testHelper - ) { - this.placeTodoService = placeTodoService; - this.databaseCleaner = databaseCleaner; - this.testHelper = testHelper; - } - @BeforeEach void setUp() { - databaseCleaner.executeTruncate(); author = testHelper.initMemberTestData(); memberAuth = new MemberAuth(author.getId()); } diff --git a/backend/src/test/java/kr/touroot/travelplan/service/TravelPlanFacadeServiceTest.java b/backend/src/test/java/kr/touroot/travelplan/service/TravelPlanFacadeServiceTest.java index 5699d16f..a8db83cd 100644 --- a/backend/src/test/java/kr/touroot/travelplan/service/TravelPlanFacadeServiceTest.java +++ b/backend/src/test/java/kr/touroot/travelplan/service/TravelPlanFacadeServiceTest.java @@ -6,15 +6,10 @@ import java.time.LocalDate; import java.util.Collections; import java.util.List; -import kr.touroot.authentication.infrastructure.PasswordEncryptor; -import kr.touroot.global.IntegrationTest; -import kr.touroot.global.ServiceTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.global.auth.dto.MemberAuth; -import kr.touroot.global.config.S3TestConfig; import kr.touroot.global.exception.BadRequestException; -import kr.touroot.image.infrastructure.AwsS3Provider; import kr.touroot.member.domain.Member; -import kr.touroot.member.service.MemberService; import kr.touroot.travelplan.domain.TravelPlan; import kr.touroot.travelplan.dto.request.PlanDayRequest; import kr.touroot.travelplan.dto.request.PlanPlaceRequest; @@ -23,48 +18,24 @@ import kr.touroot.travelplan.dto.response.PlanCreateResponse; import kr.touroot.travelplan.dto.response.PlanResponse; import kr.touroot.travelplan.helper.TravelPlanTestHelper; -import kr.touroot.utils.DatabaseCleaner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; @DisplayName("여행 계획 파사드 서비스 테스트") -@Import({ - TravelPlanFacadeService.class, - TravelPlanService.class, - MemberService.class, - PasswordEncryptor.class, - TravelPlanTestHelper.class, - AwsS3Provider.class, - S3TestConfig.class -}) -@ServiceTest -class TravelPlanFacadeServiceTest extends IntegrationTest { - - private final TravelPlanFacadeService travelPlanFacadeService; - private final DatabaseCleaner databaseCleaner; - private final TravelPlanTestHelper testHelper; +class TravelPlanFacadeServiceTest extends AbstractServiceIntegrationTest { + + @Autowired + private TravelPlanFacadeService travelPlanFacadeService; + @Autowired + private TravelPlanTestHelper testHelper; private MemberAuth memberAuth; private Member author; - @Autowired - public TravelPlanFacadeServiceTest( - TravelPlanFacadeService travelPlanFacadeService, - DatabaseCleaner databaseCleaner, - TravelPlanTestHelper testHelper - ) { - this.travelPlanFacadeService = travelPlanFacadeService; - this.databaseCleaner = databaseCleaner; - this.testHelper = testHelper; - } - @BeforeEach void setUp() { - databaseCleaner.executeTruncate(); - author = testHelper.initMemberTestData(); memberAuth = new MemberAuth(author.getId()); } diff --git a/backend/src/test/java/kr/touroot/travelplan/service/TravelPlanServiceTest.java b/backend/src/test/java/kr/touroot/travelplan/service/TravelPlanServiceTest.java index 8f7082ca..ec07423e 100644 --- a/backend/src/test/java/kr/touroot/travelplan/service/TravelPlanServiceTest.java +++ b/backend/src/test/java/kr/touroot/travelplan/service/TravelPlanServiceTest.java @@ -8,8 +8,7 @@ import java.util.Collections; import java.util.List; import java.util.UUID; -import kr.touroot.global.IntegrationTest; -import kr.touroot.global.ServiceTest; +import kr.touroot.global.AbstractServiceIntegrationTest; import kr.touroot.global.exception.BadRequestException; import kr.touroot.global.exception.ForbiddenException; import kr.touroot.member.domain.Member; @@ -21,42 +20,25 @@ import kr.touroot.travelplan.fixture.TravelPlanFixture; import kr.touroot.travelplan.helper.TravelPlanTestHelper; import kr.touroot.travelplan.repository.TravelPlanRepository; -import kr.touroot.utils.DatabaseCleaner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; @DisplayName("여행 계획 서비스") -@Import(value = {TravelPlanService.class, TravelPlanTestHelper.class}) -@ServiceTest -class TravelPlanServiceTest extends IntegrationTest { +class TravelPlanServiceTest extends AbstractServiceIntegrationTest { - private final TravelPlanService travelPlanService; - private final TravelPlanRepository travelPlanRepository; - private final DatabaseCleaner databaseCleaner; - private final TravelPlanTestHelper testHelper; + @Autowired + private TravelPlanService travelPlanService; + @Autowired + private TravelPlanRepository travelPlanRepository; + @Autowired + private TravelPlanTestHelper testHelper; private Member author; - @Autowired - public TravelPlanServiceTest( - TravelPlanService travelPlanService, - TravelPlanRepository travelPlanRepository, - DatabaseCleaner databaseCleaner, - TravelPlanTestHelper testHelper - ) { - this.travelPlanService = travelPlanService; - this.travelPlanRepository = travelPlanRepository; - this.databaseCleaner = databaseCleaner; - this.testHelper = testHelper; - } - @BeforeEach void setUp() { - databaseCleaner.executeTruncate(); - author = testHelper.initMemberTestData(); }