Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
feat(#226)/Added Collection Sample (cs) timestamp (#227)
Browse files Browse the repository at this point in the history
* Added Collection Sample (cs) timestamp

* Update ci-dockerfile.yml

* Fixed Sample Collection

* Fix Typo
  • Loading branch information
mschulte-tsi authored May 19, 2021
1 parent 691dfe9 commit 462eff9
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-dockerfile.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: ci-dockerfile
on:
workflow_dispatch:
push:
branches:
- master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import java.time.ZoneOffset;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -75,7 +76,9 @@ public class ExternalTestStateController {
*
* @param registrationToken generated by a hashed guid {@link RegistrationToken}
* @param fake flag for fake request
* @return result of the test, which can be POSITIVE, NEGATIVE, INVALID, PENDING or FAILED will POSITIVE for TeleTan
* @return result of the test, which can be POSITIVE, NEGATIVE, INVALID, PENDING, FAILED,
* quick-test-POSITIVE, quick-test-NEGATIVE, quick-test-INVALID, quick-test-PENDING or quick-test-FAILED
* will be POSITIVE for TeleTan
*/
@Operation(
summary = "COVID-19 test result for given RegistrationToken",
Expand Down Expand Up @@ -111,14 +114,16 @@ public DeferredResult<ResponseEntity<TestResult>> getTestState(
log.info("The result for registration token based on hashed Guid will be returned.");
stopWatch.stop();
fakeDelayService.updateFakeTestRequestDelay(stopWatch.getTotalTimeMillis());
deferredResult.setResult(ResponseEntity.ok(generateReturnTestResult(testResult.getTestResult(),fake)));
deferredResult.setResult(ResponseEntity.ok(generateReturnTestResult(testResult.getTestResult(),fake,
testResult.getCs())));
return deferredResult;
case TELETAN:
log.info("The result for registration token based on teleTAN will be returned.");
stopWatch.stop();
fakeDelayService.updateFakeTestRequestDelay(stopWatch.getTotalTimeMillis());
scheduledExecutor.schedule(() -> deferredResult.setResult(ResponseEntity.ok(
generateReturnTestResult(LabTestResult.POSITIVE.getTestResult(), fake))),
generateReturnTestResult(LabTestResult.POSITIVE.getTestResult(), fake,
appSession.get().getCreatedAt().toEpochSecond(ZoneOffset.UTC)))),
fakeDelayService.realDelayTest(), MILLISECONDS);
return deferredResult;
default:
Expand All @@ -132,11 +137,12 @@ public DeferredResult<ResponseEntity<TestResult>> getTestState(
"Returning the test result for the registration token failed");
}

private TestResult generateReturnTestResult(Integer testResult, String fake) {
private TestResult generateReturnTestResult(Integer testResult, String fake, Long cs) {
if (fake == null) {
return new TestResult(testResult);
return new TestResult(testResult,cs, RandomStringUtils.randomAlphanumeric(RESPONSE_PADDING_LENGTH));
}
return new TestResult(testResult, RandomStringUtils.randomAlphanumeric(RESPONSE_PADDING_LENGTH));
return new TestResult(testResult, System.currentTimeMillis(),
RandomStringUtils.randomAlphanumeric(RESPONSE_PADDING_LENGTH));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import javax.persistence.Transient;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -47,6 +48,9 @@ public class TestResult {
@NonNull
private int testResult;

@NonNull
private long cs;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Transient
private String responsePadding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public DeferredResult<ResponseEntity<TestResult>> getTestState(
long delay = fakeDelayService.getLongestJitter();
DeferredResult<ResponseEntity<TestResult>> deferredResult = new DeferredResult<>();
scheduledExecutor.schedule(() -> deferredResult.setResult(ResponseEntity
.ok(new TestResult(LabTestResult.POSITIVE.getTestResult(),
.ok(new TestResult(LabTestResult.POSITIVE.getTestResult(), System.currentTimeMillis(),
RandomStringUtils.randomAlphanumeric(TEST_RESPONSE_PADDING_LENGTH)))), delay, MILLISECONDS);
return deferredResult;
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/app/coronawarn/verification/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public class TestUtils {
static final String TEST_INVALID_REG_TOK = "1234567890";
static final String TEST_REG_TOK = "1ea6ce8a-9740-41ea-bb37-0242ac130002";
static final String TEST_REG_TOK_HASH = "0199effab87800689c15c08e234db54f088cc365132ffc230e882b82cd3ecf95";
static final TestResult TEST_LAB_POSITIVE_RESULT = new TestResult(2);
static final TestResult QUICK_TEST_POSITIVE_RESULT = new TestResult(7);
static final TestResult TEST_LAB_NEGATIVE_RESULT = new TestResult(1);
static final TestResult TEST_LAB_POSITIVE_RESULT = new TestResult(2,0);
static final TestResult QUICK_TEST_POSITIVE_RESULT = new TestResult(7,0);
static final TestResult TEST_LAB_NEGATIVE_RESULT = new TestResult(1,0);
static final String TEST_TAN = "1819d933-45f6-4e3c-80c7-eeffd2d44ee6";
static final String TEST_INVALID_TAN = "1ea6ce8a-9740-11ea-is-invalid";
static final TanSourceOfTrust TEST_SOT = TanSourceOfTrust.CONNECTED_LAB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ public void callGetTestState() throws Exception {
mockMvc.perform(post(TestUtils.PREFIX_API_VERSION + "/testresult").contentType(MediaType.APPLICATION_JSON)
.secure( true )
.content(TestUtils.getAsJsonFormat(new RegistrationToken(TestUtils.TEST_REG_TOK,TOKEN_PADDING))))
.andExpect(status().isOk());
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString()
.contains("cs");
}

/**
Expand All @@ -576,7 +580,11 @@ public void callGetTestStateWithFake() throws Exception {
.secure( true )
.header("cwa-fake", "1")
.content(TestUtils.getAsJsonFormat(new RegistrationToken(TestUtils.TEST_REG_TOK,TOKEN_PADDING))))
.andExpect(status().isOk());
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString()
.contains("cs");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class TestResultServerServiceTest {
public static final String TEST_GUI_HASH_1 = "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b";
public static final String TEST_GUI_HASH_2 = "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13c";
private static final String TEST_RESULT_PADDING = "";
public static final TestResult TEST_LAB_POSITIVE_RESULT = new TestResult(2);
public static final TestResult TEST_LAB_REDEEMED_RESULT = new TestResult(4);
public static final TestResult TEST_LAB_POSITIVE_RESULT = new TestResult(2,0);
public static final TestResult TEST_LAB_REDEEMED_RESULT = new TestResult(4,0);
private TestResultServerService testResultServerService;

@BeforeEach
Expand Down Expand Up @@ -65,9 +65,9 @@ public static class TestResultServerClientMock implements TestResultServerClient
@Override
public TestResult result(HashedGuid guid) {
if (guid.getId().equals(TEST_GUI_HASH_1)) {
return new TestResult(2);
return new TestResult(2,0);
}
return new TestResult(4);
return new TestResult(4,0);
}
}
}

0 comments on commit 462eff9

Please sign in to comment.