forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniversityRecommendServiceTest.java
More file actions
183 lines (155 loc) · 8.66 KB
/
UniversityRecommendServiceTest.java
File metadata and controls
183 lines (155 loc) · 8.66 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
package com.example.solidconnection.university.service;
import com.example.solidconnection.country.fixture.CountryFixture;
import com.example.solidconnection.entity.InterestedCountry;
import com.example.solidconnection.entity.InterestedRegion;
import com.example.solidconnection.region.fixture.RegionFixture;
import com.example.solidconnection.repositories.InterestedCountyRepository;
import com.example.solidconnection.repositories.InterestedRegionRepository;
import com.example.solidconnection.siteuser.domain.SiteUser;
import com.example.solidconnection.siteuser.repository.SiteUserRepository;
import com.example.solidconnection.support.TestContainerSpringBootTest;
import com.example.solidconnection.type.PreparationStatus;
import com.example.solidconnection.type.Role;
import com.example.solidconnection.university.domain.UniversityInfoForApply;
import com.example.solidconnection.university.dto.UniversityInfoForApplyPreviewResponse;
import com.example.solidconnection.university.dto.UniversityRecommendsResponse;
import com.example.solidconnection.university.fixture.UniversityInfoForApplyFixture;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static com.example.solidconnection.university.service.UniversityRecommendService.RECOMMEND_UNIVERSITY_NUM;
import static org.assertj.core.api.Assertions.assertThat;
@TestContainerSpringBootTest
@DisplayName("대학교 추천 서비스 테스트")
class UniversityRecommendServiceTest {
@Autowired
private UniversityRecommendService universityRecommendService;
@Autowired
private SiteUserRepository siteUserRepository;
@Autowired
private InterestedRegionRepository interestedRegionRepository;
@Autowired
private InterestedCountyRepository interestedCountyRepository;
@Autowired
private GeneralUniversityRecommendService generalUniversityRecommendService;
@Autowired
private RegionFixture regionFixture;
@Autowired
private CountryFixture countryFixture;
@Autowired
private UniversityInfoForApplyFixture universityInfoForApplyFixture;
private SiteUser testUser;
private UniversityInfoForApply 괌대학_A_지원_정보;
private UniversityInfoForApply 괌대학_B_지원_정보;
private UniversityInfoForApply 네바다주립대학_라스베이거스_지원_정보;
private UniversityInfoForApply 메모리얼대학_세인트존스_A_지원_정보;
private UniversityInfoForApply 서던덴마크대학교_지원_정보;
private UniversityInfoForApply 코펜하겐IT대학_지원_정보;
private UniversityInfoForApply 그라츠대학_지원_정보;
private UniversityInfoForApply 그라츠공과대학_지원_정보;
private UniversityInfoForApply 린츠_카톨릭대학_지원_정보;
private UniversityInfoForApply 메이지대학_지원_정보;
@BeforeEach
void setUp() {
testUser = createSiteUser();
괌대학_A_지원_정보 = universityInfoForApplyFixture.괌대학_A_지원_정보();
괌대학_B_지원_정보 = universityInfoForApplyFixture.괌대학_B_지원_정보();
네바다주립대학_라스베이거스_지원_정보 = universityInfoForApplyFixture.네바다주립대학_라스베이거스_지원_정보();
메모리얼대학_세인트존스_A_지원_정보 = universityInfoForApplyFixture.메모리얼대학_세인트존스_A_지원_정보();
서던덴마크대학교_지원_정보 = universityInfoForApplyFixture.서던덴마크대학교_지원_정보();
코펜하겐IT대학_지원_정보 = universityInfoForApplyFixture.코펜하겐IT대학_지원_정보();
그라츠대학_지원_정보 = universityInfoForApplyFixture.그라츠대학_지원_정보();
그라츠공과대학_지원_정보 = universityInfoForApplyFixture.그라츠공과대학_지원_정보();
린츠_카톨릭대학_지원_정보 = universityInfoForApplyFixture.린츠_카톨릭대학_지원_정보();
메이지대학_지원_정보 = universityInfoForApplyFixture.메이지대학_지원_정보();
generalUniversityRecommendService.init();
}
@Test
void 관심_지역_설정한_사용자의_맞춤_추천_대학을_조회한다() {
// given
interestedRegionRepository.save(new InterestedRegion(testUser, regionFixture.영미권()));
// when
UniversityRecommendsResponse response = universityRecommendService.getPersonalRecommends(testUser);
// then
assertThat(response.recommendedUniversities())
.hasSize(RECOMMEND_UNIVERSITY_NUM)
.containsAll(List.of(
UniversityInfoForApplyPreviewResponse.from(괌대학_A_지원_정보),
UniversityInfoForApplyPreviewResponse.from(괌대학_B_지원_정보),
UniversityInfoForApplyPreviewResponse.from(메모리얼대학_세인트존스_A_지원_정보),
UniversityInfoForApplyPreviewResponse.from(네바다주립대학_라스베이거스_지원_정보)
));
}
@Test
void 관심_국가_설정한_사용자의_맞춤_추천_대학을_조회한다() {
// given
interestedCountyRepository.save(new InterestedCountry(testUser, countryFixture.덴마크()));
// when
UniversityRecommendsResponse response = universityRecommendService.getPersonalRecommends(testUser);
// then
assertThat(response.recommendedUniversities())
.hasSize(RECOMMEND_UNIVERSITY_NUM)
.containsAll(List.of(
UniversityInfoForApplyPreviewResponse.from(서던덴마크대학교_지원_정보),
UniversityInfoForApplyPreviewResponse.from(코펜하겐IT대학_지원_정보)
));
}
@Test
void 관심_지역과_국가_모두_설정한_사용자의_맞춤_추천_대학을_조회한다() {
// given
interestedRegionRepository.save(new InterestedRegion(testUser, regionFixture.영미권()));
interestedCountyRepository.save(new InterestedCountry(testUser, countryFixture.덴마크()));
// when
UniversityRecommendsResponse response = universityRecommendService.getPersonalRecommends(testUser);
// then
assertThat(response.recommendedUniversities())
.hasSize(RECOMMEND_UNIVERSITY_NUM)
.containsExactlyInAnyOrder(
UniversityInfoForApplyPreviewResponse.from(괌대학_A_지원_정보),
UniversityInfoForApplyPreviewResponse.from(괌대학_B_지원_정보),
UniversityInfoForApplyPreviewResponse.from(메모리얼대학_세인트존스_A_지원_정보),
UniversityInfoForApplyPreviewResponse.from(네바다주립대학_라스베이거스_지원_정보),
UniversityInfoForApplyPreviewResponse.from(서던덴마크대학교_지원_정보),
UniversityInfoForApplyPreviewResponse.from(코펜하겐IT대학_지원_정보)
);
}
@Test
void 관심사_미설정_사용자는_일반_추천_대학을_조회한다() {
// when
UniversityRecommendsResponse response = universityRecommendService.getPersonalRecommends(testUser);
// then
assertThat(response.recommendedUniversities())
.hasSize(RECOMMEND_UNIVERSITY_NUM)
.containsExactlyInAnyOrderElementsOf(
generalUniversityRecommendService.getRecommendUniversities().stream()
.map(UniversityInfoForApplyPreviewResponse::from)
.toList()
);
}
@Test
void 일반_추천_대학을_조회한다() {
// when
UniversityRecommendsResponse response = universityRecommendService.getGeneralRecommends();
// then
assertThat(response.recommendedUniversities())
.hasSize(RECOMMEND_UNIVERSITY_NUM)
.containsExactlyInAnyOrderElementsOf(
generalUniversityRecommendService.getRecommendUniversities().stream()
.map(UniversityInfoForApplyPreviewResponse::from)
.toList()
);
}
// todo : 추후 Fixture로 대체 필요
private SiteUser createSiteUser() {
SiteUser siteUser = new SiteUser(
"test@example.com",
"nickname",
"profileImageUrl",
PreparationStatus.CONSIDERING,
Role.MENTEE
);
return siteUserRepository.save(siteUser);
}
}