22
33import static org .assertj .core .api .Assertions .assertThat ;
44import static org .assertj .core .api .Assertions .assertThatCode ;
5+ import static org .mockito .BDDMockito .then ;
6+ import static org .mockito .Mockito .times ;
57
68import com .example .solidconnection .admin .university .dto .AdminHostUniversityCreateRequest ;
79import com .example .solidconnection .admin .university .dto .AdminHostUniversityDetailResponse ;
810import com .example .solidconnection .admin .university .dto .AdminHostUniversityResponse ;
911import com .example .solidconnection .admin .university .dto .AdminHostUniversitySearchCondition ;
1012import com .example .solidconnection .admin .university .dto .AdminHostUniversityUpdateRequest ;
1113import com .example .solidconnection .admin .university .service .AdminHostUniversityService ;
14+ import com .example .solidconnection .cache .manager .CustomCacheManager ;
1215import com .example .solidconnection .common .exception .CustomException ;
1316import com .example .solidconnection .common .exception .ErrorCode ;
1417import com .example .solidconnection .location .country .domain .Country ;
1720import com .example .solidconnection .location .region .fixture .RegionFixture ;
1821import com .example .solidconnection .support .TestContainerSpringBootTest ;
1922import com .example .solidconnection .university .domain .HostUniversity ;
23+ import com .example .solidconnection .university .domain .UnivApplyInfo ;
2024import com .example .solidconnection .university .fixture .UnivApplyInfoFixtureBuilder ;
2125import com .example .solidconnection .university .fixture .UniversityFixture ;
2226import com .example .solidconnection .university .repository .HostUniversityRepository ;
27+ import java .util .List ;
2328import org .junit .jupiter .api .DisplayName ;
2429import org .junit .jupiter .api .Nested ;
2530import org .junit .jupiter .api .Test ;
2631import org .springframework .beans .factory .annotation .Autowired ;
32+ import org .springframework .boot .test .mock .mockito .SpyBean ;
2733import org .springframework .data .domain .Page ;
2834import org .springframework .data .domain .PageRequest ;
2935
@@ -49,6 +55,9 @@ class AdminHostUniversityServiceTest {
4955 @ Autowired
5056 private UnivApplyInfoFixtureBuilder univApplyInfoFixtureBuilder ;
5157
58+ @ SpyBean
59+ private CustomCacheManager cacheManager ;
60+
5261 @ Nested
5362 class 목록_조회 {
5463
@@ -398,4 +407,82 @@ class 삭제 {
398407 .hasMessage (ErrorCode .HOST_UNIVERSITY_HAS_REFERENCES .getMessage ());
399408 }
400409 }
410+
411+ @ Nested
412+ class 캐시_무효화 {
413+
414+ @ Test
415+ void 대학_생성_시_캐시가_무효화된다 () {
416+ // given
417+ Country country = countryFixture .미국 ();
418+ Region region = regionFixture .영미권 ();
419+
420+ AdminHostUniversityCreateRequest request = new AdminHostUniversityCreateRequest (
421+ "캐시 테스트 대학" ,
422+ "Cache Test University" ,
423+ "캐시 테스트 대학" ,
424+ "https://homepage.com" ,
425+ null , null ,
426+ "https://logo.com/image.png" ,
427+ "https://background.com/image.png" ,
428+ null ,
429+ country .getCode (),
430+ region .getCode ()
431+ );
432+
433+ // when
434+ adminHostUniversityService .createHostUniversity (request );
435+
436+ // then
437+ then (cacheManager ).should (times (1 )).evictUsingPrefix ("univApplyInfoTextSearch" );
438+ then (cacheManager ).should (times (1 )).evictUsingPrefix ("university:recommend:general" );
439+ }
440+
441+ @ Test
442+ void 대학_수정_시_캐시가_무효화된다 () {
443+ // given
444+ HostUniversity university = universityFixture .괌_대학 ();
445+ UnivApplyInfo univApplyInfo = univApplyInfoFixtureBuilder .univApplyInfo ()
446+ .termId (1L )
447+ .koreanName ("괌 대학 지원 정보" )
448+ .university (university )
449+ .create ();
450+
451+ Country country = countryFixture .일본 ();
452+ Region region = regionFixture .아시아 ();
453+
454+ AdminHostUniversityUpdateRequest request = new AdminHostUniversityUpdateRequest (
455+ "수정된 대학명" ,
456+ "Updated University" ,
457+ "수정된 표시명" ,
458+ null , null , null ,
459+ "https://logo.com/image.png" ,
460+ "https://background.com/image.png" ,
461+ null ,
462+ country .getCode (),
463+ region .getCode ()
464+ );
465+
466+ // when
467+ adminHostUniversityService .updateHostUniversity (university .getId (), request );
468+
469+ // then
470+ then (cacheManager ).should (times (1 )).evictUsingPrefix ("univApplyInfoTextSearch" );
471+ then (cacheManager ).should (times (1 )).evictUsingPrefix ("university:recommend:general" );
472+ then (cacheManager ).should (times (1 )).evictMultiple (List .of ("univApplyInfo:" + univApplyInfo .getId ()));
473+ }
474+
475+ @ Test
476+ void 대학_삭제_시_캐시가_무효화된다 () {
477+ // given
478+ HostUniversity university = universityFixture .괌_대학 ();
479+
480+ // when
481+ adminHostUniversityService .deleteHostUniversity (university .getId ());
482+
483+ // then
484+ then (cacheManager ).should (times (1 )).evictUsingPrefix ("univApplyInfoTextSearch" );
485+ then (cacheManager ).should (times (1 )).evictUsingPrefix ("university:recommend:general" );
486+ }
487+ }
401488}
0 commit comments