From 26948ac327912008d45e6abde18cb078df9432c4 Mon Sep 17 00:00:00 2001 From: stopmin Date: Sat, 9 Nov 2024 16:24:20 +0900 Subject: [PATCH 01/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=EB=86=8D=EC=9E=A5=20=EC=8A=A4=EC=BC=80=EC=A5=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FarmScheduleServiceTest.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java diff --git a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java new file mode 100644 index 00000000..3ca621cc --- /dev/null +++ b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java @@ -0,0 +1,91 @@ +package poomasi.domain.farm._schedule.service; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import poomasi.domain.farm._schedule.dto.FarmScheduleUpdateRequest; +import poomasi.domain.farm._schedule.entity.FarmSchedule; +import poomasi.domain.farm._schedule.repository.FarmScheduleRepository; +import poomasi.global.error.BusinessException; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.BDDMockito.given; +import static poomasi.global.error.BusinessError.FARM_SCHEDULE_ALREADY_EXISTS; +import static poomasi.global.error.BusinessError.START_TIME_SHOULD_BE_BEFORE_END_TIME; + +@ExtendWith(MockitoExtension.class) +class FarmScheduleServiceTest { + @InjectMocks + private FarmScheduleService farmScheduleService; + + @Mock + private FarmScheduleRepository farmScheduleRepository; + + @Nested + @DisplayName("농장 스케줄 추가") + class AddFarmSchedule { + @Test + @DisplayName("정상적으로 스케줄을 추가한다") + void should_addFarmSchedule() { + // given + FarmScheduleUpdateRequest request = new FarmScheduleUpdateRequest(1L, LocalDate.now(), LocalTime.of(10, 0), LocalTime.of(12, 0)); + + given(farmScheduleRepository.findByFarmIdAndDate(1L, LocalDate.now())).willReturn(List.of()); + + // when + farmScheduleService.addFarmSchedule(request); + + // then + FarmSchedule farmSchedule = FarmSchedule.builder() + .farmId(1L) + .date(LocalDate.now()) + .startTime(LocalTime.of(10, 0)) + .endTime(LocalTime.of(12, 0)) + .build(); + assertAll( + () -> assertEquals(1L, farmSchedule.getFarmId()), + () -> assertEquals(LocalDate.now(), farmSchedule.getDate()), + () -> assertEquals(LocalTime.of(10, 0), farmSchedule.getStartTime()), + () -> assertEquals(LocalTime.of(12, 0), farmSchedule.getEndTime()) + ); + } + + @Test + @DisplayName("시작 시간이 종료 시간보다 늦은 경우 예외를 발생시킨다") + void should_throwException_when_startTimeIsAfterEndTime() { + // given + FarmScheduleUpdateRequest request = new FarmScheduleUpdateRequest(1L, LocalDate.now(), LocalTime.of(10, 0), LocalTime.of(9, 0)); + + // when & then + BusinessException exception = assertThrows(BusinessException.class, () -> farmScheduleService.addFarmSchedule(request)); + assertEquals(START_TIME_SHOULD_BE_BEFORE_END_TIME, exception.getBusinessError()); + } + + @Test + @DisplayName("이미 등록된 스케줄이 있는 경우 예외를 발생시킨다") + void should_throwException_when_scheduleAlreadyExists() { + // given + FarmSchedule farmSchedule = FarmSchedule.builder() + .startTime(LocalTime.of(10, 0)) + .endTime(LocalTime.of(12, 0)) + .build(); + List farmSchedules = List.of(farmSchedule); + + given(farmScheduleRepository.findByFarmIdAndDate(1L, LocalDate.now())).willReturn(farmSchedules); + + FarmScheduleUpdateRequest request = new FarmScheduleUpdateRequest(1L, LocalDate.now(), LocalTime.of(11, 0), LocalTime.of(13, 0)); + + // when & then + BusinessException exception = assertThrows(BusinessException.class, () -> farmScheduleService.addFarmSchedule(request)); + assertEquals(FARM_SCHEDULE_ALREADY_EXISTS, exception.getBusinessError()); + } + } +} From 18a41675caa7cf1eeaf7e6aedc20cdd8463ae284 Mon Sep 17 00:00:00 2001 From: stopmin Date: Sat, 9 Nov 2024 16:24:20 +0900 Subject: [PATCH 02/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=EB=86=8D=EC=9E=A5=20=EC=8A=A4=EC=BC=80=EC=A5=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FarmScheduleServiceTest.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java diff --git a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java new file mode 100644 index 00000000..3ca621cc --- /dev/null +++ b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java @@ -0,0 +1,91 @@ +package poomasi.domain.farm._schedule.service; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import poomasi.domain.farm._schedule.dto.FarmScheduleUpdateRequest; +import poomasi.domain.farm._schedule.entity.FarmSchedule; +import poomasi.domain.farm._schedule.repository.FarmScheduleRepository; +import poomasi.global.error.BusinessException; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.BDDMockito.given; +import static poomasi.global.error.BusinessError.FARM_SCHEDULE_ALREADY_EXISTS; +import static poomasi.global.error.BusinessError.START_TIME_SHOULD_BE_BEFORE_END_TIME; + +@ExtendWith(MockitoExtension.class) +class FarmScheduleServiceTest { + @InjectMocks + private FarmScheduleService farmScheduleService; + + @Mock + private FarmScheduleRepository farmScheduleRepository; + + @Nested + @DisplayName("농장 스케줄 추가") + class AddFarmSchedule { + @Test + @DisplayName("정상적으로 스케줄을 추가한다") + void should_addFarmSchedule() { + // given + FarmScheduleUpdateRequest request = new FarmScheduleUpdateRequest(1L, LocalDate.now(), LocalTime.of(10, 0), LocalTime.of(12, 0)); + + given(farmScheduleRepository.findByFarmIdAndDate(1L, LocalDate.now())).willReturn(List.of()); + + // when + farmScheduleService.addFarmSchedule(request); + + // then + FarmSchedule farmSchedule = FarmSchedule.builder() + .farmId(1L) + .date(LocalDate.now()) + .startTime(LocalTime.of(10, 0)) + .endTime(LocalTime.of(12, 0)) + .build(); + assertAll( + () -> assertEquals(1L, farmSchedule.getFarmId()), + () -> assertEquals(LocalDate.now(), farmSchedule.getDate()), + () -> assertEquals(LocalTime.of(10, 0), farmSchedule.getStartTime()), + () -> assertEquals(LocalTime.of(12, 0), farmSchedule.getEndTime()) + ); + } + + @Test + @DisplayName("시작 시간이 종료 시간보다 늦은 경우 예외를 발생시킨다") + void should_throwException_when_startTimeIsAfterEndTime() { + // given + FarmScheduleUpdateRequest request = new FarmScheduleUpdateRequest(1L, LocalDate.now(), LocalTime.of(10, 0), LocalTime.of(9, 0)); + + // when & then + BusinessException exception = assertThrows(BusinessException.class, () -> farmScheduleService.addFarmSchedule(request)); + assertEquals(START_TIME_SHOULD_BE_BEFORE_END_TIME, exception.getBusinessError()); + } + + @Test + @DisplayName("이미 등록된 스케줄이 있는 경우 예외를 발생시킨다") + void should_throwException_when_scheduleAlreadyExists() { + // given + FarmSchedule farmSchedule = FarmSchedule.builder() + .startTime(LocalTime.of(10, 0)) + .endTime(LocalTime.of(12, 0)) + .build(); + List farmSchedules = List.of(farmSchedule); + + given(farmScheduleRepository.findByFarmIdAndDate(1L, LocalDate.now())).willReturn(farmSchedules); + + FarmScheduleUpdateRequest request = new FarmScheduleUpdateRequest(1L, LocalDate.now(), LocalTime.of(11, 0), LocalTime.of(13, 0)); + + // when & then + BusinessException exception = assertThrows(BusinessException.class, () -> farmScheduleService.addFarmSchedule(request)); + assertEquals(FARM_SCHEDULE_ALREADY_EXISTS, exception.getBusinessError()); + } + } +} From 2666d453e775d884358b0ea819b787bfa225fb6c Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 20:24:05 +0900 Subject: [PATCH 03/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=EB=86=8D=EC=9E=A5=20=EC=8A=A4=EC=BC=80=EC=A5=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FarmScheduleServiceTest.java | 18 ++++++++++++++++++ .../farm/service/FarmFarmerServiceTest.java | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java index 3ca621cc..130568cd 100644 --- a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java +++ b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java @@ -88,4 +88,22 @@ void should_throwException_when_scheduleAlreadyExists() { assertEquals(FARM_SCHEDULE_ALREADY_EXISTS, exception.getBusinessError()); } } + + @Nested + @DisplayName("농장 스케줄 조회") + class GetFarmSchedules { + @Test + @DisplayName("텅 빈 스케줄을 조회한다") + void should_getFarmSchedulesBySpecificDate() { + // given + LocalDate date = LocalDate.now(); + given(farmScheduleRepository.findByFarmIdAndDate(1L, date)).willReturn(List.of()); + + // when + List farmSchedules = farmScheduleService.getFarmScheduleByFarmIdAndDate(1L, date); + + // then + assertTrue(farmSchedules.isEmpty()); + } + } } diff --git a/src/test/java/poomasi/domain/farm/service/FarmFarmerServiceTest.java b/src/test/java/poomasi/domain/farm/service/FarmFarmerServiceTest.java index c34ca6f8..3fc65918 100644 --- a/src/test/java/poomasi/domain/farm/service/FarmFarmerServiceTest.java +++ b/src/test/java/poomasi/domain/farm/service/FarmFarmerServiceTest.java @@ -48,7 +48,7 @@ void should_throwException_when_farmAlreadyExists() { given(farmRepository.getFarmByOwnerIdAndDeletedAtIsNull(member.getId())).willReturn(Optional.of(existingFarm)); - FarmRegisterRequest request = new FarmRegisterRequest("New Farm", "Address", "Detail", 1.0, 1.0, "010-1234-5678", "Description", 10000L, 10, 5); + FarmRegisterRequest request = new FarmRegisterRequest("New Farm", "Address", "Detail", 1.0, 1.0, "010-1234-5678", "Description", 10000, 10, 5); // when & then assertThatThrownBy(() -> farmFarmerService.registerFarm(member, request)) From 3ee4ebb5180ba954e4fbd5bea51b925b9e41d7ee Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 20:29:06 +0900 Subject: [PATCH 04/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=EB=86=8D=EC=9E=A5=EC=9D=B4=20=EC=A1=B4=EC=9E=AC=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20-=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=20=EC=82=AD=EC=A0=9C=EB=90=9C=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/poomasi/domain/farm/entity/Farm.java | 3 +- .../farm/service/FarmFarmerServiceTest.java | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/poomasi/domain/farm/entity/Farm.java b/src/main/java/poomasi/domain/farm/entity/Farm.java index 1b4921f5..f3959092 100644 --- a/src/main/java/poomasi/domain/farm/entity/Farm.java +++ b/src/main/java/poomasi/domain/farm/entity/Farm.java @@ -80,7 +80,7 @@ public class Farm { List reviewList = new ArrayList<>(); @Builder - public Farm(Long id, String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude, String description, int experiencePrice, Integer maxCapacity, Integer maxReservation) { + public Farm(Long id, String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude, String description, int experiencePrice, Integer maxCapacity, Integer maxReservation, LocalDateTime deletedAt) { this.id = id; this.name = name; this.ownerId = ownerId; @@ -92,6 +92,7 @@ public Farm(Long id, String name, Long ownerId, String address, String addressDe this.experiencePrice = experiencePrice; this.maxCapacity = maxCapacity; this.maxReservation = maxReservation; + this.deletedAt = deletedAt; } public Farm updateFarm(FarmUpdateRequest farmUpdateRequest) { diff --git a/src/test/java/poomasi/domain/farm/service/FarmFarmerServiceTest.java b/src/test/java/poomasi/domain/farm/service/FarmFarmerServiceTest.java index 3fc65918..b6d3ac62 100644 --- a/src/test/java/poomasi/domain/farm/service/FarmFarmerServiceTest.java +++ b/src/test/java/poomasi/domain/farm/service/FarmFarmerServiceTest.java @@ -137,5 +137,41 @@ void should_deleteFarm_when_ownerMatches() { // then verify(farmRepository).delete(farm); } + + @Test + @DisplayName("농장이 존재하지 않는 경우 예외를 발생시킨다") + void should_throwException_when_farmNotExistOnDelete() { + // given + Long farmId = 1L; + Long farmerId = 1L; + given(farmRepository.findByIdAndDeletedAtIsNull(farmId)).willReturn(Optional.empty()); + + // when & then + assertThatThrownBy(() -> farmFarmerService.deleteFarm(farmerId, farmId)) + .isInstanceOf(BusinessException.class) + .hasFieldOrPropertyWithValue("businessError", BusinessError.FARM_NOT_FOUND); + } + + @Test + @DisplayName("농장이 이미 삭제된 경우 예외를 발생시킨다") + void should_throwException_when_farmAlreadyDeleted() { + // given + Long farmId = 1L; + Long farmerId = 1L; + Farm farm = Farm.builder() + .id(farmId) + .name("Farm") + .ownerId(farmerId) + .deletedAt(null) + .build(); + + given(farmRepository.findByIdAndDeletedAtIsNull(farmId)).willReturn(Optional.of(farm)); + + // when + farmFarmerService.deleteFarm(farmerId, farmId); + + // then + verify(farmRepository).delete(farm); + } } } From fa9b74ea4de840eae2237674d859fc737b43c137 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 20:43:34 +0900 Subject: [PATCH 05/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=EB=86=8D=EC=9E=A5=EC=9D=B4=20=EC=82=AD=EC=A0=9C=EB=90=9C=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=EB=A5=BC=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/poomasi/domain/farm/entity/Farm.java | 4 ++++ .../domain/farm/service/FarmServiceTest.java | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/poomasi/domain/farm/entity/Farm.java b/src/main/java/poomasi/domain/farm/entity/Farm.java index f3959092..9e58d938 100644 --- a/src/main/java/poomasi/domain/farm/entity/Farm.java +++ b/src/main/java/poomasi/domain/farm/entity/Farm.java @@ -116,4 +116,8 @@ public void updateMaxCapacity(Integer maxCapacity) { public void updateMaxReservation(Integer maxReservation) { this.maxReservation = maxReservation; } + + public void delete() { + this.deletedAt = LocalDateTime.now(); + } } diff --git a/src/test/java/poomasi/domain/farm/service/FarmServiceTest.java b/src/test/java/poomasi/domain/farm/service/FarmServiceTest.java index cc9603f0..a24ae9a0 100644 --- a/src/test/java/poomasi/domain/farm/service/FarmServiceTest.java +++ b/src/test/java/poomasi/domain/farm/service/FarmServiceTest.java @@ -58,6 +58,19 @@ void should_throwException_when_farmNotExist() { .isInstanceOf(BusinessException.class) .hasFieldOrPropertyWithValue("businessError", BusinessError.FARM_NOT_FOUND); } + + @Test + @DisplayName("농장이 삭제된 경우 예외를 발생시킨다") + void should_throwException_when_farmIsDeleted() { + // given + Farm farm = FarmTestHelper.makeRandomFarm(); + farm.delete(); + + // when & then + assertThatThrownBy(() -> farmService.getFarmByFarmId(farm.getId())) + .isInstanceOf(BusinessException.class) + .hasFieldOrPropertyWithValue("businessError", BusinessError.FARM_NOT_FOUND); + } } } From cb856c143275212410e33f5a59a99f849854f3d0 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 20:47:00 +0900 Subject: [PATCH 06/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=ED=8A=B9=EC=A0=95=20=EB=82=A0=EC=A7=9C=EC=9D=98=20=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=A5=B4=20=EC=A1=B0=ED=9A=8C=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FarmScheduleServiceTest.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java index 130568cd..54ccb834 100644 --- a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java +++ b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java @@ -94,7 +94,7 @@ void should_throwException_when_scheduleAlreadyExists() { class GetFarmSchedules { @Test @DisplayName("텅 빈 스케줄을 조회한다") - void should_getFarmSchedulesBySpecificDate() { + void should_getEmptyFarmSchedules() { // given LocalDate date = LocalDate.now(); given(farmScheduleRepository.findByFarmIdAndDate(1L, date)).willReturn(List.of()); @@ -105,5 +105,31 @@ void should_getFarmSchedulesBySpecificDate() { // then assertTrue(farmSchedules.isEmpty()); } + + @Test + @DisplayName("특정 날짜의 스케줄을 조회한다") + void should_getFarmSchedulesBySpecificDate() { + // given + LocalDate date = LocalDate.now(); + FarmSchedule farmSchedule = FarmSchedule.builder() + .farmId(1L) + .date(date) + .startTime(LocalTime.of(10, 0)) + .endTime(LocalTime.of(12, 0)) + .build(); + given(farmScheduleRepository.findByFarmIdAndDate(1L, date)).willReturn(List.of(farmSchedule)); + + // when + List farmSchedules = farmScheduleService.getFarmScheduleByFarmIdAndDate(1L, date); + + // then + assertAll( + () -> assertEquals(1, farmSchedules.size()), + () -> assertEquals(1L, farmSchedules.get(0).getFarmId()), + () -> assertEquals(date, farmSchedules.get(0).getDate()), + () -> assertEquals(LocalTime.of(10, 0), farmSchedules.get(0).getStartTime()), + () -> assertEquals(LocalTime.of(12, 0), farmSchedules.get(0).getEndTime()) + ); + } } } From 73682f45d197fed75ae3b925b6083b9fa84f026a Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 20:48:57 +0900 Subject: [PATCH 07/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=EB=90=9C=20=EC=8A=A4=EC=BC=80=EC=A4=84?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=88=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20save=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EA=B0=80=20=ED=98=B8=EC=B6=9C?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=EB=8B=A4=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FarmScheduleServiceTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java index 54ccb834..35dc4808 100644 --- a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java +++ b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java @@ -17,7 +17,10 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import static poomasi.global.error.BusinessError.FARM_SCHEDULE_ALREADY_EXISTS; import static poomasi.global.error.BusinessError.START_TIME_SHOULD_BE_BEFORE_END_TIME; @@ -87,6 +90,25 @@ void should_throwException_when_scheduleAlreadyExists() { BusinessException exception = assertThrows(BusinessException.class, () -> farmScheduleService.addFarmSchedule(request)); assertEquals(FARM_SCHEDULE_ALREADY_EXISTS, exception.getBusinessError()); } + + @Test + @DisplayName("중복된 스케줄이 있는 경우 save 메서드가 호출되지 않는다") + void should_notCallSave_when_scheduleAlreadyExists() { + // given + FarmSchedule farmSchedule = FarmSchedule.builder() + .startTime(LocalTime.of(10, 0)) + .endTime(LocalTime.of(12, 0)) + .build(); + List farmSchedules = List.of(farmSchedule); + + given(farmScheduleRepository.findByFarmIdAndDate(1L, LocalDate.now())).willReturn(farmSchedules); + + FarmScheduleUpdateRequest request = new FarmScheduleUpdateRequest(1L, LocalDate.now(), LocalTime.of(11, 0), LocalTime.of(13, 0)); + + // when & then + assertThrows(BusinessException.class, () -> farmScheduleService.addFarmSchedule(request)); + verify(farmScheduleRepository, never()).save(any(FarmSchedule.class)); + } } @Nested From 61d8105e2ad7ad2c26b1abae170b9a148b408061 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 20:49:52 +0900 Subject: [PATCH 08/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=EC=8A=A4=EC=BC=80=EC=A4=84=EC=9D=B4=20=EC=97=86=EB=8A=94=20?= =?UTF-8?q?=EB=82=A0=EC=A7=9C=EC=97=90=20=EB=8C=80=ED=95=B4=20=EB=B9=88=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=9C=EB=8B=A4=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_schedule/service/FarmScheduleServiceTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java index 35dc4808..df6adf61 100644 --- a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java +++ b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java @@ -153,5 +153,19 @@ void should_getFarmSchedulesBySpecificDate() { () -> assertEquals(LocalTime.of(12, 0), farmSchedules.get(0).getEndTime()) ); } + + @Test + @DisplayName("스케줄이 없는 날짜에 대해 빈 리스트를 반환한다") + void should_returnEmptyList_when_noSchedulesOnDate() { + // given + LocalDate date = LocalDate.of(2024, 11, 12); + given(farmScheduleRepository.findByFarmIdAndDate(1L, date)).willReturn(List.of()); + + // when + List result = farmScheduleService.getFarmScheduleByFarmIdAndDate(1L, date); + + // then + assertTrue(result.isEmpty()); + } } } From 091e08896073979ce14a623a0fdc00cae827f20e Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 20:52:06 +0900 Subject: [PATCH 09/20] =?UTF-8?q?test:=20FarmScheduleServiceTest=20-=20?= =?UTF-8?q?=ED=8A=B9=EC=A0=95=20=EC=9B=94=EC=97=90=20=ED=95=B4=EB=8B=B9?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=8A=A4=EC=BC=80=EC=A4=84=EC=9D=84=20?= =?UTF-8?q?=EC=98=AC=EB=B0=94=EB=A5=B4=EA=B2=8C=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=9C=EB=8B=A4=20-=20=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80?= =?UTF-8?q?=20=EC=95=8A=EB=8A=94=20=EC=8A=A4=EC=BC=80=EC=A4=84=20ID?= =?UTF-8?q?=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EA=B0=80=20=EB=B0=9C=EC=83=9D=ED=95=9C=EB=8B=A4=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FarmScheduleServiceTest.java | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java index df6adf61..7a611950 100644 --- a/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java +++ b/src/test/java/poomasi/domain/farm/_schedule/service/FarmScheduleServiceTest.java @@ -7,6 +7,8 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import poomasi.domain.farm._schedule.dto.FarmScheduleRequest; +import poomasi.domain.farm._schedule.dto.FarmScheduleResponse; import poomasi.domain.farm._schedule.dto.FarmScheduleUpdateRequest; import poomasi.domain.farm._schedule.entity.FarmSchedule; import poomasi.domain.farm._schedule.repository.FarmScheduleRepository; @@ -15,14 +17,14 @@ import java.time.LocalDate; import java.time.LocalTime; import java.util.List; +import java.util.Optional; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static poomasi.global.error.BusinessError.FARM_SCHEDULE_ALREADY_EXISTS; -import static poomasi.global.error.BusinessError.START_TIME_SHOULD_BE_BEFORE_END_TIME; +import static poomasi.global.error.BusinessError.*; @ExtendWith(MockitoExtension.class) class FarmScheduleServiceTest { @@ -167,5 +169,43 @@ void should_returnEmptyList_when_noSchedulesOnDate() { // then assertTrue(result.isEmpty()); } + + @Test + @DisplayName("특정 월에 해당하는 스케줄을 올바르게 조회한다") + void should_returnSchedulesWithinSpecifiedMonth() { + // given + LocalDate startDate = LocalDate.of(2024, 11, 1); + LocalDate endDate = LocalDate.of(2024, 11, 30); + FarmSchedule farmSchedule = FarmSchedule.builder() + .farmId(1L) + .date(LocalDate.of(2024, 11, 10)) + .startTime(LocalTime.of(10, 0)) + .endTime(LocalTime.of(12, 0)) + .build(); + + given(farmScheduleRepository.findByFarmIdAndDateRange(1L, startDate, endDate)).willReturn(List.of(farmSchedule)); + + // when + FarmScheduleRequest request = new FarmScheduleRequest(1L, 2024, 11); + List result = farmScheduleService.getFarmSchedulesByYearAndMonth(request); + + // then + assertEquals(1, result.size()); + assertEquals(farmSchedule.getDate(), result.get(0).date()); + assertEquals(farmSchedule.getStartTime(), result.get(0).startTime()); + assertEquals(farmSchedule.getEndTime(), result.get(0).endTime()); + } + + @Test + @DisplayName("존재하지 않는 스케줄 ID로 조회 시 예외가 발생한다") + void should_throwException_when_scheduleIdNotFound() { + // given + Long invalidId = 999L; + given(farmScheduleRepository.findById(invalidId)).willReturn(Optional.empty()); + + // when & then + BusinessException exception = assertThrows(BusinessException.class, () -> farmScheduleService.getFarmScheduleByScheduleId(invalidId)); + assertEquals(FARM_SCHEDULE_NOT_FOUND, exception.getBusinessError()); + } } } From e60ca722f3e3b50b0609c867095fa3fae376108f Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 21:25:15 +0900 Subject: [PATCH 10/20] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=99=98=EA=B2=BD=20=ED=82=A4=EA=B0=92=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?-=20application-test.yml=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/iamportTest/IamportTest.java | 36 ++++++++----------- .../config/s3/S3PresignedUrlServiceTest.java | 2 +- src/test/resources/application-test.yml | 5 +++ 3 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 src/test/resources/application-test.yml diff --git a/src/test/java/poomasi/domain/payment/iamportTest/IamportTest.java b/src/test/java/poomasi/domain/payment/iamportTest/IamportTest.java index 2d3df7bd..d2f79536 100644 --- a/src/test/java/poomasi/domain/payment/iamportTest/IamportTest.java +++ b/src/test/java/poomasi/domain/payment/iamportTest/IamportTest.java @@ -3,52 +3,46 @@ import com.siot.IamportRestClient.IamportClient; import com.siot.IamportRestClient.exception.IamportResponseException; import com.siot.IamportRestClient.request.PrepareData; -import com.siot.IamportRestClient.response.AccessToken; import com.siot.IamportRestClient.response.IamportResponse; -import com.siot.IamportRestClient.response.Payment; import com.siot.IamportRestClient.response.Prepare; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.web.client.RestTemplate; -import poomasi.domain.order._payment.dto.request.PaymentPreRegisterRequest; -import poomasi.domain.order._payment.dto.response.PaymentPreRegisterResponse; - +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; import java.io.IOException; import java.math.BigDecimal; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import static com.fasterxml.jackson.databind.type.LogicalType.DateTime; -import static org.junit.jupiter.api.Assertions.assertNotNull; - +@SpringBootTest +@ActiveProfiles("test") +@TestPropertySource(locations = "classpath:application-test.yml") public class IamportTest { - private IamportClient iamportClient; - private String apiKey="~"; - private String secretKey="~"; - private String accessToken; + @Value("${imp.api.key}") + private String apiKey; + + @Value("${imp.api.secretKey}") + private String secretKey; + @BeforeEach public void setUp() throws Exception { this.iamportClient = new IamportClient(apiKey, secretKey); - IamportResponse auth_response = iamportClient.getAuth(); - this.accessToken=auth_response.getResponse().getToken(); } @Test - public void portonePrePaymentRegister_Test() throws IamportResponseException ,IOException{ + public void portonePrePaymentRegister_Test() throws IamportResponseException, IOException { String merchantUid = "poomasi_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); BigDecimal amount = new BigDecimal("100"); PrepareData prepareData = new PrepareData(merchantUid, amount); - System.out.println(merchantUid); + // System.out.println(merchantUid); IamportResponse prepareIamportResponse = iamportClient.postPrepare(prepareData); System.out.println("Response Code: " + prepareIamportResponse.getCode()); System.out.println("Response Message: " + prepareIamportResponse.getMessage()); diff --git a/src/test/java/poomasi/global/config/s3/S3PresignedUrlServiceTest.java b/src/test/java/poomasi/global/config/s3/S3PresignedUrlServiceTest.java index 7bf948ae..d98d9ea6 100644 --- a/src/test/java/poomasi/global/config/s3/S3PresignedUrlServiceTest.java +++ b/src/test/java/poomasi/global/config/s3/S3PresignedUrlServiceTest.java @@ -4,6 +4,7 @@ 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.mock.mockito.MockBean; import poomasi.global.config.aws.AwsProperties; import poomasi.global.util.EncryptionUtil; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; @@ -18,7 +19,6 @@ @SpringBootTest public class S3PresignedUrlServiceTest { - private S3PresignedUrlService s3PresignedUrlService; @Autowired diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml new file mode 100644 index 00000000..d6de0111 --- /dev/null +++ b/src/test/resources/application-test.yml @@ -0,0 +1,5 @@ +imp: + api: + key: ${IMP_API_KEY} + secretKey: ${IMP_SECRET_KEY} + From 62694474664a3e5ad34b8898ab51f10e1f687560 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 21:29:56 +0900 Subject: [PATCH 11/20] =?UTF-8?q?build:=20ci-test.yml=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20-=20imp=20=ED=82=A4=EA=B0=92=20=EC=B6=94=EA=B0=80=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 4e8b8de5..170622d0 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -11,6 +11,9 @@ permissions: jobs: test: + env: + IMP_API_KEY: ${{ secrets.IMP_API_KEY }} + IMP_SECRET_KEY: ${{ secrets.IMP_SECRET_KEY }} runs-on: ubuntu-latest steps: - name: Checkout code From 7d92f9140b6dedcbba3e65e216ec5aac2f18ff23 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 21:31:20 +0900 Subject: [PATCH 12/20] =?UTF-8?q?build:=20ci-test.yml=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20-=20imp=20=ED=82=A4=EA=B0=92=20=EC=B6=94=EA=B0=80=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 170622d0..60969a86 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -27,6 +27,9 @@ jobs: - name: Cache Gradle packages uses: actions/cache@v3 + env: + IMzP_API_KEY: ${{ secrets.IMP_API_KEY }} + IMP_SECRET_KEY: ${{ secrets.IMP_SECRET_KEY }} with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} From 600183b67838b871b34b53ff592b47c1209b5fa0 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 21:34:06 +0900 Subject: [PATCH 13/20] =?UTF-8?q?chore:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 60969a86..f1aa6155 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -28,7 +28,7 @@ jobs: - name: Cache Gradle packages uses: actions/cache@v3 env: - IMzP_API_KEY: ${{ secrets.IMP_API_KEY }} + IMP_API_KEY: ${{ secrets.IMP_API_KEY }} IMP_SECRET_KEY: ${{ secrets.IMP_SECRET_KEY }} with: path: ~/.gradle/caches From 255f04582a8767d85e2f8a7dc27f03fb43865573 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 21:37:33 +0900 Subject: [PATCH 14/20] =?UTF-8?q?test:=20imp-key=20=EA=B0=92=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-test.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index f1aa6155..b296db1c 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -24,17 +24,20 @@ jobs: with: java-version: '21' distribution: 'adopt' - - - name: Cache Gradle packages - uses: actions/cache@v3 env: IMP_API_KEY: ${{ secrets.IMP_API_KEY }} IMP_SECRET_KEY: ${{ secrets.IMP_SECRET_KEY }} + + - name: Cache Gradle packages + uses: actions/cache@v3 with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle- + env: + IMP_API_KEY: ${{ secrets.IMP_API_KEY }} + IMP_SECRET_KEY: ${{ secrets.IMP_SECRET_KEY }} - name: Grant execute permission for gradlew run: chmod +x ./gradlew From f4880a957f467deb67cd1c1792d27405df80cb51 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 21:50:25 +0900 Subject: [PATCH 15/20] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=EC=8B=9C=20=EB=A1=9C=EA=B7=B8=20=EB=82=A8?= =?UTF-8?q?=EA=B8=B0=EB=8F=84=EB=A1=9D=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-test.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index b296db1c..5cb195d2 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -27,7 +27,7 @@ jobs: env: IMP_API_KEY: ${{ secrets.IMP_API_KEY }} IMP_SECRET_KEY: ${{ secrets.IMP_SECRET_KEY }} - + - name: Cache Gradle packages uses: actions/cache@v3 with: @@ -39,6 +39,13 @@ jobs: IMP_API_KEY: ${{ secrets.IMP_API_KEY }} IMP_SECRET_KEY: ${{ secrets.IMP_SECRET_KEY }} + - name: Upload test report + if: always() + uses: actions/upload-artifact@v2 + with: + name: test-report + path: build/reports/tests/test + - name: Grant execute permission for gradlew run: chmod +x ./gradlew From dcf8f8d7ed30aa39e426da6f99f05a9a8f9c5310 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 21:51:22 +0900 Subject: [PATCH 16/20] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=EC=8B=9C=20=EB=A1=9C=EA=B7=B8=20=EB=82=A8?= =?UTF-8?q?=EA=B8=B0=EB=8F=84=EB=A1=9D=20-=20=EB=B2=84=EC=A0=84=20?= =?UTF-8?q?=EC=97=85=EA=B7=B8=EB=A0=88=EC=9D=B4=EB=93=9C=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 5cb195d2..5501cdd1 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -41,7 +41,7 @@ jobs: - name: Upload test report if: always() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: test-report path: build/reports/tests/test From 52e2cfbca26652e8142d2c9d99e9fa5b160ec68a Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 22:00:40 +0900 Subject: [PATCH 17/20] =?UTF-8?q?build:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=94=94=EB=B9=84=20=EC=B6=94=EA=B0=80=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index d6de0111..51b36f18 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -1,3 +1,14 @@ +spring: + datasource: + url: jdbc:h2:mem:testdb + driver-class-name: org.h2.Driver + username: sa + password: + jpa: + hibernate: + ddl-auto: update + show-sql: true + imp: api: key: ${IMP_API_KEY} From ba92adc2abcf79694f799efc3a6e2acb67e41ac8 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 22:04:00 +0900 Subject: [PATCH 18/20] =?UTF-8?q?build:=20AWS=20=ED=82=A4=EA=B0=92=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 5501cdd1..255f110c 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -14,6 +14,8 @@ jobs: env: IMP_API_KEY: ${{ secrets.IMP_API_KEY }} IMP_SECRET_KEY: ${{ secrets.IMP_SECRET_KEY }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} runs-on: ubuntu-latest steps: - name: Checkout code From c03458a4a3e10e4f63fa702c59d5f339420d817b Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 22:07:20 +0900 Subject: [PATCH 19/20] =?UTF-8?q?test:=20Iamport=20=EB=AA=A8=ED=82=B9=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/payment/iamportTest/IamportTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/test/java/poomasi/domain/payment/iamportTest/IamportTest.java b/src/test/java/poomasi/domain/payment/iamportTest/IamportTest.java index d2f79536..9d0ac2f4 100644 --- a/src/test/java/poomasi/domain/payment/iamportTest/IamportTest.java +++ b/src/test/java/poomasi/domain/payment/iamportTest/IamportTest.java @@ -18,10 +18,15 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; + @SpringBootTest @ActiveProfiles("test") @TestPropertySource(locations = "classpath:application-test.yml") public class IamportTest { + + @MockBean private IamportClient iamportClient; @Value("${imp.api.key}") @@ -30,9 +35,8 @@ public class IamportTest { @Value("${imp.api.secretKey}") private String secretKey; - @BeforeEach - public void setUp() throws Exception { + public void setUp() { this.iamportClient = new IamportClient(apiKey, secretKey); } @@ -42,12 +46,14 @@ public void portonePrePaymentRegister_Test() throws IamportResponseException, IO BigDecimal amount = new BigDecimal("100"); PrepareData prepareData = new PrepareData(merchantUid, amount); - // System.out.println(merchantUid); + // `iamportClient.postPrepare` 모킹 설정 + IamportResponse mockResponse = new IamportResponse<>(); + given(iamportClient.postPrepare(any(PrepareData.class))).willReturn(mockResponse); + + // 테스트 실행 IamportResponse prepareIamportResponse = iamportClient.postPrepare(prepareData); System.out.println("Response Code: " + prepareIamportResponse.getCode()); System.out.println("Response Message: " + prepareIamportResponse.getMessage()); - } - } From dce5d2ba8194abf66c6e14c608c7da0744c10bd0 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 11 Nov 2024 22:10:27 +0900 Subject: [PATCH 20/20] =?UTF-8?q?test:=20spring=20profile=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20#113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 255f110c..5b739bfb 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -52,7 +52,7 @@ jobs: run: chmod +x ./gradlew - name: Run tests - run: ./gradlew test + run: SPRING_PROFILES_ACTIVE=[test] ./gradlew test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}