diff --git a/core/build.gradle b/core/build.gradle index c2a554316b..f4f228e8e7 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -36,8 +36,8 @@ ext { buildToolsVersion: "28.0.3", minSdkVersion : 19, targetSdkVersion : 28, - versionCode : 203, - versionName : "1.0.3" + versionCode : 210, + versionName : "1.1.0" ] libraries = [ @@ -54,6 +54,8 @@ ext { duktape : "1.1.0", dagger : "2.14.1", rxjava : "2.2.8", + rxandroid : "2.1.1", + sqlcipher : "4.2.0", // code checks findbugs : "3.0.0", @@ -73,9 +75,6 @@ ext { // plugins errorpronecore : "2.0.15", - //database - sqlbritemigrations : "v1.0.1", - // google safetynet : "16.0.0", ] @@ -149,11 +148,7 @@ android { dependencies { api "io.reactivex.rxjava2:rxjava:${libraries.rxjava}" - - // sqlbrite-migrations library - api ("com.github.lykmapipo:sqlbrite-migrations:${libraries.sqlbritemigrations}") { - exclude group: 'io.reactivex.rxjava2', module: 'rxjava' - } + api "io.reactivex.rxjava2:rxandroid:${libraries.rxandroid}" // Support libraries api "androidx.annotation:annotation:${libraries.support}" @@ -199,8 +194,12 @@ dependencies { api "com.gabrielittner.auto.value:auto-value-cursor-annotations:${libraries.autovaluecursor}" annotationProcessor "com.gabrielittner.auto.value:auto-value-cursor:${libraries.autovaluecursor}" + api "net.zetetic:android-database-sqlcipher:${libraries.sqlcipher}" + api "com.google.code.findbugs:annotations:${libraries.findbugs}" + api "com.squareup.okhttp3:mockwebserver:${libraries.okhttp}" + // Java test dependencies testImplementation "junit:junit:${libraries.junit}" testImplementation "org.mockito:mockito-core:${libraries.mockito}" @@ -213,7 +212,6 @@ dependencies { // Android test dependencies androidTestImplementation "commons-logging:commons-logging:1.2" androidTestImplementation "org.mockito:mockito-core:${libraries.mockito}" - androidTestImplementation "com.squareup.okhttp3:mockwebserver:${libraries.okhttp}" androidTestImplementation "android.arch.core:core-testing:${libraries.coretesting}" androidTestImplementation "com.jraska.livedata:testing:${libraries.livedatatesting}" androidTestImplementation "androidx.test:runner:${libraries.testrunner}" diff --git a/core/gradle.properties b/core/gradle.properties index bb5faa55f7..0b91150413 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.0.3 -VERSION_CODE=203 +VERSION_NAME=1.1.0 +VERSION_CODE=210 GROUP=org.hisp.dhis diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/real/BaseRealIntegrationTest.java b/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.java similarity index 68% rename from core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/real/BaseRealIntegrationTest.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.java index a377528feb..773141ac53 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/real/BaseRealIntegrationTest.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.java @@ -26,22 +26,19 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.utils.integration.real; +package org.hisp.dhis.android.core; import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; + +import androidx.test.InstrumentationRegistry; import com.facebook.stetho.Stetho; -import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.arch.call.internal.GenericCallData; import org.hisp.dhis.android.core.arch.d2.internal.D2DIComponent; import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.arch.db.access.DbOpenHelper; -import org.hisp.dhis.android.core.arch.db.access.internal.SqLiteDatabaseAdapter; -import org.hisp.dhis.android.core.arch.storage.internal.CredentialsSecureStore; -import org.hisp.dhis.android.core.arch.storage.internal.CredentialsSecureStoreImpl; +import org.hisp.dhis.android.core.arch.db.access.internal.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.arch.storage.internal.InMemorySecureStore; import org.hisp.dhis.android.core.data.server.RealServerMother; import org.hisp.dhis.android.core.resource.internal.ResourceHandler; import org.junit.After; @@ -50,18 +47,13 @@ import java.io.IOException; import java.util.Date; -import androidx.test.InstrumentationRegistry; - import static com.google.common.truth.Truth.assertThat; public abstract class BaseRealIntegrationTest { - private SQLiteDatabase sqLiteDatabase; private DatabaseAdapter databaseAdapter; - private Context context; protected Date serverDate = new Date(); protected ResourceHandler resourceHandler; - protected CredentialsSecureStore credentialsSecureStore; protected String username = RealServerMother.username; protected String password = RealServerMother.password; @@ -69,12 +61,11 @@ public abstract class BaseRealIntegrationTest { @Before public void setUp() throws IOException { - context = InstrumentationRegistry.getTargetContext().getApplicationContext(); + Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); - DbOpenHelper dbOpenHelper = new DbOpenHelper(context, null); - sqLiteDatabase = dbOpenHelper.getWritableDatabase(); - databaseAdapter = new SqLiteDatabaseAdapter(dbOpenHelper); - credentialsSecureStore = new CredentialsSecureStoreImpl(context); + DatabaseAdapterFactory databaseAdapterFactory = DatabaseAdapterFactory.create(context, new InMemorySecureStore()); + databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, null, false); resourceHandler = ResourceHandler.create(databaseAdapter); resourceHandler.setServerDate(serverDate); Stetho.initializeWithDefaults(context); @@ -82,12 +73,8 @@ public void setUp() throws IOException { @After public void tearDown() throws IOException { - assertThat(sqLiteDatabase).isNotNull(); - sqLiteDatabase.close(); - } - - protected SQLiteDatabase database() { - return sqLiteDatabase; + assertThat(databaseAdapter).isNotNull(); + databaseAdapter.close(); } protected DatabaseAdapter databaseAdapter() { @@ -99,13 +86,7 @@ protected GenericCallData getGenericCallData(D2 d2) { databaseAdapter(), d2.retrofit(), resourceHandler, d2.systemInfoModule().versionManager()); } - protected Cursor getCursor(String table, String[] columns) { - return sqLiteDatabase.query(table, columns, - null, null, null, null, null); - } - protected D2DIComponent getD2DIComponent(D2 d2) { - return D2DIComponent.create(InstrumentationRegistry.getTargetContext().getApplicationContext(), d2.retrofit(), - databaseAdapter, credentialsSecureStore); + return d2.d2DIComponent; } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/D2Factory.java b/core/src/androidTest/java/org/hisp/dhis/android/core/D2Factory.java index 9e22e2d703..29de553439 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/D2Factory.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/D2Factory.java @@ -30,39 +30,47 @@ import android.content.Context; +import androidx.test.InstrumentationRegistry; + import com.facebook.stetho.okhttp3.StethoInterceptor; -import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.arch.storage.internal.CredentialsSecureStore; -import org.hisp.dhis.android.core.arch.storage.internal.CredentialsSecureStoreImpl; +import org.hisp.dhis.android.core.arch.storage.internal.AndroidInsecureStore; +import org.hisp.dhis.android.core.arch.storage.internal.AndroidSecureStore; +import org.hisp.dhis.android.core.arch.storage.internal.InMemorySecureStore; +import org.hisp.dhis.android.core.arch.storage.internal.InMemoryUnsecureStore; +import org.hisp.dhis.android.core.arch.storage.internal.InsecureStore; +import org.hisp.dhis.android.core.arch.storage.internal.SecureStore; import java.util.Collections; -import androidx.test.InstrumentationRegistry; import okhttp3.logging.HttpLoggingInterceptor; public class D2Factory { - public static D2 forDatabaseName(String databaseName) { + public static D2 forNewDatabase() { + return forNewDatabaseInternal(new InMemorySecureStore(), new InMemoryUnsecureStore()); + } + + public static D2 forNewDatabaseWithAndroidSecureStore() { Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); + return forNewDatabaseInternal(new AndroidSecureStore(context), new AndroidInsecureStore(context)); + } - D2Configuration d2Configuration = d2Configuration(context); + private static D2 forNewDatabaseInternal(SecureStore secureStore, InsecureStore insecureStore) { + Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); - D2Manager.setDatabaseName(databaseName); + D2Configuration d2Configuration = d2Configuration(context); D2Manager.setTestMode(true); + D2Manager.setTestingSecureStore(secureStore); + D2Manager.setTestingInsecureStore(insecureStore); D2 d2 = D2Manager.blockingInstantiateD2(d2Configuration); D2Manager.clear(); - D2Manager.setDatabaseName(null); return d2; } - public static D2 forNewDatabase() { - return forDatabaseName(null); - } - private static D2Configuration d2Configuration(Context context) { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); @@ -76,17 +84,4 @@ private static D2Configuration d2Configuration(Context context) { .context(context) .build(); } - - public static D2 forDatabaseAdapter(DatabaseAdapter databaseAdapter) { - Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); - NotClosedObjectsDetector.enableNotClosedObjectsDetection(); - CredentialsSecureStore credentialsSecureStore = new CredentialsSecureStoreImpl(context); - return new D2( - RetrofitFactory.retrofit( - OkHttpClientFactory.okHttpClient(d2Configuration(context), credentialsSecureStore)), - databaseAdapter, - context, - credentialsSecureStore - ); - } } \ No newline at end of file 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 6eefdbb240..eee08bdf16 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 @@ -30,7 +30,6 @@ import android.util.Log; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjects.java b/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.java similarity index 68% rename from core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjects.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.java index 4a59ef5084..84e5a2c82e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjects.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.java @@ -26,30 +26,26 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.utils.integration.mock; +package org.hisp.dhis.android.core; import android.content.Context; -import android.database.sqlite.SQLiteDatabase; import android.util.Log; +import androidx.test.InstrumentationRegistry; + import com.facebook.stetho.Stetho; -import org.hisp.dhis.android.core.D2; -import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.d2.internal.D2DIComponent; import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.arch.storage.internal.CredentialsSecureStore; -import org.hisp.dhis.android.core.arch.storage.internal.CredentialsSecureStoreImpl; -import org.hisp.dhis.android.core.data.server.Dhis2MockServer; +import org.hisp.dhis.android.core.mockwebserver.Dhis2MockServer; +import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory; import org.hisp.dhis.android.core.resource.internal.ResourceHandler; +import org.hisp.dhis.android.core.utils.integration.mock.MockIntegrationTestDatabaseContent; import java.io.IOException; import java.util.Date; -import androidx.test.InstrumentationRegistry; - public class MockIntegrationTestObjects { - public final SQLiteDatabase database; public final DatabaseAdapter databaseAdapter; public Date serverDate = new Date(); @@ -59,41 +55,27 @@ public class MockIntegrationTestObjects { public final D2 d2; public final Dhis2MockServer dhis2MockServer; public final MockIntegrationTestDatabaseContent content; - private final String dbName; - private final CredentialsSecureStore credentialsSecureStore; - MockIntegrationTestObjects(MockIntegrationTestDatabaseContent content) throws Exception { + public MockIntegrationTestObjects(MockIntegrationTestDatabaseContent content) throws Exception { this.content = content; - dbName = content.toString().toLowerCase() + ".db"; - - deleteDatabase(); Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); Stetho.initializeWithDefaults(context); - dhis2MockServer = new Dhis2MockServer(); + dhis2MockServer = new Dhis2MockServer(0); + CalendarProviderFactory.setFixed(); - d2 = D2Factory.forDatabaseName(dbName); + d2 = D2Factory.forNewDatabase(); - database = d2.databaseAdapter().database(); databaseAdapter = d2.databaseAdapter(); - credentialsSecureStore = new CredentialsSecureStoreImpl(context); - - d2DIComponent = D2DIComponent.create(context, d2.retrofit(), databaseAdapter, credentialsSecureStore); + d2DIComponent = d2.d2DIComponent; resourceHandler = ResourceHandler.create(databaseAdapter); resourceHandler.setServerDate(serverDate); } - private void deleteDatabase() { - Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); - context.deleteDatabase(dbName); - } - public void tearDown() throws IOException { Log.i("MockIntegrationTestObjects", "Objects teardown: " + content); - database.close(); - deleteDatabase(); dhis2MockServer.shutdown(); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserMockIntegrationShould.java new file mode 100644 index 0000000000..fe2cf91080 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserMockIntegrationShould.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2004-2019, 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; + +import org.hisp.dhis.android.core.category.CategoryOptionTableInfo; +import org.hisp.dhis.android.core.configuration.internal.MultiUserDatabaseManager; +import org.hisp.dhis.android.core.data.category.CategoryOptionSamples; +import org.hisp.dhis.android.core.mockwebserver.Dhis2MockServer; +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyEnqueable; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; + +import static com.google.common.truth.Truth.assertThat; + +public class MultiUserMockIntegrationShould extends BaseMockIntegrationTestEmptyEnqueable { + + @BeforeClass + public static void setUpClass() throws Exception { + BaseMockIntegrationTestEmptyEnqueable.setUpClass(); + MultiUserDatabaseManager.setMaxServerUserPairs(5); + } + + @AfterClass + public static void tearDownClass() { + MultiUserDatabaseManager.setMaxServerUserPairs(1); + } + + @Test + public void connect_to_server_with_2_different_users() { + if (d2.userModule().blockingIsLogged()) { + d2.userModule().blockingLogOut(); + } + + dhis2MockServer.enqueueLoginResponses(); + d2.userModule().blockingLogIn("u1", "p1", dhis2MockServer.getBaseEndpoint()); + d2.databaseAdapter().insert(CategoryOptionTableInfo.TABLE_INFO.name(), null, + CategoryOptionSamples.getCategoryOption().toContentValues()); + assertThat(d2.categoryModule().categoryOptions().blockingCount()).isEqualTo(1); + + d2.userModule().blockingLogOut(); + + dhis2MockServer.enqueueLoginResponses(); + d2.userModule().blockingLogIn("u2", "p2", dhis2MockServer.getBaseEndpoint()); + assertThat(d2.categoryModule().categoryOptions().blockingCount()).isEqualTo(0); + + d2.userModule().blockingLogOut(); + + dhis2MockServer.enqueueLoginResponses(); + d2.userModule().blockingLogIn("u1", "p1", dhis2MockServer.getBaseEndpoint()); + assertThat(d2.categoryModule().categoryOptions().blockingCount()).isEqualTo(1); + } + + @Test + public void connect_to_two_servers() throws IOException { + if (d2.userModule().blockingIsLogged()) { + d2.userModule().blockingLogOut(); + } + + dhis2MockServer.enqueueLoginResponses(); + d2.userModule().blockingLogIn("u1", "p1", dhis2MockServer.getBaseEndpoint()); + d2.databaseAdapter().insert(CategoryOptionTableInfo.TABLE_INFO.name(), null, + CategoryOptionSamples.getCategoryOption().toContentValues()); + assertThat(d2.categoryModule().categoryOptions().blockingCount()).isEqualTo(1); + + d2.userModule().blockingLogOut(); + + Dhis2MockServer server2 = new Dhis2MockServer(0); + server2.enqueueLoginResponses(); + d2.userModule().blockingLogIn("u2", "p2", server2.getBaseEndpoint()); + assertThat(d2.categoryModule().categoryOptions().blockingCount()).isEqualTo(0); + + d2.userModule().blockingLogOut(); + + dhis2MockServer.enqueueLoginResponses(); + d2.userModule().blockingLogIn("u1", "p1", dhis2MockServer.getBaseEndpoint()); + assertThat(d2.categoryModule().categoryOptions().blockingCount()).isEqualTo(1); + } +} 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 new file mode 100644 index 0000000000..4c6c7044f1 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MultiUserRealIntegrationShould.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2004-2019, 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; + +import org.hisp.dhis.android.core.data.server.RealServerMother; +import org.junit.Before; + +import java.io.IOException; + +public class MultiUserRealIntegrationShould extends BaseRealIntegrationTest { + private D2 d2; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + d2 = D2Factory.forNewDatabase(); + } + + //@Test + public void connect_to_server_with_2_different_users() { + d2.userModule().blockingLogIn(username, password, url); + d2.metadataModule().blockingDownload(); + int programsA0 = d2.programModule().programs().blockingCount(); + d2.userModule().blockingLogOut(); + + + d2.userModule().blockingLogIn("admin", "district", url); + d2.metadataModule().blockingDownload(); + int programsA1 = d2.programModule().programs().blockingCount(); + d2.userModule().blockingLogOut(); + + d2.userModule().blockingLogIn(username, password, url); + int programsA2 = d2.programModule().programs().blockingCount(); + } + + //@Test + public void connect_to_2_different_servers() { + d2.userModule().blockingLogIn(username, password, RealServerMother.android_current); + d2.metadataModule().blockingDownload(); + int programsA0 = d2.programModule().programs().blockingCount(); + d2.userModule().blockingLogOut(); + + + d2.userModule().blockingLogIn(username, password, RealServerMother.url2_29); + d2.metadataModule().blockingDownload(); + int programsA1 = d2.programModule().programs().blockingCount(); + d2.userModule().blockingLogOut(); + + d2.userModule().blockingLogIn(username, password, RealServerMother.android_current); + int programsA2 = d2.programModule().programs().blockingCount(); + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.java index be0cdc044c..09282d8ba9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.arch.call.D2Progress; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceStoreImpl; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/UserAuthenticateCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/UserAuthenticateCallRealIntegrationShould.java index 41144204b4..75c40f424c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/UserAuthenticateCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/UserAuthenticateCallRealIntegrationShould.java @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core; import org.hisp.dhis.android.core.data.server.RealServerMother; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/main/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 similarity index 87% rename from core/src/main/java/org/hisp/dhis/android/core/arch/db/access/SqliteCheckerUtility.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/SqliteCheckerUtility.java index 61c66b8c19..ba8143f0f0 100644 --- a/core/src/main/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 @@ -30,14 +30,14 @@ import android.database.Cursor; -final public class SqliteCheckerUtility { +public final class SqliteCheckerUtility { private SqliteCheckerUtility() { } public static boolean isTableEmpty(DatabaseAdapter databaseAdapter, String table) { boolean isTableEmpty = true; - Cursor cursor = databaseAdapter.query(" SELECT * FROM "+table); + Cursor cursor = databaseAdapter.rawQuery(" SELECT * FROM "+table); int value = cursor.getCount(); if (value > 0) { isTableEmpty = false; @@ -48,13 +48,13 @@ public static boolean isTableEmpty(DatabaseAdapter databaseAdapter, String table public static boolean isDatabaseEmpty(DatabaseAdapter databaseAdapter) { boolean isDatabaseEmpty = true; - Cursor cursor = databaseAdapter.query(" SELECT name FROM sqlite_master WHERE " + Cursor cursor = databaseAdapter.rawQuery(" SELECT name FROM sqlite_master WHERE " + "type='table' and name!='android_metadata' and name!='sqlite_sequence'"); int value = cursor.getColumnIndex("name"); if (value != -1) { while (cursor.moveToNext()){ String tableName = cursor.getString(value); - Cursor resTable = databaseAdapter.query("SELECT * from " + tableName); + Cursor resTable = databaseAdapter.rawQuery("SELECT * from " + tableName); if (resTable.getCount() > 0) { isDatabaseEmpty = false; break; @@ -65,9 +65,9 @@ public static boolean isDatabaseEmpty(DatabaseAdapter databaseAdapter) { return isDatabaseEmpty; } - public static boolean ifTableExist(String table, DatabaseAdapter db) { + public static boolean ifTableExist(String table, DatabaseAdapter databaseAdapter) { boolean isExist = false; - Cursor cursor = db.query("PRAGMA table_info(" + table + ")"); + Cursor cursor = databaseAdapter.rawQuery("PRAGMA table_info(" + table + ")"); int itemsCount = cursor.getCount(); if (itemsCount > 0) { isExist = true; 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 new file mode 100644 index 0000000000..7c3166e333 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/db/access/internal/DatabaseAdapterFactoryIntegrationShould.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2004-2019, 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.arch.db.access.internal; + +import android.content.Context; +import android.database.Cursor; + +import androidx.test.InstrumentationRegistry; + +import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; +import org.hisp.dhis.android.core.arch.storage.internal.InMemorySecureStore; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class DatabaseAdapterFactoryIntegrationShould { + + private static final String DB_NAME = "database-adapter-factory-integration-should.db"; + private static DatabaseAdapterFactory databaseAdapterFactory; + + @BeforeClass + public static void setUpClass() { + Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); + databaseAdapterFactory = DatabaseAdapterFactory.create(context, new InMemorySecureStore()); + } + + @AfterClass + public static void tearDownClass() { + Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); + context.deleteDatabase(DB_NAME + ".db"); + } + + @Test + public void get_adapter() { + databaseAdapterFactory.newParentDatabaseAdapter(); + } + + @Test + public void get_adapter_create_and_close() { + DatabaseAdapter databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, DB_NAME, false); + databaseAdapter.close(); + } + + @Test + public void get_adapter_create_close_and_recreate() { + DatabaseAdapter databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, DB_NAME, false); + databaseAdapter.close(); + + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, DB_NAME, false); + } + + @Test + public void get_adapter_create_and_recreate_without_closing() { + DatabaseAdapter databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, DB_NAME, false); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, DB_NAME, false); + } + + @Test + public void get_adapter_create_close_and_recreate_reading_db() { + DatabaseAdapter databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, DB_NAME, false); + Cursor cursor1 = databaseAdapter.rawQuery("SELECT * FROM User"); + int count1 = cursor1.getCount(); + cursor1.close(); + + databaseAdapter.close(); + + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, DB_NAME, false); + Cursor cursor2 = databaseAdapter.rawQuery("SELECT * FROM User"); + int count2 = cursor2.getCount(); + cursor2.close(); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/RelationshipTypeAsserts.java b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/RelationshipTypeAsserts.java index 74681a8784..8b0ee73d3c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/RelationshipTypeAsserts.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/repositories/collection/RelationshipTypeAsserts.java @@ -28,8 +28,8 @@ package org.hisp.dhis.android.core.arch.repositories.collection; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.relationship.RelationshipType; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import static com.google.common.truth.Truth.assertThat; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/storage/internal/CredentialsSecureStorageMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/storage/internal/CredentialsSecureStorageMockIntegrationShould.java index 1abaeb0401..2e44de9278 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/arch/storage/internal/CredentialsSecureStorageMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/arch/storage/internal/CredentialsSecureStorageMockIntegrationShould.java @@ -40,20 +40,21 @@ @RunWith(D2JunitRunner.class) public class CredentialsSecureStorageMockIntegrationShould { - private CredentialsSecureStore credentialsSecureStore; + private ObjectKeyValueStore credentialsSecureStore; @Before public void setUp() { credentialsSecureStore = - new CredentialsSecureStoreImpl(InstrumentationRegistry.getContext().getApplicationContext()); + new CredentialsSecureStoreImpl( + new AndroidSecureStore(InstrumentationRegistry.getContext().getApplicationContext())); } @Test public void credentials_are_correctly_stored() { Credentials credentials = Credentials.create("username", "password"); - credentialsSecureStore.setCredentials(credentials); + credentialsSecureStore.set(credentials); - Credentials retrievedCredentials = credentialsSecureStore.getCredentials(); + Credentials retrievedCredentials = credentialsSecureStore.get(); assertThat(retrievedCredentials.username()).isEqualTo(credentials.username()); assertThat(retrievedCredentials.password()).isEqualTo(credentials.password()); @@ -62,11 +63,11 @@ public void credentials_are_correctly_stored() { @Test public void credentials_are_correctly_removed() { Credentials credentials = Credentials.create("username", "password"); - credentialsSecureStore.setCredentials(credentials); + credentialsSecureStore.set(credentials); - credentialsSecureStore.removeCredentials(); + credentialsSecureStore.remove(); - Credentials retrievedCredentials = credentialsSecureStore.getCredentials(); + Credentials retrievedCredentials = credentialsSecureStore.get(); assertThat(retrievedCredentials).isNull(); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreIntegrationShould.java index a4ca912dbb..291e59d966 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.category.CategoryCategoryComboLinkTableInfo; import org.hisp.dhis.android.core.data.category.CategoryCategoryComboLinkSamples; import org.hisp.dhis.android.core.data.database.LinkStoreAbstractIntegrationShould; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class CategoryCategoryComboLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public CategoryCategoryComboLinkStoreIntegrationShould() { - super(CategoryCategoryComboLinkStore.create(DatabaseAdapterFactory.get()), - CategoryCategoryComboLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(CategoryCategoryComboLinkStore.create(TestDatabaseAdapterFactory.get()), + CategoryCategoryComboLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreShould.java index 705d4fd3fa..8e197656f0 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryComboLinkStoreShould.java @@ -30,12 +30,12 @@ import androidx.test.runner.AndroidJUnit4; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore; import org.hisp.dhis.android.core.category.Category; import org.hisp.dhis.android.core.category.CategoryCategoryComboLink; import org.hisp.dhis.android.core.category.CategoryCombo; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; 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 07064b48e5..97f4c18bd5 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.category.CategoryCategoryOptionLinkTableInfo; import org.hisp.dhis.android.core.data.category.CategoryCategoryOptionLinkSamples; import org.hisp.dhis.android.core.data.database.LinkStoreAbstractIntegrationShould; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class CategoryCategoryOptionLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public CategoryCategoryOptionLinkStoreIntegrationShould() { - super(CategoryCategoryOptionLinkStore.create(DatabaseAdapterFactory.get()), - CategoryCategoryOptionLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(CategoryCategoryOptionLinkStore.create(TestDatabaseAdapterFactory.get()), + CategoryCategoryOptionLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryOptionLinkStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryOptionLinkStoreShould.java index b46c544118..e327f0ee11 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryOptionLinkStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryCategoryOptionLinkStoreShould.java @@ -30,12 +30,12 @@ import androidx.test.runner.AndroidJUnit4; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore; import org.hisp.dhis.android.core.category.Category; import org.hisp.dhis.android.core.category.CategoryCategoryOptionLink; import org.hisp.dhis.android.core.category.CategoryOption; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.java index 712e5d4d90..a15be60d1f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.java @@ -30,6 +30,7 @@ import com.google.common.collect.Lists; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; @@ -38,7 +39,6 @@ import org.hisp.dhis.android.core.category.CategoryCombo; import org.hisp.dhis.android.core.category.CategoryOption; import org.hisp.dhis.android.core.category.CategoryOptionCombo; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; @@ -64,7 +64,7 @@ public void setUp() throws IOException { public void download_categories_combos_and_relatives() throws Exception { d2.userModule().logIn(username, password, url).blockingGet(); - d2.databaseAdapter().database().setForeignKeyConstraintsEnabled(false); + d2.databaseAdapter().setForeignKeyConstraintsEnabled(false); assertNotCombosInDB(); assertTrue(getCategoryCategoryComboLinks().isEmpty()); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.java index a0e479cff3..6007644a7d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.java @@ -30,10 +30,10 @@ import com.google.common.collect.Lists; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.category.Category; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; 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 25cc90b524..25523a6113 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.category.CategoryOptionComboCategoryOptionLinkTableInfo; import org.hisp.dhis.android.core.data.category.CategoryOptionComboCategoryOptionLinkSamples; import org.hisp.dhis.android.core.data.database.LinkStoreAbstractIntegrationShould; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,9 +41,9 @@ public class CategoryOptionComboCategoryOptionLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public CategoryOptionComboCategoryOptionLinkStoreIntegrationShould() { - super(CategoryOptionComboCategoryOptionLinkStore.create(DatabaseAdapterFactory.get()), + super(CategoryOptionComboCategoryOptionLinkStore.create(TestDatabaseAdapterFactory.get()), CategoryOptionComboCategoryOptionLinkTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + TestDatabaseAdapterFactory.get()); } @Override 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 6fa53c8345..edaf536259 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 @@ -29,13 +29,12 @@ package org.hisp.dhis.android.core.common; import android.database.Cursor; -import android.database.sqlite.SQLiteConstraintException; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; import org.hisp.dhis.android.core.option.OptionSet; import org.hisp.dhis.android.core.option.OptionSetTableInfo; import org.hisp.dhis.android.core.option.internal.OptionSetStore; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.Before; import org.junit.Test; @@ -64,7 +63,7 @@ public void setUp() throws IOException { } private Cursor getCursor() { - return getCursor(OptionSetTableInfo.TABLE_INFO.name(), OptionSetTableInfo.TABLE_INFO.columns().all()); + return databaseAdapter().query(OptionSetTableInfo.TABLE_INFO.name(), OptionSetTableInfo.TABLE_INFO.columns().all()); } @Test @@ -79,7 +78,7 @@ public void throw_exception_for_null_when_inserting() { store.insert(null); } - @Test(expected = SQLiteConstraintException.class) + @Test(expected = RuntimeException.class) public void throw_exception_for_second_identical_insertion() { store.insert(this.optionSet); store.insert(this.optionSet); 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 463648a1e6..ea29e4c5c7 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 @@ -29,13 +29,12 @@ package org.hisp.dhis.android.core.common; import android.database.Cursor; -import android.database.sqlite.SQLiteConstraintException; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; import org.hisp.dhis.android.core.option.OptionSet; import org.hisp.dhis.android.core.option.OptionSetTableInfo; import org.hisp.dhis.android.core.option.internal.OptionSetStore; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.Before; import org.junit.Test; @@ -63,7 +62,7 @@ public void setUp() throws IOException { @Test public void insert_option_set() { store.insert(optionSet); - Cursor cursor = getCursor(OptionSetTableInfo.TABLE_INFO.name(), OptionSetTableInfo.TABLE_INFO.columns().all()); + Cursor cursor = databaseAdapter().query(OptionSetTableInfo.TABLE_INFO.name(), OptionSetTableInfo.TABLE_INFO.columns().all()); optionSetCursorAssert(cursor, optionSet); } @@ -72,7 +71,7 @@ public void throw_exception_for_null_when_inserting() { store.insert(null); } - @Test(expected = SQLiteConstraintException.class) + @Test(expected = RuntimeException.class) public void throw_exception_for_second_identical_insertion() { store.insert(this.optionSet); store.insert(this.optionSet); 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 9a462addbe..5c997470f8 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 @@ -31,7 +31,7 @@ import org.hisp.dhis.android.core.common.valuetype.devicerendering.internal.ValueTypeDeviceRenderingStore; import org.hisp.dhis.android.core.data.common.ValueTypeDeviceRenderingSamples; import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class ValueTypeDeviceRenderingStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould { public ValueTypeDeviceRenderingStoreIntegrationShould() { - super(ValueTypeDeviceRenderingStore.create(DatabaseAdapterFactory.get()), - ValueTypeDeviceRenderingTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ValueTypeDeviceRenderingStore.create(TestDatabaseAdapterFactory.get()), + ValueTypeDeviceRenderingTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/ConfigurationStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/ConfigurationStoreIntegrationShould.java deleted file mode 100644 index 45d2f19920..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/ConfigurationStoreIntegrationShould.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2004-2019, 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.configuration; - -import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.arch.db.tableinfos.TableInfo; -import org.hisp.dhis.android.core.data.configuration.ConfigurationSamples; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; -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; - -import java.io.IOException; -import java.util.List; - -import okhttp3.HttpUrl; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(D2JunitRunner.class) -public class ConfigurationStoreIntegrationShould { - - private final Configuration configuration; - private final ConfigurationStore store; - private final TableInfo tableInfo; - private final DatabaseAdapter databaseAdapter; - - public ConfigurationStoreIntegrationShould() { - this.store = ConfigurationStoreImpl.create(DatabaseAdapterFactory.get()); - this.configuration = buildObject(); - this.tableInfo = ConfigurationTableInfo.TABLE_INFO; - this.databaseAdapter = DatabaseAdapterFactory.get(); - } - - @Before - public void setUp() throws IOException { - store.delete(); - } - - @After - public void tearDown() { - // DatabaseAdapterFactory.get().database().close(); - } - - @Test - public void insert_and_select_first_object() { - store.insert(configuration); - Configuration objectFromDb = store.selectFirst(); - assertThat(objectFromDb.serverUrl()).isEqualTo(HttpUrl.parse("http://testserver.org/api/")); - } - - @Test - public void insert_as_content_values_and_select_first_object() { - long rowsInserted = databaseAdapter.database() - .insert(tableInfo.name(), null, configuration.toContentValues()); - assertThat(rowsInserted).isEqualTo(1); - Configuration objectFromDb = store.selectFirst(); - assertThat(objectFromDb).isEqualTo(configuration); - } - - @Test - public void insert_and_select_all_objects() { - store.insert(configuration); - List objectsFromDb = store.selectAll(); - assertThat(objectsFromDb.iterator().next().serverUrl()).isEqualTo(HttpUrl.parse("http://testserver.org/api/")); - } - - @Test - public void delete_inserted_object_by_id() { - store.insert(configuration); - Configuration insertedConfiguration = store.selectFirst(); - store.deleteById(insertedConfiguration); - assertThat(store.selectFirst()).isEqualTo(null); - } - - @Test - public void save_configuration_properly() { - store.save(configuration); - Configuration objectFromDb = store.selectFirst(); - assertThat(objectFromDb.serverUrl()).isEqualTo(HttpUrl.parse("http://testserver.org/api/")); - } - - @Test - public void delete_old_configuration_before_save_the_new_one() { - store.save(configuration); - store.save(configuration); - store.save(configuration); - assertThat(store.count()).isEqualTo(1); - } - - protected Configuration buildObject() { - return ConfigurationSamples.getConfiguration(); - } -} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/ConfigurationStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/ConfigurationStoreShould.java deleted file mode 100644 index beea81e483..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/ConfigurationStoreShould.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2004-2019, 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.configuration; - -import android.content.ContentValues; -import android.database.Cursor; - -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; - -import okhttp3.HttpUrl; - -import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor; - -public class ConfigurationStoreShould extends BaseRealIntegrationTest { - private static final String[] PROJECTION = {ConfigurationTableInfo.Columns.ID, - ConfigurationTableInfo.Columns.SERVER_URL}; - - private ConfigurationStore store; - - private static final String URL1 = "http://testserver.org/api/"; - private static final String URL2 = "http://othertestserver.org/api/"; - - @Before - @Override - public void setUp() throws IOException { - super.setUp(); - store = ConfigurationStoreImpl.create(databaseAdapter()); - } - - @Test - public void persist_row_in_database_when_save() { - store.save(Configuration.builder().serverUrl(HttpUrl.parse(URL1)).build()); - - Cursor cursor = database().query(ConfigurationTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); - - assertThatCursor(cursor) - .hasRow(1L, URL1) - .isExhausted(); - } - - @Test - public void not_thrown_on_save_conflict() { - ContentValues contentValues = new ContentValues(); - contentValues.put(ConfigurationTableInfo.Columns.SERVER_URL, URL1); - - database().insert(ConfigurationTableInfo.TABLE_INFO.name(), null, contentValues); - - // trying to configure configuration with server url (which is set to be unique in the table) - store.save(Configuration.builder().serverUrl(HttpUrl.parse(URL1)).build()); - - Cursor cursor = database().query(ConfigurationTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); - assertThatCursor(cursor) - .hasRow(2L, URL1) - .isExhausted(); - } - - @Test - public void not_persist_more_than_one_url_on_save() { - ContentValues contentValues = new ContentValues(); - contentValues.put(ConfigurationTableInfo.Columns.SERVER_URL, URL1); - - database().insert(ConfigurationTableInfo.TABLE_INFO.name(), null, contentValues); - - HttpUrl url = HttpUrl.parse(URL2); - store.save(Configuration.builder().serverUrl(url).build()); - - Cursor cursor = database().query(ConfigurationTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); - assertThatCursor(cursor) - .hasRow(2L, URL2) - .isExhausted(); - } - - @Test - public void delete_persisted_rows_on_delete() { - ContentValues contentValues = new ContentValues(); - contentValues.put(ConfigurationTableInfo.Columns.SERVER_URL, URL1); - - database().insert(ConfigurationTableInfo.TABLE_INFO.name(), null, contentValues); - - long deleted = store.delete(); - - Cursor cursor = database().query(ConfigurationTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); - assertThat(deleted).isEqualTo(1); - assertThatCursor(cursor).isExhausted(); - } - - @Test - public void not_fail_if_no_rows_persisted_on_delete() { - long deleted = store.delete(); - assertThat(deleted).isEqualTo(0); - } - - @Test - public void return_persisted_row_when_query() { - ContentValues contentValues = new ContentValues(); - contentValues.put(ConfigurationTableInfo.Columns.SERVER_URL, URL1); - - database().insert(ConfigurationTableInfo.TABLE_INFO.name(), null, contentValues); - - HttpUrl url = HttpUrl.parse(URL2); - store.save(Configuration.builder().serverUrl(url).build()); - - Configuration persistedConfiguration = store.selectFirst(); - assertThat(persistedConfiguration.serverUrl().toString()).isEqualTo(URL2); - } - - @Test - public void return_null_if_no_rows_are_persisted() { - Configuration persistedConfiguration = store.selectFirst(); - assertThat(persistedConfiguration).isNull(); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_insert_null_uid() { - store.save(null); - } -} \ No newline at end of file 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 new file mode 100644 index 0000000000..bb4245ca73 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/ConfigurationStoreIntegrationShould.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004-2019, 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.configuration.internal; + +import org.hisp.dhis.android.core.data.configuration.ConfigurationSamples; +import org.hisp.dhis.android.core.data.database.ObjectStoreAbstractIntegrationShould; +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) +public class ConfigurationStoreIntegrationShould extends ObjectStoreAbstractIntegrationShould { + + public ConfigurationStoreIntegrationShould() { + super(ConfigurationStore.create(TestDatabaseAdapterFactory.get()), + ConfigurationTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); + } + + @Override + protected Configuration buildObject() { + return ConfigurationSamples.getConfiguration(); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/DatabaseConfigurationMigrationIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/DatabaseConfigurationMigrationIntegrationShould.java new file mode 100644 index 0000000000..57746aaac0 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/configuration/internal/DatabaseConfigurationMigrationIntegrationShould.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2004-2019, 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.configuration.internal; + +import android.content.Context; + +import androidx.test.InstrumentationRegistry; + +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.db.stores.internal.ObjectStore; +import org.hisp.dhis.android.core.arch.storage.internal.InMemorySecureStore; +import org.hisp.dhis.android.core.arch.storage.internal.InMemoryUnsecureStore; +import org.hisp.dhis.android.core.arch.storage.internal.InsecureStore; +import org.hisp.dhis.android.core.arch.storage.internal.ObjectKeyValueStore; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.user.UserCredentials; +import org.hisp.dhis.android.core.user.internal.UserCredentialsStore; +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; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.util.Arrays; + +import static com.google.common.truth.Truth.assertThat; +import static org.hisp.dhis.android.core.configuration.internal.DatabaseConfigurationMigration.OLD_DBNAME; + +@RunWith(D2JunitRunner.class) +public class DatabaseConfigurationMigrationIntegrationShould { + + private final Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); + private final DatabaseConfigurationTransformer transformer = new DatabaseConfigurationTransformer(); + private final DatabaseNameGenerator nameGenerator = new DatabaseNameGenerator(); + private final DatabaseRenamer renamer = new DatabaseRenamer(context); + private final DatabaseAdapterFactory databaseAdapterFactory = DatabaseAdapterFactory.create(context, + new InMemorySecureStore()); + + private final String URL_STR = "https://server.org/"; + private final String USERNAME = "usnm"; + private final String newName = nameGenerator.getDatabaseName(URL_STR, USERNAME, false); + + private DatabaseConfigurationMigration migration; + + private final UserCredentials credentials = UserCredentials.builder() + .id(1L) + .uid("uid") + .username(USERNAME) + .user(ObjectWithUid.create("user")) + .build(); + + private ObjectKeyValueStore newConfigurationStore; + + @Before + public void setUp() throws IOException { + InsecureStore insecureStore = new InMemoryUnsecureStore(); + newConfigurationStore = DatabaseConfigurationInsecureStore.get(insecureStore); + migration = new DatabaseConfigurationMigration(context, newConfigurationStore, + transformer, nameGenerator, renamer, databaseAdapterFactory); + } + + @Test + public void delete_empty_database() { + DatabaseAdapter databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, OLD_DBNAME, false); + + assertThat(Arrays.asList(context.databaseList()).contains(OLD_DBNAME)).isTrue(); + migration.apply(); + assertThat(Arrays.asList(context.databaseList()).contains(OLD_DBNAME)).isFalse(); + } + + @Test + public void rename_database_with_credentials() { + DatabaseAdapter databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, OLD_DBNAME, false); + setCredentialsAndServerUrl(databaseAdapter); + + assertThat(Arrays.asList(context.databaseList()).contains(OLD_DBNAME)).isTrue(); + migration.apply(); + assertThat(Arrays.asList(context.databaseList()).contains(OLD_DBNAME)).isFalse(); + assertThat(Arrays.asList(context.databaseList()).contains(newName)).isTrue(); + + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, newName, false); + UserCredentialsStore credentialsStore = UserCredentialsStoreImpl.create(databaseAdapter); + assertThat(credentialsStore.selectFirst()).isEqualTo(credentials); + } + + @Test + public void return_null_new_configuration_if_both_configurations_null() { + assertThat(migration.apply()).isNull(); + } + + @Test + public void return_existing_new_configuration_if_old_configuration_null() { + DatabasesConfiguration newConfiguration = new DatabaseConfigurationHelper(nameGenerator, + () -> "2014-06-06T20:44:21.375") + .setConfiguration(null, URL_STR, USERNAME, false); + newConfigurationStore.set(newConfiguration); + assertThat(migration.apply()).isSameAs(newConfiguration); + } + + @Test + public void return_empty_new_configuration_if_existing_empty_database() { + DatabaseAdapter databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, OLD_DBNAME, false); + assertThat(migration.apply()).isNull(); + } + + public void setCredentialsAndServerUrl(DatabaseAdapter databaseAdapter) { + databaseAdapter.setForeignKeyConstraintsEnabled(false); + + UserCredentialsStore credentialsStore = UserCredentialsStoreImpl.create(databaseAdapter); + credentialsStore.insert(credentials); + + ObjectStore configurationStore = ConfigurationStore.create(databaseAdapter); + configurationStore.insert(Configuration.forServerUrl(URL_STR)); + } +} \ No newline at end of file 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 21aa45a6a3..53f0fad89f 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.constant.ConstantTableInfo; import org.hisp.dhis.android.core.data.constant.ConstantSamples; import org.hisp.dhis.android.core.data.database.IdentifiableObjectStoreAbstractIntegrationShould; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class ConstantStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ConstantStoreIntegrationShould() { - super(ConstantStore.create(DatabaseAdapterFactory.get()), ConstantTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(ConstantStore.create(TestDatabaseAdapterFactory.get()), ConstantTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DatabaseAssert.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DatabaseAssert.java index dcf9969961..b7c767b703 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DatabaseAssert.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/DatabaseAssert.java @@ -74,7 +74,7 @@ public DatabaseAssert isNotEmptyTable(String tableName) { private void verifyEmptyDatabase(boolean expectedEmpty) { boolean isEmpty = true; - Cursor cursor = databaseAdapter.query(" SELECT name FROM sqlite_master " + Cursor cursor = databaseAdapter.rawQuery(" SELECT name FROM sqlite_master " + "WHERE type='table' and name!='android_metadata' and name!='sqlite_sequence'"); int value = cursor.getColumnIndex("name"); if (value != -1) { @@ -98,7 +98,7 @@ private int tableCount(String tableName) { int count; try { - cursor = databaseAdapter.query("SELECT COUNT(*) from " + tableName); + cursor = databaseAdapter.rawQuery("SELECT COUNT(*) from " + tableName); cursor.moveToFirst(); count = cursor.getInt(0); } finally { diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectStoreAbstractIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectStoreAbstractIntegrationShould.java index e44a67fcc1..e4f9287dd6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectStoreAbstractIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/ObjectStoreAbstractIntegrationShould.java @@ -74,8 +74,7 @@ public void insert_and_select_first_object() { @Test public void insert_as_content_values_and_select_first_object() { - long rowsInserted = databaseAdapter.database() - .insert(tableInfo.name(), null, object.toContentValues()); + long rowsInserted = databaseAdapter.insert(tableInfo.name(), null, object.toContentValues()); assertThat(rowsInserted).isEqualTo(1); M objectFromDb = store.selectFirst(); assertEqualsIgnoreId(objectFromDb); 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 02d0e2a3a7..9aefb2018b 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 @@ -28,11 +28,14 @@ package org.hisp.dhis.android.core.data.database.migrations; -import android.database.sqlite.SQLiteDatabase; +import android.content.Context; + +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.arch.db.access.DbOpenHelper; -import org.hisp.dhis.android.core.arch.db.access.internal.SqLiteDatabaseAdapter; +import org.hisp.dhis.android.core.arch.db.access.internal.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.arch.storage.internal.InMemorySecureStore; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValueTableInfo; import org.hisp.dhis.android.core.user.UserTableInfo; import org.junit.After; @@ -40,9 +43,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import androidx.test.InstrumentationRegistry; -import androidx.test.runner.AndroidJUnit4; - import static org.hamcrest.CoreMatchers.is; import static org.hisp.dhis.android.core.arch.db.access.SqliteCheckerUtility.ifTableExist; import static org.junit.Assert.assertThat; @@ -50,15 +50,11 @@ @RunWith(AndroidJUnit4.class) public class DataBaseMigrationShould { private DatabaseAdapter databaseAdapter; - private DbOpenHelper dbOpenHelper; private String dbName = null; - private SQLiteDatabase databaseInMemory; @Before public void deleteDB() { this.closeAndDeleteDatabase(); - dbOpenHelper = null; - databaseInMemory = null; } @After @@ -67,8 +63,8 @@ public void tearDown() { } private void closeAndDeleteDatabase() { - if (databaseInMemory != null) { - databaseInMemory.close(); + if (databaseAdapter != null) { + databaseAdapter.close(); } if (dbName != null) { InstrumentationRegistry.getContext().deleteDatabase(dbName); @@ -94,23 +90,10 @@ public void have_tracked_entity_attribute_reserved_value_table_after_first_migra } public DatabaseAdapter initCoreDataBase(int databaseVersion) { - if (databaseAdapter == null) { - dbOpenHelper = new DbOpenHelper( - InstrumentationRegistry.getTargetContext().getApplicationContext() - , dbName, databaseVersion); - databaseAdapter = new SqLiteDatabaseAdapter(dbOpenHelper); - databaseInMemory = databaseAdapter.database(); - } else if (dbName == null) { - if (databaseInMemory.getVersion() < databaseVersion) { - dbOpenHelper.onUpgrade(databaseInMemory, databaseInMemory.getVersion(), - databaseVersion); - databaseInMemory.setVersion(databaseVersion); - } else if (databaseInMemory.getVersion() > databaseVersion) { - dbOpenHelper.onDowngrade(databaseInMemory, databaseInMemory.getVersion(), - databaseVersion); - databaseInMemory.setVersion(databaseVersion); - } - } + Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); + DatabaseAdapterFactory databaseAdapterFactory = DatabaseAdapterFactory.create(context, new InMemorySecureStore()); + databaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(databaseAdapter, dbName, false, databaseVersion); return databaseAdapter; } } \ No newline at end of file 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 54c88eeff8..df80e8a6d1 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 @@ -31,9 +31,9 @@ public class RealServerMother { public static String url2_29 = "https://play.dhis2.org/2.29/"; public static String url2_30 = "https://play.dhis2.org/2.30/"; - public static String url2_31 = "https://play.dhis2.org/2.31.5/"; - public static String url2_32 = "https://play.dhis2.org/2.32.1/"; - public static String url2_33 = "https://play.dhis2.org/2.33dev/"; + public static String url2_31 = "https://play.dhis2.org/2.31.7/"; + public static String url2_32 = "https://play.dhis2.org/2.32.3/"; + public static String url2_33 = "https://play.dhis2.org/2.33.1/"; 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/internal/DataElementEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.java index 08e51a2d8a..a0895f0aab 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.java @@ -28,10 +28,10 @@ package org.hisp.dhis.android.core.dataelement.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; 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 a61472ed18..8273ee399c 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 @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.data.dataelement.DataElementOperandSamples; import org.hisp.dhis.android.core.dataelement.DataElementOperand; import org.hisp.dhis.android.core.dataelement.DataElementOperandTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,8 +42,8 @@ public class DataElementOperandStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public DataElementOperandStoreIntegrationShould() { - super(DataElementOperandStore.create(DatabaseAdapterFactory.get()), DataElementOperandTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(DataElementOperandStore.create(TestDatabaseAdapterFactory.get()), DataElementOperandTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override 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 b90867fa7a..a532d11210 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.dataelement.DataElementSamples; import org.hisp.dhis.android.core.dataelement.DataElement; import org.hisp.dhis.android.core.dataelement.DataElementTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class DataElementStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public DataElementStoreIntegrationShould() { - super(DataElementStore.create(DatabaseAdapterFactory.get()), DataElementTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(DataElementStore.create(TestDatabaseAdapterFactory.get()), DataElementTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override 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 89a56f00b9..79c1c1f90f 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 @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.data.dataset.DataInputPeriodSamples; import org.hisp.dhis.android.core.dataset.DataInputPeriod; import org.hisp.dhis.android.core.dataset.DataInputPeriodTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,7 +42,7 @@ public class DataInputPeriodLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public DataInputPeriodLinkStoreIntegrationShould() { - super(DataInputPeriodLinkStore.create(DatabaseAdapterFactory.get()), DataInputPeriodTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(DataInputPeriodLinkStore.create(TestDatabaseAdapterFactory.get()), DataInputPeriodTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 51264e07ff..288b886f2c 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 @@ -28,9 +28,9 @@ package org.hisp.dhis.android.core.dataset.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; @@ -43,7 +43,7 @@ public class DataSetCompleteRegistrationCallRealIntegrationShould extends BaseRe public void setUp() throws IOException { super.setUp(); - d2 = D2Factory.forDatabaseName("complete"); + d2 = D2Factory.forNewDatabase(); } // commented out since it is a flaky test that works against a real server. 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 1e57415041..c1bd8875f7 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 @@ -28,12 +28,12 @@ package org.hisp.dhis.android.core.dataset.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.common.State; import org.hisp.dhis.android.core.dataset.DataSetCompleteRegistration; import org.hisp.dhis.android.core.dataset.DataSetCompleteRegistrationCollectionRepository; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; 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 573f3b7e34..3216c0a958 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.dataset.DataSetCompulsoryDataElementOperandLinkSamples; import org.hisp.dhis.android.core.dataset.DataSetCompulsoryDataElementOperandLink; import org.hisp.dhis.android.core.dataset.DataSetCompulsoryDataElementOperandLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class DataSetCompulsoryDataElementOperandLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public DataSetCompulsoryDataElementOperandLinkStoreIntegrationShould() { - super(DataSetCompulsoryDataElementOperandLinkStore.create(DatabaseAdapterFactory.get()), - DataSetCompulsoryDataElementOperandLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(DataSetCompulsoryDataElementOperandLinkStore.create(TestDatabaseAdapterFactory.get()), + DataSetCompulsoryDataElementOperandLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 67b66cd76d..e9c7e37eee 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 @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.data.dataset.DataSetElementSamples; import org.hisp.dhis.android.core.dataset.DataSetElement; import org.hisp.dhis.android.core.dataset.DataSetElementLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,8 +42,8 @@ public class DataSetDataElementLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public DataSetDataElementLinkStoreIntegrationShould() { - super(DataSetDataElementLinkStore.create(DatabaseAdapterFactory.get()), DataSetElementLinkTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(DataSetDataElementLinkStore.create(TestDatabaseAdapterFactory.get()), DataSetElementLinkTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.java index 3faa584a4b..0134379fae 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.java @@ -28,11 +28,12 @@ package org.hisp.dhis.android.core.dataset.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.dataset.DataSet; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; +import org.mockito.internal.util.collections.Sets; import java.io.IOException; import java.util.List; @@ -55,7 +56,7 @@ public void setUp() throws IOException { } private Callable> createCall() { - return getD2DIComponent(d2).dataSetCallFactory().create(); + return getD2DIComponent(d2).dataSetCallFactory().create(Sets.newSet("lyLU2wR22tC", "BfMAe6Itzgt")); } // @Test 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 f809d7b7a4..713aca968e 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.dataset.DataSetOrganisationUnitLinkSamples; import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLink; import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class DataSetOrganisationUnitLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public DataSetOrganisationUnitLinkStoreIntegrationShould() { - super(DataSetOrganisationUnitLinkStore.create(DatabaseAdapterFactory.get()), - DataSetOrganisationUnitLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(DataSetOrganisationUnitLinkStore.create(TestDatabaseAdapterFactory.get()), + DataSetOrganisationUnitLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 44e775d03a..f8852ee05d 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.dataset.DataSetSamples; import org.hisp.dhis.android.core.dataset.DataSet; import org.hisp.dhis.android.core.dataset.DataSetTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class DataSetStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public DataSetStoreIntegrationShould() { - super(DataSetStore.create(DatabaseAdapterFactory.get()), DataSetTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(DataSetStore.create(TestDatabaseAdapterFactory.get()), DataSetTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override 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 a2286e493e..17e15d0a03 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.dataset.SectionDataElementLinkSamples; import org.hisp.dhis.android.core.dataset.SectionDataElementLink; import org.hisp.dhis.android.core.dataset.SectionDataElementLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class SectionDataElementLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public SectionDataElementLinkStoreIntegrationShould() { - super(SectionDataElementLinkStore.create(DatabaseAdapterFactory.get()), - SectionDataElementLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(SectionDataElementLinkStore.create(TestDatabaseAdapterFactory.get()), + SectionDataElementLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 1ea0061963..4237f0f758 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.dataset.SectionGreyedFieldsLinkSamples; import org.hisp.dhis.android.core.dataset.SectionGreyedFieldsLink; import org.hisp.dhis.android.core.dataset.SectionGreyedFieldsLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class SectionGreyedFieldsLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public SectionGreyedFieldsLinkStoreIntegrationShould() { - super(SectionGreyedFieldsLinkStore.create(DatabaseAdapterFactory.get()), - SectionGreyedFieldsLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(SectionGreyedFieldsLinkStore.create(TestDatabaseAdapterFactory.get()), + SectionGreyedFieldsLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 38585f1e93..0ca30c74b3 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.dataset.SectionSamples; import org.hisp.dhis.android.core.dataset.Section; import org.hisp.dhis.android.core.dataset.SectionTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class SectionStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould
{ public SectionStoreIntegrationShould() { - super(SectionStore.create(DatabaseAdapterFactory.get()), SectionTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(SectionStore.create(TestDatabaseAdapterFactory.get()), SectionTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueEndpointCallRealIntegrationShould.java index cad34977f5..3e5953a50e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/internal/DataValueEndpointCallRealIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.datavalue.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutor; @@ -35,7 +36,6 @@ import org.hisp.dhis.android.core.arch.handlers.internal.Handler; import org.hisp.dhis.android.core.arch.handlers.internal.ObjectWithoutUidHandlerImpl; import org.hisp.dhis.android.core.datavalue.DataValue; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; 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 363772cfd8..2b9e6763ae 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 @@ -28,11 +28,11 @@ package org.hisp.dhis.android.core.datavalue.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.common.State; import org.hisp.dhis.android.core.datavalue.DataValue; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallRealIntegrationShould.java index 9715b3c0e0..5a345a06af 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/domain/aggregated/data/AggregatedDataCallRealIntegrationShould.java @@ -28,9 +28,9 @@ package org.hisp.dhis.android.core.domain.aggregated.data; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; 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 34ddb824de..2f6a87010b 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 @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.data.enrollment.EnrollmentSamples; import org.hisp.dhis.android.core.enrollment.Enrollment; import org.hisp.dhis.android.core.enrollment.EnrollmentTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class EnrollmentStoreIntegrationShould extends IdentifiableDataObjectStoreAbstractIntegrationShould { public EnrollmentStoreIntegrationShould() { - super(EnrollmentStoreImpl.create(DatabaseAdapterFactory.get()), - EnrollmentTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(EnrollmentStoreImpl.create(TestDatabaseAdapterFactory.get()), + EnrollmentTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 index f780bd4c3a..44b48d3ae4 100644 --- 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 @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.event.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutor; @@ -36,7 +37,6 @@ 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.utils.integration.real.BaseRealIntegrationTest; import org.junit.Assert; import org.junit.Before; 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 index 00954cf3a1..3cf31d270d 100644 --- 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 @@ -30,12 +30,12 @@ import com.google.common.truth.Truth; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; 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 org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; 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 index feed95ee60..e230393074 100644 --- 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 @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.event.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.helpers.UidGenerator; @@ -40,7 +41,6 @@ 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.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; 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 b262fcc6c2..345e3f9a48 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 @@ -34,7 +34,7 @@ import org.hisp.dhis.android.core.event.Event; import org.hisp.dhis.android.core.event.EventStatus; import org.hisp.dhis.android.core.event.EventTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,8 +42,8 @@ public class EventStoreIntegrationShould extends IdentifiableDataObjectStoreAbstractIntegrationShould { public EventStoreIntegrationShould() { - super(EventStoreImpl.create(DatabaseAdapterFactory.get()), - EventTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(EventStoreImpl.create(TestDatabaseAdapterFactory.get()), + EventTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventWithLimitCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventWithLimitCallRealIntegrationShould.java index 6104908c42..f49020a00d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventWithLimitCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/internal/EventWithLimitCallRealIntegrationShould.java @@ -28,9 +28,9 @@ package org.hisp.dhis.android.core.event.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceCallRealIntegrationShould.java index 5051b57b4a..41ae47c8c6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceCallRealIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.fileresource.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.common.State; @@ -38,7 +39,6 @@ import org.hisp.dhis.android.core.fileresource.FileResource; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.File; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceStoreIntegrationShould.java index ffa645fff3..1b114896b2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.fileresource.FileResourceSamples; import org.hisp.dhis.android.core.fileresource.FileResource; import org.hisp.dhis.android.core.fileresource.FileResourceTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class FileResourceStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public FileResourceStoreIntegrationShould() { - super(FileResourceStoreImpl.create(DatabaseAdapterFactory.get()), - FileResourceTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(FileResourceStoreImpl.create(TestDatabaseAdapterFactory.get()), + FileResourceTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 919b9bc781..e4ead93f47 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.imports.TrackerImportConflictSamples; import org.hisp.dhis.android.core.imports.TrackerImportConflict; import org.hisp.dhis.android.core.imports.TrackerImportConflictTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class TrackerImportConflictStoreIntegrationShould extends ObjectStoreAbstractIntegrationShould { public TrackerImportConflictStoreIntegrationShould() { - super(TrackerImportConflictStore.create(DatabaseAdapterFactory.get()), - TrackerImportConflictTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(TrackerImportConflictStore.create(TestDatabaseAdapterFactory.get()), + TrackerImportConflictTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 3375ef6443..dca8b5c3a4 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.indicator.DataSetIndicatorLinkSamples; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLink; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class DataSetIndicatorLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public DataSetIndicatorLinkStoreIntegrationShould() { - super(DataSetIndicatorLinkStore.create(DatabaseAdapterFactory.get()), - DataSetIndicatorLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(DataSetIndicatorLinkStore.create(TestDatabaseAdapterFactory.get()), + DataSetIndicatorLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 51d1ee634c..f3d766ac7b 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 @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.data.indicator.IndicatorSamples; import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.indicator.IndicatorTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,7 +41,7 @@ public class IndicatorStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public IndicatorStoreIntegrationShould() { - super(IndicatorStore.create(DatabaseAdapterFactory.get()), IndicatorTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(IndicatorStore.create(TestDatabaseAdapterFactory.get()), IndicatorTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 8c26253cf4..b59103adeb 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 @@ -31,7 +31,7 @@ import org.hisp.dhis.android.core.data.database.LinkStoreAbstractIntegrationShould; import org.hisp.dhis.android.core.data.legendset.ProgramIndicatorLegendSetLinkSamples; import org.hisp.dhis.android.core.legendset.internal.ProgramIndicatorLegendSetLinkStore; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class ProgramIndicatorLegendSetLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public ProgramIndicatorLegendSetLinkStoreIntegrationShould() { - super(ProgramIndicatorLegendSetLinkStore.create(DatabaseAdapterFactory.get()), - ProgramIndicatorLegendSetLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramIndicatorLegendSetLinkStore.create(TestDatabaseAdapterFactory.get()), + ProgramIndicatorLegendSetLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 842e14633b..7108821913 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.legendset.LegendSetSamples; import org.hisp.dhis.android.core.legendset.LegendSet; import org.hisp.dhis.android.core.legendset.LegendSetTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,7 +40,7 @@ public class LegendSetStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public LegendSetStoreIntegrationShould() { - super(LegendSetStore.create(DatabaseAdapterFactory.get()), LegendSetTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(LegendSetStore.create(TestDatabaseAdapterFactory.get()), LegendSetTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 71e46bd186..df947cc636 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 @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.data.legendset.LegendSamples; import org.hisp.dhis.android.core.legendset.Legend; import org.hisp.dhis.android.core.legendset.LegendTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,7 +41,7 @@ public class LegendStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public LegendStoreIntegrationShould() { - super(LegendStore.create(DatabaseAdapterFactory.get()), LegendTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(LegendStore.create(TestDatabaseAdapterFactory.get()), LegendTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 540070ac13..f0c5f85630 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 @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.maintenance.D2ErrorSamples; import org.hisp.dhis.android.core.maintenance.D2Error; import org.hisp.dhis.android.core.maintenance.D2ErrorTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class D2ErrorStoreIntegrationShould extends ObjectStoreAbstractIntegrationShould { public D2ErrorStoreIntegrationShould() { - super(D2ErrorStore.create(DatabaseAdapterFactory.get()), - D2ErrorTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(D2ErrorStore.create(TestDatabaseAdapterFactory.get()), + D2ErrorTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override 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 index 3a6c041fb6..bd79b74ef9 100644 --- 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 @@ -28,136 +28,56 @@ package org.hisp.dhis.android.core.maintenance.internal; -import android.database.Cursor; - import androidx.test.runner.AndroidJUnit4; -import com.google.common.truth.Truth; - -import org.hisp.dhis.android.core.D2; -import org.hisp.dhis.android.core.D2Factory; -import org.hisp.dhis.android.core.arch.api.internal.ServerURLWrapper; 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.category.CategoryCategoryComboLink; -import org.hisp.dhis.android.core.category.CategoryCategoryComboLinkTableInfo; import org.hisp.dhis.android.core.common.IdentifiableColumns; import org.hisp.dhis.android.core.common.ObjectWithUid; -import org.hisp.dhis.android.core.data.server.Dhis2MockServer; 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.ProgramRuleActionTableInfo; import org.hisp.dhis.android.core.program.ProgramRuleActionType; -import org.hisp.dhis.android.core.program.ProgramRuleTableInfo; 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.real.BaseRealIntegrationTest; -import org.junit.After; +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyDispatcher; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor; +import static com.google.common.truth.Truth.assertThat; @RunWith(AndroidJUnit4.class) -public class ForeignKeyCleanerShould extends BaseRealIntegrationTest { +public class ForeignKeyCleanerShould extends BaseMockIntegrationTestEmptyDispatcher { - private Dhis2MockServer dhis2MockServer; - private D2 d2; - private final String[] USER_CREDENTIALS_PROJECTION = { - UserCredentialsTableInfo.Columns.UID, - UserCredentialsTableInfo.Columns.USER - }; - private final String[] PROGRAM_RULE_PROJECTION = { - IdentifiableColumns.UID - }; - private final String[] PROGRAM_RULE_ACTION_PROJECTION = { - IdentifiableColumns.UID - }; - - @Override @Before - public void setUp() throws IOException { - super.setUp(); - - dhis2MockServer = new Dhis2MockServer(); - ServerURLWrapper.setServerUrl(dhis2MockServer.getBaseEndpoint() + "api/"); - - d2 = D2Factory.forDatabaseAdapter(databaseAdapter()); - } - - @Override - @After - public void tearDown() throws IOException { - super.tearDown(); - - dhis2MockServer.shutdown(); + public void setUp() { + d2.databaseAdapter().delete(ForeignKeyViolationTableInfo.TABLE_INFO.name()); } @Test public void remove_rows_that_produce_foreign_key_errors() throws Exception { - syncMetadataAndAddFKViolation(); - - Cursor cursor = getUserCredentialsCursor(); - assertThatCursorHasRowCount(cursor, 1); - cursor.moveToFirst(); - - int uidColumnIndex = cursor.getColumnIndex(UserCredentialsTableInfo.Columns.UID); - Truth.assertThat(cursor.getString(uidColumnIndex)).isEqualTo("M0fCOxtkURr"); - int userColumnIndex = cursor.getColumnIndex(UserCredentialsTableInfo.Columns.USER); - Truth.assertThat(cursor.getString(userColumnIndex)).isEqualTo("DXyJmlo9rge"); - - assertThatCursor(cursor).isExhausted(); - cursor.close(); + addUserCredentialsForeignKeyViolation(); + UserCredentials userCredentials = d2.userModule().userCredentials().blockingGet(); + assertThat(userCredentials.uid()).isEqualTo("M0fCOxtkURr"); + assertThat(userCredentials.user().uid()).isEqualTo("DXyJmlo9rge"); } @Test - public void not_cause_null_records_on_fk_table() throws Exception { - final D2CallExecutor executor = D2CallExecutor.create(d2.databaseAdapter()); - - executor.executeD2CallTransactionally(() -> { - givenAMetadataInDatabase(); - - CategoryCategoryComboLink categoryCategoryComboLink = CategoryCategoryComboLink.builder() - .category("no_category") - .categoryCombo("no_category_combo") - .sortOrder(2) - .build(); - - d2.databaseAdapter().database().insert(CategoryCategoryComboLinkTableInfo.TABLE_INFO.name(), - null, categoryCategoryComboLink.toContentValues()); - - ForeignKeyCleanerImpl.create(d2.databaseAdapter()).cleanForeignKeyErrors(); - - return null; - }); - - List foreignKeyViolationList = - ForeignKeyViolationStore.create(d2.databaseAdapter()).selectAll(); - - Truth.assertThat(foreignKeyViolationList.size()).isEqualTo(3); - } + public void add_foreign_key_violation_to_table() throws Exception { + addUserCredentialsForeignKeyViolation(); - @Test - public void save_foreign_key_violations_when_some_errors_are_find() throws Exception { - syncMetadataAndAddFKViolation(); + assertThat(d2.maintenanceModule().foreignKeyViolations().blockingCount()).isEqualTo(1); - List foreignKeyViolationList = - ForeignKeyViolationStore.create(d2.databaseAdapter()).selectAll(); + ForeignKeyViolation foreignKeyViolation = d2.maintenanceModule().foreignKeyViolations().one().blockingGet(); - ForeignKeyViolation categoryOptionComboViolation = ForeignKeyViolation.builder() + ForeignKeyViolation expectedViolation = ForeignKeyViolation.builder() .toTable(UserTableInfo.TABLE_INFO.name()) .toColumn(IdentifiableColumns.UID) .fromTable(UserCredentialsTableInfo.TABLE_INFO.name()) @@ -166,32 +86,21 @@ public void save_foreign_key_violations_when_some_errors_are_find() throws Excep .fromObjectUid("user_credential_uid1") .build(); - List violationsToCompare = new ArrayList<>(); - for (ForeignKeyViolation violation : foreignKeyViolationList) { - violationsToCompare.add(violation.toBuilder().id(null).created(null).fromObjectRow(null).build()); - } + ForeignKeyViolation violationWithoutId = foreignKeyViolation.toBuilder() + .id(null) + .created(null) + .fromObjectRow(null) + .build(); - assertThat(violationsToCompare.contains(categoryOptionComboViolation), is(true)); - assertThat(violationsToCompare.contains(categoryOptionComboViolation), is(true)); + assertThat(expectedViolation).isEqualTo(violationWithoutId); } @Test - public void cascade_deletion_on_foreign_key_error() throws Exception { + 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"; - givenAMetadataInDatabase(); - - final Cursor programRuleCursor = getProgramRuleCursor(); - Cursor programRuleActionCursor = getProgramRuleActionCursor(); - - final Integer programRuleCount = programRuleCursor.getCount(); - final Integer programRuleActionCount = programRuleActionCursor.getCount(); - - programRuleCursor.close(); - programRuleActionCursor.close(); - final ObjectWithUid program = ObjectWithUid.create("nonexisent-program"); executor.executeD2CallTransactionally(() -> { @@ -207,36 +116,26 @@ public void cascade_deletion_on_foreign_key_error() throws Exception { ProgramRuleActionStore.create(d2.databaseAdapter()).insert(programRuleAction); - Cursor programRuleCursor1 = getProgramRuleCursor(); - Cursor programRuleActionCursor1 = getProgramRuleActionCursor(); - assertThatCursorHasRowCount(programRuleCursor1, programRuleCount + 1); - assertThatCursorHasRowCount(programRuleActionCursor1, programRuleActionCount + 1); - programRuleCursor1.close(); - programRuleActionCursor1.close(); + assertThat(d2.programModule().programRules().blockingCount()).isEqualTo(1); + assertThat(d2.programModule().programRuleActions().blockingCount()).isEqualTo(1); ForeignKeyCleaner foreignKeyCleaner = ForeignKeyCleanerImpl.create(d2.databaseAdapter()); Integer rowsAffected = foreignKeyCleaner.cleanForeignKeyErrors(); - Truth.assertThat(rowsAffected).isEqualTo(1); + assertThat(rowsAffected).isEqualTo(1); - Cursor programRuleCursor2 = getProgramRuleCursor(); - Cursor programRuleActionCursor2 = getProgramRuleActionCursor(); - assertThatCursorHasRowCount(programRuleCursor2, programRuleCount); - assertThatCursorHasRowCount(programRuleActionCursor2, programRuleActionCount); - programRuleCursor2.close(); - programRuleActionCursor2.close(); + assertThat(d2.programModule().programRules().blockingCount()).isEqualTo(0); + assertThat(d2.programModule().programRuleActions().blockingCount()).isEqualTo(0); return null; }); } - private void syncMetadataAndAddFKViolation() throws D2Error { - + private void addUserCredentialsForeignKeyViolation() throws D2Error { final D2CallExecutor executor = D2CallExecutor.create(d2.databaseAdapter()); executor.executeD2CallTransactionally(() -> { - givenAMetadataInDatabase(); ObjectWithUid user = ObjectWithUid.create("no_user_uid"); UserCredentials userCredentials = UserCredentials.builder() .id(2L) @@ -248,41 +147,9 @@ private void syncMetadataAndAddFKViolation() throws D2Error { UserCredentialsStoreImpl.create(d2.databaseAdapter()); userCredentialsStore.insert(userCredentials); - List ds = userCredentialsStore.selectAll(); - assertThat(ds.contains(userCredentials), is(true)); - ForeignKeyCleanerImpl.create(d2.databaseAdapter()).cleanForeignKeyErrors(); - assertThat(userCredentialsStore.selectAll().contains(userCredentials), is(false)); return null; }); } - - private void givenAMetadataInDatabase() { - try { - dhis2MockServer.setRequestDispatcher(); - d2.userModule().logIn(username, password, dhis2MockServer.getBaseEndpoint()); - d2.metadataModule().blockingDownload(); - } catch (Exception ignore) { - } - } - - private Cursor getUserCredentialsCursor() { - return database().query(UserCredentialsTableInfo.TABLE_INFO.name(), USER_CREDENTIALS_PROJECTION, - null, null, null, null, null); - } - - private Cursor getProgramRuleCursor() { - return database().query(ProgramRuleTableInfo.TABLE_INFO.name(), PROGRAM_RULE_PROJECTION, - null, null, null, null, null); - } - - private Cursor getProgramRuleActionCursor() { - return database().query(ProgramRuleActionTableInfo.TABLE_INFO.name(), PROGRAM_RULE_ACTION_PROJECTION, - null, null, null, null, null); - } - - private void assertThatCursorHasRowCount(Cursor cursor, int rowCount) { - Truth.assertThat(cursor.getCount()).isEqualTo(rowCount); - } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyViolationStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyViolationStoreIntegrationShould.java index 57bc3bd045..74619cb2ea 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyViolationStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/maintenance/internal/ForeignKeyViolationStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.maintenance.ForeignKeyViolationSamples; import org.hisp.dhis.android.core.maintenance.ForeignKeyViolation; import org.hisp.dhis.android.core.maintenance.ForeignKeyViolationTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class ForeignKeyViolationStoreIntegrationShould extends ObjectStoreAbstractIntegrationShould { public ForeignKeyViolationStoreIntegrationShould() { - super(ForeignKeyViolationStore.create(DatabaseAdapterFactory.get()), - ForeignKeyViolationTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ForeignKeyViolationStore.create(TestDatabaseAdapterFactory.get()), + ForeignKeyViolationTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/note/NotePostCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/note/NotePostCallRealIntegrationShould.java index df9ddab165..d72976d126 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/note/NotePostCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/note/NotePostCallRealIntegrationShould.java @@ -28,11 +28,11 @@ package org.hisp.dhis.android.core.note; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.data.server.RealServerMother; import org.hisp.dhis.android.core.enrollment.Enrollment; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; @@ -83,7 +83,8 @@ private void downloadUpdateAndSyncTei(String serverUrl) throws Exception { private void addNote() { Enrollment enrollment = d2.enrollmentModule().enrollments().one().blockingGet(); try { - d2.noteModule().notes().blockingAdd(NoteCreateProjection.create(enrollment.uid(), "New note")); + d2.noteModule().notes().blockingAdd(NoteCreateProjection.create( + Note.NoteType.ENROLLMENT_NOTE, enrollment.uid(), "New note")); } catch (Exception ignored) { } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/note/internal/NoteStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/note/internal/NoteStoreIntegrationShould.java new file mode 100644 index 0000000000..3d3888047f --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/note/internal/NoteStoreIntegrationShould.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004-2019, 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.note.internal; + +import org.hisp.dhis.android.core.common.State; +import org.hisp.dhis.android.core.data.database.IdentifiableObjectStoreAbstractIntegrationShould; +import org.hisp.dhis.android.core.data.note.NoteSamples; +import org.hisp.dhis.android.core.note.Note; +import org.hisp.dhis.android.core.note.NoteTableInfo; +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) +public class NoteStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { + + public NoteStoreIntegrationShould() { + super(NoteStore.create(TestDatabaseAdapterFactory.get()), + NoteTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); + } + + @Override + protected Note buildObject() { + return NoteSamples.getNote(); + } + + @Override + protected Note buildObjectToUpdate() { + return NoteSamples.getNote().toBuilder() + .state(State.SYNCED) + .build(); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/option/internal/OptionGroupOptionLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/option/internal/OptionGroupOptionLinkStoreIntegrationShould.java index 3c01e6a460..ab0c07a46b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/option/internal/OptionGroupOptionLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/option/internal/OptionGroupOptionLinkStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.option.OptionGroupOptionLinkSamples; import org.hisp.dhis.android.core.option.OptionGroupOptionLink; import org.hisp.dhis.android.core.option.OptionGroupOptionLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class OptionGroupOptionLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public OptionGroupOptionLinkStoreIntegrationShould() { - super(OptionGroupOptionLinkStore.create(DatabaseAdapterFactory.get()), - OptionGroupOptionLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(OptionGroupOptionLinkStore.create(TestDatabaseAdapterFactory.get()), + OptionGroupOptionLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/option/internal/OptionGroupStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/option/internal/OptionGroupStoreIntegrationShould.java index 153623f21f..2f04d32f7e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/option/internal/OptionGroupStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/option/internal/OptionGroupStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.option.OptionGroupSamples; import org.hisp.dhis.android.core.option.OptionGroup; import org.hisp.dhis.android.core.option.OptionGroupTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class OptionGroupStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public OptionGroupStoreIntegrationShould() { - super(OptionGroupStore.create(DatabaseAdapterFactory.get()), - OptionGroupTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(OptionGroupStore.create(TestDatabaseAdapterFactory.get()), + OptionGroupTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitCallMockIntegrationShould.java index e24194ecba..8277b4eb63 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitCallMockIntegrationShould.java @@ -30,25 +30,16 @@ import android.content.ContentValues; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - 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.arch.db.stores.internal.IdentifiableObjectStore; -import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore; +import org.hisp.dhis.android.core.arch.db.tableinfos.TableInfo; +import org.hisp.dhis.android.core.category.CategoryComboTableInfo; import org.hisp.dhis.android.core.common.IdentifiableColumns; -import org.hisp.dhis.android.core.common.Unit; import org.hisp.dhis.android.core.data.organisationunit.OrganisationUnitSamples; -import org.hisp.dhis.android.core.dataset.DataSet; -import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLink; -import org.hisp.dhis.android.core.dataset.internal.DataSetOrganisationUnitLinkStore; -import org.hisp.dhis.android.core.dataset.internal.DataSetStore; +import org.hisp.dhis.android.core.dataset.DataSetTableInfo; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLink; import org.hisp.dhis.android.core.program.ProgramTableInfo; -import org.hisp.dhis.android.core.program.internal.ProgramStore; -import org.hisp.dhis.android.core.program.internal.ProgramStoreInterface; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.user.UserInternalAccessor; import org.hisp.dhis.android.core.user.UserOrganisationUnitLink; @@ -57,6 +48,7 @@ import org.hisp.dhis.android.core.user.internal.UserOrganisationUnitLinkStoreImpl; import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyEnqueable; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -75,7 +67,7 @@ public class OrganisationUnitCallMockIntegrationShould extends BaseMockIntegrationTestEmptyEnqueable { //The return of the organisationUnitCall to be tested: - private Callable organisationUnitCall; + private Callable> organisationUnitCall; private OrganisationUnit expectedAfroArabicClinic = OrganisationUnitSamples.getAfroArabClinic(); private OrganisationUnit expectedAdonkiaCHP = OrganisationUnitSamples.getAdonkiaCHP(); @@ -97,16 +89,18 @@ public void setUp() throws IOException { User user = UserInternalAccessor.insertOrganisationUnits(User.builder(), organisationUnits) .uid("user_uid").build(); - database.insert(UserTableInfo.TABLE_INFO.name(), null, user.toContentValues()); + databaseAdapter.insert(UserTableInfo.TABLE_INFO.name(), null, user.toContentValues()); ContentValues userContentValues = new ContentValues(); userContentValues.put(IdentifiableColumns.UID, "user_uid"); - database.insert(UserTableInfo.TABLE_INFO.name(), null, userContentValues); + databaseAdapter.insert(UserTableInfo.TABLE_INFO.name(), null, userContentValues); // inserting programs for creating OrgUnitProgramLinks String programUid = "lxAQ7Zs9VYR"; - insertProgramWithUid(programUid); - Set programUids = Sets.newHashSet(Lists.newArrayList(programUid)); + insertObjectWithUid(programUid, ProgramTableInfo.TABLE_INFO); + + // inserting dataSets for creating OrgUnitDataSetLinks + insertDataSet(); OrganisationUnitHandler organisationUnitHandler = OrganisationUnitHandlerImpl.create(databaseAdapter); @@ -115,24 +109,33 @@ public void setUp() throws IOException { OrganisationUnitDisplayPathTransformer pathTransformer = new OrganisationUnitDisplayPathTransformer(); + organisationUnitCall = new OrganisationUnitCallFactory(organisationUnitService, + organisationUnitHandler, pathTransformer, apiCallExecutor, objects.resourceHandler) + .create(user); + } - ProgramStoreInterface programStore = ProgramStore.create(databaseAdapter); - IdentifiableObjectStore dataSetStore = DataSetStore.create(databaseAdapter); - LinkStore organisationUnitProgramLinkStore = - OrganisationUnitProgramLinkStore.create(databaseAdapter); - LinkStore dataSetOrganisationUnitLinkStore = - DataSetOrganisationUnitLinkStore.create(databaseAdapter); + @AfterClass + public static void tearDown() { + d2.databaseAdapter().delete(ProgramTableInfo.TABLE_INFO.name()); + d2.databaseAdapter().delete(DataSetTableInfo.TABLE_INFO.name()); + d2.databaseAdapter().delete(CategoryComboTableInfo.TABLE_INFO.name()); + } - organisationUnitCall = new OrganisationUnitCallFactory(organisationUnitService, - organisationUnitHandler, pathTransformer, apiCallExecutor, objects.resourceHandler, programStore, - dataSetStore, organisationUnitProgramLinkStore, dataSetOrganisationUnitLinkStore) - .create(user, programUids, Sets.newHashSet()); + private void insertObjectWithUid(String uid, TableInfo tableInfo) { + ContentValues contentValues = new ContentValues(); + contentValues.put(IdentifiableColumns.UID, uid); + databaseAdapter.insert(tableInfo.name(), null, contentValues); } - private void insertProgramWithUid(String uid) { - ContentValues program = new ContentValues(); - program.put(IdentifiableColumns.UID, uid); - database.insert(ProgramTableInfo.TABLE_INFO.name(), null, program); + private void insertDataSet() { + String dataSetUid = "lyLU2wR22tC"; + String categoryComboUid = "category_combo_uid"; + insertObjectWithUid(categoryComboUid, CategoryComboTableInfo.TABLE_INFO); + + ContentValues contentValues = new ContentValues(); + contentValues.put(IdentifiableColumns.UID, dataSetUid); + contentValues.put(DataSetTableInfo.Columns.CATEGORY_COMBO, categoryComboUid); + databaseAdapter.insert(DataSetTableInfo.TABLE_INFO.name(), null, contentValues); } @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitGroupStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitGroupStoreIntegrationShould.java index 500d19ab02..ed25e019d7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitGroupStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitGroupStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.organisationunit.OrganisationUnitGroupSamples; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitGroup; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitGroupTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class OrganisationUnitGroupStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public OrganisationUnitGroupStoreIntegrationShould() { - super(OrganisationUnitGroupStore.create(DatabaseAdapterFactory.get()), - OrganisationUnitGroupTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(OrganisationUnitGroupStore.create(TestDatabaseAdapterFactory.get()), + OrganisationUnitGroupTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitLevelStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitLevelStoreIntegrationShould.java index b3a494334d..13c5ea8328 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitLevelStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitLevelStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.organisationunit.OrganisationUnitLevelSamples; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitLevel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitLevelTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class OrganisationUnitLevelStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public OrganisationUnitLevelStoreIntegrationShould() { - super(OrganisationUnitLevelStore.create(DatabaseAdapterFactory.get()), - OrganisationUnitLevelTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(OrganisationUnitLevelStore.create(TestDatabaseAdapterFactory.get()), + OrganisationUnitLevelTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitOrganisationUnitGroupLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitOrganisationUnitGroupLinkStoreIntegrationShould.java index 2f49dae667..95e423e18e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitOrganisationUnitGroupLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitOrganisationUnitGroupLinkStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.organisationunit.OrganisationUnitOrganisationUnitGroupLinkSamples; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitOrganisationUnitGroupLink; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitOrganisationUnitGroupLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class OrganisationUnitOrganisationUnitGroupLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public OrganisationUnitOrganisationUnitGroupLinkStoreIntegrationShould() { - super(OrganisationUnitOrganisationUnitGroupLinkStore.create(DatabaseAdapterFactory.get()), - OrganisationUnitOrganisationUnitGroupLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(OrganisationUnitOrganisationUnitGroupLinkStore.create(TestDatabaseAdapterFactory.get()), + OrganisationUnitOrganisationUnitGroupLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitProgramLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitProgramLinkStoreIntegrationShould.java index 7e40169724..20d5763c96 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitProgramLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitProgramLinkStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.organisationunit.OrganisationUnitProgramLinkSamples; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLink; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class OrganisationUnitProgramLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public OrganisationUnitProgramLinkStoreIntegrationShould() { - super(OrganisationUnitProgramLinkStore.create(DatabaseAdapterFactory.get()), - OrganisationUnitProgramLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(OrganisationUnitProgramLinkStore.create(TestDatabaseAdapterFactory.get()), + OrganisationUnitProgramLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitStoreIntegrationShould.java index 790b2cfdba..4e8c5ca8e1 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.organisationunit.OrganisationUnitSamples; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class OrganisationUnitStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public OrganisationUnitStoreIntegrationShould() { - super(OrganisationUnitStore.create(DatabaseAdapterFactory.get()), - OrganisationUnitTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(OrganisationUnitStore.create(TestDatabaseAdapterFactory.get()), + OrganisationUnitTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodMockIntegrationShould.java index 67527df320..ae570c2b25 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodMockIntegrationShould.java @@ -46,9 +46,9 @@ public class PeriodMockIntegrationShould extends BaseMockIntegrationTestFullDisp @Test public void get_period_passing_period_type_and_a_date() throws ParseException { - Period period = d2.periodModule().periodHelper().getPeriod(PeriodType.BiWeekly, - BaseIdentifiableObject.DATE_FORMAT.parse("2019-12-24T12:24:25.319")); - assertThat(period.periodId()).isEqualTo("2019BiW26"); + Period period = d2.periodModule().periodHelper().blockingGetPeriodForPeriodTypeAndDate( + PeriodType.BiWeekly, BaseIdentifiableObject.DATE_FORMAT.parse("2019-07-08T12:24:25.319")); + assertThat(period.periodId()).isEqualTo("2019BiW14"); } @Test @@ -60,7 +60,8 @@ public void create_period_in_database_if_not_exist() throws ParseException { Period periodInDb = periodStore.selectPeriodByTypeAndDate(PeriodType.Monthly, date); assertThat(periodInDb).isNull(); - Period period = d2.periodModule().periodHelper().getPeriod(PeriodType.Monthly, date); + Period period = d2.periodModule().periodHelper().blockingGetPeriodForPeriodTypeAndDate( + PeriodType.Monthly, date); assertThat(period).isNotNull(); assertThat(period.periodId()).isEqualTo("201012"); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodParserMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodParserMockIntegrationShould.java new file mode 100644 index 0000000000..784f9084fd --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodParserMockIntegrationShould.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004-2019, 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.period; + +import com.google.common.collect.Lists; + +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyDispatcher; +import org.junit.AfterClass; + +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; + +public class PeriodParserMockIntegrationShould extends BaseMockIntegrationTestEmptyDispatcher { + + private final List PERIOD_ID_LIST = Lists.newArrayList( + "20200315", "2020W10", "2020W53", "2020WedW5", + "2020ThuW6", "2020SatW7", "2020SunW8", "2020BiW1", "202003","202012", + "202001B", "2020Q1","2020Q4", "2020S1", "2020AprilS1", "2020NovS1", "2020NovS2", "2020", + "2020April", "2020July", "2020Oct", "2020Nov"); + + @AfterClass + public static void tearDown() { + d2.databaseAdapter().delete(PeriodTableInfo.TABLE_INFO.name()); + } + + //@Test + public void get_period_passing_period_id() { + for (String periodId : PERIOD_ID_LIST) { + Period period = d2.periodModule().periodHelper().blockingGetPeriodForPeriodId(periodId); + assertThat(period.periodId()).isEqualTo(periodId); + } + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/period/internal/PeriodStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/period/internal/PeriodStoreIntegrationShould.java index 723c1f1950..b3c277ed50 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/period/internal/PeriodStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/period/internal/PeriodStoreIntegrationShould.java @@ -34,7 +34,7 @@ import org.hisp.dhis.android.core.period.Period; import org.hisp.dhis.android.core.period.PeriodTableInfo; import org.hisp.dhis.android.core.period.PeriodType; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,9 +50,9 @@ public class PeriodStoreIntegrationShould extends ObjectWithoutUidStoreAbstractI private PeriodStore periodStore; public PeriodStoreIntegrationShould() { - super(PeriodStoreImpl.create(DatabaseAdapterFactory.get()), PeriodTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); - this.periodStore = PeriodStoreImpl.create(DatabaseAdapterFactory.get()); + super(PeriodStoreImpl.create(TestDatabaseAdapterFactory.get()), PeriodTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); + this.periodStore = PeriodStoreImpl.create(TestDatabaseAdapterFactory.get()); } @Override @@ -69,8 +69,7 @@ protected Period buildObjectToUpdate() { @Test public void select_correct_period_passing_period_type_and_a_date() throws ParseException { - // Update date and periodId if they are outdated - new PeriodHandler(periodStore, ParentPeriodGeneratorImpl.create()).generateAndPersist(); + new PeriodHandler(periodStore, ParentPeriodGeneratorImpl.create(CalendarProviderFactory.createFixed())).generateAndPersist(); Period period = periodStore.selectPeriodByTypeAndDate(PeriodType.SixMonthly, BaseIdentifiableObject.DATE_FORMAT.parse("2019-03-02T12:24:25.319")); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorEngineIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorEngineIntegrationShould.java index 278107306e..e96ec1bfa2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorEngineIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorEngineIntegrationShould.java @@ -125,7 +125,7 @@ public void setUp() throws Exception { teiStore.insert(trackedEntityInstance); ContentValues categoryCombo = CreateCategoryComboUtils.create(1L, CategoryCombo.DEFAULT_UID); - database.insert(CategoryComboTableInfo.TABLE_INFO.name(), null, categoryCombo); + databaseAdapter.insert(CategoryComboTableInfo.TABLE_INFO.name(), null, categoryCombo); Access access = Access.create(true, null, DataAccess.create(true, true)); Program program = Program.builder().uid(programUid) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallMockIntegrationShould.java index fea78c362f..768193c090 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallMockIntegrationShould.java @@ -53,6 +53,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.internal.util.collections.Sets; import java.io.IOException; import java.util.List; @@ -102,26 +103,26 @@ public static void setUpClass() throws Exception { BaseMockIntegrationTestEmptyEnqueable.setUpClass(); ContentValues categoryCombo = CreateCategoryComboUtils.create(1L, "nM3u9s5a52V"); - database.insert(CategoryComboTableInfo.TABLE_INFO.name(), null, categoryCombo); + databaseAdapter.insert(CategoryComboTableInfo.TABLE_INFO.name(), null, categoryCombo); ContentValues categoryCombo2 = CreateCategoryComboUtils.create(2L, "x31y45jvIQL"); - database.insert(CategoryComboTableInfo.TABLE_INFO.name(), null, categoryCombo2); + databaseAdapter.insert(CategoryComboTableInfo.TABLE_INFO.name(), null, categoryCombo2); // inserting tracked entity ContentValues trackedEntityType = CreateTrackedEntityUtils.create(1L, "nEenWmSyUEp"); - database.insert(TrackedEntityTypeTableInfo.TABLE_INFO.name(), null, trackedEntityType); + databaseAdapter.insert(TrackedEntityTypeTableInfo.TABLE_INFO.name(), null, trackedEntityType); // inserting tracked entity attributes ContentValues trackedEntityAttribute1 = CreateTrackedEntityAttributeUtils.create(1L, "w75KJ2mc4zz", null); - database.insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute1); + databaseAdapter.insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute1); ContentValues trackedEntityAttribute2 = CreateTrackedEntityAttributeUtils.create(2L, "zDhUuAYrxNC", null); - database.insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute2); + databaseAdapter.insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute2); ContentValues trackedEntityAttribute3 = CreateTrackedEntityAttributeUtils.create(3L, "cejWyOfXge6", null); - database.insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute3); + databaseAdapter.insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute3); - programEndpointCall = objects.d2DIComponent.programCallFactory().create(); + programEndpointCall = objects.d2DIComponent.programCallFactory().create(Sets.newSet("IpHINAT79UW")); } @Before @@ -135,8 +136,7 @@ public void persist_program_when_call() throws Exception { // Fake call to api programEndpointCall.call(); - Cursor programCursor = database.query(ProgramTableInfo.TABLE_INFO.name(), PROGRAM_PROJECTION, - null, null, null, null, null); + Cursor programCursor = databaseAdapter.query(ProgramTableInfo.TABLE_INFO.name(), PROGRAM_PROJECTION); assertThatCursor(programCursor).hasRow( "IpHINAT79UW", @@ -188,8 +188,8 @@ public void persist_program_rule_variables_on_call() throws Exception { ProgramRuleVariableTableInfo.Columns.PROGRAM_RULE_VARIABLE_SOURCE_TYPE }; - Cursor programRuleVariableCursor = database.query(ProgramRuleVariableTableInfo.TABLE_INFO.name(), projection, - UID + "=?", new String[]{"g2GooOydipB"}, null, null, null); + Cursor programRuleVariableCursor = databaseAdapter.query(ProgramRuleVariableTableInfo.TABLE_INFO.name(), projection, + UID + "=?", new String[]{"g2GooOydipB"}); assertThatCursor(programRuleVariableCursor).hasRow( "g2GooOydipB", @@ -229,12 +229,11 @@ public void persist_program_tracker_entity_attributes_when_call() throws Excepti ProgramTrackedEntityAttributeTableInfo.Columns.SORT_ORDER }; - Cursor programTrackedEntityAttributeCursor = database.query( + Cursor programTrackedEntityAttributeCursor = databaseAdapter.query( ProgramTrackedEntityAttributeTableInfo.TABLE_INFO.name(), projection, UID + "=?", - new String[]{"l2T72XzBCLd"}, - null, null, null); + new String[]{"l2T72XzBCLd"}); assertThatCursor(programTrackedEntityAttributeCursor).hasRow( "l2T72XzBCLd", @@ -260,10 +259,10 @@ public void persist_program_tracker_entity_attributes_when_call() throws Excepti public void persist_program_indicators_when_call() throws Exception { programEndpointCall.call(); - Cursor programIndicatorCursor = database.query( + Cursor programIndicatorCursor = databaseAdapter.query( ProgramIndicatorTableInfo.TABLE_INFO.name(), ProgramIndicatorTableInfo.TABLE_INFO.columns().all(), - UID + "=?", new String[]{"rXoaHGAXWy9"}, null, null, null); + UID + "=?", new String[]{"rXoaHGAXWy9"}); assertThatCursor(programIndicatorCursor).hasRow( "rXoaHGAXWy9", null, @@ -292,10 +291,10 @@ public void persist_program_indicators_when_call() throws Exception { public void persist_legend_sets_when_call() throws Exception { programEndpointCall.call(); - Cursor programIndicatorCursor = database.query( + Cursor programIndicatorCursor = databaseAdapter.query( LegendSetTableInfo.TABLE_INFO.name(), LegendSetTableInfo.TABLE_INFO.columns().all(), - UID + "=?", new String[]{"TiOkbpGEud4"}, null, null, null); + UID + "=?", new String[]{"TiOkbpGEud4"}); assertThatCursor(programIndicatorCursor).hasRow( "TiOkbpGEud4", "AGE15YINT", @@ -311,10 +310,10 @@ public void persist_legend_sets_when_call() throws Exception { public void persist_legends_when_call() throws Exception { programEndpointCall.call(); - Cursor programIndicatorCursor = database.query( + Cursor programIndicatorCursor = databaseAdapter.query( LegendTableInfo.TABLE_INFO.name(), LegendTableInfo.TABLE_INFO.columns().all(), - UID + "=?", new String[]{"ZUUGJnvX40X"}, null, null, null); + UID + "=?", new String[]{"ZUUGJnvX40X"}); assertThatCursor(programIndicatorCursor).hasRow( "ZUUGJnvX40X", null, @@ -339,8 +338,7 @@ public void persist_legends_when_call() throws Exception { public void not_persist_relationship_type_when_call() throws Exception { programEndpointCall.call(); - Cursor relationshipTypeCursor = database.query(RelationshipTypeTableInfo.TABLE_INFO.name(), RelationshipTypeTableInfo.TABLE_INFO.columns().all(), - null, null, null, null, null); + Cursor relationshipTypeCursor = databaseAdapter.query(RelationshipTypeTableInfo.TABLE_INFO.name(), RelationshipTypeTableInfo.TABLE_INFO.columns().all()); assertThatCursor(relationshipTypeCursor).isExhausted(); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.java new file mode 100644 index 0000000000..dd2670ac09 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2004-2019, 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.program.internal; + +import org.hisp.dhis.android.core.BaseRealIntegrationTest; +import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.D2Factory; +import org.hisp.dhis.android.core.program.Program; +import org.junit.Before; +import org.mockito.internal.util.collections.Sets; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.Callable; + +public class ProgramEndpointCallRealIntegrationShould extends BaseRealIntegrationTest { + /** + * A quick integration test that is probably flaky, but will help with finding bugs related to the + * metadataSyncCall. It works against the demo server. + */ + private D2 d2; + private Callable> programCall; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + d2 = D2Factory.forNewDatabase(); + programCall = createCall(); + } + + private Callable> createCall() { + return getD2DIComponent(d2).programCallFactory().create(Sets.newSet("lxAQ7Zs9VYR", "AwNmMxxakEo")); + } + + // @Test + public void download_programs() throws Exception { + if (!d2.userModule().isLogged().blockingGet()) { + d2.userModule().logIn(username, password, url).blockingGet(); + } + + /* This test won't pass independently of DataElementEndpointCallFactory and + CategoryComboEndpointCallFactory, as the foreign keys constraints won't be satisfied. + To run the test, you will need to disable foreign key support in database in + DbOpenHelper.java replacing 'foreign_keys = ON' with 'foreign_keys = OFF' and + uncomment the @Test tag */ + + programCall.call(); + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorStoreIntegrationShould.java index e653d033fe..879d21ded5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramIndicatorSamples; import org.hisp.dhis.android.core.program.ProgramIndicator; import org.hisp.dhis.android.core.program.ProgramIndicatorTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,7 +40,7 @@ public class ProgramIndicatorStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramIndicatorStoreIntegrationShould() { - super(ProgramIndicatorStore.create(DatabaseAdapterFactory.get()), ProgramIndicatorTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramIndicatorStore.create(TestDatabaseAdapterFactory.get()), ProgramIndicatorTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramOrganisationUnitLastUpdatedStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramOrganisationUnitLastUpdatedStoreIntegrationShould.java index e61c3941a9..019627913b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramOrganisationUnitLastUpdatedStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramOrganisationUnitLastUpdatedStoreIntegrationShould.java @@ -30,7 +30,7 @@ import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould; import org.hisp.dhis.android.core.data.program.ProgramOrganisationUnitLastUpdatedSamples; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class ProgramOrganisationUnitLastUpdatedStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould { public ProgramOrganisationUnitLastUpdatedStoreIntegrationShould() { - super(ProgramOrganisationUnitLastUpdatedStore.create(DatabaseAdapterFactory.get()), - ProgramOrganisationUnitLastUpdatedTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramOrganisationUnitLastUpdatedStore.create(TestDatabaseAdapterFactory.get()), + ProgramOrganisationUnitLastUpdatedTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleActionStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleActionStoreIntegrationShould.java index ea4a056a44..967eaa9d47 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleActionStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleActionStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramRuleActionSamples; import org.hisp.dhis.android.core.program.ProgramRuleAction; import org.hisp.dhis.android.core.program.ProgramRuleActionTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class ProgramRuleActionStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramRuleActionStoreIntegrationShould() { - super(ProgramRuleActionStore.create(DatabaseAdapterFactory.get()), ProgramRuleActionTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(ProgramRuleActionStore.create(TestDatabaseAdapterFactory.get()), ProgramRuleActionTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleStoreIntegrationShould.java index e5e49c879a..cd92797a3e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramRuleSamples; import org.hisp.dhis.android.core.program.ProgramRule; import org.hisp.dhis.android.core.program.ProgramRuleTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class ProgramRuleStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramRuleStoreIntegrationShould() { - super(ProgramRuleStore.create(DatabaseAdapterFactory.get()), - ProgramRuleTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramRuleStore.create(TestDatabaseAdapterFactory.get()), + ProgramRuleTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleVariableStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleVariableStoreIntegrationShould.java index c7d716133f..6f6d5061f9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleVariableStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramRuleVariableStoreIntegrationShould.java @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.program.ProgramRuleVariable; import org.hisp.dhis.android.core.program.ProgramRuleVariableSourceType; import org.hisp.dhis.android.core.program.ProgramRuleVariableTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,8 +42,8 @@ public class ProgramRuleVariableStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramRuleVariableStoreIntegrationShould() { - super(ProgramRuleVariableStore.create(DatabaseAdapterFactory.get()), - ProgramRuleVariableTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramRuleVariableStore.create(TestDatabaseAdapterFactory.get()), + ProgramRuleVariableTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeLinkStoreIntegrationShould.java index f9f2100391..73adaec240 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramSectionAttributeLinkStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramSectionAttributeLinkSamples; import org.hisp.dhis.android.core.program.ProgramSectionAttributeLink; import org.hisp.dhis.android.core.program.ProgramSectionAttributeLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class ProgramSectionAttributeLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public ProgramSectionAttributeLinkStoreIntegrationShould() { - super(ProgramSectionAttributeLinkStore.create(DatabaseAdapterFactory.get()), - ProgramSectionAttributeLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramSectionAttributeLinkStore.create(TestDatabaseAdapterFactory.get()), + ProgramSectionAttributeLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramSectionStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramSectionStoreIntegrationShould.java index c830e13259..d46beefb59 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramSectionStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramSectionStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramSectionSamples; import org.hisp.dhis.android.core.program.ProgramSection; import org.hisp.dhis.android.core.program.ProgramSectionTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class ProgramSectionStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramSectionStoreIntegrationShould() { - super(ProgramSectionStore.create(DatabaseAdapterFactory.get()), - ProgramSectionTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramSectionStore.create(TestDatabaseAdapterFactory.get()), + ProgramSectionTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementStoreIntegrationShould.java index e45c302ebb..403e0ec55b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramStageDataElementSamples; import org.hisp.dhis.android.core.program.ProgramStageDataElement; import org.hisp.dhis.android.core.program.ProgramStageDataElementTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class ProgramStageDataElementStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramStageDataElementStoreIntegrationShould() { - super(ProgramStageDataElementStore.create(DatabaseAdapterFactory.get()), - ProgramStageDataElementTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramStageDataElementStore.create(TestDatabaseAdapterFactory.get()), + ProgramStageDataElementTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionDataElementLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionDataElementLinkStoreIntegrationShould.java index 3e6ca877d1..cbd28dcaab 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionDataElementLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionDataElementLinkStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramStageSectionDataElementLinkSamples; import org.hisp.dhis.android.core.program.ProgramStageSectionDataElementLink; import org.hisp.dhis.android.core.program.ProgramStageSectionDataElementLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class ProgramStageSectionDataElementLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public ProgramStageSectionDataElementLinkStoreIntegrationShould() { - super(ProgramStageSectionDataElementLinkStore.create(DatabaseAdapterFactory.get()), - ProgramStageSectionDataElementLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramStageSectionDataElementLinkStore.create(TestDatabaseAdapterFactory.get()), + ProgramStageSectionDataElementLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionStoreIntegrationShould.java index 8d84f5cb08..7321d5217d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramStageSectionSamples; import org.hisp.dhis.android.core.program.ProgramStageSection; import org.hisp.dhis.android.core.program.ProgramStageSectionTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,7 +41,7 @@ public class ProgramStageSectionStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramStageSectionStoreIntegrationShould() { - super(ProgramStageSectionStore.create(DatabaseAdapterFactory.get()), ProgramStageSectionTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramStageSectionStore.create(TestDatabaseAdapterFactory.get()), ProgramStageSectionTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageStoreIntegrationShould.java index 701ae47c15..9d79eaab69 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStageStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramStageSamples; import org.hisp.dhis.android.core.program.ProgramStage; import org.hisp.dhis.android.core.program.ProgramStageTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class ProgramStageStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramStageStoreIntegrationShould() { - super(ProgramStageStore.create(DatabaseAdapterFactory.get()), - ProgramStageTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramStageStore.create(TestDatabaseAdapterFactory.get()), + ProgramStageTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStoreIntegrationShould.java index 0d10b37994..1848a1da4b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramSamples; import org.hisp.dhis.android.core.program.Program; import org.hisp.dhis.android.core.program.ProgramTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,7 +40,7 @@ public class ProgramStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramStoreIntegrationShould() { - super(ProgramStore.create(DatabaseAdapterFactory.get()), ProgramTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramStore.create(TestDatabaseAdapterFactory.get()), ProgramTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramTrackedEntityAttributeStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramTrackedEntityAttributeStoreIntegrationShould.java index 01b865fc88..5e92f411c4 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramTrackedEntityAttributeStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramTrackedEntityAttributeStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.program.ProgramTrackedEntityAttributeSamples; import org.hisp.dhis.android.core.program.ProgramTrackedEntityAttribute; import org.hisp.dhis.android.core.program.ProgramTrackedEntityAttributeTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class ProgramTrackedEntityAttributeStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public ProgramTrackedEntityAttributeStoreIntegrationShould() { - super(ProgramTrackedEntityAttributeStore.create(DatabaseAdapterFactory.get()), - ProgramTrackedEntityAttributeTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(ProgramTrackedEntityAttributeStore.create(TestDatabaseAdapterFactory.get()), + ProgramTrackedEntityAttributeTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/RelationshipCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/RelationshipCollectionRepositoryMockIntegrationShould.java index e4f03a93f7..a0792a5aee 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/RelationshipCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/RelationshipCollectionRepositoryMockIntegrationShould.java @@ -110,4 +110,14 @@ public void get_by_item() { assertThat(relationships.size(), is(4)); } + @Test + public void filter_by_object_repository() { + Relationship relationship = + d2.relationshipModule().relationships() + .uid("AJOytZW7OaB") + .blockingGet(); + + assertThat(relationship.uid(), is("AJOytZW7OaB")); + } + } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipConstraintStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipConstraintStoreIntegrationShould.java index 20dda11a14..8ca8004f5f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipConstraintStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipConstraintStoreIntegrationShould.java @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.relationship.RelationshipConstraint; import org.hisp.dhis.android.core.relationship.RelationshipConstraintTableInfo; import org.hisp.dhis.android.core.relationship.RelationshipEntityType; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,8 +42,8 @@ public class RelationshipConstraintStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould { public RelationshipConstraintStoreIntegrationShould() { - super(RelationshipConstraintStore.create(DatabaseAdapterFactory.get()), - RelationshipConstraintTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(RelationshipConstraintStore.create(TestDatabaseAdapterFactory.get()), + RelationshipConstraintTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemStoreIntegrationShould.java index dd8dea735a..b6706d2ac1 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemStoreIntegrationShould.java @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.relationship.RelationshipItem; import org.hisp.dhis.android.core.relationship.RelationshipItemEvent; import org.hisp.dhis.android.core.relationship.RelationshipItemTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,8 +42,8 @@ public class RelationshipItemStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould { public RelationshipItemStoreIntegrationShould() { - super(RelationshipItemStoreImpl.create(DatabaseAdapterFactory.get()), - RelationshipItemTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(RelationshipItemStoreImpl.create(TestDatabaseAdapterFactory.get()), + RelationshipItemTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipStoreIntegrationShould.java index 07d3e35047..517337ea2c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/relationship/internal/RelationshipStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.relationship.RelationshipSamples; import org.hisp.dhis.android.core.relationship.Relationship; import org.hisp.dhis.android.core.relationship.RelationshipTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class RelationshipStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public RelationshipStoreIntegrationShould() { - super(RelationshipStoreImpl.create(DatabaseAdapterFactory.get()), - RelationshipTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(RelationshipStoreImpl.create(TestDatabaseAdapterFactory.get()), + RelationshipTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/resource/internal/ResourceStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/resource/internal/ResourceStoreIntegrationShould.java index 28ff6954b6..f0bb87e9c5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/resource/internal/ResourceStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/resource/internal/ResourceStoreIntegrationShould.java @@ -31,7 +31,7 @@ import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould; import org.hisp.dhis.android.core.data.resource.ResourceSamples; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,9 +46,9 @@ public class ResourceStoreIntegrationShould extends ObjectWithoutUidStoreAbstrac private ResourceStore store; public ResourceStoreIntegrationShould() { - super(ResourceStoreImpl.create(DatabaseAdapterFactory.get()), ResourceTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); - this.store = ResourceStoreImpl.create(DatabaseAdapterFactory.get()); + super(ResourceStoreImpl.create(TestDatabaseAdapterFactory.get()), ResourceTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); + this.store = ResourceStoreImpl.create(TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.java index dce48ed212..5e410c1ce9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.java @@ -43,44 +43,44 @@ public class SettingsModuleMockIntegrationShould extends BaseMockIntegrationTest @Test public void allow_access_to_system_setting() { - List systemSettings = d2.systemSettingModule().systemSetting().blockingGet(); + List systemSettings = d2.settingModule().systemSetting().blockingGet(); assertThat(systemSettings.size(), is(2)); } @Test public void allow_access_to_system_setting_filtered_by_key() { - List systemSettingsFlag = d2.systemSettingModule().systemSetting().byKey() + List systemSettingsFlag = d2.settingModule().systemSetting().byKey() .eq(SystemSetting.SystemSettingKey.FLAG).blockingGet(); assertThat(systemSettingsFlag.size(), is(1)); assertThat(systemSettingsFlag.get(0).value(), is("sierra_leone")); - List systemSettingsStyle = d2.systemSettingModule().systemSetting().byKey() + List systemSettingsStyle = d2.settingModule().systemSetting().byKey() .eq(SystemSetting.SystemSettingKey.STYLE).blockingGet(); assertThat(systemSettingsStyle.get(0).value(), is("light_blue/light_blue.css")); } @Test public void allow_access_to_system_setting_filtered_by_value() { - List systemSettingsFlag = d2.systemSettingModule().systemSetting().byValue() + List systemSettingsFlag = d2.settingModule().systemSetting().byValue() .eq("sierra_leone").blockingGet(); assertThat(systemSettingsFlag.size(), is(1)); assertThat(systemSettingsFlag.get(0).key(), is(SystemSetting.SystemSettingKey.FLAG)); - List systemSettingsStyle = d2.systemSettingModule().systemSetting().byValue() + List systemSettingsStyle = d2.settingModule().systemSetting().byValue() .eq("light_blue/light_blue.css").blockingGet(); assertThat(systemSettingsStyle.get(0).key(), is(SystemSetting.SystemSettingKey.STYLE)); } @Test public void allow_access_to_flag_settings() { - SystemSetting systemSetting = d2.systemSettingModule().systemSetting().flag().blockingGet(); + SystemSetting systemSetting = d2.settingModule().systemSetting().flag().blockingGet(); assertThat(systemSetting.key(), is(SystemSetting.SystemSettingKey.FLAG)); assertThat(systemSetting.value(), is("sierra_leone")); } @Test public void allow_access_to_style_settings() { - SystemSetting systemSetting = d2.systemSettingModule().systemSetting().style().blockingGet(); + SystemSetting systemSetting = d2.settingModule().systemSetting().style().blockingGet(); assertThat(systemSetting.key(), is(SystemSetting.SystemSettingKey.STYLE)); assertThat(systemSetting.value(), is("light_blue/light_blue.css")); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/DataSetSettingStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/DataSetSettingStoreIntegrationShould.java new file mode 100644 index 0000000000..3c6b90afc9 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/DataSetSettingStoreIntegrationShould.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2004-2019, 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.settings.internal; + +import org.hisp.dhis.android.core.data.database.ObjectStoreAbstractIntegrationShould; +import org.hisp.dhis.android.core.data.settings.DataSetSettingSamples; +import org.hisp.dhis.android.core.settings.DataSetSetting; +import org.hisp.dhis.android.core.settings.DataSetSettingTableInfo; +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) +public class DataSetSettingStoreIntegrationShould + extends ObjectStoreAbstractIntegrationShould { + + public DataSetSettingStoreIntegrationShould() { + super(DataSetSettingStore.create(TestDatabaseAdapterFactory.get()), DataSetSettingTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); + } + + @Override + protected DataSetSetting buildObject() { + return DataSetSettingSamples.getDataSetSetting(); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/GeneralSettingsStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/GeneralSettingsStoreIntegrationShould.java new file mode 100644 index 0000000000..00e1b7a576 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/GeneralSettingsStoreIntegrationShould.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2004-2019, 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.settings.internal; + +import org.hisp.dhis.android.core.data.database.ObjectStoreAbstractIntegrationShould; +import org.hisp.dhis.android.core.data.settings.GeneralSettingsSamples; +import org.hisp.dhis.android.core.settings.GeneralSettings; +import org.hisp.dhis.android.core.settings.GeneralSettingTableInfo; +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) +public class GeneralSettingsStoreIntegrationShould + extends ObjectStoreAbstractIntegrationShould { + + public GeneralSettingsStoreIntegrationShould() { + super(GeneralSettingStore.create(TestDatabaseAdapterFactory.get()), GeneralSettingTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); + } + + @Override + protected GeneralSettings buildObject() { + return GeneralSettingsSamples.getGeneralSettings(); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/ProgramSettingStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/ProgramSettingStoreIntegrationShould.java new file mode 100644 index 0000000000..19c1e5773e --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/ProgramSettingStoreIntegrationShould.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2004-2019, 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.settings.internal; + +import org.hisp.dhis.android.core.data.database.ObjectStoreAbstractIntegrationShould; +import org.hisp.dhis.android.core.data.settings.ProgramSettingSamples; +import org.hisp.dhis.android.core.settings.ProgramSetting; +import org.hisp.dhis.android.core.settings.ProgramSettingTableInfo; +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) +public class ProgramSettingStoreIntegrationShould + extends ObjectStoreAbstractIntegrationShould { + + public ProgramSettingStoreIntegrationShould() { + super(ProgramSettingStore.create(TestDatabaseAdapterFactory.get()), ProgramSettingTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); + } + + @Override + protected ProgramSetting buildObject() { + return ProgramSettingSamples.getProgramSetting(); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/SystemSettingStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/SystemSettingStoreIntegrationShould.java index f53edc2956..5f666286eb 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/SystemSettingStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/internal/SystemSettingStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.settings.SystemSettingSamples; import org.hisp.dhis.android.core.settings.SystemSetting; import org.hisp.dhis.android.core.settings.SystemSettingTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class SystemSettingStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould { public SystemSettingStoreIntegrationShould() { - super(SystemSettingStore.create(DatabaseAdapterFactory.get()), SystemSettingTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(SystemSettingStore.create(TestDatabaseAdapterFactory.get()), SystemSettingTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/DHISVersionsManagerRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/DHISVersionsManagerRealIntegrationShould.java index f02dde5631..be169f6812 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/DHISVersionsManagerRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/DHISVersionsManagerRealIntegrationShould.java @@ -28,10 +28,10 @@ package org.hisp.dhis.android.core.systeminfo; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.data.server.RealServerMother; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/SystemInfoCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/SystemInfoCallMockIntegrationShould.java index 7394dd2859..ac2154c574 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/SystemInfoCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/SystemInfoCallMockIntegrationShould.java @@ -59,7 +59,7 @@ public static void setUpClass() throws Exception { @Before public void setUp() { dhis2MockServer.enqueueMockResponse("systeminfo/system_info.json"); - database.delete(tableInfo.name(), "1", new String[]{}); + databaseAdapter.delete(tableInfo.name(), "1", new String[]{}); } @Test @@ -70,7 +70,7 @@ public void persist_system_info_when_call() { @Test public void update_system_info_when_call() { - database.insert(tableInfo.name(), null, systemInfoFromDB.toContentValues()); + databaseAdapter.insert(tableInfo.name(), null, systemInfoFromDB.toContentValues()); isSystemInfoInDb(systemInfoFromDB); systemInfoRepository.blockingDownload(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/internal/SystemInfoStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/internal/SystemInfoStoreIntegrationShould.java index 3020fe6d1c..fb6f7d9013 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/internal/SystemInfoStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/systeminfo/internal/SystemInfoStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.systeminfo.SystemInfoSamples; import org.hisp.dhis.android.core.systeminfo.SystemInfo; import org.hisp.dhis.android.core.systeminfo.SystemInfoTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class SystemInfoStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould { public SystemInfoStoreIntegrationShould() { - super(SystemInfoStore.create(DatabaseAdapterFactory.get()), SystemInfoTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(SystemInfoStore.create(TestDatabaseAdapterFactory.get()), SystemInfoTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManagerRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManagerRealIntegrationShould.java index cf83601f9a..01f364a27d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManagerRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManagerRealIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.trackedentity; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.call.factories.internal.QueryCallFactory; @@ -52,7 +53,6 @@ import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityAttributeReservedValueStore; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityAttributeReservedValueStoreInterface; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityAttributeStore; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -143,7 +143,7 @@ public void setUp() throws IOException { trackedEntityAttributeStore.updateOrInsert(TrackedEntityAttribute.builder().uid(ownerUid).pattern(pattern).build()); CategoryCombo categoryCombo = CategoryCombo.builder().uid(categoryComboUid).build(); - database().insert(CategoryComboTableInfo.TABLE_INFO.name(), null, categoryCombo.toContentValues()); + databaseAdapter().insert(CategoryComboTableInfo.TABLE_INFO.name(), null, categoryCombo.toContentValues()); Program program = Program.builder().uid(programUid).categoryCombo(ObjectWithUid.create(categoryCombo.uid())) .access(Access.create(null, null, DataAccess.create(true, true))).build(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallRealIntegrationShould.java index 1a32631906..9e94932861 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallRealIntegrationShould.java @@ -30,9 +30,9 @@ import com.google.common.truth.Truth; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/BreakTheGlassAPIShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/BreakTheGlassAPIShould.java index 0da3aa685d..88cc67a6f4 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/BreakTheGlassAPIShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/BreakTheGlassAPIShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.trackedentity.api; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutor; @@ -47,7 +48,6 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceInternalAccessor; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstancePayload; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceService; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/TrackedEntityInstanceAPIShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/TrackedEntityInstanceAPIShould.java index 5771eb4089..8b1e81adb9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/TrackedEntityInstanceAPIShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/TrackedEntityInstanceAPIShould.java @@ -30,6 +30,7 @@ import junit.framework.Assert; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutor; @@ -50,7 +51,6 @@ import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceFields; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstancePayload; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceService; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeReservedValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeReservedValueEndpointCallRealIntegrationShould.java index 32b6d11d72..082d0be8c4 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeReservedValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeReservedValueEndpointCallRealIntegrationShould.java @@ -28,11 +28,12 @@ package org.hisp.dhis.android.core.trackedentity.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; +import org.hisp.dhis.android.core.trackedentity.ReservedValueSummary; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValue; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; @@ -113,6 +114,18 @@ public void reserve_and_count() { assertThat(attributeAndOrgUnitCount).isEqualTo(numberToReserve); } + // @Test + public void retrieve_the_reserved_value_summaries() { + login(); + syncMetadata(); + d2.trackedEntityModule().reservedValueManager().blockingDownloadAllReservedValues(5); + + List reservedValueSummaries = + d2.trackedEntityModule().reservedValueManager().blockingGetReservedValueSummaries(); + + assertThat(reservedValueSummaries).isNotEmpty(); + } + private void login() { if (!d2.userModule().isLogged().blockingGet()) { d2.userModule().logIn(username, password, url).blockingGet(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeReservedValueStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeReservedValueStoreIntegrationShould.java index ca4a07b062..b688a8b6d3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeReservedValueStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeReservedValueStoreIntegrationShould.java @@ -28,11 +28,11 @@ package org.hisp.dhis.android.core.trackedentity.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.organisationunit.internal.OrganisationUnitStore; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValue; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeStoreIntegrationShould.java index 7fe9d28e64..be78ddd243 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.trackedentity.TrackedEntityAttributeSamples; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class TrackedEntityAttributeStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public TrackedEntityAttributeStoreIntegrationShould() { - super(TrackedEntityAttributeStore.create(DatabaseAdapterFactory.get()), - TrackedEntityAttributeTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(TrackedEntityAttributeStore.create(TestDatabaseAdapterFactory.get()), + TrackedEntityAttributeTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreIntegrationShould.java index 968238acac..fbdb369a34 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.trackedentity.TrackedEntityAttributeValueSamples; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class TrackedEntityAttributeValueStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould { public TrackedEntityAttributeValueStoreIntegrationShould() { - super(TrackedEntityAttributeValueStoreImpl.create(DatabaseAdapterFactory.get()), - TrackedEntityAttributeValueTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(TrackedEntityAttributeValueStoreImpl.create(TestDatabaseAdapterFactory.get()), + TrackedEntityAttributeValueTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreShould.java index 2bdd0bf7b4..d7c06b5a77 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueStoreShould.java @@ -30,12 +30,12 @@ import android.content.ContentValues; import android.database.Cursor; -import android.database.sqlite.SQLiteConstraintException; import androidx.test.runner.AndroidJUnit4; import com.google.common.collect.Lists; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.IdentifiableColumns; import org.hisp.dhis.android.core.data.organisationunit.OrganisationUnitSamples; @@ -50,7 +50,6 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueTableInfo.Columns; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceTableInfo; import org.hisp.dhis.android.core.trackedentity.TrackedEntityTypeTableInfo; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -108,12 +107,12 @@ public void setUp() throws IOException { ContentValues trackedEntityAttribute2 = CreateTrackedEntityAttributeUtils .create(2L, TRACKED_ENTITY_ATTRIBUTE_2, null); - database().insert(OrganisationUnitTableInfo.TABLE_INFO.name(), null, organisationUnit.toContentValues()); - database().insert(TrackedEntityTypeTableInfo.TABLE_INFO.name(), null, trackedEntityType); - database().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance); - database().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance_2); - database().insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute); - database().insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute2); + databaseAdapter().insert(OrganisationUnitTableInfo.TABLE_INFO.name(), null, organisationUnit.toContentValues()); + databaseAdapter().insert(TrackedEntityTypeTableInfo.TABLE_INFO.name(), null, trackedEntityType); + databaseAdapter().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance); + databaseAdapter().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance_2); + databaseAdapter().insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute); + databaseAdapter().insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute2); trackedEntityAttributeValue = TrackedEntityAttributeValue.builder() .value(VALUE).created(date).lastUpdated(date).trackedEntityAttribute(TRACKED_ENTITY_ATTRIBUTE) @@ -125,8 +124,7 @@ public void setUp() throws IOException { public void insert_tracked_entity_attribute_value_in_data_base_when_insert() { long rowId = trackedEntityAttributeValueStore.insert(trackedEntityAttributeValue); - Cursor cursor = database().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThat(rowId).isEqualTo(1L); assertThatCursor(cursor) @@ -140,7 +138,7 @@ public void insert_deferrable_tracked_entity_attribute_value_in_data_base_when_i final String deferredTrackedEntityAttribute = "deferredTrackedEntityAttribute"; final String deferredTrackedEntityInstance = "deferredTrackedEntityInstance"; - database().beginTransaction(); + databaseAdapter().beginNewTransaction(); long rowId = trackedEntityAttributeValueStore.insert(trackedEntityAttributeValue.toBuilder() .trackedEntityAttribute(deferredTrackedEntityAttribute) .trackedEntityInstance(deferredTrackedEntityInstance).build()); @@ -148,13 +146,12 @@ public void insert_deferrable_tracked_entity_attribute_value_in_data_base_when_i deferredTrackedEntityInstance, ORGANIZATION_UNIT, TRACKED_ENTITY); ContentValues trackedEntityAttribute = CreateTrackedEntityAttributeUtils.create(3L, deferredTrackedEntityAttribute, null); - database().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance); - database().insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute); - database().setTransactionSuccessful(); - database().endTransaction(); + databaseAdapter().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance); + databaseAdapter().insert(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), null, trackedEntityAttribute); + databaseAdapter().setTransactionSuccessful(); + databaseAdapter().endTransaction(); - Cursor cursor = database().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThat(rowId).isEqualTo(1L); assertThatCursor(cursor) @@ -167,9 +164,7 @@ public void insert_deferrable_tracked_entity_attribute_value_in_data_base_when_i public void insert_nullable_tracked_entity_attribute_value_in_data_base_when_insert_nullable_tracked_entity_attribute_value() { long rowId = trackedEntityAttributeValueStore.insert(trackedEntityAttributeValue.toBuilder().value(null).build()); - Cursor cursor = database().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), - PROJECTION, - null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThat(rowId).isEqualTo(1L); assertThatCursor(cursor) @@ -183,9 +178,7 @@ public void update_event_in_data_base_after_update() throws Exception { trackedEntityAttributeValueStore.insert(trackedEntityAttributeValue.toBuilder().value("0").build()); trackedEntityAttributeValueStore.updateOrInsertWhere(trackedEntityAttributeValue.toBuilder().value("4").build()); - Cursor cursor = database().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), PROJECTION, null, - null, null, - null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThatCursor(cursor).hasRow( "4", @@ -232,7 +225,7 @@ public void delete_tracked_entity_attribute_value_by_instance_and_attribute_uids trackedEntityAttributeValueStore.insert(trackedEntityAttributeValue.toBuilder().trackedEntityAttribute("wrong").build()); } - @Test(expected = SQLiteConstraintException.class) + @Test(expected = RuntimeException.class) public void throw_sqlite_constraint_exception_when_insert_tracked_entity_attribute_value_with_invalid_tracked_entity_instance() { trackedEntityAttributeValueStore.insert(trackedEntityAttributeValue.toBuilder().trackedEntityInstance("wrong").build()); @@ -243,12 +236,11 @@ public void delete_tracked_entity_attribute_value_by_instance_and_attribute_uids public void delete_tracked_entity_attribute_value_in_data_base_when_delete_tracked_entity_attribute() { insert_nullable_tracked_entity_attribute_value_in_data_base_when_insert_nullable_tracked_entity_attribute_value(); - database().delete(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), + databaseAdapter().delete(TrackedEntityAttributeTableInfo.TABLE_INFO.name(), IdentifiableColumns.UID + "=?", new String[]{TRACKED_ENTITY_ATTRIBUTE}); - Cursor cursor = database().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThatCursor(cursor).isExhausted(); } @@ -256,22 +248,21 @@ public void delete_tracked_entity_attribute_value_in_data_base_when_delete_track public void delete_tracked_entity_attribute_value_in_data_base_when_delete_tracked_entity_instance() { insert_nullable_tracked_entity_attribute_value_in_data_base_when_insert_nullable_tracked_entity_attribute_value(); - database().delete(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), + databaseAdapter().delete(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), TrackedEntityInstanceTableInfo.Columns.UID + "=?", new String[]{TRACKED_ENTITY_INSTANCE}); - Cursor cursor = database().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityAttributeValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThatCursor(cursor).isExhausted(); } - @Test(expected = SQLiteConstraintException.class) + @Test(expected = RuntimeException.class) public void throw_illegal_argument_exception_when_insert_null_tracked_entity_attribute() { trackedEntityAttributeValueStore.insert(trackedEntityAttributeValue.toBuilder().trackedEntityAttribute(null).build()); } - @Test(expected = SQLiteConstraintException.class) + @Test(expected = RuntimeException.class) public void throw_illegal_argument_exception_when_insert_null_tracked_entity_instance() { trackedEntityAttributeValueStore.insert(trackedEntityAttributeValue.toBuilder().trackedEntityInstance(null).build()); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreIntegrationShould.java index 64454780fa..d2bee4de7b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreIntegrationShould.java @@ -42,7 +42,7 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue; import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueTableInfo; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.After; import org.junit.Test; @@ -61,9 +61,9 @@ public class TrackedEntityDataValueStoreIntegrationShould protected TrackedEntityDataValueStore store; public TrackedEntityDataValueStoreIntegrationShould() { - super(TrackedEntityDataValueStoreImpl.create(DatabaseAdapterFactory.get()), - TrackedEntityDataValueTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); - this.store = TrackedEntityDataValueStoreImpl.create(DatabaseAdapterFactory.get()); + super(TrackedEntityDataValueStoreImpl.create(TestDatabaseAdapterFactory.get()), + TrackedEntityDataValueTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); + this.store = TrackedEntityDataValueStoreImpl.create(TestDatabaseAdapterFactory.get()); } @Override @@ -73,7 +73,7 @@ protected TrackedEntityDataValue buildObject() { @After public void tearDown() { - EventStoreImpl.create(DatabaseAdapterFactory.get()).delete(); + EventStoreImpl.create(TestDatabaseAdapterFactory.get()).delete(); } @Override @@ -124,7 +124,7 @@ public void select_data_values_by_event_uid() { @Test public void select_single_events_data_values() { - EventStore eventStore = EventStoreImpl.create(DatabaseAdapterFactory.get()); + EventStore eventStore = EventStoreImpl.create(TestDatabaseAdapterFactory.get()); eventStore.insert(EventSamples.get().toBuilder().uid("event_1").enrollment(null).state(State.TO_POST).build()); eventStore.insert(EventSamples.get().toBuilder().uid("event_2").state(State.TO_POST).build()); assertThat(eventStore.count()).isEqualTo(2); @@ -148,17 +148,17 @@ public void select_single_events_data_values() { @Test public void select_tracker_data_values() { TrackedEntityInstanceStore trackedEntityInstanceStore = TrackedEntityInstanceStoreImpl - .create(DatabaseAdapterFactory.get()); + .create(TestDatabaseAdapterFactory.get()); TrackedEntityInstance trackedEntityInstance = TrackedEntityInstance.builder().uid("tei_uid") .organisationUnit("organisation_unit_uid").trackedEntityType("tei_type").state(State.TO_POST).build(); trackedEntityInstanceStore.insert(trackedEntityInstance); - EnrollmentStore enrollmentStore = EnrollmentStoreImpl.create(DatabaseAdapterFactory.get()); + EnrollmentStore enrollmentStore = EnrollmentStoreImpl.create(TestDatabaseAdapterFactory.get()); Enrollment enrollment = Enrollment.builder().uid("enrollment").organisationUnit("organisation_unit") .program("program").trackedEntityInstance("tei_uid").state(State.TO_POST).build(); enrollmentStore.insert(enrollment); - EventStore eventStore = EventStoreImpl.create(DatabaseAdapterFactory.get()); + EventStore eventStore = EventStoreImpl.create(TestDatabaseAdapterFactory.get()); eventStore.insert(EventSamples.get().toBuilder().uid("event_1").state(State.TO_POST).build()); eventStore.insert(EventSamples.get().toBuilder().uid("event_2").enrollment(null).state(State.TO_POST).build()); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreShould.java index 55bb2682f7..88feaa00b0 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueStoreShould.java @@ -30,10 +30,10 @@ import android.content.ContentValues; import android.database.Cursor; -import android.database.sqlite.SQLiteConstraintException; import androidx.test.runner.AndroidJUnit4; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.category.CategoryCombo; import org.hisp.dhis.android.core.category.CategoryComboTableInfo; import org.hisp.dhis.android.core.category.internal.CreateCategoryComboUtils; @@ -61,7 +61,6 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueTableInfo.Columns; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceTableInfo; import org.hisp.dhis.android.core.trackedentity.TrackedEntityTypeTableInfo; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -152,20 +151,20 @@ public void setUp() throws IOException { ContentValues dataElement1 = CreateDataElementUtils.create(1L, DATA_ELEMENT_1, CategoryCombo.DEFAULT_UID, null); ContentValues dataElement2 = CreateDataElementUtils.create(2L, DATA_ELEMENT_2, CategoryCombo.DEFAULT_UID, null); - database().insert(TrackedEntityTypeTableInfo.TABLE_INFO.name(), null, trackedEntityType); - database().insert(RelationshipTypeTableInfo.TABLE_INFO.name(), null, + databaseAdapter().insert(TrackedEntityTypeTableInfo.TABLE_INFO.name(), null, trackedEntityType); + databaseAdapter().insert(RelationshipTypeTableInfo.TABLE_INFO.name(), null, relationshipType); - database().insert(ProgramTableInfo.TABLE_INFO.name(), null, program); - database().insert(OrganisationUnitTableInfo.TABLE_INFO.name(), null, organisationUnit.toContentValues()); - database().insert(ProgramStageTableInfo.TABLE_INFO.name(), null, programStage); - database().insert(CategoryComboTableInfo.TABLE_INFO.name(), null, defaultCategoryCombo); - database().insert(DataElementTableInfo.TABLE_INFO.name(), null, dataElement1); - database().insert(DataElementTableInfo.TABLE_INFO.name(), null, dataElement2); - database().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, + databaseAdapter().insert(ProgramTableInfo.TABLE_INFO.name(), null, program); + databaseAdapter().insert(OrganisationUnitTableInfo.TABLE_INFO.name(), null, organisationUnit.toContentValues()); + databaseAdapter().insert(ProgramStageTableInfo.TABLE_INFO.name(), null, programStage); + databaseAdapter().insert(CategoryComboTableInfo.TABLE_INFO.name(), null, defaultCategoryCombo); + databaseAdapter().insert(DataElementTableInfo.TABLE_INFO.name(), null, dataElement1); + databaseAdapter().insert(DataElementTableInfo.TABLE_INFO.name(), null, dataElement2); + databaseAdapter().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance); - database().insert(EnrollmentTableInfo.TABLE_INFO.name(), null, enrollment); - database().insert(EventTableInfo.TABLE_INFO.name(), null, event1); - database().insert(EventTableInfo.TABLE_INFO.name(), null, event2); + databaseAdapter().insert(EnrollmentTableInfo.TABLE_INFO.name(), null, enrollment); + databaseAdapter().insert(EventTableInfo.TABLE_INFO.name(), null, event1); + databaseAdapter().insert(EventTableInfo.TABLE_INFO.name(), null, event2); trackedEntityDataValue = TrackedEntityDataValue.builder() .event(EVENT_1) @@ -181,8 +180,7 @@ public void setUp() throws IOException { @Test public void insert_tracked_entity_data_value_in_data_base_when_insert() { long rowId = trackedEntityDataValueStore.insert(trackedEntityDataValue); - Cursor cursor = database().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThat(rowId).isEqualTo(1L); assertThatCursor(cursor).hasRow( EVENT_1, @@ -205,8 +203,7 @@ public void insert_nullable_tracked_entity_data_value_in_data_base_when_insert_n .value(null) .providedElsewhere(null).build()); - Cursor cursor = database().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThat(rowId).isEqualTo(1L); assertThatCursor(cursor).hasRow(EVENT_1, null, null, DATA_ELEMENT_1, null, null, @@ -218,11 +215,10 @@ public void insert_nullable_tracked_entity_data_value_in_data_base_when_insert_n public void delete_tracked_entity_data_value_when_delete_event_foreign_key() { trackedEntityDataValueStore.insert(trackedEntityDataValue); - database().delete(EventTableInfo.TABLE_INFO.name(), EventTableInfo.Columns.UID + "=?", + databaseAdapter().delete(EventTableInfo.TABLE_INFO.name(), EventTableInfo.Columns.UID + "=?", new String[]{EVENT_1}); - Cursor cursor = database().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThatCursor(cursor).isExhausted(); cursor.close(); } @@ -232,12 +228,11 @@ public void delete_tracked_entity_data_value_when_delete_event_foreign_key() { public void delete_tracked_entity_data_value_when_delete_data_element_foreign_key() { trackedEntityDataValueStore.insert(trackedEntityDataValue); - database().delete(DataElementTableInfo.TABLE_INFO.name(), + databaseAdapter().delete(DataElementTableInfo.TABLE_INFO.name(), IdentifiableColumns.UID + "=?", new String[]{DATA_ELEMENT_1}); - Cursor cursor = database().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThatCursor(cursor).isExhausted(); cursor.close(); } @@ -248,10 +243,10 @@ public void return_list_of_tracked_entity_data_value_when_query_tracked_entity_d String[] projection = {Columns.EVENT}; Cursor cursor = - database().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), + databaseAdapter().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), projection, Columns.EVENT + "=?", - new String[]{EVENT_1}, null, null, null); + new String[]{EVENT_1}); assertThatCursor(cursor).hasRow(EVENT_1).isExhausted(); cursor.close(); @@ -273,7 +268,7 @@ public void return_list_of_tracked_entity_data_value_when_query_tracked_entity_d } - @Test(expected = SQLiteConstraintException.class) + @Test(expected = RuntimeException.class) public void throw_illegal_argument_exception_when_insert_tracked_entity_data_value_with_invalid_event() { trackedEntityDataValueStore.insert(trackedEntityDataValue.toBuilder().event("wrong").build()); } @@ -295,8 +290,7 @@ public void update_tracked_entity_data_value() { trackedEntityDataValueStore.updateWhere(trackedEntityDataValue); - Cursor cursor = database().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), - PROJECTION, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityDataValueTableInfo.TABLE_INFO.name(), PROJECTION); assertThatCursor(cursor).hasRow(EVENT_1, dateString, diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceCallMockIntegrationShould.java index 3b1b362ce8..5817f3be18 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceCallMockIntegrationShould.java @@ -36,7 +36,7 @@ import org.hisp.dhis.android.core.arch.api.payload.internal.Payload; import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; -import org.hisp.dhis.android.core.data.file.ResourcesFileReader; +import org.hisp.dhis.android.core.arch.file.ResourcesFileReader; import org.hisp.dhis.android.core.enrollment.Enrollment; import org.hisp.dhis.android.core.enrollment.EnrollmentInternalAccessor; import org.hisp.dhis.android.core.enrollment.EnrollmentTableInfo; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstancePostCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstancePostCallRealIntegrationShould.java index cb73b8d791..fa5ecd9a45 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstancePostCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstancePostCallRealIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.trackedentity.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.call.D2Progress; @@ -59,7 +60,6 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue; import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; @@ -350,10 +350,11 @@ public void post_new_relationship_to_client_created_tei() throws Exception { List responseTeiB = d2.trackedEntityModule().trackedEntityInstances().byUid().eq(teiBUid).blockingGet(); assertThat(responseTeiB.size() == 1).isTrue(); - List relationships = d2.relationshipModule().relationships().getByItem(RelationshipHelper.teiItem(teiA.uid())); + List relationships = + d2.relationshipModule().relationships().getByItem(RelationshipHelper.teiItem(teiA.uid()), true); assertThat(relationships.size() > 0).isTrue(); - Boolean relationshipFound = false; + boolean relationshipFound = false; for (Relationship relationship : relationships) { if (!relationshipType.uid().equals(relationship.relationshipType())) { break; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceStoreIntegrationShould.java index c3e0f3457a..1be569d35c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceStoreIntegrationShould.java @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.data.trackedentity.TrackedEntityInstanceSamples; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,8 +42,8 @@ public class TrackedEntityInstanceStoreIntegrationShould extends IdentifiableDataObjectStoreAbstractIntegrationShould { public TrackedEntityInstanceStoreIntegrationShould() { - super(TrackedEntityInstanceStoreImpl.create(DatabaseAdapterFactory.get()), - TrackedEntityInstanceTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(TrackedEntityInstanceStoreImpl.create(TestDatabaseAdapterFactory.get()), + TrackedEntityInstanceTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceStoreShould.java index a44f9f2dd4..389b67bdc0 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceStoreShould.java @@ -30,10 +30,10 @@ import android.content.ContentValues; import android.database.Cursor; -import android.database.sqlite.SQLiteConstraintException; import androidx.test.runner.AndroidJUnit4; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.common.DataColumns; import org.hisp.dhis.android.core.common.FeatureType; import org.hisp.dhis.android.core.common.Geometry; @@ -47,7 +47,6 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceTableInfo; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceTableInfo.Columns; import org.hisp.dhis.android.core.trackedentity.TrackedEntityTypeTableInfo; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -101,8 +100,8 @@ public void setUp() throws IOException { trackedEntityInstanceStore = TrackedEntityInstanceStoreImpl.create(databaseAdapter()); OrganisationUnit organisationUnit = OrganisationUnitSamples.getOrganisationUnit(ORGANISATION_UNIT); ContentValues trackedEntityType = CreateTrackedEntityUtils.create(1L, TRACKED_ENTITY); - database().insert(OrganisationUnitTableInfo.TABLE_INFO.name(), null, organisationUnit.toContentValues()); - database().insert(TrackedEntityTypeTableInfo.TABLE_INFO.name(), null, trackedEntityType); + databaseAdapter().insert(OrganisationUnitTableInfo.TABLE_INFO.name(), null, organisationUnit.toContentValues()); + databaseAdapter().insert(TrackedEntityTypeTableInfo.TABLE_INFO.name(), null, trackedEntityType); trackedEntityInstance = TrackedEntityInstance.builder() .uid(UID) .created(date) @@ -120,12 +119,11 @@ public void setUp() throws IOException { public void delete_tei_in_data_base_when_delete_organisation_unit_foreign_key() { trackedEntityInstanceStore.insert(trackedEntityInstance); - database().delete(OrganisationUnitTableInfo.TABLE_INFO.name(), + databaseAdapter().delete(OrganisationUnitTableInfo.TABLE_INFO.name(), IdentifiableColumns.UID + "=?", new String[]{ ORGANISATION_UNIT }); - Cursor cursor = database().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), PROJECTION, null, null, - null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), PROJECTION); assertThatCursor(cursor).isExhausted(); } @@ -133,12 +131,11 @@ public void delete_tei_in_data_base_when_delete_organisation_unit_foreign_key() public void delete_tracked_entity_instance_in_data_base_when_delete_tracked_entity_foreign_key() { trackedEntityInstanceStore.insert(trackedEntityInstance); - database().delete(TrackedEntityTypeTableInfo.TABLE_INFO.name(), + databaseAdapter().delete(TrackedEntityTypeTableInfo.TABLE_INFO.name(), TrackedEntityTypeTableInfo.Columns.UID + "=?", new String[]{ TRACKED_ENTITY} ); - Cursor cursor = database().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), PROJECTION, null, null, - null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), PROJECTION); assertThatCursor(cursor).isExhausted(); } @@ -150,7 +147,7 @@ public void update_set_state_in_data_base_when_update_tracked_entity_instance_st trackedEntityInstance.put(Columns.TRACKED_ENTITY_TYPE, TRACKED_ENTITY); trackedEntityInstance.put(DataColumns.STATE, STATE.name()); - database().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance); + databaseAdapter().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstance); String[] projection = { Columns.UID, @@ -159,13 +156,13 @@ public void update_set_state_in_data_base_when_update_tracked_entity_instance_st DataColumns.STATE }; - Cursor cursor = database().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), projection, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), projection); // check that tracked entity instance was successfully inserted assertThatCursor(cursor).hasRow(UID, ORGANISATION_UNIT, TRACKED_ENTITY, STATE).isExhausted(); State updatedState = State.SYNCED; trackedEntityInstanceStore.setState(UID, updatedState); - cursor = database().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), projection, null, null, null, null, null); + cursor = databaseAdapter().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), projection); // check that trackedEntityInstance is updated with updated state assertThatCursor(cursor).hasRow(UID, ORGANISATION_UNIT, TRACKED_ENTITY, updatedState).isExhausted(); @@ -178,10 +175,10 @@ public void return_list_of_tracked_entity_instance_when_query() throws Exception trackedEntityInstanceContentValues.put(Columns.ORGANISATION_UNIT, ORGANISATION_UNIT); trackedEntityInstanceContentValues.put(Columns.TRACKED_ENTITY_TYPE, TRACKED_ENTITY); trackedEntityInstanceContentValues.put(DataColumns.STATE, State.TO_POST.name()); - database().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstanceContentValues); + databaseAdapter().insert(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), null, trackedEntityInstanceContentValues); String[] projection = {Columns.UID}; - Cursor cursor = database().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), projection, null, null, null, null, null); + Cursor cursor = databaseAdapter().query(TrackedEntityInstanceTableInfo.TABLE_INFO.name(), projection); // verify that tei was successfully inserted into database assertThatCursor(cursor).hasRow(UID).isExhausted(); @@ -200,22 +197,16 @@ public void return_list_of_tracked_entity_instance_when_query() throws Exception } - @Test(expected = SQLiteConstraintException.class) + @Test(expected = RuntimeException.class) public void throw_sqlite_constraint_exception_when_insert_tracked_entity_instance_with_invalid_org_unit_foreign_key() { trackedEntityInstanceStore.insert(trackedEntityInstance.toBuilder().organisationUnit("wrong").build()); } - @Test(expected = SQLiteConstraintException.class) + @Test(expected = RuntimeException.class) public void throw_sqlite_constraint_exception_when_insert_tracked_entity_instance_with_invalid_tracked_entity_foreign_key() { trackedEntityInstanceStore.insert(trackedEntityInstance.toBuilder().trackedEntityType("wrong").build()); } - // ToDo: consider introducing conflict resolution strategy - @Test - public void not_close_data_base_on_close() { - assertThat(database().isOpen()).isTrue(); - } - @Test(expected = IllegalStateException.class) public void throw_sqlite_constraint_exception_when_insert_null_uid() { trackedEntityInstanceStore.insert(trackedEntityInstance.toBuilder().uid(null).build()); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeAttributeStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeAttributeStoreIntegrationShould.java index 413c958c75..faa1466352 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeAttributeStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeAttributeStoreIntegrationShould.java @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.data.trackedentity.TrackedEntityTypeAttributeSamples; import org.hisp.dhis.android.core.trackedentity.TrackedEntityTypeAttribute; import org.hisp.dhis.android.core.trackedentity.TrackedEntityTypeAttributeTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -42,8 +42,8 @@ public class TrackedEntityTypeAttributeStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public TrackedEntityTypeAttributeStoreIntegrationShould() { - super(TrackedEntityTypeAttributeStore.create(DatabaseAdapterFactory.get()), - TrackedEntityTypeAttributeTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(TrackedEntityTypeAttributeStore.create(TestDatabaseAdapterFactory.get()), + TrackedEntityTypeAttributeTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeStoreIntegrationShould.java index df655feaef..88ae927e44 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.trackedentity.TrackedEntityTypeSamples; import org.hisp.dhis.android.core.trackedentity.TrackedEntityType; import org.hisp.dhis.android.core.trackedentity.TrackedEntityTypeTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class TrackedEntityTypeStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public TrackedEntityTypeStoreIntegrationShould() { - super(TrackedEntityTypeStore.create(DatabaseAdapterFactory.get()), - TrackedEntityTypeTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(TrackedEntityTypeStore.create(TestDatabaseAdapterFactory.get()), + TrackedEntityTypeTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.java index 896a09f570..82bc2f0775 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.java @@ -28,11 +28,11 @@ package org.hisp.dhis.android.core.trackedentity.search; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCallRealIntegrationShould.java index e6fa51a00b..dfd6f4d283 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCallRealIntegrationShould.java @@ -30,11 +30,11 @@ import com.google.common.collect.Lists; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/AuthenticatedUserStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/AuthenticatedUserStoreIntegrationShould.java index ff3216069c..1574731a81 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/AuthenticatedUserStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/AuthenticatedUserStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.user.AuthenticatedUserSamples; import org.hisp.dhis.android.core.user.AuthenticatedUser; import org.hisp.dhis.android.core.user.AuthenticatedUserTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class AuthenticatedUserStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould { public AuthenticatedUserStoreIntegrationShould() { - super(AuthenticatedUserStore.create(DatabaseAdapterFactory.get()), AuthenticatedUserTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(AuthenticatedUserStore.create(TestDatabaseAdapterFactory.get()), AuthenticatedUserTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/AuthorityStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/AuthorityStoreIntegrationShould.java index a518295077..91ff9614e0 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/AuthorityStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/AuthorityStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.user.AuthoritySamples; import org.hisp.dhis.android.core.user.Authority; import org.hisp.dhis.android.core.user.AuthorityTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -40,8 +40,8 @@ public class AuthorityStoreIntegrationShould extends ObjectStoreAbstractIntegrationShould { public AuthorityStoreIntegrationShould() { - super(AuthorityStore.create(DatabaseAdapterFactory.get()), AuthorityTableInfo.TABLE_INFO, - DatabaseAdapterFactory.get()); + super(AuthorityStore.create(TestDatabaseAdapterFactory.get()), AuthorityTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.java index 56e59b2847..d04c5d6f1d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.user.internal; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectWithoutUidStore; @@ -35,7 +36,6 @@ import org.hisp.dhis.android.core.event.EventTableInfo; import org.hisp.dhis.android.core.event.internal.EventCallFactory; import org.hisp.dhis.android.core.user.AuthenticatedUser; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; @@ -81,7 +81,7 @@ public void delete_credentials_when_log_out_after_sync_data() throws Exception { AuthenticatedUser authenticatedUser = authenticatedUserStore.selectFirst(); assertThat(authenticatedUser).isNotNull(); - assertThat(credentialsSecureStore.getCredentials()).isNull(); + assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull(); } //@Test @@ -100,14 +100,14 @@ public void recreate_credentials_when_login_again() AuthenticatedUser authenticatedUser = authenticatedUserStore.selectFirst(); assertThat(authenticatedUser).isNotNull(); - assertThat(credentialsSecureStore.getCredentials()).isNull(); + assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull(); d2.userModule().logIn(username, password, url).blockingGet(); authenticatedUser = authenticatedUserStore.selectFirst(); assertThat(authenticatedUser).isNotNull(); - assertThat(credentialsSecureStore.getCredentials()).isNotNull(); + assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull(); } //@Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateCallMockIntegrationShould.java index eb025b5f3a..83c65951d6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateCallMockIntegrationShould.java @@ -50,13 +50,12 @@ public class UserAuthenticateCallMockIntegrationShould extends BaseMockIntegrati @Before public void setUp() throws D2Error { - dhis2MockServer.enqueueMockResponse("user/user.json"); - dhis2MockServer.enqueueMockResponse("systeminfo/system_info.json"); + dhis2MockServer.enqueueLoginResponses(); } @After public void tearDown() { - UserStore.create(databaseAdapter).delete(); + d2.userModule().blockingLogOut(); } @Test @@ -93,14 +92,9 @@ public void return_correct_user_when_call() throws Exception { } private User login() { - User user; - try { - d2.userModule().logOut().blockingAwait(); - } catch (RuntimeException e) { - // Do nothing - } finally { - user = d2.userModule().blockingLogIn("test_user", "test_password", dhis2MockServer.getBaseEndpoint()); + if (d2.userModule().blockingIsLogged()) { + d2.userModule().blockingLogOut(); } - return user; + return d2.userModule().blockingLogIn("test_user", "test_password", dhis2MockServer.getBaseEndpoint()); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateWithEncryptionMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateWithEncryptionMockIntegrationShould.java new file mode 100644 index 0000000000..ba16f0938e --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateWithEncryptionMockIntegrationShould.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2004-2019, 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.user.internal; + +import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.D2Factory; +import org.hisp.dhis.android.core.mockwebserver.Dhis2MockServer; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; + +import static com.google.common.truth.Truth.assertThat; + +public class UserAuthenticateWithEncryptionMockIntegrationShould { + + private static D2 d2; + private static Dhis2MockServer dhis2MockServer; + + @BeforeClass + public static void setUpClass() throws IOException { + d2 = D2Factory.forNewDatabase(); + dhis2MockServer = new Dhis2MockServer(0); + dhis2MockServer.setRequestDispatcher(); + } + + @Test + public void return_false_for_blocking_is_logged_when_not_logged() { + assertThat(d2.userModule().blockingIsLogged()).isFalse(); + } + + @Test + public void return_false_for_is_logged_when_not_logged() { + assertThat(d2.userModule().isLogged().blockingGet()).isFalse(); + } + + @Test + public void return_true_for_blocking_is_logged_when_logged() { + logIn(); + assertThat(d2.userModule().blockingIsLogged()).isTrue(); + logOut(); + } + + @Test + public void unencrypted_login_logout_once_succeeds() { + logIn(); + logOut(); + } + + @Test + public void unencrypted_login_logout_twice_succeeds() { + logIn(); + logOut(); + logIn(); + logOut(); + } + + /* TODO this has to be configured in json + @Test + public void encrypted_login_logout_login_succeeds() { + DatabaseAdapterFactory.setExperimentalEncryption(true); + logIn(); + logOut(); + logIn(); + logOut(); + DatabaseAdapterFactory.setExperimentalEncryption(false); + } + + @Test + public void unencrypted_and_then_encypted_login_logout_login_succeeds() { + logIn(); + logOut(); + DatabaseAdapterFactory.setExperimentalEncryption(true); + logIn(); + logOut(); + DatabaseAdapterFactory.setExperimentalEncryption(false); + }*/ + + private void logIn() { + d2.userModule().blockingLogIn("test_user", "test_password", dhis2MockServer.getBaseEndpoint()); + } + + private void logOut() { + d2.userModule().blockingLogOut(); + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserCallMockIntegrationShould.java index ad4e411324..af1d366700 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserCallMockIntegrationShould.java @@ -64,11 +64,11 @@ public static void setUpClass() throws Exception { ContentValues program4 = CreateProgramUtils.create(4L, "WSGAb5XwJ3Y", null, null); ContentValues program5 = CreateProgramUtils.create(5L, "IpHINAT79UW", null, null); - database.insert(ProgramTableInfo.TABLE_INFO.name(), null, program1); - database.insert(ProgramTableInfo.TABLE_INFO.name(), null, program2); - database.insert(ProgramTableInfo.TABLE_INFO.name(), null, program3); - database.insert(ProgramTableInfo.TABLE_INFO.name(), null, program4); - database.insert(ProgramTableInfo.TABLE_INFO.name(), null, program5); + databaseAdapter.insert(ProgramTableInfo.TABLE_INFO.name(), null, program1); + databaseAdapter.insert(ProgramTableInfo.TABLE_INFO.name(), null, program2); + databaseAdapter.insert(ProgramTableInfo.TABLE_INFO.name(), null, program3); + databaseAdapter.insert(ProgramTableInfo.TABLE_INFO.name(), null, program4); + databaseAdapter.insert(ProgramTableInfo.TABLE_INFO.name(), null, program5); } @Test @@ -77,7 +77,7 @@ public void persist_user_in_data_base_when_call() throws Exception { userCall.call(); - Cursor userCursor = database.query(UserTableInfo.TABLE_INFO.name(), UserTableInfo.TABLE_INFO.columns().all(), null, null, null, null, null); + Cursor userCursor = databaseAdapter.query(UserTableInfo.TABLE_INFO.name(), UserTableInfo.TABLE_INFO.columns().all()); assertThatCursor(userCursor).hasRow( "DXyJmlo9rge", @@ -120,8 +120,7 @@ public void persist_user_credentials_in_data_base_when_call() throws Exception { }; - Cursor userCredentialsCursor = database.query(UserCredentialsTableInfo.TABLE_INFO.name(), projection, - null, null, null, null, null); + Cursor userCredentialsCursor = databaseAdapter.query(UserCredentialsTableInfo.TABLE_INFO.name(), projection); assertThatCursor(userCredentialsCursor).hasRow( "M0fCOxtkURr", diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserOrganisationUnitLinkStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserOrganisationUnitLinkStoreIntegrationShould.java index 5e070250b5..15e7bb522c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserOrganisationUnitLinkStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserOrganisationUnitLinkStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.user.UserOrganisationUnitLinkSamples; import org.hisp.dhis.android.core.user.UserOrganisationUnitLink; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class UserOrganisationUnitLinkStoreIntegrationShould extends LinkStoreAbstractIntegrationShould { public UserOrganisationUnitLinkStoreIntegrationShould() { - super(UserOrganisationUnitLinkStoreImpl.create(DatabaseAdapterFactory.get()), - UserOrganisationUnitLinkTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(UserOrganisationUnitLinkStoreImpl.create(TestDatabaseAdapterFactory.get()), + UserOrganisationUnitLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserRoleStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserRoleStoreIntegrationShould.java index 360ba8b473..aafa7f0058 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserRoleStoreIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserRoleStoreIntegrationShould.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.data.user.UserRoleSamples; import org.hisp.dhis.android.core.user.UserRole; import org.hisp.dhis.android.core.user.UserRoleTableInfo; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; import org.junit.runner.RunWith; @@ -41,8 +41,8 @@ public class UserRoleStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould { public UserRoleStoreIntegrationShould() { - super(UserRoleStore.create(DatabaseAdapterFactory.get()), - UserRoleTableInfo.TABLE_INFO, DatabaseAdapterFactory.get()); + super(UserRoleStore.create(TestDatabaseAdapterFactory.get()), + UserRoleTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.java new file mode 100644 index 0000000000..970cb9cae2 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004-2019, 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.utils; + +import android.content.Context; + +import androidx.test.InstrumentationRegistry; + +public class DatabaseRemover { + + public static void removeAllDatabases() { + Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); + for (String dbName : context.databaseList()) { + context.deleteDatabase(dbName); + } + + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.java index fde3195d5a..d26e99f66a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.java @@ -28,12 +28,11 @@ package org.hisp.dhis.android.core.utils.integration.mock; -import android.database.sqlite.SQLiteDatabase; - import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.MockIntegrationTestObjects; import org.hisp.dhis.android.core.arch.api.internal.ServerURLWrapper; import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.data.server.Dhis2MockServer; +import org.hisp.dhis.android.core.mockwebserver.Dhis2MockServer; public abstract class BaseMockIntegrationTest { @@ -41,13 +40,11 @@ public abstract class BaseMockIntegrationTest { protected static D2 d2; protected static Dhis2MockServer dhis2MockServer; protected static DatabaseAdapter databaseAdapter; - protected static SQLiteDatabase database; static boolean setUpClass(MockIntegrationTestDatabaseContent content) throws Exception { MockIntegrationTestObjectsFactory.IntegrationTestObjectsWithIsNewInstance tuple = MockIntegrationTestObjectsFactory.getObjects(content); objects = tuple.objects; d2 = objects.d2; - database = objects.database; databaseAdapter = objects.databaseAdapter; dhis2MockServer = objects.dhis2MockServer; ServerURLWrapper.setServerUrl(dhis2MockServer.getBaseEndpoint()); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyDispatcher.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyDispatcher.java index 1817f39549..7ba7237802 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyDispatcher.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyDispatcher.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.utils.integration.mock; +import org.hisp.dhis.android.core.data.server.RealServerMother; import org.junit.BeforeClass; public abstract class BaseMockIntegrationTestEmptyDispatcher extends BaseMockIntegrationTest { @@ -37,6 +38,8 @@ public static void setUpClass() throws Exception { boolean isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.EmptyDispatcher); if (isNewInstance) { objects.dhis2MockServer.setRequestDispatcher(); + objects.d2.userModule().blockingLogIn(RealServerMother.username, RealServerMother.password, + objects.dhis2MockServer.getBaseEndpoint()); } } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyEnqueable.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyEnqueable.java index d76cbf84e4..eb6bae7b2d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyEnqueable.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyEnqueable.java @@ -28,12 +28,18 @@ package org.hisp.dhis.android.core.utils.integration.mock; +import org.hisp.dhis.android.core.data.server.RealServerMother; import org.junit.BeforeClass; public abstract class BaseMockIntegrationTestEmptyEnqueable extends BaseMockIntegrationTest { @BeforeClass public static void setUpClass() throws Exception { - setUpClass(MockIntegrationTestDatabaseContent.EmptyEnqueable); + boolean isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.EmptyEnqueable); + if (isNewInstance) { + dhis2MockServer.enqueueLoginResponses(); + objects.d2.userModule().blockingLogIn(RealServerMother.username, RealServerMother.password, + objects.dhis2MockServer.getBaseEndpoint()); + } } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestFullDispatcher.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestFullDispatcher.java index 6df0448d09..bd189d32e9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestFullDispatcher.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestFullDispatcher.java @@ -100,7 +100,7 @@ private static void storeSomeD2Errors() { d2ErrorStore.insert(D2ErrorSamples.get()); d2ErrorStore.insert(D2Error.builder() .errorComponent(D2ErrorComponent.SDK) - .errorCode(D2ErrorCode.DIFFERENT_SERVER_OFFLINE) + .errorCode(D2ErrorCode.BAD_CREDENTIALS) .url("http://dhis2.org/api/programs/uid") .errorDescription("Different server offline") .httpErrorCode(402) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataDispatcher.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataDispatcher.java index 47a6fa0ce3..fc8239e32a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataDispatcher.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataDispatcher.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.utils.integration.mock; +import org.hisp.dhis.android.core.data.server.RealServerMother; import org.junit.BeforeClass; public abstract class BaseMockIntegrationTestMetadataDispatcher extends BaseMockIntegrationTest { @@ -36,20 +37,10 @@ public abstract class BaseMockIntegrationTestMetadataDispatcher extends BaseMock public static void setUpClass() throws Exception { boolean isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.MetadataDispatcher); if (isNewInstance) { - dhis2MockServer.setRequestDispatcher(); - - freshLogin(); - d2.metadataModule().blockingDownload(); - } - } - - private static void freshLogin() { - try { - d2.userModule().logOut().blockingAwait(); - } catch (RuntimeException e) { - // Do nothing - } finally { - d2.userModule().blockingLogIn("android", "Android123", dhis2MockServer.getBaseEndpoint()); + objects.dhis2MockServer.setRequestDispatcher(); + objects.d2.userModule().blockingLogIn(RealServerMother.username, RealServerMother.password, + objects.dhis2MockServer.getBaseEndpoint()); + objects.d2.metadataModule().blockingDownload(); } } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataEnqueable.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataEnqueable.java index f1c694e23c..e404d58bce 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataEnqueable.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataEnqueable.java @@ -36,6 +36,10 @@ public abstract class BaseMockIntegrationTestMetadataEnqueable extends BaseMockI public static void setUpClass() throws Exception { boolean isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.MetadataEnqueable); if (isNewInstance) { + objects.dhis2MockServer.enqueueLoginResponses(); + objects.d2.userModule().blockingLogIn("android", "Android123", + objects.dhis2MockServer.getBaseEndpoint()); + objects.dhis2MockServer.enqueueMetadataResponses(); objects.d2.metadataModule().blockingDownload(); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjectsFactory.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjectsFactory.java index c7de36a54a..ee5801b59a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjectsFactory.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjectsFactory.java @@ -28,6 +28,8 @@ package org.hisp.dhis.android.core.utils.integration.mock; +import org.hisp.dhis.android.core.MockIntegrationTestObjects; + import java.io.IOException; import java.util.HashMap; import java.util.Map; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/DatabaseAdapterFactory.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/TestDatabaseAdapterFactory.java similarity index 78% rename from core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/DatabaseAdapterFactory.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/TestDatabaseAdapterFactory.java index c153d8ab80..88a6ae56a4 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/DatabaseAdapterFactory.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/TestDatabaseAdapterFactory.java @@ -30,41 +30,40 @@ import android.content.Context; +import androidx.test.InstrumentationRegistry; + import com.facebook.stetho.Stetho; import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.arch.db.access.DbOpenHelper; -import org.hisp.dhis.android.core.arch.db.access.internal.SqLiteDatabaseAdapter; - -import androidx.test.InstrumentationRegistry; +import org.hisp.dhis.android.core.arch.db.access.internal.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.arch.storage.internal.InMemorySecureStore; -public class DatabaseAdapterFactory { +public class TestDatabaseAdapterFactory { private static String dbName = null; private static DatabaseAdapter databaseAdapter = null; - public static void setUp() { + public static DatabaseAdapter get() { if (databaseAdapter == null) { databaseAdapter = create(); - databaseAdapter.database().setForeignKeyConstraintsEnabled(false); } - } - - public static DatabaseAdapter get() { return databaseAdapter; } public static void tearDown() { if (databaseAdapter != null) { - databaseAdapter.database().close(); + databaseAdapter.close(); databaseAdapter = null; } } private static DatabaseAdapter create() { Context context = InstrumentationRegistry.getTargetContext().getApplicationContext(); - DbOpenHelper dbOpenHelper = new DbOpenHelper(context, dbName); - dbOpenHelper.getWritableDatabase(); Stetho.initializeWithDefaults(context); - return new SqLiteDatabaseAdapter(dbOpenHelper); + DatabaseAdapterFactory databaseAdapterFactory = DatabaseAdapterFactory.create(context, + new InMemorySecureStore()); + DatabaseAdapter parentDatabaseAdapter = databaseAdapterFactory.newParentDatabaseAdapter(); + databaseAdapterFactory.createOrOpenDatabase(parentDatabaseAdapter, dbName,false); + parentDatabaseAdapter.setForeignKeyConstraintsEnabled(false); + return parentDatabaseAdapter; } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.java index 96c8c66a73..c44884eb47 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.java @@ -30,8 +30,10 @@ import android.util.Log; -import org.hisp.dhis.android.core.utils.integration.mock.DatabaseAdapterFactory; +import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory; +import org.hisp.dhis.android.core.utils.DatabaseRemover; import org.hisp.dhis.android.core.utils.integration.mock.MockIntegrationTestObjectsFactory; +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; import org.junit.runner.Description; import org.junit.runner.Result; import org.junit.runner.notification.RunListener; @@ -42,13 +44,15 @@ public class D2JunitTestListener extends RunListener { @Override public void testRunStarted(Description description) { Log.e("D2JunitTestListener", "Test run started"); - DatabaseAdapterFactory.setUp(); + CalendarProviderFactory.setFixed(); } @Override public void testRunFinished(Result result) throws Exception { Log.i("D2JunitTestListener", "Test run finished"); - DatabaseAdapterFactory.tearDown(); + TestDatabaseAdapterFactory.tearDown(); + CalendarProviderFactory.setRegular(); MockIntegrationTestObjectsFactory.tearDown(); + DatabaseRemover.removeAllDatabases(); } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallMockIntegrationShould.java index b153ddd573..345636b73f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallMockIntegrationShould.java @@ -28,9 +28,7 @@ package org.hisp.dhis.android.core.wipe; -import org.hisp.dhis.android.core.configuration.ConfigurationTableInfo; import org.hisp.dhis.android.core.data.database.DatabaseAssert; -import org.hisp.dhis.android.core.data.server.RealServerMother; import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyDispatcher; import org.junit.Test; @@ -46,8 +44,6 @@ public void have_empty_database_when_wipe_db_after_sync_data() throws Exception DatabaseAssert.assertThatDatabase(databaseAdapter).isNotEmpty(); - databaseAdapter.delete(ConfigurationTableInfo.TABLE_INFO.name()); - d2.wipeModule().wipeEverything(); DatabaseAssert.assertThatDatabase(databaseAdapter).isEmpty(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallRealIntegrationShould.java index 87eea58783..f30c4c89ce 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallRealIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.wipe; +import org.hisp.dhis.android.core.BaseRealIntegrationTest; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Factory; import org.hisp.dhis.android.core.data.database.DatabaseAssert; @@ -35,7 +36,6 @@ import org.hisp.dhis.android.core.event.internal.EventCallFactory; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceStore; import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceStoreImpl; -import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest; import org.junit.Before; import java.io.IOException; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCollectionRepositoryMockIntegrationShould.java index b4e43e9fc8..6b0479f6c7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCollectionRepositoryMockIntegrationShould.java @@ -29,6 +29,7 @@ package org.hisp.dhis.android.testapp.dataset; import org.hisp.dhis.android.core.dataset.DataSet; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.period.PeriodType; import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; @@ -48,7 +49,7 @@ public class DataSetCollectionRepositoryMockIntegrationShould extends BaseMockIn public void find_all() { List dataSets = d2.dataSetModule().dataSets() .blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); } @Test @@ -56,7 +57,7 @@ public void filter_by_period_type() { List dataSets = d2.dataSetModule().dataSets() .byPeriodType().eq(PeriodType.Monthly) .blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); } @Test @@ -64,7 +65,7 @@ public void filter_by_category_combo() { List dataSets = d2.dataSetModule().dataSets() .byCategoryComboUid().eq("m2jTvAj5kkm") .blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); } @Test @@ -104,7 +105,7 @@ public void filter_by_version_smaller_0() { List dataSets = d2.dataSetModule().dataSets() .byVersion().smallerThan(21) .blockingGet(); - assertThat(dataSets.size(), is(0)); + assertThat(dataSets.size(), is(1)); } @Test @@ -112,7 +113,7 @@ public void filter_by_version_smaller_1() { List dataSets = d2.dataSetModule().dataSets() .byVersion().smallerThan(23) .blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); } @Test @@ -144,7 +145,7 @@ public void filter_by_open_future_periods() { List dataSets = d2.dataSetModule().dataSets() .byOpenFuturePeriods().eq(3) .blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); } @Test @@ -208,7 +209,7 @@ public void filter_by_access_data_write() { List dataSets = d2.dataSetModule().dataSets() .byAccessDataWrite().isTrue() .blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); } @Test @@ -232,7 +233,7 @@ public void filter_by_organisation_unit_uid() { List dataSets = d2.dataSetModule().dataSets() .byOrganisationUnitUid("DiszpKrYNg8") .blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); } @Test @@ -240,7 +241,20 @@ public void filter_by_organisation_unit_uid_list() { List dataSets = d2.dataSetModule().dataSets() .byOrganisationUnitList(Collections.singletonList("DiszpKrYNg8")) .blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); + } + + @Test + public void filter_by_orgunit_scope() { + List dataSetCapture = d2.dataSetModule().dataSets() + .byOrganisationUnitScope(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE) + .blockingGet(); + assertThat(dataSetCapture.size(), is(2)); + + List dataSetSearch = d2.dataSetModule().dataSets() + .byOrganisationUnitScope(OrganisationUnit.Scope.SCOPE_TEI_SEARCH) + .blockingGet(); + assertThat(dataSetSearch.size(), is(0)); } @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java new file mode 100644 index 0000000000..7df4fe85ac --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2004-2019, 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.testapp.dataset; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.dataset.DataSetInstanceSummary; +import org.hisp.dhis.android.core.period.PeriodType; +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.text.ParseException; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +@RunWith(D2JunitRunner.class) +public class DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher { + + @Test + public void find_all() { + List summaries = d2.dataSetModule().dataSetInstanceSummaries() + .blockingGet(); + assertThat(summaries.size(), is(1)); + assertThat(summaries.get(0).dataSetInstanceCount(), is(4)); + assertThat(summaries.get(0).valueCount(), is(4)); + } + + @Test + public void filter_by_dataset() { + List summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byDataSetUid().eq("lyLU2wR22tC") + .blockingGet(); + assertThat(summaries.size(), is(1)); + } + + @Test + public void filter_by_period() { + List summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byPeriod().eq("2018") + .blockingGet(); + assertThat(summaries.size(), is(1)); + } + + @Test + public void filter_by_period_type() { + List summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byPeriodType().eq(PeriodType.Yearly) + .blockingGet(); + assertThat(summaries.size(), is(1)); + } + + @Test + public void filter_by_period_start_date() throws ParseException { + List summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byPeriodStartDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) + .blockingGet(); + assertThat(summaries.size(), is(1)); + } + + @Test + public void filter_by_period_end_date() throws ParseException { + List summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byPeriodEndDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) + .blockingGet(); + assertThat(summaries.size(), is(1)); + } + + @Test + public void filter_by_organisation_unit() { + List summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byOrganisationUnitUid().eq("DiszpKrYNg8") + .blockingGet(); + assertThat(summaries.size(), is(1)); + } + +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetModuleMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetModuleMockIntegrationShould.java index d8fb741d92..7bedca2eae 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetModuleMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetModuleMockIntegrationShould.java @@ -50,7 +50,7 @@ public class DataSetModuleMockIntegrationShould extends BaseMockIntegrationTestF @Test public void allow_access_to_all_data_sets_without_children() { List dataSets = d2.dataSetModule().dataSets().blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); for (DataSet dataSet : dataSets) { assertThat(dataSet.dataSetElements() == null, is(true)); } @@ -65,7 +65,7 @@ public void allow_access_to_one_data_set_without_children() { @Test public void allow_access_to_all_data_sets_with_children() { List dataSets = d2.dataSetModule().dataSets().withDataSetElements().blockingGet(); - assertThat(dataSets.size(), is(1)); + assertThat(dataSets.size(), is(2)); for (DataSet dataSet : dataSets) { assertThat(dataSet.dataSetElements() == null, is(false)); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentCollectionRepositoryMockIntegrationShould.java index 8464aa9cee..89a5dbc9b2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentCollectionRepositoryMockIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.testapp.enrollment; +import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.FeatureType; import org.hisp.dhis.android.core.common.State; @@ -107,7 +108,7 @@ public void filter_by_last_updated() throws ParseException { @Test public void filter_by_created_as_client() { List enrollments = d2.enrollmentModule().enrollments() - .byCreatedAtClient().eq("2019-01-08T13:40:28.718") + .byCreatedAtClient().eq("2018-01-08T13:40:28.718") .blockingGet(); assertThat(enrollments.size(), is(1)); } @@ -212,6 +213,66 @@ public void filter_by_geometry_coordinates() { assertThat(enrollments.size(), is(1)); } + @Test + public void order_by_created() { + List enrollments = d2.enrollmentModule().enrollments() + .orderByCreated(RepositoryScope.OrderByDirection.DESC) + .blockingGet(); + + assertThat(enrollments.get(0).uid(), is("enroll1")); + assertThat(enrollments.get(1).uid(), is("enroll2")); + } + + @Test + public void order_by_created_at_client() { + List enrollments = d2.enrollmentModule().enrollments() + .orderByCreatedAtClient(RepositoryScope.OrderByDirection.DESC) + .blockingGet(); + + assertThat(enrollments.get(0).uid(), is("enroll2")); + assertThat(enrollments.get(1).uid(), is("enroll1")); + } + + @Test + public void order_by_last_updated() { + List enrollments = d2.enrollmentModule().enrollments() + .orderByLastUpdated(RepositoryScope.OrderByDirection.DESC) + .blockingGet(); + + assertThat(enrollments.get(0).uid(), is("enroll1")); + assertThat(enrollments.get(1).uid(), is("enroll2")); + } + + @Test + public void order_by_last_updated_at_client() { + List enrollments = d2.enrollmentModule().enrollments() + .orderByLastUpdatedAtClient(RepositoryScope.OrderByDirection.DESC) + .blockingGet(); + + assertThat(enrollments.get(0).uid(), is("enroll2")); + assertThat(enrollments.get(1).uid(), is("enroll1")); + } + + @Test + public void order_by_enrollment_date() { + List enrollments = d2.enrollmentModule().enrollments() + .orderByEnrollmentDate(RepositoryScope.OrderByDirection.DESC) + .blockingGet(); + + assertThat(enrollments.get(0).uid(), is("enroll1")); + assertThat(enrollments.get(1).uid(), is("enroll2")); + } + + @Test + public void order_by_incident_date() { + List enrollments = d2.enrollmentModule().enrollments() + .orderByIncidentDate(RepositoryScope.OrderByDirection.DESC) + .blockingGet(); + + assertThat(enrollments.get(0).uid(), is("enroll1")); + assertThat(enrollments.get(1).uid(), is("enroll2")); + } + @Test public void add_enrollments_to_the_repository() throws D2Error { List enrollments1 = d2.enrollmentModule().enrollments().blockingGet(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/event/EventCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/event/EventCollectionRepositoryMockIntegrationShould.java index a72cfdb611..b119610304 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/event/EventCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/event/EventCollectionRepositoryMockIntegrationShould.java @@ -250,6 +250,16 @@ public void filter_by_tracked_entity_instance() { assertThat(events.size(), is(1)); } + @Test + public void filter_by_assigned_user() { + List events = + d2.eventModule().events() + .byAssignedUser().eq("aTwqot2S410") + .blockingGet(); + + assertThat(events.size(), is(1)); + } + @Test public void count_tracked_entity_instances_unrestricted() { int count = d2.eventModule().events().countTrackedEntityInstances(); @@ -271,6 +281,13 @@ public void include_tracked_entity_data_values_as_children() { assertThat(event.trackedEntityDataValues().size(), is(6)); } + @Test + public void include_notes_as_children() { + Event event = d2.eventModule().events() + .withNotes().uid("single1").blockingGet(); + assertThat(event.notes().size(), is(2)); + } + @Test public void order_by_due_date() { List events = d2.eventModule().events() @@ -282,6 +299,28 @@ public void order_by_due_date() { assertThat(events.get(3).uid(), is("single2")); } + @Test + public void order_by_created() { + List events = d2.eventModule().events() + .orderByCreated(RepositoryScope.OrderByDirection.ASC) + .blockingGet(); + assertThat(events.get(0).uid(), is("event1")); + assertThat(events.get(1).uid(), is("event2")); + assertThat(events.get(2).uid(), is("single1")); + assertThat(events.get(3).uid(), is("single2")); + } + + @Test + public void order_by_created_at_client() { + List events = d2.eventModule().events() + .orderByCreatedAtClient(RepositoryScope.OrderByDirection.ASC) + .blockingGet(); + assertThat(events.get(0).uid(), is("event1")); + assertThat(events.get(1).uid(), is("event2")); + assertThat(events.get(2).uid(), is("single1")); + assertThat(events.get(3).uid(), is("single2")); + } + @Test public void order_by_last_updated() { List events = d2.eventModule().events() @@ -293,6 +332,17 @@ public void order_by_last_updated() { assertThat(events.get(3).uid(), is("single1")); } + @Test + public void order_by_last_updated_at_client() { + List events = d2.eventModule().events() + .orderByLastUpdatedAtClient(RepositoryScope.OrderByDirection.ASC) + .blockingGet(); + assertThat(events.get(0).uid(), is("event1")); + assertThat(events.get(1).uid(), is("event2")); + assertThat(events.get(2).uid(), is("single1")); + assertThat(events.get(3).uid(), is("single2")); + } + @Test public void order_by_event_date_and_last_updated() { List events = d2.eventModule().events() diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/event/EventObjectRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/event/EventObjectRepositoryMockIntegrationShould.java index ed3f8a9e03..fdaae297f3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/event/EventObjectRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/event/EventObjectRepositoryMockIntegrationShould.java @@ -169,6 +169,18 @@ public void not_update_attribute_option_combo_if_not_exists() throws D2Error { } } + @Test + public void update_assigned_user() throws D2Error { + String assignedUser = "aTwqot2S410"; + + EventObjectRepository repository = objectRepository(); + + repository.setAssignedUser(assignedUser); + assertThat(repository.blockingGet().assignedUser(), is(assignedUser)); + + repository.blockingDelete(); + } + private EventObjectRepository objectRepository() throws D2Error { String eventUid = d2.eventModule().events().blockingAdd( EventCreateProjection.create("enroll1", "lxAQ7Zs9VYR", "dBwrot7S420", diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java index 58579389df..e34d3434cb 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java @@ -60,7 +60,7 @@ public void filter_d2_error_by_url() { @Test public void filter_d2_error_by_d2_error_code() { List d2Errors = d2.maintenanceModule().d2Errors() - .byD2ErrorCode().eq(D2ErrorCode.DIFFERENT_SERVER_OFFLINE).blockingGet(); + .byD2ErrorCode().eq(D2ErrorCode.BAD_CREDENTIALS).blockingGet(); assertThat(d2Errors.size(), is(1)); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/note/NoteCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/note/NoteCollectionRepositoryMockIntegrationShould.java index 75d80708b6..7897f0dbd7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/note/NoteCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/note/NoteCollectionRepositoryMockIntegrationShould.java @@ -45,15 +45,32 @@ public class NoteCollectionRepositoryMockIntegrationShould extends BaseMockInteg @Test public void find_all() { List notes = d2.noteModule().notes().blockingGet(); - assertThat(notes.size(), is(4)); + assertThat(notes.size(), is(10)); } @Test public void filter_by_uid() { - List notes = d2.noteModule().notes().byUid().eq("noteUid1").blockingGet(); + List notes = d2.noteModule().notes().byUid().eq("enrollmentNote1").blockingGet(); assertThat(notes.size(), is(1)); } + @Test + public void filter_by_note_type() { + List enrollmentNotes = d2.noteModule().notes() + .byNoteType().eq(Note.NoteType.ENROLLMENT_NOTE).blockingGet(); + assertThat(enrollmentNotes.size(), is(4)); + + List eventNotes = d2.noteModule().notes() + .byNoteType().eq(Note.NoteType.EVENT_NOTE).blockingGet(); + assertThat(eventNotes.size(), is(6)); + } + + @Test + public void filter_by_event_uid() { + List notes = d2.noteModule().notes().byEventUid().eq("event1").blockingGet(); + assertThat(notes.size(), is(2)); + } + @Test public void filter_by_enrollment_uid() { List notes = d2.noteModule().notes().byEnrollmentUid().eq("enroll1").blockingGet(); @@ -62,19 +79,19 @@ public void filter_by_enrollment_uid() { @Test public void filter_by_value() { - List notes = d2.noteModule().notes().byValue().eq("Note 3").blockingGet(); + List notes = d2.noteModule().notes().byValue().eq("TEI enrollment note 3").blockingGet(); assertThat(notes.size(), is(1)); } @Test public void filter_by_stored_by() { List notes = d2.noteModule().notes().byStoredBy().eq("android").blockingGet(); - assertThat(notes.size(), is(4)); + assertThat(notes.size(), is(10)); } @Test public void filter_by_stored_date() { List notes = d2.noteModule().notes().byStoredDate().eq("2018-03-19T15:20:55.058").blockingGet(); - assertThat(notes.size(), is(4)); + assertThat(notes.size(), is(8)); } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/option/OptionCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/option/OptionCollectionRepositoryMockIntegrationShould.java index c48ae93076..de41fc244b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/option/OptionCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/option/OptionCollectionRepositoryMockIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.testapp.option; +import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope; import org.hisp.dhis.android.core.option.Option; import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher; import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; @@ -78,4 +79,14 @@ public void filter_by_field_icon() { .blockingGet(); assertThat(options.size(), is(1)); } + + @Test + public void order_by_sort_order() { + List