diff --git a/.idea/scopes/copyright.xml b/.idea/scopes/copyright.xml index 2c36356d01..addb4c64cd 100644 --- a/.idea/scopes/copyright.xml +++ b/.idea/scopes/copyright.xml @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index d7d74ec625..3ef3d75915 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -63,6 +63,8 @@ pipeline { expression { env.CHANGE_ID == null } anyOf { expression { env.GIT_BRANCH == "master" } + expression { env.GIT_BRANCH == "develop" } + expression { env.GIT_BRANCH ==~ /[0-9]+\.[0-9]+\.[0-9]+-rc/ } } } } diff --git a/README.md b/README.md index aba8e1a3b5..af89dc8ba2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # DHIS2 Android SDK -[![Build Status](https://api.travis-ci.com/dhis2/dhis2-android-sdk.svg?branch=master)](https://travis-ci.com/dhis2/dhis2-android-sdk) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.hisp.dhis/android-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.hisp.dhis/android-core) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=dhis2_dhis2-android-sdk&metric=coverage&branch=master)](https://sonarcloud.io/summary/new_code?id=dhis2_dhis2-android-sdk&branch=master) +[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=dhis2_dhis2-android-sdk&metric=ncloc&branch=master)](https://sonarcloud.io/summary/new_code?id=dhis2_dhis2-android-sdk&branch=master) ## Introduction diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 82e4bb4e3c..0000000000 --- a/build.gradle +++ /dev/null @@ -1,71 +0,0 @@ -buildscript { - ext.kotlin_version = '1.6.10' - repositories { - google() - mavenLocal() - mavenCentral() - maven { url 'https://plugins.gradle.org/m2/' } - } - - dependencies { - classpath "com.android.tools.build:gradle:7.0.4" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0" - classpath "org.jacoco:org.jacoco.core:0.8.8" - } -} - -plugins { - id "org.sonarqube" version "3.3" -} - -sonarqube { - properties { - def branch = System.getenv("GIT_BRANCH") - def targetBranch = System.getenv("GIT_BRANCH_DEST") - def pullRequestId = System.getenv("PULL_REQUEST") - property "sonar.projectKey", "dhis2_dhis2-android-sdk" - property "sonar.organization", "dhis2" - property "sonar.host.url", "https://sonarcloud.io" - property "sonar.projectName", "dhis2-android-sdk" - if (pullRequestId == null) { - property "sonar.branch.name", branch - } else { - property "sonar.pullrequest.base", targetBranch - property "sonar.pullrequest.branch", branch - property "sonar.pullrequest.key", pullRequestId - } - } -} - -allprojects { - repositories { - maven { url "https://maven.google.com" } - maven { url "https://oss.sonatype.org/content/repositories/snapshots" } - google() - mavenCentral() - maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" } - maven { url "https://jitpack.io" } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - -subprojects { project -> - group = GROUP - version = VERSION_NAME - - apply plugin: "org.jlleitschuh.gradle.ktlint" - - ktlint { - version = "0.37.2" - android = true - outputColorName = "RED" - reporters { - reporter "plain" - reporter "checkstyle" - } - } -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000..d2e72f7549 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,77 @@ +import org.jlleitschuh.gradle.ktlint.reporter.ReporterType + +buildscript { + val kotlinVersion = "1.7.21" + + repositories { + google() + mavenLocal() + mavenCentral() + maven(url = "https://plugins.gradle.org/m2/") + } + + dependencies { + classpath("com.android.tools.build:gradle:7.4.1") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}") + classpath("org.jlleitschuh.gradle:ktlint-gradle:11.0.0") + classpath("org.jacoco:org.jacoco.core:0.8.8") + } +} + +plugins { + id("org.sonarqube") version "3.3" +} + +sonarqube { + properties { + val branch = System.getenv("GIT_BRANCH") + val targetBranch = System.getenv("GIT_BRANCH_DEST") + val pullRequestId = System.getenv("PULL_REQUEST") + + property("sonar.projectKey", "dhis2_dhis2-android-sdk") + property("sonar.organization", "dhis2") + property("sonar.host.url", "https://sonarcloud.io") + property("sonar.projectName", "dhis2-android-sdk") + + if (pullRequestId == null) { + property("sonar.branch.name", branch) + } else { + property("sonar.pullrequest.base", targetBranch) + property("sonar.pullrequest.branch", branch) + property("sonar.pullrequest.key", pullRequestId) + } + } +} + +allprojects { + repositories { + maven(url = "https://maven.google.com") + maven(url = "https://oss.sonatype.org/content/repositories/snapshots") + google() + mavenCentral() + maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") + maven(url = "https://jitpack.io") + } +} + +tasks.register("clean", Delete::class) { + delete(rootProject.buildDir) +} + + +subprojects { + apply(plugin = "org.jlleitschuh.gradle.ktlint") + + //group = GROUP + //version = VERSION_NAME + + configure { + version.set("0.45.2") + android.set(true) + outputColorName.set("RED") + reporters { + reporter(ReporterType.PLAIN) + reporter(ReporterType.CHECKSTYLE) + } + } +} \ No newline at end of file diff --git a/core/build.gradle b/core/build.gradle deleted file mode 100644 index 66c438e280..0000000000 --- a/core/build.gradle +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2016, University of Oslo - * - * All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -plugins { - id "com.android.library" - id "kotlin-android" - id "kotlin-kapt" - id "io.gitlab.arturbosch.detekt" version "1.21.0" - id "org.jetbrains.dokka" version "1.6.10" apply false -} - -apply from: project.file("plugins/android-checkstyle.gradle") -apply from: project.file("plugins/android-pmd.gradle") -apply from: project.file("plugins/jacoco.gradle") - -ext { - configuration = [ - buildToolsVersion: "30.0.2", - minSdkVersion : 21, - targetSdkVersion : 31, - versionCode : 271, - versionName : "1.7.1" - ] - - libraries = [ - // android - annotation : '1.4.0', - paging : '2.1.2', - - // java - apacheCommons : "3.8.1", - jackson : "2.11.2", - autoValue : "1.7.4", - autoValueCursor : "2.0.1", - retrofit : "2.9.0", - okHttp : "3.12.0", - dagger : "2.39.1", - rxJava : "2.2.12", - rxAndroid : "2.1.1", - sqlCipher : "4.4.3", - jexl : "2.1.1", - jodaTime : "2.10.6", - smsCompression : "0.2.0", - expressionParser: "1.0.29", - - // test dependencies - coreTesting : "2.1.0", - jUnit : "4.13.2", - mockito : "3.4.6", - mockitoKotlin : "2.2.0", - truth : "1.1.2", - testRunner : "1.4.0", - equalsVerifier : "3.4.1", - flipper : "0.83.0", - soloader : "0.10.1", - liveDataTesting : "1.2.0", - commonsLogging : "1.2", - - // open id - appauth : "0.8.1" - ] -} - -def configuration = project.ext.configuration -def libraries = project.ext.libraries - -android { - compileSdkVersion configuration.targetSdkVersion - buildToolsVersion configuration.buildToolsVersion - - defaultConfig { - minSdkVersion configuration.minSdkVersion - targetSdkVersion configuration.targetSdkVersion - versionCode configuration.versionCode - versionName configuration.versionName - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - multiDexEnabled true - vectorDrawables.useSupportLibrary = true - - buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}") - buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"") - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - packagingOptions { - // excluding duplicate license files - // from jackson modules - exclude "META-INF/LICENSE" - - // should be removed with interoperability library - exclude "META-INF/rxjava.properties" - } - - lintOptions { - // casting 'InvalidPackage' error to warning - warning "InvalidPackage" - disable 'MissingTranslation' - - // Fail early. - abortOnError true - } - - buildTypes { - debug { - // a fix for the debugger not being able to find local scope variables - testCoverageEnabled = (project.hasProperty('coverage')) - } - } - - sourceSets { - test { - resources.srcDirs += ['src/sharedTest/resources'] - } - androidTest { - java.srcDirs += ['src/sharedTest/java'] - resources.srcDirs += ['src/sharedTest/resources'] - } - - } - - testOptions { - unitTests.returnDefaultValues = true - } -} - - -dependencies { - // RxJava - api "io.reactivex.rxjava2:rxjava:${libraries.rxJava}" - api "io.reactivex.rxjava2:rxandroid:${libraries.rxAndroid}" - - // AndroidX - api "androidx.annotation:annotation:${libraries.annotation}" - api "androidx.paging:paging-runtime:${libraries.paging}" - - // Auto Value - api "com.google.auto.value:auto-value-annotations:${libraries.autoValue}" - kapt "com.google.auto.value:auto-value:${libraries.autoValue}" - - // Dagger - api "com.google.dagger:dagger:${libraries.dagger}" - kapt "com.google.dagger:dagger-compiler:${libraries.dagger}" - - // Jackson - api "com.fasterxml.jackson.core:jackson-databind:${libraries.jackson}" - api "com.fasterxml.jackson.module:jackson-module-kotlin:${libraries.jackson}" - - // Square libraries - api "com.squareup.okhttp3:okhttp:${libraries.okHttp}" - api "com.squareup.retrofit2:retrofit:${libraries.retrofit}" - api "com.squareup.retrofit2:converter-jackson:${libraries.retrofit}" - api "com.squareup.retrofit2:adapter-rxjava2:${libraries.retrofit}" - - // Apache libraries - api "org.apache.commons:commons-lang3:${libraries.apacheCommons}" - api("org.apache.commons:commons-jexl:${libraries.jexl}") { - exclude group: 'commons-logging', module: 'commons-logging' - } - - // Joda time - api "joda-time:joda-time:${libraries.jodaTime}" - - // sms compression library - api "com.github.dhis2:sms-compression:${libraries.smsCompression}" - - // DHIS 2 antlr expression parser - api "org.hisp.dhis.parser:dhis-antlr-expression-parser:${libraries.expressionParser}" - - // Extension which generates mappers for work with cursor and content values - api "com.gabrielittner.auto.value:auto-value-cursor-annotations:${libraries.autoValueCursor}" - kapt "com.gabrielittner.auto.value:auto-value-cursor:${libraries.autoValueCursor}" - - api "net.zetetic:android-database-sqlcipher:${libraries.sqlCipher}" - - api "com.squareup.okhttp3:mockwebserver:${libraries.okHttp}" - - // Java test dependencies - testImplementation "junit:junit:${libraries.jUnit}" - testImplementation "org.mockito:mockito-core:${libraries.mockito}" - testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${libraries.mockitoKotlin}" - testImplementation("com.google.truth:truth:${libraries.truth}") { - exclude group: 'junit' // Android has JUnit built in. - } - testImplementation "nl.jqno.equalsverifier:equalsverifier:${libraries.equalsVerifier}" - testImplementation "com.squareup.okhttp3:mockwebserver:${libraries.okHttp}" - testImplementation "androidx.test:runner:${libraries.testRunner}" - testImplementation "commons-logging:commons-logging:${libraries.commonsLogging}" - - // Android test dependencies - androidTestImplementation "commons-logging:commons-logging:${libraries.commonsLogging}" - androidTestImplementation "org.mockito:mockito-core:${libraries.mockito}" - androidTestImplementation "com.jraska.livedata:testing-ktx:${libraries.liveDataTesting}" - androidTestImplementation "androidx.arch.core:core-testing:${libraries.coreTesting}" - androidTestImplementation "androidx.test:runner:${libraries.testRunner}" - androidTestImplementation "androidx.test:rules:${libraries.testRunner}" - androidTestImplementation "com.squareup.okhttp3:logging-interceptor:${libraries.okHttp}" - androidTestImplementation("com.google.truth:truth:${libraries.truth}") { - exclude group: 'junit' // Android has JUnit built in. - } - debugImplementation "com.facebook.flipper:flipper:${libraries.flipper}" - debugImplementation "com.facebook.soloader:soloader:${libraries.soloader}" - debugImplementation ("com.facebook.flipper:flipper-network-plugin:${libraries.flipper}") { - exclude group: 'com.squareup.okhttp3' - } - - releaseImplementation "com.facebook.flipper:flipper-noop:${libraries.flipper}" - - implementation "net.openid:appauth:${libraries.appauth}" - implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' -} - -apply from: project.file("plugins/gradle-mvn-push.gradle") -repositories { - mavenCentral() - maven { url "https://oss.sonatype.org/content/repositories/snapshots" } -} - -detekt { - toolVersion = "1.18.0" - config = files("config/detekt.yml") - parallel = true - buildUponDefaultConfig = false -} - - diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 0000000000..3a08789eb2 --- /dev/null +++ b/core/build.gradle.kts @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2016, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +plugins { + id("com.android.library") + id("kotlin-android") + id("kotlin-kapt") + id("io.gitlab.arturbosch.detekt") version "1.21.0" + id("org.jetbrains.dokka") version "1.7.20" apply false +} + +apply(from = project.file("plugins/android-checkstyle.gradle")) +apply(from = project.file("plugins/android-pmd.gradle")) +apply(from = project.file("plugins/jacoco.gradle")) +apply(from = project.file("plugins/gradle-mvn-push.gradle")) + +repositories { + mavenCentral() + maven(url = "https://oss.sonatype.org/content/repositories/snapshots") +} + +val _targetSdkVersion = 33 +val _minSdkVersion = 21 +val VERSION_CODE: String by project +val VERSION_NAME: String by project + +/* +** Libraries +*/ +val libraryDesugaring = "1.2.2" + +// android +val annotation = "1.4.0" +val paging = "2.1.2" + +// java +val jackson = "2.13.4" +val autoValue = "1.10.1" +val autoValueCursor = "2.0.1" +val retrofit = "2.9.0" +val okHttp = "3.14.9" +val dagger = "2.44.2" +val rxJava = "2.2.21" +val rxAndroid = "2.1.1" +val sqlCipher = "4.4.3" +val smsCompression = "0.2.0" +val expressionParser = "1.0.33" + +// Kotlin +val kotlinxDatetime = "0.4.0" +val coroutines = "1.6.4" + +// test dependencies +val coreTesting = "2.2.0" +val jUnit = "4.13.2" +val mockito = "3.4.6" +val mockitoKotlin = "2.2.0" +val truth = "1.1.3" +val testRunner = "1.5.2" +val testRules = "1.5.0" +val equalsVerifier = "3.14" +val flipper = "0.83.0" +val soloader = "0.10.5" +val liveDataTesting = "1.3.0" + +// open id +val appauth = "0.8.1" + +android { + compileSdk = _targetSdkVersion + + defaultConfig { + minSdk = _minSdkVersion + targetSdk = _targetSdkVersion + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + multiDexEnabled = true + vectorDrawables.useSupportLibrary = true + + buildConfigField("long", "VERSION_CODE", VERSION_CODE) + buildConfigField("String", "VERSION_NAME", "\"${VERSION_NAME}\"") + } + + compileOptions { + isCoreLibraryDesugaringEnabled = true + + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + packagingOptions { + resources { + excludes += listOf("META-INF/LICENSE", "META-INF/rxjava.properties") + } + } + + buildTypes { + getByName("debug") { + // a fix for the debugger not being able to find local scope variables + enableAndroidTestCoverage = (project.hasProperty("coverage")) + } + } + + sourceSets { + sourceSets.getByName("test") { + resources.srcDirs("src/sharedTest/resources") + } + sourceSets.getByName("androidTest") { + java.srcDirs("src/sharedTest/java") + resources.srcDirs("src/sharedTest/resources") + } + } + + testOptions { + unitTests.apply { + isReturnDefaultValues = true + } + } + + lint { + abortOnError = true + disable += "MissingTranslation" + warning += "InvalidPackage" + } + + namespace = "org.hisp.dhis.android" +} + +dependencies { + coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:$libraryDesugaring") + + // RxJava + api("io.reactivex.rxjava2:rxjava:$rxJava") + api("io.reactivex.rxjava2:rxandroid:$rxAndroid") + + // AndroidX + api("androidx.annotation:annotation:$annotation") + api("androidx.paging:paging-runtime:$paging") + + // Auto Value + api("com.google.auto.value:auto-value-annotations:$autoValue") + kapt("com.google.auto.value:auto-value:$autoValue") + + // Dagger + api("com.google.dagger:dagger:$dagger") + kapt("com.google.dagger:dagger-compiler:$dagger") + + // Jackson + api("com.fasterxml.jackson.core:jackson-databind:$jackson") + api("com.fasterxml.jackson.module:jackson-module-kotlin:$jackson") + + // Square libraries + api("com.squareup.okhttp3:okhttp:$okHttp") + api("com.squareup.retrofit2:retrofit:$retrofit") + api("com.squareup.retrofit2:converter-jackson:$retrofit") + api("com.squareup.retrofit2:adapter-rxjava2:$retrofit") + + // Kotlin + api("org.jetbrains.kotlinx:kotlinx-datetime:$kotlinxDatetime") + api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines") + api("org.jetbrains.kotlinx:kotlinx-coroutines-rx2:$coroutines") + + // sms compression library + api("com.github.dhis2:sms-compression:$smsCompression") + + // DHIS 2 antlr expression parser + api("org.hisp.dhis.parser:dhis-antlr-expression-parser:$expressionParser") + + // Extension which generates mappers for work with cursor and content values + api("com.gabrielittner.auto.value:auto-value-cursor-annotations:$autoValueCursor") + kapt("com.gabrielittner.auto.value:auto-value-cursor:$autoValueCursor") + + api("net.zetetic:android-database-sqlcipher:$sqlCipher") + + api("com.squareup.okhttp3:mockwebserver:$okHttp") + + // Java test dependencies + testImplementation("junit:junit:$jUnit") + testImplementation("org.mockito:mockito-core:$mockito") + testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:$mockitoKotlin") + testImplementation("com.google.truth:truth:$truth") { + exclude(group = "junit") // Android has JUnit built in. + } + + testImplementation("nl.jqno.equalsverifier:equalsverifier:$equalsVerifier") + testImplementation("com.squareup.okhttp3:mockwebserver:$okHttp") + testImplementation("androidx.test:runner:$testRunner") + + // Android test dependencies + androidTestImplementation("org.mockito:mockito-core:$mockito") + androidTestImplementation("com.jraska.livedata:testing-ktx:$liveDataTesting") + androidTestImplementation("androidx.arch.core:core-testing:$coreTesting") + androidTestImplementation("androidx.test:runner:$testRunner") + androidTestImplementation("androidx.test:rules:$testRules") + androidTestImplementation("com.squareup.okhttp3:logging-interceptor:$okHttp") + androidTestImplementation("com.google.truth:truth:$truth") { + exclude(group = "junit") // Android has JUnit built in. + } + + debugImplementation("com.facebook.flipper:flipper:$flipper") + debugImplementation("com.facebook.soloader:soloader:$soloader") + debugImplementation("com.facebook.flipper:flipper-network-plugin:$flipper") { + exclude(group = "com.squareup.okhttp3") + } + + releaseImplementation("com.facebook.flipper:flipper-noop:$flipper") + + implementation("net.openid:appauth:$appauth") + implementation("com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava") +} + +detekt { + toolVersion = "1.18.0" + config = files("config/detekt.yml") + parallel = true + buildUponDefaultConfig = false +} diff --git a/core/gradle.properties b/core/gradle.properties index 5c45c50ddc..6198e65e97 100644 --- a/core/gradle.properties +++ b/core/gradle.properties @@ -29,8 +29,8 @@ # Properties which are consumed by plugins/gradle-mvn-push.gradle plugin. # They are used for publishing artifact to snapshot repository. -VERSION_NAME=1.7.1 -VERSION_CODE=271 +VERSION_NAME=1.8.0 +VERSION_CODE=280 GROUP=org.hisp.dhis diff --git a/core/src/androidTest/AndroidManifest.xml b/core/src/androidTest/AndroidManifest.xml index bd6e29a3c7..a43c2ca9af 100644 --- a/core/src/androidTest/AndroidManifest.xml +++ b/core/src/androidTest/AndroidManifest.xml @@ -27,8 +27,7 @@ --> + xmlns:tools="http://schemas.android.com/tools"> diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/BaseIntegrationTestWithDatabase.java b/core/src/androidTest/java/org/hisp/dhis/android/core/BaseIntegrationTestWithDatabase.java index 3e4e186986..98c448f5ff 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/BaseIntegrationTestWithDatabase.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/BaseIntegrationTestWithDatabase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.kt index 4de61aaeea..2c0555e2f7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/D2DIComponentAccessor.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/D2DIComponentAccessor.kt index 9305787819..ce2c9bb016 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/D2DIComponentAccessor.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/D2DIComponentAccessor.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/D2Factory.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/D2Factory.kt index 35d37cd0f6..c373dcf63d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/D2Factory.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/D2Factory.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/LogInCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/LogInCallRealIntegrationShould.java index bc8cb22177..b5bb0330d6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/LogInCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/LogInCallRealIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java index e9604d3671..9b0bcd45dd 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.kt index 8235fde132..132b668207 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserMockIntegrationShould.kt index cb674e0094..9dad0dd160 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserRealIntegrationShould.java index 6a1ae50800..6fac9ca1e4 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserRealIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.kt index f6f26a3a72..cc06cf65a5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/AnalyticsRepositoryIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/AnalyticsRepositoryIntegrationShould.kt index 947a5be155..4d1ffe2977 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/AnalyticsRepositoryIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/AnalyticsRepositoryIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/AnalyticsVisualizationRepositoryIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/AnalyticsVisualizationRepositoryIntegrationShould.kt index 3bc88f92ed..68d36694d6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/AnalyticsVisualizationRepositoryIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/AnalyticsVisualizationRepositoryIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/BaseEvaluatorIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/BaseEvaluatorIntegrationShould.kt index 831ac92321..615b152562 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/BaseEvaluatorIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/BaseEvaluatorIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -55,9 +55,11 @@ import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEv import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.orgunitChild1 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.orgunitChild2 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.orgunitParent +import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period201910 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period201911 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period201912 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period2019Q4 +import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period2019SunW25 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period202001 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period202012 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.program @@ -148,6 +150,8 @@ internal open class BaseEvaluatorIntegrationShould : BaseMockIntegrationTestEmpt dataElement1.displayName()!!, categoryOptionCombo.displayName() ), + period2019SunW25.periodId()!! to MetadataItem.PeriodItem(period2019SunW25), + period201910.periodId()!! to MetadataItem.PeriodItem(period201910), period201911.periodId()!! to MetadataItem.PeriodItem(period201911), period201912.periodId()!! to MetadataItem.PeriodItem(period201912), period202001.periodId()!! to MetadataItem.PeriodItem(period202001), @@ -207,8 +211,11 @@ internal open class BaseEvaluatorIntegrationShould : BaseMockIntegrationTestEmpt dataElementStore.insert(dataElement3) dataElementStore.insert(dataElement4) + periodStore.insert(period2019SunW25) + periodStore.insert(period201910) periodStore.insert(period201911) periodStore.insert(period201912) + periodStore.insert(period202001) periodStore.insert(period2019Q4) trackedEntityTypeStore.insert(trackedEntityType) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/BaseEvaluatorSamples.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/BaseEvaluatorSamples.kt index 7c9981a26f..ec74e947b6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/BaseEvaluatorSamples.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/BaseEvaluatorSamples.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -220,6 +220,20 @@ object BaseEvaluatorSamples { .valueType(ValueType.INTEGER) .build() + val period2019SunW25: Period = Period.builder() + .periodId("2019SunW25") + .periodType(PeriodType.WeeklySunday) + .startDate(DateUtils.DATE_FORMAT.parse("2019-06-16T00:00:00.000")) + .endDate(DateUtils.DATE_FORMAT.parse("2019-06-22T23:59:59.999")) + .build() + + val period201910: Period = Period.builder() + .periodId("201910") + .periodType(PeriodType.Monthly) + .startDate(DateUtils.DATE_FORMAT.parse("2019-10-01T00:00:00.000")) + .endDate(DateUtils.DATE_FORMAT.parse("2019-10-31T23:59:59.999")) + .build() + val period201911: Period = Period.builder() .periodId("201911") .periodType(PeriodType.Monthly) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/DataElementSQLEvaluatorIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/DataElementSQLEvaluatorIntegrationShould.kt index 9a209c6bf7..7a316557d9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/DataElementSQLEvaluatorIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/DataElementSQLEvaluatorIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/EventDataItemSQLEvaluatorIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/EventDataItemSQLEvaluatorIntegrationShould.kt index a94e42eeb3..4e48128908 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/EventDataItemSQLEvaluatorIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/EventDataItemSQLEvaluatorIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorEvaluatorIntegrationBaseShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorEvaluatorIntegrationBaseShould.kt index 833c80849a..488a37a571 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorEvaluatorIntegrationBaseShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorEvaluatorIntegrationBaseShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,9 +40,12 @@ import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEv import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.generator import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.orgunitChild1 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.orgunitParent +import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period201910 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period201911 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period201912 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period2019Q4 +import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period2019SunW25 +import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.period202001 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.program import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.programStage1 import org.hisp.dhis.android.core.analytics.aggregated.internal.evaluator.BaseEvaluatorSamples.trackedEntityType @@ -176,6 +179,117 @@ internal abstract class IndicatorEvaluatorIntegrationBaseShould : BaseEvaluatorI assertThat(overrideValue).isEqualTo("2.5") } + @Test + fun should_evaluate_period_offset() { + createDataValue("2", dataElementUid = dataElement1.uid(), periodId = period201911.periodId()!!) + createDataValue("3", dataElementUid = dataElement1.uid(), periodId = period201912.periodId()!!) + + val indicator = createIndicator(numerator = "(${de(dataElement1.uid())}.periodOffset(-2)).periodOffset(+1)") + + val value = evaluateForAbsolute(indicator, periodId = period201912.periodId()!!) + assertThat(value).isEqualTo("2.0") + } + + @Test + fun should_evaluate_relative_period_offset() { + createDataValue("2", dataElementUid = dataElement1.uid(), periodId = period201911.periodId()!!) + createDataValue("3", dataElementUid = dataElement1.uid(), periodId = period201912.periodId()!!) + createDataValue("20", dataElementUid = dataElement2.uid(), periodId = period201911.periodId()!!) + createDataValue("30", dataElementUid = dataElement2.uid(), periodId = period201912.periodId()!!) + + val expression = "${de(dataElement1.uid())} + ${de(dataElement2.uid())}.periodOffset(-1)" + val indicator = createIndicator(numerator = expression) + + val value = evaluateForThisMonth(indicator) + assertThat(value).isEqualTo("23.0") + } + + @Test + fun should_evaluate_aggregation_type_function() { + createDataValue("2", dataElementUid = dataElement1.uid(), periodId = period201911.periodId()!!) + createDataValue("3", dataElementUid = dataElement1.uid(), periodId = period201912.periodId()!!) + + val sumIndicator = createIndicator(numerator = "${de(dataElement1.uid())}.aggregationType(SUM)") + val sumResult = evaluateForAbsolute(sumIndicator, periodId = period2019Q4.periodId()!!) + assertThat(sumResult).isEqualTo("5.0") + + val avgIndicator = createIndicator(numerator = "${de(dataElement1.uid())}.aggregationType(AVERAGE)") + val avgResult = evaluateForAbsolute(avgIndicator, periodId = period2019Q4.periodId()!!) + assertThat(avgResult).isEqualTo("2.5") + } + + @Test + fun should_evaluate_min_date_function() { + createDataValue("2", dataElementUid = dataElement1.uid(), periodId = period201910.periodId()!!) + createDataValue("4", dataElementUid = dataElement1.uid(), periodId = period201911.periodId()!!) + createDataValue("8", dataElementUid = dataElement1.uid(), periodId = period201912.periodId()!!) + + mapOf( + "${de(dataElement1.uid())}.minDate(2019-10-05)" to "12.0", + "${de(dataElement1.uid())}.maxDate(2019-12-01)" to "6.0", + "${de(dataElement1.uid())}.minDate(2019-10-05).maxDate(2019-12-01)" to "4.0", + ).forEach { (numerator, expected) -> + val indicator = createIndicator(numerator = numerator) + val result = evaluateForAbsolute(indicator, periodId = period2019Q4.periodId()!!) + assertThat(result).isEqualTo(expected) + } + } + + @Test + fun should_evaluate_yearly_period_count_item() { + val indicator = createIndicator(numerator = "[yearlyPeriodCount]") + + mapOf( + period201910 to "12.0", + period2019Q4 to "4.0", + period2019SunW25 to "52.0" + ).forEach { (period, expected) -> + val result = evaluateForAbsolute(indicator, periodId = period.periodId()!!) + assertThat(result).isEqualTo(expected) + } + } + + @Test + fun should_evaluate_period_in_year() { + val indicator = createIndicator(numerator = "[periodInYear]") + + mapOf( + period201910 to "10.0", + period2019Q4 to "4.0", + period2019SunW25 to "25.0" + ).forEach { (period, expected) -> + val result = evaluateForAbsolute(indicator, periodId = period.periodId()!!) + assertThat(result).isEqualTo(expected) + } + } + + @Test + fun should_evaluate_year_to_date() { + createDataValue("2", dataElementUid = dataElement1.uid(), periodId = period201910.periodId()!!) + createDataValue("4", dataElementUid = dataElement1.uid(), periodId = period201911.periodId()!!) + createDataValue("8", dataElementUid = dataElement1.uid(), periodId = period201912.periodId()!!) + createDataValue("16", dataElementUid = dataElement1.uid(), periodId = period202001.periodId()!!) + + val indicator = createIndicator(numerator = "${de(dataElement1.uid())}.yearToDate()") + + mapOf( + period201910 to "2.0", + period201911 to "6.0", + period201912 to "14.0", + period202001 to "16.0", + ).forEach { (period, expected) -> + val result = evaluateForAbsolute(indicator, periodId = period.periodId()!!) + assertThat(result).isEqualTo(expected) + } + } + + @Test + fun should_evaluate_null_literal() { + val indicator = createIndicator(numerator = "firstNonNull(null, 4, 2)") + val result = evaluateForThisMonth(indicator) + assertThat(result).isEqualTo("4.0") + } + private fun evaluateForThisMonth( indicator: Indicator, aggregationType: AggregationType = AggregationType.DEFAULT diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorEvaluatorIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorEvaluatorIntegrationShould.kt index fb9cb55b3f..fd86b5b14b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorEvaluatorIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorEvaluatorIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorSQLEvaluatorIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorSQLEvaluatorIntegrationShould.kt index bb0bcd7dc9..9ca7257f8d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorSQLEvaluatorIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/IndicatorSQLEvaluatorIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/ProgramIndicatorEvaluatorIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/ProgramIndicatorEvaluatorIntegrationShould.kt index 1f7bca67d4..57dfbbfd5c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/ProgramIndicatorEvaluatorIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/ProgramIndicatorEvaluatorIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/eventlinelist/EventLineListIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/eventlinelist/EventLineListIntegrationShould.kt index 78ad8e609e..691368faa3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/eventlinelist/EventLineListIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/eventlinelist/EventLineListIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/eventlinelist/EventLineListSamples.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/eventlinelist/EventLineListSamples.kt index 087ce06969..389a18772b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/eventlinelist/EventLineListSamples.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/analytics/eventlinelist/EventLineListSamples.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/SqliteCheckerUtility.java b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/SqliteCheckerUtility.java index 13d0c3a3b8..03c48808b2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/SqliteCheckerUtility.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/SqliteCheckerUtility.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseAdapterFactoryIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseAdapterFactoryIntegrationShould.java index f507d79b64..2abd54b050 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseAdapterFactoryIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseAdapterFactoryIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseFromMigrationsIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseFromMigrationsIntegrationShould.kt index 7b9ea009b7..558655db9a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseFromMigrationsIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseFromMigrationsIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseImportExportFromDatabaseAssetsMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseImportExportFromDatabaseAssetsMockIntegrationShould.kt index 390487b8a5..0ceef2c025 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseImportExportFromDatabaseAssetsMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseImportExportFromDatabaseAssetsMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/TestDatabaseImporter.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/TestDatabaseImporter.kt index 2964bfffe1..38c596a871 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/TestDatabaseImporter.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/TestDatabaseImporter.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/CollectionRepositoryOneMethodMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/CollectionRepositoryOneMethodMockIntegrationShould.java index 016e9eb7c2..f31d8138ec 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/CollectionRepositoryOneMethodMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/CollectionRepositoryOneMethodMockIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -77,9 +77,8 @@ public void get_first_when_filter_limits_to_no_objects() { @Test public void get_with_all_children_returns_object_children() { CategoryCombo combo = d2.categoryModule().categoryCombos() - .withCategories().withCategoryOptionCombos().one().blockingGet(); + .withCategories().one().blockingGet(); assertThat(combo.uid()).isEqualTo(BIRTH_UID); assertThat(combo.categories().size()).isEqualTo(2); - assertThat(CategoryComboInternalAccessor.accessCategoryOptionCombos(combo).size()).isEqualTo(2); } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/FiltersOperatorsMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/FiltersOperatorsMockIntegrationShould.java index 2029b11223..b2b0c9b049 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/FiltersOperatorsMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/FiltersOperatorsMockIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/IdentifiableCollectionFiltersMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/IdentifiableCollectionFiltersMockIntegrationShould.java index 6041be5420..80657fca5d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/IdentifiableCollectionFiltersMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/IdentifiableCollectionFiltersMockIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/NameableCollectionFiltersMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/NameableCollectionFiltersMockIntegrationShould.java index 5292eab368..1a43e31d8c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/NameableCollectionFiltersMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/NameableCollectionFiltersMockIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/PagingMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/PagingMockIntegrationShould.kt index 070a25ccbb..6e4d927860 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/PagingMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/PagingMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepositoryImplIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepositoryImplIntegrationShould.kt index 013a403623..d44dfa310a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepositoryImplIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepositoryImplIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyIdentifiableCollectionRepositoryImplIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyIdentifiableCollectionRepositoryImplIntegrationShould.kt index 3c92abd048..d49e38532a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyIdentifiableCollectionRepositoryImplIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyIdentifiableCollectionRepositoryImplIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -63,7 +63,7 @@ class ReadOnlyIdentifiableCollectionRepositoryImplIntegrationShould : BaseMockIn .withConstraints() .blockingGet() - assertThat(relationshipType.size).isEqualTo(2) + assertThat(relationshipType.size).isEqualTo(1) } @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/RelationshipTypeAsserts.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/RelationshipTypeAsserts.kt index 390046ecf0..ea3c3fa493 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/RelationshipTypeAsserts.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/RelationshipTypeAsserts.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/storage/internal/CredentialsSecureStorageMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/storage/internal/CredentialsSecureStorageMockIntegrationShould.kt index 957769f172..4ab8771cd1 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/storage/internal/CredentialsSecureStorageMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/storage/internal/CredentialsSecureStorageMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/AttributeStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/AttributeStoreIntegrationShould.java index 479da09eee..fba040971d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/AttributeStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/AttributeStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/DataElementAttributeValueLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/DataElementAttributeValueLinkStoreIntegrationShould.java index e3a5ec5c0d..719ebaef89 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/DataElementAttributeValueLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/DataElementAttributeValueLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/ProgramAttributeValueLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/ProgramAttributeValueLinkStoreIntegrationShould.java index 9415420a8e..fa20f8cfcc 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/ProgramAttributeValueLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/ProgramAttributeValueLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/ProgramStageAttributeValueLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/ProgramStageAttributeValueLinkStoreIntegrationShould.java index 3972d81760..1e7d874c02 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/ProgramStageAttributeValueLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/attribute/internal/ProgramStageAttributeValueLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreIntegrationShould.kt index d94be6ef2a..c182920df3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryOptionLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryOptionLinkStoreIntegrationShould.java index 9a8db4c74d..71dd213770 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryOptionLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryOptionLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.kt index c0cbc64472..dbe0145493 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboUidsSeekerMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboUidsSeekerMockIntegrationShould.kt similarity index 67% rename from core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboUidsSeekerMockIntegrationShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboUidsSeekerMockIntegrationShould.kt index 29c40ca32b..0a5133d125 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboUidsSeekerMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboUidsSeekerMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,28 +25,23 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +package org.hisp.dhis.android.core.category.internal -package org.hisp.dhis.android.core.category.internal; - -import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher; -import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.Set; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(D2JunitRunner.class) -public class CategoryComboUidsSeekerMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher { +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.Test +import org.junit.runner.RunWith +@RunWith(D2JunitRunner::class) +class CategoryComboUidsSeekerMockIntegrationShould : BaseMockIntegrationTestFullDispatcher() { @Test - public void seek_category_combos_uids() { - Set categories = new CategoryComboUidsSeeker(databaseAdapter).seekUids(); + fun seek_category_combos_uids() { + val categories = CategoryComboUidsSeeker(databaseAdapter).seekUids() + assertThat(categories.size).isEqualTo(2) + assertThat(categories.contains("m2jTvAj5kkm")).isTrue() - assertThat(categories.size()).isEqualTo(2); - assertThat(categories.contains("m2jTvAj5kkm")).isTrue(); // Default category combo (p0KPaWEg3cf). - assertThat(categories.contains("p0KPaWEg3cf")).isTrue(); + assertThat(categories.contains("p0KPaWEg3cf")).isTrue() } -} \ No newline at end of file +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.kt index 52a8765439..467691ac59 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallShould.kt index 833816fcaa..7328287b2e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryOptionComboCategoryOptionLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryOptionComboCategoryOptionLinkStoreIntegrationShould.java index 00ab113edd..b4ca21cd74 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryOptionComboCategoryOptionLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryOptionComboCategoryOptionLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryOptionOrganisationUnitLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryOptionOrganisationUnitLinkStoreIntegrationShould.kt index 34a4859e0d..e0bc6a40b0 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryOptionOrganisationUnitLinkStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryOptionOrganisationUnitLinkStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CreateCategoryComboUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CreateCategoryComboUtils.java index 4d87d77c09..183c326745 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CreateCategoryComboUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CreateCategoryComboUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreIntegrationShould.java index 022e42fb02..c388bc97bd 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ObjectStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ObjectStoreIntegrationShould.java index 93ea694c1b..0cddec6e6a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ObjectStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ObjectStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/StoreMocks.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/StoreMocks.java index 47db5b9eff..b1eb9bef5b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/StoreMocks.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/StoreMocks.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingStoreIntegrationShould.java index 961b915dfb..8f7a762387 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/internal/DataStatePropagatorIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/common/internal/DataStatePropagatorIntegrationShould.kt index cd90849b2c..043c100098 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/internal/DataStatePropagatorIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/internal/DataStatePropagatorIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/ConfigurationStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/ConfigurationStoreIntegrationShould.java index 0b3efb1fbd..b3e6ce3ea7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/ConfigurationStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/ConfigurationStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/DatabaseConfigurationMigrationIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/DatabaseConfigurationMigrationIntegrationShould.kt index cc885d2cd6..739ed9796b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/DatabaseConfigurationMigrationIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/DatabaseConfigurationMigrationIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,13 +35,11 @@ import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter import org.hisp.dhis.android.core.arch.db.access.internal.DatabaseAdapterFactory import org.hisp.dhis.android.core.arch.helpers.FileResourceDirectoryHelper import org.hisp.dhis.android.core.arch.storage.internal.* -import org.hisp.dhis.android.core.common.ObjectWithUid import org.hisp.dhis.android.core.configuration.internal.migration.DatabaseConfigurationInsecureStoreOld import org.hisp.dhis.android.core.configuration.internal.migration.DatabaseServerConfigurationOld import org.hisp.dhis.android.core.configuration.internal.migration.DatabaseUserConfigurationOld import org.hisp.dhis.android.core.configuration.internal.migration.DatabasesConfigurationOld import org.hisp.dhis.android.core.user.UserCredentials -import org.hisp.dhis.android.core.user.internal.UserCredentialsStoreImpl import org.hisp.dhis.android.core.utils.runner.D2JunitRunner import org.junit.Before import org.junit.Test @@ -64,10 +62,7 @@ class DatabaseConfigurationMigrationIntegrationShould { private val newName = nameGenerator.getDatabaseName(serverUrl, username, false) private val credentials = UserCredentials.builder() - .id(1L) - .uid("uid") .username(username) - .user(ObjectWithUid.create("user")) .build() private lateinit var migration: DatabaseConfigurationMigration @@ -113,8 +108,7 @@ class DatabaseConfigurationMigrationIntegrationShould { assertThat(context.databaseList().contains(newName)).isTrue() databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, newName, false) - val credentialsStore = UserCredentialsStoreImpl.create(databaseAdapter) - assertThat(credentialsStore.selectFirst()).isEqualTo(credentials) + assertThat(getUsernameForOldDatabase(databaseAdapter)).isEqualTo(credentials.username()) assertThat(credentialsSecureStore.get()).isNull() } @@ -184,10 +178,24 @@ class DatabaseConfigurationMigrationIntegrationShould { } private fun setCredentialsAndServerUrl(databaseAdapter: DatabaseAdapter) { + databaseAdapter.execSQL("CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT)") databaseAdapter.setForeignKeyConstraintsEnabled(false) - val credentialsStore = UserCredentialsStoreImpl.create(databaseAdapter) - credentialsStore.insert(credentials) + databaseAdapter.execSQL("INSERT INTO UserCredentials (username) VALUES ('${credentials.username()}')") val configurationStore = ConfigurationStore.create(databaseAdapter) configurationStore.insert(Configuration.forServerUrl(serverUrl)) } + + private fun getUsernameForOldDatabase(databaseAdapter: DatabaseAdapter): String? { + val cursor = databaseAdapter.rawQuery("SELECT username FROM UserCredentials") + var username: String? = null + + cursor.use { + if (cursor.count > 0) { + cursor.moveToFirst() + username = it.getString(0) + } + } + + return username + } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/constant/internal/ConstantStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/constant/internal/ConstantStoreIntegrationShould.java index 4d6093620f..39f3d7ae7e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/constant/internal/ConstantStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/constant/internal/ConstantStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/CursorAssert.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/CursorAssert.java index 0bd478d320..4723daed28 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/CursorAssert.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/CursorAssert.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DatabaseAssert.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DatabaseAssert.kt index 86fc10457b..019fb646fd 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DatabaseAssert.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DatabaseAssert.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DbTestUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DbTestUtils.java index 37df661520..5eae5943c0 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DbTestUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DbTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/IdentifiableDataObjectStoreAbstractIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/IdentifiableDataObjectStoreAbstractIntegrationShould.kt index fc13ece95a..d8da22510f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/IdentifiableDataObjectStoreAbstractIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/IdentifiableDataObjectStoreAbstractIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/IdentifiableObjectStoreAbstractIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/IdentifiableObjectStoreAbstractIntegrationShould.kt index df112b0047..47d394d7dd 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/IdentifiableObjectStoreAbstractIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/IdentifiableObjectStoreAbstractIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/LinkStoreAbstractIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/LinkStoreAbstractIntegrationShould.kt index 7f4806dc50..30154db495 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/LinkStoreAbstractIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/LinkStoreAbstractIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectStoreAbstractIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectStoreAbstractIntegrationShould.kt index cfaa708024..a6fee2b337 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectStoreAbstractIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectStoreAbstractIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectWithoutUidStoreAbstractIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectWithoutUidStoreAbstractIntegrationShould.kt index efcff6a6f7..8ebb31b600 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectWithoutUidStoreAbstractIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectWithoutUidStoreAbstractIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java index 2c14341c1b..7507a9e7db 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java index 4e0a14e585..83d01e1217 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,6 +39,8 @@ public class RealServerMother { public static String url2_36 = "https://play.dhis2.org/2.36/"; public static String url2_37 = "https://play.dhis2.org/2.37/"; public static String url2_38 = "https://play.dhis2.org/2.38/"; + public static String url2_39 = "https://play.dhis2.org/2.39/"; + public static String url2_40 = "https://play.dhis2.org/2.40/"; public static String url_dev = "https://play.dhis2.org/dev/"; public static String android_current = "https://play.dhis2.org/android-current/"; public static String android_previous1 = "https://play.dhis2.org/android-previous1/"; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/CreateDataElementUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/CreateDataElementUtils.java index ede5d09780..ac76d13408 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/CreateDataElementUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/CreateDataElementUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.kt index 9cedb01187..91c29ab963 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementOperandStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementOperandStoreIntegrationShould.java index 7be7f17032..96f5684bc8 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementOperandStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementOperandStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementStoreIntegrationShould.java index cee249e514..2e1d7db62d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataInputPeriodLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataInputPeriodLinkStoreIntegrationShould.java index 1930190dbe..b3cd312839 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataInputPeriodLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataInputPeriodLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationCallRealIntegrationShould.java index 7f12c9172c..c669577d6d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationCallRealIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationPostCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationPostCallRealIntegrationShould.java index 5123003597..b8244b8809 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationPostCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationPostCallRealIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompulsoryDataElementOperandLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompulsoryDataElementOperandLinkStoreIntegrationShould.java index dedac2613d..a1b3e858bd 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompulsoryDataElementOperandLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompulsoryDataElementOperandLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetDataElementLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetDataElementLinkStoreIntegrationShould.java index 8b4768d60e..cd75369b2e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetDataElementLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetDataElementLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.kt index 8703f398c8..125a46bb79 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -53,7 +53,7 @@ class DataSetEndpointCallRealIntegrationShould : BaseRealIntegrationTest() { // @Test @Throws(Exception::class) fun download_data_sets() { - if (!d2.userModule().isLogged.blockingGet()) { + if (!d2.userModule().isLogged().blockingGet()) { d2.userModule().logIn(username, password, url).blockingGet() } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceStoreIntegrationShould.kt index c0bd853d1d..af097e1c93 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetOrganisationUnitLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetOrganisationUnitLinkStoreIntegrationShould.java index c6910f2ba1..367250a0ac 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetOrganisationUnitLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetOrganisationUnitLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetStoreIntegrationShould.java index 45d00b4c03..272bf82c47 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionDataElementLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionDataElementLinkStoreIntegrationShould.java index 53c25948ae..dde4e9b02f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionDataElementLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionDataElementLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionGreyedFieldsLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionGreyedFieldsLinkStoreIntegrationShould.java index 0867fdf5bc..66cb03861b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionGreyedFieldsLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionGreyedFieldsLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionIndicatorLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionIndicatorLinkStoreIntegrationShould.kt index 96dd026b48..d2113db7d5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionIndicatorLinkStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionIndicatorLinkStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionStoreIntegrationShould.java index 535c837cfc..c3c562ae94 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/SectionStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/DataStoreEntryStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/DataStoreEntryStoreIntegrationShould.kt new file mode 100644 index 0000000000..c6396f6e0b --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/DataStoreEntryStoreIntegrationShould.kt @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.datastore + +import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould +import org.hisp.dhis.android.core.data.datastore.DataStoreEntrySamples +import org.hisp.dhis.android.core.datastore.internal.DataStoreEntryStoreImpl.Companion.create +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class DataStoreEntryStoreIntegrationShould : ObjectWithoutUidStoreAbstractIntegrationShould( + create(TestDatabaseAdapterFactory.get()), + DataStoreEntryTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get() +) { + override fun buildObject(): DataStoreEntry { + return DataStoreEntrySamples.get() + } + + override fun buildObjectToUpdate(): DataStoreEntry { + return DataStoreEntrySamples.get() + .toBuilder() + .value("value2") + .build() + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/LocalDataStoreStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/LocalDataStoreStoreIntegrationShould.kt index e58f53dcdc..a9f79f10d7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/LocalDataStoreStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/LocalDataStoreStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/internal/DataStorePostCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/internal/DataStorePostCallMockIntegrationShould.kt new file mode 100644 index 0000000000..f72e5acd07 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datastore/internal/DataStorePostCallMockIntegrationShould.kt @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.datastore.internal + +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.common.State +import org.hisp.dhis.android.core.maintenance.D2Error +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestMetadataEnqueable +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.After +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class DataStorePostCallMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueable() { + + @After + @Throws(D2Error::class) + fun tearDown() { + d2.wipeModule().wipeData() + } + + @Test + fun post_dataStore_success() { + // Given user sets valid value + dhis2MockServer.enqueueMockResponse(201, "datastore/actions/namespace_key_post_201.json") + provideDataStore("config", "key", "{\"enabled\": true}") + + assertExistWithState(State.TO_POST) + d2.dataStoreModule().dataStore().blockingUpload() + assertExistWithState(State.SYNCED) + } + + @Test + fun put_if_already_exists() { + dhis2MockServer.enqueueMockResponse(409, "datastore/actions/namespace_key_post_already_exists_409.json") + dhis2MockServer.enqueueMockResponse("datastore/actions/namespace_key_put_200.json") + provideDataStore("config", "key", "{\"enabled\": true}") + + assertExistWithState(State.TO_POST) + d2.dataStoreModule().dataStore().blockingUpload() + assertExistWithState(State.SYNCED) + } + + @Test + fun post_if_not_found() { + dhis2MockServer.enqueueMockResponse(404, "datastore/actions/namespace_key_put_not_found_404.json") + dhis2MockServer.enqueueMockResponse(201, "datastore/actions/namespace_key_post_201.json") + provideDataStore("config", "key", "{\"enabled\": true}") + setState(State.TO_UPDATE) + + assertExistWithState(State.TO_UPDATE) + d2.dataStoreModule().dataStore().blockingUpload() + assertExistWithState(State.SYNCED) + } + + @Test + fun delete_locally() { + dhis2MockServer.enqueueMockResponse("datastore/actions/namespace_key_deleted_200.json") + provideDataStore("config", "key", "{\"enabled\": true}") + setState(State.TO_UPDATE) + d2.dataStoreModule().dataStore().value("config", "key").blockingDelete() + + assertExistWithState(State.TO_UPDATE) + d2.dataStoreModule().dataStore().blockingUpload() + assertThat(d2.dataStoreModule().dataStore().blockingIsEmpty()).isTrue() + } + + @Test + fun delete_locally_even_if_not_found() { + dhis2MockServer.enqueueMockResponse(404, "datastore/actions/namespace_key_deleted_not_found_404.json") + provideDataStore("config", "key", "{\"enabled\": true}") + setState(State.TO_UPDATE) + d2.dataStoreModule().dataStore().value("config", "key").blockingDelete() + + assertExistWithState(State.TO_UPDATE) + d2.dataStoreModule().dataStore().blockingUpload() + assertThat(d2.dataStoreModule().dataStore().blockingIsEmpty()).isTrue() + } + + private fun assertExistWithState(state: State) { + val entries = d2.dataStoreModule().dataStore().blockingGet() + assertThat(entries.size).isEqualTo(1) + assertThat(entries[0].syncState()).isEqualTo(state) + } + + private fun provideDataStore(namespace: String, key: String, value: String) { + d2.dataStoreModule().dataStore() + .value(namespace, key) + .blockingSet(value) + } + + private fun setState(state: State) { + val entries = d2.dataStoreModule().dataStore().blockingGet() + + val store = DataStoreEntryStoreImpl.create(databaseAdapter) + entries.forEach { + store.setState(it, state) + } + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueConflictStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueConflictStoreIntegrationShould.kt index c3a7a1f3c9..fa8a42b3d7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueConflictStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueConflictStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueEndpointCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueEndpointCallRealIntegrationShould.kt index 00e130d360..14a7f75adc 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueEndpointCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueEndpointCallRealIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -77,7 +77,7 @@ class DataValueEndpointCallRealIntegrationShould : BaseRealIntegrationTest() { // @Test @Throws(Exception::class) fun download_data_values() { - if (!d2.userModule().isLogged.blockingGet()) { + if (!d2.userModule().isLogged().blockingGet()) { d2.userModule().logIn(username, password, url).blockingGet() } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValuePostCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValuePostCallMockIntegrationShould.kt index acd61775e6..58625b5be8 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValuePostCallMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValuePostCallMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValuePostCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValuePostCallRealIntegrationShould.java index f6351b7733..88ad61016d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValuePostCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValuePostCallRealIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/debug/flipper/debug/FlipperManager.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/debug/flipper/debug/FlipperManager.kt index b29e8034c0..8e17d9f745 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/debug/flipper/debug/FlipperManager.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/debug/flipper/debug/FlipperManager.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallMockIntegrationShould.kt index d5aa83c1cf..ffb6f94924 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallRealIntegrationShould.kt index d145432c5c..80ef2bef1e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallRealIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataSyncStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataSyncStoreIntegrationShould.kt index e94653d6dc..c148e95a08 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataSyncStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/internal/AggregatedDataSyncStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/enrollment/CreateEnrollmentUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/enrollment/CreateEnrollmentUtils.java index b38b5848fb..0a6f9350c2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/enrollment/CreateEnrollmentUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/enrollment/CreateEnrollmentUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentStoreIntegrationShould.java index 644c3e4c57..fc48f931bf 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/CreateEventUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/CreateEventUtils.java index a59f2bf807..0a3b39ca76 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/CreateEventUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/CreateEventUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/EventWithLimitCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallBaseMockIntegrationShould.kt similarity index 62% rename from core/src/androidTest/java/org/hisp/dhis/android/core/EventWithLimitCallMockIntegrationShould.kt rename to core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallBaseMockIntegrationShould.kt index f0b133e5fd..eb5eb0f2ee 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/EventWithLimitCallMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallBaseMockIntegrationShould.kt @@ -1,19 +1,19 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * Neither the name of the HISP project nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -25,42 +25,61 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core +package org.hisp.dhis.android.core.event -import com.google.common.truth.Truth +import com.google.common.truth.Truth.assertThat import org.hisp.dhis.android.core.event.internal.EventStoreImpl -import org.hisp.dhis.android.core.maintenance.D2Error +import org.hisp.dhis.android.core.settings.SynchronizationSettings +import org.hisp.dhis.android.core.settings.internal.SynchronizationSettingStore +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestMetadataEnqueable -import org.hisp.dhis.android.core.utils.runner.D2JunitRunner import org.junit.After +import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -@RunWith(D2JunitRunner::class) -class EventWithLimitCallMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueable() { +abstract class EventWithLimitCallBaseMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueable() { + + abstract val importerVersion: TrackerImporterVersion + abstract val exporterVersion: TrackerExporterVersion + abstract val downloadEventsFile: String + abstract val downloadEventsByUidLimitedByOneFile: String + + private lateinit var initSyncParams: SynchronizationSettings + private val syncStore = SynchronizationSettingStore.create(databaseAdapter) + + @Before + fun setUp() { + initSyncParams = syncStore.selectFirst()!! + val testParams = initSyncParams.toBuilder().trackerImporterVersion(importerVersion) + .trackerExporterVersion(exporterVersion).build() + syncStore.delete() + syncStore.insert(testParams) + } @After - @Throws(D2Error::class) fun tearDown() { d2.wipeModule().wipeData() + syncStore.delete() + syncStore.insert(initSyncParams) } @Test fun download_events() { val eventLimitByOrgUnit = 1 dhis2MockServer.enqueueSystemInfoResponse() - dhis2MockServer.enqueueMockResponse("event/events_1.json") + dhis2MockServer.enqueueMockResponse(downloadEventsFile) d2.eventModule().eventDownloader().limit(eventLimitByOrgUnit).blockingDownload() val eventStore = EventStoreImpl.create(databaseAdapter) val downloadedEvents = eventStore.querySingleEvents() - Truth.assertThat(downloadedEvents.size).isEqualTo(eventLimitByOrgUnit) + assertThat(downloadedEvents.size).isEqualTo(eventLimitByOrgUnit) } // @Test TODO https://jira.dhis2.org/browse/ANDROSDK-1328 fun download_events_by_uid_limited_by_one() { val eventLimitByOrgUnit = 1 dhis2MockServer.enqueueSystemInfoResponse() - dhis2MockServer.enqueueMockResponse("event/events_with_uids.json") + dhis2MockServer.enqueueMockResponse(downloadEventsByUidLimitedByOneFile) d2.eventModule().eventDownloader() .byUid() .`in`("wAiGPfJGMxt", "PpNGhvEYnXe") @@ -68,6 +87,6 @@ class EventWithLimitCallMockIntegrationShould : BaseMockIntegrationTestMetadataE .blockingDownload() val eventStore = EventStoreImpl.create(databaseAdapter) val downloadedEvents = eventStore.querySingleEvents() - Truth.assertThat(downloadedEvents.size).isEqualTo(eventLimitByOrgUnit) + assertThat(downloadedEvents.size).isEqualTo(eventLimitByOrgUnit) } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallNewMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallNewMockIntegrationShould.kt new file mode 100644 index 0000000000..91f82f4ca8 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallNewMockIntegrationShould.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event + +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class EventWithLimitCallNewMockIntegrationShould : EventWithLimitCallBaseMockIntegrationShould() { + override val importerVersion = TrackerImporterVersion.V2 + override val exporterVersion = TrackerExporterVersion.V2 + override val downloadEventsFile = "event/new_tracker_importer_events_1.json" + override val downloadEventsByUidLimitedByOneFile = "event/new_tracker_events_with_uids.json" +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallOldMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallOldMockIntegrationShould.kt new file mode 100644 index 0000000000..0cecc3d98d --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventWithLimitCallOldMockIntegrationShould.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event + +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class EventWithLimitCallOldMockIntegrationShould : EventWithLimitCallBaseMockIntegrationShould() { + override val importerVersion = TrackerImporterVersion.V1 + override val exporterVersion = TrackerExporterVersion.V1 + override val downloadEventsFile = "event/events_1.json" + override val downloadEventsByUidLimitedByOneFile = "event/events_with_uids.json" +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPI29RealShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPI29RealShould.java index e5aa01cacb..23f9e1bd5c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPI29RealShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPI29RealShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPI30RealShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPI30RealShould.java index 00edaea4f0..b262ce7bfe 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPI30RealShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPI30RealShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPIRealShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPIRealShould.java deleted file mode 100644 index a68c4bec19..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPIRealShould.java +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.event.internal; - -import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.event.internal.EventUtils.assertEvent; -import static org.hisp.dhis.android.core.event.internal.EventUtils.createEventWithFutureDate; -import static org.hisp.dhis.android.core.event.internal.EventUtils.createEventWithInvalidAttributeOptionCombo; -import static org.hisp.dhis.android.core.event.internal.EventUtils.createEventWithInvalidDataValues; -import static org.hisp.dhis.android.core.event.internal.EventUtils.createEventWithInvalidOrgunit; -import static org.hisp.dhis.android.core.event.internal.EventUtils.createEventWithInvalidProgram; -import static org.hisp.dhis.android.core.event.internal.EventUtils.createValidEvent; -import static org.hisp.dhis.android.core.imports.ImportStatus.ERROR; -import static org.hisp.dhis.android.core.imports.ImportStatus.SUCCESS; -import static org.hisp.dhis.android.core.imports.ImportStatus.WARNING; - -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutor; -import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutorImpl; -import org.hisp.dhis.android.core.event.Event; -import org.hisp.dhis.android.core.imports.internal.EventImportSummary; -import org.hisp.dhis.android.core.imports.internal.EventWebResponse; -import org.hisp.dhis.android.core.maintenance.D2Error; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode; -import org.junit.Assert; -import org.junit.Before; - -import java.util.Arrays; -import java.util.Collections; - -public abstract class EventAPIRealShould extends BaseRealIntegrationTest { - - // API version dependant parameters - private String serverUrl; - private String strategy; - private String ouMode = OrganisationUnitMode.ACCESSIBLE.name(); - - private APICallExecutor apiCallExecutor; - - private EventService eventService; - - EventAPIRealShould(String serverUrl, String strategy) { - super(); - this.serverUrl = serverUrl; - this.strategy = strategy; - } - - @Before - public void setUp() { - super.setUp(); - apiCallExecutor = APICallExecutorImpl.create(d2.databaseAdapter(), null); - - eventService = d2.retrofit().create(EventService.class); - } - - //@Test - public void valid_events() throws Exception { - login(); - - Event validEvent1 = createValidEvent(); - - Event validEvent2 = createValidEvent(); - - EventPayload payload = new EventPayload(); - payload.events = Arrays.asList(validEvent1, validEvent2); - - EventWebResponse response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes(eventService - .postEvents(payload, this.strategy), Collections.singletonList(409), EventWebResponse.class); - - assertThat(response.response().status()).isEqualTo(SUCCESS); - - for (EventImportSummary importSummary : response.response().importSummaries()) { - if (validEvent1.uid().equals(importSummary.reference())) { - assertEvent(importSummary, SUCCESS); - } - else if (validEvent2.uid().equals(importSummary.reference())) { - assertEvent(importSummary, SUCCESS); - } - } - - // Check server status - Event serverValidEvent1 = apiCallExecutor.executeObjectCall(eventService.getEvent(validEvent1.uid(), EventFields.allFields, ouMode)); - Event serverValidEvent2 = apiCallExecutor.executeObjectCall(eventService.getEvent(validEvent2.uid(), EventFields.allFields, ouMode)); - - assertThat(serverValidEvent1).isNotNull(); - assertThat(serverValidEvent2).isNotNull(); - } - - //@Test - public void event_with_invalid_orgunit() throws Exception { - login(); - - Event validEvent = createValidEvent(); - - Event invalidEvent = createEventWithInvalidOrgunit(); - - EventPayload payload = new EventPayload(); - payload.events = Arrays.asList(validEvent, invalidEvent); - - EventWebResponse response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes(eventService - .postEvents(payload, this.strategy), Collections.singletonList(409), EventWebResponse.class); - - assertThat(response.response().status()).isEqualTo(ERROR); - - for (EventImportSummary importSummary : response.response().importSummaries()) { - if (validEvent.uid().equals(importSummary.reference())) { - assertEvent(importSummary, SUCCESS); - } - else if (invalidEvent.uid().equals(importSummary.reference())) { - assertEvent(importSummary, ERROR); - } - } - - // Check server status - Event serverValidEvent = apiCallExecutor.executeObjectCall(eventService.getEvent(validEvent.uid(), EventFields.allFields, ouMode)); - - assertThat(serverValidEvent).isNotNull(); - - try { - apiCallExecutor.executeObjectCall(eventService.getEvent(invalidEvent.uid(), EventFields.allFields, ouMode)); - Assert.fail("Should not reach that line"); - } catch (D2Error e) { - assertThat(e.httpErrorCode()).isEqualTo(404); - } - } - - //@Test - public void event_with_invalid_attribute_option_combo() throws Exception { - login(); - - Event validEvent = createValidEvent(); - - Event invalidEvent = createEventWithInvalidAttributeOptionCombo(); - - EventPayload payload = new EventPayload(); - payload.events = Arrays.asList(validEvent, invalidEvent); - - EventWebResponse response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes(eventService - .postEvents(payload, this.strategy), Collections.singletonList(409), EventWebResponse.class); - - assertThat(response.response().status()).isEqualTo(ERROR); - - for (EventImportSummary importSummary : response.response().importSummaries()) { - if (validEvent.uid().equals(importSummary.reference())) { - assertEvent(importSummary, SUCCESS); - } - else if (invalidEvent.uid().equals(importSummary.reference())) { - assertEvent(importSummary, ERROR); - } - } - - // Check server status - Event serverValidEvent = apiCallExecutor.executeObjectCall(eventService.getEvent(validEvent.uid(), EventFields.allFields, ouMode)); - - assertThat(serverValidEvent).isNotNull(); - - try { - apiCallExecutor.executeObjectCall(eventService.getEvent(invalidEvent.uid(), EventFields.allFields, ouMode)); - Assert.fail("Should not reach that line"); - } catch (D2Error e) { - assertThat(e.httpErrorCode()).isEqualTo(404); - } - } - - //@Test - public void event_with_future_date_does_not_fail() throws Exception { - login(); - - Event validEvent1 = createValidEvent(); - - Event validEvent2 = createEventWithFutureDate(); - - EventPayload payload = new EventPayload(); - payload.events = Arrays.asList(validEvent1, validEvent2); - - EventWebResponse response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes(eventService - .postEvents(payload, this.strategy), Collections.singletonList(409), EventWebResponse.class); - - assertThat(response.response().status()).isEqualTo(SUCCESS); - - for (EventImportSummary importSummary : response.response().importSummaries()) { - if (validEvent1.uid().equals(importSummary.reference())) { - assertEvent(importSummary, SUCCESS); - } - else if (validEvent2.uid().equals(importSummary.reference())) { - assertEvent(importSummary, SUCCESS); - } - } - - // Check server status - Event serverValidEvent1 = apiCallExecutor.executeObjectCall(eventService.getEvent(validEvent1.uid(), EventFields.allFields, ouMode)); - Event serverValidEvent2 = apiCallExecutor.executeObjectCall(eventService.getEvent(validEvent2.uid(), EventFields.allFields, ouMode)); - - assertThat(serverValidEvent1).isNotNull(); - assertThat(serverValidEvent2).isNotNull(); - } - - //@Test - public void event_with_invalid_program() throws Exception { - login(); - - Event validEvent = createValidEvent(); - - Event invalidEvent = createEventWithInvalidProgram(); - - EventPayload payload = new EventPayload(); - payload.events = Arrays.asList(validEvent, invalidEvent); - - EventWebResponse response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes(eventService - .postEvents(payload, this.strategy), Collections.singletonList(409), EventWebResponse.class); - - assertThat(response.response().status()).isEqualTo(ERROR); - - for (EventImportSummary importSummary : response.response().importSummaries()) { - if (validEvent.uid().equals(importSummary.reference())) { - assertEvent(importSummary, SUCCESS); - } - else if (invalidEvent.uid().equals(importSummary.reference())) { - assertEvent(importSummary, ERROR); - } - } - - // Check server status - Event serverValidEvent = apiCallExecutor.executeObjectCall(eventService.getEvent(validEvent.uid(), EventFields.allFields, ouMode)); - - assertThat(serverValidEvent).isNotNull(); - - try { - apiCallExecutor.executeObjectCall(eventService.getEvent(invalidEvent.uid(), EventFields.allFields, ouMode)); - Assert.fail("Should not reach that line"); - } catch (D2Error e) { - assertThat(e.httpErrorCode()).isEqualTo(404); - } - } - - //@Test - public void event_with_invalid_data_values() throws Exception { - login(); - - Event validEvent = createValidEvent(); - - Event invalidEvent = createEventWithInvalidDataValues(); - - EventPayload payload = new EventPayload(); - payload.events = Arrays.asList(validEvent, invalidEvent); - - EventWebResponse response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes(eventService - .postEvents(payload, this.strategy), Collections.singletonList(409), EventWebResponse.class); - - assertThat(response.response().status()).isEqualTo(WARNING); - - for (EventImportSummary importSummary : response.response().importSummaries()) { - if (validEvent.uid().equals(importSummary.reference())) { - assertEvent(importSummary, SUCCESS); - } - else if (invalidEvent.uid().equals(importSummary.reference())) { - assertEvent(importSummary, WARNING); - } - } - - // Check server status - Event serverValidEvent = apiCallExecutor.executeObjectCall(eventService.getEvent(validEvent.uid(), - EventFields.allFields, ouMode)); - Event serverInvalidEvent = apiCallExecutor.executeObjectCall(eventService.getEvent(invalidEvent.uid(), - EventFields.allFields, ouMode)); - - assertThat(serverValidEvent).isNotNull(); - assertThat(serverValidEvent.trackedEntityDataValues().size()).isEqualTo(2); - - assertThat(serverInvalidEvent).isNotNull(); - assertThat(serverInvalidEvent.trackedEntityDataValues()).isNull(); - } - - private void login() { - d2.userModule().logIn(username, password, url).blockingGet(); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPIRealShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPIRealShould.kt new file mode 100644 index 0000000000..96049a80c3 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventAPIRealShould.kt @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event.internal + +import com.google.common.truth.Truth.assertThat +import java.util.* +import org.hisp.dhis.android.core.BaseRealIntegrationTest +import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutor +import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutorImpl +import org.hisp.dhis.android.core.imports.ImportStatus +import org.hisp.dhis.android.core.imports.internal.EventWebResponse +import org.hisp.dhis.android.core.maintenance.D2Error +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode +import org.junit.Assert +import org.junit.Before + +abstract class EventAPIRealShould internal constructor( + // API version dependant parameters + private val serverUrl: String, + private val strategy: String +) : BaseRealIntegrationTest() { + private val ouMode = OrganisationUnitMode.ACCESSIBLE.name + private lateinit var apiCallExecutor: APICallExecutor + private lateinit var eventService: EventService + + @Before + override fun setUp() { + super.setUp() + apiCallExecutor = APICallExecutorImpl.create(d2.databaseAdapter(), null) + eventService = d2.retrofit().create(EventService::class.java) + } + + // @Test + @Throws(Exception::class) + fun valid_events() { + login() + val validEvent1 = EventUtils.createValidEvent() + val validEvent2 = EventUtils.createValidEvent() + val payload = EventPayload() + payload.events = listOf(validEvent1, validEvent2) + val response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes( + eventService + .postEvents(payload, strategy), + listOf(409), EventWebResponse::class.java + ) + assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS) + for (importSummary in response.response()!!.importSummaries()!!) { + if (validEvent1.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.SUCCESS) + } else if (validEvent2.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.SUCCESS) + } + } + + // Check server status + val serverValidEvent1 = apiCallExecutor.executeObjectCall( + eventService.getEvent(validEvent1.uid(), EventFields.allFields, ouMode) + ) + val serverValidEvent2 = apiCallExecutor.executeObjectCall( + eventService.getEvent(validEvent2.uid(), EventFields.allFields, ouMode) + ) + assertThat(serverValidEvent1).isNotNull() + assertThat(serverValidEvent2).isNotNull() + } + + // @Test + @Throws(Exception::class) + fun event_with_invalid_orgunit() { + login() + val validEvent = EventUtils.createValidEvent() + val invalidEvent = EventUtils.createEventWithInvalidOrgunit() + val payload = EventPayload() + payload.events = listOf(validEvent, invalidEvent) + val response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes( + eventService + .postEvents(payload, strategy), + listOf(409), EventWebResponse::class.java + ) + assertThat(response.response()!!.status()).isEqualTo(ImportStatus.ERROR) + for (importSummary in response.response()!!.importSummaries()!!) { + if (validEvent.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.SUCCESS) + } else if (invalidEvent.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.ERROR) + } + } + + // Check server status + val serverValidEvent = apiCallExecutor.executeObjectCall( + eventService.getEvent(validEvent.uid(), EventFields.allFields, ouMode) + ) + assertThat(serverValidEvent).isNotNull() + try { + apiCallExecutor.executeObjectCall( + eventService.getEvent( + invalidEvent.uid(), + EventFields.allFields, + ouMode + ) + ) + Assert.fail("Should not reach that line") + } catch (e: D2Error) { + assertThat(e.httpErrorCode()).isEqualTo(404) + } + } + + // @Test + @Throws(Exception::class) + fun event_with_invalid_attribute_option_combo() { + login() + val validEvent = EventUtils.createValidEvent() + val invalidEvent = EventUtils.createEventWithInvalidAttributeOptionCombo() + val payload = EventPayload() + payload.events = listOf(validEvent, invalidEvent) + val response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes( + eventService + .postEvents(payload, strategy), + listOf(409), EventWebResponse::class.java + ) + assertThat(response.response()!!.status()).isEqualTo(ImportStatus.ERROR) + for (importSummary in response.response()!!.importSummaries()!!) { + if (validEvent.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.SUCCESS) + } else if (invalidEvent.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.ERROR) + } + } + + // Check server status + val serverValidEvent = apiCallExecutor.executeObjectCall( + eventService.getEvent(validEvent.uid(), EventFields.allFields, ouMode) + ) + assertThat(serverValidEvent).isNotNull() + try { + apiCallExecutor.executeObjectCall( + eventService.getEvent( + invalidEvent.uid(), + EventFields.allFields, + ouMode + ) + ) + Assert.fail("Should not reach that line") + } catch (e: D2Error) { + assertThat(e.httpErrorCode()).isEqualTo(404) + } + } + + // @Test + @Throws(Exception::class) + fun event_with_future_date_does_not_fail() { + login() + val validEvent1 = EventUtils.createValidEvent() + val validEvent2 = EventUtils.createEventWithFutureDate() + val payload = EventPayload() + payload.events = listOf(validEvent1, validEvent2) + val response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes( + eventService + .postEvents(payload, strategy), + listOf(409), EventWebResponse::class.java + ) + assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS) + for (importSummary in response.response()!!.importSummaries()!!) { + if (validEvent1.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.SUCCESS) + } else if (validEvent2.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.SUCCESS) + } + } + + // Check server status + val serverValidEvent1 = apiCallExecutor.executeObjectCall( + eventService.getEvent(validEvent1.uid(), EventFields.allFields, ouMode) + ) + val serverValidEvent2 = apiCallExecutor.executeObjectCall( + eventService.getEvent(validEvent2.uid(), EventFields.allFields, ouMode) + ) + assertThat(serverValidEvent1).isNotNull() + assertThat(serverValidEvent2).isNotNull() + } + + // @Test + @Throws(Exception::class) + fun event_with_invalid_program() { + login() + val validEvent = EventUtils.createValidEvent() + val invalidEvent = EventUtils.createEventWithInvalidProgram() + val payload = EventPayload() + payload.events = listOf(validEvent, invalidEvent) + val response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes( + eventService + .postEvents(payload, strategy), + listOf(409), EventWebResponse::class.java + ) + assertThat(response.response()!!.status()).isEqualTo(ImportStatus.ERROR) + for (importSummary in response.response()!!.importSummaries()!!) { + if (validEvent.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.SUCCESS) + } else if (invalidEvent.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.ERROR) + } + } + + // Check server status + val serverValidEvent = apiCallExecutor.executeObjectCall( + eventService.getEvent(validEvent.uid(), EventFields.allFields, ouMode) + ) + assertThat(serverValidEvent).isNotNull() + try { + apiCallExecutor.executeObjectCall( + eventService.getEvent( + invalidEvent.uid(), + EventFields.allFields, + ouMode + ) + ) + Assert.fail("Should not reach that line") + } catch (e: D2Error) { + assertThat(e.httpErrorCode()).isEqualTo(404) + } + } + + // @Test + @Throws(Exception::class) + fun event_with_invalid_data_values() { + login() + val validEvent = EventUtils.createValidEvent() + val invalidEvent = EventUtils.createEventWithInvalidDataValues() + val payload = EventPayload() + payload.events = listOf(validEvent, invalidEvent) + val response = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes( + eventService + .postEvents(payload, strategy), + listOf(409), EventWebResponse::class.java + ) + assertThat(response.response()!!.status()).isEqualTo(ImportStatus.WARNING) + for (importSummary in response.response()!!.importSummaries()!!) { + if (validEvent.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.SUCCESS) + } else if (invalidEvent.uid() == importSummary.reference()) { + EventUtils.assertEvent(importSummary, ImportStatus.WARNING) + } + } + + // Check server status + val serverValidEvent = apiCallExecutor.executeObjectCall( + eventService.getEvent( + validEvent.uid(), + EventFields.allFields, ouMode + ) + ) + val serverInvalidEvent = apiCallExecutor.executeObjectCall( + eventService.getEvent( + invalidEvent.uid(), + EventFields.allFields, ouMode + ) + ) + assertThat(serverValidEvent).isNotNull() + assertThat(serverValidEvent.trackedEntityDataValues()!!.size).isEqualTo(2) + assertThat(serverInvalidEvent).isNotNull() + assertThat(serverInvalidEvent.trackedEntityDataValues()).isNull() + } + + private fun login() { + d2.userModule().logIn(username, password, url).blockingGet() + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventCallFactory.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventCallFactory.kt index 2f075babdd..9cc514754b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventCallFactory.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventCallFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,9 +27,8 @@ */ package org.hisp.dhis.android.core.event.internal -import java.util.concurrent.Callable -import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutorImpl -import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter +import io.reactivex.Single +import org.hisp.dhis.android.core.arch.api.payload.internal.Payload import org.hisp.dhis.android.core.event.Event import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode import org.hisp.dhis.android.core.trackedentity.internal.TrackerQueryCommonParams @@ -40,12 +39,10 @@ object EventCallFactory { @JvmStatic fun create( retrofit: Retrofit, - databaseAdapter: DatabaseAdapter, orgUnit: String?, pageSize: Int, uids: Collection = emptyList() - - ): Callable> { + ): Single> { val eventQuery = TrackerAPIQuery( commonParams = TrackerQueryCommonParams( @@ -63,9 +60,8 @@ object EventCallFactory { uids = uids ) - return EventEndpointCallFactory( - retrofit.create(EventService::class.java), - APICallExecutorImpl.create(databaseAdapter, null) - ).getCall(eventQuery) + return OldEventEndpointCallFactory( + retrofit.create(EventService::class.java) + ).getCollectionCall(eventQuery) } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDataFilterStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDataFilterStoreIntegrationShould.kt index a552d3a41f..d718c5e876 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDataFilterStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDataFilterStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDownloadCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDownloadCallMockIntegrationShould.kt index aac586af96..e8ecbf9ece 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDownloadCallMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDownloadCallMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDownloadRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDownloadRealIntegrationShould.java index 57b0856744..04308dfaa2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDownloadRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventDownloadRealIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallBaseMockIntegrationShould.kt similarity index 75% rename from core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallMockIntegrationShould.kt rename to core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallBaseMockIntegrationShould.kt index a14d92701e..32613d0827 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallBaseMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,34 +30,52 @@ package org.hisp.dhis.android.core.event.internal import com.google.common.truth.Truth.assertThat import org.hisp.dhis.android.core.common.State import org.hisp.dhis.android.core.event.EventStatus -import org.hisp.dhis.android.core.maintenance.D2Error +import org.hisp.dhis.android.core.settings.SynchronizationSettings +import org.hisp.dhis.android.core.settings.internal.SynchronizationSettingStore +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestMetadataEnqueable -import org.hisp.dhis.android.core.utils.runner.D2JunitRunner import org.junit.After +import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -@RunWith(D2JunitRunner::class) -class EventEndpointCallMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueable() { +abstract class EventEndpointCallBaseMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueable() { + + abstract val importerVersion: TrackerImporterVersion + abstract val exporterVersion: TrackerExporterVersion + abstract val events1File: String + abstract val eventsFirstGoodSecondWrongFKFile: String + abstract val eventsWithUids: String + + private lateinit var initSyncParams: SynchronizationSettings + private val syncStore = SynchronizationSettingStore.create(databaseAdapter) + + @Before + fun setUp() { + initSyncParams = syncStore.selectFirst()!! + val testParams = initSyncParams.toBuilder().trackerImporterVersion(importerVersion) + .trackerExporterVersion(exporterVersion).build() + syncStore.delete() + syncStore.insert(testParams) + } @After - @Throws(D2Error::class) fun tearDown() { d2.wipeModule().wipeData() + syncStore.delete() + syncStore.insert(initSyncParams) } @Test - @Throws(Exception::class) fun download_number_of_events_according_to_page_default_query() { - enqueue("event/events_1.json") + enqueue(events1File) d2.eventModule().eventDownloader().blockingDownload() assertThat(d2.eventModule().events().blockingCount()).isEqualTo(1) } @Test - @Throws(Exception::class) fun rollback_transaction_when_insert_a_event_with_wrong_foreign_key() { - enqueue("event/two_events_first_good_second_wrong_foreign_key.json") + enqueue(eventsFirstGoodSecondWrongFKFile) d2.eventModule().eventDownloader().blockingDownload() assertThat(d2.eventModule().events().blockingCount()).isEqualTo(0) assertThat(d2.trackedEntityModule().trackedEntityDataValues().blockingCount()) @@ -65,16 +83,14 @@ class EventEndpointCallMockIntegrationShould : BaseMockIntegrationTestMetadataEn } @Test - @Throws(Exception::class) fun download_events_by_uid() { - enqueue("event/events_with_uids.json") + enqueue(eventsWithUids) d2.eventModule().eventDownloader().byUid().`in`("wAiGPfJGMxt", "PpNGhvEYnXe").blockingDownload() assertThat(d2.eventModule().events().blockingCount()).isEqualTo(2) } - @Throws(Exception::class) private fun checkOverwrite(state: State, finalStatus: EventStatus) { - enqueue("event/events_1.json") + enqueue(events1File) d2.eventModule().eventDownloader().blockingDownload() val events = d2.eventModule().events().blockingGet() @@ -88,7 +104,7 @@ class EventEndpointCallMockIntegrationShould : BaseMockIntegrationTestMetadataEn .status(EventStatus.SKIPPED).build() ) - enqueue("event/events_1.json") + enqueue(events1File) d2.eventModule().eventDownloader().blockingDownload() val event1 = d2.eventModule().events().one().blockingGet() @@ -97,25 +113,21 @@ class EventEndpointCallMockIntegrationShould : BaseMockIntegrationTestMetadataEn } @Test - @Throws(Exception::class) fun overwrite_when_state_sync() { checkOverwrite(State.SYNCED, EventStatus.COMPLETED) } @Test - @Throws(Exception::class) fun not_overwrite_when_state_to_post() { checkOverwrite(State.TO_POST, EventStatus.SKIPPED) } @Test - @Throws(Exception::class) fun not_overwrite_when_state_error() { checkOverwrite(State.ERROR, EventStatus.SKIPPED) } @Test - @Throws(Exception::class) fun not_overwrite_when_state_to_update() { checkOverwrite(State.TO_UPDATE, EventStatus.SKIPPED) } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallNewMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallNewMockIntegrationShould.kt new file mode 100644 index 0000000000..29816aa6ed --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallNewMockIntegrationShould.kt @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event.internal + +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class EventEndpointCallNewMockIntegrationShould : EventEndpointCallBaseMockIntegrationShould() { + + override val importerVersion: TrackerImporterVersion = TrackerImporterVersion.V2 + override val exporterVersion = TrackerExporterVersion.V2 + override val events1File: String = "event/new_tracker_importer_events_1.json" + override val eventsFirstGoodSecondWrongFKFile: String = + "event/new_tracker_importer_two_events_first_good_second_wrong_foreign_key.json" + override val eventsWithUids: String = "event/new_tracker_importer_events_with_uids.json" +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallOldMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallOldMockIntegrationShould.kt new file mode 100644 index 0000000000..f09287ee50 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallOldMockIntegrationShould.kt @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event.internal + +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class EventEndpointCallOldMockIntegrationShould : EventEndpointCallBaseMockIntegrationShould() { + + override val importerVersion: TrackerImporterVersion = TrackerImporterVersion.V1 + override val exporterVersion = TrackerExporterVersion.V1 + override val events1File: String = "event/events_1.json" + override val eventsFirstGoodSecondWrongFKFile: String = "event/two_events_first_good_second_wrong_foreign_key.json" + override val eventsWithUids: String = "event/events_with_uids.json" +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallRealIntegrationShould.java deleted file mode 100644 index a31e652a93..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallRealIntegrationShould.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.event.internal; - -import static com.google.common.truth.Truth.assertThat; - -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.event.Event; -import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStore; -import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStoreImpl; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Callable; - -public class EventEndpointCallRealIntegrationShould extends BaseRealIntegrationTest { - - //This test is commented because technically it is flaky. - //It depends on a live server to operate and the login is hardcoded here. - //Uncomment in order to quickly test changes vs a real server, but keep it uncommented after. - //@Test - public void download_number_of_events_according_to_default_limit() throws Exception { - d2.userModule().logIn(username, password, url).blockingGet(); - - d2.metadataModule().blockingDownload(); - - Callable> eventEndpointCall = EventCallFactory.create(d2.retrofit(), d2.databaseAdapter(), "DiszpKrYNg8", 0, Collections.emptyList()); - - List events = eventEndpointCall.call(); - assertThat(events.isEmpty()).isFalse(); - - //TODO: we should create dependant server data verifications in other test suite - /* verifyNumberOfDownloadedEvents(49); - verifyNumberOfDownloadedTrackedEntityDataValue(335);*/ - } - - - //@Test - public void download_event_with_category_combo_option() throws Exception { - d2.userModule().logIn(username, password, url).blockingGet(); - - d2.metadataModule().blockingDownload(); - - Callable> eventEndpointCall = EventCallFactory.create(d2.retrofit(), d2.databaseAdapter(), "DiszpKrYNg8", 0, Collections.emptyList()); - - eventEndpointCall.call(); - - assertThat(verifyAtLeastOneEventWithOptionCombo()).isTrue(); - } - - private boolean verifyAtLeastOneEventWithOptionCombo() { - EventStore eventStore = EventStoreImpl.create(d2.databaseAdapter()); - - List downloadedEvents = eventStore.querySingleEvents(); - for (Event event : downloadedEvents) { - if (event.attributeOptionCombo() != null) { - return true; - } - } - return false; - } - - private void verifyNumberOfDownloadedEvents(int numEvents) { - EventStore eventStore = EventStoreImpl.create(d2.databaseAdapter()); - - List downloadedEvents = eventStore.querySingleEvents(); - - assertThat(downloadedEvents.size()).isEqualTo(numEvents); - } - - private void verifyNumberOfDownloadedTrackedEntityDataValue(int num) { - TrackedEntityDataValueStore trackedEntityDataValueStore = TrackedEntityDataValueStoreImpl.create(d2.databaseAdapter()); - - int numPersisted = trackedEntityDataValueStore.selectAll().size(); - - assertThat(numPersisted).isEqualTo(num); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallRealIntegrationShould.kt new file mode 100644 index 0000000000..077c9381b4 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventEndpointCallRealIntegrationShould.kt @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event.internal + +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.BaseRealIntegrationTest +import org.hisp.dhis.android.core.event.internal.EventCallFactory.create +import org.hisp.dhis.android.core.event.internal.EventStoreImpl.Companion.create +import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStoreImpl + +class EventEndpointCallRealIntegrationShould : BaseRealIntegrationTest() { + // This test is commented because technically it is flaky. + // It depends on a live server to operate and the login is hardcoded here. + // Uncomment in order to quickly test changes vs a real server, but keep it uncommented after. + // @Test + @Throws(Exception::class) + fun download_number_of_events_according_to_default_limit() { + d2.userModule().logIn(username, password, url).blockingGet() + d2.metadataModule().blockingDownload() + val eventEndpointCall = create(d2.retrofit(), "DiszpKrYNg8", 0, emptyList()) + val events = eventEndpointCall.blockingGet().items() + + assertThat(events.isEmpty()).isFalse() + + // TODO: we should create dependant server data verifications in other test suite + /* verifyNumberOfDownloadedEvents(49); + verifyNumberOfDownloadedTrackedEntityDataValue(335); + */ + } + + // @Test + @Throws(Exception::class) + fun download_event_with_category_combo_option() { + d2.userModule().logIn(username, password, url).blockingGet() + d2.metadataModule().blockingDownload() + val eventEndpointCall = create(d2.retrofit(), "DiszpKrYNg8", 0, emptyList()) + eventEndpointCall.blockingGet() + + assertThat(verifyAtLeastOneEventWithOptionCombo()).isTrue() + } + + private fun verifyAtLeastOneEventWithOptionCombo(): Boolean { + val eventStore = create(d2.databaseAdapter()) + val downloadedEvents = eventStore.querySingleEvents() + return downloadedEvents.any { it.attributeOptionCombo() != null } + } + + private fun verifyNumberOfDownloadedEvents(numEvents: Int) { + val eventStore = create(d2.databaseAdapter()) + val downloadedEvents = eventStore.querySingleEvents() + + assertThat(downloadedEvents.size).isEqualTo(numEvents) + } + + private fun verifyNumberOfDownloadedTrackedEntityDataValue(num: Int) { + val trackedEntityDataValueStore = TrackedEntityDataValueStoreImpl.create(d2.databaseAdapter()) + val numPersisted = trackedEntityDataValueStore.selectAll().size + + assertThat(numPersisted).isEqualTo(num) + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventFilterStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventFilterStoreIntegrationShould.kt index 03aa1c0085..47448d85f0 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventFilterStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventFilterStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostPayloadGeneratorMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostBaseMockIntegrationShould.kt similarity index 63% rename from core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostPayloadGeneratorMockIntegrationShould.kt rename to core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostBaseMockIntegrationShould.kt index 09d1bc51c3..ad9fcbc2ea 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostPayloadGeneratorMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostBaseMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,49 +28,55 @@ package org.hisp.dhis.android.core.event.internal import com.google.common.truth.Truth.assertThat -import org.hisp.dhis.android.core.arch.helpers.UidsHelper.getUidsList import org.hisp.dhis.android.core.common.State -import org.hisp.dhis.android.core.common.State.Companion.uploadableStatesIncludingError import org.hisp.dhis.android.core.data.trackedentity.TrackedEntityDataValueSamples import org.hisp.dhis.android.core.event.Event import org.hisp.dhis.android.core.event.internal.EventStoreImpl.Companion.create -import org.hisp.dhis.android.core.note.Note -import org.hisp.dhis.android.core.note.NoteCreateProjection -import org.hisp.dhis.android.core.program.Program +import org.hisp.dhis.android.core.settings.SynchronizationSettings +import org.hisp.dhis.android.core.settings.internal.SynchronizationSettingStore import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStoreImpl +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestMetadataEnqueable -import org.hisp.dhis.android.core.utils.runner.D2JunitRunner import org.junit.After +import org.junit.Before import org.junit.BeforeClass import org.junit.Test -import org.junit.runner.RunWith -@RunWith(D2JunitRunner::class) -class EventPostPayloadGeneratorMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueable() { +abstract class EventPostBaseMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueable() { + abstract val importerVersion: TrackerImporterVersion + abstract val exporterVersion: TrackerExporterVersion + abstract val importConflictsFile1: List + abstract val importConflictsFile2: List + private val event1Id = "event1Id" private val event2Id = "event2Id" private val event3Id = "event3Id" private val event4Id = "event4Id" + private lateinit var initSyncParams: SynchronizationSettings + private val syncStore = SynchronizationSettingStore.create(databaseAdapter) + + @Before + fun setUp() { + initSyncParams = syncStore.selectFirst()!! + val testParams = initSyncParams.toBuilder().trackerImporterVersion(importerVersion) + .trackerExporterVersion(exporterVersion).build() + syncStore.delete() + syncStore.insert(testParams) + } + @After fun tearDown() { d2.wipeModule().wipeData() - } - - @Test - fun build_payload_with_different_enrollments() { - storeEvents() - val events = payloadGenerator.getEvents(eventStore.querySingleEventsToPost()) - assertThat(events.size).isEqualTo(4) - for (event in events) { - assertThat(event.trackedEntityDataValues()!!.size).isEqualTo(1) - } + syncStore.delete() + syncStore.insert(initSyncParams) } @Test fun handle_import_conflicts_correctly() { storeEvents() - dhis2MockServer.enqueueMockResponse("imports/web_response_with_event_import_conflicts.json") + importConflictsFile1.forEach { dhis2MockServer.enqueueMockResponse(it) } d2.eventModule().events().blockingUpload() assertThat(d2.importModule().trackerImportConflicts().blockingCount()).isEqualTo(3) } @@ -78,7 +84,7 @@ class EventPostPayloadGeneratorMockIntegrationShould : BaseMockIntegrationTestMe @Test fun delete_old_import_conflicts() { storeEvents() - dhis2MockServer.enqueueMockResponse("imports/web_response_with_event_import_conflicts.json") + importConflictsFile1.forEach { dhis2MockServer.enqueueMockResponse(it) } d2.eventModule().events().blockingUpload() assertThat(d2.importModule().trackerImportConflicts().blockingCount()).isEqualTo(3) @@ -89,7 +95,7 @@ class EventPostPayloadGeneratorMockIntegrationShould : BaseMockIntegrationTestMe eventStore.setAggregatedSyncState(event2Id, State.TO_POST) eventStore.setAggregatedSyncState(event3Id, State.TO_POST) - dhis2MockServer.enqueueMockResponse("imports/web_response_with_event_import_conflicts2.json") + importConflictsFile2.forEach { dhis2MockServer.enqueueMockResponse(it) } d2.eventModule().events().blockingUpload() assertThat(d2.importModule().trackerImportConflicts().blockingCount()).isEqualTo(2) } @@ -100,54 +106,12 @@ class EventPostPayloadGeneratorMockIntegrationShould : BaseMockIntegrationTestMe assertThat(d2.eventModule().events().blockingCount()).isEqualTo(4) d2.eventModule().events().uid("event1Id").blockingDelete() - dhis2MockServer.enqueueMockResponse("imports/web_response_with_event_import_conflicts2.json") + importConflictsFile2.forEach { dhis2MockServer.enqueueMockResponse(it) } d2.eventModule().events().blockingUpload() assertThat(d2.eventModule().events().blockingCount()).isEqualTo(3) } - @Test - fun recreate_events_with_filters() { - val event1 = "event1" - val event2 = "event2" - val event3 = "event3" - val event4 = "event4" - val program = d2.programModule().programs().one().blockingGet() - - storeSingleEvent(event1, program, State.TO_POST, false) - storeSingleEvent(event2, program, State.TO_UPDATE, false) - storeSingleEvent(event3, program, State.TO_UPDATE, true) - storeSingleEvent(event4, program, State.SYNCED, false) - - val events = payloadGenerator.getEvents( - d2.eventModule().events().byProgramUid().eq(program.uid()) - .bySyncState().`in`(*uploadableStatesIncludingError()).blockingGet() - ) - - assertThat(events.size).isEqualTo(3) - assertThat(getUidsList(events).containsAll(listOf(event1, event2, event3))).isTrue() - } - - @Test - fun build_payload_with_event_notes() { - storeEvents() - d2.noteModule().notes().blockingAdd( - NoteCreateProjection.builder() - .event(event1Id) - .noteType(Note.NoteType.EVENT_NOTE) - .value("This is an event note") - .build() - ) - val events = payloadGenerator.getEvents(eventStore.querySingleEventsToPost()) - for (event in events) { - if (event1Id == event.uid()) { - assertThat(event.notes()!!.size).isEqualTo(1) - } else { - assertThat(event.notes()!!.size).isEqualTo(0) - } - } - } - private fun storeEvents() { val orgUnit = d2.organisationUnitModule().organisationUnits().one().blockingGet() val program = d2.programModule().programs().one().blockingGet() @@ -214,35 +178,16 @@ class EventPostPayloadGeneratorMockIntegrationShould : BaseMockIntegrationTestMe assertThat(d2.eventModule().events().blockingCount()).isEqualTo(4) } - private fun storeSingleEvent(eventUid: String, program: Program, state: State, deleted: Boolean) { - val orgUnit = d2.organisationUnitModule().organisationUnits().one().blockingGet() - val programStage = d2.programModule().programStages().one().blockingGet() - eventStore.insert( - Event.builder() - .uid(eventUid) - .organisationUnit(orgUnit.uid()) - .program(program.uid()) - .programStage(programStage.uid()) - .syncState(state) - .aggregatedSyncState(state) - .deleted(deleted) - .build() - ) - } - companion object { - private lateinit var payloadGenerator: EventPostPayloadGenerator private lateinit var eventStore: EventStore @BeforeClass @JvmStatic - @Throws(Exception::class) fun setUpClass() { BaseMockIntegrationTestMetadataEnqueable.setUpClass() eventStore = create( objects.databaseAdapter ) - payloadGenerator = objects.d2DIComponent.eventPostPayloadGenerator() } } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostCallRealIntegrationShould.java deleted file mode 100644 index 256de00a47..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostCallRealIntegrationShould.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.event.internal; - -import static com.google.common.truth.Truth.assertThat; - -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.arch.helpers.UidGenerator; -import org.hisp.dhis.android.core.arch.helpers.UidGeneratorImpl; -import org.hisp.dhis.android.core.common.State; -import org.hisp.dhis.android.core.event.Event; -import org.hisp.dhis.android.core.event.EventCreateProjection; -import org.hisp.dhis.android.core.event.EventObjectRepository; -import org.hisp.dhis.android.core.event.EventStatus; -import org.hisp.dhis.android.core.program.ProgramType; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue; -import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStore; -import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStoreImpl; -import org.junit.Before; - -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.concurrent.Callable; - -public class EventPostCallRealIntegrationShould extends BaseRealIntegrationTest { - - private EventStore eventStore; - private TrackedEntityDataValueStore trackedEntityDataValueStore; - - private String eventUid1; - private String eventUid2; - private String orgUnitUid; - private String programUid; - private String programStageUid; - private String dataElementUid; - private String attributeOptionCombo; - - @Override - @Before - public void setUp() { - super.setUp(); - eventStore = EventStoreImpl.create(d2.databaseAdapter()); - trackedEntityDataValueStore = TrackedEntityDataValueStoreImpl.create(d2.databaseAdapter()); - - UidGenerator uidGenerator = new UidGeneratorImpl(); - - eventUid1 = uidGenerator.generate(); - eventUid2 = uidGenerator.generate(); - } - - // commented out since it is a flaky test that works against a real server. - //@Test - public void successful_response_after_sync_events() throws Exception { - downloadMetadata(); - - createDummyDataToPost(eventUid1); - - d2.eventModule().events().blockingUpload(); - } - - //@Test - public void create_event_with_repository() throws Exception { - downloadMetadata(); - - String eventUid = d2.eventModule().events().blockingAdd( - EventCreateProjection.builder() - .organisationUnit(orgUnitUid) - .program(programUid) - .programStage(programStageUid) - .attributeOptionCombo(attributeOptionCombo) - .build() - ); - - EventObjectRepository repo = d2.eventModule().events().uid(eventUid); - - repo.setEventDate(new Date()); - - d2.eventModule().events().blockingUpload(); - } - - - - // commented out since it is a flaky test that works against a real server. - //@Test - public void pull_event_with_correct_category_combo_after_be_pushed() throws Exception { - downloadMetadata(); - - createDummyDataToPost(eventUid1); - - pushDummyEvent(); - - Event pushedEvent = getEventFromDB(); - - d2.wipeModule().wipeEverything(); - - downloadMetadata(); - - downloadEvents(); - - assertThatEventPushedIsDownloaded(pushedEvent); - } - - //@Test - public void pull_events_delete_with_repository_and_post() throws Exception { - downloadMetadata(); - - d2.eventModule().eventDownloader().limit(10).blockingDownload(); - - String uid = d2.eventModule().events().one().blockingGet().uid(); - - d2.eventModule().events().uid(uid).blockingDelete(); - - d2.eventModule().events().blockingUpload(); - } - - // commented out since it is a flaky test that works against a real server. - //@Test - public void pull_two_events_with_correct_category_combo_after_be_pushed() throws Exception { - downloadMetadata(); - - createDummyDataToPost(eventUid1); - - createDummyDataToPost(eventUid2); - - pushDummyEvent(); - - Event pushedEvent = getEventFromDB(); - - d2.wipeModule().wipeEverything(); - - downloadMetadata(); - - downloadEvents(); - - assertThatEventPushedIsDownloaded(pushedEvent); - } - - private void createDummyDataToPost(String eventUid) { - eventStore.insert(Event.builder().uid(eventUid).created(new Date()).lastUpdated(new Date()) - .status(EventStatus.ACTIVE).program(programUid) - .programStage(programStageUid).organisationUnit(orgUnitUid).eventDate(new Date()) - .completedDate(new Date()).dueDate(new Date()).syncState(State.TO_POST) - .attributeOptionCombo(attributeOptionCombo).build()); - - TrackedEntityDataValue trackedEntityDataValue = TrackedEntityDataValue.builder() - .event(eventUid) - .created(new Date()) - .lastUpdated(new Date()) - .dataElement(dataElementUid) - .storedBy("user_name") - .value("12") - .providedElsewhere(Boolean.FALSE) - .build(); - - trackedEntityDataValueStore.insert(trackedEntityDataValue); - } - - private void assertThatEventPushedIsDownloaded(Event pushedEvent) { - List downloadedEvents = eventStore.querySingleEvents(); - - assertThat(verifyPushedEventIsInPullList(pushedEvent, downloadedEvents)).isTrue(); - } - - private void downloadEvents() throws Exception { - Callable> eventEndpointCall = EventCallFactory.create( - d2.retrofit(), d2.databaseAdapter(), orgUnitUid, 50, Collections.emptyList()); - - List events = eventEndpointCall.call(); - - for (Event event : events) { - eventStore.insert(event); - } - - assertThat(events.isEmpty()).isFalse(); - } - - private Event getEventFromDB() { - Event event = null; - List storedEvents = eventStore.selectAll(); - for (Event storedEvent : storedEvents) { - if (storedEvent.uid().equals(eventUid1)) { - event = storedEvent; - } - } - return event; - } - - private void pushDummyEvent() { - d2.eventModule().events().blockingUpload(); - } - - private void downloadMetadata() { - d2.userModule().logIn(username, password, url).blockingGet(); - d2.metadataModule().blockingDownload(); - - orgUnitUid = d2.organisationUnitModule().organisationUnits() - .one().blockingGet() - .uid(); - programUid = d2.programModule().programs() - .byOrganisationUnitUid(orgUnitUid) - .byProgramType().eq(ProgramType.WITHOUT_REGISTRATION) - .one().blockingGet() - .uid(); - // Before running, make sure no data elements are compulsory - programStageUid = d2.programModule().programStages() - .byProgramUid().eq(programUid) - .one().blockingGet() - .uid(); - dataElementUid = d2.programModule().programStageDataElements() - .byProgramStage().eq(programStageUid) - .one().blockingGet().dataElement() - .uid(); - attributeOptionCombo = d2.categoryModule().categoryOptionCombos() - .one().blockingGet() - .uid(); - } - - private boolean verifyPushedEventIsInPullList(Event event, List eventList) { - for (Event pullEvent : eventList) { - if (event.uid().equals(pullEvent.uid()) && - event.attributeOptionCombo().equals(pullEvent.attributeOptionCombo())) { - return true; - } - } - return false; - } -} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostCallRealIntegrationShould.kt new file mode 100644 index 0000000000..1c2704302b --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostCallRealIntegrationShould.kt @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event.internal + +import com.google.common.truth.Truth +import com.google.common.truth.Truth.assertThat +import java.util.* +import org.hisp.dhis.android.core.BaseRealIntegrationTest +import org.hisp.dhis.android.core.arch.helpers.UidGenerator +import org.hisp.dhis.android.core.arch.helpers.UidGeneratorImpl +import org.hisp.dhis.android.core.common.State +import org.hisp.dhis.android.core.event.Event +import org.hisp.dhis.android.core.event.EventCreateProjection +import org.hisp.dhis.android.core.event.EventStatus +import org.hisp.dhis.android.core.event.internal.EventStoreImpl.Companion.create +import org.hisp.dhis.android.core.program.ProgramType +import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue +import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStore +import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStoreImpl +import org.junit.Before + +class EventPostCallRealIntegrationShould : BaseRealIntegrationTest() { + private lateinit var eventStore: EventStore + private lateinit var trackedEntityDataValueStore: TrackedEntityDataValueStore + private lateinit var eventUid1: String + private lateinit var eventUid2: String + + private var orgUnitUid: String? = null + private var programUid: String? = null + private var programStageUid: String? = null + private var dataElementUid: String? = null + private var attributeOptionCombo: String? = null + + @Before + override fun setUp() { + super.setUp() + eventStore = create(d2.databaseAdapter()) + trackedEntityDataValueStore = TrackedEntityDataValueStoreImpl.create(d2.databaseAdapter()) + val uidGenerator: UidGenerator = UidGeneratorImpl() + eventUid1 = uidGenerator.generate() + eventUid2 = uidGenerator.generate() + } + + // commented out since it is a flaky test that works against a real server. + // @Test + @Throws(Exception::class) + fun successful_response_after_sync_events() { + downloadMetadata() + createDummyDataToPost(eventUid1) + d2.eventModule().events().blockingUpload() + } + + // @Test + @Throws(Exception::class) + fun create_event_with_repository() { + downloadMetadata() + val eventUid = d2.eventModule().events().blockingAdd( + EventCreateProjection.builder() + .organisationUnit(orgUnitUid) + .program(programUid) + .programStage(programStageUid) + .attributeOptionCombo(attributeOptionCombo) + .build() + ) + val repo = d2.eventModule().events().uid(eventUid) + repo.setEventDate(Date()) + d2.eventModule().events().blockingUpload() + } + + // commented out since it is a flaky test that works against a real server. + // @Test + @Throws(Exception::class) + fun pull_event_with_correct_category_combo_after_be_pushed() { + downloadMetadata() + createDummyDataToPost(eventUid1) + pushDummyEvent() + val pushedEvent = eventFromDB + d2.wipeModule().wipeEverything() + downloadMetadata() + downloadEvents() + assertThatEventPushedIsDownloaded(pushedEvent) + } + + // @Test + @Throws(Exception::class) + fun pull_events_delete_with_repository_and_post() { + downloadMetadata() + d2.eventModule().eventDownloader().limit(10).blockingDownload() + val uid = d2.eventModule().events().one().blockingGet().uid() + d2.eventModule().events().uid(uid).blockingDelete() + d2.eventModule().events().blockingUpload() + } + + // commented out since it is a flaky test that works against a real server. + // @Test + @Throws(Exception::class) + fun pull_two_events_with_correct_category_combo_after_be_pushed() { + downloadMetadata() + createDummyDataToPost(eventUid1) + createDummyDataToPost(eventUid2) + pushDummyEvent() + val pushedEvent = eventFromDB + d2.wipeModule().wipeEverything() + downloadMetadata() + downloadEvents() + assertThatEventPushedIsDownloaded(pushedEvent) + } + + private fun createDummyDataToPost(eventUid: String?) { + eventStore.insert( + Event.builder().uid(eventUid).created(Date()).lastUpdated(Date()) + .status(EventStatus.ACTIVE).program(programUid) + .programStage(programStageUid).organisationUnit(orgUnitUid).eventDate(Date()) + .completedDate(Date()).dueDate(Date()).syncState(State.TO_POST) + .attributeOptionCombo(attributeOptionCombo).build() + ) + val trackedEntityDataValue = TrackedEntityDataValue.builder() + .event(eventUid) + .created(Date()) + .lastUpdated(Date()) + .dataElement(dataElementUid) + .storedBy("user_name") + .value("12") + .providedElsewhere(java.lang.Boolean.FALSE) + .build() + trackedEntityDataValueStore.insert(trackedEntityDataValue) + } + + private fun assertThatEventPushedIsDownloaded(pushedEvent: Event?) { + val downloadedEvents = eventStore.querySingleEvents() + Truth.assertThat(verifyPushedEventIsInPullList(pushedEvent, downloadedEvents)).isTrue() + } + + @Throws(Exception::class) + private fun downloadEvents() { + val eventEndpointCall = EventCallFactory.create( + d2.retrofit(), orgUnitUid, 50, emptyList() + ) + val events = eventEndpointCall.blockingGet().items() + for (event in events) { + eventStore.insert(event) + } + assertThat(events.isEmpty()).isFalse() + } + + private val eventFromDB: Event? + private get() { + var event: Event? = null + val storedEvents = eventStore.selectAll() + for (storedEvent in storedEvents) { + if (storedEvent.uid() == eventUid1) { + event = storedEvent + } + } + return event + } + + private fun pushDummyEvent() { + d2.eventModule().events().blockingUpload() + } + + private fun downloadMetadata() { + d2.userModule().logIn(username, password, url).blockingGet() + d2.metadataModule().blockingDownload() + orgUnitUid = d2.organisationUnitModule().organisationUnits() + .one().blockingGet() + .uid() + programUid = d2.programModule().programs() + .byOrganisationUnitUid(orgUnitUid) + .byProgramType().eq(ProgramType.WITHOUT_REGISTRATION) + .one().blockingGet() + .uid() + + // Before running, make sure no data elements are compulsory + programStageUid = d2.programModule().programStages() + .byProgramUid().eq(programUid) + .one().blockingGet() + .uid() + dataElementUid = d2.programModule().programStageDataElements() + .byProgramStage().eq(programStageUid) + .one().blockingGet().dataElement() + ?.uid() + attributeOptionCombo = d2.categoryModule().categoryOptionCombos() + .one().blockingGet() + .uid() + } + + private fun verifyPushedEventIsInPullList(event: Event?, eventList: List): Boolean { + for (pullEvent in eventList) { + if (event!!.uid() == pullEvent.uid() && event.attributeOptionCombo() == pullEvent.attributeOptionCombo()) { + return true + } + } + return false + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostNewMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostNewMockIntegrationShould.kt new file mode 100644 index 0000000000..05183b9f22 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostNewMockIntegrationShould.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event.internal + +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class EventPostNewMockIntegrationShould : EventPostBaseMockIntegrationShould() { + override val importerVersion = TrackerImporterVersion.V2 + override val exporterVersion = TrackerExporterVersion.V2 + override val importConflictsFile1 = listOf( + "imports/tracker-importer/job_response.json", + "imports/web_response_with_event_import_conflicts_new.json" + ) + override val importConflictsFile2 = listOf( + "imports/tracker-importer/job_response.json", + "imports/web_response_with_event_import_conflicts2_new.json" + ) +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostOldMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostOldMockIntegrationShould.kt new file mode 100644 index 0000000000..f198d19508 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventPostOldMockIntegrationShould.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.event.internal + +import org.hisp.dhis.android.core.tracker.TrackerExporterVersion +import org.hisp.dhis.android.core.tracker.TrackerImporterVersion +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class EventPostOldMockIntegrationShould : EventPostBaseMockIntegrationShould() { + override val importerVersion = TrackerImporterVersion.V1 + override val exporterVersion = TrackerExporterVersion.V1 + override val importConflictsFile1 = listOf("imports/web_response_with_event_import_conflicts.json") + override val importConflictsFile2 = listOf("imports/web_response_with_event_import_conflicts2.json") +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventStoreIntegrationShould.java index f68310a8f0..f232ba0394 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventSyncStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventSyncStoreIntegrationShould.java index 931b6a3870..1424671a59 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventSyncStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventSyncStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventUtils.java index 1707318c47..2f90d188a4 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/BaseFileResourceRoutineIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/BaseFileResourceRoutineIntegrationShould.kt index f53fa8d1b8..ea927d025b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/BaseFileResourceRoutineIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/BaseFileResourceRoutineIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceCallRealIntegrationShould.kt index 0c14a6d485..268784df63 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceCallRealIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceRoutineSamples.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceRoutineSamples.kt index f531ef4511..5e078ba931 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceRoutineSamples.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceRoutineSamples.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceRoutineShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceRoutineShould.kt index 631a75679f..198df4e469 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceRoutineShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceRoutineShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceStoreIntegrationShould.kt index 19d0782408..9162d954e6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/imports/internal/TrackerImportConflictStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/imports/internal/TrackerImportConflictStoreIntegrationShould.java index f08e9f7455..4ce7a8053e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/imports/internal/TrackerImportConflictStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/imports/internal/TrackerImportConflictStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/internal/DataSetIndicatorLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/internal/DataSetIndicatorLinkStoreIntegrationShould.java index 94c7b1fa5d..1f7c60c84c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/internal/DataSetIndicatorLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/internal/DataSetIndicatorLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/internal/IndicatorStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/internal/IndicatorStoreIntegrationShould.java index e7cef7fda1..907ca88602 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/internal/IndicatorStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/internal/IndicatorStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/DataElementLegendSetLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/DataElementLegendSetLinkStoreIntegrationShould.kt index e70e1e8ad8..d387889cbf 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/DataElementLegendSetLinkStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/DataElementLegendSetLinkStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/IndicatorLegendSetLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/IndicatorLegendSetLinkStoreIntegrationShould.kt index 9b4c0af785..0bef7afc44 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/IndicatorLegendSetLinkStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/IndicatorLegendSetLinkStoreIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/ProgramIndicatorLegendSetLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/ProgramIndicatorLegendSetLinkStoreIntegrationShould.java index 35f57aedb9..71d9a95bec 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/ProgramIndicatorLegendSetLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/ProgramIndicatorLegendSetLinkStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendSetStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendSetStoreIntegrationShould.java index ef8ef2a2a4..76c7351a33 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendSetStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendSetStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendSetUidsSeekerMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendSetUidsSeekerMockIntegrationShould.kt index 221763cadb..bba8d062f9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendSetUidsSeekerMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendSetUidsSeekerMockIntegrationShould.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendStoreIntegrationShould.java index 6c547f4635..866f0376c5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/legendset/internal/LegendStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/D2ErrorStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/D2ErrorStoreIntegrationShould.java index 514d8c2ee3..cd8d728795 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/D2ErrorStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/D2ErrorStoreIntegrationShould.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyCleanerShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyCleanerShould.java deleted file mode 100644 index 300da3fb68..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyCleanerShould.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.maintenance.internal; - -import androidx.test.runner.AndroidJUnit4; - -import org.hisp.dhis.android.core.arch.call.executors.internal.D2CallExecutor; -import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.IdentifiableColumns; -import org.hisp.dhis.android.core.common.ObjectWithUid; -import org.hisp.dhis.android.core.maintenance.D2Error; -import org.hisp.dhis.android.core.maintenance.ForeignKeyViolation; -import org.hisp.dhis.android.core.maintenance.ForeignKeyViolationTableInfo; -import org.hisp.dhis.android.core.program.ProgramRule; -import org.hisp.dhis.android.core.program.ProgramRuleAction; -import org.hisp.dhis.android.core.program.ProgramRuleActionType; -import org.hisp.dhis.android.core.program.internal.ProgramRuleActionStore; -import org.hisp.dhis.android.core.program.internal.ProgramRuleStore; -import org.hisp.dhis.android.core.user.UserCredentials; -import org.hisp.dhis.android.core.user.UserCredentialsTableInfo; -import org.hisp.dhis.android.core.user.UserTableInfo; -import org.hisp.dhis.android.core.user.internal.UserCredentialsStoreImpl; -import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyDispatcher; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(AndroidJUnit4.class) -public class ForeignKeyCleanerShould extends BaseMockIntegrationTestEmptyDispatcher { - - @Before - public void setUp() { - d2.databaseAdapter().delete(ForeignKeyViolationTableInfo.TABLE_INFO.name()); - } - - @Test - public void remove_rows_that_produce_foreign_key_errors() throws Exception { - addUserCredentialsForeignKeyViolation(); - UserCredentials userCredentials = d2.userModule().userCredentials().blockingGet(); - assertThat(userCredentials.uid()).isEqualTo("M0fCOxtkURr"); - assertThat(userCredentials.user().uid()).isEqualTo("DXyJmlo9rge"); - } - - @Test - public void add_foreign_key_violation_to_table() throws Exception { - addUserCredentialsForeignKeyViolation(); - - assertThat(d2.maintenanceModule().foreignKeyViolations().blockingCount()).isEqualTo(1); - - ForeignKeyViolation foreignKeyViolation = d2.maintenanceModule().foreignKeyViolations().one().blockingGet(); - - ForeignKeyViolation expectedViolation = ForeignKeyViolation.builder() - .toTable(UserTableInfo.TABLE_INFO.name()) - .toColumn(IdentifiableColumns.UID) - .fromTable(UserCredentialsTableInfo.TABLE_INFO.name()) - .fromColumn(UserCredentialsTableInfo.Columns.USER) - .notFoundValue("no_user_uid") - .fromObjectUid("user_credential_uid1") - .build(); - - ForeignKeyViolation violationWithoutId = foreignKeyViolation.toBuilder() - .id(null) - .created(null) - .fromObjectRow(null) - .build(); - - assertThat(expectedViolation).isEqualTo(violationWithoutId); - } - - @Test - public void delete_in_cascade_on_foreign_key_error() throws Exception { - final D2CallExecutor executor = D2CallExecutor.create(d2.databaseAdapter()); - - final String PROGRAM_RULE_UID = "program_rule_uid"; - - final ObjectWithUid program = ObjectWithUid.create("nonexisent-program"); - - executor.executeD2CallTransactionally(() -> { - ProgramRuleStore.create(d2.databaseAdapter()).insert(ProgramRule.builder() - .uid(PROGRAM_RULE_UID).name("Rule").program(program).build()); - - ProgramRuleAction programRuleAction = ProgramRuleAction.builder() - .uid("action_uid") - .name("name") - .programRuleActionType(ProgramRuleActionType.ASSIGN) - .programRule(ObjectWithUid.create(PROGRAM_RULE_UID)) - .build(); - - ProgramRuleActionStore.create(d2.databaseAdapter()).insert(programRuleAction); - - assertThat(d2.programModule().programRules().blockingCount()).isEqualTo(1); - assertThat(d2.programModule().programRuleActions().blockingCount()).isEqualTo(1); - - ForeignKeyCleaner foreignKeyCleaner = ForeignKeyCleanerImpl.create(d2.databaseAdapter()); - Integer rowsAffected = foreignKeyCleaner.cleanForeignKeyErrors(); - - assertThat(rowsAffected).isEqualTo(1); - - assertThat(d2.programModule().programRules().blockingCount()).isEqualTo(0); - assertThat(d2.programModule().programRuleActions().blockingCount()).isEqualTo(0); - - return null; - }); - - } - - private void addUserCredentialsForeignKeyViolation() throws D2Error { - final D2CallExecutor executor = D2CallExecutor.create(d2.databaseAdapter()); - - executor.executeD2CallTransactionally(() -> { - ObjectWithUid user = ObjectWithUid.create("no_user_uid"); - UserCredentials userCredentials = UserCredentials.builder() - .id(2L) - .uid("user_credential_uid1") - .user(user) - .build(); - - IdentifiableObjectStore userCredentialsStore = - UserCredentialsStoreImpl.create(d2.databaseAdapter()); - userCredentialsStore.insert(userCredentials); - - ForeignKeyCleanerImpl.create(d2.databaseAdapter()).cleanForeignKeyErrors(); - - return null; - }); - } -} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyCleanerShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyCleanerShould.kt new file mode 100644 index 0000000000..8c75d3402b --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyCleanerShould.kt @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2004-2023, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.maintenance.internal + +import androidx.test.runner.AndroidJUnit4 +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.arch.call.executors.internal.D2CallExecutor +import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.common.IdentifiableColumns +import org.hisp.dhis.android.core.common.ObjectWithUid +import org.hisp.dhis.android.core.maintenance.ForeignKeyViolation +import org.hisp.dhis.android.core.maintenance.ForeignKeyViolationTableInfo +import org.hisp.dhis.android.core.option.Option +import org.hisp.dhis.android.core.option.OptionSetTableInfo +import org.hisp.dhis.android.core.option.OptionTableInfo +import org.hisp.dhis.android.core.option.internal.OptionStore +import org.hisp.dhis.android.core.program.ProgramRule +import org.hisp.dhis.android.core.program.ProgramRuleAction +import org.hisp.dhis.android.core.program.ProgramRuleActionType +import org.hisp.dhis.android.core.program.internal.ProgramRuleActionStore +import org.hisp.dhis.android.core.program.internal.ProgramRuleStore +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyDispatcher +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class ForeignKeyCleanerShould : BaseMockIntegrationTestEmptyDispatcher() { + + @Before + fun setUp() { + d2.databaseAdapter().delete(ForeignKeyViolationTableInfo.TABLE_INFO.name()) + } + + @Test + fun remove_rows_that_produce_foreign_key_errors() { + addOptionForeignKeyViolation() + val options = d2.optionModule().options().blockingGet() + assertThat(options).isEmpty() + } + + @Test + fun add_foreign_key_violation_to_table() { + addOptionForeignKeyViolation() + assertThat(d2.maintenanceModule().foreignKeyViolations().blockingCount()).isEqualTo(1) + val foreignKeyViolation = d2.maintenanceModule().foreignKeyViolations().one().blockingGet() + val expectedViolation = ForeignKeyViolation.builder() + .toTable(OptionSetTableInfo.TABLE_INFO.name()) + .toColumn(IdentifiableColumns.UID) + .fromTable(OptionTableInfo.TABLE_INFO.name()) + .fromColumn(OptionTableInfo.Columns.OPTION_SET) + .notFoundValue("no_option_set") + .fromObjectUid("option_uid") + .build() + val violationWithoutId = foreignKeyViolation.toBuilder() + .id(null) + .created(null) + .fromObjectRow(null) + .build() + assertThat(expectedViolation).isEqualTo(violationWithoutId) + } + + @Test + @Throws(Exception::class) + fun delete_in_cascade_on_foreign_key_error() { + val executor = D2CallExecutor.create(d2.databaseAdapter()) + val PROGRAM_RULE_UID = "program_rule_uid" + val program = ObjectWithUid.create("nonexisent-program") + executor.executeD2CallTransactionally { + ProgramRuleStore.create(d2.databaseAdapter()).insert( + ProgramRule.builder() + .uid(PROGRAM_RULE_UID).name("Rule").program(program).build() + ) + val programRuleAction = ProgramRuleAction.builder() + .uid("action_uid") + .name("name") + .programRuleActionType(ProgramRuleActionType.ASSIGN) + .programRule(ObjectWithUid.create(PROGRAM_RULE_UID)) + .build() + ProgramRuleActionStore.create(d2.databaseAdapter()).insert(programRuleAction) + assertThat(d2.programModule().programRules().blockingCount()).isEqualTo(1) + assertThat(d2.programModule().programRuleActions().blockingCount()).isEqualTo(1) + val foreignKeyCleaner = ForeignKeyCleanerImpl.create(d2.databaseAdapter()) + val rowsAffected = foreignKeyCleaner.cleanForeignKeyErrors() + assertThat(rowsAffected).isEqualTo(1) + assertThat(d2.programModule().programRules().blockingCount()).isEqualTo(0) + assertThat(d2.programModule().programRuleActions().blockingCount()).isEqualTo(0) + null + } + } + + private fun addOptionForeignKeyViolation() { + val executor = D2CallExecutor.create(d2.databaseAdapter()) + + executor.executeD2CallTransactionally { + val optionSet = ObjectWithUid.create("no_option_set") + val option = Option.builder() + .uid("option_uid") + .optionSet(optionSet) + .build() + val optionStore: IdentifiableObjectStore