Skip to content

Commit

Permalink
test: 캐싱 여부 테스트 내 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ikjo39 committed Nov 18, 2024
1 parent 8d54c75 commit 5b39a04
Showing 1 changed file with 80 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import kr.momo.config.constant.CacheType;
import kr.momo.domain.attendee.Attendee;
import kr.momo.domain.attendee.AttendeeGroup;
import kr.momo.domain.attendee.AttendeeRepository;
Expand Down Expand Up @@ -65,6 +66,9 @@ class ScheduleServiceTest {
@Autowired
private AvailableDateRepository availableDateRepository;

@Autowired
private ScheduleCache scheduleCache;

private Meeting meeting;
private Attendee attendee;
private AvailableDate today;
Expand Down Expand Up @@ -97,8 +101,12 @@ void createSchedulesReplacesOldSchedules() {

scheduleService.create(meeting.getUuid(), attendee.getId(), request);
long scheduleCount = scheduleRepository.count();
String scheduleCacheData = scheduleCache.get(CacheType.SCHEDULES_STORE, meeting.getUuid(), String.class);

assertThat(scheduleCount).isEqualTo(4);
assertAll(
() -> assertThat(scheduleCount).isEqualTo(4),
() -> assertThat(scheduleCacheData).isEqualTo("invalid")
);
}

@DisplayName("days only 약속의 스케줄 생성 시 하루에 하나의 스케줄을 저장한다.")
Expand Down Expand Up @@ -167,20 +175,26 @@ void findAllSchedulesInMeetingByUuid() {
scheduleRepository.saveAll(List.of(schedule1, schedule2, schedule3, schedule4));

SchedulesResponse response = scheduleService.findAllSchedules(meeting.getUuid());
SchedulesResponse cacheData = scheduleCache.get(
CacheType.SCHEDULES_STORE, meeting.getUuid(), SchedulesResponse.class
);

assertThat(response.schedules()).containsExactlyInAnyOrder(
new AttendeesScheduleResponse(
today.getDate(),
Timeslot.TIME_0100.startTime(),
List.of(attendee.name(), attendee2.name())),
new AttendeesScheduleResponse(
today.getDate(),
Timeslot.TIME_0130.startTime(),
List.of(attendee2.name())),
new AttendeesScheduleResponse(
tomorrow.getDate(),
Timeslot.TIME_0100.startTime(),
List.of(attendee.name()))
assertAll(
() -> assertThat(response.schedules()).containsExactlyInAnyOrder(
new AttendeesScheduleResponse(
today.getDate(),
Timeslot.TIME_0100.startTime(),
List.of(attendee.name(), attendee2.name())),
new AttendeesScheduleResponse(
today.getDate(),
Timeslot.TIME_0130.startTime(),
List.of(attendee2.name())),
new AttendeesScheduleResponse(
tomorrow.getDate(),
Timeslot.TIME_0100.startTime(),
List.of(attendee.name()))
),
() -> assertThat(cacheData).isEqualTo(response)
);
}

Expand Down Expand Up @@ -266,26 +280,34 @@ void recommendLongTermSchedules() {
RecommendedSchedulesResponse responses = scheduleService.recommendSchedules(
movieMeeting.getUuid(), LONG_TERM_ORDER.getType(), List.of(jazz.name(), daon.name()), 0
);
RecommendedSchedulesResponse cacheData = scheduleCache.get(
CacheType.RECOMMEND_STORE,
LONG_TERM_ORDER.getType() + movieMeeting.getUuid(),
RecommendedSchedulesResponse.class
);

assertThat(responses.recommendedSchedules()).containsExactly(
RecommendedScheduleResponse.of(
1,
LocalDateTime.of(today.getDate(), Timeslot.TIME_0500.startTime()),
LocalDateTime.of(today.getDate(), Timeslot.TIME_0630.endTime()),
new AttendeeGroup(List.of(jazz, daon))
),
RecommendedScheduleResponse.of(
2,
LocalDateTime.of(tomorrow.getDate(), Timeslot.TIME_0130.startTime()),
LocalDateTime.of(tomorrow.getDate(), Timeslot.TIME_0230.endTime()),
new AttendeeGroup(List.of(jazz, daon))
assertAll(
() -> assertThat(responses.recommendedSchedules()).containsExactly(
RecommendedScheduleResponse.of(
1,
LocalDateTime.of(today.getDate(), Timeslot.TIME_0500.startTime()),
LocalDateTime.of(today.getDate(), Timeslot.TIME_0630.endTime()),
new AttendeeGroup(List.of(jazz, daon))
),
RecommendedScheduleResponse.of(
2,
LocalDateTime.of(tomorrow.getDate(), Timeslot.TIME_0130.startTime()),
LocalDateTime.of(tomorrow.getDate(), Timeslot.TIME_0230.endTime()),
new AttendeeGroup(List.of(jazz, daon))
),
RecommendedScheduleResponse.of(
3,
LocalDateTime.of(today.getDate(), Timeslot.TIME_0330.startTime()),
LocalDateTime.of(today.getDate(), Timeslot.TIME_0400.endTime()),
new AttendeeGroup(List.of(jazz, daon))
)
),
RecommendedScheduleResponse.of(
3,
LocalDateTime.of(today.getDate(), Timeslot.TIME_0330.startTime()),
LocalDateTime.of(today.getDate(), Timeslot.TIME_0400.endTime()),
new AttendeeGroup(List.of(jazz, daon))
)
() -> assertThat(cacheData).isEqualTo(responses)
);
}

Expand All @@ -306,26 +328,34 @@ void recommendFastestSchedules() {
RecommendedSchedulesResponse responses = scheduleService.recommendSchedules(
movieMeeting.getUuid(), EARLIEST_ORDER.getType(), List.of(jazz.name(), daon.name()), 0
);
RecommendedSchedulesResponse cacheData = scheduleCache.get(
CacheType.RECOMMEND_STORE,
EARLIEST_ORDER.getType() + movieMeeting.getUuid(),
RecommendedSchedulesResponse.class
);

assertThat(responses.recommendedSchedules()).containsExactly(
RecommendedScheduleResponse.of(
1,
LocalDateTime.of(today.getDate(), Timeslot.TIME_0330.startTime()),
LocalDateTime.of(today.getDate(), Timeslot.TIME_0400.endTime()),
new AttendeeGroup(List.of(jazz, daon))
),
RecommendedScheduleResponse.of(
2,
LocalDateTime.of(today.getDate(), Timeslot.TIME_0500.startTime()),
LocalDateTime.of(today.getDate(), Timeslot.TIME_0630.endTime()),
new AttendeeGroup(List.of(jazz, daon))
assertAll(
() -> assertThat(responses.recommendedSchedules()).containsExactly(
RecommendedScheduleResponse.of(
1,
LocalDateTime.of(today.getDate(), Timeslot.TIME_0330.startTime()),
LocalDateTime.of(today.getDate(), Timeslot.TIME_0400.endTime()),
new AttendeeGroup(List.of(jazz, daon))
),
RecommendedScheduleResponse.of(
2,
LocalDateTime.of(today.getDate(), Timeslot.TIME_0500.startTime()),
LocalDateTime.of(today.getDate(), Timeslot.TIME_0630.endTime()),
new AttendeeGroup(List.of(jazz, daon))
),
RecommendedScheduleResponse.of(
3,
LocalDateTime.of(tomorrow.getDate(), Timeslot.TIME_0130.startTime()),
LocalDateTime.of(tomorrow.getDate(), Timeslot.TIME_0230.endTime()),
new AttendeeGroup(List.of(jazz, daon))
)
),
RecommendedScheduleResponse.of(
3,
LocalDateTime.of(tomorrow.getDate(), Timeslot.TIME_0130.startTime()),
LocalDateTime.of(tomorrow.getDate(), Timeslot.TIME_0230.endTime()),
new AttendeeGroup(List.of(jazz, daon))
)
() -> assertThat(cacheData).isEqualTo(responses)
);
}

Expand Down

0 comments on commit 5b39a04

Please sign in to comment.