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/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/"' 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? } 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); + } +} 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()); + } +} 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;"); + } + } 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); + + + } + + } + +