This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved devicePairingSuccessfulTimestamp to new edit call Signed-off-by: Kolya Opahle <k.opahle@sap.com> * Added some new Tests to VerificationServiceTest Signed-off-by: Kolya Opahle <k.opahle@sap.com> * Renamed VerificationServiceTest to SubmissionServiceTest Signed-off-by: Kolya Opahle <k.opahle@sap.com>
- Loading branch information
1 parent
b1ea123
commit f67b79d
Showing
3 changed files
with
163 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
...a-Warn-App/src/test/java/de/rki/coronawarnapp/service/submission/SubmissionServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package de.rki.coronawarnapp.service.submission | ||
|
||
import de.rki.coronawarnapp.exception.NoGUIDOrTANSetException | ||
import de.rki.coronawarnapp.exception.NoRegistrationTokenSetException | ||
import de.rki.coronawarnapp.http.WebRequestBuilder | ||
import de.rki.coronawarnapp.storage.LocalData | ||
import de.rki.coronawarnapp.transaction.SubmitDiagnosisKeysTransaction | ||
import de.rki.coronawarnapp.util.formatter.TestResult | ||
import io.mockk.Runs | ||
import io.mockk.coEvery | ||
import io.mockk.every | ||
import io.mockk.just | ||
import io.mockk.mockkObject | ||
import io.mockk.verify | ||
import kotlinx.coroutines.runBlocking | ||
import org.hamcrest.CoreMatchers.equalTo | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class SubmissionServiceTest { | ||
private val guid = "123456-12345678-1234-4DA7-B166-B86D85475064" | ||
private val registrationToken = "asdjnskjfdniuewbheboqudnsojdff" | ||
|
||
@Before | ||
fun setUp() { | ||
mockkObject(LocalData) | ||
mockkObject(WebRequestBuilder) | ||
mockkObject(SubmitDiagnosisKeysTransaction) | ||
|
||
every { LocalData.teletan() } returns null | ||
every { LocalData.testGUID() } returns null | ||
every { LocalData.registrationToken() } returns null | ||
} | ||
|
||
@Test(expected = NoGUIDOrTANSetException::class) | ||
fun registerDeviceWithoutTANOrGUIDFails() { | ||
runBlocking { | ||
SubmissionService.asyncRegisterDevice() | ||
} | ||
} | ||
|
||
@Test | ||
fun registrationWithGUIDSucceeds() { | ||
every { LocalData.testGUID() } returns guid | ||
|
||
every { LocalData.testGUID(any()) } just Runs | ||
every { LocalData.registrationToken(any()) } just Runs | ||
every { LocalData.devicePairingSuccessfulTimestamp(any()) } just Runs | ||
|
||
coEvery { | ||
WebRequestBuilder.getInstance() | ||
.asyncGetRegistrationToken(any(), SubmissionConstants.QR_CODE_KEY_TYPE) | ||
} returns registrationToken | ||
|
||
runBlocking { | ||
SubmissionService.asyncRegisterDevice() | ||
} | ||
|
||
verify(exactly = 1) { | ||
LocalData.registrationToken(registrationToken) | ||
LocalData.devicePairingSuccessfulTimestamp(any()) | ||
LocalData.testGUID(null) | ||
} | ||
} | ||
|
||
@Test | ||
fun registrationWithTeleTANSucceeds() { | ||
every { LocalData.teletan() } returns guid | ||
|
||
every { LocalData.teletan(any()) } just Runs | ||
every { LocalData.registrationToken(any()) } just Runs | ||
every { LocalData.devicePairingSuccessfulTimestamp(any()) } just Runs | ||
|
||
coEvery { | ||
WebRequestBuilder.getInstance() | ||
.asyncGetRegistrationToken(any(), SubmissionConstants.TELE_TAN_KEY_TYPE) | ||
} returns registrationToken | ||
|
||
runBlocking { | ||
SubmissionService.asyncRegisterDevice() | ||
} | ||
|
||
verify(exactly = 1) { | ||
LocalData.registrationToken(registrationToken) | ||
LocalData.devicePairingSuccessfulTimestamp(any()) | ||
LocalData.teletan(null) | ||
} | ||
} | ||
|
||
@Test(expected = NoRegistrationTokenSetException::class) | ||
fun requestTestResultWithoutRegistrationTokenFails() { | ||
runBlocking { | ||
SubmissionService.asyncRequestTestResult() | ||
} | ||
} | ||
|
||
@Test | ||
fun requestTestResultSucceeds() { | ||
every { LocalData.registrationToken() } returns registrationToken | ||
coEvery { | ||
WebRequestBuilder.getInstance().asyncGetTestResult(registrationToken) | ||
} returns TestResult.NEGATIVE.value | ||
|
||
runBlocking { | ||
assertThat(SubmissionService.asyncRequestTestResult(), equalTo(TestResult.NEGATIVE)) | ||
} | ||
} | ||
|
||
@Test(expected = NoRegistrationTokenSetException::class) | ||
fun submitExposureKeysWithoutRegistrationTokenFails() { | ||
runBlocking { | ||
SubmissionService.asyncSubmitExposureKeys(listOf()) | ||
} | ||
} | ||
|
||
@Test | ||
fun submitExposureKeysSucceeds() { | ||
every { LocalData.registrationToken() } returns registrationToken | ||
coEvery { SubmitDiagnosisKeysTransaction.start(registrationToken, any()) } just Runs | ||
|
||
runBlocking { | ||
SubmissionService.asyncSubmitExposureKeys(listOf()) | ||
} | ||
} | ||
|
||
@Test | ||
fun deleteRegistrationTokenSucceeds() { | ||
every { LocalData.registrationToken(null) } just Runs | ||
every { LocalData.devicePairingSuccessfulTimestamp(0L) } just Runs | ||
|
||
SubmissionService.deleteRegistrationToken() | ||
|
||
verify(exactly = 1) { | ||
LocalData.registrationToken(null) | ||
LocalData.devicePairingSuccessfulTimestamp(0L) | ||
} | ||
} | ||
|
||
@Test | ||
fun containsValidGUID() { | ||
// valid | ||
assertThat( | ||
SubmissionService.containsValidGUID("https://bs-sd.de/covid-19/?$guid"), | ||
equalTo(true) | ||
) | ||
|
||
// invalid | ||
assertThat( | ||
SubmissionService.containsValidGUID("https://no-guid-here"), | ||
equalTo(false) | ||
) | ||
} | ||
|
||
@Test | ||
fun extractGUID() { | ||
assertThat( | ||
SubmissionService.extractGUID("https://bs-sd.de/covid-19/?$guid"), | ||
equalTo(guid) | ||
) | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
...Warn-App/src/test/java/de/rki/coronawarnapp/service/submission/VerificationServiceTest.kt
This file was deleted.
Oops, something went wrong.