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

Commit

Permalink
Merge pull request #2002 from corona-warn-app/release/1.10.x
Browse files Browse the repository at this point in the history
Release v1.10.1
  • Loading branch information
d4rken authored Dec 28, 2020
2 parents 715c30a + 352157e commit 4f76644
Show file tree
Hide file tree
Showing 199 changed files with 8,241 additions and 373 deletions.
4 changes: 2 additions & 2 deletions Corona-Warn-App/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ dependencies {
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.work:work-runtime-ktx:2.5.0-beta01'
implementation 'androidx.work:work-runtime-ktx:2.5.0-beta02'

implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0'
implementation 'androidx.lifecycle:lifecycle-process:2.2.0'
Expand Down Expand Up @@ -387,7 +387,7 @@ dependencies {
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.ext:truth:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.work:work-testing:2.5.0-beta01'
androidTestImplementation 'androidx.work:work-testing:2.5.0-beta02'
androidTestImplementation "io.mockk:mockk-android:1.10.2"
debugImplementation 'androidx.fragment:fragment-testing:1.2.5'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "857201ec8eba4f3c64ca96c8975ceb69",
"entities": [
{
"tableName": "locations",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`locationId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `locationName` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "locationId",
"columnName": "locationId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "locationName",
"columnName": "locationName",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"locationId"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "locationvisits",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `date` TEXT NOT NULL, `fkLocationId` INTEGER NOT NULL, FOREIGN KEY(`fkLocationId`) REFERENCES `locations`(`locationId`) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fkLocationId",
"columnName": "fkLocationId",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_locationvisits_fkLocationId",
"unique": false,
"columnNames": [
"fkLocationId"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_locationvisits_fkLocationId` ON `${TABLE_NAME}` (`fkLocationId`)"
}
],
"foreignKeys": [
{
"table": "locations",
"onDelete": "CASCADE",
"onUpdate": "CASCADE",
"columns": [
"fkLocationId"
],
"referencedColumns": [
"locationId"
]
}
]
},
{
"tableName": "persons",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`personId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `fullName` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "personId",
"columnName": "personId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "fullName",
"columnName": "fullName",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"personId"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "personencounters",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `date` TEXT NOT NULL, `fkPersonId` INTEGER NOT NULL, FOREIGN KEY(`fkPersonId`) REFERENCES `persons`(`personId`) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "fkPersonId",
"columnName": "fkPersonId",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_personencounters_fkPersonId",
"unique": false,
"columnNames": [
"fkPersonId"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_personencounters_fkPersonId` ON `${TABLE_NAME}` (`fkPersonId`)"
}
],
"foreignKeys": [
{
"table": "persons",
"onDelete": "CASCADE",
"onUpdate": "CASCADE",
"columns": [
"fkPersonId"
],
"referencedColumns": [
"personId"
]
}
]
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '857201ec8eba4f3c64ca96c8975ceb69')"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package de.rki.coronawarnapp.contactdiary.storage

import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryLocationEntity
import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryLocationVisitEntity
import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryLocationVisitWrapper
import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryPersonEncounterEntity
import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryPersonEncounterWrapper
import de.rki.coronawarnapp.contactdiary.storage.entity.ContactDiaryPersonEntity
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking
import org.joda.time.LocalDate
import org.junit.After
import org.junit.Test
import org.junit.runner.RunWith
import testhelpers.BaseTest

