Skip to content

Commit

Permalink
DMP-4385 Filter out 0 second audios from ATS processing
Browse files Browse the repository at this point in the history
Added tests for ATS filtering to filter out audio files that have less than a second apart
  • Loading branch information
karen-hedges committed Jan 3, 2025
1 parent e77a67d commit a8a12e3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ List<MediaEntity> filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel
return mediaEntitiesForRequest.stream()
.filter(media -> nonNull(media.getStart()))
.filter(media -> nonNull(media.getEnd()))
// Filter out media where the media start and media end times are the same
// Filter out media where the media start and media end times are the same and not less than a second apart
.filter(media -> !media.getStart().truncatedTo(ChronoUnit.SECONDS).isEqual(media.getEnd().truncatedTo(ChronoUnit.SECONDS)))
// Filter out media where the media start time is after the media end time
.filter(media -> media.getStart().isBefore(media.getEnd()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class AudioTransformationServiceImplTest {
private static final OffsetDateTime TIME_12_00 = OffsetDateTime.parse("2023-01-01T12:00Z");
private static final OffsetDateTime TIME_12_01 = OffsetDateTime.parse("2023-01-01T12:01Z");
private static final OffsetDateTime TIME_12_20 = OffsetDateTime.parse("2023-01-01T12:20Z");
private static final OffsetDateTime TIME_12_20_00_900 = OffsetDateTime.parse("2023-01-01T12:20:00.900Z");
private static final OffsetDateTime TIME_12_21 = OffsetDateTime.parse("2023-01-01T12:21Z");
private static final OffsetDateTime TIME_12_39 = OffsetDateTime.parse("2023-01-01T12:39Z");
private static final OffsetDateTime TIME_12_40 = OffsetDateTime.parse("2023-01-01T12:40Z");
Expand Down Expand Up @@ -247,13 +248,37 @@ void testHandleKedaInvocationForMediaRequestsCaseNull() {

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WhichContainsMediaWithStartDateAndEndDateTheSame() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_20, TIME_12_20, TIME_12_20, TIME_12_40, TIME_13_00);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(2, mediaEntitiesResult.size());
assertEquals(TIME_12_00, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_12_20, mediaEntitiesResult.get(0).getEnd());
assertEquals(TIME_12_40, mediaEntitiesResult.get(1).getStart());
assertEquals(TIME_13_00, mediaEntitiesResult.get(1).getEnd());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WhichContainsMediaWithStartDateAndEndDateLessThan1Second() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_20, TIME_12_20, TIME_12_20_00_900, TIME_12_40, TIME_13_00);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(2, mediaEntitiesResult.size());
assertEquals(TIME_12_00, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_12_20, mediaEntitiesResult.get(0).getEnd());
Expand All @@ -263,25 +288,34 @@ void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilte

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WhichContainsOnlyMediaWithStartDateAndEndDateTheSame() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_00, TIME_12_20, TIME_12_20, TIME_13_00, TIME_13_00);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(0, mediaEntitiesResult.size());
}


@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WhichContainsMediaWithStartDateAfterEndDate() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_20, TIME_12_40, TIME_12_20, TIME_12_40, TIME_13_00);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(2, mediaEntitiesResult.size());
assertEquals(TIME_12_00, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_12_20, mediaEntitiesResult.get(0).getEnd());
Expand All @@ -291,25 +325,33 @@ void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilte

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WhichContainsOnlyMediaWithStartDateAfterEndDate() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_20, TIME_12_00, TIME_12_40, TIME_12_20, TIME_13_00, TIME_12_40);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(0, mediaEntitiesResult.size());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WhichContainsMediaWithNullStartDate() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_20, null, TIME_12_20, TIME_12_40, TIME_13_00);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(2, mediaEntitiesResult.size());
assertEquals(TIME_12_00, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_12_20, mediaEntitiesResult.get(0).getEnd());
Expand All @@ -331,13 +373,17 @@ void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilte

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WhichContainsMediaWithNullEndDate() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_20, TIME_12_40, null, TIME_12_40, TIME_13_00);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(2, mediaEntitiesResult.size());
assertEquals(TIME_12_00, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_12_20, mediaEntitiesResult.get(0).getEnd());
Expand All @@ -359,104 +405,141 @@ void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilte

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WithStartDateExactRequestAndEndDateExactRequest() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_20, TIME_12_20, TIME_12_40, TIME_12_40, TIME_13_00);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(3, mediaEntitiesResult.size());
assertEquals(TIME_12_00, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_13_00, mediaEntitiesResult.get(2).getEnd());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WithStartDateAfterRequestAndEndDateBeforeRequest() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_01, TIME_12_20, TIME_12_20, TIME_12_40, TIME_12_40, TIME_12_59);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(3, mediaEntitiesResult.size());
assertEquals(TIME_12_01, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_12_59, mediaEntitiesResult.get(2).getEnd());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WithStartDateBeforeRequestAndEndDateAfterRequest() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_11_59, TIME_12_20, TIME_12_20, TIME_12_40, TIME_12_40, TIME_13_01);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_00, TIME_13_00);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(3, mediaEntitiesResult.size());
assertEquals(TIME_11_59, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_13_01, mediaEntitiesResult.get(2).getEnd());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WithStartDateAndEndDateExactMiddleMediaMatch() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_11_59, TIME_12_20, TIME_12_20, TIME_12_40, TIME_12_40, TIME_13_01);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_20, TIME_12_40);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(1, mediaEntitiesResult.size());
assertEquals(TIME_12_20, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_12_40, mediaEntitiesResult.get(0).getEnd());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WithStartDateBetweenRequestAndEndDateBetweenRequest() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_20, TIME_12_20, TIME_12_40, TIME_12_40, TIME_13_00);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_12_21, TIME_12_39);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(1, mediaEntitiesResult.size());
assertEquals(TIME_12_20, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_12_40, mediaEntitiesResult.get(0).getEnd());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WithRequestStartAndEndDateOutSideMediaRange() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_12_00, TIME_12_20, TIME_12_20, TIME_12_40, TIME_12_40, TIME_12_59);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_13_00, TIME_13_01);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(0, mediaEntitiesResult.size());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WithRequestStartTimeMatchesAnAudioEndTime() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_09_59, TIME_10_00, TIME_10_05, TIME_10_10, TIME_10_15, TIME_10_20);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_10_00, TIME_10_10);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(1, mediaEntitiesResult.size());
assertEquals(TIME_10_05, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_10_10, mediaEntitiesResult.get(0).getEnd());
}

@Test
void filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel_ReturnsFilteredData_WithRequestEndTimeMatchesAnAudioStartTime() {
// given
List<MediaEntity> mediaEntities = createMediaEntities(TIME_09_59, TIME_10_00, TIME_10_05, TIME_10_10, TIME_10_15, TIME_10_20);
MediaRequestEntity mediaRequestEntity = createMediaRequest(TIME_09_59, TIME_10_15);

// when
List<MediaEntity> mediaEntitiesResult = audioTransformationService.filterMediaByMediaRequestTimeframeAndSortByStartTimeAndChannel(
mediaEntities,
mediaRequestEntity
);

// then
assertEquals(2, mediaEntitiesResult.size());
assertEquals(TIME_09_59, mediaEntitiesResult.get(0).getStart());
assertEquals(TIME_10_10, mediaEntitiesResult.get(1).getEnd());
Expand Down

0 comments on commit a8a12e3

Please sign in to comment.