From feb8b1080d76c9ff0cea381fa3613eed1ef42ab5 Mon Sep 17 00:00:00 2001 From: songusika Date: Fri, 17 Nov 2023 14:29:17 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DigginRoomApplicationTests.java | 3 ++- .../repository/CommentRepositoryTest.java | 21 +++++++++---------- .../repository/RoomRepositoryTest.java | 7 ++----- .../digginroom/service/RoomServiceTest.java | 8 +++---- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/backend/src/test/java/com/digginroom/digginroom/DigginRoomApplicationTests.java b/backend/src/test/java/com/digginroom/digginroom/DigginRoomApplicationTests.java index a0fbfdf6e..7e45ee5dc 100644 --- a/backend/src/test/java/com/digginroom/digginroom/DigginRoomApplicationTests.java +++ b/backend/src/test/java/com/digginroom/digginroom/DigginRoomApplicationTests.java @@ -2,8 +2,9 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -@SpringBootTest +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class DigginRoomApplicationTests { @Test diff --git a/backend/src/test/java/com/digginroom/digginroom/repository/CommentRepositoryTest.java b/backend/src/test/java/com/digginroom/digginroom/repository/CommentRepositoryTest.java index 88617d071..942b43adf 100644 --- a/backend/src/test/java/com/digginroom/digginroom/repository/CommentRepositoryTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/repository/CommentRepositoryTest.java @@ -9,27 +9,25 @@ import com.digginroom.digginroom.domain.comment.Comment; import com.digginroom.digginroom.domain.member.Member; import com.digginroom.digginroom.exception.CommentException; +import com.digginroom.digginroom.util.DatabaseCleanerExtension; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import java.util.List; import java.util.stream.LongStream; import org.junit.jupiter.api.BeforeEach; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import com.digginroom.digginroom.exception.CommentException; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; -import org.springframework.test.annotation.DirtiesContext; +import org.springframework.transaction.annotation.Transactional; -@DataJpaTest +@Transactional +@ExtendWith(DatabaseCleanerExtension.class) @SuppressWarnings("NonAsciiCharacters") -@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class CommentRepositoryTest { @PersistenceContext @@ -75,7 +73,8 @@ void init() { PageRequest pageRequest = PageRequest.of(0, 10); Slice comments = commentRepository.getCommentsByCursor(1L, 15L, pageRequest); - + System.out.println("===================================="); + System.out.println(commentRepository.count()); assertThat(comments.getContent()) .hasSize(10) .map(BaseEntity::getId) diff --git a/backend/src/test/java/com/digginroom/digginroom/repository/RoomRepositoryTest.java b/backend/src/test/java/com/digginroom/digginroom/repository/RoomRepositoryTest.java index ff276bd25..542c77b57 100644 --- a/backend/src/test/java/com/digginroom/digginroom/repository/RoomRepositoryTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/repository/RoomRepositoryTest.java @@ -9,14 +9,11 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.Test; 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.transaction.annotation.Transactional; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -@Transactional +@DataJpaTest @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(ReplaceUnderscores.class) -@SpringBootTest(webEnvironment = WebEnvironment.NONE) class RoomRepositoryTest { @Autowired diff --git a/backend/src/test/java/com/digginroom/digginroom/service/RoomServiceTest.java b/backend/src/test/java/com/digginroom/digginroom/service/RoomServiceTest.java index ae168c37b..b455f386e 100644 --- a/backend/src/test/java/com/digginroom/digginroom/service/RoomServiceTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/service/RoomServiceTest.java @@ -8,9 +8,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import com.digginroom.digginroom.service.dto.RoomResponse; -import com.digginroom.digginroom.service.dto.RoomsResponse; -import com.digginroom.digginroom.service.dto.TrackResponse; import com.digginroom.digginroom.domain.Genre; import com.digginroom.digginroom.domain.member.Member; import com.digginroom.digginroom.domain.room.Room; @@ -19,6 +16,9 @@ import com.digginroom.digginroom.exception.RoomException.NotScrappedException; import com.digginroom.digginroom.repository.MemberRepository; import com.digginroom.digginroom.repository.RoomRepository; +import com.digginroom.digginroom.service.dto.RoomResponse; +import com.digginroom.digginroom.service.dto.RoomsResponse; +import com.digginroom.digginroom.service.dto.TrackResponse; import java.util.Collections; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; @@ -32,7 +32,7 @@ @Transactional @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(ReplaceUnderscores.class) -@SpringBootTest(webEnvironment = WebEnvironment.NONE) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class RoomServiceTest { @Autowired From 7b0a2114b548f363b847fa9eab1cf8fe6ac557c2 Mon Sep 17 00:00:00 2001 From: songusika Date: Fri, 17 Nov 2023 19:07:50 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EB=B3=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../digginroom/{controller => }/ControllerTest.java | 4 ++-- .../{ => comment}/controller/CommentControllerTest.java | 5 +++-- .../{ => comment}/repository/CommentRepositoryTest.java | 3 ++- .../{ => comment}/service/CommentServiceTest.java | 3 ++- .../GlobalExceptionHandlerTest.java | 3 ++- .../feedback/controller/FeedbackControllerTest.java | 2 +- .../feedback/{ => service}/FeedbackServiceTest.java | 3 ++- .../{ => member}/controller/MemberArgumentResolverTest.java | 3 ++- .../{ => member}/controller/MemberJoinControllerTest.java | 3 ++- .../{ => member}/controller/MemberLoginControllerTest.java | 5 +++-- .../controller/MemberOperationControllerTest.java | 3 ++- .../dto => member/controller}/MemberSaveRequestTest.java | 2 +- .../digginroom/{ => member}/domain/GenreTest.java | 2 +- .../digginroom/{ => member}/domain/MemberGenreTest.java | 3 ++- .../digginroom/{ => member}/domain/MemberTest.java | 3 ++- .../digginroom/{ => member}/domain/PasswordTest.java | 2 +- .../digginroom/{ => member}/domain/member/ProviderTest.java | 6 ++++-- .../domain/password}/DigginRoomPasswordEncoderTest.java | 3 ++- .../{util => member/domain/password}/HashAlgorithmTest.java | 3 ++- .../{ => member}/repository/MemberRepositoryTest.java | 3 ++- .../digginroom/{ => member}/service/MemberServiceTest.java | 3 ++- .../{ => room}/controller/RoomControllerTest.java | 5 +++-- .../digginroom/digginroom/{ => room}/domain/RoomTest.java | 2 +- .../digginroom/digginroom/{ => room}/domain/TrackTest.java | 3 ++- .../{ => room}/repository/RoomRepositoryTest.java | 3 ++- .../digginroom/{ => room}/service/RoomServiceTest.java | 3 ++- 26 files changed, 52 insertions(+), 31 deletions(-) rename backend/src/test/java/com/digginroom/digginroom/{controller => }/ControllerTest.java (92%) rename backend/src/test/java/com/digginroom/digginroom/{ => comment}/controller/CommentControllerTest.java (98%) rename backend/src/test/java/com/digginroom/digginroom/{ => comment}/repository/CommentRepositoryTest.java (97%) rename backend/src/test/java/com/digginroom/digginroom/{ => comment}/service/CommentServiceTest.java (97%) rename backend/src/test/java/com/digginroom/digginroom/{controller => exception}/GlobalExceptionHandlerTest.java (88%) rename backend/src/test/java/com/digginroom/digginroom/feedback/{ => service}/FeedbackServiceTest.java (94%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/controller/MemberArgumentResolverTest.java (93%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/controller/MemberJoinControllerTest.java (94%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/controller/MemberLoginControllerTest.java (96%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/controller/MemberOperationControllerTest.java (97%) rename backend/src/test/java/com/digginroom/digginroom/{controller/dto => member/controller}/MemberSaveRequestTest.java (98%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/domain/GenreTest.java (93%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/domain/MemberGenreTest.java (93%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/domain/MemberTest.java (98%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/domain/PasswordTest.java (97%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/domain/member/ProviderTest.java (76%) rename backend/src/test/java/com/digginroom/digginroom/{util => member/domain/password}/DigginRoomPasswordEncoderTest.java (88%) rename backend/src/test/java/com/digginroom/digginroom/{util => member/domain/password}/HashAlgorithmTest.java (87%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/repository/MemberRepositoryTest.java (94%) rename backend/src/test/java/com/digginroom/digginroom/{ => member}/service/MemberServiceTest.java (98%) rename backend/src/test/java/com/digginroom/digginroom/{ => room}/controller/RoomControllerTest.java (99%) rename backend/src/test/java/com/digginroom/digginroom/{ => room}/domain/RoomTest.java (93%) rename backend/src/test/java/com/digginroom/digginroom/{ => room}/domain/TrackTest.java (94%) rename backend/src/test/java/com/digginroom/digginroom/{ => room}/repository/RoomRepositoryTest.java (90%) rename backend/src/test/java/com/digginroom/digginroom/{ => room}/service/RoomServiceTest.java (99%) diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/ControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/ControllerTest.java similarity index 92% rename from backend/src/test/java/com/digginroom/digginroom/controller/ControllerTest.java rename to backend/src/test/java/com/digginroom/digginroom/ControllerTest.java index 5907bf070..dd3a8bdab 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/ControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/ControllerTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom; import com.digginroom.digginroom.util.DatabaseCleanerExtension; @@ -20,7 +20,7 @@ public abstract class ControllerTest { private int port; @BeforeEach - void setUp() { + public void setUp() { RestAssured.port = port; } } diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/CommentControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/comment/controller/CommentControllerTest.java similarity index 98% rename from backend/src/test/java/com/digginroom/digginroom/controller/CommentControllerTest.java rename to backend/src/test/java/com/digginroom/digginroom/comment/controller/CommentControllerTest.java index aea0e78fd..57b3e0f40 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/CommentControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/comment/controller/CommentControllerTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom.comment.controller; import static com.digginroom.digginroom.TestFixture.COMMENT_UPDATE_REQUEST; import static com.digginroom.digginroom.TestFixture.MEMBER2_LOGIN_REQUEST; @@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat; import com.digginroom.digginroom.TestFixture; +import com.digginroom.digginroom.ControllerTest; import com.digginroom.digginroom.domain.comment.Comment; import com.digginroom.digginroom.domain.member.Member; import com.digginroom.digginroom.domain.room.Room; @@ -47,7 +48,7 @@ class CommentControllerTest extends ControllerTest { @Override @BeforeEach - void setUp() { + public void setUp() { super.setUp(); 파워 = memberRepository.save(파워()); memberRepository.save(블랙캣()); diff --git a/backend/src/test/java/com/digginroom/digginroom/repository/CommentRepositoryTest.java b/backend/src/test/java/com/digginroom/digginroom/comment/repository/CommentRepositoryTest.java similarity index 97% rename from backend/src/test/java/com/digginroom/digginroom/repository/CommentRepositoryTest.java rename to backend/src/test/java/com/digginroom/digginroom/comment/repository/CommentRepositoryTest.java index 942b43adf..ee53f8ec0 100644 --- a/backend/src/test/java/com/digginroom/digginroom/repository/CommentRepositoryTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/comment/repository/CommentRepositoryTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.repository; +package com.digginroom.digginroom.comment.repository; import static com.digginroom.digginroom.TestFixture.블랙캣; import static com.digginroom.digginroom.TestFixture.파워; @@ -9,6 +9,7 @@ import com.digginroom.digginroom.domain.comment.Comment; import com.digginroom.digginroom.domain.member.Member; import com.digginroom.digginroom.exception.CommentException; +import com.digginroom.digginroom.repository.CommentRepository; import com.digginroom.digginroom.util.DatabaseCleanerExtension; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; diff --git a/backend/src/test/java/com/digginroom/digginroom/service/CommentServiceTest.java b/backend/src/test/java/com/digginroom/digginroom/comment/service/CommentServiceTest.java similarity index 97% rename from backend/src/test/java/com/digginroom/digginroom/service/CommentServiceTest.java rename to backend/src/test/java/com/digginroom/digginroom/comment/service/CommentServiceTest.java index 8b97398d9..d3b524c80 100644 --- a/backend/src/test/java/com/digginroom/digginroom/service/CommentServiceTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/comment/service/CommentServiceTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.service; +package com.digginroom.digginroom.comment.service; import static com.digginroom.digginroom.TestFixture.블랙캣; import static org.assertj.core.api.Assertions.assertThat; @@ -10,6 +10,7 @@ import com.digginroom.digginroom.exception.CommentException.InvalidLastCommentIdException; import com.digginroom.digginroom.repository.CommentRepository; import com.digginroom.digginroom.repository.MemberRepository; +import com.digginroom.digginroom.service.CommentService; import com.digginroom.digginroom.service.dto.CommentResponse; import com.digginroom.digginroom.service.dto.CommentsResponse; import java.util.List; diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/GlobalExceptionHandlerTest.java b/backend/src/test/java/com/digginroom/digginroom/exception/GlobalExceptionHandlerTest.java similarity index 88% rename from backend/src/test/java/com/digginroom/digginroom/controller/GlobalExceptionHandlerTest.java rename to backend/src/test/java/com/digginroom/digginroom/exception/GlobalExceptionHandlerTest.java index 74c6c8c4d..bbe0dbde4 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/GlobalExceptionHandlerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/exception/GlobalExceptionHandlerTest.java @@ -1,7 +1,8 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom.exception; import static org.hamcrest.Matchers.equalTo; +import com.digginroom.digginroom.ControllerTest; import io.restassured.RestAssured; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/com/digginroom/digginroom/feedback/controller/FeedbackControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/feedback/controller/FeedbackControllerTest.java index a9e0dc94f..8bc34f600 100644 --- a/backend/src/test/java/com/digginroom/digginroom/feedback/controller/FeedbackControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/feedback/controller/FeedbackControllerTest.java @@ -5,7 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import com.digginroom.digginroom.TestFixture; -import com.digginroom.digginroom.controller.ControllerTest; +import com.digginroom.digginroom.ControllerTest; import com.digginroom.digginroom.feedback.domain.Feedback; import com.digginroom.digginroom.feedback.dto.FeedbackRequest; import com.digginroom.digginroom.feedback.dto.FeedbackResponse; diff --git a/backend/src/test/java/com/digginroom/digginroom/feedback/FeedbackServiceTest.java b/backend/src/test/java/com/digginroom/digginroom/feedback/service/FeedbackServiceTest.java similarity index 94% rename from backend/src/test/java/com/digginroom/digginroom/feedback/FeedbackServiceTest.java rename to backend/src/test/java/com/digginroom/digginroom/feedback/service/FeedbackServiceTest.java index 590e92b21..cbfa43571 100644 --- a/backend/src/test/java/com/digginroom/digginroom/feedback/FeedbackServiceTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/feedback/service/FeedbackServiceTest.java @@ -1,6 +1,7 @@ -package com.digginroom.digginroom.feedback; +package com.digginroom.digginroom.feedback.service; import com.digginroom.digginroom.domain.member.Member; +import com.digginroom.digginroom.feedback.FeedbackService; import com.digginroom.digginroom.feedback.domain.Feedback; import com.digginroom.digginroom.feedback.dto.FeedbackRequest; import com.digginroom.digginroom.feedback.dto.FeedbackResponse; diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/MemberArgumentResolverTest.java b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberArgumentResolverTest.java similarity index 93% rename from backend/src/test/java/com/digginroom/digginroom/controller/MemberArgumentResolverTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/controller/MemberArgumentResolverTest.java index 3c896c82f..e02da307b 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/MemberArgumentResolverTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberArgumentResolverTest.java @@ -1,7 +1,8 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom.member.controller; import static org.hamcrest.Matchers.equalTo; +import com.digginroom.digginroom.ControllerTest; import com.digginroom.digginroom.service.dto.ErrorResponse; import io.restassured.RestAssured; import io.restassured.http.ContentType; diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/MemberJoinControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberJoinControllerTest.java similarity index 94% rename from backend/src/test/java/com/digginroom/digginroom/controller/MemberJoinControllerTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/controller/MemberJoinControllerTest.java index 0b6a756ab..1ccab5959 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/MemberJoinControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberJoinControllerTest.java @@ -1,8 +1,9 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom.member.controller; import static org.hamcrest.Matchers.equalTo; import com.digginroom.digginroom.TestFixture; +import com.digginroom.digginroom.ControllerTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/MemberLoginControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberLoginControllerTest.java similarity index 96% rename from backend/src/test/java/com/digginroom/digginroom/controller/MemberLoginControllerTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/controller/MemberLoginControllerTest.java index a335a7ac6..891d74b1d 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/MemberLoginControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberLoginControllerTest.java @@ -1,5 +1,6 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom.member.controller; +import com.digginroom.digginroom.ControllerTest; import com.digginroom.digginroom.service.dto.MemberLoginRequest; import com.digginroom.digginroom.repository.MemberRepository; import io.restassured.RestAssured; @@ -23,7 +24,7 @@ class MemberLoginControllerTest extends ControllerTest { @Override @BeforeEach - void setUp() { + public void setUp() { super.setUp(); memberRepository.save(파워()); } diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/MemberOperationControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberOperationControllerTest.java similarity index 97% rename from backend/src/test/java/com/digginroom/digginroom/controller/MemberOperationControllerTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/controller/MemberOperationControllerTest.java index 0b35956c8..ac99bfc86 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/MemberOperationControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberOperationControllerTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom.member.controller; import static com.digginroom.digginroom.TestFixture.MEMBER_LOGIN_REQUEST; import static com.digginroom.digginroom.domain.Genre.DANCE; @@ -6,6 +6,7 @@ import static com.digginroom.digginroom.domain.Genre.ROCK; import com.digginroom.digginroom.TestFixture; +import com.digginroom.digginroom.ControllerTest; import com.digginroom.digginroom.service.dto.FavoriteGenresRequest; import com.digginroom.digginroom.service.dto.MemberDetailsResponse; import io.restassured.RestAssured; diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/dto/MemberSaveRequestTest.java b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberSaveRequestTest.java similarity index 98% rename from backend/src/test/java/com/digginroom/digginroom/controller/dto/MemberSaveRequestTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/controller/MemberSaveRequestTest.java index 734b9fd51..c4a848efd 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/dto/MemberSaveRequestTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberSaveRequestTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.controller.dto; +package com.digginroom.digginroom.member.controller; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/backend/src/test/java/com/digginroom/digginroom/domain/GenreTest.java b/backend/src/test/java/com/digginroom/digginroom/member/domain/GenreTest.java similarity index 93% rename from backend/src/test/java/com/digginroom/digginroom/domain/GenreTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/domain/GenreTest.java index 0e14933fd..60a0c463f 100644 --- a/backend/src/test/java/com/digginroom/digginroom/domain/GenreTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/domain/GenreTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.domain; +package com.digginroom.digginroom.member.domain; import static com.digginroom.digginroom.domain.Genre.of; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/backend/src/test/java/com/digginroom/digginroom/domain/MemberGenreTest.java b/backend/src/test/java/com/digginroom/digginroom/member/domain/MemberGenreTest.java similarity index 93% rename from backend/src/test/java/com/digginroom/digginroom/domain/MemberGenreTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/domain/MemberGenreTest.java index ad54be83b..8e1c14af5 100644 --- a/backend/src/test/java/com/digginroom/digginroom/domain/MemberGenreTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/domain/MemberGenreTest.java @@ -1,8 +1,9 @@ -package com.digginroom.digginroom.domain; +package com.digginroom.digginroom.member.domain; import static com.digginroom.digginroom.TestFixture.파워; import static org.assertj.core.api.Assertions.assertThat; +import com.digginroom.digginroom.domain.Genre; import com.digginroom.digginroom.domain.member.MemberGenre; import com.digginroom.digginroom.domain.member.WeightFactor; import com.digginroom.digginroom.domain.member.WeightStatus; diff --git a/backend/src/test/java/com/digginroom/digginroom/domain/MemberTest.java b/backend/src/test/java/com/digginroom/digginroom/member/domain/MemberTest.java similarity index 98% rename from backend/src/test/java/com/digginroom/digginroom/domain/MemberTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/domain/MemberTest.java index d250ae94c..c0cc5a9e6 100644 --- a/backend/src/test/java/com/digginroom/digginroom/domain/MemberTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/domain/MemberTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.domain; +package com.digginroom.digginroom.member.domain; import static com.digginroom.digginroom.TestFixture.나무; import static com.digginroom.digginroom.TestFixture.파워; @@ -15,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import com.digginroom.digginroom.domain.Genre; import com.digginroom.digginroom.domain.member.Member; import com.digginroom.digginroom.domain.room.Room; import com.digginroom.digginroom.exception.MemberException.DuplicatedFavoriteException; diff --git a/backend/src/test/java/com/digginroom/digginroom/domain/PasswordTest.java b/backend/src/test/java/com/digginroom/digginroom/member/domain/PasswordTest.java similarity index 97% rename from backend/src/test/java/com/digginroom/digginroom/domain/PasswordTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/domain/PasswordTest.java index 65454fe01..ea136b70b 100644 --- a/backend/src/test/java/com/digginroom/digginroom/domain/PasswordTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/domain/PasswordTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.domain; +package com.digginroom.digginroom.member.domain; import static org.assertj.core.api.Assertions.assertThat; diff --git a/backend/src/test/java/com/digginroom/digginroom/domain/member/ProviderTest.java b/backend/src/test/java/com/digginroom/digginroom/member/domain/member/ProviderTest.java similarity index 76% rename from backend/src/test/java/com/digginroom/digginroom/domain/member/ProviderTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/domain/member/ProviderTest.java index 5ecf793bb..37fd50bf8 100644 --- a/backend/src/test/java/com/digginroom/digginroom/domain/member/ProviderTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/domain/member/ProviderTest.java @@ -1,5 +1,7 @@ -package com.digginroom.digginroom.domain.member; +package com.digginroom.digginroom.member.domain.member; +import com.digginroom.digginroom.domain.member.Provider; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -14,7 +16,7 @@ class ProviderTest { @Test void URL에_맞는_프로바이더를_찾는다() { - assertThat(Provider.of(ID_TOKEN_ISSUER_GOOGLE)).get().isEqualTo(Provider.GOOGLE); + Assertions.assertThat(Provider.of(ID_TOKEN_ISSUER_GOOGLE)).get().isEqualTo(Provider.GOOGLE); assertThat(Provider.of(ID_TOKEN_ISSUER_KAKAO)).get().isEqualTo(Provider.KAKAO); } diff --git a/backend/src/test/java/com/digginroom/digginroom/util/DigginRoomPasswordEncoderTest.java b/backend/src/test/java/com/digginroom/digginroom/member/domain/password/DigginRoomPasswordEncoderTest.java similarity index 88% rename from backend/src/test/java/com/digginroom/digginroom/util/DigginRoomPasswordEncoderTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/domain/password/DigginRoomPasswordEncoderTest.java index 9bd3d1b58..b8d1d4a22 100644 --- a/backend/src/test/java/com/digginroom/digginroom/util/DigginRoomPasswordEncoderTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/domain/password/DigginRoomPasswordEncoderTest.java @@ -1,7 +1,8 @@ -package com.digginroom.digginroom.util; +package com.digginroom.digginroom.member.domain.password; import static org.assertj.core.api.Assertions.assertThat; +import com.digginroom.digginroom.util.DigginRoomPasswordEncoder; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/com/digginroom/digginroom/util/HashAlgorithmTest.java b/backend/src/test/java/com/digginroom/digginroom/member/domain/password/HashAlgorithmTest.java similarity index 87% rename from backend/src/test/java/com/digginroom/digginroom/util/HashAlgorithmTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/domain/password/HashAlgorithmTest.java index 1db9caf63..d1ec412b3 100644 --- a/backend/src/test/java/com/digginroom/digginroom/util/HashAlgorithmTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/domain/password/HashAlgorithmTest.java @@ -1,7 +1,8 @@ -package com.digginroom.digginroom.util; +package com.digginroom.digginroom.member.domain.password; import static org.assertj.core.api.Assertions.assertThat; +import com.digginroom.digginroom.util.HashAlgorithm; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/src/test/java/com/digginroom/digginroom/repository/MemberRepositoryTest.java b/backend/src/test/java/com/digginroom/digginroom/member/repository/MemberRepositoryTest.java similarity index 94% rename from backend/src/test/java/com/digginroom/digginroom/repository/MemberRepositoryTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/repository/MemberRepositoryTest.java index 88d42e6fc..b0483bb78 100644 --- a/backend/src/test/java/com/digginroom/digginroom/repository/MemberRepositoryTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/repository/MemberRepositoryTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.repository; +package com.digginroom.digginroom.member.repository; import static com.digginroom.digginroom.TestFixture.파워; import static org.assertj.core.api.Assertions.assertThat; @@ -7,6 +7,7 @@ import com.digginroom.digginroom.domain.Genre; import com.digginroom.digginroom.domain.member.Member; import com.digginroom.digginroom.exception.MemberException; +import com.digginroom.digginroom.repository.MemberRepository; import jakarta.persistence.EntityManager; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/src/test/java/com/digginroom/digginroom/service/MemberServiceTest.java b/backend/src/test/java/com/digginroom/digginroom/member/service/MemberServiceTest.java similarity index 98% rename from backend/src/test/java/com/digginroom/digginroom/service/MemberServiceTest.java rename to backend/src/test/java/com/digginroom/digginroom/member/service/MemberServiceTest.java index 48df5869c..710479f14 100644 --- a/backend/src/test/java/com/digginroom/digginroom/service/MemberServiceTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/service/MemberServiceTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.service; +package com.digginroom.digginroom.member.service; import static com.digginroom.digginroom.TestFixture.ID_TOKEN_PAYLOAD; import static com.digginroom.digginroom.TestFixture.MEMBER_PASSWORD; @@ -17,6 +17,7 @@ import com.digginroom.digginroom.exception.MemberException; import com.digginroom.digginroom.oauth.IdTokenResolver; import com.digginroom.digginroom.repository.MemberRepository; +import com.digginroom.digginroom.service.MemberService; import com.digginroom.digginroom.service.dto.FavoriteGenresRequest; import com.digginroom.digginroom.service.dto.MemberLoginRequest; import com.digginroom.digginroom.service.dto.MemberLoginResponse; diff --git a/backend/src/test/java/com/digginroom/digginroom/controller/RoomControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/room/controller/RoomControllerTest.java similarity index 99% rename from backend/src/test/java/com/digginroom/digginroom/controller/RoomControllerTest.java rename to backend/src/test/java/com/digginroom/digginroom/room/controller/RoomControllerTest.java index 94915424a..e77a4ec0f 100644 --- a/backend/src/test/java/com/digginroom/digginroom/controller/RoomControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/room/controller/RoomControllerTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom.room.controller; import static com.digginroom.digginroom.TestFixture.MEMBER_LOGIN_REQUEST; import static com.digginroom.digginroom.TestFixture.MEMBER_PASSWORD; @@ -10,6 +10,7 @@ import static org.hamcrest.Matchers.emptyCollectionOf; import static org.hamcrest.Matchers.hasSize; +import com.digginroom.digginroom.ControllerTest; import com.digginroom.digginroom.service.dto.MemberLoginRequest; import com.digginroom.digginroom.service.dto.RoomRequest; import com.digginroom.digginroom.service.dto.RoomResponse; @@ -38,7 +39,7 @@ class RoomControllerTest extends ControllerTest { @Override @BeforeEach - void setUp() { + public void setUp() { super.setUp(); memberRepository.save(파워()); room1 = roomRepository.save(나무()); diff --git a/backend/src/test/java/com/digginroom/digginroom/domain/RoomTest.java b/backend/src/test/java/com/digginroom/digginroom/room/domain/RoomTest.java similarity index 93% rename from backend/src/test/java/com/digginroom/digginroom/domain/RoomTest.java rename to backend/src/test/java/com/digginroom/digginroom/room/domain/RoomTest.java index 80dcfa2dc..9fd3f50b0 100644 --- a/backend/src/test/java/com/digginroom/digginroom/domain/RoomTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/room/domain/RoomTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.domain; +package com.digginroom.digginroom.room.domain; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/backend/src/test/java/com/digginroom/digginroom/domain/TrackTest.java b/backend/src/test/java/com/digginroom/digginroom/room/domain/TrackTest.java similarity index 94% rename from backend/src/test/java/com/digginroom/digginroom/domain/TrackTest.java rename to backend/src/test/java/com/digginroom/digginroom/room/domain/TrackTest.java index 232be4497..ef139ee98 100644 --- a/backend/src/test/java/com/digginroom/digginroom/domain/TrackTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/room/domain/TrackTest.java @@ -1,8 +1,9 @@ -package com.digginroom.digginroom.domain; +package com.digginroom.digginroom.room.domain; import static org.assertj.core.api.Assertions.assertThat; import com.digginroom.digginroom.TestFixture; +import com.digginroom.digginroom.domain.Genre; import com.digginroom.digginroom.domain.room.Room; import com.digginroom.digginroom.domain.track.Track; import jakarta.persistence.EntityManager; diff --git a/backend/src/test/java/com/digginroom/digginroom/repository/RoomRepositoryTest.java b/backend/src/test/java/com/digginroom/digginroom/room/repository/RoomRepositoryTest.java similarity index 90% rename from backend/src/test/java/com/digginroom/digginroom/repository/RoomRepositoryTest.java rename to backend/src/test/java/com/digginroom/digginroom/room/repository/RoomRepositoryTest.java index 542c77b57..257982450 100644 --- a/backend/src/test/java/com/digginroom/digginroom/repository/RoomRepositoryTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/room/repository/RoomRepositoryTest.java @@ -1,9 +1,10 @@ -package com.digginroom.digginroom.repository; +package com.digginroom.digginroom.room.repository; import static com.digginroom.digginroom.TestFixture.나무; import static org.assertj.core.api.Assertions.assertThat; import com.digginroom.digginroom.domain.room.Room; +import com.digginroom.digginroom.repository.RoomRepository; import jakarta.persistence.EntityManager; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; diff --git a/backend/src/test/java/com/digginroom/digginroom/service/RoomServiceTest.java b/backend/src/test/java/com/digginroom/digginroom/room/service/RoomServiceTest.java similarity index 99% rename from backend/src/test/java/com/digginroom/digginroom/service/RoomServiceTest.java rename to backend/src/test/java/com/digginroom/digginroom/room/service/RoomServiceTest.java index b455f386e..3aef8ee4e 100644 --- a/backend/src/test/java/com/digginroom/digginroom/service/RoomServiceTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/room/service/RoomServiceTest.java @@ -1,4 +1,4 @@ -package com.digginroom.digginroom.service; +package com.digginroom.digginroom.room.service; import static com.digginroom.digginroom.TestFixture.PASSWORD; import static com.digginroom.digginroom.TestFixture.나무; @@ -16,6 +16,7 @@ import com.digginroom.digginroom.exception.RoomException.NotScrappedException; import com.digginroom.digginroom.repository.MemberRepository; import com.digginroom.digginroom.repository.RoomRepository; +import com.digginroom.digginroom.service.RoomService; import com.digginroom.digginroom.service.dto.RoomResponse; import com.digginroom.digginroom.service.dto.RoomsResponse; import com.digginroom.digginroom.service.dto.TrackResponse; From 860fb21236c04a8dfd361f4d4ea318e98a266a7d Mon Sep 17 00:00:00 2001 From: songusika Date: Fri, 17 Nov 2023 19:07:50 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EB=B3=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../digginroom/comment/repository/CommentRepositoryTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/test/java/com/digginroom/digginroom/comment/repository/CommentRepositoryTest.java b/backend/src/test/java/com/digginroom/digginroom/comment/repository/CommentRepositoryTest.java index ee53f8ec0..751378487 100644 --- a/backend/src/test/java/com/digginroom/digginroom/comment/repository/CommentRepositoryTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/comment/repository/CommentRepositoryTest.java @@ -74,8 +74,7 @@ void init() { PageRequest pageRequest = PageRequest.of(0, 10); Slice comments = commentRepository.getCommentsByCursor(1L, 15L, pageRequest); - System.out.println("===================================="); - System.out.println(commentRepository.count()); + assertThat(comments.getContent()) .hasSize(10) .map(BaseEntity::getId) From 12b171323ac8bd8ad02c0c6127d0a92696c723c0 Mon Sep 17 00:00:00 2001 From: 0chil <0@chll.it> Date: Thu, 23 Nov 2023 14:09:59 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EC=99=80=20ControllerTest=20?= =?UTF-8?q?=EA=B0=84=20=EA=B2=B0=ED=95=A9=20=EC=99=84=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../digginroom/digginroom/ControllerTest.java | 2 +- .../controller/CommentControllerTest.java | 98 +++++++++---------- .../controller/MemberLoginControllerTest.java | 11 +-- .../room/controller/RoomControllerTest.java | 33 +++---- 4 files changed, 70 insertions(+), 74 deletions(-) diff --git a/backend/src/test/java/com/digginroom/digginroom/ControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/ControllerTest.java index dd3a8bdab..9f79cf9af 100644 --- a/backend/src/test/java/com/digginroom/digginroom/ControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/ControllerTest.java @@ -20,7 +20,7 @@ public abstract class ControllerTest { private int port; @BeforeEach - public void setUp() { + void setPortUp() { RestAssured.port = port; } } diff --git a/backend/src/test/java/com/digginroom/digginroom/comment/controller/CommentControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/comment/controller/CommentControllerTest.java index 57b3e0f40..357028148 100644 --- a/backend/src/test/java/com/digginroom/digginroom/comment/controller/CommentControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/comment/controller/CommentControllerTest.java @@ -1,16 +1,7 @@ package com.digginroom.digginroom.comment.controller; -import static com.digginroom.digginroom.TestFixture.COMMENT_UPDATE_REQUEST; -import static com.digginroom.digginroom.TestFixture.MEMBER2_LOGIN_REQUEST; -import static com.digginroom.digginroom.TestFixture.MEMBER_LOGIN_REQUEST; -import static com.digginroom.digginroom.TestFixture.나무; -import static com.digginroom.digginroom.TestFixture.블랙캣; -import static com.digginroom.digginroom.TestFixture.차이; -import static com.digginroom.digginroom.TestFixture.파워; -import static org.assertj.core.api.Assertions.assertThat; - -import com.digginroom.digginroom.TestFixture; import com.digginroom.digginroom.ControllerTest; +import com.digginroom.digginroom.TestFixture; import com.digginroom.digginroom.domain.comment.Comment; import com.digginroom.digginroom.domain.member.Member; import com.digginroom.digginroom.domain.room.Room; @@ -24,14 +15,24 @@ import io.restassured.RestAssured; import io.restassured.http.ContentType; import io.restassured.response.Response; -import java.util.List; -import java.util.stream.Collectors; import org.hamcrest.Matchers; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import java.util.List; +import java.util.stream.Collectors; + +import static com.digginroom.digginroom.TestFixture.COMMENT_UPDATE_REQUEST; +import static com.digginroom.digginroom.TestFixture.MEMBER2_LOGIN_REQUEST; +import static com.digginroom.digginroom.TestFixture.MEMBER_LOGIN_REQUEST; +import static com.digginroom.digginroom.TestFixture.나무; +import static com.digginroom.digginroom.TestFixture.블랙캣; +import static com.digginroom.digginroom.TestFixture.차이; +import static com.digginroom.digginroom.TestFixture.파워; +import static org.assertj.core.api.Assertions.assertThat; + @SuppressWarnings("NonAsciiCharacters") class CommentControllerTest extends ControllerTest { @@ -46,10 +47,8 @@ class CommentControllerTest extends ControllerTest { private Room 차이; private Member 파워; - @Override @BeforeEach - public void setUp() { - super.setUp(); + void setUp() { 파워 = memberRepository.save(파워()); memberRepository.save(블랙캣()); 나무 = roomRepository.save(나무()); @@ -58,7 +57,7 @@ public void setUp() { @Test void 댓글을_작성_할_수_있다() { - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(cookie) @@ -76,7 +75,7 @@ public void setUp() { @Test void 댓글은_500자_이하여야한다() { - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(cookie) @@ -89,7 +88,7 @@ public void setUp() { @Test void 댓글은_1자_이상이여야한다() { - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(cookie) @@ -102,9 +101,8 @@ public void setUp() { @Test void 유저는_자신의_댓글을_삭제할_수_있다() { - String cookie = login(MEMBER_LOGIN_REQUEST); - - CommentResponse commentResponse = commentRequest(cookie, "댓글"); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); + CommentResponse commentResponse = commentWith(new CommentRequest("댓글"), cookie); RestAssured.given().log().all() .cookie(cookie) @@ -116,10 +114,10 @@ public void setUp() { @Test void 유저는_다른_유저의_댓글을_삭제할_수_없다() { - String powerCookie = login(MEMBER_LOGIN_REQUEST); - String blackcatCookie = login(MEMBER2_LOGIN_REQUEST); + String powerCookie = getCookieWith(MEMBER_LOGIN_REQUEST); + String blackcatCookie = getCookieWith(MEMBER2_LOGIN_REQUEST); - CommentResponse commentResponse = commentRequest(blackcatCookie, "댓글"); + CommentResponse commentResponse = commentWith(new CommentRequest("댓글"), blackcatCookie); RestAssured.given().log().all() .cookie(powerCookie) @@ -131,7 +129,7 @@ public void setUp() { @Test void 유저는_존재하지_않은_댓글을_삭제할_수_없다() { - String powerCookie = login(MEMBER_LOGIN_REQUEST); + String powerCookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(powerCookie) @@ -147,7 +145,7 @@ public void setUp() { commentRepository.save(new Comment(나무.getId(), "댓글" + i, 파워)); } - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); List comments = RestAssured.given().log().all() .cookie(cookie) @@ -172,7 +170,7 @@ public void setUp() { commentRepository.save(new Comment(나무.getId(), "댓글" + i, 파워)); } - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); List comments = RestAssured.given().log().all() .cookie(cookie) @@ -195,7 +193,7 @@ public void setUp() { commentRepository.save(new Comment(나무.getId(), "댓글" + i, 파워)); } - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); List comments = RestAssured.given().log().all() .cookie(cookie) @@ -218,7 +216,7 @@ public void setUp() { commentRepository.save(new Comment(나무.getId(), "댓글" + i, 파워)); } - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); List comments = RestAssured.given().log().all() .cookie(cookie) @@ -235,30 +233,10 @@ public void setUp() { assertThat(comments).containsExactly("댓글6", "댓글5"); } - private static String login(final MemberLoginRequest loginRequest) { - Response response = RestAssured.given().log().all() - .body(loginRequest) - .contentType(ContentType.JSON) - .when() - .post("/login"); - - return response.header("Set-Cookie"); - } - - private CommentResponse commentRequest(final String cookie, final String comment) { - return RestAssured.given().log().all() - .cookie(cookie) - .contentType(ContentType.JSON) - .body(new CommentRequest(comment)) - .when().post("/rooms/" + 나무.getId() + "/comments").then().log() - .all().statusCode(HttpStatus.CREATED.value()) - .extract().as(CommentResponse.class); - } - @Test void 유저는_자신의_댓글을_수정할_수_있다() { Comment comment = commentRepository.save(new Comment(나무.getId(), "댓글1", 파워)); - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(cookie) @@ -272,4 +250,24 @@ private CommentResponse commentRequest(final String cookie, final String comment Comment updatedComment = commentRepository.getCommentById(comment.getId()); assertThat(updatedComment.getComment()).isEqualTo(COMMENT_UPDATE_REQUEST.comment()); } + + private String getCookieWith(final MemberLoginRequest loginRequest) { + Response response = RestAssured.given().log().all() + .body(loginRequest) + .contentType(ContentType.JSON) + .when() + .post("/login"); + + return response.header("Set-Cookie"); + } + + private CommentResponse commentWith(final CommentRequest comment, final String cookie) { + return RestAssured.given().log().all() + .cookie(cookie) + .contentType(ContentType.JSON) + .body(comment) + .when().post("/rooms/" + 나무.getId() + "/comments").then().log() + .all().statusCode(HttpStatus.CREATED.value()) + .extract().as(CommentResponse.class); + } } diff --git a/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberLoginControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberLoginControllerTest.java index 891d74b1d..2ff1f8edb 100644 --- a/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberLoginControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/member/controller/MemberLoginControllerTest.java @@ -1,8 +1,8 @@ package com.digginroom.digginroom.member.controller; import com.digginroom.digginroom.ControllerTest; -import com.digginroom.digginroom.service.dto.MemberLoginRequest; import com.digginroom.digginroom.repository.MemberRepository; +import com.digginroom.digginroom.service.dto.MemberLoginRequest; import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.hamcrest.Matchers; @@ -13,7 +13,9 @@ import static com.digginroom.digginroom.TestFixture.MEMBER_LOGIN_REQUEST; import static com.digginroom.digginroom.TestFixture.파워; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.isA; @SuppressWarnings("NonAsciiCharacters") class MemberLoginControllerTest extends ControllerTest { @@ -21,11 +23,8 @@ class MemberLoginControllerTest extends ControllerTest { @Autowired private MemberRepository memberRepository; - - @Override @BeforeEach - public void setUp() { - super.setUp(); + void setUp() { memberRepository.save(파워()); } diff --git a/backend/src/test/java/com/digginroom/digginroom/room/controller/RoomControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/room/controller/RoomControllerTest.java index e77a4ec0f..a74233abe 100644 --- a/backend/src/test/java/com/digginroom/digginroom/room/controller/RoomControllerTest.java +++ b/backend/src/test/java/com/digginroom/digginroom/room/controller/RoomControllerTest.java @@ -1,32 +1,33 @@ package com.digginroom.digginroom.room.controller; -import static com.digginroom.digginroom.TestFixture.MEMBER_LOGIN_REQUEST; -import static com.digginroom.digginroom.TestFixture.MEMBER_PASSWORD; -import static com.digginroom.digginroom.TestFixture.MEMBER_USERNAME; -import static com.digginroom.digginroom.TestFixture.나무; -import static com.digginroom.digginroom.TestFixture.차이; -import static com.digginroom.digginroom.TestFixture.파워; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.emptyCollectionOf; -import static org.hamcrest.Matchers.hasSize; - import com.digginroom.digginroom.ControllerTest; -import com.digginroom.digginroom.service.dto.MemberLoginRequest; -import com.digginroom.digginroom.service.dto.RoomRequest; -import com.digginroom.digginroom.service.dto.RoomResponse; import com.digginroom.digginroom.domain.room.Room; import com.digginroom.digginroom.repository.MemberRepository; import com.digginroom.digginroom.repository.RoomRepository; +import com.digginroom.digginroom.service.dto.MemberLoginRequest; +import com.digginroom.digginroom.service.dto.RoomRequest; +import com.digginroom.digginroom.service.dto.RoomResponse; import io.restassured.RestAssured; import io.restassured.http.ContentType; import io.restassured.response.Response; -import java.util.List; import org.hamcrest.Matchers; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import java.util.List; + +import static com.digginroom.digginroom.TestFixture.MEMBER_LOGIN_REQUEST; +import static com.digginroom.digginroom.TestFixture.MEMBER_PASSWORD; +import static com.digginroom.digginroom.TestFixture.MEMBER_USERNAME; +import static com.digginroom.digginroom.TestFixture.나무; +import static com.digginroom.digginroom.TestFixture.차이; +import static com.digginroom.digginroom.TestFixture.파워; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.emptyCollectionOf; +import static org.hamcrest.Matchers.hasSize; + @SuppressWarnings("NonAsciiCharacters") class RoomControllerTest extends ControllerTest { @@ -37,10 +38,8 @@ class RoomControllerTest extends ControllerTest { private Room room1; private Room room2; - @Override @BeforeEach - public void setUp() { - super.setUp(); + void setUp() { memberRepository.save(파워()); room1 = roomRepository.save(나무()); room2 = roomRepository.save(차이());