Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 29ab6fe9 authored by avocatier tac's avatar avocatier tac Committed by calocedre TAC
Browse files

Feature/clea/cucumber tests

parent 5a36e60c
package fr.gouv.clea.client.model;
public abstract class HTTPResponse {
public int statusCode;
}
package fr.gouv.clea.client.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
@Data
public class MalformedReport<T> {
@JsonInclude(JsonInclude.Include.NON_ABSENT)
Optional<T> pivotDate;
List<Visit> visits;
@JsonIgnore
boolean qrCodeMalformed;
@JsonIgnore
boolean scanTimeMalformed;
@JsonIgnore
boolean qrCodeAbsent;
@JsonIgnore
boolean scanTimeAbsent;
public MalformedReport(){
this.visits = new ArrayList<>();
this.pivotDate = Optional.empty();
this.qrCodeMalformed = false;
this.scanTimeMalformed = false;
this.qrCodeAbsent = false;
this.scanTimeAbsent = false;
}
public MalformedReport(T pivotDate){
this.visits = new ArrayList<>();
this.pivotDate = Optional.of(pivotDate);
this.qrCodeMalformed = false;
this.scanTimeMalformed = false;
this.qrCodeAbsent = false;
this.scanTimeAbsent = false;
}
public void addVisit(ScannedQrCode scannedQr){
String qr = scannedQr.getQrCode();
if(qrCodeMalformed)
qr = "";
else if(qrCodeAbsent)
qr = null;
Long scantime = scannedQr.getScanTimeAsNtpTimestamp();
if(scanTimeMalformed)
scantime = -1L;
else if(scanTimeAbsent)
scantime = null;
this.visits.add(new Visit(qr, scantime));
}
public void addAllVisits(List<ScannedQrCode> localList) {
localList.forEach(this::addVisit);
}
}
package fr.gouv.clea.client.model;
import java.util.Arrays;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -7,7 +10,15 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ReportResponse {
public class ReportResponse extends HTTPResponse {
private boolean success;
private String message;
//Assuming message being equivalent to : "2 qr processed, 0 rejected"
public int getAcceptedVisits(){
return Integer.parseInt(message.replaceAll("[^0-9]+", " ").trim().split(" ")[0]);
}
public int getRejectedVisits(){
return Integer.parseInt(message.replaceAll("[^0-9]+", " ").trim().split(" ")[1]);
}
}
package fr.gouv.clea.client.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
......@@ -11,8 +12,10 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class Visit {
@JsonInclude(JsonInclude.Include.NON_NULL)
private String qrCode;
@JsonProperty("qrCodeScanTime")
private long scanTime;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Long scanTime;
}
......@@ -13,6 +13,7 @@ import java.util.concurrent.TimeUnit;
import fr.gouv.clea.client.configuration.CleaClientConfiguration;
import fr.gouv.clea.client.model.ClusterIndex;
import fr.gouv.clea.client.model.ReportResponse;
import fr.gouv.clea.client.model.ScannedQrCode;
import fr.inria.clea.lsp.utils.TimeUtils;
import lombok.ToString;
......@@ -29,6 +30,7 @@ public class CleaClient {
private Optional<ReportService> reportService;
@ToString.Exclude
private Optional<CleaBatchTriggerService> batchTriggerService;
private boolean dupVerification = false;
public CleaClient(String name) {
this.name = name;
......@@ -64,11 +66,13 @@ public class CleaClient {
qrCode = qrCode.substring(configuration.getQrPrefix().length());
ScannedQrCode scannedQr = new ScannedQrCode(qrCode, scanTime);
//Check for duplicate in local list
for (ScannedQrCode prevQR : this.localList) {
if(scannedQr.getLocationTemporaryId().equals(prevQR.getLocationTemporaryId())
&& (Duration.between(prevQR.getScanTime(), scanTime).abs().toSeconds() <= configuration.getDupScanThreshold())) {
return false;
if(this.dupVerification){
//Check for duplicate in local list
for (ScannedQrCode prevQR : this.localList) {
if(scannedQr.getLocationTemporaryId().equals(prevQR.getLocationTemporaryId())
&& (Duration.between(prevQR.getScanTime(), scanTime).abs().toSeconds() <= configuration.getDupScanThreshold())) {
return false;
}
}
}
localList.add(scannedQr);
......@@ -95,8 +99,23 @@ public class CleaClient {
return this.sendReport(Instant.now().minus(Duration.ofDays(14)));
}
public boolean sendMalformedReport(boolean pivotDateMalformed, boolean qrCodeMalformed, boolean scanTimeMalformed) throws IOException, InterruptedException{
this.getReportService().reportMalformed(localList, pivotDateMalformed, qrCodeMalformed, scanTimeMalformed);
return this.getLastReportSuccess();
}
public boolean sendReportWithEmptyField(boolean pivotDateEmpty, boolean qrCodeEmpty, boolean scanTimeEmpty) throws IOException, InterruptedException{
this.getReportService().reportEmpty(localList, pivotDateEmpty, qrCodeEmpty, scanTimeEmpty);
return this.getLastReportSuccess();
}
public boolean getLastReportSuccess() throws IOException{
return this.getReportService().getLastReportResponse().isSuccess();
return (this.getReportService().getLastReportResponse().statusCode == 200) && (this.getReportService().getLastReportResponse().isSuccess()) && (this.getReportService().getLastReportResponse().getAcceptedVisits() > 0);
}
public ReportResponse getLastReportResponse() throws IOException{
return this.getReportService().getLastReportResponse();
}
public void triggerNewClusterIdenfication() throws IOException, InterruptedException {
......@@ -105,6 +124,10 @@ public class CleaClient {
this.waitForClusterIndex(currentClusterIteration+1);
}
public void setDupVerification(boolean dupVerif){
this.dupVerification = dupVerif;
}
protected int getCurrentClusterIndexIteration() throws IOException {
Optional<ClusterIndex> currentIndex = this.getStatusService().getClusterIndex();
if (currentIndex.isPresent()) {
......@@ -116,20 +139,31 @@ public class CleaClient {
private void waitForClusterIndex(int clusterIteration) {
Awaitility.with().pollInterval(1, TimeUnit.SECONDS)
.await()
.atMost(30, TimeUnit.SECONDS)
.atMost(90, TimeUnit.SECONDS)
.until(() -> this.getCurrentClusterIndexIteration() == clusterIteration);
}
private CleaBatchTriggerService getBatchTriggerService() throws IOException {
return batchTriggerService.orElse(new CleaBatchTriggerService(CleaClientConfiguration.getInstance().getBatchTriggerUrl()));
if(batchTriggerService.isPresent()){
return batchTriggerService.get();
}
return this.createBatchTriggerService();
}
private CleaBatchTriggerService createBatchTriggerService() throws IOException{
batchTriggerService = Optional.of(new CleaBatchTriggerService(CleaClientConfiguration.getInstance().getBatchTriggerUrl()));
return batchTriggerService.get();
}
public float getStatus() throws IOException {
return this.getStatusService().status(localList);
}
private ReportService getReportService() throws IOException {
return reportService.orElse(this.createReportService());
private ReportService getReportService() throws IOException {
if(reportService.isPresent()){
return reportService.get();
}
return this.createReportService();
}
private ReportService createReportService() throws IOException{
......@@ -140,7 +174,10 @@ public class CleaClient {
}
private StatusService getStatusService() throws IOException{
return statusService.orElse(this.createStatusService());
if(statusService.isPresent()){
return statusService.get();
}
return this.createStatusService();
}
private StatusService createStatusService() throws IOException {
......
package fr.gouv.clea.client.service;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import fr.gouv.clea.client.model.MalformedReport;
import fr.gouv.clea.client.model.Report;
import fr.gouv.clea.client.model.ReportResponse;
import fr.gouv.clea.client.model.ScannedQrCode;
import fr.gouv.clea.client.utils.HttpClientWrapper;
import fr.inria.clea.lsp.utils.TimeUtils;
import lombok.extern.slf4j.Slf4j;
@Slf4j
......@@ -37,10 +42,11 @@ public class ReportService {
reportRequest.addAllVisits(localList);
this.lastReportRequest = reportRequest;
log.info("Reporting {} visits to {}", localList.size(), this.reportEndPoint);
log.info("Reporting {} visits to {} with pivot date : {}", localList.size(), this.reportEndPoint, pivotDate);
jsonRequest = new ObjectMapper().registerModule(new Jdk8Module()).writeValueAsString(reportRequest);
log.info(jsonRequest);
this.lastReportResponse = this.post(jsonRequest);
log.info("REPORTRESPONSE : {}",lastReportResponse);
return this.lastReportResponse;
}
......@@ -56,6 +62,48 @@ public class ReportService {
return this.lastReportResponse;
}
public ReportResponse reportMalformed(List<ScannedQrCode> localList, boolean pivotDateMalformed, boolean qrCodeMalformed, boolean scanTimeMalformed) throws IOException, InterruptedException {
String jsonRequest;
MalformedReport reportRequest;
if(pivotDateMalformed){
reportRequest = new MalformedReport<String>("error");
}else{
reportRequest = new MalformedReport<Long>(TimeUtils.ntpTimestampFromInstant(Instant.now().minus(Duration.ofDays(14))));
}
reportRequest.setQrCodeMalformed(qrCodeMalformed);
reportRequest.setScanTimeMalformed(scanTimeMalformed);
reportRequest.addAllVisits(localList);
log.info("Reporting {} visits to {} Using a malformed request", localList.size(), this.reportEndPoint);
jsonRequest = new ObjectMapper().registerModule(new Jdk8Module()).writeValueAsString(reportRequest);
log.info(jsonRequest);
this.lastReportResponse = this.post(jsonRequest);
log.info("REPORTRESPONSE : {}",lastReportResponse);
return this.lastReportResponse;
}
public ReportResponse reportEmpty(List<ScannedQrCode> localList, boolean pivotDateEmpty, boolean qrCodeEmpty,
boolean scanTimeEmpty) throws IOException, InterruptedException {
String jsonRequest;
MalformedReport reportRequest;
if(pivotDateEmpty){
reportRequest = new MalformedReport<Long>();
}else{
reportRequest = new MalformedReport<Long>(TimeUtils.ntpTimestampFromInstant(Instant.now().minus(Duration.ofDays(14))));
}
reportRequest.setQrCodeAbsent(qrCodeEmpty);
reportRequest.setScanTimeAbsent(scanTimeEmpty);
reportRequest.addAllVisits(localList);
log.info("Reporting {} visits to {} Using a malformed request", localList.size(), this.reportEndPoint);
jsonRequest = new ObjectMapper().registerModule(new Jdk8Module()).writeValueAsString(reportRequest);
log.info(jsonRequest);
this.lastReportResponse = this.post(jsonRequest);
log.info("REPORTRESPONSE : {}",lastReportResponse);
return this.lastReportResponse;
}
public ReportResponse getLastReportResponse(){
return this.lastReportResponse;
}
......
......@@ -66,7 +66,7 @@ public class StatusService {
}
}
}
log.info("SCORES : {}", scores);
return scores.stream().max(Comparator.naturalOrder()).orElse(0f);
}
......
......@@ -20,8 +20,11 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.gouv.clea.client.model.HTTPResponse;
public class HttpClientWrapper {
private HttpClient client;
private Map<String,String> headers;
......@@ -61,10 +64,12 @@ public class HttpClientWrapper {
.build();
}
public <T> T get(String uri, Class<T> returnType) throws IOException, InterruptedException{
public <T extends HTTPResponse> T get(String uri, Class<T> returnType) throws IOException, InterruptedException{
HttpRequest request = HttpRequest.newBuilder(URI.create(uri)).GET().build();
HttpResponse<String> response = this.client.send(request, HttpResponse.BodyHandlers.ofString());
return (T) new ObjectMapper().readValue(response.body(), returnType);
T typedResponse = (T) new ObjectMapper().readValue(response.body(), returnType);
typedResponse.statusCode = response.statusCode();
return typedResponse;
}
public int getStatusCode(String uri) throws IOException, InterruptedException{
......@@ -73,7 +78,7 @@ public class HttpClientWrapper {
return response.statusCode();
}
public <T> T post(String uri, String body, Class<T> returnType) throws IOException, InterruptedException{
public <T extends HTTPResponse> T post(String uri, String body, Class<T> returnType) throws IOException, InterruptedException{
Builder requestBuilder = HttpRequest.newBuilder(URI.create(uri)).POST(HttpRequest.BodyPublishers.ofString(body));
for(Entry<String, String> header : headers.entrySet()){
requestBuilder.setHeader(header.getKey(), header.getValue());
......@@ -81,7 +86,9 @@ public class HttpClientWrapper {
requestBuilder.setHeader("Content-Type", "application/json");
HttpRequest request = requestBuilder.build();
HttpResponse<String> response = this.client.send(request, HttpResponse.BodyHandlers.ofString());
return (T) new ObjectMapper().readValue(response.body(), returnType);
T typedResponse = (T) new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(response.body(), returnType);
typedResponse.statusCode = response.statusCode();
return typedResponse;
}
public int postStatusCode(String uri, String body) throws IOException, InterruptedException{
......
......@@ -85,5 +85,10 @@ public class LocationQrCodeGeneratorTest {
QRCode qr2 = dynamicGenerator.getQrCodeAt(dynamicGenerator.getInitialPeriodStart().plus(1, ChronoUnit.DAYS));
assertThat(qr).isNotEqualTo(qr2);
assertThat(qr.getLocationTemporaryPublicID().toString()).isNotEqualTo(qr2.getLocationTemporaryPublicID().toString());
qr = staticGenerator.getQrCodeAt(dynamicGenerator.getInitialPeriodStart());
qr2 = staticGenerator.getQrCodeAt(dynamicGenerator.getInitialPeriodStart().plus(1, ChronoUnit.DAYS));
assertThat(qr).isNotEqualTo(qr2);
assertThat(qr.getLocationTemporaryPublicID().toString()).isNotEqualTo(qr2.getLocationTemporaryPublicID().toString());
}
}
......@@ -18,35 +18,134 @@ public class CleaClientStepDefinitions implements En {
public CleaClientStepDefinitions(ScenarioAppContext scenarioAppContext) {
this.scenarioAppContext = Objects.requireNonNull(scenarioAppContext, "scenarioAppContext must not be null");
Given("^\"([^\"]*)\" registered on TAC$", (String visitorName) -> {
Given("{string} registered on TAC", (String visitorName) -> {
// TODO Robert registration of the user
this.scenarioAppContext.getOrCreateVisitor(visitorName);
});
Given("^\"([^\"]*)\" created a QRCode \"([^\"]*)\" as a \"([^\"]*)\" at \"([^\"]*)\" with a capacity of (\\d+) and category \"([^\"]*)\" and with a renewal time of \"(\\d+) ([^\"]*)\"$",
(String locationName, String qrCodeId, String venueType, String periodStartTime, Integer venueCapacity, String venueCategory1, Integer qrCodeRenewalInterval, String qrCodeRenewalIntervalUnit) -> {
Given("{string} has no duplicate verification", (String visitorName) -> {
// TODO Robert registration of the user
this.scenarioAppContext.getOrCreateVisitor(visitorName).setDupVerification(false);
});
//Risk configuration declaration
Given("VType of {string}, VCategory1 of {string} and VCategory2 of {int} has risk configuration of \\(Threshold , ExposureTime, Risklevel) for backward \\({int},{int},{float}) and for forward \\({int},{int},{float})",
(String vtype, String vcategory1, Integer vcategory2, Integer backwardThreshold, Integer backwardExposureTime, Float backwardRisk, Integer forwardThreshold, Integer forwardExposureTime, Float forwardRisk) -> {
this.scenarioAppContext.updateOrCreateRiskConfig(vtype, vcategory1, vcategory2, backwardThreshold, backwardExposureTime, backwardRisk, forwardThreshold, forwardExposureTime, forwardRisk);
});
//Dynamic Location
Given("{string} created a dynamic QRCode at {string} with VType as {string} and with VCategory1 as {string} and with VCategory2 as {int} and with a renewal time of \"{int} {word}\" and with a periodDuration of \"{int} hours\"",
(String locationName, String periodStartTime, String venueType, String venueCategory1, Integer venueCategory2, Integer qrCodeRenewalInterval, String qrCodeRenewalIntervalUnit, Integer periodDuration) -> {
Instant periodStartTimeInstant = TimeUtils.naturalLanguageDateStringToInstant(periodStartTime);
Duration qrCodeRenewalIntervalDuration = Duration.of(qrCodeRenewalInterval, ChronoUnit.valueOf(qrCodeRenewalIntervalUnit.toUpperCase()));
LocationQrCodeGenerator location = this.scenarioAppContext.getOrCreateDynamicLocation(locationName, periodStartTimeInstant, venueType, venueCategory1, venueCategory2, qrCodeRenewalIntervalDuration, periodDuration);
// TODO: add QR id
});
//Dynamic Location with default period duration
Given("{string} created a dynamic QRCode at {string} with VType as {string} and with VCategory1 as {string} and with VCategory2 as {int} and with and with a renewal time of \"{int} {word}\"",
(String locationName, String periodStartTime, String venueType, String venueCategory1, Integer venueCategory2, Integer qrCodeRenewalInterval, String qrCodeRenewalIntervalUnit) -> {
Instant periodStartTimeInstant = TimeUtils.naturalLanguageDateStringToInstant(periodStartTime);
Duration qrCodeRenewalIntervalDuration = Duration.of(qrCodeRenewalInterval, ChronoUnit.valueOf(qrCodeRenewalIntervalUnit.toUpperCase()));
LocationQrCodeGenerator location = this.scenarioAppContext.getOrCreateLocation(locationName, periodStartTimeInstant, venueType, venueCategory1, venueCapacity, qrCodeRenewalIntervalDuration);
LocationQrCodeGenerator location = this.scenarioAppContext.getOrCreateDynamicLocation(locationName, periodStartTimeInstant, venueType, venueCategory1, venueCategory2, qrCodeRenewalIntervalDuration);
// TODO: add QR id
});
//Static Location
Given("{string} created a static QRCode at {string} with VType as {string} and with VCategory1 as {string} and with VCategory2 as {int} and with a periodDuration of \"{int} hours\"",
(String locationName, String periodStartTime, String venueType,String venueCategory1, Integer venueCategory2, Integer periodDuration) -> {
Instant periodStartTimeInstant = TimeUtils.naturalLanguageDateStringToInstant(periodStartTime);
LocationQrCodeGenerator location = this.scenarioAppContext.getOrCreateStaticLocation(locationName, periodStartTimeInstant, venueType, venueCategory1, venueCategory2, periodDuration);
// TODO: add QR id
});
Given("^\"([^\"]*)\" recorded a visit to \"([^\"]*)\" at \"([^\"]*)\" withQRCode \"([^\"]*)\"$",
(String visitorName, String locationName, String qrCodeScanTime, String qrCodeId) -> {
//Static Location with default Period Duration
Given("{string} created a static QRCode at {string} with VType as {string} and VCategory1 as {string} and with VCategory2 as {int}",
(String locationName, String periodStartTime, String venueType,String venueCategory1, Integer venueCategory2)-> {
Instant periodStartTimeInstant = TimeUtils.naturalLanguageDateStringToInstant(periodStartTime);
LocationQrCodeGenerator location = this.scenarioAppContext.getOrCreateStaticLocation(locationName, periodStartTimeInstant, venueType, venueCategory1, venueCategory2);
// TODO: add QR id
});
//Visitor scan a QR code at given instant
Given("{string} recorded a visit to {string} at {string}",
(String visitorName, String locationName, String qrCodeScanTime) -> {
LocationQrCodeGenerator location = this.scenarioAppContext.getLocation(locationName);
Instant qrCodeScanTimeInstant = TimeUtils.naturalLanguageDateStringToInstant(qrCodeScanTime);
QRCode qr = location.getQrCodeAt(TimeUtils.naturalLanguageDateStringToInstant(qrCodeScanTime));
this.scenarioAppContext.getOrCreateVisitor(visitorName).scanQrCode(qr.getQrCode(), qrCodeScanTimeInstant);
});
//Visitor scan a staff QR code at given instant
Given("{string} recorded a visit to {string} at {string} as a STAFF",
(String visitorName, String locationName, String qrCodeScanTime) -> {
LocationQrCodeGenerator location = this.scenarioAppContext.getStaffLocation(locationName);
Instant qrCodeScanTimeInstant = TimeUtils.naturalLanguageDateStringToInstant(qrCodeScanTime);
QRCode qr = location.getQrCodeAt(TimeUtils.naturalLanguageDateStringToInstant(qrCodeScanTime));
this.scenarioAppContext.getOrCreateVisitor(visitorName).scanQrCode(qr.getQrCode(), qrCodeScanTimeInstant);
});
//Visitor scan a QR code at a given Instant, but the scanned QR code is valid for another Instant
Given("{string} recorded a visit to {string} at {string} with a QR code valid for {string}",
(String visitorName, String locationName, String qrCodeScanTime, String qrCodeValidTime) -> {
LocationQrCodeGenerator location = this.scenarioAppContext.getLocation(locationName);
Instant qrCodeScanTimeInstant = TimeUtils.naturalLanguageDateStringToInstant(qrCodeScanTime);
QRCode qr = location.getQrCodeAt(TimeUtils.naturalLanguageDateStringToInstant(qrCodeValidTime));
this.scenarioAppContext.getOrCreateVisitor(visitorName).scanQrCode(qr.getQrCode(), qrCodeScanTimeInstant);
});
When("^Cluster detection triggered$", () -> {
this.scenarioAppContext.triggerNewClusterIdenfication();
});
Then("^Exposure status should reports \"([^\"]*)\" as not being at risk$", (String visitorName) -> {
When("{string} declares himself/herself sick", (String visitorName) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
visitor.sendReport();
});
When("{string} declares himself/herself sick with a {string} pivot date", (String visitorName, String pivotDate) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
System.out.println(pivotDate);
visitor.sendReport(TimeUtils.naturalLanguageDateStringToInstant(pivotDate));
});
When("{string} declares himself/herself sick with a malformed pivot date", (String visitorName) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
visitor.sendMalformedReport(true, false, false);
});
When("{string} declares himself/herself sick with a malformed QrCode", (String visitorName) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
visitor.sendMalformedReport(false, true, false);
});
When("{string} declares himself/herself sick with a malformed scan time", (String visitorName) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
visitor.sendMalformedReport(false, false, true);
});
When("{string} declares himself/herself sick with no scan time", (String visitorName) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
visitor.sendReportWithEmptyField(false, false, true);
});
When("{string} declares himself/herself sick with no QrCode", (String visitorName) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
visitor.sendReportWithEmptyField(false, true, false);
});
When("{string} asks for exposure status", (String string) -> {
});
Then("Exposure status should reports {string} as not being at risk", (String visitorName) -> {
float riskLevel = this.scenarioAppContext.getOrCreateVisitor(visitorName).getStatus();
assertThat(riskLevel).isEqualTo(0);
});
Then("Exposure status should reports {string} as being at risk", (String visitorName) -> {
Then("Exposure status should reports {string} as being at risk of {float}", (String visitorName, Float risk) -> {
float riskLevel = this.scenarioAppContext.getVisitor(visitorName).getStatus();
assertThat(riskLevel).isGreaterThan(0);
assertThat(riskLevel).isEqualTo(risk);
});
Then("Exposure status request for {string} should include only {int} visit\\(s) to {string} at {string}", (String visitorName, Integer nbVisits, String locationName, String qrScanTime) -> {
......@@ -54,14 +153,10 @@ public class CleaClientStepDefinitions implements En {
assertThat(visitor.getLocalList().size()).isEqualTo(nbVisits);
});
When("{string} declares himself/herself sick", (String visitorName) -> {
Then("{string} has {int} rejected visit(s)", (String visitorName, Integer rejectedVisits) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
visitor.sendReport();
});
When("{string} declares himself/herself sick with pivot date : {string}", (String visitorName, String pivotDate) -> {
CleaClient visitor = this.scenarioAppContext.getVisitor(visitorName);
visitor.sendReport(TimeUtils.naturalLanguageDateStringToInstant(pivotDate));
System.out.println(visitor.getLastReportResponse());
assertThat(visitor.getLastReportResponse().getRejectedVisits()).isEqualTo(rejectedVisits);
});
Then("{string} cannot send his/her visits", (String visitorName) -> {
......
......@@ -19,19 +19,26 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ScenarioAppContext {
private final Map<String, Integer> venueCategories;
private final Map<String, Integer> venueCategories1;
private final Map<String, Integer> venueTypes;
private Map<String, CleaClient> visitors;
private Map<String, LocationQrCodeGenerator> locations;
private Map<String, LocationQrCodeGenerator> staffLocations;
private String manualContactTracingAuthorityPublicKey;
private String serverAuthorityPublicKey;
private int venueTypeCounter = 0;
private int venueCategoryCounter = 0;