Commit e81de0dc authored by Ananas Orange's avatar Ananas Orange
Browse files

Minor

parent a66b360e
package fr.gouv.clea.consumer.service.impl;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import fr.gouv.clea.consumer.configuration.VenueConsumerConfiguration;
import fr.gouv.clea.consumer.model.ExposedVisitEntity;
import fr.gouv.clea.consumer.model.Visit;
......@@ -20,6 +8,17 @@ import fr.gouv.clea.consumer.service.IStatService;
import fr.gouv.clea.consumer.service.IVisitExpositionAggregatorService;
import fr.inria.clea.lsp.utils.TimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@Component
@Slf4j
......@@ -89,7 +88,7 @@ public class VisitExpositionAggregatorService implements IVisitExpositionAggrega
protected int getPeriodMaxSlot(int periodDuration) {
// This check should go in venue consumer configuration validation
if (Duration.ofHours(1).toSeconds() % periodDuration == 0) {
log.error("durationUnitInSeconds does not have a valid value: {}. 1 hour / durationUnitInSeconds has a reminder!");
log.error("durationUnitInSeconds does not have a valid value: {}. 60(secs) / durationUnitInSeconds has a reminder!", periodDuration);
}
if (periodDuration == 255) {
return Integer.MAX_VALUE;
......
......@@ -193,6 +193,40 @@ class ReportServiceTest {
assertThat(processed.stream().filter(DecodedVisit::isForward).count()).isEqualTo(3L);
}
@Test
@DisplayName("if pivot date is before or equal qrScanTime, visits should be marked as forward")
void testForward() throws CleaEncodingException {
long pivotDate = TimeUtils.ntpTimestampFromInstant(now.minus(1, ChronoUnit.DAYS));
long qrScan = TimeUtils.ntpTimestampFromInstant(now);
UUID uuid1 = UUID.randomUUID();
UUID uuid2 = UUID.randomUUID();
List<Visit> visits = List.of(
newVisit(uuid1, qrScan),
newVisit(uuid2, pivotDate)
);
List<DecodedVisit> processed = reportService.report(new ReportRequest(visits, pivotDate));
assertThat(processed.size()).isEqualTo(2);
assertThat(processed.get(0).isForward()).isTrue();
assertThat(processed.get(1).isForward()).isTrue();
}
@Test
@DisplayName("if pivot date is strictly after qrScanTime, visits should be marked as backward")
void testBackward() throws CleaEncodingException {
long pivotDate = TimeUtils.ntpTimestampFromInstant(now);
long qrScan = TimeUtils.ntpTimestampFromInstant(now.minus(1, ChronoUnit.DAYS));
UUID uuid = UUID.randomUUID();
List<Visit> visits = List.of(newVisit(uuid, qrScan));
List<DecodedVisit> processed = reportService.report(new ReportRequest(visits, pivotDate));
assertThat(processed.size()).isEqualTo(1);
assertThat(processed.get(0).isBackward()).isTrue();
}
private EncryptedLocationSpecificPart createEncryptedLocationSpecificPart(UUID locationTemporaryPublicId) {
return EncryptedLocationSpecificPart.builder()
.locationTemporaryPublicId(locationTemporaryPublicId)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment