Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: class cast exception for statistics #3

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeek
private long getCountOfEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(String adviceSeekerId,
Collection<StatisticsEvent> createMessageEvents) {
return createMessageEvents.stream()
.filter(event -> event.getMetaData() instanceof CreateMessageMetaData)
.filter(event -> {
CreateMessageMetaData metaData = (CreateMessageMetaData) event.getMetaData();
return metaData.getReceiverId() != null && metaData.getReceiverId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() {
givenValidStatisticEvent(1L);

// when
RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(testEvent, new StatisticEventsContainer());
RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(
testEvent, new StatisticEventsContainer());

// then
assertThat(result.getUserId(), is(ASKER_ID));
Expand All @@ -76,11 +77,11 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() {
}

@Test
void convertStatisticsEvent_Should_convertToRegistrationStatisticResponseWithoutErrorIfMetadataIsLinkedHashMap() {
void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse_SkipCounting() {
// given
givenValidStatisticEvent(1L);

var videoCallStartedEvent = StatisticsEvent.builder()
var eventWithInvalidMetadataType = StatisticsEvent.builder()
.sessionId(1L)
.eventType(EventType.REGISTRATION)
.user(User.builder().userRole(UserRole.ASKER).id(ASKER_ID).build())
Expand All @@ -90,9 +91,13 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponseWithout
.metaData(new LinkedHashMap<>())
.build();

var statisticEventsContainer = StatisticEventsContainer.builder().videoCallStartedEvents(Lists.newArrayList(videoCallStartedEvent)).build();
var statisticEventsContainer = StatisticEventsContainer.builder()
.videoCallStartedEvents(Lists.newArrayList(eventWithInvalidMetadataType))
.bookingCreatedEvents(Lists.newArrayList(eventWithInvalidMetadataType))
.consultantMessageCreatedEvents(Lists.newArrayList(eventWithInvalidMetadataType)).build();
// when
RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(testEvent, statisticEventsContainer);
RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(
testEvent, statisticEventsContainer);

// then
assertThat(result.getUserId(), is(ASKER_ID));
Expand Down Expand Up @@ -220,27 +225,31 @@ private void givenValidStatisticEvent(Long sessionId) {
}

private void givenAccountDeleteStatisticEvents() {
deleteAccountEvents = List.of(deleteEvent(ASKER_ID, "2022-10-19T10:00:00.00Z", "delete date for user 1"),
deleteAccountEvents = List.of(
deleteEvent(ASKER_ID, "2022-10-19T10:00:00.00Z", "delete date for user 1"),
deleteEvent("user 2", "2022-10-17T10:00:00.00Z", "delete date for user 2"));
}


private void givenValidArchiveStatisticEvents() {
archiveSessionEvents = List.of(archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"),
archiveSessionEvents = List.of(
archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"),
archiveEvent(1L, "2022-10-18T10:00:00.00Z", "2 end date for session 1"),
archiveEvent(2L, "2022-10-18T10:00:00.00Z", "end date for session 2"),
archiveEvent(999L, "2022-10-19T10:00:00.00Z", "dummy end date"));
}

private StatisticsEvent archiveEvent(Long sessionId, String timestampString, String endDate) {
Object metaData = ArchiveMetaData.builder().endDate(endDate).build();
return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).sessionId(sessionId).metaData(metaData).build();
return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).sessionId(sessionId)
.metaData(metaData).build();
}

private StatisticsEvent deleteEvent(String userId, String timestampString, String deleteDate) {
Object metaData = DeleteAccountMetaData.builder().deleteDate(deleteDate).build();
User user = new User();
user.setId(userId);
return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).user(user).metaData(metaData).build();
return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).user(user)
.metaData(metaData).build();
}
}
Loading