-
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
a392d88
commit 98efa89
Showing
13 changed files
with
193 additions
and
18 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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/spaceclub/global/exception/MailTemplateException.java
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.spaceclub.global.exception; | ||
|
||
public class MailTemplateException extends RuntimeException { | ||
|
||
public MailTemplateException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/spaceclub/notification/mail/service/MailTemplateLoader.java
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.spaceclub.notification.mail.service; | ||
|
||
import com.spaceclub.global.exception.MailTemplateException; | ||
import com.spaceclub.notification.mail.domain.Template; | ||
import com.spaceclub.notification.mail.domain.repository.TemplateRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@Profile("!test") | ||
@RequiredArgsConstructor | ||
public class MailTemplateLoader implements ApplicationRunner { | ||
|
||
private final static int MAIL_TEMPLATE_COUNT = 2; | ||
|
||
private final TemplateRepository templateRepository; | ||
|
||
@Override | ||
public void run(ApplicationArguments args) { | ||
List<Template> mailTemplates = templateRepository.findAll(); | ||
|
||
if (mailTemplates.size() != MAIL_TEMPLATE_COUNT) { | ||
throw new MailTemplateException("메일 템플릿이 2개가 아닙니다."); | ||
} | ||
} | ||
|
||
} |
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
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
52 changes: 52 additions & 0 deletions
52
src/test/java/com/spaceclub/notification/mail/service/MailTemplateLoaderTest.java
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.spaceclub.notification.mail.service; | ||
|
||
import com.spaceclub.global.exception.MailTemplateException; | ||
import com.spaceclub.notification.mail.domain.Template; | ||
import com.spaceclub.notification.mail.domain.repository.TemplateRepository; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatNoException; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@SpringBootTest | ||
class MailTemplateLoaderTest { | ||
|
||
@MockBean | ||
private TemplateRepository templateRepository; | ||
|
||
@Test | ||
void DB에_메일템플릿이_두개일경우_예외를_발생하지_않는다() { | ||
// given | ||
MailTemplateLoader mailTemplateLoader = new MailTemplateLoader(templateRepository); | ||
|
||
Template template1 = Template.builder().id(1L).template("test").build(); | ||
Template template2 = Template.builder().id(2L).template("TEST2").build(); | ||
given(templateRepository.findAll()).willReturn(List.of(template1, template2)); | ||
|
||
// when, then | ||
assertThatNoException() | ||
.isThrownBy(() -> mailTemplateLoader.run(mock(ApplicationArguments.class))); | ||
|
||
} | ||
|
||
@Test | ||
void DB에_메일템플릿이_두개가_아닐경우_예외를_발생한다() { | ||
// given | ||
MailTemplateLoader mailTemplateLoader = new MailTemplateLoader(templateRepository); | ||
|
||
Template template1 = Template.builder().id(1L).template("test").build(); | ||
given(templateRepository.findAll()).willReturn(List.of(template1)); | ||
|
||
// when, then | ||
assertThrows(MailTemplateException.class, () -> mailTemplateLoader.run(mock(ApplicationArguments.class))); | ||
} | ||
|
||
} | ||
|
41 changes: 41 additions & 0 deletions
41
src/test/java/com/spaceclub/notification/mail/service/event/MailEventTest.java
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.spaceclub.notification.mail.service.event; | ||
|
||
import com.spaceclub.notification.mail.service.vo.EventStatusChangeMailInfo; | ||
import com.spaceclub.notification.mail.service.vo.MailInfo; | ||
import com.spaceclub.notification.mail.service.vo.WelcomeMailInfo; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class MailEventTest { | ||
|
||
@Test | ||
void 이메일만으로_웰컴_메일_이벤트_생성에_성공한다() { | ||
// given | ||
String email = "[email protected]"; | ||
|
||
// when | ||
MailEvent mailEvent = MailEvent.createMailEvent(email); | ||
MailInfo mailInfo = mailEvent.mailInfo(); | ||
|
||
// then | ||
assertThat(mailInfo).isInstanceOf(WelcomeMailInfo.class); | ||
} | ||
|
||
@Test | ||
void 이메일과_클럽이름_이벤트이름_이벤트_상태로_상태변경_이벤트_생성에_성공한다() { | ||
// given | ||
String email = "[email protected]"; | ||
String clubName = "Skrrr"; | ||
String eventName = "Skrrr Event"; | ||
String eventStatus = "CONFIRMED"; | ||
|
||
// when | ||
MailEvent mailEvent = MailEvent.createMailEvent(email, clubName, eventName, eventStatus); | ||
MailInfo mailInfo = mailEvent.mailInfo(); | ||
|
||
// then | ||
assertThat(mailInfo).isInstanceOf(EventStatusChangeMailInfo.class); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/com/spaceclub/notification/mail/service/vo/ParticipationStatusTest.java
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.spaceclub.notification.mail.service.vo; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatNoException; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
class ParticipationStatusTest { | ||
|
||
@ParameterizedTest | ||
@EnumSource(ParticipationStatus.class) | ||
void 이벤트_상태로_상태_명을_조회하는데_성공한다(ParticipationStatus status) { | ||
// when, then | ||
String statusName = ParticipationStatus.getStatusName(status.name()); | ||
|
||
assertThatNoException().isThrownBy(() -> ParticipationStatus.getStatusName(status.name())); | ||
assertThat(statusName).isNotEmpty(); | ||
} | ||
|
||
@Test | ||
void 존재하지_않는_이벤트_상태로_상태명을_조회하면_예외가_발생한다() { | ||
// given | ||
String eventStatus = "NON_EXISTING_STATUS"; | ||
|
||
// when, then | ||
assertThatThrownBy(() -> ParticipationStatus.getStatusName(eventStatus)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
} |