diff --git a/backend/baton/src/main/java/touch/baton/domain/tag/command/repository/TagCommandRepository.java b/backend/baton/src/main/java/touch/baton/domain/tag/command/repository/TagCommandRepository.java index e4d1e077d..187d4b72a 100644 --- a/backend/baton/src/main/java/touch/baton/domain/tag/command/repository/TagCommandRepository.java +++ b/backend/baton/src/main/java/touch/baton/domain/tag/command/repository/TagCommandRepository.java @@ -1,25 +1,12 @@ package touch.baton.domain.tag.command.repository; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import touch.baton.domain.common.vo.TagName; import touch.baton.domain.tag.command.Tag; -import touch.baton.domain.tag.command.vo.TagReducedName; -import java.util.List; import java.util.Optional; public interface TagCommandRepository extends JpaRepository { Optional findByTagName(final TagName tagName); - - @Query(""" - select t - from Tag t - where t.tagReducedName like :tagReducedName% - order by t.tagReducedName asc - limit 10 - """) - List readTagsByReducedName(@Param("tagReducedName") TagReducedName tagReducedName); } diff --git a/backend/baton/src/main/java/touch/baton/domain/tag/query/controller/TagQueryController.java b/backend/baton/src/main/java/touch/baton/domain/tag/query/controller/TagQueryController.java index 32fd148d3..d94506f47 100644 --- a/backend/baton/src/main/java/touch/baton/domain/tag/query/controller/TagQueryController.java +++ b/backend/baton/src/main/java/touch/baton/domain/tag/query/controller/TagQueryController.java @@ -7,11 +7,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import touch.baton.domain.tag.query.controller.response.TagSearchResponse; +import touch.baton.domain.tag.command.Tag; +import touch.baton.domain.tag.command.vo.TagReducedName; import touch.baton.domain.tag.query.controller.response.TagSearchResponses; import touch.baton.domain.tag.query.service.TagQueryService; -import java.util.Collections; import java.util.List; @RequiredArgsConstructor @@ -23,14 +23,9 @@ public class TagQueryController { @GetMapping("/search") public ResponseEntity readTagsByTagName(@Nullable @RequestParam(required = false) final String tagName) { - if (tagName == null || tagName.isBlank()) { - return ResponseEntity.ok().body(TagSearchResponses.Detail.from(Collections.emptyList())); - } + final TagReducedName tagReducedName = TagReducedName.nullableInstance(tagName); + final List foundTags = tagQueryService.readTagsByReducedName(tagReducedName, 10); - final List tagSearchResponses = tagQueryService.readTagsByReducedName(tagName).stream() - .map(TagSearchResponse.TagResponse::from) - .toList(); - - return ResponseEntity.ok(TagSearchResponses.Detail.from(tagSearchResponses)); + return ResponseEntity.ok(TagSearchResponses.Detail.from(foundTags)); } } diff --git a/backend/baton/src/main/java/touch/baton/domain/tag/query/controller/response/TagSearchResponses.java b/backend/baton/src/main/java/touch/baton/domain/tag/query/controller/response/TagSearchResponses.java index f58871384..5bd9be9ba 100644 --- a/backend/baton/src/main/java/touch/baton/domain/tag/query/controller/response/TagSearchResponses.java +++ b/backend/baton/src/main/java/touch/baton/domain/tag/query/controller/response/TagSearchResponses.java @@ -1,12 +1,19 @@ package touch.baton.domain.tag.query.controller.response; +import touch.baton.domain.tag.command.Tag; + import java.util.List; public record TagSearchResponses() { public record Detail(List data) { - public static Detail from(final List data) { - return new Detail(data); + + public static Detail from(final List tags) { + final List response = tags.stream() + .map(TagSearchResponse.TagResponse::from) + .toList(); + + return new Detail(response); } } } diff --git a/backend/baton/src/main/java/touch/baton/domain/tag/query/repository/TagQueryRepository.java b/backend/baton/src/main/java/touch/baton/domain/tag/query/repository/TagQueryRepository.java deleted file mode 100644 index eb01a4a7c..000000000 --- a/backend/baton/src/main/java/touch/baton/domain/tag/query/repository/TagQueryRepository.java +++ /dev/null @@ -1,25 +0,0 @@ -package touch.baton.domain.tag.query.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import touch.baton.domain.common.vo.TagName; -import touch.baton.domain.tag.command.Tag; -import touch.baton.domain.tag.command.vo.TagReducedName; - -import java.util.List; -import java.util.Optional; - -public interface TagQueryRepository extends JpaRepository { - - Optional findByTagName(final TagName tagName); - - @Query(""" - select t - from Tag t - where t.tagReducedName like :tagReducedName% - order by t.tagReducedName asc - limit 10 - """) - List readTagsByReducedName(@Param("tagReducedName") final TagReducedName tagReducedName); -} diff --git a/backend/baton/src/main/java/touch/baton/domain/tag/query/repository/TagQuerydslRepository.java b/backend/baton/src/main/java/touch/baton/domain/tag/query/repository/TagQuerydslRepository.java new file mode 100644 index 000000000..d1e74cd8b --- /dev/null +++ b/backend/baton/src/main/java/touch/baton/domain/tag/query/repository/TagQuerydslRepository.java @@ -0,0 +1,26 @@ +package touch.baton.domain.tag.query.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import touch.baton.domain.tag.command.Tag; +import touch.baton.domain.tag.command.vo.TagReducedName; + +import java.util.List; + +import static touch.baton.domain.tag.command.QTag.tag; + +@RequiredArgsConstructor +@Repository +public class TagQuerydslRepository { + + private final JPAQueryFactory queryFactory; + + public List findByTagReducedName(final TagReducedName tagReducedName, final int limit) { + return queryFactory.selectFrom(tag) + .where(tag.tagReducedName.value.startsWith(tagReducedName.getValue())) + .orderBy(tag.tagReducedName.value.asc(), tag.tagName.value.desc()) + .limit(limit) + .fetch(); + } +} diff --git a/backend/baton/src/main/java/touch/baton/domain/tag/query/service/TagQueryService.java b/backend/baton/src/main/java/touch/baton/domain/tag/query/service/TagQueryService.java index bb624ebd8..1fcee1ae1 100644 --- a/backend/baton/src/main/java/touch/baton/domain/tag/query/service/TagQueryService.java +++ b/backend/baton/src/main/java/touch/baton/domain/tag/query/service/TagQueryService.java @@ -5,8 +5,9 @@ import org.springframework.transaction.annotation.Transactional; import touch.baton.domain.tag.command.Tag; import touch.baton.domain.tag.command.vo.TagReducedName; -import touch.baton.domain.tag.query.repository.TagQueryRepository; +import touch.baton.domain.tag.query.repository.TagQuerydslRepository; +import java.util.Collections; import java.util.List; @RequiredArgsConstructor @@ -14,9 +15,13 @@ @Service public class TagQueryService { - private final TagQueryRepository tagQueryRepository; + private final TagQuerydslRepository tagQuerydslRepository; - public List readTagsByReducedName(final String tagName) { - return tagQueryRepository.readTagsByReducedName(TagReducedName.from(tagName)); + public List readTagsByReducedName(final TagReducedName tagReducedName, final int limit) { + if (tagReducedName == null || tagReducedName.getValue().isBlank()) { + return Collections.emptyList(); + } + + return tagQuerydslRepository.findByTagReducedName(tagReducedName, limit); } } diff --git a/backend/baton/src/test/java/touch/baton/assure/repository/TestTagQueryRepository.java b/backend/baton/src/test/java/touch/baton/assure/repository/TestTagQueryRepository.java deleted file mode 100644 index b67ad4b15..000000000 --- a/backend/baton/src/test/java/touch/baton/assure/repository/TestTagQueryRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package touch.baton.assure.repository; - -import touch.baton.domain.tag.query.repository.TagQueryRepository; - -public interface TestTagQueryRepository extends TagQueryRepository { -} diff --git a/backend/baton/src/test/java/touch/baton/assure/repository/TestTagQuerydslRepository.java b/backend/baton/src/test/java/touch/baton/assure/repository/TestTagQuerydslRepository.java new file mode 100644 index 000000000..d1f557b8f --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/assure/repository/TestTagQuerydslRepository.java @@ -0,0 +1,13 @@ +package touch.baton.assure.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.stereotype.Repository; +import touch.baton.domain.tag.query.repository.TagQuerydslRepository; + +@Repository +public class TestTagQuerydslRepository extends TagQuerydslRepository { + + public TestTagQuerydslRepository(final JPAQueryFactory queryFactory) { + super(queryFactory); + } +} diff --git a/backend/baton/src/test/java/touch/baton/assure/tag/query/TagReadAssuredTest.java b/backend/baton/src/test/java/touch/baton/assure/tag/query/TagReadAssuredTest.java index 12ba0db56..e491a3c53 100644 --- a/backend/baton/src/test/java/touch/baton/assure/tag/query/TagReadAssuredTest.java +++ b/backend/baton/src/test/java/touch/baton/assure/tag/query/TagReadAssuredTest.java @@ -2,57 +2,56 @@ import org.junit.jupiter.api.Test; import touch.baton.assure.runnerpost.support.command.RunnerPostCreateSupport; -import touch.baton.assure.tag.support.query.TagAssuredSupport; +import touch.baton.assure.tag.support.query.TagQuerySupport; import touch.baton.config.AssuredTestConfig; import touch.baton.config.infra.auth.oauth.authcode.FakeAuthCodes; import touch.baton.domain.tag.command.Tag; import touch.baton.domain.tag.command.vo.TagReducedName; +import touch.baton.domain.tag.query.controller.response.TagSearchResponses; import java.time.LocalDateTime; import java.util.List; import static touch.baton.assure.runnerpost.support.command.RunnerPostCreateSupport.러너_게시글_생성_요청; -import static touch.baton.assure.tag.support.query.TagAssuredSupport.태그_검색_Detail_응답; @SuppressWarnings("NonAsciiCharacters") class TagReadAssuredTest extends AssuredTestConfig { @Test - void 태그_검색에_성공한다() { + void 입력된_문자열로_태그_목록_검색에_성공한다() { // given final String 헤나_액세스_토큰 = oauthLoginTestManager.소셜_회원가입을_진행한_후_액세스_토큰을_반환한다(FakeAuthCodes.hyenaAuthCode()); - 러너_게시글_생성을_성공하고_러너_게시글_식별자값을_반환한다(헤나_액세스_토큰, List.of("java", "javascript", "script")); - final TagReducedName reducedName = TagReducedName.from("ja"); - final List 검색된_태그_목록 = tagRepository.readTagsByReducedName(reducedName); + 러너_게시글과_태그를_생성한다(헤나_액세스_토큰, List.of("java", "javascript", "script")); + + final TagReducedName 요청할_태그_이름 = TagReducedName.nullableInstance("ja"); // when, then - TagAssuredSupport + final List 검색된_태그_목록 = tagQueryRepository.findByTagReducedName(요청할_태그_이름, 10); + + TagQuerySupport .클라이언트_요청() - .액세스_토큰으로_로그인한다(헤나_액세스_토큰) - .태그_이름을_오름차순으로_10개_검색한다("ja") + .입력된_문자열로_태그_목록을_검색한다(요청할_태그_이름) .서버_응답() - .태그_검색_성공을_검증한다( - 태그_검색_Detail_응답(검색된_태그_목록) + .입력된_문자열로_태그_목록_검색_성공을_검증한다( + TagSearchResponses.Detail.from(검색된_태그_목록) ); } - private void 러너_게시글_생성을_성공하고_러너_게시글_식별자값을_반환한다(final String 헤나_액세스_토큰, final List 태그_목록) { + private void 러너_게시글과_태그를_생성한다(final String 액세스_토큰, final List 태그_목록) { RunnerPostCreateSupport .클라이언트_요청() - .액세스_토큰으로_로그인한다(헤나_액세스_토큰) - .러너_게시글_등록_요청한다( - 러너_게시글_생성_요청( - "테스트용_러너_게시글_제목", - 태그_목록, - "https://test-pull-request.com", - LocalDateTime.now().plusHours(100), - "테스트용_러너_게시글_구현_내용", - "테스트용_러너_게시글_궁금한_내용", - "테스트용_러너_게시글_참고_사항" - ) - ) + .액세스_토큰으로_로그인한다(액세스_토큰) + .러너_게시글_등록_요청한다(러너_게시글_생성_요청( + "테스트용_러너_게시글_제목", + 태그_목록, + "https://test-pull-request.com", + LocalDateTime.now().plusHours(100), + "테스트용_러너_게시글_구현_내용", + "테스트용_러너_게시글_궁금한_내용", + "테스트용_러너_게시글_참고_사항" + )) .서버_응답() .러너_게시글_생성_성공을_검증한다(); diff --git a/backend/baton/src/test/java/touch/baton/assure/tag/support/query/TagAssuredSupport.java b/backend/baton/src/test/java/touch/baton/assure/tag/support/query/TagAssuredSupport.java deleted file mode 100644 index ef774f0c7..000000000 --- a/backend/baton/src/test/java/touch/baton/assure/tag/support/query/TagAssuredSupport.java +++ /dev/null @@ -1,85 +0,0 @@ -package touch.baton.assure.tag.support.query; - -import io.restassured.common.mapper.TypeRef; -import io.restassured.response.ExtractableResponse; -import io.restassured.response.Response; -import org.springframework.http.HttpStatus; -import touch.baton.assure.common.AssuredSupport; -import touch.baton.assure.common.QueryParams; -import touch.baton.domain.runnerpost.command.service.dto.RunnerPostCreateRequest; -import touch.baton.domain.tag.command.Tag; -import touch.baton.domain.tag.query.controller.response.TagSearchResponse; -import touch.baton.domain.tag.query.controller.response.TagSearchResponses; - -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.SoftAssertions.assertSoftly; - -@SuppressWarnings("NonAsciiCharacters") -public class TagAssuredSupport { - - private TagAssuredSupport() { - } - - public static TagQueryBuilder 클라이언트_요청() { - return new TagQueryBuilder(); - } - - public static class TagQueryBuilder { - - private ExtractableResponse response; - - private String accessToken; - - public TagQueryBuilder 액세스_토큰으로_로그인한다(final String 액세스_토큰) { - this.accessToken = 액세스_토큰; - return this; - } - - public TagQueryBuilder 러너_게시글_등록_요청한다(final RunnerPostCreateRequest 게시글_생성_요청) { - response = AssuredSupport.post("/api/v1/posts/runner", accessToken, 게시글_생성_요청); - return this; - } - - public TagQueryBuilder 태그_이름을_오름차순으로_10개_검색한다(final String 태그_이름) { - response = AssuredSupport.get("/api/v1/tags/search", new QueryParams(Map.of("tagName", 태그_이름))); - return this; - } - - public TagQueryResponseBuilder 서버_응답() { - return new TagQueryResponseBuilder(response); - } - - } - - public static class TagQueryResponseBuilder { - - private final ExtractableResponse response; - - public TagQueryResponseBuilder(final ExtractableResponse response) { - this.response = response; - } - - public void 태그_검색_성공을_검증한다(final TagSearchResponses.Detail 검색된_태그_목록) { - final TagSearchResponses.Detail actual = this.response.as(new TypeRef<>() { - - }); - - assertSoftly(softly -> { - softly.assertThat(this.response.statusCode()).isEqualTo(HttpStatus.OK.value()); - softly.assertThat(actual.data()).isEqualTo(검색된_태그_목록.data()); - } - ); - } - } - - public static TagSearchResponses.Detail 태그_검색_Detail_응답(final List 검색된_태그_목록) { - List 태그_목록_응답 = 검색된_태그_목록.stream() - .map(TagSearchResponse.TagResponse::from) - .toList(); - final TagSearchResponses.Detail 검색된_태그_목록_응답들 = TagSearchResponses.Detail.from(태그_목록_응답); - - return 검색된_태그_목록_응답들; - } -} diff --git a/backend/baton/src/test/java/touch/baton/assure/tag/support/query/TagQuerySupport.java b/backend/baton/src/test/java/touch/baton/assure/tag/support/query/TagQuerySupport.java new file mode 100644 index 000000000..115fbde5b --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/assure/tag/support/query/TagQuerySupport.java @@ -0,0 +1,58 @@ +package touch.baton.assure.tag.support.query; + +import io.restassured.common.mapper.TypeRef; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import org.springframework.http.HttpStatus; +import touch.baton.assure.common.AssuredSupport; +import touch.baton.assure.common.QueryParams; +import touch.baton.domain.tag.command.vo.TagReducedName; +import touch.baton.domain.tag.query.controller.response.TagSearchResponses; + +import java.util.Map; + +import static org.assertj.core.api.SoftAssertions.assertSoftly; + +@SuppressWarnings("NonAsciiCharacters") +public class TagQuerySupport { + + private TagQuerySupport() { + } + + public static TagQueryBuilder 클라이언트_요청() { + return new TagQueryBuilder(); + } + + public static class TagQueryBuilder { + + private ExtractableResponse response; + + public TagQueryBuilder 입력된_문자열로_태그_목록을_검색한다(final TagReducedName 요청할_태그_이름) { + response = AssuredSupport.get("/api/v1/tags/search", new QueryParams(Map.of("tagName", 요청할_태그_이름.getValue()))); + return this; + } + + public TagQueryResponseBuilder 서버_응답() { + return new TagQueryResponseBuilder(response); + } + } + + public static class TagQueryResponseBuilder { + + private final ExtractableResponse response; + + public TagQueryResponseBuilder(final ExtractableResponse response) { + this.response = response; + } + + public void 입력된_문자열로_태그_목록_검색_성공을_검증한다(final TagSearchResponses.Detail 검색된_태그_목록) { + final TagSearchResponses.Detail actual = this.response.as(new TypeRef<>() { + }); + + assertSoftly(softly -> { + softly.assertThat(this.response.statusCode()).isEqualTo(HttpStatus.OK.value()); + softly.assertThat(actual.data()).isEqualTo(검색된_태그_목록.data()); + }); + } + } +} diff --git a/backend/baton/src/test/java/touch/baton/config/AssuredTestConfig.java b/backend/baton/src/test/java/touch/baton/config/AssuredTestConfig.java index 2c7ee44b5..417005ffa 100644 --- a/backend/baton/src/test/java/touch/baton/config/AssuredTestConfig.java +++ b/backend/baton/src/test/java/touch/baton/config/AssuredTestConfig.java @@ -19,7 +19,7 @@ import touch.baton.assure.repository.TestRunnerQueryRepository; import touch.baton.assure.repository.TestSupporterQueryRepository; import touch.baton.assure.repository.TestSupporterRunnerPostQueryRepository; -import touch.baton.assure.repository.TestTagQueryRepository; +import touch.baton.assure.repository.TestTagQuerydslRepository; import touch.baton.config.converter.ConverterConfig; import touch.baton.config.infra.auth.MockBeanAuthTestConfig; import touch.baton.config.infra.github.MockGithubBranchServiceConfig; @@ -47,7 +47,7 @@ public abstract class AssuredTestConfig { protected TestSupporterRunnerPostQueryRepository supporterRunnerPostRepository; @Autowired - protected TestTagQueryRepository tagRepository; + protected TestTagQuerydslRepository tagQueryRepository; @Autowired protected TestNotificationCommandRepository notificationCommandRepository; diff --git a/backend/baton/src/test/java/touch/baton/config/QueryDslRepositoryTestConfig.java b/backend/baton/src/test/java/touch/baton/config/QueryDslRepositoryTestConfig.java index d46c842b0..a06536c83 100644 --- a/backend/baton/src/test/java/touch/baton/config/QueryDslRepositoryTestConfig.java +++ b/backend/baton/src/test/java/touch/baton/config/QueryDslRepositoryTestConfig.java @@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean; import touch.baton.domain.notification.query.repository.NotificationQuerydslRepository; import touch.baton.domain.runnerpost.query.repository.RunnerPostPageRepository; +import touch.baton.domain.tag.query.repository.TagQuerydslRepository; @TestConfiguration public class QueryDslRepositoryTestConfig { @@ -28,4 +29,9 @@ public RunnerPostPageRepository runnerPostPageRepository() { public NotificationQuerydslRepository notificationQuerydslRepository() { return new NotificationQuerydslRepository(jpaQueryFactory()); } + + @Bean + public TagQuerydslRepository tagQuerydslRepository() { + return new TagQuerydslRepository(jpaQueryFactory()); + } } diff --git a/backend/baton/src/test/java/touch/baton/config/ServiceTestConfig.java b/backend/baton/src/test/java/touch/baton/config/ServiceTestConfig.java index 84bfaa8f0..647434219 100644 --- a/backend/baton/src/test/java/touch/baton/config/ServiceTestConfig.java +++ b/backend/baton/src/test/java/touch/baton/config/ServiceTestConfig.java @@ -16,7 +16,7 @@ import touch.baton.domain.runnerpost.query.repository.RunnerPostQueryRepository; import touch.baton.domain.tag.command.repository.TagCommandRepository; import touch.baton.domain.tag.query.repository.RunnerPostTagQueryRepository; -import touch.baton.domain.tag.query.repository.TagQueryRepository; +import touch.baton.domain.tag.query.repository.TagQuerydslRepository; import touch.baton.domain.technicaltag.command.repository.RunnerTechnicalTagCommandRepository; import touch.baton.domain.technicaltag.command.repository.SupporterTechnicalTagCommandRepository; import touch.baton.domain.technicaltag.query.repository.TechnicalTagQueryRepository; @@ -45,7 +45,7 @@ public abstract class ServiceTestConfig extends RepositoryTestConfig { protected RunnerPostTagQueryRepository runnerPostTagQueryRepository; @Autowired - protected TagQueryRepository tagQueryRepository; + protected TagQuerydslRepository tagQuerydslRepository; @Autowired protected SupporterFeedbackCommandRepository supporterFeedbackCommandRepository; diff --git a/backend/baton/src/test/java/touch/baton/document/runnerpost/read/TagReadApiTest.java b/backend/baton/src/test/java/touch/baton/document/runnerpost/read/TagReadApiTest.java index cdb8165ac..18e65d9b5 100644 --- a/backend/baton/src/test/java/touch/baton/document/runnerpost/read/TagReadApiTest.java +++ b/backend/baton/src/test/java/touch/baton/document/runnerpost/read/TagReadApiTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import touch.baton.config.RestdocsConfig; import touch.baton.domain.tag.command.Tag; +import touch.baton.domain.tag.command.vo.TagReducedName; import touch.baton.fixture.domain.TagFixture; import java.util.List; @@ -35,7 +36,7 @@ void readTagsByReducedName() throws Exception { final Tag javascriptTagSpy = spy(javascriptTag); // when - when(tagQueryService.readTagsByReducedName("java")) + when(tagQueryService.readTagsByReducedName(TagReducedName.nullableInstance("java"), 10)) .thenReturn(List.of(javaTagSpy, javascriptTagSpy)); when(javaTagSpy.getId()) .thenReturn(1L); diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/query/service/RunnerPostQueryServiceTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/query/service/RunnerPostQueryServiceTest.java index 45b685a48..be09c19ca 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/query/service/RunnerPostQueryServiceTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/query/service/RunnerPostQueryServiceTest.java @@ -75,8 +75,8 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_firstPage() { final Member hyenaMember = memberCommandRepository.save(MemberFixture.createHyena()); final Runner hyenaRunner = runnerQueryRepository.save(RunnerFixture.createRunner(hyenaMember)); - final Tag javaTag = tagQueryRepository.save(TagFixture.create(tagName("자바"))); - final Tag springTag = tagQueryRepository.save(TagFixture.create(tagName("스프링"))); + final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); + final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -136,8 +136,8 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_middlePage() { final Member hyenaMember = memberCommandRepository.save(MemberFixture.createHyena()); final Runner hyenaRunner = runnerQueryRepository.save(RunnerFixture.createRunner(hyenaMember)); - final Tag javaTag = tagQueryRepository.save(TagFixture.create(tagName("자바"))); - final Tag springTag = tagQueryRepository.save(TagFixture.create(tagName("스프링"))); + final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); + final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -204,8 +204,8 @@ void readRunnerPostByPageInfoAndReviewStatus_firstPage() { final Member hyenaMember = memberCommandRepository.save(MemberFixture.createHyena()); final Runner hyenaRunner = runnerQueryRepository.save(RunnerFixture.createRunner(hyenaMember)); - final Tag javaTag = tagQueryRepository.save(TagFixture.create(tagName("자바"))); - final Tag springTag = tagQueryRepository.save(TagFixture.create(tagName("스프링"))); + final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); + final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -267,8 +267,8 @@ void readRunnerPostByPageInfoAndReviewStatus_middlePage() { final Member hyenaMember = memberCommandRepository.save(MemberFixture.createHyena()); final Runner hyenaRunner = runnerQueryRepository.save(RunnerFixture.createRunner(hyenaMember)); - final Tag javaTag = tagQueryRepository.save(TagFixture.create(tagName("자바"))); - final Tag springTag = tagQueryRepository.save(TagFixture.create(tagName("스프링"))); + final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); + final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -336,8 +336,8 @@ void readRunnerPostByPageInfoAndTagName_firstPage() { final Member hyenaMember = memberCommandRepository.save(MemberFixture.createHyena()); final Runner hyenaRunner = runnerQueryRepository.save(RunnerFixture.createRunner(hyenaMember)); - final Tag javaTag = tagQueryRepository.save(TagFixture.create(tagName("자바"))); - final Tag springTag = tagQueryRepository.save(TagFixture.create(tagName("스프링"))); + final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); + final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -390,8 +390,8 @@ void readRunnerPostByPageInfoAndTagName_middlePage() { final Member hyenaMember = memberCommandRepository.save(MemberFixture.createHyena()); final Runner hyenaRunner = runnerQueryRepository.save(RunnerFixture.createRunner(hyenaMember)); - final Tag javaTag = tagQueryRepository.save(TagFixture.create(tagName("자바"))); - final Tag springTag = tagQueryRepository.save(TagFixture.create(tagName("스프링"))); + final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); + final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -451,8 +451,8 @@ void readRunnerPostByPageInfo_firstPage() { final Member hyenaMember = memberCommandRepository.save(MemberFixture.createHyena()); final Runner hyenaRunner = runnerQueryRepository.save(RunnerFixture.createRunner(hyenaMember)); - final Tag javaTag = tagQueryRepository.save(TagFixture.create(tagName("자바"))); - final Tag springTag = tagQueryRepository.save(TagFixture.create(tagName("스프링"))); + final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); + final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -507,8 +507,8 @@ void readRunnerPostByPageInfo_middlePage() { final Member hyenaMember = memberCommandRepository.save(MemberFixture.createHyena()); final Runner hyenaRunner = runnerQueryRepository.save(RunnerFixture.createRunner(hyenaMember)); - final Tag javaTag = tagQueryRepository.save(TagFixture.create(tagName("자바"))); - final Tag springTag = tagQueryRepository.save(TagFixture.create(tagName("스프링"))); + final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); + final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -604,7 +604,7 @@ void success_findByRunnerPostId() { .tagName(new TagName("자바")) .tagReducedName(TagReducedName.from("자바")) .build(); - tagQueryRepository.save(tag); + tagCommandRepository.save(tag); final RunnerPostTag runnerPostTag = RunnerPostTag.builder() .runnerPost(runnerPost) diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/RunnerPostTagTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/command/RunnerPostTagTest.java similarity index 96% rename from backend/baton/src/test/java/touch/baton/domain/tag/RunnerPostTagTest.java rename to backend/baton/src/test/java/touch/baton/domain/tag/command/RunnerPostTagTest.java index c9ca1728e..3742f29ae 100644 --- a/backend/baton/src/test/java/touch/baton/domain/tag/RunnerPostTagTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/tag/command/RunnerPostTagTest.java @@ -1,4 +1,4 @@ -package touch.baton.domain.tag; +package touch.baton.domain.tag.command; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -23,9 +23,6 @@ import touch.baton.domain.runnerpost.command.vo.ReviewStatus; import touch.baton.domain.runnerpost.command.vo.Title; import touch.baton.domain.runnerpost.command.vo.WatchedCount; -import touch.baton.domain.tag.command.RunnerPostTag; -import touch.baton.domain.tag.command.RunnerPostTags; -import touch.baton.domain.tag.command.Tag; import touch.baton.domain.tag.exception.RunnerPostTagDomainException; import touch.baton.domain.technicaltag.command.SupporterTechnicalTags; import touch.baton.fixture.domain.RunnerTechnicalTagsFixture; diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/RunnerPostTagsTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/command/RunnerPostTagsTest.java similarity index 92% rename from backend/baton/src/test/java/touch/baton/domain/tag/RunnerPostTagsTest.java rename to backend/baton/src/test/java/touch/baton/domain/tag/command/RunnerPostTagsTest.java index 08f83ab30..598c3ee51 100644 --- a/backend/baton/src/test/java/touch/baton/domain/tag/RunnerPostTagsTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/tag/command/RunnerPostTagsTest.java @@ -1,4 +1,4 @@ -package touch.baton.domain.tag; +package touch.baton.domain.tag.command; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,9 +11,6 @@ import touch.baton.domain.member.command.vo.OauthId; import touch.baton.domain.member.command.vo.SocialId; import touch.baton.domain.runnerpost.command.RunnerPost; -import touch.baton.domain.tag.command.RunnerPostTag; -import touch.baton.domain.tag.command.RunnerPostTags; -import touch.baton.domain.tag.command.Tag; import touch.baton.fixture.domain.RunnerTechnicalTagsFixture; import java.time.LocalDateTime; diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/TagTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/command/TagTest.java similarity index 97% rename from backend/baton/src/test/java/touch/baton/domain/tag/TagTest.java rename to backend/baton/src/test/java/touch/baton/domain/tag/command/TagTest.java index e57d9c1a0..f2bec9b19 100644 --- a/backend/baton/src/test/java/touch/baton/domain/tag/TagTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/tag/command/TagTest.java @@ -1,4 +1,4 @@ -package touch.baton.domain.tag; +package touch.baton.domain.tag.command; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/vo/TagReducedNameTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/command/vo/TagReducedNameTest.java similarity index 94% rename from backend/baton/src/test/java/touch/baton/domain/tag/vo/TagReducedNameTest.java rename to backend/baton/src/test/java/touch/baton/domain/tag/command/vo/TagReducedNameTest.java index 550e2d137..a26810c05 100644 --- a/backend/baton/src/test/java/touch/baton/domain/tag/vo/TagReducedNameTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/tag/command/vo/TagReducedNameTest.java @@ -1,8 +1,7 @@ -package touch.baton.domain.tag.vo; +package touch.baton.domain.tag.command.vo; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import touch.baton.domain.tag.command.vo.TagReducedName; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/repository/RunnerPostTagQueryRepositoryTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/query/repository/RunnerPostTagQueryRepositoryTest.java similarity index 94% rename from backend/baton/src/test/java/touch/baton/domain/tag/repository/RunnerPostTagQueryRepositoryTest.java rename to backend/baton/src/test/java/touch/baton/domain/tag/query/repository/RunnerPostTagQueryRepositoryTest.java index 40916fe5a..ba2e2837d 100644 --- a/backend/baton/src/test/java/touch/baton/domain/tag/repository/RunnerPostTagQueryRepositoryTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/tag/query/repository/RunnerPostTagQueryRepositoryTest.java @@ -1,4 +1,4 @@ -package touch.baton.domain.tag.repository; +package touch.baton.domain.tag.query.repository; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -8,7 +8,6 @@ import touch.baton.domain.runnerpost.command.RunnerPost; import touch.baton.domain.tag.command.RunnerPostTag; import touch.baton.domain.tag.command.Tag; -import touch.baton.domain.tag.query.repository.RunnerPostTagQueryRepository; import touch.baton.fixture.domain.MemberFixture; import java.util.List; diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/query/repository/TagQuerydslRepositoryTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/query/repository/TagQuerydslRepositoryTest.java new file mode 100644 index 000000000..19c05e202 --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/domain/tag/query/repository/TagQuerydslRepositoryTest.java @@ -0,0 +1,103 @@ +package touch.baton.domain.tag.query.repository; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import touch.baton.config.RepositoryTestConfig; +import touch.baton.domain.common.vo.TagName; +import touch.baton.domain.tag.command.Tag; +import touch.baton.domain.tag.command.vo.TagReducedName; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class TagQuerydslRepositoryTest extends RepositoryTestConfig { + + @Autowired + private TagQuerydslRepository tagQuerydslRepository; + + @DisplayName("축약된 태그 이름으로 태그 목록을 limit 개 축약된 태그 이름 기준 오름차순으로 검색한다.") + @Test + void readTagsByTagReducedName() { + // given + for (int saveTagCount = 1; saveTagCount <= 3; saveTagCount++) { + persistTag("java" + saveTagCount); + persistTag("javascript" + saveTagCount); + persistTag("assertj" + saveTagCount); + } + for (int saveTagCount = 4; saveTagCount <= 6; saveTagCount++) { + persistTag("j ava" + saveTagCount); + persistTag("j avascript" + saveTagCount); + persistTag("a ssertj" + saveTagCount); + } + for (int saveTagCount = 7; saveTagCount <= 10; saveTagCount++) { + persistTag("ja va" + saveTagCount); + persistTag("ja vascript" + saveTagCount); + persistTag("as sertj" + saveTagCount); + } + + em.flush(); + em.close(); + + // when + final List actual = tagQuerydslRepository.findByTagReducedName(TagReducedName.from("j"), 10); + + // then + final List actualSortedTagNames = actual.stream() + .map(Tag::getTagName) + .map(TagName::getValue) + .toList(); + + assertThat(actualSortedTagNames).containsExactly( + "java1", "ja va10", "java2", "java3", "j ava4", "j ava5", "j ava6", "ja va7", "ja va8", "ja va9" + ); + } + + @DisplayName("입력된 TagReducedName 으로 시작하는 태그만 검색한다") + @Test + void success_readTagsByReducedName_when_name_isNotMatched_atAll() { + // given + persistTag("assertj"); + + em.flush(); + em.close(); + + // when + final TagReducedName tagReducedName = TagReducedName.nullableInstance("j"); + final List actual = tagQuerydslRepository.findByTagReducedName(tagReducedName, 10); + + // then + assertThat(actual.isEmpty()).isTrue(); + } + + @DisplayName("입력된 TagReducedName 으로 시작하는 이름을 갖는 태그가 없다면 빈 목록을 반환한다.") + @Test + void success_readTagsByReducedName_when_foundTags_isEmpty() { + // given + persistTag("aaaaaaaaa"); + + em.flush(); + em.close(); + + // when + final TagReducedName tagReducedName = TagReducedName.nullableInstance("b"); + final List actual = tagQuerydslRepository.findByTagReducedName(tagReducedName, 10); + + // then + assertThat(actual.isEmpty()).isTrue(); + } + + @DisplayName("TagReducedName 내부 값이 blank 인 경우 빈 목록을 반환한다.") + @Test + void success_readTagsByReducedName_when_tagReducedNameIsBlank() { + // given + final TagReducedName tagReducedName = TagReducedName.nullableInstance(""); + + // when + final List actual = tagQuerydslRepository.findByTagReducedName(tagReducedName, 10); + + // then + assertThat(actual.isEmpty()).isTrue(); + } +} diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/query/service/TagQueryServiceTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/query/service/TagQueryServiceTest.java new file mode 100644 index 000000000..eba2b23bd --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/domain/tag/query/service/TagQueryServiceTest.java @@ -0,0 +1,77 @@ +package touch.baton.domain.tag.query.service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import touch.baton.config.ServiceTestConfig; +import touch.baton.domain.tag.command.Tag; +import touch.baton.domain.tag.command.vo.TagReducedName; +import touch.baton.fixture.domain.TagFixture; +import touch.baton.fixture.vo.TagNameFixture; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.SoftAssertions.assertSoftly; + +class TagQueryServiceTest extends ServiceTestConfig { + + private TagQueryService tagQueryService; + + @BeforeEach + void setUp() { + tagQueryService = new TagQueryService(tagQuerydslRepository); + } + + @DisplayName("Tag의 이름으로 Tag를 오름차순으로 10개 조회한다.") + @Test + void success_readTagsByReducedName() { + // given + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("ja va"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("jav a1"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("j ava2"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("ja va3"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("jav a4"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("java 5"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("j ava6"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("ja va7"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("jav a8"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("java 9"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("ju ja"))); + + // when + final TagReducedName tagReducedName = TagReducedName.nullableInstance("j a"); + final List actual = tagQueryService.readTagsByReducedName(tagReducedName, 10); + + // then + assertSoftly(softly -> { + softly.assertThat(actual).hasSize(10); + softly.assertThat(actual.get(0).getTagName().getValue()).isEqualTo("ja va"); + softly.assertThat(actual.get(9).getTagName().getValue()).isEqualTo("java 9"); + }); + } + + @DisplayName("TagReducedName 이 null 인 경우 빈 목록을 반환한다.") + @Test + void success_when_TagReducedName_IsNull() { + // given + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("ja va"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("jav a1"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("j ava2"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("ja va3"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("jav a4"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("java 5"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("j ava6"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("ja va7"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("jav a8"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("java 9"))); + tagCommandRepository.save(TagFixture.create(TagNameFixture.tagName("ju ja"))); + + // when + final TagReducedName nullTagReducedName = null; + final List actual = tagQueryService.readTagsByReducedName(nullTagReducedName, 10); + + // then + assertThat(actual).isEmpty(); + } +} diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/repository/TagQueryRepositoryReadTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/repository/TagQueryRepositoryReadTest.java deleted file mode 100644 index 8cce780ce..000000000 --- a/backend/baton/src/test/java/touch/baton/domain/tag/repository/TagQueryRepositoryReadTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package touch.baton.domain.tag.repository; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import touch.baton.config.RepositoryTestConfig; -import touch.baton.domain.tag.command.Tag; -import touch.baton.domain.tag.command.vo.TagReducedName; -import touch.baton.domain.tag.query.repository.TagQueryRepository; -import touch.baton.fixture.domain.TagFixture; -import touch.baton.fixture.vo.TagNameFixture; - -import java.util.List; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.SoftAssertions.assertSoftly; - -class TagQueryRepositoryReadTest extends RepositoryTestConfig { - - @Autowired - private TagQueryRepository tagQueryRepository; - - @DisplayName("이름으로 단건 검색한다.") - @Test - void findByName() { - // given - final Tag javaTag = persistTag("java"); - final Tag uppercaseJavaTag = persistTag("Java"); - - em.flush(); - em.close(); - - // when - final Optional actual = tagQueryRepository.findByTagName(TagNameFixture.tagName("java")); - - // then - assertThat(actual).contains(javaTag); - } - - @DisplayName("이름을 오름차순으로 10개 검색한다.") - @Test - void success_readTagsByReducedName() { - // given - persistTag("ja va"); - persistTag("j ava1"); - persistTag("ja va2"); - persistTag("jav a3"); - persistTag("java 4"); - persistTag("ja va5"); - persistTag("j ava6"); - persistTag("ja va7"); - persistTag("jav a8"); - persistTag("java 9"); - persistTag("assert ja"); - - em.flush(); - em.close(); - - // when - final TagReducedName reducedName = TagReducedName.from("ja"); - final List actual = tagQueryRepository.readTagsByReducedName(reducedName); - - // then - assertSoftly(softly -> { - softly.assertThat(actual).hasSize(10); - softly.assertThat(actual.get(0).getTagName().getValue()).isEqualTo("ja va"); - softly.assertThat(actual.get(9).getTagName().getValue()).isEqualTo("java 9"); - }); - - } - - @DisplayName("이름으로 시작하는 태그만 검색한다") - @Test - void fail_readTagsByReducedName() { - // given - final Tag tag = TagFixture.create(TagNameFixture.tagName("assertj")); - final TagReducedName reducedName = TagReducedName.from("j"); - tagQueryRepository.save(tag); - - // when - final List actual = tagQueryRepository.readTagsByReducedName(reducedName); - - // then - assertThat(actual.isEmpty()).isTrue(); - } - - @DisplayName("이름에 해당하는 태그가 없다면 빈 배열을 반환한다.") - @Test - void success_readTagsByReducedName_when_no_match_tag() { - // given - final TagReducedName reducedName = TagReducedName.from("hi"); - persistTag("hellohi"); - - em.flush(); - em.close(); - - // when - final List actual = tagQueryRepository.readTagsByReducedName(reducedName); - - // then - assertThat(actual.isEmpty()).isTrue(); - } -} diff --git a/backend/baton/src/test/java/touch/baton/domain/tag/service/TagQueryServiceReadTest.java b/backend/baton/src/test/java/touch/baton/domain/tag/service/TagQueryServiceReadTest.java deleted file mode 100644 index 317eb9e65..000000000 --- a/backend/baton/src/test/java/touch/baton/domain/tag/service/TagQueryServiceReadTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package touch.baton.domain.tag.service; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import touch.baton.config.ServiceTestConfig; -import touch.baton.domain.tag.command.Tag; -import touch.baton.domain.tag.query.service.TagQueryService; -import touch.baton.fixture.domain.TagFixture; -import touch.baton.fixture.vo.TagNameFixture; - -import java.util.List; - -import static org.assertj.core.api.SoftAssertions.assertSoftly; - -class TagQueryServiceReadTest extends ServiceTestConfig { - - private TagQueryService tagQueryService; - - @BeforeEach - void setUp() { - tagQueryService = new TagQueryService(tagQueryRepository); - } - - @DisplayName("Tag의 이름으로 Tag를 오름차순으로 10개 조회한다.") - @Test - void success_readTagsByReducedName() { - // given - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("ja va"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("jav a1"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("j ava2"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("ja va3"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("jav a4"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("java 5"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("j ava6"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("ja va7"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("jav a8"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("java 9"))); - tagQueryRepository.save(TagFixture.create(TagNameFixture.tagName("ju ja"))); - - // when - final List actual = tagQueryService.readTagsByReducedName("j a"); - - // then - assertSoftly(softly -> { - softly.assertThat(actual).hasSize(10); - softly.assertThat(actual.get(0).getTagName().getValue()).isEqualTo("ja va"); - softly.assertThat(actual.get(9).getTagName().getValue()).isEqualTo("java 9"); - }); - } -}