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

Added dirties context for embededKafka

parent e916a8fa
package fr.gouv.clea.consumer.configuration;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
@DirtiesContext
@TestPropertySource("classpath:application.yml")
public class VenueConsumerConfigurationIntegrationTest {
class VenueConsumerConfigurationIntegrationTest {
@Autowired
VenueConsumerConfiguration config;
private VenueConsumerConfiguration config;
@Test
void should_get_expected_values() {
assertThat(config.getDurationUnitInSeconds()).isEqualTo(1800);
......
package fr.gouv.clea.consumer.configuration;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class VenueConsumerConfigurationValidationTest {
public class VenueConsumerConfigurationValidationTest {
private static final ValidatorFactory VALIDATOR_FACTORY = Validation.buildDefaultValidatorFactory();
private Validator validator;
@BeforeEach
void setUp() {
validator = VALIDATOR_FACTORY.getValidator();
}
@Test
void should_get_no_exception_when_configuration_is_valid() {
VenueConsumerConfiguration config = this.getValidVenueConsumerConfiguration();
assertThat(validator.validate(config)).isEmpty();
}
@Test
void should_get_violation_when_duration_unit_not_valid() {
VenueConsumerConfiguration config = this.getValidVenueConsumerConfiguration()
.toBuilder().durationUnitInSeconds(-1).build();
assertThat(validator.validate(config)).hasSize(1);
}
@Test
void should_get_violation_when_driftBetweenDeviceAndOfficialTimeInSecs_not_valid() {
VenueConsumerConfiguration config = this.getValidVenueConsumerConfiguration()
.toBuilder().driftBetweenDeviceAndOfficialTimeInSecs(-1).build();
assertThat(validator.validate(config)).hasSize(1);
}
@Test
void should_get_violation_when_cleaClockDriftInSecs_not_valid() {
VenueConsumerConfiguration config = this.getValidVenueConsumerConfiguration()
.toBuilder().cleaClockDriftInSecs(-1).build();
assertThat(validator.validate(config)).hasSize(1);
}
@Test
void should_get_violation_when_retentionDurationInDays_less_than_min_value() {
VenueConsumerConfiguration config = this.getValidVenueConsumerConfiguration()
.toBuilder().retentionDurationInDays(9).build();
assertThat(validator.validate(config)).hasSize(1);
}
@Test
void should_get_violation_when_retentionDurationInDays_greater_than_max_value() {
VenueConsumerConfiguration config = this.getValidVenueConsumerConfiguration()
.toBuilder().retentionDurationInDays(31).build();
assertThat(validator.validate(config)).hasSize(1);
}
VenueConsumerConfiguration getValidVenueConsumerConfiguration() {
return VenueConsumerConfiguration.builder()
.durationUnitInSeconds(1800)
.statSlotDurationInSeconds(1800)
.driftBetweenDeviceAndOfficialTimeInSecs(300)
.cleaClockDriftInSecs(300)
.retentionDurationInDays(14)
.build();
.durationUnitInSeconds(1800)
.statSlotDurationInSeconds(1800)
.driftBetweenDeviceAndOfficialTimeInSecs(300)
.cleaClockDriftInSecs(300)
.retentionDurationInDays(14)
.build();
}
}
package fr.gouv.clea.consumer.service.impl;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.UUID;
import fr.gouv.clea.consumer.model.StatLocation;
import fr.gouv.clea.consumer.model.Visit;
import fr.gouv.clea.consumer.repository.IStatLocationRepository;
import fr.gouv.clea.consumer.service.IStatService;
import fr.inria.clea.lsp.utils.TimeUtils;
import org.apache.commons.lang3.RandomUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayNameGeneration;
......@@ -14,14 +12,17 @@ import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import fr.gouv.clea.consumer.model.StatLocation;
import fr.gouv.clea.consumer.model.Visit;
import fr.gouv.clea.consumer.repository.IStatLocationRepository;
import fr.gouv.clea.consumer.service.IStatService;
import fr.inria.clea.lsp.utils.TimeUtils;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
@DirtiesContext
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class StatServiceTest {
......@@ -37,6 +38,26 @@ class StatServiceTest {
@Autowired
private IStatService service;
static Visit defaultVisit() {
return Visit.builder()
.version(0)
.type(0)
.staff(true)
.locationTemporaryPublicId(_UUID)
.qrCodeRenewalIntervalExponentCompact(2)
.venueType(4)
.venueCategory1(1)
.venueCategory2(2)
.periodDuration(24)
.compressedPeriodStartTime((int) (TODAY_AT_MIDNIGHT_AS_NTP / 3600))
.qrCodeValidityStartTime(Instant.now())
.qrCodeScanTime(Instant.now())
.locationTemporarySecretKey(LOCATION_TEMPORARY_SECRET_KEY)
.encryptedLocationContactMessage(ENCRYPTED_LOCATION_CONTACT_MESSAGE)
.isBackward(true)
.build();
}
@AfterEach
void clean() {
repository.deleteAll();
......@@ -127,7 +148,7 @@ class StatServiceTest {
service.logStats(visit1);
service.logStats(visit2);
service.logStats(visit3);
assertThat(repository.count()).isEqualTo(1);
}
......@@ -139,10 +160,10 @@ class StatServiceTest {
Visit visit2 = defaultVisit().toBuilder()
.qrCodeScanTime(TODAY_AT_8AM.plus(31, ChronoUnit.MINUTES)) // different stat slot
.build();
service.logStats(visit1);
service.logStats(visit2);
assertThat(repository.count()).isEqualTo(2);
}
......@@ -153,7 +174,7 @@ class StatServiceTest {
service.logStats(visit1);
service.logStats(visit2);
assertThat(repository.count()).isEqualTo(2);
}
......@@ -178,24 +199,4 @@ class StatServiceTest {
assertThat(repository.count()).isEqualTo(2);
}
static Visit defaultVisit() {
return Visit.builder()
.version(0)
.type(0)
.staff(true)
.locationTemporaryPublicId(_UUID)
.qrCodeRenewalIntervalExponentCompact(2)
.venueType(4)
.venueCategory1(1)
.venueCategory2(2)
.periodDuration(24)
.compressedPeriodStartTime((int) (TODAY_AT_MIDNIGHT_AS_NTP / 3600))
.qrCodeValidityStartTime(Instant.now())
.qrCodeScanTime(Instant.now())
.locationTemporarySecretKey(LOCATION_TEMPORARY_SECRET_KEY)
.encryptedLocationContactMessage(ENCRYPTED_LOCATION_CONTACT_MESSAGE)
.isBackward(true)
.build();
}
}
\ No newline at end of file
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