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..9f79cf9af 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() { + void setPortUp() { RestAssured.port = port; } } 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/controller/CommentControllerTest.java b/backend/src/test/java/com/digginroom/digginroom/comment/controller/CommentControllerTest.java similarity index 88% 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..357028148 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,14 +1,6 @@ -package com.digginroom.digginroom.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; +package com.digginroom.digginroom.comment.controller; +import com.digginroom.digginroom.ControllerTest; import com.digginroom.digginroom.TestFixture; import com.digginroom.digginroom.domain.comment.Comment; import com.digginroom.digginroom.domain.member.Member; @@ -23,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 { @@ -45,10 +47,8 @@ class CommentControllerTest extends ControllerTest { private Room 차이; private Member 파워; - @Override @BeforeEach void setUp() { - super.setUp(); 파워 = memberRepository.save(파워()); memberRepository.save(블랙캣()); 나무 = roomRepository.save(나무()); @@ -57,7 +57,7 @@ void setUp() { @Test void 댓글을_작성_할_수_있다() { - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(cookie) @@ -75,7 +75,7 @@ void setUp() { @Test void 댓글은_500자_이하여야한다() { - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(cookie) @@ -88,7 +88,7 @@ void setUp() { @Test void 댓글은_1자_이상이여야한다() { - String cookie = login(MEMBER_LOGIN_REQUEST); + String cookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(cookie) @@ -101,9 +101,8 @@ 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) @@ -115,10 +114,10 @@ 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) @@ -130,7 +129,7 @@ void setUp() { @Test void 유저는_존재하지_않은_댓글을_삭제할_수_없다() { - String powerCookie = login(MEMBER_LOGIN_REQUEST); + String powerCookie = getCookieWith(MEMBER_LOGIN_REQUEST); RestAssured.given().log().all() .cookie(powerCookie) @@ -146,7 +145,7 @@ 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) @@ -171,7 +170,7 @@ 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) @@ -194,7 +193,7 @@ 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) @@ -217,7 +216,7 @@ 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) @@ -234,30 +233,10 @@ 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) @@ -271,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/repository/CommentRepositoryTest.java b/backend/src/test/java/com/digginroom/digginroom/comment/repository/CommentRepositoryTest.java similarity index 88% 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 88617d071..751378487 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,27 +9,26 @@ 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; 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 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 93% 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..2ff1f8edb 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,7 +1,8 @@ -package com.digginroom.digginroom.controller; +package com.digginroom.digginroom.member.controller; -import com.digginroom.digginroom.service.dto.MemberLoginRequest; +import com.digginroom.digginroom.ControllerTest; 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; @@ -12,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 { @@ -20,11 +23,8 @@ class MemberLoginControllerTest extends ControllerTest { @Autowired private MemberRepository memberRepository; - - @Override @BeforeEach 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..a74233abe 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,31 +1,33 @@ -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; -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.service.dto.MemberLoginRequest; -import com.digginroom.digginroom.service.dto.RoomRequest; -import com.digginroom.digginroom.service.dto.RoomResponse; +import com.digginroom.digginroom.ControllerTest; 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 { @@ -36,10 +38,8 @@ class RoomControllerTest extends ControllerTest { private Room room1; private Room room2; - @Override @BeforeEach void setUp() { - super.setUp(); memberRepository.save(파워()); room1 = roomRepository.save(나무()); room2 = 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 74% 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 ff276bd25..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,22 +1,20 @@ -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; 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/room/service/RoomServiceTest.java similarity index 98% 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 ae168c37b..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.나무; @@ -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,10 @@ 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; import java.util.Collections; import java.util.List; import org.junit.jupiter.api.DisplayNameGeneration; @@ -32,7 +33,7 @@ @Transactional @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(ReplaceUnderscores.class) -@SpringBootTest(webEnvironment = WebEnvironment.NONE) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class RoomServiceTest { @Autowired