-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathUnivApplyInfoQueryServiceTest.java
More file actions
222 lines (183 loc) · 10.1 KB
/
UnivApplyInfoQueryServiceTest.java
File metadata and controls
222 lines (183 loc) · 10.1 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package com.example.solidconnection.university.service;
import static com.example.solidconnection.common.exception.ErrorCode.UNIV_APPLY_INFO_NOT_FOUND;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.times;
import com.example.solidconnection.common.exception.CustomException;
import com.example.solidconnection.support.TestContainerSpringBootTest;
import com.example.solidconnection.term.domain.Term;
import com.example.solidconnection.term.fixture.TermFixture;
import com.example.solidconnection.university.domain.UnivApplyInfo;
import com.example.solidconnection.university.dto.UnivApplyInfoDetailResponse;
import com.example.solidconnection.university.dto.UnivApplyInfoPreviewResponse;
import com.example.solidconnection.university.dto.UnivApplyInfoPreviewResponses;
import com.example.solidconnection.university.fixture.UnivApplyInfoFixture;
import com.example.solidconnection.university.repository.UnivApplyInfoRepository;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.SpyBean;
@TestContainerSpringBootTest
@DisplayName("대학 지원 정보 조회 서비스 테스트")
class UnivApplyInfoQueryServiceTest {
@Autowired
private UnivApplyInfoQueryService univApplyInfoQueryService;
@SpyBean
private UnivApplyInfoRepository univApplyInfoRepository;
@Autowired
private UnivApplyInfoFixture univApplyInfoFixture;
@Autowired
private TermFixture termFixture;
private Term term;
@BeforeEach
void setUp() {
term = termFixture.현재_학기("2025-2");
}
@Nested
class 대학_지원_정보_상세_조회 {
@Test
void 대학_지원_정보를_상세_조회한다() {
// given
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보(term.getId());
// when
UnivApplyInfoDetailResponse response = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
// then
assertThat(response.id()).isEqualTo(괌대학_A_지원_정보.getId());
}
@Test
void 대학_지원_정보_상세_조회시_캐시가_적용된다() {
// given
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보(term.getId());
// when
UnivApplyInfoDetailResponse firstResponse = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
UnivApplyInfoDetailResponse secondResponse = univApplyInfoQueryService.getUnivApplyInfoDetail(괌대학_A_지원_정보.getId());
// then
assertThat(firstResponse).isEqualTo(secondResponse);
then(univApplyInfoRepository).should(times(1)).getUnivApplyInfoById(괌대학_A_지원_정보.getId());
}
@Test
void 존재하지_않는_대학_지원_정보를_조회하면_예외가_발생한다() {
// given
Long invalidUnivApplyInfoId = 9999L;
// when & then
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> univApplyInfoQueryService.getUnivApplyInfoDetail(invalidUnivApplyInfoId))
.havingRootCause()
.isInstanceOf(CustomException.class)
.withMessage(UNIV_APPLY_INFO_NOT_FOUND.getMessage());
}
}
@Nested
class 대학_지원_정보_텍스트_검색 {
@Test
void 텍스트가_없으면_전체_대학을_id_순으로_정렬하여_반환한다() {
// given
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보(term.getId());
UnivApplyInfo 메이지대학_지원_정보 = univApplyInfoFixture.메이지대학_지원_정보(term.getId());
// when
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfoByText(null);
// then
assertThat(response.univApplyInfoPreviews())
.containsExactly(
UnivApplyInfoPreviewResponse.of(괌대학_A_지원_정보, term.getName()),
UnivApplyInfoPreviewResponse.of(메이지대학_지원_정보, term.getName())
);
}
@Nested
class 각각의_검색_대상에_대해_검색한다 {
@Test
void 국문_대학_지원_정보명() {
// given
String text = "메";
UnivApplyInfo 메이지대학_지원_정보 = univApplyInfoFixture.메이지대학_지원_정보(term.getId());
UnivApplyInfo 메모리얼대학_세인트존스_A_지원_정보 = univApplyInfoFixture.메모리얼대학_세인트존스_A_지원_정보(term.getId());
univApplyInfoFixture.괌대학_A_지원_정보(term.getId());
// when
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfoByText(text);
// then
assertThat(response.univApplyInfoPreviews())
.containsExactly(
UnivApplyInfoPreviewResponse.of(메이지대학_지원_정보, term.getName()),
UnivApplyInfoPreviewResponse.of(메모리얼대학_세인트존스_A_지원_정보, term.getName())
);
}
@Test
void 국문_국가명() {
// given
String text = "미국";
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보(term.getId());
UnivApplyInfo 버지니아공과대학_지원_정보 = univApplyInfoFixture.버지니아공과대학_지원_정보(term.getId());
univApplyInfoFixture.메이지대학_지원_정보(term.getId());
// when
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfoByText(text);
// then
assertThat(response.univApplyInfoPreviews())
.containsExactly(
UnivApplyInfoPreviewResponse.of(괌대학_A_지원_정보, term.getName()),
UnivApplyInfoPreviewResponse.of(버지니아공과대학_지원_정보, term.getName())
);
}
@Test
void 국문_권역명() {
// given
String text = "유럽";
UnivApplyInfo 린츠_카톨릭대학_지원_정보 = univApplyInfoFixture.린츠_카톨릭대학_지원_정보(term.getId());
UnivApplyInfo 서던덴마크대학교_지원_정보 = univApplyInfoFixture.서던덴마크대학교_지원_정보(term.getId());
univApplyInfoFixture.메이지대학_지원_정보(term.getId());
// when
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfoByText(text);
// then
assertThat(response.univApplyInfoPreviews())
.containsExactly(
UnivApplyInfoPreviewResponse.of(린츠_카톨릭대학_지원_정보, term.getName()),
UnivApplyInfoPreviewResponse.of(서던덴마크대학교_지원_정보, term.getName())
);
}
}
@Test
void 대학_국가_권역_일치_순서로_정렬하여_응답한다() {
// given
String text = "아";
UnivApplyInfo 권역_아 = univApplyInfoFixture.메이지대학_지원_정보(term.getId());
UnivApplyInfo 국가_아 = univApplyInfoFixture.그라츠대학_지원_정보(term.getId());
UnivApplyInfo 대학지원정보_아 = univApplyInfoFixture.아칸소주립대학_지원_정보(term.getId());
// when
UnivApplyInfoPreviewResponses response = univApplyInfoQueryService.searchUnivApplyInfoByText(text);
// then
assertThat(response.univApplyInfoPreviews())
.containsExactly(
UnivApplyInfoPreviewResponse.of(대학지원정보_아, term.getName()),
UnivApplyInfoPreviewResponse.of(국가_아, term.getName()),
UnivApplyInfoPreviewResponse.of(권역_아, term.getName())
);
}
// todo: 현재 레디스 관련 에러 발생중으로 임시 주석처리, 추후 원인 분석 후 적용 필요
// @Test
void 캐시가_적용된다() {
// given
String text = "Guam";
UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보(term.getId());
// when
UnivApplyInfoPreviewResponses firstResponse = univApplyInfoQueryService.searchUnivApplyInfoByText(text);
UnivApplyInfoPreviewResponses secondResponse = univApplyInfoQueryService.searchUnivApplyInfoByText(text);
// then
assertThatCode(() -> {
List<Long> firstResponseIds = extractIds(firstResponse);
List<Long> secondResponseIds = extractIds(secondResponse);
assertThat(firstResponseIds).isEqualTo(secondResponseIds);
}).doesNotThrowAnyException();
then(univApplyInfoRepository).should(times(1)).findAllByText(text, term.getId());
}
private List<Long> extractIds(UnivApplyInfoPreviewResponses responses) {
return responses.univApplyInfoPreviews()
.stream()
.map(UnivApplyInfoPreviewResponse::id)
.toList();
}
}
}