diff --git a/backend/src/test/java/com/festago/artist/application/ArtistCommandServiceTest.java b/backend/src/test/java/com/festago/artist/application/ArtistCommandServiceTest.java index 3dc0274fc..5d1ba42cd 100644 --- a/backend/src/test/java/com/festago/artist/application/ArtistCommandServiceTest.java +++ b/backend/src/test/java/com/festago/artist/application/ArtistCommandServiceTest.java @@ -8,6 +8,7 @@ import com.festago.artist.dto.command.ArtistUpdateCommand; import com.festago.artist.repository.ArtistRepository; import com.festago.artist.repository.MemoryArtistRepository; +import com.festago.support.fixture.ArtistFixture; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -37,14 +38,13 @@ void setUp() { Long artistId = artistCommandService.save(command); // then - Artist actual = artistRepository.getOrThrow(artistId); - assertThat(actual.getId()).isPositive(); + assertThat(artistRepository.findById(artistId)).isPresent(); } @Test void 아티스트_정보를_변경한다() { // given - Long artistId = artistRepository.save(new Artist("고윤하", "https://image.com/image1.png")).getId(); + Long artistId = artistRepository.save(ArtistFixture.builder().name("고윤하").build()).getId(); ArtistUpdateCommand command = new ArtistUpdateCommand("윤하", "https://image.com/image2.png", "https://image.com/image2.png"); @@ -57,13 +57,14 @@ void setUp() { assertSoftly(softly -> { softly.assertThat(actual.getName()).isEqualTo(command.name()); softly.assertThat(actual.getProfileImage()).isEqualTo(command.profileImageUrl()); + softly.assertThat(actual.getBackgroundImageUrl()).isEqualTo(command.backgroundImageUrl()); }); } @Test void 아티스트를_삭제한다() { // given - Long artistId = artistRepository.save(new Artist("고윤하", "https://image.com/image.png")).getId(); + Long artistId = artistRepository.save(ArtistFixture.builder().name("고윤하").build()).getId(); // when artistCommandService.delete(artistId); diff --git a/backend/src/test/java/com/festago/artist/application/integration/ArtistCommandServiceIntegrationTest.java b/backend/src/test/java/com/festago/artist/application/integration/ArtistCommandServiceIntegrationTest.java deleted file mode 100644 index 7f720295f..000000000 --- a/backend/src/test/java/com/festago/artist/application/integration/ArtistCommandServiceIntegrationTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.festago.artist.application.integration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.SoftAssertions.assertSoftly; - -import com.festago.artist.application.ArtistCommandService; -import com.festago.artist.domain.Artist; -import com.festago.artist.dto.command.ArtistCreateCommand; -import com.festago.artist.dto.command.ArtistUpdateCommand; -import com.festago.artist.repository.ArtistRepository; -import com.festago.support.ApplicationIntegrationTest; -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; - -@DisplayNameGeneration(ReplaceUnderscores.class) -@SuppressWarnings("NonAsciiCharacters") -class ArtistCommandServiceIntegrationTest extends ApplicationIntegrationTest { - - @Autowired - ArtistCommandService artistCommandService; - - @Autowired - ArtistRepository artistRepository; - - @Test - void 아티스트를_저장한다() { - // given - ArtistCreateCommand command = new ArtistCreateCommand("윤서연", "https://image.com/image.png", - "https://image.com/image.png"); - - // when - Long artistId = artistCommandService.save(command); - - // then - Artist actual = artistRepository.getOrThrow(artistId); - assertThat(actual.getId()).isPositive(); - } - - @Test - void 아티스트_정보를_변경한다() { - // given - Long artistId = artistRepository.save(new Artist("고윤하", "https://image.com/image1.png")).getId(); - ArtistUpdateCommand command = new ArtistUpdateCommand("윤하", "https://image.com/image2.png", - "https://image.com/image2.png"); - - // when - artistCommandService.update(command, artistId); - - // then - Artist actual = artistRepository.getOrThrow(artistId); - - assertSoftly(softly -> { - softly.assertThat(actual.getName()).isEqualTo(command.name()); - softly.assertThat(actual.getProfileImage()).isEqualTo(command.profileImageUrl()); - }); - } - - @Test - void 아티스트를_삭제한다() { - // given - Long artistId = artistRepository.save(new Artist("고윤하", "https://image.com/image.png")).getId(); - - // when - artistCommandService.delete(artistId); - - // then - assertThat(artistRepository.findById(artistId)).isEmpty(); - } -} diff --git a/backend/src/test/java/com/festago/artist/application/integration/ArtistDetailV1QueryServiceIntegrationTest.java b/backend/src/test/java/com/festago/artist/application/integration/ArtistDetailV1QueryServiceIntegrationTest.java index c6e395e5e..5e8d73607 100644 --- a/backend/src/test/java/com/festago/artist/application/integration/ArtistDetailV1QueryServiceIntegrationTest.java +++ b/backend/src/test/java/com/festago/artist/application/integration/ArtistDetailV1QueryServiceIntegrationTest.java @@ -5,30 +5,35 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.BDDMockito.given; -import com.festago.artist.application.ArtistCommandService; import com.festago.artist.application.ArtistDetailV1QueryService; +import com.festago.artist.domain.Artist; import com.festago.artist.dto.ArtistFestivalDetailV1Response; import com.festago.artist.dto.ArtistMediaV1Response; -import com.festago.artist.dto.command.ArtistCreateCommand; +import com.festago.artist.repository.ArtistRepository; import com.festago.common.exception.ErrorCode; import com.festago.common.exception.NotFoundException; -import com.festago.festival.application.command.FestivalCreateService; -import com.festago.festival.dto.command.FestivalCreateCommand; -import com.festago.school.application.SchoolCommandService; +import com.festago.festival.domain.Festival; +import com.festago.festival.repository.FestivalRepository; +import com.festago.school.domain.School; import com.festago.school.domain.SchoolRegion; -import com.festago.school.dto.SchoolCreateCommand; +import com.festago.school.repository.SchoolRepository; import com.festago.socialmedia.domain.OwnerType; -import com.festago.socialmedia.domain.SocialMedia; import com.festago.socialmedia.domain.SocialMediaType; import com.festago.socialmedia.repository.SocialMediaRepository; -import com.festago.stage.application.command.StageCreateService; -import com.festago.stage.dto.command.StageCreateCommand; +import com.festago.stage.domain.Stage; +import com.festago.stage.repository.StageArtistRepository; +import com.festago.stage.repository.StageRepository; import com.festago.support.ApplicationIntegrationTest; import com.festago.support.TimeInstantProvider; +import com.festago.support.fixture.ArtistFixture; +import com.festago.support.fixture.FestivalFixture; +import com.festago.support.fixture.SchoolFixture; +import com.festago.support.fixture.SocialMediaFixture; +import com.festago.support.fixture.StageArtistFixture; +import com.festago.support.fixture.StageFixture; import java.time.Clock; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; @@ -48,16 +53,19 @@ class ArtistDetailV1QueryServiceIntegrationTest extends ApplicationIntegrationTe ArtistDetailV1QueryService artistDetailV1QueryService; @Autowired - ArtistCommandService artistCommandService; + ArtistRepository artistRepository; @Autowired - FestivalCreateService festivalCreateService; + FestivalRepository festivalRepository; @Autowired - SchoolCommandService schoolCommandService; + SchoolRepository schoolRepository; @Autowired - StageCreateService stageCreateService; + StageRepository stageRepository; + + @Autowired + StageArtistRepository stageArtistRepository; @Autowired SocialMediaRepository socialMediaRepository; @@ -68,7 +76,7 @@ class 아티스트_상세_정보_조회 { @Test void 조회할_수_있다() { // given - Long 아티스트_식별자 = createArtist("pooh"); + Long 아티스트_식별자 = createArtist("pooh").getId(); makeSocialMedia(아티스트_식별자, OwnerType.ARTIST, SocialMediaType.INSTAGRAM); makeSocialMedia(아티스트_식별자, OwnerType.ARTIST, SocialMediaType.YOUTUBE); @@ -85,7 +93,7 @@ class 아티스트_상세_정보_조회 { @Test void 소셜_미디어가_없어도_조회할_수_있다() { // given - Long 아티스트_식별자 = createArtist("pooh"); + Long 아티스트_식별자 = createArtist("pooh").getId(); // when var actual = artistDetailV1QueryService.findArtistDetail(아티스트_식별자); @@ -100,7 +108,7 @@ class 아티스트_상세_정보_조회 { @Test void 소셜_미디어의_주인_아이디가_같더라도_주인의_타입에_따라_구분하여_조회한다() { // given - Long 아티스트_식별자 = createArtist("pooh"); + Long 아티스트_식별자 = createArtist("pooh").getId(); makeSocialMedia(아티스트_식별자, OwnerType.ARTIST, SocialMediaType.INSTAGRAM); // when @@ -122,8 +130,11 @@ class 아티스트_상세_정보_조회 { } Long makeSocialMedia(Long ownerId, OwnerType ownerType, SocialMediaType socialMediaType) { - SocialMedia socialMedia = new SocialMedia(ownerId, ownerType, socialMediaType, "총학생회", - "https://image.com/logo.png", "https://instgram.com/blahblah"); + var socialMedia = SocialMediaFixture.builder() + .ownerId(ownerId) + .ownerType(ownerType) + .mediaType(socialMediaType) + .build(); return socialMediaRepository.save(socialMedia).getId(); } } @@ -141,49 +152,58 @@ class 아티스트가_참여한_축제_목록_조회 { LocalDate _6월_15일 = LocalDate.parse("2077-06-15"); LocalDate _6월_16일 = LocalDate.parse("2077-06-16"); - Long 아티스트A_식별자; + Artist 아티스트A; - Long 서울대학교_축제_식별자; - Long 부산대학교_축제_식별자; - Long 대구대학교_축제_식별자; + Festival 서울대학교_축제; + Festival 부산대학교_축제; + Festival 대구대학교_축제; @BeforeEach void setUp() { - Long 서울대학교_식별자 = createSchool("서울대학교", "seoul.ac.kr", SchoolRegion.서울); - Long 부산대학교_식별자 = createSchool("부산대학교", "busan.ac.kr", SchoolRegion.부산); - Long 대구대학교_식별자 = createSchool("대구대학교", "daegu.ac.kr", SchoolRegion.대구); - - 서울대학교_축제_식별자 = festivalCreateService.createFestival(new FestivalCreateCommand( - "서울대학교 축제", _6월_14일, _6월_14일, "https://image.com/posterImage.png", 서울대학교_식별자 - )); - 부산대학교_축제_식별자 = festivalCreateService.createFestival(new FestivalCreateCommand( - "부산대학교 축제", _6월_15일, _6월_15일, "https://image.com/posterImage.png", 부산대학교_식별자 - )); - 대구대학교_축제_식별자 = festivalCreateService.createFestival(new FestivalCreateCommand( - "대구대학교 축제", _6월_16일, _6월_16일, "https://image.com/posterImage.png", 대구대학교_식별자 - )); - - 아티스트A_식별자 = createArtist("아티스트A"); - - stageCreateService.createStage(new StageCreateCommand( - 서울대학교_축제_식별자, _6월_14일.atTime(18, 0), _6월_14일.minusWeeks(1).atStartOfDay(), List.of(아티스트A_식별자) - )); - stageCreateService.createStage(new StageCreateCommand( - 부산대학교_축제_식별자, _6월_15일.atTime(18, 0), _6월_15일.minusWeeks(1).atStartOfDay(), List.of(아티스트A_식별자) - )); - stageCreateService.createStage(new StageCreateCommand( - 대구대학교_축제_식별자, _6월_16일.atTime(18, 0), _6월_16일.minusWeeks(1).atStartOfDay(), List.of(아티스트A_식별자) - )); + School 서울대학교 = createSchool("서울대학교", "seoul.ac.kr", SchoolRegion.서울); + School 부산대학교 = createSchool("부산대학교", "busan.ac.kr", SchoolRegion.부산); + School 대구대학교 = createSchool("대구대학교", "daegu.ac.kr", SchoolRegion.대구); + + 서울대학교_축제 = createFestival("서울대학교 축제", _6월_14일, _6월_14일, 서울대학교); + 부산대학교_축제 = createFestival("부산대학교 축제", _6월_15일, _6월_15일, 부산대학교); + 대구대학교_축제 = createFestival("대구대학교 축제", _6월_16일, _6월_16일, 대구대학교); + + 아티스트A = createArtist("아티스트A"); + + createStage(서울대학교_축제, _6월_14일.atTime(18, 0), 아티스트A); + createStage(부산대학교_축제, _6월_15일.atTime(18, 0), 아티스트A); + createStage(대구대학교_축제, _6월_16일.atTime(18, 0), 아티스트A); given(clock.instant()) .willReturn(TimeInstantProvider.from(now)); } + private Festival createFestival(String festivalName, LocalDate startDate, LocalDate endDate, School school) { + return festivalRepository.save(FestivalFixture.builder() + .name(festivalName) + .startDate(startDate) + .endDate(endDate) + .school(school) + .build() + ); + } + + private void createStage(Festival festival, LocalDateTime startTime, Artist... artists) { + Stage stage = stageRepository.save(StageFixture.builder() + .festival(festival) + .startTime(startTime) + .build() + ); + for (Artist artist : artists) { + stageArtistRepository.save(StageArtistFixture.builder(stage.getId(), artist.getId()).build()); + } + } + @Test void 진행중인_축제_조회가_가능하다() { // given & when var actual = artistDetailV1QueryService.findArtistFestivals( - 아티스트A_식별자, + 아티스트A.getId(), null, null, false, @@ -193,14 +213,14 @@ void setUp() { // then assertThat(actual.getContent()) .map(ArtistFestivalDetailV1Response::id) - .containsExactly(부산대학교_축제_식별자, 대구대학교_축제_식별자); + .containsExactly(부산대학교_축제.getId(), 대구대학교_축제.getId()); } @Test void 종료된_축제_조회가_가능하다() { // given & when var actual = artistDetailV1QueryService.findArtistFestivals( - 아티스트A_식별자, + 아티스트A.getId(), null, null, true, @@ -210,14 +230,14 @@ void setUp() { // then assertThat(actual.getContent()) .map(ArtistFestivalDetailV1Response::id) - .containsExactly(서울대학교_축제_식별자); + .containsExactly(서울대학교_축제.getId()); } @Test void 커서_기반_페이징이_가능하다() { // given var firstResponse = artistDetailV1QueryService.findArtistFestivals( - 아티스트A_식별자, + 아티스트A.getId(), null, null, false, @@ -228,7 +248,7 @@ void setUp() { // when var secondResponse = artistDetailV1QueryService.findArtistFestivals( - 아티스트A_식별자, + 아티스트A.getId(), firstFestivalResponse.id(), firstFestivalResponse.startDate(), false, @@ -238,25 +258,23 @@ void setUp() { // then assertThat(secondResponse.getContent()) .map(ArtistFestivalDetailV1Response::id) - .containsExactly(대구대학교_축제_식별자); + .containsExactly(대구대학교_축제.getId()); } } - private Long createSchool(String schoolName, String domain, SchoolRegion region) { - return schoolCommandService.createSchool(new SchoolCreateCommand( - schoolName, - domain, - region, - "https://image.com/logo.png", - "https://image.com/background.png" - )); + private School createSchool(String schoolName, String domain, SchoolRegion region) { + return schoolRepository.save(SchoolFixture.builder() + .name(schoolName) + .domain(domain) + .region(region) + .build() + ); } - private Long createArtist(String artistName) { - return artistCommandService.save(new ArtistCreateCommand( - artistName, - "https://image.com/profileImage.png", - "https://image.com/backgroundImage.png" - )); + private Artist createArtist(String artistName) { + return artistRepository.save(ArtistFixture.builder() + .name(artistName) + .build() + ); } } diff --git a/backend/src/test/java/com/festago/artist/presentation/v1/ArtistDetailV1ControllerTest.java b/backend/src/test/java/com/festago/artist/presentation/v1/ArtistDetailV1ControllerTest.java index 694fef42c..97bf867a6 100644 --- a/backend/src/test/java/com/festago/artist/presentation/v1/ArtistDetailV1ControllerTest.java +++ b/backend/src/test/java/com/festago/artist/presentation/v1/ArtistDetailV1ControllerTest.java @@ -3,7 +3,6 @@ import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; @@ -11,7 +10,6 @@ import com.festago.artist.dto.ArtistDetailV1Response; import com.festago.artist.dto.ArtistFestivalDetailV1Response; import com.festago.artist.dto.ArtistMediaV1Response; -import com.festago.common.dto.SliceResponse; import com.festago.socialmedia.domain.SocialMediaType; import com.festago.support.CustomWebMvcTest; import java.time.LocalDate; @@ -71,16 +69,12 @@ class 올바른_주소로 { mockMvc.perform(get(uri, 1L) .contentType(MediaType.APPLICATION_JSON)) .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(expected))); + .andExpect(status().isOk()); } } } - - - @Nested class 아티스트별_축제_조회 { @@ -98,10 +92,7 @@ class 올바른_주소로 { 1L, "경북대학교", today, today.plusDays(1), "www.image.com/image.png", "아티스트" )); - Pageable pageable = Pageable.ofSize(10); - var slice = new SliceImpl(content, pageable, true); - var expected = SliceResponse.from(slice); - + var slice = new SliceImpl<>(content, Pageable.ofSize(10), true); given(artistDetailV1QueryService.findArtistFestivals(1L, null, null, false, Pageable.ofSize(10))) .willReturn(slice); @@ -109,8 +100,7 @@ class 올바른_주소로 { mockMvc.perform(get(uri, 1L) .contentType(MediaType.APPLICATION_JSON)) .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(expected))); + .andExpect(status().isOk()); } @Test @@ -124,7 +114,6 @@ class 올바른_주소로 { .param("size", String.valueOf(maxPageSize + 1))) .andDo(print()) .andExpect(status().isBadRequest()); - } } }