@RunWith(AndroidJUnit4::class)
class ContactDiaryDatabaseTest : BaseTest() {

// TestData
private val date = LocalDate.now()
private val person = ContactDiaryPersonEntity(personId = 1, fullName = "Peter")
private val location = ContactDiaryLocationEntity(locationId = 2, locationName = "Rewe Wiesloch")
private val personEncounter = ContactDiaryPersonEncounterEntity(id = 3, date = date, fkPersonId = person.personId)
private val locationVisit = ContactDiaryLocationVisitEntity(id = 4, date = date, fkLocationId = location.locationId)

// DB
private val contactDiaryDatabase: ContactDiaryDatabase =
Room.inMemoryDatabaseBuilder(
ApplicationProvider.getApplicationContext(),
ContactDiaryDatabase::class.java
)
.build()

private val personDao = contactDiaryDatabase.personDao()
private val locationDao = contactDiaryDatabase.locationDao()
private val personEncounterDao = contactDiaryDatabase.personEncounterDao()
private val locationVisitDao = contactDiaryDatabase.locationVisitDao()

private fun List<ContactDiaryPersonEncounterWrapper>.toContactDiaryPersonEncounterEntityList(): List<ContactDiaryPersonEncounterEntity> =
this.map { it.contactDiaryPersonEncounterEntity }

private fun List<ContactDiaryLocationVisitWrapper>.toContactDiaryLocationVisitEntityList(): List<ContactDiaryLocationVisitEntity> =
this.map { it.contactDiaryLocationVisitEntity }

@After
fun teardown() {
contactDiaryDatabase.clearAllTables()
}

@Test
fun checkPersonEncounterDeletedWhenReferencedPersonDeleted() = runBlocking {
val personFlow = personDao.allEntries()
val personEncounterFlow = personEncounterDao
.allEntries()
.map { it.toContactDiaryPersonEncounterEntityList() }

personFlow.first() shouldBe emptyList()
personEncounterFlow.first() shouldBe emptyList()

personDao.insert(person)
personEncounterDao.insert(personEncounter)
personFlow.first() shouldBe listOf(person)
personEncounterFlow.first() shouldBe listOf(personEncounter)

personDao.delete(person)
personFlow.first() shouldBe emptyList()
personEncounterFlow.first() shouldBe emptyList()
}

@Test
fun checkLocationVisitDeletedWhenReferencedLocationDeleted() = runBlocking {
val locationFlow = locationDao.allEntries()
val locationVisitFlow = locationVisitDao
.allEntries()
.map { it.toContactDiaryLocationVisitEntityList() }

locationFlow.first() shouldBe emptyList()
locationVisitFlow.first() shouldBe emptyList()

locationDao.insert(location)
locationVisitDao.insert(locationVisit)
locationFlow.first() shouldBe listOf(location)
locationVisitFlow.first() shouldBe listOf(locationVisit)

locationDao.delete(location)
locationFlow.first() shouldBe emptyList()
locationVisitFlow.first() shouldBe emptyList()
}

@Test
fun getCorrectEntityForDate() = runBlocking {
val yesterday = LocalDate.now().minusDays(1)
val tomorrow = LocalDate.now().plusDays(1)
val personEncounterYesterday =
ContactDiaryPersonEncounterEntity(id = 5, date = yesterday, fkPersonId = person.personId)
val personEncounterTomorrow =
ContactDiaryPersonEncounterEntity(id = 6, date = tomorrow, fkPersonId = person.personId)
val locationVisitYesterday =
ContactDiaryLocationVisitEntity(id = 7, date = yesterday, fkLocationId = location.locationId)
val locationVisitTomorrow =
ContactDiaryLocationVisitEntity(id = 8, date = tomorrow, fkLocationId = location.locationId)
val encounterList = listOf(personEncounter, personEncounterYesterday, personEncounterTomorrow)
val visitList = listOf(locationVisit, locationVisitYesterday, locationVisitTomorrow)
val personEncounterFlow = personEncounterDao.allEntries().map { it.toContactDiaryPersonEncounterEntityList() }
val locationVisitFlow = locationVisitDao.allEntries()
.map { it.toContactDiaryLocationVisitEntityList() }

personDao.insert(person)
personEncounterDao.insert(encounterList)
locationDao.insert(location)
locationVisitDao.insert(visitList)

personEncounterFlow.first() shouldBe encounterList
locationVisitFlow.first() shouldBe visitList

personEncounterDao.entitiesForDate(yesterday).first().toContactDiaryPersonEncounterEntityList() shouldBe listOf(personEncounterYesterday)
personEncounterDao.entitiesForDate(date).first().toContactDiaryPersonEncounterEntityList() shouldBe listOf(personEncounter)
personEncounterDao.entitiesForDate(tomorrow).first().toContactDiaryPersonEncounterEntityList() shouldBe listOf(personEncounterTomorrow)

locationVisitDao.entitiesForDate(yesterday).first().toContactDiaryLocationVisitEntityList() shouldBe listOf(locationVisitYesterday)
locationVisitDao.entitiesForDate(date).first().toContactDiaryLocationVisitEntityList() shouldBe listOf(locationVisit)
locationVisitDao.entitiesForDate(tomorrow).first().toContactDiaryLocationVisitEntityList() shouldBe listOf(locationVisitTomorrow)
}
}

This file was deleted.

Loading

0 comments on commit 4f76644

Please sign in to comment.