-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91f694a
commit 160b364
Showing
7 changed files
with
162 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import static org.springframework.test.util.AssertionErrors.fail; | ||
|
||
import gdsc.konkuk.platformcore.application.email.exceptions.EmailAlreadyProcessedException; | ||
import gdsc.konkuk.platformcore.controller.email.dtos.EmailReceiverInfo; | ||
import gdsc.konkuk.platformcore.controller.email.dtos.EmailSendRequest; | ||
import gdsc.konkuk.platformcore.domain.email.entity.EmailTask; | ||
import gdsc.konkuk.platformcore.domain.email.repository.EmailTaskRepository; | ||
|
@@ -74,11 +75,15 @@ void should_save_task_at_InMemoryTaskRepository() { | |
EmailSendRequest.builder() | ||
.subject("subject") | ||
.content("content") | ||
.receivers(Set.of("example1.com", "example2.com")) | ||
.receiverInfos(Set.of( | ||
EmailReceiverInfo.builder().email("example1.com").name("guest1").build(), | ||
EmailReceiverInfo.builder().email("example2.com").name("guest2").build())) | ||
.sendAt(LocalDateTime.now().plusHours(1)) | ||
.build(); | ||
|
||
// when | ||
EmailTask emailTask = emailTaskFacade.register(emailRequest); | ||
|
||
// then | ||
assertNotNull("Task should not be null", emailTask); | ||
assertNotNull( | ||
|
@@ -94,15 +99,18 @@ void should_send_task_when_time_is_up() throws InterruptedException { | |
EmailSendRequest.builder() | ||
.subject("subject") | ||
.content("content") | ||
.receivers(Set.of("[email protected]", "[email protected]")) | ||
.receiverInfos(Set.of( | ||
EmailReceiverInfo.builder().email("[email protected]").name("guest1").build(), | ||
EmailReceiverInfo.builder().email("[email protected]").name("guest2").build())) | ||
.sendAt(LocalDateTime.now().plusSeconds(5L)) | ||
.build(); | ||
|
||
// when | ||
emailTaskFacade.register(emailRequest); | ||
sleep(10000); | ||
|
||
// then | ||
verify(emailClient).sendEmailToReceivers(any(EmailTask.class)); | ||
|
||
assertEquals(0, executor.getQueue().size()); | ||
assertEquals(0, taskInMemoryRepository.size()); | ||
} | ||
|
@@ -113,7 +121,6 @@ void should_send_task_when_time_is_up() throws InterruptedException { | |
* 2. 작업 수정 요청 | ||
* 3. 기존의 작업 취소, 새로운 작업 예약 | ||
* */ | ||
|
||
@Test | ||
@DisplayName("작업 수정 시 스케줄된 작업 취소 후 다시 스케줄") | ||
void should_cancel_and_schedule_new_when_update() { | ||
|
@@ -122,21 +129,29 @@ void should_cancel_and_schedule_new_when_update() { | |
EmailSendRequest.builder() | ||
.subject("subject") | ||
.content("content") | ||
.receivers(Set.of("example1.com", "example2.com")) | ||
.receiverInfos(Set.of( | ||
EmailReceiverInfo.builder().email("example1.com").name("guest1").build(), | ||
EmailReceiverInfo.builder().email("example2.com").name("guest2").build())) | ||
.sendAt(LocalDateTime.now().plusHours(1)) | ||
.build(); | ||
EmailTask emailTask = emailTaskFacade.register(emailRequest); | ||
|
||
assertEquals(1, executor.getQueue().size()); | ||
assertEquals(1, taskInMemoryRepository.size()); | ||
|
||
EmailSendRequest updatedRequest = | ||
EmailSendRequest.builder() | ||
.subject("subject") | ||
.content("content") | ||
.receivers(Set.of("example1.com", "example2.com")) | ||
.receiverInfos(Set.of( | ||
EmailReceiverInfo.builder().email("example1.com").name("guest1").build(), | ||
EmailReceiverInfo.builder().email("example2.com").name("guest2").build())) | ||
.sendAt(LocalDateTime.now().plusHours(2)) | ||
.build(); | ||
|
||
// when | ||
emailTaskFacade.update(emailTask.getId(), updatedRequest); | ||
|
||
// then | ||
assertEquals(1, executor.getQueue().size()); | ||
assertNotNull( | ||
|
@@ -158,7 +173,9 @@ void should_cancel_task() { | |
EmailSendRequest.builder() | ||
.subject("subject") | ||
.content("content") | ||
.receivers(Set.of("example1.com", "example2.com")) | ||
.receiverInfos(Set.of( | ||
EmailReceiverInfo.builder().email("example1.com").name("guest1").build(), | ||
EmailReceiverInfo.builder().email("example2.com").name("guest2").build())) | ||
.sendAt(LocalDateTime.now().plusHours(1)) | ||
.build(); | ||
EmailTask emailTask = emailTaskFacade.register(emailRequest); | ||
|
@@ -167,7 +184,6 @@ void should_cancel_task() { | |
// when | ||
emailTaskFacade.cancel(emailTask.getId()); | ||
|
||
|
||
// then | ||
assertEquals(0, executor.getQueue().size()); | ||
assertTrue(emailTaskRepository.findById(emailTask.getId()).isEmpty()); | ||
|
@@ -184,7 +200,9 @@ void should_fail_when_cancel_already_processed_task() throws Exception { | |
EmailSendRequest.builder() | ||
.subject("subject") | ||
.content("content") | ||
.receivers(Set.of("example1.com", "example2.com")) | ||
.receiverInfos(Set.of( | ||
EmailReceiverInfo.builder().email("example1.com").name("guest1").build(), | ||
EmailReceiverInfo.builder().email("example2.com").name("guest2").build())) | ||
.sendAt(LocalDateTime.now().plusSeconds(1L)) | ||
.build(); | ||
|
||
|
@@ -208,11 +226,14 @@ void should_send_discord_message_when_email_sending_error() throws InterruptedEx | |
EmailSendRequest.builder() | ||
.subject("subject") | ||
.content("content") | ||
.receivers(Set.of("example1.com", "example2.com")) | ||
.receiverInfos(Set.of( | ||
EmailReceiverInfo.builder().email("example1.com").name("guest1").build(), | ||
EmailReceiverInfo.builder().email("example2.com").name("guest2").build())) | ||
.sendAt(LocalDateTime.now().plusSeconds(1L)) | ||
.build(); | ||
doThrow(EmailSendingException.of(GlobalErrorCode.INTERNAL_SERVER_ERROR)) | ||
.when(emailClient).sendEmailToReceivers(any()); | ||
|
||
//when | ||
EmailTask scheduledTask = emailTaskFacade.register(emailRequest); | ||
sleep(2000); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.