Skip to content

Commit

Permalink
fix: class cast exception for statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Apr 24, 2024
1 parent 7f66acb commit 784dc57
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ private Integer countEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(String
private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeekerId,
Collection<StatisticsEvent> statisticsEvents) {
return statisticsEvents.stream()
.filter(event -> event.getMetaData() instanceof AdviceSeekerAwareMetaData)
.filter(event -> {
AdviceSeekerAwareMetaData metaData = (AdviceSeekerAwareMetaData) event.getMetaData();
return metaData.getAdviceSeekerId() != null && metaData.getAdviceSeekerId()
.equals(adviceSeekerId);
AdviceSeekerAwareMetaData metaData = (AdviceSeekerAwareMetaData) event.getMetaData();
return metaData.getAdviceSeekerId() != null && metaData.getAdviceSeekerId()
.equals(adviceSeekerId);

})
.count();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

import com.google.common.collect.Lists;
import de.caritas.cob.statisticsservice.api.model.EventType;
import de.caritas.cob.statisticsservice.api.model.RegistrationStatisticsResponseDTO;
import de.caritas.cob.statisticsservice.api.model.UserRole;
Expand All @@ -19,6 +20,7 @@
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.DeleteAccountMetaData;
import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData;
import java.time.Instant;
import java.util.LinkedHashMap;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -73,6 +75,47 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() {
is("aReferer"));
}

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

var videoCallStartedEvent = StatisticsEvent.builder()
.sessionId(1L)
.eventType(EventType.REGISTRATION)
.user(User.builder().userRole(UserRole.ASKER).id(ASKER_ID).build())
.consultingType(ConsultingType.builder().id(CONSULTING_TYPE_ID).build())
.agency(Agency.builder().id(AGENCY_ID).build())
.timestamp(Instant.now())
.metaData(new LinkedHashMap<>())
.build();

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

// then
assertThat(result.getUserId(), is(ASKER_ID));
assertThat(result.getRegistrationDate(),
is("2022-09-15T09:14:45Z"));
assertThat(result.getAge(), is(26));
assertThat(result.getGender(), is("FEMALE"));
assertThat(result.getMainTopicInternalAttribute(),
is("alk"));
assertThat(result.getTopicsInternalAttributes(),
is(List.of("alk", "drogen")));
assertThat(result.getPostalCode(), is("12345"));
assertThat(result.getCounsellingRelation(),
is("SELF_COUNSELLING"));
assertThat(result.getTenantName(),
is("tenantName"));
assertThat(result.getAgencyName(),
is("agencyName"));
assertThat(result.getReferer(),
is("aReferer"));
}


@Test
void convertStatisticsEvent_Should_notFail_When_archiveSessionEventsAreNull() {
// given
Expand Down

0 comments on commit 784dc57

Please sign in to comment.