From 7dc70b4582bee307ce0ebd186f91897c455be1bb Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Thu, 18 May 2023 12:19:32 +0500 Subject: [PATCH 1/7] Index Sync Status Column --- .../immunization/repository/VaccineRepository.java | 2 ++ .../immunization/repository/VaccineRepositoryTest.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineRepository.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineRepository.java index bb969fa8..1a670d30 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineRepository.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineRepository.java @@ -66,6 +66,7 @@ public class VaccineRepository extends BaseRepository { private static final String VACCINE_SQL = "CREATE TABLE vaccines (_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,base_entity_id VARCHAR NOT NULL,program_client_id VARCHAR NULL,name VARCHAR NOT NULL,calculation INTEGER,date DATETIME NOT NULL,anmid VARCHAR NULL,location_id VARCHAR NULL,sync_status VARCHAR, updated_at INTEGER NULL, UNIQUE(base_entity_id, program_client_id, name) ON CONFLICT IGNORE)"; private static final String BASE_ENTITY_ID_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + BASE_ENTITY_ID + "_index ON " + VACCINE_TABLE_NAME + "(" + BASE_ENTITY_ID + " COLLATE NOCASE);"; private static final String UPDATED_AT_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + UPDATED_AT_COLUMN + "_index ON " + VACCINE_TABLE_NAME + "(" + UPDATED_AT_COLUMN + ");"; + public static final String SYNC_STATUS_INDEX = "CREATE INDEX IF NOT EXISTS " + VACCINE_TABLE_NAME + "_" + SYNC_STATUS + "_index ON " + VACCINE_TABLE_NAME + "(" + SYNC_STATUS + ");"; public static String HIA2_Within = "Within"; public static String HIA2_Overdue = "Overdue"; @@ -81,6 +82,7 @@ public static void createTable(SQLiteDatabase database) { database.execSQL(VACCINE_SQL); database.execSQL(BASE_ENTITY_ID_INDEX); database.execSQL(UPDATED_AT_INDEX); + database.execSQL(SYNC_STATUS_INDEX); } public static void migrateCreatedAt(SQLiteDatabase database) { diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java index 53046cbd..a87b94d7 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java @@ -122,7 +122,7 @@ public void verifyUpdateHia2StatusTest() { @Test public void verifyCreateTableTest() { VaccineRepository.createTable(sqliteDatabase); - Mockito.verify(sqliteDatabase, Mockito.times(3)).execSQL(ArgumentMatchers.anyString()); + Mockito.verify(sqliteDatabase, Mockito.times(4)).execSQL(org.mockito.ArgumentMatchers.anyString()); } @Test From 1b13ac4634af7d39585c204db6da7cb14a377ebb Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Thu, 18 May 2023 12:26:49 +0500 Subject: [PATCH 2/7] Bump up library version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 91ec69d3..b77a47fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=5.1.0-SNAPSHOT +VERSION_NAME=5.1.1-SNAPSHOT VERSION_CODE=3 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Immunization From cacc1523599553bc0f35a6947656a4781ed74baf Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Thu, 18 May 2023 13:04:52 +0500 Subject: [PATCH 3/7] Fix failing test --- .../immunization/utils/VaccinateActionUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/utils/VaccinateActionUtilsTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/utils/VaccinateActionUtilsTest.java index 09867a3a..2ff3cfd9 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/utils/VaccinateActionUtilsTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/utils/VaccinateActionUtilsTest.java @@ -326,7 +326,7 @@ public void assertMoreThanThreeMonthsReturnsTrueForDatesMoreThanThreeMonths() { Assert.assertFalse(VaccinateActionUtils.moreThanThreeMonths(new Date(dateTime.getMillis()))); dateTime = new DateTime(); - dateTime = dateTime.minusMonths(3).minusHours(1); + dateTime = dateTime.minusMonths(3).minusDays(1).minusHours(1); Assert.assertTrue(VaccinateActionUtils.moreThanThreeMonths(new Date(dateTime.getMillis()))); From a40e8e6e4438fc9297fb220fcd1ab08b83fde0ee Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Thu, 18 May 2023 13:26:16 +0500 Subject: [PATCH 4/7] Increase code coverage --- .../immunization/domain/ServiceScheduleTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/ServiceScheduleTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/ServiceScheduleTest.java index b00baf35..ceb2b072 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/ServiceScheduleTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/ServiceScheduleTest.java @@ -11,7 +11,9 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.rule.PowerMockRule; +import org.robolectric.util.ReflectionHelpers; import org.smartregister.Context; +import org.smartregister.domain.AlertStatus; import org.smartregister.immunization.BaseUnitTest; import org.smartregister.immunization.ImmunizationLibrary; import org.smartregister.immunization.repository.RecurringServiceRecordRepository; @@ -149,4 +151,18 @@ public void isServiceIssuedShouldReturnTrueWhenServiceIsWithinServiceRecords() { Assert.assertTrue(ServiceSchedule.isServiceIssued("bcg2", serviceRecords)); } + @Test + public void testCalculateAlertStatusShouldReturnNormalForTodayDate() { + AlertStatus status = ReflectionHelpers.callStaticMethod(ServiceSchedule.class, "calculateAlertStatus", + ReflectionHelpers.ClassParameter.from(DateTime.class, new DateTime())); + Assert.assertEquals(AlertStatus.normal, status); + } + + @Test + public void testCalculateAlertStatusShouldReturnNullForUpcomingDate() { + AlertStatus status = ReflectionHelpers.callStaticMethod(ServiceSchedule.class, "calculateAlertStatus", + ReflectionHelpers.ClassParameter.from(DateTime.class, new DateTime().plusDays(10))); + Assert.assertNull(status); + } + } From 8c9d2d55fc4a15f914dc79abaf76a53898d1dfff Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Thu, 18 May 2023 13:50:16 +0500 Subject: [PATCH 5/7] Trigger CI From 38779af717c3661b03da9a49e56236f7156bdea1 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Thu, 18 May 2023 14:10:51 +0500 Subject: [PATCH 6/7] Fix codacy error --- .../immunization/repository/VaccineRepositoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java index a87b94d7..4e8fa29d 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java @@ -122,7 +122,7 @@ public void verifyUpdateHia2StatusTest() { @Test public void verifyCreateTableTest() { VaccineRepository.createTable(sqliteDatabase); - Mockito.verify(sqliteDatabase, Mockito.times(4)).execSQL(org.mockito.ArgumentMatchers.anyString()); + Mockito.verify(sqliteDatabase, Mockito.times(4)).execSQL(ArgumentMatchers.anyString()); } @Test From a53467c3da5662b33a97ae8391a6b9d985334788 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Thu, 18 May 2023 14:40:33 +0500 Subject: [PATCH 7/7] Increase coverage --- .../domain/VaccinationClientTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 opensrp-immunization/src/test/java/org/smartregister/immunization/domain/VaccinationClientTest.java diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/VaccinationClientTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/VaccinationClientTest.java new file mode 100644 index 00000000..d0c7b1c9 --- /dev/null +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/VaccinationClientTest.java @@ -0,0 +1,26 @@ +package org.smartregister.immunization.domain; + +import org.joda.time.DateTime; +import org.junit.Assert; +import org.junit.Test; +import org.smartregister.immunization.BaseUnitTest; + +public class VaccinationClientTest extends BaseUnitTest { + + + @Test + public void testSetBaseEntityIdSetsTheCorrectValue() { + VaccinationClient client = new VaccinationClient(); + client.setBaseEntityId("baseEntityId"); + Assert.assertEquals("baseEntityId", client.getBaseEntityId()); + } + + @Test + public void testSetBirthDateTimeSetsTheCorrectValue() { + VaccinationClient client = new VaccinationClient(); + DateTime dateTime = new DateTime(); + client.setBirthDateTime(dateTime); + Assert.assertEquals(dateTime, client.getBirthDateTime()); + } + +}