{
+ return store.selectAll()
+ }
+
+ private fun login() {
+ try {
+ if (!d2.userModule().isLogged().blockingGet()) {
+ d2.userModule().logIn(username, password, url).blockingGet()
+ }
+ } catch (ignored: Exception) {
+ }
+ }
+
+ /*
+ * This method stopped working because QueryCallFactory mock instance differs from Dagger's injected one,
+ * so the code is calling .create() on Dagger's instance and .verify() is trying to catch the call from Mockito's instace.
+ */
+ private suspend fun assertQueryIsCreatedRight(numberOfValuesExpected: Int) {
+ Mockito.verify(trackedEntityAttributeReservedValueQueryCallFactory)!!.create(
+ trackedEntityAttributeReservedValueQueryCaptor!!.capture(),
+ )
+ val query = trackedEntityAttributeReservedValueQueryCaptor.value
+ Truth.assertThat(query.organisationUnit()!!.uid()).isEqualTo(organisationUnit.uid())
+ Truth.assertThat(query.numberToReserve())
+ .isEqualTo(numberOfValuesExpected) // values expected - 3 that it had before.
+ Truth.assertThat(query.trackedEntityAttributePattern()).isEqualTo(pattern)
+ Truth.assertThat(query.trackedEntityAttributeUid()).isEqualTo(ownerUid)
+ }
+}
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
deleted file mode 100644
index 73c0c53543..0000000000
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/BreakTheGlassAPIShould.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * Copyright (c) 2004-2023, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package org.hisp.dhis.android.core.trackedentity.api;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.hisp.dhis.android.core.imports.ImportStatus.ERROR;
-import static org.hisp.dhis.android.core.imports.ImportStatus.SUCCESS;
-import static org.hisp.dhis.android.core.trackedentity.api.TrackedEntityInstanceUtils.assertEnrollments;
-import static org.hisp.dhis.android.core.trackedentity.api.TrackedEntityInstanceUtils.assertEvents;
-import static org.hisp.dhis.android.core.trackedentity.api.TrackedEntityInstanceUtils.assertTei;
-
-import org.hisp.dhis.android.core.BaseRealIntegrationTest;
-import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutor;
-import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutorImpl;
-import org.hisp.dhis.android.core.arch.helpers.UidGenerator;
-import org.hisp.dhis.android.core.arch.helpers.UidGeneratorImpl;
-import org.hisp.dhis.android.core.data.server.RealServerMother;
-import org.hisp.dhis.android.core.enrollment.Enrollment;
-import org.hisp.dhis.android.core.enrollment.EnrollmentInternalAccessor;
-import org.hisp.dhis.android.core.enrollment.EnrollmentStatus;
-import org.hisp.dhis.android.core.event.Event;
-import org.hisp.dhis.android.core.imports.internal.HttpMessageResponse;
-import org.hisp.dhis.android.core.imports.internal.TEIImportSummary;
-import org.hisp.dhis.android.core.imports.internal.TEIWebResponse;
-import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue;
-import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance;
-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.trackedentity.ownership.OwnershipService;
-import org.junit.Before;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-
-public class BreakTheGlassAPIShould extends BaseRealIntegrationTest {
-
- /**
- * Expected configuration to run these tests:
- * - user: android
- * - role: not a superuser
- * - capture orgunit: DiszpKrYNg8 - Negelhun CHC
- * - search orgunit: YuQRtpLP10I - Badja
- *
- * - read/write access to PROTECTED program: IpHINAT79UW
- */
-
- private String captureOrgunit = "DiszpKrYNg8"; // Ngelehun CHC
- private String searchOrgunit = "g8upMTyEZGZ"; // Njandama MCHP
- private String outOfScopeOrgunit = "jNb63DIHuwU"; // Baoma Hospital
-
- private String trackedEntityType = "nEenWmSyUEp"; // Person
- private String attribute1 = "w75KJ2mc4zz"; // First name
- private String attribute2 = "zDhUuAYrxNC"; // Last name
-
-
- private String program = "IpHINAT79UW"; // Child programme
- private String programStage1 = "A03MvHHogjR"; // Birth
- private String programStage2 = "ZzYYXq4fJie"; // Baby Postnatal
- private String attributeOptionCombo = "HllvX50cXC0"; // Default
-
- // API version dependant parameters
- private String serverUrl = RealServerMother.url2_30;
- private String strategy = "SYNC";
-
- private APICallExecutor executor;
-
- private TrackedEntityInstanceService trackedEntityInstanceService;
- private OwnershipService ownershipService;
-
- private UidGenerator uidGenerator = new UidGeneratorImpl();
-
- @Before
- public void setUp() {
- super.setUp();
-
- executor = APICallExecutorImpl.create(d2.databaseAdapter(), null);
-
- trackedEntityInstanceService = d2.retrofit().create(TrackedEntityInstanceService.class);
- ownershipService = d2.retrofit().create(OwnershipService.class);
-
- login();
- }
-
- //@Test
- public void tei_with_event_in_search_scope_in_open_program() throws Exception {
-
- TrackedEntityInstance tei = teiWithEventInSearchScope();
-
- for (int i = 0; i < 2; i++) {
- TEIWebResponse response =
- executor.executeObjectCallWithAcceptedErrorCodes(trackedEntityInstanceService
- .postTrackedEntityInstances(wrapPayload(tei), this.strategy), Collections.singletonList(409),
- TEIWebResponse.class);
-
- assertThat(response.response().status()).isEqualTo(SUCCESS);
-
- for (TEIImportSummary importSummary : response.response().importSummaries()) {
- assertTei(importSummary, SUCCESS);
- assertEnrollments(importSummary, SUCCESS);
- assertEvents(importSummary, SUCCESS);
- }
- }
- }
-
- // Make program protected
- //@Test
- public void tei_with_event_in_search_scope_in_protected_program() throws Exception {
-
- TrackedEntityInstance tei = teiWithEventInSearchScope();
-
- TEIWebResponse response = executor.executeObjectCallWithAcceptedErrorCodes(trackedEntityInstanceService
- .postTrackedEntityInstances(wrapPayload(tei), this.strategy), Collections.singletonList(409),
- TEIWebResponse.class);
-
- assertThat(response.response().status()).isEqualTo(SUCCESS);
-
- for (TEIImportSummary importSummary : response.response().importSummaries()) {
- assertTei(importSummary, SUCCESS);
- assertEnrollments(importSummary, SUCCESS);
- assertEvents(importSummary, SUCCESS);
- }
-
- TEIWebResponse response2 =
- executor.executeObjectCallWithAcceptedErrorCodes(trackedEntityInstanceService
- .postTrackedEntityInstances(wrapPayload(tei), this.strategy), Collections.singletonList(409),
- TEIWebResponse.class);
-
- assertThat(response2.response().status()).isEqualTo(SUCCESS);
-
- for (TEIImportSummary importSummary : response2.response().importSummaries()) {
- assertTei(importSummary, SUCCESS);
- assertEnrollments(importSummary, SUCCESS);
- assertEvents(importSummary, SUCCESS);
- }
- }
-
- // Make program protected
- //@Test
- public void tei_with_enrollment_in_search_scope_in_protected_program() throws Exception {
-
- TrackedEntityInstance tei = teiWithEnrollmentInSearchScope();
-
- TEIWebResponse response = executor.executeObjectCallWithAcceptedErrorCodes(trackedEntityInstanceService
- .postTrackedEntityInstances(wrapPayload(tei), this.strategy), Collections.singletonList(409),
- TEIWebResponse.class);
-
- assertThat(response.response().status()).isEqualTo(SUCCESS);
-
- for (TEIImportSummary importSummary : response.response().importSummaries()) {
- assertTei(importSummary, SUCCESS);
- assertEnrollments(importSummary, SUCCESS); // Because it is the first upload.Ownership is not defined
- assertEvents(importSummary, ERROR); // It takes enrollment ownership
- }
-
- TEIWebResponse response2 = executor.executeObjectCallWithAcceptedErrorCodes(trackedEntityInstanceService
- .postTrackedEntityInstances(wrapPayload(tei), this.strategy), Collections.singletonList(409),
- TEIWebResponse.class);
-
- assertThat(response2.response().status()).isEqualTo(SUCCESS);
-
- for (TEIImportSummary importSummary : response2.response().importSummaries()) {
- assertTei(importSummary, SUCCESS);
- assertEnrollments(importSummary, ERROR); // Because ownership was previously set
- }
- }
-
- // Make program protected
- // @Test
- public void tei_with_enrollment_in_search_scope_in_protected_program_breaking_glass() throws Exception {
-
- TrackedEntityInstance tei = teiWithEnrollmentInSearchScope();
-
- TEIWebResponse response = executor.executeObjectCallWithAcceptedErrorCodes(trackedEntityInstanceService
- .postTrackedEntityInstances(wrapPayload(tei), this.strategy), Collections.singletonList(409),
- TEIWebResponse.class);
-
- assertThat(response.response().status()).isEqualTo(SUCCESS);
-
- for (TEIImportSummary importSummary : response.response().importSummaries()) {
- assertTei(importSummary, SUCCESS);
- assertEnrollments(importSummary, SUCCESS); // Because it is the first upload.Ownership is not defined
- assertEvents(importSummary, ERROR); // It takes enrollment ownership
- }
-
- HttpMessageResponse glassResponse =
- executor.executeObjectCall(ownershipService.breakGlass(tei.uid(), program, "Sync"));
-
- TEIWebResponse response2 = executor.executeObjectCallWithAcceptedErrorCodes(trackedEntityInstanceService
- .postTrackedEntityInstances(wrapPayload(tei), this.strategy), Collections.singletonList(409),
- TEIWebResponse.class);
-
- assertThat(response2.response().status()).isEqualTo(SUCCESS);
-
- for (TEIImportSummary importSummary : response2.response().importSummaries()) {
- assertTei(importSummary, SUCCESS);
- assertEnrollments(importSummary, SUCCESS);
- assertEvents(importSummary, SUCCESS);
-
- }
- }
-
- private TrackedEntityInstance validTei() {
- return TrackedEntityInstanceInternalAccessor
- .insertEnrollments(TrackedEntityInstance.builder(), Arrays.asList(validEnrollment()))
- .uid(uidGenerator.generate())
- .organisationUnit(captureOrgunit)
- .trackedEntityType(trackedEntityType)
- .trackedEntityAttributeValues(Arrays.asList(
- TrackedEntityAttributeValue.builder()
- .trackedEntityAttribute(attribute1)
- .value("Test")
- .build(),
- TrackedEntityAttributeValue.builder()
- .trackedEntityAttribute(attribute2)
- .value("TrackedEntity")
- .build()
- ))
- .build();
- }
-
- private Enrollment validEnrollment() {
- return EnrollmentInternalAccessor.insertEvents(Enrollment.builder(), Arrays.asList(validEvent()))
- .uid(uidGenerator.generate())
- .organisationUnit(captureOrgunit)
- .program(program)
- .status(EnrollmentStatus.ACTIVE)
- .build();
- }
-
- private Event validEvent() {
- return Event.builder()
- .uid(uidGenerator.generate())
- .organisationUnit(captureOrgunit)
- .programStage(programStage1)
- .attributeOptionCombo(attributeOptionCombo)
- .build();
- }
-
- private TrackedEntityInstancePayload wrapPayload(TrackedEntityInstance... instances) {
- TrackedEntityInstancePayload payload = TrackedEntityInstancePayload.create(Arrays.asList(instances));
- return payload;
- }
-
- private TrackedEntityInstance teiWithEventInSearchScope() {
-
- return TrackedEntityInstanceInternalAccessor.insertEnrollments(validTei().toBuilder(),
- Collections.singletonList(
- EnrollmentInternalAccessor.insertEvents(validEnrollment().toBuilder(),
- Collections.singletonList(validEvent().toBuilder()
- .organisationUnit(searchOrgunit)
- .build()))
- .build()))
- .build();
- }
-
- private TrackedEntityInstance teiWithEnrollmentInSearchScope() {
- return TrackedEntityInstanceInternalAccessor.insertEnrollments(validTei().toBuilder(), Collections.singletonList(
- EnrollmentInternalAccessor.insertEvents(validEnrollment().toBuilder(),
- Collections.singletonList(validEvent()))
- .organisationUnit(searchOrgunit).build()))
- .build();
- }
-
- private TrackedEntityInstance teiInSearchScope() {
- return validTei().toBuilder()
- .organisationUnit(searchOrgunit)
- .build();
- }
-
- private void login() {
- d2.userModule().logIn(username, password, serverUrl).blockingGet();
- }
-}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/BreakTheGlassAPIShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/BreakTheGlassAPIShould.kt
new file mode 100644
index 0000000000..d02d2b6be8
--- /dev/null
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/BreakTheGlassAPIShould.kt
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2004-2023, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.hisp.dhis.android.core.trackedentity.api
+
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runTest
+import org.hisp.dhis.android.core.BaseRealIntegrationTest
+import org.hisp.dhis.android.core.arch.api.executors.internal.CoroutineAPICallExecutor
+import org.hisp.dhis.android.core.arch.helpers.UidGenerator
+import org.hisp.dhis.android.core.arch.helpers.UidGeneratorImpl
+import org.hisp.dhis.android.core.data.server.RealServerMother
+import org.hisp.dhis.android.core.enrollment.Enrollment
+import org.hisp.dhis.android.core.enrollment.EnrollmentInternalAccessor
+import org.hisp.dhis.android.core.enrollment.EnrollmentStatus
+import org.hisp.dhis.android.core.event.Event
+import org.hisp.dhis.android.core.imports.ImportStatus
+import org.hisp.dhis.android.core.imports.internal.HttpMessageResponse
+import org.hisp.dhis.android.core.imports.internal.TEIWebResponse
+import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue
+import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance
+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.trackedentity.ownership.OwnershipService
+import org.junit.Before
+import java.util.Arrays
+
+@OptIn(ExperimentalCoroutinesApi::class)
+class BreakTheGlassAPIShould : BaseRealIntegrationTest() {
+ /**
+ * Expected configuration to run these tests:
+ * - user: android
+ * - role: not a superuser
+ * - capture orgunit: DiszpKrYNg8 - Negelhun CHC
+ * - search orgunit: YuQRtpLP10I - Badja
+ *
+ *
+ * - read/write access to PROTECTED program: IpHINAT79UW
+ */
+ private val captureOrgunit = "DiszpKrYNg8" // Ngelehun CHC
+ private val searchOrgunit = "g8upMTyEZGZ" // Njandama MCHP
+ private val outOfScopeOrgunit = "jNb63DIHuwU" // Baoma Hospital
+ private val trackedEntityType = "nEenWmSyUEp" // Person
+ private val attribute1 = "w75KJ2mc4zz" // First name
+ private val attribute2 = "zDhUuAYrxNC" // Last name
+ private val program = "IpHINAT79UW" // Child programme
+ private val programStage1 = "A03MvHHogjR" // Birth
+ private val programStage2 = "ZzYYXq4fJie" // Baby Postnatal
+ private val attributeOptionCombo = "HllvX50cXC0" // Default
+
+ // API version dependant parameters
+ private val serverUrl = RealServerMother.url2_30
+ private val strategy = "SYNC"
+ private lateinit var executor: CoroutineAPICallExecutor
+ private lateinit var trackedEntityInstanceService: TrackedEntityInstanceService
+ private lateinit var ownershipService: OwnershipService
+ private val uidGenerator: UidGenerator = UidGeneratorImpl()
+
+ @Before
+ override fun setUp() {
+ super.setUp()
+ executor = d2.coroutineAPICallExecutor()
+ trackedEntityInstanceService = d2.retrofit().create(
+ TrackedEntityInstanceService::class.java,
+ )
+ ownershipService = d2.retrofit().create(OwnershipService::class.java)
+ login()
+ }
+
+ // @Test
+ @Throws(Exception::class)
+ fun tei_with_event_in_search_scope_in_open_program() = runTest {
+ val tei = teiWithEventInSearchScope()
+ for (i in 0..1) {
+ val response = postTrackedEntities(tei)
+ assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
+
+ for (importSummary in response.response()!!.importSummaries()!!) {
+ TrackedEntityInstanceUtils.assertTei(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEnrollments(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.SUCCESS)
+ }
+ }
+ }
+
+ // Make program protected
+ // @Test
+ @Throws(Exception::class)
+ fun tei_with_event_in_search_scope_in_protected_program() = runTest {
+ val tei = teiWithEventInSearchScope()
+
+ val response = postTrackedEntities(tei)
+ assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
+ for (importSummary in response.response()!!.importSummaries()!!) {
+ TrackedEntityInstanceUtils.assertTei(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEnrollments(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.SUCCESS)
+ }
+
+ val response2 = postTrackedEntities(tei)
+ assertThat(response2.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
+ for (importSummary in response2.response()!!.importSummaries()!!) {
+ TrackedEntityInstanceUtils.assertTei(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEnrollments(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.SUCCESS)
+ }
+ }
+
+ // Make program protected
+ // @Test
+ @Throws(Exception::class)
+ fun tei_with_enrollment_in_search_scope_in_protected_program() = runTest {
+ val tei = teiWithEnrollmentInSearchScope()
+ val response = postTrackedEntities(tei)
+ assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
+ for (importSummary in response.response()!!.importSummaries()!!) {
+ TrackedEntityInstanceUtils.assertTei(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEnrollments(
+ importSummary,
+ ImportStatus.SUCCESS,
+ ) // Because it is the first upload.Ownership is not defined
+ TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.ERROR) // It takes enrollment ownership
+ }
+
+ val response2 = postTrackedEntities(tei)
+ assertThat(response2.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
+ for (importSummary in response2.response()!!.importSummaries()!!) {
+ TrackedEntityInstanceUtils.assertTei(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEnrollments(
+ importSummary,
+ ImportStatus.ERROR,
+ ) // Because ownership was previously set
+ }
+ }
+
+ // Make program protected
+ // @Test
+ @Throws(Exception::class)
+ fun tei_with_enrollment_in_search_scope_in_protected_program_breaking_glass() = runTest {
+ val tei = teiWithEnrollmentInSearchScope()
+ val response = postTrackedEntities(tei)
+ assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
+ for (importSummary in response.response()!!.importSummaries()!!) {
+ TrackedEntityInstanceUtils.assertTei(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEnrollments(
+ importSummary,
+ ImportStatus.SUCCESS,
+ ) // Because it is the first upload.Ownership is not defined
+ TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.ERROR) // It takes enrollment ownership
+ }
+
+ val glassResponse: HttpMessageResponse =
+ executor.wrap { ownershipService.breakGlass(tei.uid(), program, "Sync") }.getOrThrow()
+
+ val response2 = postTrackedEntities(tei)
+ assertThat(response2.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
+ for (importSummary in response2.response()!!.importSummaries()!!) {
+ TrackedEntityInstanceUtils.assertTei(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEnrollments(importSummary, ImportStatus.SUCCESS)
+ TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.SUCCESS)
+ }
+ }
+
+ private fun validTei(): TrackedEntityInstance {
+ return TrackedEntityInstanceInternalAccessor
+ .insertEnrollments(TrackedEntityInstance.builder(), Arrays.asList(validEnrollment()))
+ .uid(uidGenerator.generate())
+ .organisationUnit(captureOrgunit)
+ .trackedEntityType(trackedEntityType)
+ .trackedEntityAttributeValues(
+ Arrays.asList(
+ TrackedEntityAttributeValue.builder()
+ .trackedEntityAttribute(attribute1)
+ .value("Test")
+ .build(),
+ TrackedEntityAttributeValue.builder()
+ .trackedEntityAttribute(attribute2)
+ .value("TrackedEntity")
+ .build(),
+ ),
+ )
+ .build()
+ }
+
+ private fun validEnrollment(): Enrollment {
+ return EnrollmentInternalAccessor.insertEvents(Enrollment.builder(), Arrays.asList(validEvent()))
+ .uid(uidGenerator.generate())
+ .organisationUnit(captureOrgunit)
+ .program(program)
+ .status(EnrollmentStatus.ACTIVE)
+ .build()
+ }
+
+ private fun validEvent(): Event {
+ return Event.builder()
+ .uid(uidGenerator.generate())
+ .organisationUnit(captureOrgunit)
+ .programStage(programStage1)
+ .attributeOptionCombo(attributeOptionCombo)
+ .build()
+ }
+
+ private fun wrapPayload(vararg instances: TrackedEntityInstance): TrackedEntityInstancePayload {
+ return TrackedEntityInstancePayload.create(listOf(*instances))
+ }
+
+ private fun teiWithEventInSearchScope(): TrackedEntityInstance {
+ return TrackedEntityInstanceInternalAccessor.insertEnrollments(
+ validTei().toBuilder(),
+ listOf(
+ EnrollmentInternalAccessor.insertEvents(
+ validEnrollment().toBuilder(),
+ listOf(
+ validEvent().toBuilder()
+ .organisationUnit(searchOrgunit)
+ .build(),
+ ),
+ )
+ .build(),
+ ),
+ )
+ .build()
+ }
+
+ private fun teiWithEnrollmentInSearchScope(): TrackedEntityInstance {
+ return TrackedEntityInstanceInternalAccessor.insertEnrollments(
+ validTei().toBuilder(),
+ listOf(
+ EnrollmentInternalAccessor.insertEvents(validEnrollment().toBuilder(), listOf(validEvent()))
+ .organisationUnit(searchOrgunit).build(),
+ ),
+ )
+ .build()
+ }
+
+ private fun teiInSearchScope(): TrackedEntityInstance {
+ return validTei().toBuilder()
+ .organisationUnit(searchOrgunit)
+ .build()
+ }
+
+ private suspend fun postTrackedEntities(vararg instances: TrackedEntityInstance): TEIWebResponse {
+ return executor.wrap(
+ storeError = false,
+ acceptedErrorCodes = listOf(409),
+ errorClass = TEIWebResponse::class.java,
+ ) {
+ trackedEntityInstanceService
+ .postTrackedEntityInstances(wrapPayload(*instances), strategy)
+ }.getOrThrow()
+ }
+
+ private fun login() {
+ d2.userModule().logIn(username, password, serverUrl).blockingGet()
+ }
+}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/TrackedEntityInstanceAPIShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/TrackedEntityInstanceAPIShould.kt
index 74c1949309..8903a73c19 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/TrackedEntityInstanceAPIShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/api/TrackedEntityInstanceAPIShould.kt
@@ -28,10 +28,11 @@
package org.hisp.dhis.android.core.trackedentity.api
import com.google.common.truth.Truth.assertThat
-import java.util.*
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runTest
import org.hisp.dhis.android.core.BaseRealIntegrationTest
-import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutor
-import org.hisp.dhis.android.core.arch.api.executors.internal.APICallExecutorImpl
+import org.hisp.dhis.android.core.arch.api.executors.internal.CoroutineAPICallExecutor
+import org.hisp.dhis.android.core.arch.api.payload.internal.Payload
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.enrollment.EnrollmentInternalAccessor
import org.hisp.dhis.android.core.enrollment.EnrollmentStatus
@@ -40,6 +41,7 @@ import org.hisp.dhis.android.core.event.EventStatus
import org.hisp.dhis.android.core.imports.ImportStatus
import org.hisp.dhis.android.core.imports.internal.TEIWebResponse
import org.hisp.dhis.android.core.maintenance.D2Error
+import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceInternalAccessor
import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceFields
@@ -47,36 +49,34 @@ import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstancePa
import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceService
import org.junit.Assert
import org.junit.Before
+import java.util.*
+@OptIn(ExperimentalCoroutinesApi::class)
abstract class TrackedEntityInstanceAPIShould internal constructor(
// API version dependant parameters
private val serverUrl: String,
- private val strategy: String
+ private val strategy: String,
) : BaseRealIntegrationTest() {
- private lateinit var executor: APICallExecutor
+ private lateinit var executor: CoroutineAPICallExecutor
private lateinit var trackedEntityInstanceService: TrackedEntityInstanceService
@Before
override fun setUp() {
super.setUp()
- executor = APICallExecutorImpl.create(d2.databaseAdapter(), null)
+ executor = d2.coroutineAPICallExecutor()
trackedEntityInstanceService = d2.retrofit().create(
- TrackedEntityInstanceService::class.java
+ TrackedEntityInstanceService::class.java,
)
}
// @Test
@Throws(Exception::class)
- fun tei_with_invalid_tracked_entity_attribute() {
+ fun tei_with_invalid_tracked_entity_attribute() = runTest {
login()
val validTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstance()
val invalidTEI = TrackedEntityInstanceUtils.createTrackedEntityInstanceWithInvalidAttribute()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI, invalidTEI))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.ERROR)
@@ -89,22 +89,9 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
}
// Check server status
- val serverValidTEI = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI.uid(),
- TrackedEntityInstanceFields.allFields,
- true,
- true
- )
- )
+ val serverValidTEI = getTrackedEntity(validTEI.uid())
try {
- executor.executeObjectCall(
- trackedEntityInstanceService.getTrackedEntityInstanceAsCall(
- invalidTEI.uid(),
- TrackedEntityInstanceFields.allFields, true, true
- )
- )
+ getTrackedEntity(invalidTEI.uid())
Assert.fail("Should not reach that line")
} catch (e: D2Error) {
assertThat(e.httpErrorCode()).isEqualTo(404)
@@ -114,16 +101,12 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
// @Test
@Throws(Exception::class)
- fun tei_with_invalid_orgunit() {
+ fun tei_with_invalid_orgunit() = runTest {
login()
val validTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstance()
val invalidTEI = TrackedEntityInstanceUtils.createTrackedEntityInstanceWithInvalidOrgunit()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI, invalidTEI))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.ERROR)
@@ -136,20 +119,9 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
}
// Check server status
- val serverValidTEI = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI = getTrackedEntity(validTEI.uid())
try {
- executor.executeObjectCall(
- trackedEntityInstanceService.getTrackedEntityInstanceAsCall(
- invalidTEI.uid(),
- TrackedEntityInstanceFields.allFields, true, true
- )
- )
+ getTrackedEntity(invalidTEI.uid())
Assert.fail("Should not reach that line")
} catch (e: D2Error) {
assertThat(e.httpErrorCode()).isEqualTo(404)
@@ -159,16 +131,12 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
// @Test
@Throws(Exception::class)
- fun enrollment_with_valid_values() {
+ fun enrollment_with_valid_values() = runTest {
login()
val validTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstance()
val invalidTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceAndEnrollment()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI, invalidTEI))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (validTEI.uid() == importSummary.reference()) {
@@ -179,34 +147,18 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
}
// TODO Check server status
- val serverValidTEI = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
- val serverInvalidTEI = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- invalidTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI = getTrackedEntity(validTEI.uid())
+ val serverInvalidTEI = getTrackedEntity(invalidTEI.uid())
}
// @Test
@Throws(Exception::class)
- fun enrollment_future_date() {
+ fun enrollment_future_date() = runTest {
login()
val validTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceAndEnrollment()
val invalidTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceWithFutureEnrollment()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI, invalidTEI))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (validTEI.uid() == importSummary.reference()) {
@@ -217,36 +169,20 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
TrackedEntityInstanceUtils.assertEnrollments(importSummary, ImportStatus.ERROR)
}
}
- val serverValidTEI = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
- val serverInvalidTEI = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- invalidTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI = getTrackedEntity(validTEI.uid())
+ val serverInvalidTEI = getTrackedEntity(invalidTEI.uid())
assertThat(getEnrollments(serverValidTEI.items()[0])).isNotEmpty()
assertThat(getEnrollments(serverInvalidTEI.items()[0])).isEmpty()
}
// @Test
@Throws(Exception::class)
- fun already_active_enrollment() {
+ fun already_active_enrollment() = runTest {
login()
val validTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceAndEnrollment()
val invalidTEI = TrackedEntityInstanceUtils.createTrackedEntityInstanceAndTwoActiveEnrollment()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI, invalidTEI))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (validTEI.uid() == importSummary.reference()) {
@@ -259,36 +195,20 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
assertThat(importSummary.enrollments()!!.ignored()).isEqualTo(1)
}
}
- val serverValidTEI = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
- val serverInvalidTEI = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- invalidTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI = getTrackedEntity(validTEI.uid())
+ val serverInvalidTEI = getTrackedEntity(invalidTEI.uid())
assertThat(getEnrollments(serverValidTEI.items()[0]).size).isEqualTo(1)
assertThat(getEnrollments(serverInvalidTEI.items()[0]).size).isEqualTo(1)
}
// @Test
@Throws(Exception::class)
- fun event_with_valid_values() {
+ fun event_with_valid_values() = runTest {
login()
val validTEI1 = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceAndEnrollment()
val validTEI2 = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceWithEnrollmentAndEvent()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI1, validTEI2))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (validTEI1.uid() == importSummary.reference()) {
@@ -300,20 +220,8 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.SUCCESS)
}
}
- val serverValidTEI1 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI1.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
- val serverValidTEI2 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI2.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI1 = getTrackedEntity(validTEI1.uid())
+ val serverValidTEI2 = getTrackedEntity(validTEI2.uid())
assertThat(getEnrollments(serverValidTEI1.items()[0]).size).isEqualTo(1)
assertThat(getEnrollments(serverValidTEI2.items()[0]).size).isEqualTo(1)
assertThat(getEvents(getEnrollments(serverValidTEI2.items()[0])[0]).size).isEqualTo(1)
@@ -322,16 +230,12 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
// IMPORTANT: check the programStage is set to "NO WRITE ACCESS" before running the test
// @Test
@Throws(Exception::class)
- fun event_with_no_write_access() {
+ fun event_with_no_write_access() = runTest {
login()
val validTEI1 = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceAndEnrollment()
val validTEI2 = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceWithEnrollmentAndEvent()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI1, validTEI2))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (validTEI1.uid() == importSummary.reference()) {
@@ -343,20 +247,8 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.ERROR)
}
}
- val serverValidTEI1 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI1.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
- val serverValidTEI2 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI2.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI1 = getTrackedEntity(validTEI1.uid())
+ val serverValidTEI2 = getTrackedEntity(validTEI2.uid())
assertThat(getEnrollments(serverValidTEI1.items()[0]).size).isEqualTo(1)
assertThat(getEvents(getEnrollments(serverValidTEI1.items()[0])[0])).isEmpty()
assertThat(getEnrollments(serverValidTEI2.items()[0]).size).isEqualTo(1)
@@ -365,16 +257,12 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
// @Test
@Throws(Exception::class)
- fun event_with_future_event_date_does_not_fail() {
+ fun event_with_future_event_date_does_not_fail() = runTest {
login()
val validTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceWithEnrollmentAndEvent()
val invalidTEI = TrackedEntityInstanceUtils.createTrackedEntityInstanceWithEnrollmentAndFutureEvent()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI, invalidTEI))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (validTEI.uid() == importSummary.reference()) {
@@ -387,20 +275,8 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.SUCCESS)
}
}
- val serverValidTEI1 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
- val serverValidTEI2 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- invalidTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI1 = getTrackedEntity(validTEI.uid())
+ val serverValidTEI2 = getTrackedEntity(invalidTEI.uid())
assertThat(getEnrollments(serverValidTEI1.items()[0]).size).isEqualTo(1)
assertThat(getEvents(getEnrollments(serverValidTEI1.items()[0])[0]).size).isEqualTo(1)
assertThat(getEnrollments(serverValidTEI2.items()[0]).size).isEqualTo(1)
@@ -409,16 +285,12 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
// @Test
@Throws(Exception::class)
- fun event_with_invalid_data_element() {
+ fun event_with_invalid_data_element() = runTest {
login()
val validTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceWithEnrollmentAndEvent()
val invalidTEI = TrackedEntityInstanceUtils.createTrackedEntityInstanceWithInvalidDataElement()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI, invalidTEI))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (validTEI.uid() == importSummary.reference()) {
@@ -431,46 +303,30 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.WARNING)
}
}
- val serverValidTEI1 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
- val serverValidTEI2 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- invalidTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI1 = getTrackedEntity(validTEI.uid())
+ val serverValidTEI2 = getTrackedEntity(invalidTEI.uid())
assertThat(getEnrollments(serverValidTEI1.items()[0]).size).isEqualTo(1)
assertThat(getEvents(getEnrollments(serverValidTEI1.items()[0])[0]).size).isEqualTo(1)
assertThat(
getEvents(getEnrollments(serverValidTEI1.items()[0])[0])[0]!!
- .trackedEntityDataValues()!!.size
+ .trackedEntityDataValues()!!.size,
).isEqualTo(1)
assertThat(getEnrollments(serverValidTEI2.items()[0]).size).isEqualTo(1)
assertThat(getEvents(getEnrollments(serverValidTEI2.items()[0])[0]).size).isEqualTo(1)
assertThat(
getEvents(getEnrollments(serverValidTEI2.items()[0])[0])[0]!!
- .trackedEntityDataValues()
+ .trackedEntityDataValues(),
).isEmpty()
}
// @Test
@Throws(Exception::class)
- fun event_with_valid_and_invalid_data_value() {
+ fun event_with_valid_and_invalid_data_value() = runTest {
login()
val validTEI = TrackedEntityInstanceUtils.createValidTrackedEntityInstanceWithEnrollmentAndEvent()
val invalidTEI = TrackedEntityInstanceUtils.createTrackedEntityInstanceWithValidAndInvalidDataValue()
val payload = TrackedEntityInstancePayload.create(listOf(validTEI, invalidTEI))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (validTEI.uid() == importSummary.reference()) {
@@ -483,47 +339,31 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.WARNING)
}
}
- val serverValidTEI1 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- validTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
- val serverValidTEI2 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- invalidTEI.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI1 = getTrackedEntity(validTEI.uid())
+ val serverValidTEI2 = getTrackedEntity(invalidTEI.uid())
assertThat(getEnrollments(serverValidTEI1.items()[0]).size).isEqualTo(1)
assertThat(getEvents(getEnrollments(serverValidTEI1.items()[0])[0]).size).isEqualTo(1)
assertThat(
getEvents(getEnrollments(serverValidTEI1.items()[0])[0])[0]!!
- .trackedEntityDataValues()!!.size
+ .trackedEntityDataValues()!!.size,
).isEqualTo(1)
assertThat(getEnrollments(serverValidTEI2.items()[0]).size).isEqualTo(1)
assertThat(getEvents(getEnrollments(serverValidTEI2.items()[0])[0]).size).isEqualTo(1)
assertThat(
getEvents(getEnrollments(serverValidTEI2.items()[0])[0])[0]!!
- .trackedEntityDataValues()!!.size
+ .trackedEntityDataValues()!!.size,
).isEqualTo(1)
}
// This test is failing
// @Test
@Throws(Exception::class)
- fun event_in_completed_enrollment() {
+ fun event_in_completed_enrollment() = runTest {
login()
val completedEnrollment =
TrackedEntityInstanceUtils.createTrackedEntityInstanceWithCompletedEnrollmentAndEvent()
val payload = TrackedEntityInstancePayload.create(listOf(completedEnrollment))
- val response = executor.executeObjectCallWithAcceptedErrorCodes(
- trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ val response = executePostCall(payload)
assertThat(response.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (importSummary in response.response()!!.importSummaries()!!) {
if (completedEnrollment.uid() == importSummary.reference()) {
@@ -532,46 +372,40 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
TrackedEntityInstanceUtils.assertEvents(importSummary, ImportStatus.SUCCESS)
}
}
- val serverValidTEI1 = executor.executeObjectCall(
- trackedEntityInstanceService
- .getTrackedEntityInstanceAsCall(
- completedEnrollment.uid(), TrackedEntityInstanceFields.allFields,
- true, true
- )
- )
+ val serverValidTEI1 = getTrackedEntity(completedEnrollment.uid())
assertThat(getEnrollments(serverValidTEI1.items()[0]).size).isEqualTo(1)
assertThat(
getEnrollments(serverValidTEI1.items()[0])[0]!!
- .status()
+ .status(),
).isEqualTo(EnrollmentStatus.COMPLETED)
assertThat(getEvents(getEnrollments(serverValidTEI1.items()[0])[0]).size).isEqualTo(1)
assertThat(
getEvents(getEnrollments(serverValidTEI1.items()[0])[0])[0]!!
- .trackedEntityDataValues()!!.size
+ .trackedEntityDataValues()!!.size,
).isEqualTo(1)
assertThat(
getEvents(
- getEnrollments(serverValidTEI1.items()[0])[0]
- )[0]!!.status()
+ getEnrollments(serverValidTEI1.items()[0])[0],
+ )[0]!!.status(),
).isEqualTo(EventStatus.COMPLETED)
}
// @Test
@Throws(D2Error::class)
- fun tracked_entity_deletion_returns_deleted_equals_1() {
+ fun tracked_entity_deletion_returns_deleted_equals_1() = runTest {
login()
syncMetadata()
d2.trackedEntityModule().trackedEntityInstanceDownloader().limit(100).blockingDownload()
val instance = instanceWithOneEnrollmentAndOneEvent
val deletedEvents = setEventsToDelete(instance)
val deletedEventsPayload = TrackedEntityInstancePayload.create(listOf(deletedEvents))
- val deletedEventsResponse = executePostCall(deletedEventsPayload, strategy)
+ val deletedEventsResponse = executePostCall(deletedEventsPayload)
assertThat(deletedEventsResponse.response()!!.status()).isEqualTo(ImportStatus.SUCCESS)
for (teiImportSummaries in deletedEventsResponse.response()!!.importSummaries()!!) {
assertThat(teiImportSummaries.importCount().updated()).isEqualTo(1)
for (
- enrollmentImportSummary in teiImportSummaries.enrollments()!!
- .importSummaries()!!
+ enrollmentImportSummary in teiImportSummaries.enrollments()!!
+ .importSummaries()!!
) {
assertThat(enrollmentImportSummary.importCount().updated()).isEqualTo(1)
for (eventImportSummary in enrollmentImportSummary.events()!!.importSummaries()!!) {
@@ -590,12 +424,27 @@ abstract class TrackedEntityInstanceAPIShould internal constructor(
}
@Throws(D2Error::class)
- private fun executePostCall(payload: TrackedEntityInstancePayload, strategy: String): TEIWebResponse {
- return executor.executeObjectCallWithAcceptedErrorCodes(
+ private suspend fun executePostCall(payload: TrackedEntityInstancePayload): TEIWebResponse {
+ return executor.wrap(
+ storeError = false,
+ acceptedErrorCodes = listOf(409),
+ errorClass = TEIWebResponse::class.java,
+ ) {
+ trackedEntityInstanceService.postTrackedEntityInstances(payload, strategy)
+ }.getOrThrow()
+ }
+
+ private suspend fun getTrackedEntity(teiUid: String): Payload {
+ return executor.wrap {
trackedEntityInstanceService
- .postTrackedEntityInstances(payload, strategy),
- listOf(409), TEIWebResponse::class.java
- )
+ .getTrackedEntityInstance(
+ teiUid,
+ OrganisationUnitMode.ACCESSIBLE.name,
+ TrackedEntityInstanceFields.allFields,
+ includeAllAttributes = true,
+ includeDeleted = true,
+ )
+ }.getOrThrow()
}
private val instanceWithOneEnrollmentAndOneEvent: TrackedEntityInstance
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/AttributeValueFilterStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/AttributeValueFilterStoreIntegrationShould.kt
index f3187a916f..b341849f93 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/AttributeValueFilterStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/AttributeValueFilterStoreIntegrationShould.kt
@@ -31,16 +31,15 @@ import org.hisp.dhis.android.core.common.tableinfo.ItemFilterTableInfo
import org.hisp.dhis.android.core.data.database.ObjectStoreAbstractIntegrationShould
import org.hisp.dhis.android.core.data.trackedentity.AttributeValueFilterSamples
import org.hisp.dhis.android.core.trackedentity.AttributeValueFilter
-import org.hisp.dhis.android.core.trackedentity.internal.AttributeValueFilterStore.create
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class AttributeValueFilterStoreIntegrationShould : ObjectStoreAbstractIntegrationShould(
- create(TestDatabaseAdapterFactory.get()),
+ AttributeValueFilterStoreImpl(TestDatabaseAdapterFactory.get()),
ItemFilterTableInfo.TABLE_INFO,
- TestDatabaseAdapterFactory.get()
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): AttributeValueFilter {
return AttributeValueFilterSamples.get()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/BasePayloadGeneratorMockIntegration.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/BasePayloadGeneratorMockIntegration.kt
index 55aeeeab89..6ddf0a2522 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/BasePayloadGeneratorMockIntegration.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/BasePayloadGeneratorMockIntegration.kt
@@ -43,16 +43,16 @@ import org.hisp.dhis.android.core.event.internal.EventStore
import org.hisp.dhis.android.core.event.internal.EventStoreImpl
import org.hisp.dhis.android.core.maintenance.D2Error
import org.hisp.dhis.android.core.maintenance.internal.ForeignKeyCleanerImpl
-import org.hisp.dhis.android.core.organisationunit.internal.OrganisationUnitStore.create
-import org.hisp.dhis.android.core.program.internal.ProgramStageStore
+import org.hisp.dhis.android.core.organisationunit.internal.OrganisationUnitStoreImpl
+import org.hisp.dhis.android.core.program.internal.ProgramStageStoreImpl
import org.hisp.dhis.android.core.program.internal.ProgramStore
-import org.hisp.dhis.android.core.program.internal.ProgramStoreInterface
+import org.hisp.dhis.android.core.program.internal.ProgramStoreImpl
import org.hisp.dhis.android.core.relationship.RelationshipConstraintType
import org.hisp.dhis.android.core.relationship.RelationshipHelper
import org.hisp.dhis.android.core.relationship.RelationshipItem
import org.hisp.dhis.android.core.relationship.internal.RelationshipItemStoreImpl
import org.hisp.dhis.android.core.relationship.internal.RelationshipStoreImpl
-import org.hisp.dhis.android.core.relationship.internal.RelationshipTypeStore
+import org.hisp.dhis.android.core.relationship.internal.RelationshipTypeStoreImpl
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceInternalAccessor
import org.hisp.dhis.android.core.trackedentity.TrackedEntityType
@@ -79,19 +79,19 @@ open class BasePayloadGeneratorMockIntegration : BaseMockIntegrationTestMetadata
}
protected fun storeTrackerData() {
- val orgUnit = create(databaseAdapter).selectFirst()
- val teiType = TrackedEntityTypeStore.create(databaseAdapter).selectFirst()
- val program = d2.programModule().programs().one().blockingGet()
- val programStage = ProgramStageStore.create(databaseAdapter).selectFirst()
+ val orgUnit = OrganisationUnitStoreImpl(databaseAdapter).selectFirst()!!
+ val teiType = TrackedEntityTypeStoreImpl(databaseAdapter).selectFirst()!!
+ val program = d2.programModule().programs().one().blockingGet()!!
+ val programStage = ProgramStageStoreImpl(databaseAdapter).selectFirst()!!
val dataValue1 = TrackedEntityDataValueSamples.get().toBuilder().event(event1Id).build()
val event1 = Event.builder()
.uid(event1Id)
.enrollment(enrollment1Id)
- .organisationUnit(orgUnit!!.uid())
+ .organisationUnit(orgUnit.uid())
.program(program.uid())
- .programStage(programStage!!.uid())
+ .programStage(programStage.uid())
.syncState(State.TO_UPDATE)
.aggregatedSyncState(State.TO_UPDATE)
.trackedEntityDataValues(listOf(dataValue1))
@@ -150,10 +150,11 @@ open class BasePayloadGeneratorMockIntegration : BaseMockIntegrationTestMetadata
.build()
val tei = TrackedEntityInstanceInternalAccessor.insertEnrollments(
- TrackedEntityInstance.builder(), listOf(enrollment1, enrollment2, enrollment3)
+ TrackedEntityInstance.builder(),
+ listOf(enrollment1, enrollment2, enrollment3),
)
.uid(teiId)
- .trackedEntityType(teiType!!.uid())
+ .trackedEntityType(teiType.uid())
.organisationUnit(orgUnit.uid())
.syncState(State.TO_POST)
.aggregatedSyncState(State.TO_POST)
@@ -186,16 +187,16 @@ open class BasePayloadGeneratorMockIntegration : BaseMockIntegrationTestMetadata
}
protected fun storeSimpleTrackedEntityInstance(teiUid: String, state: State) {
- val orgUnit = create(databaseAdapter).selectFirst()
- val teiType = TrackedEntityTypeStore.create(databaseAdapter).selectFirst()
- TrackedEntityInstanceStoreImpl.create(databaseAdapter).insert(
+ val orgUnit = OrganisationUnitStoreImpl(databaseAdapter).selectFirst()
+ val teiType = TrackedEntityTypeStoreImpl(databaseAdapter).selectFirst()
+ TrackedEntityInstanceStoreImpl(databaseAdapter).insert(
TrackedEntityInstanceSamples.get().toBuilder()
.uid(teiUid)
.trackedEntityType(teiType!!.uid())
.organisationUnit(orgUnit!!.uid())
.syncState(state)
.aggregatedSyncState(state)
- .build()
+ .build(),
)
}
@@ -203,7 +204,7 @@ open class BasePayloadGeneratorMockIntegration : BaseMockIntegrationTestMetadata
protected fun storeRelationship(
relationshipUid: String,
from: String,
- to: String
+ to: String,
) {
storeRelationship(relationshipUid, RelationshipHelper.teiItem(from), RelationshipHelper.teiItem(to))
}
@@ -212,28 +213,28 @@ open class BasePayloadGeneratorMockIntegration : BaseMockIntegrationTestMetadata
protected fun storeRelationship(
relationshipUid: String,
from: RelationshipItem,
- to: RelationshipItem
+ to: RelationshipItem,
) {
- val relationshipType = RelationshipTypeStore.create(databaseAdapter).selectFirst()
+ val relationshipType = RelationshipTypeStoreImpl(databaseAdapter).selectFirst()
val executor = D2CallExecutor.create(databaseAdapter)
executor.executeD2CallTransactionally {
- RelationshipStoreImpl.create(databaseAdapter).insert(
+ RelationshipStoreImpl(databaseAdapter).insert(
RelationshipSamples.get230(relationshipUid, from, to).toBuilder()
.relationshipType(relationshipType!!.uid())
.syncState(State.TO_POST)
- .build()
+ .build(),
)
- RelationshipItemStoreImpl.create(databaseAdapter).insert(
+ RelationshipItemStoreImpl(databaseAdapter).insert(
from.toBuilder()
.relationship(ObjectWithUid.create(relationshipUid))
.relationshipItemType(RelationshipConstraintType.FROM)
- .build()
+ .build(),
)
- RelationshipItemStoreImpl.create(databaseAdapter).insert(
+ RelationshipItemStoreImpl(databaseAdapter).insert(
to.toBuilder()
.relationship(ObjectWithUid.create(relationshipUid))
.relationshipItemType(RelationshipConstraintType.TO)
- .build()
+ .build(),
)
ForeignKeyCleanerImpl.create(databaseAdapter).cleanForeignKeyErrors()
null
@@ -255,20 +256,20 @@ open class BasePayloadGeneratorMockIntegration : BaseMockIntegrationTestMetadata
internal lateinit var eventStore: EventStore
internal lateinit var enrollmentStore: EnrollmentStore
internal lateinit var trackedEntityTypeStore: IdentifiableObjectStore
- internal lateinit var programStore: ProgramStoreInterface
+ internal lateinit var programStore: ProgramStore
@BeforeClass
@JvmStatic
@Throws(Exception::class)
fun setUp() {
setUpClass()
- oldTrackerPayloadGenerator = objects.d2DIComponent.oldTrackerImporterPayloadGenerator()
- teiStore = TrackedEntityInstanceStoreImpl.create(databaseAdapter)
- teiDataValueStore = TrackedEntityDataValueStoreImpl.create(databaseAdapter)
- eventStore = EventStoreImpl.create(databaseAdapter)
- enrollmentStore = EnrollmentStoreImpl.create(databaseAdapter)
- trackedEntityTypeStore = TrackedEntityTypeStore.create(databaseAdapter)
- programStore = ProgramStore.create(databaseAdapter)
+ oldTrackerPayloadGenerator = objects.d2DIComponent.oldTrackerImporterPayloadGenerator
+ teiStore = TrackedEntityInstanceStoreImpl(databaseAdapter)
+ teiDataValueStore = TrackedEntityDataValueStoreImpl(databaseAdapter)
+ eventStore = EventStoreImpl(databaseAdapter)
+ enrollmentStore = EnrollmentStoreImpl(databaseAdapter)
+ trackedEntityTypeStore = TrackedEntityTypeStoreImpl(databaseAdapter)
+ programStore = ProgramStoreImpl(databaseAdapter)
}
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/OldTrackerImporterPayloadGeneratorMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/OldTrackerImporterPayloadGeneratorMockIntegrationShould.kt
index efd97fdb3b..74e4978d83 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/OldTrackerImporterPayloadGeneratorMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/OldTrackerImporterPayloadGeneratorMockIntegrationShould.kt
@@ -84,7 +84,7 @@ class OldTrackerImporterPayloadGeneratorMockIntegrationShould : BasePayloadGener
storeRelationship(
relationshipUid = "relationship1",
from = RelationshipHelper.teiItem(teiId),
- to = RelationshipHelper.eventItem(singleEventId)
+ to = RelationshipHelper.eventItem(singleEventId),
)
val instance = teiStore.selectByUid(teiId)!!
@@ -106,7 +106,7 @@ class OldTrackerImporterPayloadGeneratorMockIntegrationShould : BasePayloadGener
storeRelationship(
relationshipUid = "relationship1",
from = RelationshipHelper.teiItem(fromTeiUid),
- to = RelationshipHelper.eventItem(event1Id)
+ to = RelationshipHelper.eventItem(event1Id),
)
val instance = teiStore.selectByUid(fromTeiUid)!!
@@ -124,7 +124,7 @@ class OldTrackerImporterPayloadGeneratorMockIntegrationShould : BasePayloadGener
storeRelationship(
relationshipUid = "relationship1",
from = RelationshipHelper.teiItem(fromTeiUid),
- to = RelationshipHelper.enrollmentItem(enrollment1Id)
+ to = RelationshipHelper.enrollmentItem(enrollment1Id),
)
val instance = teiStore.selectByUid(fromTeiUid)!!
@@ -142,7 +142,7 @@ class OldTrackerImporterPayloadGeneratorMockIntegrationShould : BasePayloadGener
storeRelationship(
relationshipUid = "relationship1",
from = RelationshipHelper.teiItem(fromTeiUid),
- to = RelationshipHelper.teiItem(teiId)
+ to = RelationshipHelper.teiItem(teiId),
)
val instance = teiStore.selectByUid(fromTeiUid)!!
@@ -172,7 +172,7 @@ class OldTrackerImporterPayloadGeneratorMockIntegrationShould : BasePayloadGener
storeRelationship(
relationshipUid = "relationship1",
from = RelationshipHelper.eventItem(singleEventId),
- to = RelationshipHelper.teiItem(teiId)
+ to = RelationshipHelper.teiItem(teiId),
)
val event = eventStore.selectByUid(singleEventId)!!
@@ -193,7 +193,7 @@ class OldTrackerImporterPayloadGeneratorMockIntegrationShould : BasePayloadGener
storeRelationship(
relationshipUid = "relationship1",
from = RelationshipHelper.enrollmentItem(enrollment1Id),
- to = RelationshipHelper.enrollmentItem(enrollment1Id)
+ to = RelationshipHelper.enrollmentItem(enrollment1Id),
)
val instance = teiStore.selectByUid(teiId)!!
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/ReservedValueSettingStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/ReservedValueSettingStoreIntegrationShould.java
index 0954104f8a..39c14b4641 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/ReservedValueSettingStoreIntegrationShould.java
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/ReservedValueSettingStoreIntegrationShould.java
@@ -41,7 +41,7 @@ public class ReservedValueSettingStoreIntegrationShould extends
IdentifiableObjectStoreAbstractIntegrationShould {
public ReservedValueSettingStoreIntegrationShould() {
- super(ReservedValueSettingStore.create(TestDatabaseAdapterFactory.get()),
+ super(new ReservedValueSettingStoreImpl(TestDatabaseAdapterFactory.get()),
ReservedValueSettingTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
}
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 231aff2280..9dd9140df1 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
@@ -67,7 +67,7 @@ public void download_and_persist_reserved_values() {
syncMetadata();
reserveValues();
- List reservedValues = TrackedEntityAttributeReservedValueStore.create(
+ List reservedValues = new TrackedEntityAttributeReservedValueStoreImpl(
d2.databaseAdapter()).selectAll();
assertThat(reservedValues.size()).isEqualTo(numberToReserve);
@@ -79,7 +79,7 @@ public void download_and_persist_all_reserved_values() {
syncMetadata();
d2.trackedEntityModule().reservedValueManager().blockingDownloadAllReservedValues(20);
- List reservedValues = TrackedEntityAttributeReservedValueStore.create(
+ List reservedValues = new TrackedEntityAttributeReservedValueStoreImpl(
d2.databaseAdapter()).selectAll();
String value = d2.trackedEntityModule().reservedValueManager().blockingGetValue("xs8A6tQJY0s", orgunitUid);
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 39ccce7416..30e1814238 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,10 +28,13 @@
package org.hisp.dhis.android.core.trackedentity.internal;
+import static com.google.common.truth.Truth.assertThat;
+import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.parseDate;
+
import org.hisp.dhis.android.core.BaseIntegrationTestWithDatabase;
-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.organisationunit.internal.OrganisationUnitStoreImpl;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValue;
import org.junit.After;
import org.junit.Before;
@@ -43,9 +46,6 @@
import java.util.Date;
import java.util.List;
-import static com.google.common.truth.Truth.assertThat;
-import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.parseDate;
-
@RunWith(JUnit4.class)
public class TrackedEntityAttributeReservedValueStoreIntegrationShould extends BaseIntegrationTestWithDatabase {
@@ -59,20 +59,20 @@ public class TrackedEntityAttributeReservedValueStoreIntegrationShould extends B
private final String ownerUid = "owUid";
// object to test
- private TrackedEntityAttributeReservedValueStoreInterface store;
- private IdentifiableObjectStore organisationUnitStore;
+ private TrackedEntityAttributeReservedValueStore store;
+ private OrganisationUnitStore organisationUnitStore;
@Before
public void setUp() throws IOException {
super.setUp();
- store = TrackedEntityAttributeReservedValueStore.create(databaseAdapter());
+ store = new TrackedEntityAttributeReservedValueStoreImpl(databaseAdapter());
serverDate = parseDate("2018-05-13T12:35:36.743");
Date expiredDate = parseDate("2018-05-12T12:35:36.743");
Date notExpiredDate = parseDate("2018-05-17T12:35:36.743");
OrganisationUnit organisationUnit = OrganisationUnit.builder().uid(orgUnitUid).build();
- organisationUnitStore = OrganisationUnitStore.create(databaseAdapter());
+ organisationUnitStore = new OrganisationUnitStoreImpl(databaseAdapter());
organisationUnitStore.insert(organisationUnit);
TrackedEntityAttributeReservedValue.Builder builder = TrackedEntityAttributeReservedValue.builder()
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 b5aa5f45d9..cf62e1f184 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
@@ -41,7 +41,7 @@ public class TrackedEntityAttributeStoreIntegrationShould
extends IdentifiableObjectStoreAbstractIntegrationShould {
public TrackedEntityAttributeStoreIntegrationShould() {
- super(TrackedEntityAttributeStore.create(TestDatabaseAdapterFactory.get()),
+ super(new TrackedEntityAttributeStoreImpl(TestDatabaseAdapterFactory.get()),
TrackedEntityAttributeTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
}
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 4778d45693..89254df101 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
@@ -41,7 +41,7 @@ public class TrackedEntityAttributeValueStoreIntegrationShould
extends ObjectWithoutUidStoreAbstractIntegrationShould {
public TrackedEntityAttributeValueStoreIntegrationShould() {
- super(TrackedEntityAttributeValueStoreImpl.create(TestDatabaseAdapterFactory.get()),
+ super(new TrackedEntityAttributeValueStoreImpl(TestDatabaseAdapterFactory.get()),
TrackedEntityAttributeValueTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
}
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 2b0a05b3a0..138a75db8d 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
@@ -47,8 +47,8 @@
import org.hisp.dhis.android.core.event.internal.EventStoreImpl;
import org.hisp.dhis.android.core.program.ProgramStage;
import org.hisp.dhis.android.core.program.ProgramStageDataElement;
-import org.hisp.dhis.android.core.program.internal.ProgramStageDataElementStore;
-import org.hisp.dhis.android.core.program.internal.ProgramStageStore;
+import org.hisp.dhis.android.core.program.internal.ProgramStageDataElementStoreImpl;
+import org.hisp.dhis.android.core.program.internal.ProgramStageStoreImpl;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueTableInfo;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance;
@@ -71,9 +71,9 @@ public class TrackedEntityDataValueStoreIntegrationShould
protected TrackedEntityDataValueStore store;
public TrackedEntityDataValueStoreIntegrationShould() {
- super(TrackedEntityDataValueStoreImpl.create(TestDatabaseAdapterFactory.get()),
+ super(new TrackedEntityDataValueStoreImpl(TestDatabaseAdapterFactory.get()),
TrackedEntityDataValueTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
- this.store = TrackedEntityDataValueStoreImpl.create(TestDatabaseAdapterFactory.get());
+ this.store = new TrackedEntityDataValueStoreImpl(TestDatabaseAdapterFactory.get());
}
@Override
@@ -84,11 +84,11 @@ protected TrackedEntityDataValue buildObject() {
@After
public void tearDown() {
super.tearDown();
- TrackedEntityInstanceStoreImpl.create(TestDatabaseAdapterFactory.get()).delete();
- EnrollmentStoreImpl.create(TestDatabaseAdapterFactory.get()).delete();
- EventStoreImpl.create(TestDatabaseAdapterFactory.get()).delete();
- ProgramStageStore.create(TestDatabaseAdapterFactory.get()).delete();
- ProgramStageDataElementStore.create(TestDatabaseAdapterFactory.get()).delete();
+ new TrackedEntityInstanceStoreImpl(TestDatabaseAdapterFactory.get()).delete();
+ new EnrollmentStoreImpl(TestDatabaseAdapterFactory.get()).delete();
+ new EventStoreImpl(TestDatabaseAdapterFactory.get()).delete();
+ new ProgramStageStoreImpl(TestDatabaseAdapterFactory.get()).delete();
+ new ProgramStageDataElementStoreImpl(TestDatabaseAdapterFactory.get()).delete();
}
@Override
@@ -139,7 +139,7 @@ public void select_data_values_by_event_uid() {
@Test
public void select_single_events_data_values() {
- EventStore eventStore = EventStoreImpl.create(TestDatabaseAdapterFactory.get());
+ EventStore eventStore = new EventStoreImpl(TestDatabaseAdapterFactory.get());
eventStore.insert(EventSamples.get().toBuilder().uid("event_1").enrollment(null).syncState(State.TO_POST).build());
eventStore.insert(EventSamples.get().toBuilder().uid("event_2").syncState(State.TO_POST).build());
assertThat(eventStore.count()).isEqualTo(2);
@@ -162,19 +162,19 @@ public void select_single_events_data_values() {
@Test
public void select_tracker_data_values() {
- TrackedEntityInstanceStore trackedEntityInstanceStore = TrackedEntityInstanceStoreImpl
- .create(TestDatabaseAdapterFactory.get());
+ TrackedEntityInstanceStore trackedEntityInstanceStore =
+ new TrackedEntityInstanceStoreImpl(TestDatabaseAdapterFactory.get());
TrackedEntityInstance trackedEntityInstance = TrackedEntityInstance.builder().uid("tei_uid")
.organisationUnit("organisation_unit_uid").trackedEntityType("tei_type").syncState(State.TO_POST).build();
trackedEntityInstanceStore.insert(trackedEntityInstance);
- EnrollmentStore enrollmentStore = EnrollmentStoreImpl.create(TestDatabaseAdapterFactory.get());
+ EnrollmentStore enrollmentStore = new EnrollmentStoreImpl(TestDatabaseAdapterFactory.get());
Enrollment enrollment = Enrollment.builder().uid("enrollment").organisationUnit("organisation_unit")
.program("program").trackedEntityInstance("tei_uid")
.aggregatedSyncState(State.TO_POST).syncState(State.TO_POST).build();
enrollmentStore.insert(enrollment);
- EventStore eventStore = EventStoreImpl.create(TestDatabaseAdapterFactory.get());
+ EventStore eventStore = new EventStoreImpl(TestDatabaseAdapterFactory.get());
eventStore.insert(EventSamples.get().toBuilder().uid("event_1").syncState(State.TO_POST).build());
eventStore.insert(EventSamples.get().toBuilder().uid("event_2").enrollment(null).syncState(State.TO_POST).build());
@@ -198,17 +198,17 @@ public void select_tracker_data_values() {
@Test
public void remove_unassigned_event_values() {
ProgramStage stage = ProgramStageSamples.getProgramStage().toBuilder().uid("stage_uid").build();
- IdentifiableObjectStore stageStore = ProgramStageStore.create(TestDatabaseAdapterFactory.get());
+ IdentifiableObjectStore stageStore = new ProgramStageStoreImpl(TestDatabaseAdapterFactory.get());
stageStore.insert(stage);
Event event = EventSamples.get().toBuilder().uid("event_1").programStage(stage.uid()).build();
- EventStore eventStore = EventStoreImpl.create(TestDatabaseAdapterFactory.get());
+ EventStore eventStore = new EventStoreImpl(TestDatabaseAdapterFactory.get());
eventStore.insert(event);
String dataElement1 = "data_element_1";
String dataElement2 = "data_element_2";
IdentifiableObjectStore psStore =
- ProgramStageDataElementStore.create(TestDatabaseAdapterFactory.get());
+ new ProgramStageDataElementStoreImpl(TestDatabaseAdapterFactory.get());
psStore.insert(ProgramStageDataElementSamples.getProgramStageDataElement().toBuilder()
.uid(dataElement1)
.dataElement(DataElementSamples.getDataElement().toBuilder().uid(dataElement1).build())
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceCallBaseMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceCallBaseMockIntegrationShould.kt
index 2f53c79ce9..c5285d2806 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceCallBaseMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceCallBaseMockIntegrationShould.kt
@@ -28,7 +28,6 @@
package org.hisp.dhis.android.core.trackedentity.internal
import com.google.common.truth.Truth.assertThat
-import java.io.IOException
import junit.framework.Assert.fail
import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder
import org.hisp.dhis.android.core.common.State
@@ -41,7 +40,7 @@ import org.hisp.dhis.android.core.event.internal.EventStoreImpl
import org.hisp.dhis.android.core.maintenance.D2Error
import org.hisp.dhis.android.core.maintenance.D2ErrorCode
import org.hisp.dhis.android.core.settings.SynchronizationSettings
-import org.hisp.dhis.android.core.settings.internal.SynchronizationSettingStore
+import org.hisp.dhis.android.core.settings.internal.SynchronizationSettingStoreImpl
import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance
@@ -52,6 +51,7 @@ import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTest
import org.junit.After
import org.junit.Before
import org.junit.Test
+import java.io.IOException
abstract class TrackedEntityInstanceCallBaseMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueable() {
@@ -64,7 +64,7 @@ abstract class TrackedEntityInstanceCallBaseMockIntegrationShould : BaseMockInte
abstract val teiWithRelationshipFile: String
private lateinit var initSyncParams: SynchronizationSettings
- private val syncStore = SynchronizationSettingStore.create(databaseAdapter)
+ private val syncStore = SynchronizationSettingStoreImpl(databaseAdapter)
@Before
fun setUp() {
@@ -117,7 +117,7 @@ abstract class TrackedEntityInstanceCallBaseMockIntegrationShould : BaseMockInte
verifyDownloadedTrackedEntityInstanceSingle(
teiWithRemovedDataFile,
- teiUid
+ teiUid,
)
}
@@ -215,35 +215,38 @@ abstract class TrackedEntityInstanceCallBaseMockIntegrationShould : BaseMockInte
}
private fun getDownloadedTei(teiUid: String): TrackedEntityInstance? {
- val teiAttributeValuesStore = TrackedEntityAttributeValueStoreImpl.create(databaseAdapter)
+ val teiAttributeValuesStore = TrackedEntityAttributeValueStoreImpl(databaseAdapter)
val attValues = teiAttributeValuesStore.queryByTrackedEntityInstance(teiUid)
val attValuesWithoutIdAndTEI = attValues.map {
it.toBuilder().id(null).trackedEntityInstance(null).build()
}
- val teiStore = TrackedEntityInstanceStoreImpl.create(databaseAdapter)
+ val teiStore = TrackedEntityInstanceStoreImpl(databaseAdapter)
val downloadedTei = teiStore.selectByUid(teiUid)
- val enrollmentStore = EnrollmentStoreImpl.create(databaseAdapter)
+ val enrollmentStore = EnrollmentStoreImpl(databaseAdapter)
val downloadedEnrollments = enrollmentStore.selectWhere(
WhereClauseBuilder()
- .appendKeyStringValue(EnrollmentTableInfo.Columns.TRACKED_ENTITY_INSTANCE, teiUid).build()
+ .appendKeyStringValue(EnrollmentTableInfo.Columns.TRACKED_ENTITY_INSTANCE, teiUid).build(),
)
val downloadedEnrollmentsWithoutIdAndDeleteFalse = downloadedEnrollments.map {
it.toBuilder().id(null).deleted(false).notes(ArrayList()).build()
}
- val eventStore = EventStoreImpl.create(databaseAdapter)
+ val eventStore = EventStoreImpl(databaseAdapter)
val downloadedEventsWithoutValues = eventStore.selectAll()
val downloadedEventsWithoutValuesAndDeleteFalse = downloadedEventsWithoutValues.map {
it.toBuilder().id(null).deleted(false).build()
}
- val dataValueList = TrackedEntityDataValueStoreImpl.create(databaseAdapter).selectAll()
+ val dataValueList = TrackedEntityDataValueStoreImpl(databaseAdapter).selectAll()
val downloadedValues = dataValueList.groupBy { it.event() }
return createTei(
- downloadedTei, attValuesWithoutIdAndTEI, downloadedEnrollmentsWithoutIdAndDeleteFalse,
- downloadedEventsWithoutValuesAndDeleteFalse, downloadedValues
+ downloadedTei,
+ attValuesWithoutIdAndTEI,
+ downloadedEnrollmentsWithoutIdAndDeleteFalse,
+ downloadedEventsWithoutValuesAndDeleteFalse,
+ downloadedValues,
)
}
@@ -252,7 +255,7 @@ abstract class TrackedEntityInstanceCallBaseMockIntegrationShould : BaseMockInte
attValuesWithoutIdAndTEI: List,
downloadedEnrollmentsWithoutEvents: List,
downloadedEventsWithoutValues: List,
- downloadedValues: Map?>
+ downloadedValues: Map?>,
): TrackedEntityInstance? {
val downloadedEvents = downloadedEventsWithoutValues.map { event ->
val trackedEntityDataValuesWithNullIdsAndEvents = downloadedValues[event.uid()]!!.map {
@@ -265,7 +268,7 @@ abstract class TrackedEntityInstanceCallBaseMockIntegrationShould : BaseMockInte
val downloadedEnrollments = downloadedEnrollmentsWithoutEvents.map { enrollment ->
EnrollmentInternalAccessor.insertEvents(
enrollment.toBuilder(),
- downloadedEvents[enrollment.uid()]
+ downloadedEvents[enrollment.uid()],
)
.trackedEntityInstance(downloadedTei!!.uid())
.build()
@@ -275,9 +278,10 @@ abstract class TrackedEntityInstanceCallBaseMockIntegrationShould : BaseMockInte
return TrackedEntityInstanceInternalAccessor.insertEnrollments(
TrackedEntityInstanceInternalAccessor.insertRelationships(
- downloadedTei!!.toBuilder(), relationships
+ downloadedTei!!.toBuilder(),
+ relationships,
),
- downloadedEnrollments
+ downloadedEnrollments,
)
.id(null)
.deleted(false)
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceDownloadCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceDownloadCallMockIntegrationShould.kt
index 64d3307f3b..dc54a7cefe 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceDownloadCallMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceDownloadCallMockIntegrationShould.kt
@@ -39,6 +39,8 @@ class TrackedEntityInstanceDownloadCallMockIntegrationShould : BaseMockIntegrati
fun emit_progress() {
val testObserver = d2.trackedEntityModule().trackedEntityInstanceDownloader().download().test()
+ testObserver.awaitTerminalEvent()
+
testObserver.assertValueCount(5)
testObserver.assertValueAt(0) { v: TrackerD2Progress ->
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceEventFilterStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceEventFilterStoreIntegrationShould.java
index 1e0d5b5b72..3c8486748e 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceEventFilterStoreIntegrationShould.java
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceEventFilterStoreIntegrationShould.java
@@ -41,7 +41,7 @@ public class TrackedEntityInstanceEventFilterStoreIntegrationShould
extends ObjectStoreAbstractIntegrationShould {
public TrackedEntityInstanceEventFilterStoreIntegrationShould() {
- super(TrackedEntityInstanceEventFilterStore.create(TestDatabaseAdapterFactory.get()),
+ super(new TrackedEntityInstanceEventFilterStoreImpl(TestDatabaseAdapterFactory.get()),
TrackedEntityInstanceEventFilterTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterStoreIntegrationShould.kt
index 381805bb5a..398339c5d8 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterStoreIntegrationShould.kt
@@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.data.database.IdentifiableObjectStoreAbstractI
import org.hisp.dhis.android.core.data.trackedentity.TrackedEntityInstanceFilterSamples
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceFilter
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceFilterTableInfo
-import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceFilterStore.create
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.runner.RunWith
@@ -39,8 +38,9 @@ import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class TrackedEntityInstanceFilterStoreIntegrationShould :
IdentifiableObjectStoreAbstractIntegrationShould(
- create(TestDatabaseAdapterFactory.get()),
- TrackedEntityInstanceFilterTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()
+ TrackedEntityInstanceFilterStoreImpl(TestDatabaseAdapterFactory.get()),
+ TrackedEntityInstanceFilterTableInfo.TABLE_INFO,
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): TrackedEntityInstanceFilter {
return TrackedEntityInstanceFilterSamples.get()
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 d193d594ef..61d6ea228c 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
@@ -107,11 +107,11 @@ public class TrackedEntityInstancePostCallRealIntegrationShould extends BaseReal
public void setUp() {
super.setUp();
- trackedEntityInstanceStore = TrackedEntityInstanceStoreImpl.create(d2.databaseAdapter());
- enrollmentStore = EnrollmentStoreImpl.create(d2.databaseAdapter());
- eventStore = EventStoreImpl.create(d2.databaseAdapter());
- trackedEntityAttributeValueStore = TrackedEntityAttributeValueStoreImpl.create(d2.databaseAdapter());
- trackedEntityDataValueStore = TrackedEntityDataValueStoreImpl.create(d2.databaseAdapter());
+ trackedEntityInstanceStore = new TrackedEntityInstanceStoreImpl(d2.databaseAdapter());
+ enrollmentStore = new EnrollmentStoreImpl(d2.databaseAdapter());
+ eventStore = new EventStoreImpl(d2.databaseAdapter());
+ trackedEntityAttributeValueStore = new TrackedEntityAttributeValueStoreImpl(d2.databaseAdapter());
+ trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(d2.databaseAdapter());
uidGenerator = new UidGeneratorImpl();
orgUnitUid = "DiszpKrYNg8";
@@ -135,9 +135,9 @@ public void setUp() {
}
/*
- * If you want run this test you need config the correct uids in the server side.
- * At this moment is necessary add into the "child programme" program the category combo : Implementing Partner
- * */
+ * If you want run this test you need config the correct uids in the server side.
+ * At this moment is necessary add into the "child programme" program the category combo : Implementing Partner
+ * */
//@Test
public void response_true_when_data_sync() throws Exception {
downloadMetadata();
@@ -207,9 +207,9 @@ public void add_and_post_tei_using_repositories() throws Exception {
/*
- * If you want run this test you need config the correct uids in the server side.
- * At this moment is necessary add into the "child programme" program the category combo : Implementing Partner
- * */
+ * If you want run this test you need config the correct uids in the server side.
+ * At this moment is necessary add into the "child programme" program the category combo : Implementing Partner
+ * */
//@Test
public void pull_event_after_push_tracked_entity_instance_with_that_event() throws Exception {
@@ -290,7 +290,7 @@ public void post_more_than_one_tei() throws Exception {
d2.trackedEntityModule().trackedEntityInstanceDownloader().byUid().eq(newUid1).blockingDownload();
- List teiList = d2.trackedEntityModule().trackedEntityInstances().byUid().eq(newUid1).blockingGet();
+ List teiList = d2.trackedEntityModule().trackedEntityInstances().byUid().eq(newUid1).blockingGet();
assertThat(teiList.size() == 1).isTrue();
}
@@ -315,7 +315,7 @@ public void post_teis_filtering_what_to_post() throws Exception {
d2.trackedEntityModule().trackedEntityInstanceDownloader().byUid().eq(newUid1).blockingDownload();
- List teiList = d2.trackedEntityModule().trackedEntityInstances().byUid().eq(newUid1).blockingGet();
+ List teiList = d2.trackedEntityModule().trackedEntityInstances().byUid().eq(newUid1).blockingGet();
assertThat(teiList.size() == 1).isTrue();
@@ -345,7 +345,7 @@ public void post_one_tei_and_delete_it() throws Exception {
d2.trackedEntityModule().trackedEntityInstances().blockingUpload();
d2.trackedEntityModule().trackedEntityInstanceDownloader().byUid().eq(newUid).blockingDownload();
- List response = d2.trackedEntityModule().trackedEntityInstances().byUid().eq(newUid).blockingGet();
+ List response = d2.trackedEntityModule().trackedEntityInstances().byUid().eq(newUid).blockingGet();
assertThat(response.size()).isEqualTo(1);
@@ -504,7 +504,7 @@ private void createDummyDataToPost(String orgUnitUid, String programUid, String
String trackedEntityUid, String coordinates, Geometry geometry,
String eventUid, String enrollmentUid, String trackedEntityInstanceUid,
String trackedEntityAttributeUid, String dataElementUid) {
-
+
Date refDate = getCurrentDateMinusTwoHoursTenMinutes();
TrackedEntityInstance trackedEntityInstance = TrackedEntityInstance.builder()
@@ -573,19 +573,19 @@ private void assertPushAndDownloadTrackedEntityInstances(
private TrackedEntityInstance getTrackedEntityInstanceFromDB(String trackedEntityInstanceUid) {
TrackedEntityInstance trackedEntityInstance = null;
TrackedEntityInstance storedTrackedEntityInstance = trackedEntityInstanceStore.selectByUid(trackedEntityInstanceUid);
- if(storedTrackedEntityInstance.uid().equals(trackedEntityInstanceUid)) {
+ if (storedTrackedEntityInstance.uid().equals(trackedEntityInstanceUid)) {
trackedEntityInstance = storedTrackedEntityInstance;
}
return trackedEntityInstance;
}
private Enrollment getEnrollmentsByTrackedEntityInstanceFromDb(String trackedEntityInstanceUid) {
- EnrollmentStore enrollmentStore = EnrollmentStoreImpl.create(d2.databaseAdapter());
+ EnrollmentStore enrollmentStore = new EnrollmentStoreImpl(d2.databaseAdapter());
Enrollment enrollment = null;
List storedEnrollments = enrollmentStore.selectWhere(new WhereClauseBuilder()
.appendKeyStringValue(EnrollmentTableInfo.Columns.TRACKED_ENTITY_INSTANCE, trackedEntityInstanceUid).build());
for (Enrollment storedEnrollment : storedEnrollments) {
- if(storedEnrollment.uid().equals(enrollmentUid)) {
+ if (storedEnrollment.uid().equals(enrollmentUid)) {
enrollment = storedEnrollment;
}
}
@@ -595,8 +595,8 @@ private Enrollment getEnrollmentsByTrackedEntityInstanceFromDb(String trackedEnt
private Event getEventsFromDb(String eventUid) {
Event event = null;
List storedEvents = eventStore.selectAll();
- for(Event storedEvent : storedEvents) {
- if(storedEvent.uid().equals(eventUid)) {
+ for (Event storedEvent : storedEvents) {
+ if (storedEvent.uid().equals(eventUid)) {
event = storedEvent;
}
}
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 9e290f2159..46d50d610f 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
@@ -42,7 +42,7 @@ public class TrackedEntityInstanceStoreIntegrationShould extends
IdentifiableDataObjectStoreAbstractIntegrationShould {
public TrackedEntityInstanceStoreIntegrationShould() {
- super(TrackedEntityInstanceStoreImpl.create(TestDatabaseAdapterFactory.get()),
+ super(new TrackedEntityInstanceStoreImpl(TestDatabaseAdapterFactory.get()),
TrackedEntityInstanceTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceSyncStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceSyncStoreIntegrationShould.java
index 02ecdd57ed..5aca186e22 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceSyncStoreIntegrationShould.java
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceSyncStoreIntegrationShould.java
@@ -37,7 +37,7 @@
public class TrackedEntityInstanceSyncStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould {
public TrackedEntityInstanceSyncStoreIntegrationShould() {
- super(TrackedEntityInstanceSyncStore.create(TestDatabaseAdapterFactory.get()), TrackedEntityInstanceSyncTableInfo.TABLE_INFO,
+ super(new TrackedEntityInstanceSyncStoreImpl(TestDatabaseAdapterFactory.get()), TrackedEntityInstanceSyncTableInfo.TABLE_INFO,
TestDatabaseAdapterFactory.get());
}
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 511ed35eb9..fa6bb8b033 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
@@ -42,7 +42,7 @@ public class TrackedEntityTypeAttributeStoreIntegrationShould
extends LinkStoreAbstractIntegrationShould {
public TrackedEntityTypeAttributeStoreIntegrationShould() {
- super(TrackedEntityTypeAttributeStore.create(TestDatabaseAdapterFactory.get()),
+ super(new TrackedEntityTypeAttributeStoreImpl(TestDatabaseAdapterFactory.get()),
TrackedEntityTypeAttributeTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
}
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 d54dae51e7..6bce9bec4b 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
@@ -41,7 +41,7 @@ public class TrackedEntityTypeStoreIntegrationShould
extends IdentifiableObjectStoreAbstractIntegrationShould {
public TrackedEntityTypeStoreIntegrationShould() {
- super(TrackedEntityTypeStore.create(TestDatabaseAdapterFactory.get()),
+ super(new TrackedEntityTypeStoreImpl(TestDatabaseAdapterFactory.get()),
TrackedEntityTypeTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/ownership/ProgramOwnerStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/ownership/ProgramOwnerStoreIntegrationShould.kt
index 3e1d1e61d1..62b356b991 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/ownership/ProgramOwnerStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/ownership/ProgramOwnerStoreIntegrationShould.kt
@@ -29,16 +29,15 @@ package org.hisp.dhis.android.core.trackedentity.ownership
import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould
import org.hisp.dhis.android.core.data.trackedentity.ownership.ProgramOwnerSamples
-import org.hisp.dhis.android.core.trackedentity.ownership.ProgramOwnerStore.create
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class ProgramOwnerStoreIntegrationShould : ObjectWithoutUidStoreAbstractIntegrationShould(
- create(TestDatabaseAdapterFactory.get()),
+ ProgramOwnerStoreImpl(TestDatabaseAdapterFactory.get()),
ProgramOwnerTableInfo.TABLE_INFO,
- TestDatabaseAdapterFactory.get()
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): ProgramOwner {
return ProgramOwnerSamples.programOwner
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/ownership/ProgramTempOwnerStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/ownership/ProgramTempOwnerStoreIntegrationShould.kt
index 16c3a6de4d..cc86f4315d 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/ownership/ProgramTempOwnerStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/ownership/ProgramTempOwnerStoreIntegrationShould.kt
@@ -29,16 +29,15 @@ package org.hisp.dhis.android.core.trackedentity.ownership
import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould
import org.hisp.dhis.android.core.data.trackedentity.ownership.ProgramTempOwnerSamples
-import org.hisp.dhis.android.core.trackedentity.ownership.ProgramTempOwnerStore.create
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class ProgramTempOwnerStoreIntegrationShould : ObjectWithoutUidStoreAbstractIntegrationShould(
- create(TestDatabaseAdapterFactory.get()),
+ ProgramTempOwnerStoreImpl(TestDatabaseAdapterFactory.get()),
ProgramTempOwnerTableInfo.TABLE_INFO,
- TestDatabaseAdapterFactory.get()
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): ProgramTempOwner {
return ProgramTempOwnerSamples.programTempOwner
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelperMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelperMockIntegrationShould.kt
index b16e072dd9..0dd16ad38f 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelperMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelperMockIntegrationShould.kt
@@ -39,14 +39,11 @@ import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory
import org.hisp.dhis.android.core.period.internal.ParentPeriodGeneratorImpl.Companion.create
import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceStoreImpl
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher
-import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.Test
-import org.junit.runner.RunWith
-@RunWith(D2JunitRunner::class)
class TrackedEntityInstanceLocalQueryHelperMockIntegrationShould : BaseMockIntegrationTestFullDispatcher() {
- private val trackedEntityInstanceStore = TrackedEntityInstanceStoreImpl.create(databaseAdapter)
+ private val trackedEntityInstanceStore = TrackedEntityInstanceStoreImpl(databaseAdapter)
private val calendarProvider = CalendarProviderFactory.calendarProvider
private val periodHelper = DateFilterPeriodHelper(calendarProvider, create(calendarProvider))
@@ -60,18 +57,18 @@ class TrackedEntityInstanceLocalQueryHelperMockIntegrationShould : BaseMockInteg
.programDate(
DateFilterPeriod.builder()
.period(RelativePeriod.LAST_10_YEARS)
- .build()
+ .build(),
)
.incidentDate(
DateFilterPeriod.builder()
.period(RelativePeriod.LAST_3_MONTHS)
- .build()
+ .build(),
)
.enrollmentStatus(listOf(EnrollmentStatus.ACTIVE))
.eventDate(
DateFilterPeriod.builder()
.period(RelativePeriod.LAST_10_YEARS)
- .build()
+ .build(),
)
.eventStatus(listOf(EventStatus.ACTIVE))
.filter(
@@ -85,15 +82,15 @@ class TrackedEntityInstanceLocalQueryHelperMockIntegrationShould : BaseMockInteg
.key("attributeUid2")
.operator(FilterItemOperator.EQ)
.value("value2")
- .build()
- )
+ .build(),
+ ),
)
.query(
RepositoryScopeFilterItem.builder()
.key("")
.operator(FilterItemOperator.EQ)
.value("value1")
- .build()
+ .build(),
)
.trackedEntityType("trackedEntityTypeUid")
.orgUnitMode(OrganisationUnitMode.CAPTURE)
@@ -109,16 +106,16 @@ class TrackedEntityInstanceLocalQueryHelperMockIntegrationShould : BaseMockInteg
.eventDate(
DateFilterPeriod.builder()
.period(RelativePeriod.LAST_10_YEARS)
- .build()
+ .build(),
)
- .build()
- )
+ .build(),
+ ),
)
.states(listOf(State.SYNCED, State.TO_UPDATE))
.lastUpdatedDate(
DateFilterPeriod.builder()
.period(RelativePeriod.LAST_10_YEARS)
- .build()
+ .build(),
)
.order(
listOf(
@@ -129,8 +126,8 @@ class TrackedEntityInstanceLocalQueryHelperMockIntegrationShould : BaseMockInteg
TrackedEntityInstanceQueryScopeOrderByItem.builder()
.column(TrackedEntityInstanceQueryScopeOrderColumn.LAST_UPDATED)
.direction(RepositoryScope.OrderByDirection.ASC)
- .build()
- )
+ .build(),
+ ),
)
.build()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.kt
index 5da9c78af3..c0663cfa3d 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.kt
@@ -39,7 +39,7 @@ class TrackedEntityInstanceQueryAndDownloadRealIntegrationShould : BaseRealInteg
d2.metadataModule().blockingDownload()
val orgUnit = d2.organisationUnitModule().organisationUnits()
- .one().blockingGet().uid()
+ .one().blockingGet()!!.uid()
val queriedTeis = d2.trackedEntityModule().trackedEntityInstanceQuery()
.byOrgUnits().`in`(listOf(orgUnit))
.byOrgUnitMode().eq(OrganisationUnitMode.ACCESSIBLE)
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCallRealIntegrationShould.kt
index 0830387861..5f91ece7ce 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCallRealIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCallRealIntegrationShould.kt
@@ -28,11 +28,11 @@
package org.hisp.dhis.android.core.trackedentity.search
import com.google.common.truth.Truth.assertThat
-import java.util.*
import org.hisp.dhis.android.core.BaseRealIntegrationTest
import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode
import org.junit.Assert
import org.junit.Before
+import java.util.*
class TrackedEntityInstanceQueryCallRealIntegrationShould : BaseRealIntegrationTest() {
private lateinit var repository: TrackedEntityInstanceQueryCollectionRepository
@@ -479,7 +479,7 @@ class TrackedEntityInstanceQueryCallRealIntegrationShould : BaseRealIntegrationT
"aVlSMMvgVzf", "zAyK28LLaez", "IcVHzEm0b6Z", "lc3eMKXaEfw", "VfZnZ6UKyn8", "uYG1rUdsJJi",
"szbAJSWOXjT", "cZZG5BMDLps", "GRc9WXp9gSy", "kbPmt60yi0L", "vRC0stJ5y9Q", "tO01bqIipeD",
"iUauWFeH8Qp", "AXZq6q7Dr6E", "LZclRdyVk1t", "OI0BQUurVFS", "DwpbWkiqjMy", "MwfWgjMRgId",
- "Q2USZSJmcNK", "EJoI3HArJ2W", "E497Rk80ivZ", "nOYt1LtFSyU", "wbtk73Zwhj9", "cMFi8lYbXHY"
+ "Q2USZSJmcNK", "EJoI3HArJ2W", "E497Rk80ivZ", "nOYt1LtFSyU", "wbtk73Zwhj9", "cMFi8lYbXHY",
)
try {
repository.byOrgUnits().`in`(orgUnits).blockingGet()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould.kt
index 3c026cde3e..7a9d3545e2 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould.kt
@@ -32,13 +32,10 @@ import androidx.paging.PagedList
import com.jraska.livedata.TestObserver
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher
-import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestRule
-import org.junit.runner.RunWith
-@RunWith(D2JunitRunner::class)
class TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould : BaseMockIntegrationTestFullDispatcher() {
@get:Rule
@@ -48,7 +45,6 @@ class TrackedEntityInstanceQueryCollectionRepositoryMockIntegrationShould : Base
fun get_offline_initial_objects() {
val liveData = d2.trackedEntityModule().trackedEntityInstanceQuery()
.offlineOnly().getPaged(2)
-
TestObserver.test(liveData)
.awaitValue()
.assertHasValue()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/tracker/importer/internal/TrackerJobObjectStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/tracker/importer/internal/TrackerJobObjectStoreIntegrationShould.kt
index d23e904e57..ce7aa3f774 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/tracker/importer/internal/TrackerJobObjectStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/tracker/importer/internal/TrackerJobObjectStoreIntegrationShould.kt
@@ -29,16 +29,15 @@ package org.hisp.dhis.android.core.tracker.importer.internal
import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould
import org.hisp.dhis.android.core.data.tracker.importer.internal.TrackerJobObjectSamples
-import org.hisp.dhis.android.core.tracker.importer.internal.TrackerJobObjectStore.create
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class TrackerJobObjectStoreIntegrationShould : ObjectWithoutUidStoreAbstractIntegrationShould(
- create(TestDatabaseAdapterFactory.get()),
+ TrackerJobObjectStoreImpl(TestDatabaseAdapterFactory.get()),
TrackerJobObjectTableInfo.TABLE_INFO,
- TestDatabaseAdapterFactory.get()
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): TrackerJobObject {
return TrackerJobObjectSamples.get1()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/usecase/stock/internal/StockUseCaseStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/usecase/stock/internal/StockUseCaseStoreIntegrationShould.kt
index 88e1e9c11a..eb4471516d 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/usecase/stock/internal/StockUseCaseStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/usecase/stock/internal/StockUseCaseStoreIntegrationShould.kt
@@ -31,15 +31,15 @@ import org.hisp.dhis.android.core.data.database.IdentifiableObjectStoreAbstractI
import org.hisp.dhis.android.core.data.usecase.stock.InternalStockUseCaseSamples.get
import org.hisp.dhis.android.core.usecase.stock.InternalStockUseCase
import org.hisp.dhis.android.core.usecase.stock.StockUseCaseTableInfo
-import org.hisp.dhis.android.core.usecase.stock.internal.StockUseCaseStore.create
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class StockUseCaseStoreIntegrationShould : IdentifiableObjectStoreAbstractIntegrationShould(
- create(TestDatabaseAdapterFactory.get()), StockUseCaseTableInfo.TABLE_INFO,
- TestDatabaseAdapterFactory.get()
+ StockUseCaseStoreImpl(TestDatabaseAdapterFactory.get()),
+ StockUseCaseTableInfo.TABLE_INFO,
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): InternalStockUseCase {
return get()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/usecase/stock/internal/StockUseCaseTransactionLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/usecase/stock/internal/StockUseCaseTransactionLinkStoreIntegrationShould.kt
index 78a8e82d66..c871c70c6e 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/usecase/stock/internal/StockUseCaseTransactionLinkStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/usecase/stock/internal/StockUseCaseTransactionLinkStoreIntegrationShould.kt
@@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.data.database.LinkStoreAbstractIntegrationShou
import org.hisp.dhis.android.core.data.usecase.stock.InternalStockUseCaseTransactionSamples
import org.hisp.dhis.android.core.usecase.stock.InternalStockUseCaseTransaction
import org.hisp.dhis.android.core.usecase.stock.StockUseCaseTransactionTableInfo
-import org.hisp.dhis.android.core.usecase.stock.internal.StockUseCaseTransactionLinkStore.create
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.Test
@@ -41,8 +40,9 @@ import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class StockUseCaseTransactionLinkStoreIntegrationShould :
LinkStoreAbstractIntegrationShould(
- create(TestDatabaseAdapterFactory.get()),
- StockUseCaseTransactionTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()
+ StockUseCaseTransactionLinkStoreImpl(TestDatabaseAdapterFactory.get()),
+ StockUseCaseTransactionTableInfo.TABLE_INFO,
+ TestDatabaseAdapterFactory.get(),
) {
override fun addMasterUid(): String {
return InternalStockUseCaseTransactionSamples.get().programUid()!!
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/OpenIdConnectRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/OpenIdConnectRealIntegrationShould.kt
index 0cd1a75fb9..bfe2973fe0 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/OpenIdConnectRealIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/OpenIdConnectRealIntegrationShould.kt
@@ -27,6 +27,7 @@
*/
package org.hisp.dhis.android.core.user
+import kotlinx.coroutines.runBlocking
import net.openid.appauth.AuthState
import org.hisp.dhis.android.core.BaseRealIntegrationTest
@@ -34,7 +35,9 @@ class OpenIdConnectRealIntegrationShould : BaseRealIntegrationTest() {
// @Test(expected = D2Error::class)
fun throw_error_when_not_passing_token() {
- val logInCall = getD2DIComponent(d2).internalModules().user.logInCall
- logInCall.blockingLogInOpenIDConnect(url, AuthState())
+ val logInCall = getD2DIComponent(d2).internalModules.user.logInCall
+ runBlocking {
+ logInCall.blockingLogInOpenIDConnect(url, AuthState())
+ }
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserDisabledMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserDisabledMockIntegrationShould.kt
index 940da386a0..e14377ee94 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserDisabledMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserDisabledMockIntegrationShould.kt
@@ -84,7 +84,7 @@ class UserDisabledMockIntegrationShould : BaseMockIntegrationTestMetadataEnqueab
"DiszpKrYNg8",
"Ok9OQpitjQr",
"DwrQJzeChWp",
- "DwrQJzeChWp"
+ "DwrQJzeChWp",
).blockingSet("30")
}
}
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 06e3d0b6c6..14414407f2 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
@@ -41,7 +41,7 @@ public class AuthenticatedUserStoreIntegrationShould
extends ObjectWithoutUidStoreAbstractIntegrationShould {
public AuthenticatedUserStoreIntegrationShould() {
- super(AuthenticatedUserStore.create(TestDatabaseAdapterFactory.get()), AuthenticatedUserTableInfo.TABLE_INFO,
+ super(new AuthenticatedUserStoreImpl(TestDatabaseAdapterFactory.get()), AuthenticatedUserTableInfo.TABLE_INFO,
TestDatabaseAdapterFactory.get());
}
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 9c62bb9f23..0977f307d2 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
@@ -40,7 +40,7 @@
public class AuthorityStoreIntegrationShould extends ObjectStoreAbstractIntegrationShould {
public AuthorityStoreIntegrationShould() {
- super(AuthorityStore.create(TestDatabaseAdapterFactory.get()), AuthorityTableInfo.TABLE_INFO,
+ super(new AuthorityStoreImpl(TestDatabaseAdapterFactory.get()), AuthorityTableInfo.TABLE_INFO,
TestDatabaseAdapterFactory.get());
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogInCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogInCallMockIntegrationShould.kt
index 63a9f27c88..1593f85f0b 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogInCallMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogInCallMockIntegrationShould.kt
@@ -55,15 +55,15 @@ class LogInCallMockIntegrationShould : BaseMockIntegrationTestEmptyEnqueable() {
@Test
fun persist_user_in_data_base_when_call() {
login()
- val user = d2.userModule().user().blockingGet()
+ val user = d2.userModule().user().blockingGet()!!
assertThat(user.uid()).isEqualTo("DXyJmlo9rge")
assertThat(user.name()).isEqualTo("John Barnes")
assertThat(user.username()).isEqualTo("android")
- val userCredentials = d2.userModule().userCredentials().blockingGet()
+ val userCredentials = d2.userModule().userCredentials().blockingGet()!!
assertThat(userCredentials.username()).isEqualTo("android")
- val authenticatedUser = d2.userModule().authenticatedUser().blockingGet()
+ val authenticatedUser = d2.userModule().authenticatedUser().blockingGet()!!
assertThat(authenticatedUser.user()).isEqualTo("DXyJmlo9rge")
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.kt
index 6199cf6628..a183f5cc45 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.kt
@@ -28,6 +28,7 @@
package org.hisp.dhis.android.core.user.internal
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.test.runTest
import org.hisp.dhis.android.core.BaseRealIntegrationTest
import org.hisp.dhis.android.core.arch.db.access.SqliteCheckerUtility
import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectWithoutUidStore
@@ -42,16 +43,15 @@ class LogoutCallRealIntegrationShould : BaseRealIntegrationTest() {
@Before
override fun setUp() {
super.setUp()
- authenticatedUserStore = AuthenticatedUserStore.create(d2.databaseAdapter())
+ authenticatedUserStore = AuthenticatedUserStoreImpl(d2.databaseAdapter())
}
// @Test
- fun delete_credentials_when_log_out_after_sync_data() {
+ fun delete_credentials_when_log_out_after_sync_data() = runTest {
d2.userModule().logIn(username, password, url).blockingGet()
d2.metadataModule().blockingDownload()
- val eventCall = create(d2.retrofit(), "DiszpKrYNg8", 0, emptyList())
- eventCall.blockingGet()
+ create(d2.retrofit(), "DiszpKrYNg8", 0, emptyList())
assertThat(SqliteCheckerUtility.isDatabaseEmpty(d2.databaseAdapter())).isFalse()
d2.userModule().logOut().blockingAwait()
@@ -60,7 +60,7 @@ class LogoutCallRealIntegrationShould : BaseRealIntegrationTest() {
val authenticatedUser = authenticatedUserStore!!.selectFirst()
assertThat(authenticatedUser).isNotNull()
- assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull()
+ assertThat(getD2DIComponent(d2).credentialsSecureStore.get()).isNull()
}
// @Test
@@ -74,12 +74,12 @@ class LogoutCallRealIntegrationShould : BaseRealIntegrationTest() {
var authenticatedUser = authenticatedUserStore!!.selectFirst()
assertThat(authenticatedUser).isNotNull()
- assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull()
+ assertThat(getD2DIComponent(d2).credentialsSecureStore.get()).isNull()
d2.userModule().logIn(username, password, url).blockingGet()
authenticatedUser = authenticatedUserStore!!.selectFirst()
assertThat(authenticatedUser).isNotNull()
- assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull()
+ assertThat(getD2DIComponent(d2).credentialsSecureStore.get()).isNull()
}
// @Test
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateWithEncryptionMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateWithEncryptionMockIntegrationShould.kt
index f1fb65b0dc..26b1bb7b68 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateWithEncryptionMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserAuthenticateWithEncryptionMockIntegrationShould.kt
@@ -28,15 +28,21 @@
package org.hisp.dhis.android.core.user.internal
import com.google.common.truth.Truth.assertThat
-import org.hisp.dhis.android.core.D2
-import org.hisp.dhis.android.core.D2Factory.clear
-import org.hisp.dhis.android.core.D2Factory.forNewDatabase
-import org.hisp.dhis.android.core.mockwebserver.Dhis2MockServer
-import org.junit.AfterClass
-import org.junit.BeforeClass
+import org.hisp.dhis.android.core.data.server.RealServerMother
+import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyDispatcher
+import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
+import org.junit.Before
import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(D2JunitRunner::class)
+class UserAuthenticateWithEncryptionMockIntegrationShould : BaseMockIntegrationTestEmptyDispatcher() {
+
+ @Before
+ fun setUp() {
+ tryLogout()
+ }
-class UserAuthenticateWithEncryptionMockIntegrationShould {
@Test
fun return_false_for_blocking_is_logged_when_not_logged() {
assertThat(d2.userModule().blockingIsLogged()).isFalse()
@@ -89,29 +95,14 @@ class UserAuthenticateWithEncryptionMockIntegrationShould {
DatabaseAdapterFactory.setExperimentalEncryption(false);
}*/
private fun logIn() {
- d2.userModule().blockingLogIn("test_user", "test_password", dhis2MockServer.baseEndpoint)
+ freshLogin(
+ RealServerMother.username,
+ RealServerMother.password,
+ dhis2MockServer.baseEndpoint,
+ )
}
private fun logOut() {
d2.userModule().blockingLogOut()
}
-
- companion object {
- private lateinit var d2: D2
- private lateinit var dhis2MockServer: Dhis2MockServer
-
- @BeforeClass
- @JvmStatic
- fun setUpClass() {
- d2 = forNewDatabase()
- dhis2MockServer = Dhis2MockServer(0)
- dhis2MockServer.setRequestDispatcher()
- }
-
- @AfterClass
- @JvmStatic
- fun tearDown() {
- clear()
- }
- }
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserCallMockIntegrationShould.kt
index 7734da6840..2971fc2ff0 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserCallMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserCallMockIntegrationShould.kt
@@ -28,36 +28,35 @@
package org.hisp.dhis.android.core.user.internal
import com.google.common.truth.Truth.assertThat
-import java.util.concurrent.Callable
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runTest
import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore
import org.hisp.dhis.android.core.data.user.UserSamples
import org.hisp.dhis.android.core.user.User
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyEnqueable
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
-import org.junit.BeforeClass
+import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(D2JunitRunner::class)
class UserCallMockIntegrationShould : BaseMockIntegrationTestEmptyEnqueable() {
- companion object {
- private lateinit var userStore: IdentifiableObjectStore
+ private lateinit var userStore: IdentifiableObjectStore
+ private lateinit var userCall: suspend() -> User
- @BeforeClass
- @JvmStatic
- @Throws(Exception::class)
- internal fun setUpClass() {
- BaseMockIntegrationTestEmptyEnqueable.setUpClass()
- val userCall: Callable = objects.d2DIComponent.internalModules().user.userCall
- userStore = UserStore.create(databaseAdapter)
- dhis2MockServer.enqueueMockResponse("user/user38.json")
- userCall.call()
- }
+ @Before
+ fun setUp() {
+ userStore = UserStoreImpl(databaseAdapter)
+ userCall = { objects.d2DIComponent.internalModules.user.userCall.call() }
}
@Test
- fun persist_user_in_database_when_call() {
+ fun persist_user_in_database_when_call() = runTest {
+ dhis2MockServer.enqueueMockResponse("user/user38.json")
+ userCall.invoke()
+
assertThat(userStore.count()).isEqualTo(1)
assertThat(userStore.selectFirst()).isEqualTo(UserSamples.getUser())
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserOrganisationUnitLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserOrganisationUnitLinkStoreIntegrationShould.kt
index c0ad9c3eb6..871aa111d8 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserOrganisationUnitLinkStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserOrganisationUnitLinkStoreIntegrationShould.kt
@@ -33,7 +33,6 @@ import org.hisp.dhis.android.core.data.user.UserOrganisationUnitLinkSamples
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.android.core.user.UserOrganisationUnitLink
import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkTableInfo
-import org.hisp.dhis.android.core.user.internal.UserOrganisationUnitLinkStoreImpl.Companion.create
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.Test
@@ -41,8 +40,9 @@ import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class UserOrganisationUnitLinkStoreIntegrationShould : LinkStoreAbstractIntegrationShould(
- create(TestDatabaseAdapterFactory.get()),
- UserOrganisationUnitLinkTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()
+ UserOrganisationUnitLinkStoreImpl(TestDatabaseAdapterFactory.get()),
+ UserOrganisationUnitLinkTableInfo.TABLE_INFO,
+ TestDatabaseAdapterFactory.get(),
) {
private var linkStore: UserOrganisationUnitLinkStore = store as UserOrganisationUnitLinkStore
@@ -65,11 +65,11 @@ class UserOrganisationUnitLinkStoreIntegrationShould : LinkStoreAbstractIntegrat
linkStore.insert(UserOrganisationUnitLinkSamples.getUserOrganisationUnitLink())
linkStore.insert(
UserOrganisationUnitLinkSamples
- .getAssignedUserOrganisationUnitLink(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE)
+ .getAssignedUserOrganisationUnitLink(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE),
)
linkStore.insert(
UserOrganisationUnitLinkSamples
- .getUnassignedUserOrganisationUnitLink(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE)
+ .getUnassignedUserOrganisationUnitLink(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE),
)
val orgUnitUids = linkStore
.queryAssignedOrganisationUnitUidsByScope(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE)
@@ -81,11 +81,11 @@ class UserOrganisationUnitLinkStoreIntegrationShould : LinkStoreAbstractIntegrat
linkStore.insert(UserOrganisationUnitLinkSamples.getUserOrganisationUnitLink())
linkStore.insert(
UserOrganisationUnitLinkSamples
- .getAssignedUserOrganisationUnitLink(OrganisationUnit.Scope.SCOPE_TEI_SEARCH)
+ .getAssignedUserOrganisationUnitLink(OrganisationUnit.Scope.SCOPE_TEI_SEARCH),
)
linkStore.insert(
UserOrganisationUnitLinkSamples
- .getUnassignedUserOrganisationUnitLink(OrganisationUnit.Scope.SCOPE_TEI_SEARCH)
+ .getUnassignedUserOrganisationUnitLink(OrganisationUnit.Scope.SCOPE_TEI_SEARCH),
)
val orgUnitUids = linkStore.queryAssignedOrganisationUnitUidsByScope(OrganisationUnit.Scope.SCOPE_TEI_SEARCH)
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserRoleStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserRoleStoreIntegrationShould.kt
index 742f2fe4ac..1acd16fe64 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserRoleStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserRoleStoreIntegrationShould.kt
@@ -37,8 +37,9 @@ import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class UserRoleStoreIntegrationShould : IdentifiableObjectStoreAbstractIntegrationShould(
- UserRoleStore.create(TestDatabaseAdapterFactory.get()),
- UserRoleTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()
+ UserRoleStoreImpl(TestDatabaseAdapterFactory.get()),
+ UserRoleTableInfo.TABLE_INFO,
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): UserRole {
return UserRoleSamples.getUserRole()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserStoreIntegrationShould.kt
index 4aa6bfd69e..5368970d84 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/UserStoreIntegrationShould.kt
@@ -37,8 +37,9 @@ import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class UserStoreIntegrationShould : IdentifiableObjectStoreAbstractIntegrationShould(
- UserStore.create(TestDatabaseAdapterFactory.get()),
- UserTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get()
+ UserStoreImpl(TestDatabaseAdapterFactory.get()),
+ UserTableInfo.TABLE_INFO,
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): User {
return UserSamples.getUser()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.kt
index 338a7bc17a..2ad13ea217 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.kt
@@ -44,10 +44,13 @@ abstract class BaseMockIntegrationTest {
companion object {
@JvmStatic
lateinit var objects: MockIntegrationTestObjects
+
@JvmStatic
lateinit var d2: D2
+
@JvmStatic
lateinit var dhis2MockServer: Dhis2MockServer
+
@JvmStatic
lateinit var databaseAdapter: DatabaseAdapter
@@ -65,6 +68,24 @@ abstract class BaseMockIntegrationTest {
return tuple.isNewInstance
}
+ fun freshLogin(username: String, password: String, url: String) {
+ try {
+ d2.userModule().logOut().blockingAwait()
+ } catch (e: RuntimeException) {
+ // Do nothing
+ } finally {
+ d2.userModule().blockingLogIn(username, password, url)
+ }
+ }
+
+ fun tryLogout() {
+ try {
+ d2.userModule().logOut().blockingAwait()
+ } catch (e: RuntimeException) {
+ // Do nothing
+ }
+ }
+
@JvmStatic
fun removeObjects(content: MockIntegrationTestDatabaseContent) {
MockIntegrationTestObjectsFactory.removeObjects(content)
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyDispatcher.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyDispatcher.kt
index cb2b4fd3f0..93adc53403 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyDispatcher.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyDispatcher.kt
@@ -37,12 +37,13 @@ abstract class BaseMockIntegrationTestEmptyDispatcher : BaseMockIntegrationTest(
fun setUpClass() {
val isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.EmptyDispatcher)
if (isNewInstance) {
- objects.dhis2MockServer.setRequestDispatcher()
- objects.d2.userModule().blockingLogIn(
- RealServerMother.username, RealServerMother.password,
- objects.dhis2MockServer.baseEndpoint
- )
+ dhis2MockServer.setRequestDispatcher()
}
+ freshLogin(
+ RealServerMother.username,
+ RealServerMother.password,
+ dhis2MockServer.baseEndpoint,
+ )
}
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyEnqueable.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyEnqueable.kt
index 1f7f3cf0dd..e79d2219a0 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyEnqueable.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestEmptyEnqueable.kt
@@ -36,13 +36,12 @@ abstract class BaseMockIntegrationTestEmptyEnqueable : BaseMockIntegrationTest()
@JvmStatic
fun setUpClass() {
val isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.EmptyEnqueable)
- if (isNewInstance) {
- dhis2MockServer.enqueueLoginResponses()
- objects.d2.userModule().blockingLogIn(
- RealServerMother.username, RealServerMother.password,
- objects.dhis2MockServer.baseEndpoint
- )
- }
+ dhis2MockServer.enqueueLoginResponses()
+ freshLogin(
+ RealServerMother.username,
+ RealServerMother.password,
+ dhis2MockServer.baseEndpoint,
+ )
}
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestFullDispatcher.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestFullDispatcher.kt
index f536fa1088..a9e7ec2c63 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestFullDispatcher.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestFullDispatcher.kt
@@ -31,14 +31,14 @@ import org.hisp.dhis.android.core.data.datavalue.DataValueConflictSamples
import org.hisp.dhis.android.core.data.imports.TrackerImportConflictSamples
import org.hisp.dhis.android.core.data.maintenance.D2ErrorSamples
import org.hisp.dhis.android.core.datastore.KeyValuePair
-import org.hisp.dhis.android.core.datastore.internal.LocalDataStoreStore.create
-import org.hisp.dhis.android.core.datavalue.internal.DataValueConflictStore
+import org.hisp.dhis.android.core.datastore.internal.LocalDataStoreStoreImpl
+import org.hisp.dhis.android.core.datavalue.internal.DataValueConflictStoreImpl
import org.hisp.dhis.android.core.imports.ImportStatus
import org.hisp.dhis.android.core.imports.internal.TrackerImportConflictStoreImpl
import org.hisp.dhis.android.core.maintenance.D2Error
import org.hisp.dhis.android.core.maintenance.D2ErrorCode
import org.hisp.dhis.android.core.maintenance.D2ErrorComponent
-import org.hisp.dhis.android.core.maintenance.internal.D2ErrorStore
+import org.hisp.dhis.android.core.maintenance.internal.D2ErrorStoreImpl
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.AfterClass
import org.junit.BeforeClass
@@ -51,9 +51,9 @@ abstract class BaseMockIntegrationTestFullDispatcher : BaseMockIntegrationTest()
@JvmStatic
fun setUpClass() {
val isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.FullDispatcher)
+ dhis2MockServer.setRequestDispatcher()
+ freshLogin("android", "Android123", dhis2MockServer.baseEndpoint)
if (isNewInstance) {
- dhis2MockServer.setRequestDispatcher()
- freshLogin()
downloadMetadata()
downloadTrackedEntityInstances()
downloadEvents()
@@ -72,16 +72,6 @@ abstract class BaseMockIntegrationTestFullDispatcher : BaseMockIntegrationTest()
dhis2MockServer.shutdown()
}
- private fun freshLogin() {
- try {
- d2.userModule().logOut().blockingAwait()
- } catch (e: RuntimeException) {
- // Do nothing
- } finally {
- d2.userModule().blockingLogIn("android", "Android123", dhis2MockServer.baseEndpoint)
- }
- }
-
private fun downloadMetadata() {
d2.metadataModule().blockingDownload()
}
@@ -107,7 +97,7 @@ abstract class BaseMockIntegrationTestFullDispatcher : BaseMockIntegrationTest()
}
private fun storeSomeD2Errors() {
- val d2ErrorStore = D2ErrorStore.create(databaseAdapter)
+ val d2ErrorStore = D2ErrorStoreImpl(databaseAdapter)
d2ErrorStore.insert(D2ErrorSamples.get())
d2ErrorStore.insert(
D2Error.builder()
@@ -116,18 +106,18 @@ abstract class BaseMockIntegrationTestFullDispatcher : BaseMockIntegrationTest()
.url("http://dhis2.org/api/programs/uid")
.errorDescription("Different server offline")
.httpErrorCode(402)
- .build()
+ .build(),
)
}
private fun storeSomeConflicts() {
- val trackerImportConflictStore = TrackerImportConflictStoreImpl.create(databaseAdapter)
+ val trackerImportConflictStore = TrackerImportConflictStoreImpl(databaseAdapter)
trackerImportConflictStore.insert(
TrackerImportConflictSamples.get().toBuilder()
.trackedEntityInstance(null)
.enrollment(null)
.event(null)
- .build()
+ .build(),
)
trackerImportConflictStore.insert(
TrackerImportConflictSamples.get().toBuilder()
@@ -139,10 +129,10 @@ abstract class BaseMockIntegrationTestFullDispatcher : BaseMockIntegrationTest()
.tableReference("table_reference_2")
.errorCode("error_code_2")
.status(ImportStatus.ERROR)
- .build()
+ .build(),
)
- val dataValueConflictStore = DataValueConflictStore.create(databaseAdapter)
+ val dataValueConflictStore = DataValueConflictStoreImpl(databaseAdapter)
dataValueConflictStore.insert(DataValueConflictSamples.get())
dataValueConflictStore.insert(
@@ -152,7 +142,7 @@ abstract class BaseMockIntegrationTestFullDispatcher : BaseMockIntegrationTest()
.dataElement("bx6fsa0t90x")
.categoryOptionCombo("bRowv6yZOF2")
.status(ImportStatus.WARNING)
- .build()
+ .build(),
)
dataValueConflictStore.insert(
DataValueConflictSamples.get().toBuilder()
@@ -161,25 +151,24 @@ abstract class BaseMockIntegrationTestFullDispatcher : BaseMockIntegrationTest()
.period("202201")
.orgUnit("YuQRtpLP10I")
.displayDescription("display_description_other")
- .build()
+ .build(),
)
}
private fun storeSomeKeyValuesInLocalDataStore() {
- val dataStore = create(
- databaseAdapter
- )
+ val dataStore = LocalDataStoreStoreImpl(databaseAdapter)
+
dataStore.insert(
KeyValuePair.builder()
.key("key1")
.value("value1")
- .build()
+ .build(),
)
dataStore.insert(
KeyValuePair.builder()
.key("key2")
.value("value2")
- .build()
+ .build(),
)
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestLocalAnalyticsSuperLargeDispatcher.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestLocalAnalyticsSuperLargeDispatcher.kt
index 3ec035242e..eebd49c104 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestLocalAnalyticsSuperLargeDispatcher.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestLocalAnalyticsSuperLargeDispatcher.kt
@@ -44,13 +44,12 @@ abstract class BaseMockIntegrationTestLocalAnalyticsSuperLargeDispatcher : BaseM
@JvmStatic
fun setUpClass() {
val isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.LocalAnalyticsSuperLargeDispatcher)
- if (isNewInstance) {
- objects.dhis2MockServer.setRequestDispatcher()
- objects.d2.userModule().blockingLogIn(
- RealServerMother.username, RealServerMother.password,
- objects.dhis2MockServer.baseEndpoint!!
- )
- }
+ dhis2MockServer.setRequestDispatcher()
+ freshLogin(
+ RealServerMother.username,
+ RealServerMother.password,
+ dhis2MockServer.baseEndpoint!!,
+ )
objects.d2.let {
val filler = LocalAnalyticsDatabaseFiller(it)
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataDispatcher.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataDispatcher.kt
index 8644450b6d..795f24bc2c 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataDispatcher.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataDispatcher.kt
@@ -37,13 +37,14 @@ abstract class BaseMockIntegrationTestMetadataDispatcher : BaseMockIntegrationTe
@JvmStatic
fun setUpClass() {
val isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.MetadataDispatcher)
+ dhis2MockServer.setRequestDispatcher()
+ freshLogin(
+ RealServerMother.username,
+ RealServerMother.password,
+ dhis2MockServer.baseEndpoint,
+ )
if (isNewInstance) {
- objects.dhis2MockServer.setRequestDispatcher()
- objects.d2.userModule().blockingLogIn(
- RealServerMother.username, RealServerMother.password,
- objects.dhis2MockServer.baseEndpoint
- )
- objects.d2.metadataModule().blockingDownload()
+ d2.metadataModule().blockingDownload()
}
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataEnqueable.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataEnqueable.kt
index 29d98e3e77..92f2c54230 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataEnqueable.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTestMetadataEnqueable.kt
@@ -35,14 +35,15 @@ abstract class BaseMockIntegrationTestMetadataEnqueable : BaseMockIntegrationTes
@JvmStatic
fun setUpClass() {
val isNewInstance = setUpClass(MockIntegrationTestDatabaseContent.MetadataEnqueable)
+ dhis2MockServer.enqueueLoginResponses()
+ freshLogin(
+ "android",
+ "Android123",
+ dhis2MockServer.baseEndpoint,
+ )
if (isNewInstance) {
- objects.dhis2MockServer.enqueueLoginResponses()
- objects.d2.userModule().blockingLogIn(
- "android", "Android123",
- objects.dhis2MockServer.baseEndpoint
- )
- objects.dhis2MockServer.enqueueMetadataResponses()
- objects.d2.metadataModule().blockingDownload()
+ dhis2MockServer.enqueueMetadataResponses()
+ d2.metadataModule().blockingDownload()
}
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjectsFactory.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjectsFactory.kt
index 0228db6d2d..b75c879b35 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjectsFactory.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/MockIntegrationTestObjectsFactory.kt
@@ -27,17 +27,29 @@
*/
package org.hisp.dhis.android.core.utils.integration.mock
+import org.hisp.dhis.android.core.D2
+import org.hisp.dhis.android.core.D2Factory
import org.hisp.dhis.android.core.MockIntegrationTestObjects
+import org.hisp.dhis.android.core.configuration.internal.MultiUserDatabaseManager
+import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory.setFixed
internal object MockIntegrationTestObjectsFactory {
private val instances: MutableMap = HashMap()
+ private val d2: D2
+
+ init {
+ setFixed()
+ d2 = D2Factory.forNewDatabase()
+ d2.userModule().accountManager().setMaxAccounts(MultiUserDatabaseManager.DefaultTestMaxAccounts)
+ }
+
fun getObjects(content: MockIntegrationTestDatabaseContent): IntegrationTestObjectsWithIsNewInstance {
val instance = instances[content]
return if (instance != null) {
IntegrationTestObjectsWithIsNewInstance(instance, false)
} else {
- val newInstance = MockIntegrationTestObjects(content)
+ val newInstance = MockIntegrationTestObjects(d2, content)
instances[content] = newInstance
IntegrationTestObjectsWithIsNewInstance(newInstance, true)
}
@@ -63,6 +75,6 @@ internal object MockIntegrationTestObjectsFactory {
internal class IntegrationTestObjectsWithIsNewInstance(
val objects: MockIntegrationTestObjects,
- val isNewInstance: Boolean
+ val isNewInstance: Boolean,
)
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.kt
index f1b2bda097..2faa149f27 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.kt
@@ -28,8 +28,6 @@
package org.hisp.dhis.android.core.utils.runner
import android.util.Log
-import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory.setFixed
-import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory.setRegular
import org.hisp.dhis.android.core.utils.DatabaseRemover
import org.hisp.dhis.android.core.utils.integration.mock.MockIntegrationTestObjectsFactory.tearDown
import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory
@@ -40,14 +38,13 @@ import org.junit.runner.notification.RunListener
class D2JunitTestListener : RunListener() {
override fun testRunStarted(description: Description) {
Log.e("D2JunitTestListener", "Test run started")
- setFixed()
}
override fun testRunFinished(result: Result) {
Log.i("D2JunitTestListener", "Test run finished")
TestDatabaseAdapterFactory.tearDown()
- setRegular()
tearDown()
DatabaseRemover.removeAllDatabases()
+ Log.i("D2JunitTestListener", "Test run database clearing finished")
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/validation/internal/ValidationRuleStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/validation/internal/ValidationRuleStoreIntegrationShould.java
index 3f3fba20ae..d7891c471f 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/validation/internal/ValidationRuleStoreIntegrationShould.java
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/validation/internal/ValidationRuleStoreIntegrationShould.java
@@ -41,7 +41,7 @@
public class ValidationRuleStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould {
public ValidationRuleStoreIntegrationShould() {
- super(ValidationRuleStore.create(TestDatabaseAdapterFactory.get()),
+ super(new ValidationRuleStoreImpl(TestDatabaseAdapterFactory.get()),
ValidationRuleTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get());
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionItemStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionItemStoreIntegrationShould.kt
index 7bbddea0f1..257084e40f 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionItemStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionItemStoreIntegrationShould.kt
@@ -38,9 +38,9 @@ import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class VisualizationDimensionItemStoreIntegrationShould :
LinkStoreAbstractIntegrationShould(
- VisualizationDimensionItemStore.create(TestDatabaseAdapterFactory.get()),
+ VisualizationDimensionItemStoreImpl(TestDatabaseAdapterFactory.get()),
VisualizationDimensionItemTableInfo.TABLE_INFO,
- TestDatabaseAdapterFactory.get()
+ TestDatabaseAdapterFactory.get(),
) {
override fun addMasterUid(): String {
return "visualization_uid"
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationEndpointCallShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationEndpointCallShould.kt
index b6f29d0796..dd04a3bd55 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationEndpointCallShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationEndpointCallShould.kt
@@ -29,35 +29,19 @@ package org.hisp.dhis.android.core.visualization.internal
import com.google.common.collect.Lists
import com.google.common.truth.Truth
-import io.reactivex.Single
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runTest
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyEnqueable
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
-import org.hisp.dhis.android.core.visualization.Visualization
-import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
+@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(D2JunitRunner::class)
class VisualizationEndpointCallShould : BaseMockIntegrationTestEmptyEnqueable() {
- companion object {
- private lateinit var visualizationsSingle: Single>
-
- @BeforeClass
- @JvmStatic
- @Throws(Exception::class)
- internal fun setUpClass() {
- BaseMockIntegrationTestEmptyEnqueable.setUpClass()
- visualizationsSingle = objects.d2DIComponent.internalModules().visualization.visualizationCall.download(
- HashSet(
- Lists.newArrayList("PYBH8ZaAQnC", "FAFa11yFeFe")
- )
- )
- }
- }
-
@Test
- fun download_persist_and_get_visualizations_successfully() {
+ fun download_persist_and_get_visualizations_successfully() = runTest {
if (d2.userModule().blockingIsLogged()) {
d2.userModule().blockingLogOut()
}
@@ -69,7 +53,12 @@ class VisualizationEndpointCallShould : BaseMockIntegrationTestEmptyEnqueable()
dhis2MockServer.enqueueMockResponse("visualization/visualizations_2.json")
d2.databaseAdapter().setForeignKeyConstraintsEnabled(false)
- var visualizations = visualizationsSingle.blockingGet()
+ var visualizations = objects.d2DIComponent.internalModules.visualization.visualizationCall.download(
+ HashSet(
+ Lists.newArrayList("PYBH8ZaAQnC", "FAFa11yFeFe"),
+ ),
+ )
+
Truth.assertThat(visualizations.isEmpty()).isFalse()
visualizations = d2.visualizationModule().visualizations().blockingGet()
Truth.assertThat(visualizations.isEmpty()).isFalse()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationStoreIntegrationShould.kt
index 5a6254f496..4f6344e5ce 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationStoreIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/visualization/internal/VisualizationStoreIntegrationShould.kt
@@ -38,9 +38,9 @@ import org.junit.runner.RunWith
@RunWith(D2JunitRunner::class)
class VisualizationStoreIntegrationShould : IdentifiableObjectStoreAbstractIntegrationShould(
- VisualizationStore.create(TestDatabaseAdapterFactory.get()),
+ VisualizationStoreImpl(TestDatabaseAdapterFactory.get()),
VisualizationTableInfo.TABLE_INFO,
- TestDatabaseAdapterFactory.get()
+ TestDatabaseAdapterFactory.get(),
) {
override fun buildObject(): Visualization {
return VisualizationSamples.visualization()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallMockIntegrationShould.kt
index 4a5b4257c8..7dd36fcd9a 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallMockIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallMockIntegrationShould.kt
@@ -37,24 +37,24 @@ import org.hisp.dhis.android.core.data.tracker.importer.internal.TrackerJobObjec
import org.hisp.dhis.android.core.data.usecase.stock.InternalStockUseCaseSamples
import org.hisp.dhis.android.core.data.usecase.stock.InternalStockUseCaseTransactionSamples
import org.hisp.dhis.android.core.datastore.KeyValuePair
-import org.hisp.dhis.android.core.datastore.internal.LocalDataStoreStore
+import org.hisp.dhis.android.core.datastore.internal.LocalDataStoreStoreImpl
import org.hisp.dhis.android.core.datavalue.DataValueConflict
-import org.hisp.dhis.android.core.datavalue.internal.DataValueConflictStore
+import org.hisp.dhis.android.core.datavalue.internal.DataValueConflictStoreImpl
import org.hisp.dhis.android.core.fileresource.FileResource
import org.hisp.dhis.android.core.fileresource.internal.FileResourceStoreImpl
import org.hisp.dhis.android.core.imports.TrackerImportConflict
import org.hisp.dhis.android.core.imports.internal.TrackerImportConflictStoreImpl
import org.hisp.dhis.android.core.maintenance.D2Error
import org.hisp.dhis.android.core.maintenance.D2ErrorCode
-import org.hisp.dhis.android.core.maintenance.internal.D2ErrorStore
-import org.hisp.dhis.android.core.map.layer.internal.MapLayerImageryProviderStore
-import org.hisp.dhis.android.core.map.layer.internal.MapLayerStore
+import org.hisp.dhis.android.core.maintenance.internal.D2ErrorStoreImpl
+import org.hisp.dhis.android.core.map.layer.internal.MapLayerImageryProviderStoreImpl
+import org.hisp.dhis.android.core.map.layer.internal.MapLayerStoreImpl
import org.hisp.dhis.android.core.sms.data.localdbrepository.internal.SMSConfigStoreImpl
-import org.hisp.dhis.android.core.sms.data.localdbrepository.internal.SMSOngoingSubmissionStore
-import org.hisp.dhis.android.core.trackedentity.ownership.ProgramTempOwnerStore
-import org.hisp.dhis.android.core.tracker.importer.internal.TrackerJobObjectStore
-import org.hisp.dhis.android.core.usecase.stock.internal.StockUseCaseStore
-import org.hisp.dhis.android.core.usecase.stock.internal.StockUseCaseTransactionLinkStore
+import org.hisp.dhis.android.core.sms.data.localdbrepository.internal.SMSOngoingSubmissionStoreImpl
+import org.hisp.dhis.android.core.trackedentity.ownership.ProgramTempOwnerStoreImpl
+import org.hisp.dhis.android.core.tracker.importer.internal.TrackerJobObjectStoreImpl
+import org.hisp.dhis.android.core.usecase.stock.internal.StockUseCaseStoreImpl
+import org.hisp.dhis.android.core.usecase.stock.internal.StockUseCaseTransactionLinkStoreImpl
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyDispatcher
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.Test
@@ -65,7 +65,6 @@ class WipeDBCallMockIntegrationShould : BaseMockIntegrationTestEmptyDispatcher()
@Test
fun have_empty_database_when_wipe_db_after_sync_data() {
- givenAFreshLoginInDatabase()
activateSMSModule()
givenAMetadataInDatabase()
givenDataInDatabase()
@@ -78,16 +77,6 @@ class WipeDBCallMockIntegrationShould : BaseMockIntegrationTestEmptyDispatcher()
assertThatDatabase(databaseAdapter).isEmpty
}
- private fun givenAFreshLoginInDatabase() {
- try {
- d2.userModule().logOut().blockingAwait()
- } catch (e: RuntimeException) {
- // Do nothing
- } finally {
- d2.userModule().blockingLogIn("android", "Android123", dhis2MockServer.baseEndpoint)
- }
- }
-
private fun activateSMSModule() {
d2.smsModule().configCase().setModuleEnabled(true).blockingAwait()
}
@@ -105,43 +94,43 @@ class WipeDBCallMockIntegrationShould : BaseMockIntegrationTestEmptyDispatcher()
}
private fun givenOthersInDatabase() {
- D2ErrorStore.create(databaseAdapter).insert(
+ D2ErrorStoreImpl(databaseAdapter).insert(
D2Error.builder()
.errorCode(D2ErrorCode.API_RESPONSE_PROCESS_ERROR)
.errorDescription("Sample error")
- .build()
+ .build(),
)
- TrackerImportConflictStoreImpl.create(databaseAdapter).insert(TrackerImportConflict.builder().build())
- FileResourceStoreImpl.create(databaseAdapter).insert(FileResource.builder().uid("uid").build())
- TrackerJobObjectStore.create(databaseAdapter).insert(TrackerJobObjectSamples.get1())
- DataValueConflictStore.create(databaseAdapter).insert(DataValueConflict.builder().build())
- LocalDataStoreStore.create(databaseAdapter).insert(
+ TrackerImportConflictStoreImpl(databaseAdapter).insert(TrackerImportConflict.builder().build())
+ FileResourceStoreImpl(databaseAdapter).insert(FileResource.builder().uid("uid").build())
+ TrackerJobObjectStoreImpl(databaseAdapter).insert(TrackerJobObjectSamples.get1())
+ DataValueConflictStoreImpl(databaseAdapter).insert(DataValueConflict.builder().build())
+ LocalDataStoreStoreImpl(databaseAdapter).insert(
KeyValuePair.builder()
.key("key1")
.value("value1")
- .build()
+ .build(),
)
- LocalDataStoreStore.create(databaseAdapter).insert(
+ LocalDataStoreStoreImpl(databaseAdapter).insert(
KeyValuePair.builder()
.key("key2")
.value("value2")
- .build()
+ .build(),
)
- ProgramTempOwnerStore.create(databaseAdapter).insert(ProgramTempOwnerSamples.programTempOwner)
+ ProgramTempOwnerStoreImpl(databaseAdapter).insert(ProgramTempOwnerSamples.programTempOwner)
- SMSConfigStoreImpl.create(databaseAdapter).insert(KeyValuePairSamples.keyValuePairSample)
- SMSOngoingSubmissionStore.create(databaseAdapter).insert(SMSOngoingSubmissionSample.get)
+ SMSConfigStoreImpl(databaseAdapter).insert(KeyValuePairSamples.keyValuePairSample)
+ SMSOngoingSubmissionStoreImpl(databaseAdapter).insert(SMSOngoingSubmissionSample.get)
- StockUseCaseStore.create(databaseAdapter).insert(
+ StockUseCaseStoreImpl(databaseAdapter).insert(
InternalStockUseCaseSamples.get()
- .toBuilder().uid("lxAQ7Zs9VYR").build()
+ .toBuilder().uid("lxAQ7Zs9VYR").build(),
)
- StockUseCaseTransactionLinkStore.create(databaseAdapter).insert(
+ StockUseCaseTransactionLinkStoreImpl(databaseAdapter).insert(
InternalStockUseCaseTransactionSamples.get()
- .toBuilder().programUid("lxAQ7Zs9VYR").build()
+ .toBuilder().programUid("lxAQ7Zs9VYR").build(),
)
- MapLayerStore.create(databaseAdapter).insert(MapLayerSamples.get())
- MapLayerImageryProviderStore.create(databaseAdapter).insert(MapLayerImageryProviderSamples.get())
+ MapLayerStoreImpl(databaseAdapter).insert(MapLayerSamples.get())
+ MapLayerImageryProviderStoreImpl(databaseAdapter).insert(MapLayerImageryProviderSamples.get())
}
}
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallRealIntegrationShould.kt
index 699494830c..a52b3ae8ef 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallRealIntegrationShould.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/core/wipe/WipeDBCallRealIntegrationShould.kt
@@ -28,6 +28,7 @@
package org.hisp.dhis.android.core.wipe
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.test.runTest
import org.hisp.dhis.android.core.BaseRealIntegrationTest
import org.hisp.dhis.android.core.data.database.DatabaseAssert.Companion.assertThatDatabase
import org.hisp.dhis.android.core.event.internal.EventCallFactory.create
@@ -45,12 +46,11 @@ class WipeDBCallRealIntegrationShould : BaseRealIntegrationTest() {
// @Test
@Throws(Exception::class)
- fun have_empty_database_when_wipe_db_after_sync_data() {
+ fun have_empty_database_when_wipe_db_after_sync_data() = runTest {
d2.userModule().logIn(username, password, url).blockingGet()
d2.metadataModule().blockingDownload()
- val eventCall = create(d2.retrofit(), "DiszpKrYNg8", 0, emptyList())
- eventCall.blockingGet()
+ create(d2.retrofit(), "DiszpKrYNg8", 0, emptyList())
assertThatDatabase(d2.databaseAdapter()).isNotEmpty
@@ -75,7 +75,7 @@ class WipeDBCallRealIntegrationShould : BaseRealIntegrationTest() {
d2.userModule().logIn(username, password, url).blockingGet()
d2.metadataModule().blockingDownload()
d2.trackedEntityModule().trackedEntityInstanceDownloader().limit(5).blockingDownload()
- val trackedEntityInstanceStore = TrackedEntityInstanceStoreImpl.create(d2.databaseAdapter())
+ val trackedEntityInstanceStore = TrackedEntityInstanceStoreImpl(d2.databaseAdapter())
var hasTrackedEntities = trackedEntityInstanceStore.count() > 0
assertThat(hasTrackedEntities).isTrue()
d2.wipeModule().wipeData()
diff --git a/core/src/androidTest/java/org/hisp/dhis/android/localanalytics/dbgeneration/LocalAnalyticsDataGenerator.kt b/core/src/androidTest/java/org/hisp/dhis/android/localanalytics/dbgeneration/LocalAnalyticsDataGenerator.kt
index 9031930b93..8e2d6082d2 100644
--- a/core/src/androidTest/java/org/hisp/dhis/android/localanalytics/dbgeneration/LocalAnalyticsDataGenerator.kt
+++ b/core/src/androidTest/java/org/hisp/dhis/android/localanalytics/dbgeneration/LocalAnalyticsDataGenerator.kt
@@ -27,8 +27,6 @@
*/
package org.hisp.dhis.android.localanalytics.dbgeneration
-import java.util.*
-import kotlin.random.Random
import org.hisp.dhis.android.core.arch.helpers.UidGeneratorImpl
import org.hisp.dhis.android.core.data.datavalue.DataValueSamples
import org.hisp.dhis.android.core.data.enrollment.EnrollmentSamples
@@ -46,6 +44,8 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute
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 java.util.*
+import kotlin.random.Random
internal class LocalAnalyticsDataGenerator(private val params: LocalAnalyticsDataParams) {
@@ -74,8 +74,12 @@ internal class LocalAnalyticsDataGenerator(private val params: LocalAnalyticsDat
(0 until iterations).map {
val (period, ou) = periodOrgUnits[it]
DataValueSamples.getDataValue(
- ou.uid(), dataElement.uid(), period.periodId()!!, categoryOptionCombo.uid(),
- metadata.categoryOptionCombos.first().uid(), random.nextDouble().toString()
+ ou.uid(),
+ dataElement.uid(),
+ period.periodId()!!,
+ categoryOptionCombo.uid(),
+ metadata.categoryOptionCombos.first().uid(),
+ random.nextDouble().toString(),
)
}
}
@@ -94,8 +98,11 @@ internal class LocalAnalyticsDataGenerator(private val params: LocalAnalyticsDat
fun generateEnrollments(teis: List, program: Program): List {
return teis.map { tei ->
EnrollmentSamples.get(
- uidGenerator.generate(), tei.organisationUnit(), program.uid(), tei.uid(),
- getRandomDateInLastYear()
+ uidGenerator.generate(),
+ tei.organisationUnit(),
+ program.uid(),
+ tei.uid(),
+ getRandomDateInLastYear(),
)
}
}
@@ -109,8 +116,13 @@ internal class LocalAnalyticsDataGenerator(private val params: LocalAnalyticsDat
val ou = level3OrgUnits[i % level3OrgUnits.size]
val programStage = programStages[i % programStages.size]
EventSamples.get(
- uidGenerator.generate(), null, ou.uid(), programStage.program()!!.uid(), programStage.uid(),
- metadata.categoryOptionCombos.first().uid(), getRandomDateInLastYear()
+ uidGenerator.generate(),
+ null,
+ ou.uid(),
+ programStage.program()!!.uid(),
+ programStage.uid(),
+ metadata.categoryOptionCombos.first().uid(),
+ getRandomDateInLastYear(),
)
}
}
@@ -123,9 +135,13 @@ internal class LocalAnalyticsDataGenerator(private val params: LocalAnalyticsDat
programStages.flatMap { ps ->
(1..params.eventsWithRegistrationPerEnrollmentAndPS).map {
EventSamples.get(
- uidGenerator.generate(), enrollment.uid(), enrollment.organisationUnit(),
- enrollment.program(), ps.uid(), metadata.categoryOptionCombos.first().uid(),
- getRandomDateInLastYear()
+ uidGenerator.generate(),
+ enrollment.uid(),
+ enrollment.organisationUnit(),
+ enrollment.program(),
+ ps.uid(),
+ metadata.categoryOptionCombos.first().uid(),
+ getRandomDateInLastYear(),
)
}
}
@@ -134,7 +150,7 @@ internal class LocalAnalyticsDataGenerator(private val params: LocalAnalyticsDat
fun generateTrackedEntityAttributeValues(
trackedEntityAttributes: List,
- teis: List
+ teis: List,
): List {
return trackedEntityAttributes.flatMap { tea ->
teis.map { tei ->
@@ -145,7 +161,7 @@ internal class LocalAnalyticsDataGenerator(private val params: LocalAnalyticsDat
fun generateTrackedEntityDataValues(
dataElements: List,
- events: List
+ events: List,
): List