-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParticipantFacadeTest.java
More file actions
167 lines (135 loc) · 6.82 KB
/
ParticipantFacadeTest.java
File metadata and controls
167 lines (135 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package org.festimate.team.api.facade;
import org.festimate.team.api.participant.dto.MessageRequest;
import org.festimate.team.api.participant.dto.ProfileRequest;
import org.festimate.team.common.mock.MockFactory;
import org.festimate.team.domain.festival.entity.Festival;
import org.festimate.team.domain.festival.service.FestivalService;
import org.festimate.team.domain.matching.service.MatchingService;
import org.festimate.team.domain.participant.entity.Participant;
import org.festimate.team.domain.participant.entity.TypeResult;
import org.festimate.team.domain.participant.service.ParticipantService;
import org.festimate.team.domain.point.service.PointService;
import org.festimate.team.domain.user.entity.Gender;
import org.festimate.team.domain.user.entity.User;
import org.festimate.team.domain.user.service.UserService;
import org.festimate.team.global.exception.FestimateException;
import org.festimate.team.global.response.ResponseError;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.time.LocalDate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.*;
class ParticipantFacadeTest {
@Mock
private UserService userService;
@Mock
private FestivalService festivalService;
@Mock
private ParticipantService participantService;
@Mock
private PointService pointService;
@Mock
private MatchingService matchingService;
@InjectMocks
private ParticipantFacade participantFacade;
private User user;
private Festival festival;
private Participant participant;
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
user = MockFactory.mockUser("테스터", Gender.MAN, 1L);
festival = MockFactory.mockFestival(user, 1L, LocalDate.now(), LocalDate.now().plusDays(1));
participant = MockFactory.mockParticipant(user, festival, TypeResult.HEALING, 1L);
}
@Test
@DisplayName("참가자 입장 성공")
void entryFestival_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
var response = participantFacade.entryFestival(1L, 1L);
assertThat(response.participantId()).isNotNull();
}
@Test
@DisplayName("참가자 생성 성공")
void createParticipant_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.createParticipant(any(), any(), any())).thenReturn(participant);
var response = participantFacade.createParticipant(1L, 1L, null);
assertThat(response.participantId()).isNotNull();
verify(matchingService).matchPendingParticipants(participant);
}
@Test
@DisplayName("내 프로필 조회 성공")
void getParticipantProfile_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
var response = participantFacade.getParticipantProfile(1L, 1L);
assertThat(response.nickname()).isEqualTo("테스터");
}
@Test
@DisplayName("포인트 포함 요약정보 조회 성공")
void getParticipantSummary_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
when(pointService.getTotalPointByParticipant(participant)).thenReturn(10);
var response = participantFacade.getParticipantSummary(1L, 1L);
assertThat(response.point()).isEqualTo(10);
}
@Test
@DisplayName("자세한 프로필 조회 성공")
void getParticipantType_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
var response = participantFacade.getParticipantType(1L, 1L);
assertThat(response.nickname()).isEqualTo("테스터");
}
@Test
@DisplayName("메시지 수정 성공")
void modifyMessage_success() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(participant);
MessageRequest request = new MessageRequest("새로운 소개", "새로운 메세지");
participantFacade.modifyMessage(1L, 1L, request);
assertThat(participant.getIntroduction()).isEqualTo("새로운 소개");
assertThat(participant.getMessage()).isEqualTo("새로운 메세지");
}
@Test
@DisplayName("참가자 조회 실패 시 예외 발생")
void getParticipant_fail() {
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
when(participantService.getParticipant(user, festival)).thenReturn(null);
assertThatThrownBy(() -> participantFacade.getParticipant(1L, 1L))
.isInstanceOf(FestimateException.class)
.hasMessageContaining(ResponseError.PARTICIPANT_NOT_FOUND.getMessage());
}
@Test
@DisplayName("같은 유저가 같은 페스티벌에 중복 참가하려고 하면 예외가 발생해야 한다")
void createParticipant_duplicate_fail() {
// given
when(userService.getUserByIdOrThrow(1L)).thenReturn(user);
when(festivalService.getFestivalByIdOrThrow(1L)).thenReturn(festival);
// 이미 참가자가 존재한다고 설정
when(participantService.getParticipant(user, festival)).thenReturn(participant);
// createParticipant 호출 시 예외를 직접 발생시키도록 설정
when(participantService.createParticipant(any(), any(), any()))
.thenThrow(new FestimateException(ResponseError.PARTICIPANT_ALREADY_EXISTS));
// when & then
assertThatThrownBy(() -> participantFacade.createParticipant(1L, 1L,
new ProfileRequest(TypeResult.HEALING, "자기소개", "메시지")))
.isInstanceOf(FestimateException.class)
.hasMessageContaining(ResponseError.PARTICIPANT_ALREADY_EXISTS.getMessage());
}
}