From 7631c7ab29c21c4b11156af74ea2f42af9722ac6 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Feb 2023 14:30:23 +0500 Subject: [PATCH 1/6] chaged the ba Unique ID source to 1 --- opensrp-chw/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 7f885101af..5b1a3c73a6 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -234,7 +234,7 @@ android { versionName "1.0.8" buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '10000' buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10000' - buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2' + buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '1' buildConfigField "String", 'opensrp_url', '"https://boresha-afya.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/ba/"' buildConfigField "String", 'opensrp_url_debug', '"https://boresha-afya-stage.smartregister.org/opensrp/"' From 23019f4c15961d3c58c1dce0f282f587c9f98f7a Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 16 Feb 2023 17:39:38 +0500 Subject: [PATCH 2/6] added the missing code from the merged PR 1855 issue ref#296 --- build.gradle | 2 +- .../chw/sync/ChwSyncIntentService.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 7187516bb0..40b9a15431 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ allprojects { maven { url "https://cloudant.github.io/cloudant-sync-eap/repository" } maven { url 'https://maven.fabric.io/public' } maven { url "https://s3.amazonaws.com/repo.commonsware.com" } - maven { url 'https://nexus.pentaho.org/content/groups/omni/' } + //maven { url 'https://nexus.pentaho.org/content/groups/omni/' } maven { url 'https://dl.bintray.com/ibm-watson-health/ibm-fhir-server-releases' content { diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java b/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java index efb9a9c2b5..c70d94a029 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java @@ -1,9 +1,23 @@ package org.smartregister.chw.sync; +import org.smartregister.chw.dao.EventDao; import org.smartregister.sync.intent.SyncIntentService; public class ChwSyncIntentService extends SyncIntentService { + @Override + protected void handleSync() { + // fetch the last downloaded serverVersion before any unsyced data + Long serverVersion = EventDao.getMinimumVerifiedServerVersion(); + if (serverVersion != null) + org.smartregister.util.Utils.getAllSharedPreferences().saveLastSyncDate(serverVersion); + + // flag all contentious events as unsynced + EventDao.markEventsForReUpload(); + super.handleSync(); + } + + @Override public int getEventPullLimit() { return 1000; @@ -12,6 +26,6 @@ public int getEventPullLimit() { @Override protected Integer getEventBatchSize(){ - return 50; + return 250; } // Should this be configurable? } From bdd30299335c745c80445136a55d47c792edfc22 Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 17 Feb 2023 21:23:54 +0500 Subject: [PATCH 3/6] updated the test coverage in repository utils --- .../chw/util/RepositoryUtilsTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/util/RepositoryUtilsTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/util/RepositoryUtilsTest.java index 598fbb6163..fb53534580 100644 --- a/opensrp-chw/src/test/java/org/smartregister/chw/util/RepositoryUtilsTest.java +++ b/opensrp-chw/src/test/java/org/smartregister/chw/util/RepositoryUtilsTest.java @@ -15,6 +15,8 @@ import org.smartregister.chw.application.ChwApplication; import org.smartregister.repository.EventClientRepository; +import static org.mockito.Mockito.verify; + @RunWith(RobolectricTestRunner.class) @Config(application = ChwApplication.class, sdk = 22) public class RepositoryUtilsTest { @@ -35,7 +37,7 @@ public void updateNullEventIdsUpdatesCorrectEvents() { ArgumentMatchers.any(String[].class), ArgumentMatchers.eq("eventId IS NULL AND validationStatus = ?"), ArgumentMatchers.any(String[].class), ArgumentMatchers.isNull(), ArgumentMatchers.isNull(), ArgumentMatchers.isNull()); RepositoryUtils.updateNullEventIds(database); - Mockito.verify(database).execSQL("UPDATE event SET eventId = '3b598b80-13ee-4a9a-8cd1-8e66fa76bbe9', " + + verify(database).execSQL("UPDATE event SET eventId = '3b598b80-13ee-4a9a-8cd1-8e66fa76bbe9', " + "syncStatus = 'Synced' WHERE formSubmissionId = '45a294f5-ec2f-4233-847a-6f7910a6e63f';"); } @@ -131,4 +133,16 @@ private static String getSampleEventJSONString() { "}"; } + + @Test + public void testAddDetailsColumnToFamilySearchTable() throws Exception { + + SQLiteDatabase database = Mockito.mock(SQLiteDatabase.class); + RepositoryUtils.addDetailsColumnToFamilySearchTable(database); + + verify(database).execSQL("ALTER TABLE ec_family ADD COLUMN entity_type VARCHAR; UPDATE ec_family SET entity_type = 'ec_family' WHERE id is not null;"); + + verify(database).execSQL("ALTER TABLE ec_family ADD COLUMN entity_type VARCHAR; UPDATE ec_family SET entity_type = 'ec_family' WHERE id is not null;"); + } + } From ee49309d98eebe128a4913374d5964f1603d27f3 Mon Sep 17 00:00:00 2001 From: vend Date: Mon, 20 Feb 2023 12:12:46 +0500 Subject: [PATCH 4/6] updated the test coverage in utils --- .../org/smartregister/chw/util/UtilsTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/util/UtilsTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/util/UtilsTest.java index c340a585c9..359148c9ed 100644 --- a/opensrp-chw/src/test/java/org/smartregister/chw/util/UtilsTest.java +++ b/opensrp-chw/src/test/java/org/smartregister/chw/util/UtilsTest.java @@ -2,23 +2,32 @@ import android.app.Activity; import android.os.Environment; +import android.view.Menu; + +import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.google.android.material.bottomnavigation.LabelVisibilityMode; import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.smartregister.chw.BaseUnitTest; import org.smartregister.chw.BuildConfig; +import org.smartregister.chw.R; import org.smartregister.chw.application.ChwApplication; import org.smartregister.chw.core.utils.Utils; import org.smartregister.chw.model.ReferralTypeModel; +import org.smartregister.helper.BottomNavigationHelper; import java.util.Arrays; import java.util.List; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.smartregister.chw.util.Utils.addHyphenBetweenNumbers; import static org.smartregister.chw.util.Utils.formatDateForVisual; import static org.smartregister.chw.util.Utils.getClientName; @@ -26,6 +35,18 @@ public class UtilsTest extends BaseUnitTest { + @Mock + BottomNavigationHelper mockBottomNavigationHelper; + + @Mock + BottomNavigationView mockBottomNavigationView; + + @Mock + BottomNavigationView.OnNavigationItemSelectedListener mockListener; + + @Mock + Menu menu; + @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -123,4 +144,22 @@ public void testAddHyphenBetweenNumbers() { Assert.assertEquals("Ali is around 2-3 years old", addHyphenBetweenNumbers("Ali is around 2 3 years old")); Assert.assertEquals("Ali is around 2 years old", addHyphenBetweenNumbers("Ali is around 2 years old")); } + + @Test + public void testSetupBottomNavigation() { + + when(mockBottomNavigationView.getMenu()).thenReturn(menu); + + org.smartregister.chw.util.Utils.setupBottomNavigation(mockBottomNavigationHelper, mockBottomNavigationView, mockListener); + verify(mockBottomNavigationView).setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED); + verify(mockBottomNavigationView).inflateMenu(R.menu.bottom_nav_menu); + verify(mockBottomNavigationHelper).disableShiftMode(mockBottomNavigationView); + verify(mockBottomNavigationView).setOnNavigationItemSelectedListener(mockListener); + + + } + + } + + From 7460b7d4284b6a0c90e16d578d6a69b0bbb2a1d2 Mon Sep 17 00:00:00 2001 From: vend Date: Mon, 20 Feb 2023 13:09:09 +0500 Subject: [PATCH 5/6] updated the test coverage in utils --- .../chw/util/AllClientsUtilsTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 opensrp-chw/src/test/java/org/smartregister/chw/util/AllClientsUtilsTest.java diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/util/AllClientsUtilsTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/util/AllClientsUtilsTest.java new file mode 100644 index 0000000000..bfaa211b00 --- /dev/null +++ b/opensrp-chw/src/test/java/org/smartregister/chw/util/AllClientsUtilsTest.java @@ -0,0 +1,38 @@ +package org.smartregister.chw.util; + +import android.app.Activity; +import android.os.Bundle; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.smartregister.commonregistry.CommonPersonObjectClient; + +import static org.mockito.Mockito.verify; + +public class AllClientsUtilsTest { + + + @Mock + Activity mockActivity; + + @Mock + CommonPersonObjectClient mockPatient; + + @Mock + Bundle mockBundle; + + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testGoToChildProfile() { + AllClientsUtils.goToChildProfile(mockActivity, mockPatient, mockBundle); + verify(mockActivity).startActivity(ArgumentMatchers.any()); + } +} From f882d635b74b698deac15b8050d4a6b20c6dac5e Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 23 Feb 2023 16:31:16 +0500 Subject: [PATCH 6/6] uptaded the unit test related to ChwSyncIntentService --- .../chw/sync/ChwSyncIntentServiceTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 opensrp-chw/src/test/java/org/smartregister/chw/sync/ChwSyncIntentServiceTest.java diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/sync/ChwSyncIntentServiceTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/sync/ChwSyncIntentServiceTest.java new file mode 100644 index 0000000000..3465279803 --- /dev/null +++ b/opensrp-chw/src/test/java/org/smartregister/chw/sync/ChwSyncIntentServiceTest.java @@ -0,0 +1,57 @@ +package org.smartregister.chw.sync; + + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.powermock.reflect.Whitebox; +import org.robolectric.RuntimeEnvironment; +import org.smartregister.AllConstants; +import org.smartregister.Context; +import org.smartregister.CoreLibrary; +import org.smartregister.SyncConfiguration; +import org.smartregister.chw.BaseUnitTest; + + +public class ChwSyncIntentServiceTest extends BaseUnitTest { + + + ChwSyncIntentService chwSyncIntentService; + + @Mock + Context context; + + @Mock + private SyncConfiguration syncConfiguration; + + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + CoreLibrary.init(context); + Whitebox.setInternalState(CoreLibrary.getInstance(), "syncConfiguration", syncConfiguration); + CoreLibrary.getInstance().context().allSharedPreferences().savePreference(AllConstants.DRISHTI_BASE_URL, "https://sample-stage.smartregister.org/opensrp"); + chwSyncIntentService = Mockito.spy(new ChwSyncIntentService()); + Whitebox.setInternalState(chwSyncIntentService, "mBase", RuntimeEnvironment.application); + + } + + @Test + public void testHandleSync() { + chwSyncIntentService.handleSync(); + } + + @Test + public void testGetEventPullLimit() { + int eventPullLimit = chwSyncIntentService.getEventPullLimit(); + assert (eventPullLimit == 1000); + } + + @Test + public void testGetEventBatchSize() { + Integer eventBatchSize = chwSyncIntentService.getEventBatchSize(); + assert (eventBatchSize == 250); + } +}