diff --git a/gradle.properties b/gradle.properties
index 62d9b98c6..ab52d5fa0 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
-VERSION_NAME=6.0.0-SNAPSHOT
+VERSION_NAME=6.1.0-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Core Application
diff --git a/opensrp-core/build.gradle b/opensrp-core/build.gradle
index 01c12289b..5d386030a 100644
--- a/opensrp-core/build.gradle
+++ b/opensrp-core/build.gradle
@@ -92,7 +92,7 @@ android {
buildConfigField "int", "DB_ENCRYPTION_VERSION", '1'
buildConfigField("int", "VERSION_CODE", "${defaultConfig.versionCode}")
buildConfigField("String", "VERSION_NAME", "\"${defaultConfig.versionName}\"")
- }
+ }
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
diff --git a/opensrp-core/res/layout/fragment_stats.xml b/opensrp-core/res/layout/fragment_stats.xml
index f268f118e..70b1f63bb 100644
--- a/opensrp-core/res/layout/fragment_stats.xml
+++ b/opensrp-core/res/layout/fragment_stats.xml
@@ -1,22 +1,33 @@
-
+ android:layout_height="match_parent"
+ android:fillViewport="true">
+
+
@@ -25,17 +36,18 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
- android:textSize="15sp"
- android:textStyle="bold"
- android:text="@string/synced_events"/>
+ android:text="@string/synced_events"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
@@ -46,21 +58,22 @@
android:weightSum="2">
+ android:text="@string/unsynced_events"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
@@ -71,47 +84,49 @@
android:weightSum="2">
+ android:text="@string/task_unprocessed_events"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text="@string/synced_clients"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
@@ -122,47 +137,49 @@
android:weightSum="2">
+ android:text="@string/unsynced_clients"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text="@string/validated_events"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
@@ -173,34 +190,439 @@
android:weightSum="2">
+ android:text="@string/validated_clients"
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+ android:text=""
+ android:textColor="@color/text_black"
+ android:textSize="18sp" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
+
\ No newline at end of file
diff --git a/opensrp-core/res/values/strings.xml b/opensrp-core/res/values/strings.xml
index 8b587d131..4a29333b7 100644
--- a/opensrp-core/res/values/strings.xml
+++ b/opensrp-core/res/values/strings.xml
@@ -457,4 +457,24 @@
Return
Other Forms
Write access to the device internal storage is required for database download.
+
+ App Version Name:
+ App Version Code:
+ Database Version:
+ Team:
+ Locality:
+ Sync
+ App Info
+ Device Info
+ Manufacturer:
+ Device:
+ OS Version:
+ Sync Statistics
+ User Info
+ Build Date:
+ Date:
+ User:
+ Unsynced vaccine events:
+ Unsynced weight events:
+ Unsynced height events:
diff --git a/opensrp-core/src/main/java/org/smartregister/AllConstants.java b/opensrp-core/src/main/java/org/smartregister/AllConstants.java
index 26b50309e..4d7c0a6ce 100644
--- a/opensrp-core/src/main/java/org/smartregister/AllConstants.java
+++ b/opensrp-core/src/main/java/org/smartregister/AllConstants.java
@@ -236,6 +236,7 @@ public interface ClientProcessing {
public interface DatabaseKeys {
String SYNC_STATUS = "syncStatus";
String VALIDATION_STATUS = "validationStatus";
+ String DB_VERSION = "db_version";
}
public interface SyncInfo {
@@ -249,6 +250,21 @@ public interface SyncInfo {
String INVALID_CLIENTS = "INValidClients";
String TASK_UNPROCESSED_EVENTS = "taskUnprocessedEvents";
String NULL_EVENT_SYNC_STATUS = "nullEventSyncStatus";
+ String USER_NAME = "user";
+ String USER_TEAM = "user_team";
+ String USER_LOCALITY = "user_locality";
+ String APP_VERSION_NAME = "app_ver_name";
+ String APP_VERSION_CODE = "app_ver_code";
+ String APP_BUILD_DATE = "app_build_date";
+ String UNSYNCED_VACCINE_EVENTS = "unsuncyed_vaccine_events";
+ String UNSYNCED_WEIGHT_EVENTS = "unsuncyed_weight_events";
+ String UNSYNCED_HEIGHT_EVENTS = "unsuncyed_height_events";
+ }
+
+ public interface DeviceInfo {
+ String MANUFACTURER = "manufacturer";
+ String MODEL = "model";
+ String OS_VERSION = "os_version";
}
public interface ECClientType {
diff --git a/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java b/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java
new file mode 100644
index 000000000..1b2af7776
--- /dev/null
+++ b/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java
@@ -0,0 +1,221 @@
+package org.smartregister.util;
+
+import static org.smartregister.AllConstants.DatabaseKeys.DB_VERSION;
+import static org.smartregister.AllConstants.DatabaseKeys.SYNC_STATUS;
+import static org.smartregister.AllConstants.DatabaseKeys.VALIDATION_STATUS;
+import static org.smartregister.AllConstants.DeviceInfo.MANUFACTURER;
+import static org.smartregister.AllConstants.DeviceInfo.MODEL;
+import static org.smartregister.AllConstants.DeviceInfo.OS_VERSION;
+import static org.smartregister.AllConstants.SyncInfo.APP_BUILD_DATE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_CODE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_NAME;
+import static org.smartregister.AllConstants.SyncInfo.INVALID_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.INVALID_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.NULL_EVENT_SYNC_STATUS;
+import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_HEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_VACCINE_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_WEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.USER_LOCALITY;
+import static org.smartregister.AllConstants.SyncInfo.USER_NAME;
+import static org.smartregister.AllConstants.SyncInfo.USER_TEAM;
+import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
+
+import android.content.pm.PackageManager;
+import android.os.Build;
+
+import net.sqlcipher.Cursor;
+import net.sqlcipher.database.SQLiteDatabase;
+
+import org.apache.commons.lang3.StringUtils;
+import org.smartregister.CoreLibrary;
+import org.smartregister.repository.AllSharedPreferences;
+import org.smartregister.repository.BaseRepository;
+import org.smartregister.view.activity.DrishtiApplication;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import timber.log.Timber;
+
+public class StatsUtils {
+
+ private final Map syncInfoMap = new HashMap<>();
+ private final SQLiteDatabase database;
+
+ public StatsUtils() {
+ database = DrishtiApplication.getInstance().getRepository().getReadableDatabase();
+ }
+
+ public Map fetchStatsInfo() {
+ populateSyncStatistics();
+ populateUserInfo();
+ populateBuildInfo();
+ populateDeviceInfo();
+ return syncInfoMap;
+ }
+
+ private void populateSyncStatistics() {
+ try {
+ syncInfoMap.put(SYNCED_EVENTS, "-");
+ syncInfoMap.put(SYNCED_CLIENTS, "-");
+ syncInfoMap.put(UNSYNCED_EVENTS, "-");
+ syncInfoMap.put(UNSYNCED_CLIENTS, "-");
+ syncInfoMap.put(VALID_EVENTS, "-");
+ syncInfoMap.put(INVALID_EVENTS, "-");
+ syncInfoMap.put(VALID_CLIENTS, "-");
+ syncInfoMap.put(INVALID_CLIENTS, "-");
+ syncInfoMap.put(TASK_UNPROCESSED_EVENTS, "-");
+ syncInfoMap.put(NULL_EVENT_SYNC_STATUS, "-");
+ syncInfoMap.put(UNSYNCED_VACCINE_EVENTS, "-");
+ syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, "-");
+ syncInfoMap.put(UNSYNCED_HEIGHT_EVENTS, "-");
+
+ String eventSyncSql = "select count(*), syncStatus from event group by syncStatus";
+ String clientSyncSql = "select count(*), syncStatus from client group by syncStatus";
+
+ String validatedEventsSql = "select count(*), validationStatus from event group by validationStatus";
+ String validatedClientsSql = "select count(*), validationStatus from client group by validationStatus";
+
+ String unsyncedVaccineEventsSQL = "SELECT COUNT(*) FROM vaccines WHERE sync_status = 'Unsynced'";
+ String unsyncedWeightEventsSQL = "SELECT COUNT(*) FROM weights WHERE sync_status = 'Unsynced'";
+ String unsyncedHeightEventsSQL = "SELECT COUNT(*) FROM heights WHERE sync_status = 'Unsynced'";
+
+ Cursor cursor;
+
+ cursor = database.rawQuery(eventSyncSql, new String[]{});
+ while (cursor.moveToNext()) {
+ populateEventSyncInfo(cursor);
+ }
+ cursor.close();
+
+ cursor = database.rawQuery(clientSyncSql, new String[]{});
+ while (cursor.moveToNext()) {
+ populateClientSyncInfo(cursor);
+ }
+ cursor.close();
+
+ cursor = database.rawQuery(validatedEventsSql, new String[]{});
+ while (cursor.moveToNext()) {
+ populateValidatedEventsInfo(cursor);
+ }
+ cursor.close();
+
+ cursor = database.rawQuery(validatedClientsSql, new String[]{});
+ while (cursor.moveToNext()) {
+ populateValidatedClientsInfo(cursor);
+ }
+
+ cursor = database.rawQuery(unsyncedVaccineEventsSQL, new String[]{});
+ while (cursor.moveToNext()) {
+ syncInfoMap.put(UNSYNCED_VACCINE_EVENTS, String.valueOf(cursor.getInt(0)));
+ }
+
+ cursor = database.rawQuery(unsyncedWeightEventsSQL, new String[]{});
+ while (cursor.moveToNext()) {
+ syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, String.valueOf(cursor.getInt(0)));
+ }
+ if (CoreLibrary.getInstance().context().getAppProperties().isTrue("monitor.height")) { // Constant is defined in growth-monitoring module
+ cursor = database.rawQuery(unsyncedHeightEventsSQL, new String[]{});
+ while (cursor.moveToNext()) {
+ syncInfoMap.put(UNSYNCED_HEIGHT_EVENTS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ cursor.close();
+ } catch (Exception e) {
+ Timber.e(e);
+ }
+ }
+
+ private void populateEventSyncInfo(Cursor cursor) {
+ String syncStatus = cursor.getString(cursor.getColumnIndex(SYNC_STATUS));
+ if (BaseRepository.TYPE_Synced.equals(syncStatus)) {
+ syncInfoMap.put(SYNCED_EVENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_Unsynced.equals(syncStatus)) {
+ syncInfoMap.put(UNSYNCED_EVENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_Task_Unprocessed.equals(syncStatus)) {
+ syncInfoMap.put(TASK_UNPROCESSED_EVENTS, String.valueOf(cursor.getInt(0)));
+ } else if (syncStatus == null) {
+ syncInfoMap.put(NULL_EVENT_SYNC_STATUS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ private void populateClientSyncInfo(Cursor cursor) {
+ String syncStatus = cursor.getString(cursor.getColumnIndex(SYNC_STATUS));
+ if (BaseRepository.TYPE_Synced.equals(syncStatus)) {
+ syncInfoMap.put(SYNCED_CLIENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_Unsynced.equals(syncStatus)) {
+ syncInfoMap.put(UNSYNCED_CLIENTS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ private void populateValidatedEventsInfo(Cursor cursor) {
+ String syncStatus = cursor.getString(cursor.getColumnIndex(VALIDATION_STATUS));
+ if (BaseRepository.TYPE_Valid.equals(syncStatus)) {
+ syncInfoMap.put(VALID_EVENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_InValid.equals(syncStatus)) {
+ syncInfoMap.put(INVALID_EVENTS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ private void populateValidatedClientsInfo(Cursor cursor) {
+ String validationStatus = cursor.getString(cursor.getColumnIndex(VALIDATION_STATUS));
+ if (BaseRepository.TYPE_Valid.equals(validationStatus)) {
+ syncInfoMap.put(VALID_CLIENTS, String.valueOf(cursor.getInt(0)));
+ } else if (BaseRepository.TYPE_InValid.equals(validationStatus)) {
+ syncInfoMap.put(INVALID_CLIENTS, String.valueOf(cursor.getInt(0)));
+ }
+ }
+
+ public void populateUserInfo() {
+ AllSharedPreferences sharedPreferences = CoreLibrary.getInstance().context().userService().getAllSharedPreferences();
+ String userName = sharedPreferences.fetchRegisteredANM();
+ String userTeam = sharedPreferences.fetchDefaultTeam(sharedPreferences.fetchRegisteredANM());
+ String userLocality = sharedPreferences.fetchCurrentLocality();
+ syncInfoMap.put(USER_NAME, StringUtils.isNotBlank(userName) ? userName : "-");
+ syncInfoMap.put(USER_TEAM, StringUtils.isNotBlank(userTeam) ? userTeam : "-");
+ syncInfoMap.put(USER_LOCALITY, StringUtils.isNotBlank(userLocality) ? userLocality : "-");
+ }
+
+
+ private void populateBuildInfo() {
+ try {
+ syncInfoMap.put(APP_VERSION_NAME, Utils.getVersion(CoreLibrary.getInstance().context().applicationContext()));
+ } catch (PackageManager.NameNotFoundException e) {
+ syncInfoMap.put(APP_VERSION_NAME, "-");
+ Timber.e(e);
+ }
+ try {
+ syncInfoMap.put(APP_VERSION_CODE, String.valueOf(Utils.getVersionCode(CoreLibrary.getInstance().context().applicationContext())));
+ } catch (PackageManager.NameNotFoundException e) {
+ syncInfoMap.put(APP_VERSION_CODE, "-");
+ Timber.e(e);
+ }
+ try {
+ syncInfoMap.put(DB_VERSION, String.valueOf(Utils.getDatabaseVersion()));
+ } catch (Exception e) {
+ syncInfoMap.put(DB_VERSION, "-");
+ Timber.e(e);
+ }
+ }
+
+ private void populateDeviceInfo() {
+ try {
+ syncInfoMap.put(MANUFACTURER, Build.MANUFACTURER);
+ syncInfoMap.put(MODEL, Build.MODEL);
+ syncInfoMap.put(APP_BUILD_DATE, Utils.getBuildDate(true));
+
+ String osName = Build.VERSION_CODES.class.getFields()[android.os.Build.VERSION.SDK_INT].getName();
+ syncInfoMap.put(OS_VERSION, osName);
+ } catch (Exception e) {
+ Timber.e(e);
+ }
+
+ }
+}
diff --git a/opensrp-core/src/main/java/org/smartregister/util/Utils.java b/opensrp-core/src/main/java/org/smartregister/util/Utils.java
index c50cdcf42..79c36736a 100644
--- a/opensrp-core/src/main/java/org/smartregister/util/Utils.java
+++ b/opensrp-core/src/main/java/org/smartregister/util/Utils.java
@@ -77,6 +77,7 @@
import org.smartregister.domain.jsonmapping.util.TreeNode;
import org.smartregister.receiver.SyncStatusBroadcastReceiver;
import org.smartregister.repository.AllSharedPreferences;
+import org.smartregister.view.activity.DrishtiApplication;
import java.io.BufferedReader;
import java.io.File;
@@ -1038,4 +1039,8 @@ public static String extractTranslatableValue(String value) {
}
return value;
}
+
+ public static int getDatabaseVersion() {
+ return DrishtiApplication.getInstance().getRepository().getReadableDatabase().getVersion();
+ }
}
\ No newline at end of file
diff --git a/opensrp-core/src/main/java/org/smartregister/view/contract/StatsFragmentContract.java b/opensrp-core/src/main/java/org/smartregister/view/contract/StatsFragmentContract.java
index 8c51df68c..4353c7d4a 100644
--- a/opensrp-core/src/main/java/org/smartregister/view/contract/StatsFragmentContract.java
+++ b/opensrp-core/src/main/java/org/smartregister/view/contract/StatsFragmentContract.java
@@ -7,7 +7,7 @@
public interface StatsFragmentContract {
interface Presenter {
- void onECSyncInfoFetched(Map syncInfoMap);
+ void onECSyncInfoFetched(Map syncInfoMap);
void fetchSyncInfo();
@@ -16,7 +16,7 @@ interface Presenter {
interface View {
Context getContext();
- void refreshECSyncInfo(Map syncInfoMap);
+ void refreshECSyncInfo(Map syncInfoMap);
}
interface Interactor {
diff --git a/opensrp-core/src/main/java/org/smartregister/view/fragment/StatsFragment.java b/opensrp-core/src/main/java/org/smartregister/view/fragment/StatsFragment.java
index 04d46464c..b2c2ff011 100644
--- a/opensrp-core/src/main/java/org/smartregister/view/fragment/StatsFragment.java
+++ b/opensrp-core/src/main/java/org/smartregister/view/fragment/StatsFragment.java
@@ -1,5 +1,26 @@
package org.smartregister.view.fragment;
+import static org.smartregister.AllConstants.DatabaseKeys.DB_VERSION;
+import static org.smartregister.AllConstants.DeviceInfo.MANUFACTURER;
+import static org.smartregister.AllConstants.DeviceInfo.MODEL;
+import static org.smartregister.AllConstants.DeviceInfo.OS_VERSION;
+import static org.smartregister.AllConstants.SyncInfo.APP_BUILD_DATE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_CODE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_NAME;
+import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_HEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_VACCINE_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_WEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.USER_LOCALITY;
+import static org.smartregister.AllConstants.SyncInfo.USER_NAME;
+import static org.smartregister.AllConstants.SyncInfo.USER_TEAM;
+import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
+import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
+
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -12,20 +33,15 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
+import org.smartregister.CoreLibrary;
import org.smartregister.R;
import org.smartregister.view.contract.StatsFragmentContract;
import org.smartregister.view.presenter.StatsFragmentPresenter;
+import java.text.DateFormat;
+import java.util.Date;
import java.util.Map;
-import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
-
public class StatsFragment extends Fragment implements StatsFragmentContract.View {
private StatsFragmentPresenter presenter;
@@ -37,6 +53,20 @@ public class StatsFragment extends Fragment implements StatsFragmentContract.Vie
private TextView tvValidatedEvents;
private TextView tvValidatedClients;
private TextView tvTaskUnprocessedEvents;
+ private TextView tvUserName;
+ private TextView tvAppVersionName;
+ private TextView tvAppVersionCode;
+ private TextView tvDBVersion;
+ private TextView tvTeam;
+ private TextView tvLocality;
+ private TextView tvManufacturer;
+ private TextView tvDevice;
+ private TextView tvOS;
+ private TextView tvBuildDate;
+ private TextView tvCurrentDate;
+ private TextView tvUnsyncedVaccineEvents;
+ private TextView tvUnsyncedWeightEvents;
+ private TextView tvUnsyncedHeightEvents;
public static StatsFragment newInstance(Bundle bundle) {
StatsFragment fragment = new StatsFragment();
@@ -70,6 +100,20 @@ private void initializeViews(View view) {
tvValidatedEvents = view.findViewById(R.id.validated_events);
tvValidatedClients = view.findViewById(R.id.validated_clients);
tvTaskUnprocessedEvents = view.findViewById(R.id.task_unprocessed_events);
+ tvUserName = view.findViewById(R.id.user_value);
+ tvAppVersionName = view.findViewById(R.id.app_version_name_value);
+ tvAppVersionCode = view.findViewById(R.id.app_version_code_value);
+ tvDBVersion = view.findViewById(R.id.db_version_value);
+ tvTeam = view.findViewById(R.id.team_value);
+ tvLocality = view.findViewById(R.id.locality_value);
+ tvManufacturer = view.findViewById(R.id.manufacturer_value);
+ tvDevice = view.findViewById(R.id.device_value);
+ tvOS = view.findViewById(R.id.os_value);
+ tvBuildDate = view.findViewById(R.id.build_date_value);
+ tvCurrentDate = view.findViewById(R.id.date_value);
+ tvUnsyncedVaccineEvents = view.findViewById(R.id.synced_vaccine_events);
+ tvUnsyncedHeightEvents = view.findViewById(R.id.synced_height_events);
+ tvUnsyncedWeightEvents = view.findViewById(R.id.synced_weight_events);
Button btnRefreshStats = view.findViewById(R.id.refresh_button);
btnRefreshStats.setOnClickListener(v -> presenter.fetchSyncInfo());
@@ -79,17 +123,41 @@ private void initializeViews(View view) {
@SuppressLint("SetTextI18n")
@Override
- public void refreshECSyncInfo(Map syncInfoMap) {
-
- tvSyncedEvents.setText(syncInfoMap.get(SYNCED_EVENTS) + "");
- tvUnSyncedEvents.setText(syncInfoMap.get(UNSYNCED_EVENTS) + "");
- tvTaskUnprocessedEvents.setText(syncInfoMap.get(TASK_UNPROCESSED_EVENTS) + "");
-
- tvSyncedClient.setText(syncInfoMap.get(SYNCED_CLIENTS) + "");
- tvUnSyncedClients.setText(syncInfoMap.get(UNSYNCED_CLIENTS) + "");
-
- tvValidatedEvents.setText(syncInfoMap.get(VALID_EVENTS) + "");
- tvValidatedClients.setText(syncInfoMap.get(VALID_CLIENTS) + "");
+ public void refreshECSyncInfo(Map syncInfoMap) {
+
+ tvSyncedEvents.setText(syncInfoMap.get(SYNCED_EVENTS));
+ tvUnSyncedEvents.setText(syncInfoMap.get(UNSYNCED_EVENTS));
+ tvTaskUnprocessedEvents.setText(syncInfoMap.get(TASK_UNPROCESSED_EVENTS));
+
+ tvSyncedClient.setText(syncInfoMap.get(SYNCED_CLIENTS));
+ tvUnSyncedClients.setText(syncInfoMap.get(UNSYNCED_CLIENTS));
+
+ tvValidatedEvents.setText(syncInfoMap.get(VALID_EVENTS));
+ tvValidatedClients.setText(syncInfoMap.get(VALID_CLIENTS));
+
+ tvUnsyncedVaccineEvents.setText(syncInfoMap.get(UNSYNCED_VACCINE_EVENTS));
+ tvUnsyncedWeightEvents.setText(syncInfoMap.get(UNSYNCED_WEIGHT_EVENTS));
+ // Only show height stats if they are record height is enabled
+ if (CoreLibrary.getInstance().context().getAppProperties().isTrue("monitor.height")) // Constant is defined in growth-monitoring module
+ tvUnsyncedHeightEvents.setText(syncInfoMap.get(UNSYNCED_HEIGHT_EVENTS));
+ else {
+ if (getView() != null) {
+ getView().findViewById(R.id.height_stats).setVisibility(View.GONE);
+ }
+ }
+ tvUserName.setText(syncInfoMap.get(USER_NAME));
+ tvAppVersionName.setText(syncInfoMap.get(APP_VERSION_NAME));
+ tvAppVersionCode.setText(syncInfoMap.get(APP_VERSION_CODE));
+ tvDBVersion.setText(syncInfoMap.get(DB_VERSION));
+ tvBuildDate.setText(syncInfoMap.get(APP_BUILD_DATE));
+
+ tvTeam.setText(syncInfoMap.get(USER_TEAM));
+ tvLocality.setText(syncInfoMap.get(USER_LOCALITY));
+
+ tvManufacturer.setText(syncInfoMap.get(MANUFACTURER));
+ tvDevice.setText(syncInfoMap.get(MODEL));
+ tvOS.setText(syncInfoMap.get(OS_VERSION));
+ tvCurrentDate.setText(DateFormat.getDateTimeInstance().format(new Date()));
}
}
diff --git a/opensrp-core/src/main/java/org/smartregister/view/interactor/StatsFragmentInteractor.java b/opensrp-core/src/main/java/org/smartregister/view/interactor/StatsFragmentInteractor.java
index 59ab35bd4..5a0e16e62 100644
--- a/opensrp-core/src/main/java/org/smartregister/view/interactor/StatsFragmentInteractor.java
+++ b/opensrp-core/src/main/java/org/smartregister/view/interactor/StatsFragmentInteractor.java
@@ -1,147 +1,32 @@
package org.smartregister.view.interactor;
-import net.sqlcipher.Cursor;
-import net.sqlcipher.database.SQLiteDatabase;
-
-import org.smartregister.repository.BaseRepository;
import org.smartregister.util.AppExecutors;
-import org.smartregister.view.activity.DrishtiApplication;
+import org.smartregister.util.StatsUtils;
import org.smartregister.view.contract.StatsFragmentContract;
-import java.util.HashMap;
import java.util.Map;
import timber.log.Timber;
-import static org.smartregister.AllConstants.DatabaseKeys.SYNC_STATUS;
-import static org.smartregister.AllConstants.DatabaseKeys.VALIDATION_STATUS;
-import static org.smartregister.AllConstants.SyncInfo.INVALID_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.INVALID_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.NULL_EVENT_SYNC_STATUS;
-import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
-import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
-import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
-
public class StatsFragmentInteractor implements StatsFragmentContract.Interactor {
- private AppExecutors appExecutors;
-
- private SQLiteDatabase database;
+ private final AppExecutors appExecutors;
- private StatsFragmentContract.Presenter presenter;
-
- private Map syncInfoMap = new HashMap<>();
+ private final StatsFragmentContract.Presenter presenter;
public StatsFragmentInteractor(StatsFragmentContract.Presenter presenter) {
this.presenter = presenter;
appExecutors = new AppExecutors();
- database = DrishtiApplication.getInstance().getRepository().getReadableDatabase();
}
@Override
public void fetchECSyncInfo() {
- syncInfoMap = new HashMap<>();
- syncInfoMap.put(SYNCED_EVENTS, 0);
- syncInfoMap.put(SYNCED_CLIENTS, 0);
- syncInfoMap.put(UNSYNCED_EVENTS, 0);
- syncInfoMap.put(UNSYNCED_CLIENTS, 0);
- syncInfoMap.put(VALID_EVENTS, 0);
- syncInfoMap.put(INVALID_EVENTS, 0);
- syncInfoMap.put(VALID_CLIENTS, 0);
- syncInfoMap.put(INVALID_CLIENTS, 0);
- syncInfoMap.put(TASK_UNPROCESSED_EVENTS, 0);
- syncInfoMap.put(NULL_EVENT_SYNC_STATUS, 0);
-
- String eventSyncSql = "select count(*), syncStatus from event group by syncStatus";
- String clientSyncSql = "select count(*), syncStatus from client group by syncStatus";
-
- String validatedEventsSql = "select count(*), validationStatus from event group by validationStatus";
- String validatedClientsSql = "select count(*), validationStatus from client group by validationStatus";
-
- Cursor cursor = null;
-
try {
- cursor = database.rawQuery(eventSyncSql, new String[]{});
- while (cursor.moveToNext()) {
- populateEventSyncInfo(cursor);
- }
- cursor.close();
-
- cursor = database.rawQuery(clientSyncSql, new String[]{});
- while (cursor.moveToNext()) {
- populateClientSyncInfo(cursor);
- }
- cursor.close();
-
- cursor = database.rawQuery(validatedEventsSql, new String[]{});
- while (cursor.moveToNext()) {
- populateValidatedEventsInfo(cursor);
- }
- cursor.close();
-
- cursor = database.rawQuery(validatedClientsSql, new String[]{});
- while (cursor.moveToNext()) {
- populateValidatedClientsInfo(cursor);
- }
-
- cursor.close();
-
- appExecutors.mainThread().execute(new Runnable() {
- @Override
- public void run() {
- presenter.onECSyncInfoFetched(syncInfoMap);
- }
- });
+ Map syncInfoMap = new StatsUtils().fetchStatsInfo();
+ appExecutors.mainThread().execute(() -> presenter.onECSyncInfoFetched(syncInfoMap));
} catch (Exception e) {
Timber.e(e);
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- }
-
- private void populateEventSyncInfo(Cursor cursor) {
- String syncStatus = cursor.getString(cursor.getColumnIndex(SYNC_STATUS));
- if (BaseRepository.TYPE_Synced.equals(syncStatus)) {
- syncInfoMap.put(SYNCED_EVENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_Unsynced.equals(syncStatus)) {
- syncInfoMap.put(UNSYNCED_EVENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_Task_Unprocessed.equals(syncStatus)) {
- syncInfoMap.put(TASK_UNPROCESSED_EVENTS, cursor.getInt(0));
- } else if (syncStatus == null) {
- syncInfoMap.put(NULL_EVENT_SYNC_STATUS, cursor.getInt(0));
- }
- }
-
- private void populateClientSyncInfo(Cursor cursor) {
- String syncStatus = cursor.getString(cursor.getColumnIndex(SYNC_STATUS));
- if (BaseRepository.TYPE_Synced.equals(syncStatus)) {
- syncInfoMap.put(SYNCED_CLIENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_Unsynced.equals(syncStatus)) {
- syncInfoMap.put(UNSYNCED_CLIENTS, cursor.getInt(0));
- }
- }
-
- private void populateValidatedEventsInfo(Cursor cursor) {
- String syncStatus = cursor.getString(cursor.getColumnIndex(VALIDATION_STATUS));
- if (BaseRepository.TYPE_Valid.equals(syncStatus)) {
- syncInfoMap.put(VALID_EVENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_InValid.equals(syncStatus)) {
- syncInfoMap.put(INVALID_EVENTS, cursor.getInt(0));
}
}
- private void populateValidatedClientsInfo(Cursor cursor) {
- String validationStatus = cursor.getString(cursor.getColumnIndex(VALIDATION_STATUS));
- if (BaseRepository.TYPE_Valid.equals(validationStatus)) {
- syncInfoMap.put(VALID_CLIENTS, cursor.getInt(0));
- } else if (BaseRepository.TYPE_InValid.equals(validationStatus)) {
- syncInfoMap.put(INVALID_CLIENTS, cursor.getInt(0));
- }
- }
}
diff --git a/opensrp-core/src/main/java/org/smartregister/view/presenter/StatsFragmentPresenter.java b/opensrp-core/src/main/java/org/smartregister/view/presenter/StatsFragmentPresenter.java
index 018e94134..6003c5a23 100644
--- a/opensrp-core/src/main/java/org/smartregister/view/presenter/StatsFragmentPresenter.java
+++ b/opensrp-core/src/main/java/org/smartregister/view/presenter/StatsFragmentPresenter.java
@@ -1,5 +1,6 @@
package org.smartregister.view.presenter;
+
import org.smartregister.view.contract.StatsFragmentContract;
import org.smartregister.view.interactor.StatsFragmentInteractor;
@@ -16,7 +17,7 @@ public StatsFragmentPresenter(StatsFragmentContract.View view) {
}
@Override
- public void onECSyncInfoFetched(Map syncInfoMap) {
+ public void onECSyncInfoFetched(Map syncInfoMap) {
view.refreshECSyncInfo(syncInfoMap);
}
diff --git a/opensrp-core/src/test/assets/app.properties b/opensrp-core/src/test/assets/app.properties
index 06a6d97c6..4847bbc01 100644
--- a/opensrp-core/src/test/assets/app.properties
+++ b/opensrp-core/src/test/assets/app.properties
@@ -2,4 +2,4 @@ DRISHTI_BASE_URL=
PORT=-1
SHOULD_VERIFY_CERTIFICATE=false
SYNC_DOWNLOAD_BATCH_SIZE=10
-system.toaster.centered=true
+system.toaster.centered=true
\ No newline at end of file
diff --git a/opensrp-core/src/test/java/org/smartregister/CoreLibraryTest.java b/opensrp-core/src/test/java/org/smartregister/CoreLibraryTest.java
index f1585ca0e..12adff3a5 100644
--- a/opensrp-core/src/test/java/org/smartregister/CoreLibraryTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/CoreLibraryTest.java
@@ -74,8 +74,7 @@ public void initP2pLibrary() {
@Test(expected = IllegalStateException.class)
public void getInstanceShouldThrowException() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
-
+ CoreLibrary.destroyInstance();
CoreLibrary.getInstance();
}
diff --git a/opensrp-core/src/test/java/org/smartregister/TestApplication.java b/opensrp-core/src/test/java/org/smartregister/TestApplication.java
index 5c006c2d4..11176eaad 100644
--- a/opensrp-core/src/test/java/org/smartregister/TestApplication.java
+++ b/opensrp-core/src/test/java/org/smartregister/TestApplication.java
@@ -14,8 +14,11 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import net.sqlcipher.database.SQLiteDatabase;
+
/**
* Created by samuelgithengi on 12/30/19.
*/
@@ -45,8 +48,13 @@ public void logoutCurrentUser() {
@Override
public Repository getRepository() {
- if (repository == null)
- repository = mock(Repository.class);
+ if (repository == null) {
+ Repository mockRepository = mock(Repository.class);
+ SQLiteDatabase mockSqLiteDatabase = mock(SQLiteDatabase.class);
+ doReturn(mockSqLiteDatabase).when(mockRepository).getReadableDatabase();
+ doReturn(1).when(mockSqLiteDatabase).getVersion();
+ repository = mockRepository;
+ }
return repository;
}
diff --git a/opensrp-core/src/test/java/org/smartregister/TestP2pApplication.java b/opensrp-core/src/test/java/org/smartregister/TestP2pApplication.java
index 7b3f64647..c92f9cc19 100644
--- a/opensrp-core/src/test/java/org/smartregister/TestP2pApplication.java
+++ b/opensrp-core/src/test/java/org/smartregister/TestP2pApplication.java
@@ -1,10 +1,9 @@
package org.smartregister;
-import org.robolectric.util.ReflectionHelpers;
-import org.smartregister.repository.AllSharedPreferences;
-
import static android.preference.PreferenceManager.getDefaultSharedPreferences;
+import org.smartregister.repository.AllSharedPreferences;
+
/**
* Created by Ephraim Kigamba - nek.eam@gmail.com on 18-08-2020.
*/
@@ -18,7 +17,7 @@ public void onCreate() {
AllSharedPreferences allSharedPreferences = new AllSharedPreferences(getDefaultSharedPreferences(context.applicationContext()));
allSharedPreferences.updateANMUserName("demo");
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
CoreLibrary.init(context, new TestSyncConfiguration(), 1588062490000l, new P2POptions(true));
}
}
diff --git a/opensrp-core/src/test/java/org/smartregister/clientandeventmodel/populateform/ModelTest.java b/opensrp-core/src/test/java/org/smartregister/clientandeventmodel/populateform/ModelTest.java
new file mode 100644
index 000000000..1d1a06812
--- /dev/null
+++ b/opensrp-core/src/test/java/org/smartregister/clientandeventmodel/populateform/ModelTest.java
@@ -0,0 +1,31 @@
+package org.smartregister.clientandeventmodel.populateform;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.smartregister.BaseUnitTest;
+import org.smartregister.clientandeventmodel.populateform.Model;
+
+public class ModelTest extends BaseUnitTest {
+
+ private Model model;
+
+ @Before
+ public void setUp() {
+ model = new Model("tag","openMRSEntity","openMRSEntityId","OpenMRSEntityParent");
+ }
+
+ @Test
+ public void testConstructorNotNull() {
+ Assert.assertNotNull(model);
+ }
+
+ @Test
+ public void testFieldMembers() {
+ Assert.assertEquals("tag", model.getTag());
+ Assert.assertEquals("openMRSEntity", model.getOpenMRSEntity());
+ Assert.assertEquals("openMRSEntityId", model.getOpenMRSEntityId());
+ Assert.assertEquals("OpenMRSEntityParent", model.getOpenMRSEntityParent());
+ }
+
+}
\ No newline at end of file
diff --git a/opensrp-core/src/test/java/org/smartregister/login/model/BaseLoginModelTest.java b/opensrp-core/src/test/java/org/smartregister/login/model/BaseLoginModelTest.java
index e66804594..22a890173 100644
--- a/opensrp-core/src/test/java/org/smartregister/login/model/BaseLoginModelTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/login/model/BaseLoginModelTest.java
@@ -1,14 +1,5 @@
package org.smartregister.login.model;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.robolectric.util.ReflectionHelpers;
-import org.smartregister.BaseRobolectricUnitTest;
-import org.smartregister.Context;
-import org.smartregister.CoreLibrary;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -17,6 +8,14 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.smartregister.BaseRobolectricUnitTest;
+import org.smartregister.Context;
+import org.smartregister.CoreLibrary;
+
/**
* Created by samuelgithengi on 8/18/20.
*/
@@ -34,7 +33,7 @@ public void setUp() {
@After
public void tearDown() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
@Test
diff --git a/opensrp-core/src/test/java/org/smartregister/login/presenter/BaseLoginPresenterTest.java b/opensrp-core/src/test/java/org/smartregister/login/presenter/BaseLoginPresenterTest.java
index 0c2f94e6c..8f9e7aca5 100644
--- a/opensrp-core/src/test/java/org/smartregister/login/presenter/BaseLoginPresenterTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/login/presenter/BaseLoginPresenterTest.java
@@ -1,5 +1,16 @@
package org.smartregister.login.presenter;
+import static android.preference.PreferenceManager.getDefaultSharedPreferences;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
import android.content.res.Configuration;
import android.view.ViewTreeObserver;
import android.widget.RelativeLayout;
@@ -15,7 +26,6 @@
import org.mockito.Spy;
import org.powermock.reflect.Whitebox;
import org.robolectric.Robolectric;
-import org.robolectric.util.ReflectionHelpers;
import org.smartregister.BaseRobolectricUnitTest;
import org.smartregister.CoreLibrary;
import org.smartregister.R;
@@ -25,17 +35,6 @@
import java.lang.ref.WeakReference;
-import static android.preference.PreferenceManager.getDefaultSharedPreferences;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
/**
* Created by samuelgithengi on 8/18/20.
*/
@@ -66,7 +65,7 @@ public void setUp() {
@After
public void tearDown() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
@Test
diff --git a/opensrp-core/src/test/java/org/smartregister/presenter/StatsFragmentPresenterTest.java b/opensrp-core/src/test/java/org/smartregister/presenter/StatsFragmentPresenterTest.java
index 980d15aec..d5dfbcc27 100644
--- a/opensrp-core/src/test/java/org/smartregister/presenter/StatsFragmentPresenterTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/presenter/StatsFragmentPresenterTest.java
@@ -3,10 +3,10 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.Spy;
+import org.mockito.MockitoAnnotations;
import org.robolectric.util.ReflectionHelpers;
-import org.smartregister.BaseUnitTest;
import org.smartregister.view.contract.StatsFragmentContract;
import org.smartregister.view.interactor.StatsFragmentInteractor;
import org.smartregister.view.presenter.StatsFragmentPresenter;
@@ -14,26 +14,32 @@
import java.util.HashMap;
import java.util.Map;
-public class StatsFragmentPresenterTest extends BaseUnitTest {
- @Spy
- StatsFragmentContract.View view;
+public class StatsFragmentPresenterTest {
+
+ @Mock
private StatsFragmentInteractor interactor;
+
private StatsFragmentPresenter presenter;
+ @Mock
+ StatsFragmentContract.View view;
+
@Before
public void setUp() {
+ MockitoAnnotations.initMocks(this);
presenter = Mockito.mock(StatsFragmentPresenter.class, Mockito.CALLS_REAL_METHODS);
- interactor = Mockito.mock(StatsFragmentInteractor.class, Mockito.CALLS_REAL_METHODS);
+ view = Mockito.spy(view);
+ interactor = Mockito.spy(interactor);
ReflectionHelpers.setField(presenter, "interactor", interactor);
ReflectionHelpers.setField(presenter, "view", view);
}
@Test
public void onECSyncInfoFetchedRefreshesECSyncInfo() {
- Map syncInfoMap = new HashMap<>();
+ Map syncInfoMap = new HashMap<>();
presenter.onECSyncInfoFetched(syncInfoMap);
- Mockito.verify(view).refreshECSyncInfo(ArgumentMatchers.eq(syncInfoMap));
+ Mockito.verify(view, Mockito.times(2)).refreshECSyncInfo(ArgumentMatchers.eq(syncInfoMap));
}
@Test
diff --git a/opensrp-core/src/test/java/org/smartregister/sync/ClientProcessorForJavaTest.java b/opensrp-core/src/test/java/org/smartregister/sync/ClientProcessorForJavaTest.java
index 4dc3ad47e..ac1a36693 100644
--- a/opensrp-core/src/test/java/org/smartregister/sync/ClientProcessorForJavaTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/sync/ClientProcessorForJavaTest.java
@@ -651,7 +651,7 @@ public void processFieldShouldCreateCaseBasedOnObsValueFilled() {
@After
public void tearDown() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
clientProcessor = null;
}
}
diff --git a/opensrp-core/src/test/java/org/smartregister/sync/helper/BaseHelperTest.java b/opensrp-core/src/test/java/org/smartregister/sync/helper/BaseHelperTest.java
index 7bab700ea..1af2c2b37 100644
--- a/opensrp-core/src/test/java/org/smartregister/sync/helper/BaseHelperTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/sync/helper/BaseHelperTest.java
@@ -26,6 +26,6 @@ public void getFormattedBaseUrl() {
Assert.assertEquals("http://site.com", new BaseHelper().getFormattedBaseUrl());
// Return the configuration to the previous state to fix the TaskServiceHelperTest failures
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
}
\ No newline at end of file
diff --git a/opensrp-core/src/test/java/org/smartregister/sync/helper/LocationServiceHelperTest.java b/opensrp-core/src/test/java/org/smartregister/sync/helper/LocationServiceHelperTest.java
index 5465c7792..420d4e610 100644
--- a/opensrp-core/src/test/java/org/smartregister/sync/helper/LocationServiceHelperTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/sync/helper/LocationServiceHelperTest.java
@@ -1,5 +1,15 @@
package org.smartregister.sync.helper;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.smartregister.AllConstants.OPERATIONAL_AREAS;
+import static org.smartregister.sync.helper.LocationServiceHelper.LOCATION_LAST_SYNC_DATE;
+
import com.google.gson.reflect.TypeToken;
import net.sqlcipher.database.SQLiteDatabase;
@@ -13,7 +23,6 @@
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
import org.powermock.reflect.Whitebox;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.BaseRobolectricUnitTest;
@@ -41,16 +50,6 @@
import java.util.Collections;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.smartregister.AllConstants.OPERATIONAL_AREAS;
-import static org.smartregister.sync.helper.LocationServiceHelper.LOCATION_LAST_SYNC_DATE;
-
public class LocationServiceHelperTest extends BaseRobolectricUnitTest {
@Mock
@@ -354,6 +353,6 @@ public void testGetLocationHierarchyReturnsTreeForValidParentLocationId() {
@After
public void tearDown() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
}
\ No newline at end of file
diff --git a/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java b/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java
new file mode 100644
index 000000000..9b7f85264
--- /dev/null
+++ b/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java
@@ -0,0 +1,148 @@
+package org.smartregister.util;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.smartregister.AllConstants.DatabaseKeys.DB_VERSION;
+import static org.smartregister.AllConstants.DatabaseKeys.VALIDATION_STATUS;
+import static org.smartregister.AllConstants.DeviceInfo.MANUFACTURER;
+import static org.smartregister.AllConstants.DeviceInfo.MODEL;
+import static org.smartregister.AllConstants.SyncInfo.APP_BUILD_DATE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_CODE;
+import static org.smartregister.AllConstants.SyncInfo.APP_VERSION_NAME;
+import static org.smartregister.AllConstants.SyncInfo.INVALID_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.USER_LOCALITY;
+import static org.smartregister.AllConstants.SyncInfo.USER_NAME;
+import static org.smartregister.AllConstants.SyncInfo.USER_TEAM;
+import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
+
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import net.sqlcipher.Cursor;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.robolectric.util.ReflectionHelpers;
+import org.smartregister.BaseUnitTest;
+import org.smartregister.Context;
+import org.smartregister.CoreLibrary;
+import org.smartregister.repository.AllSharedPreferences;
+import org.smartregister.repository.BaseRepository;
+import org.smartregister.service.UserService;
+
+import java.util.Map;
+
+public class StatsUtilsTest extends BaseUnitTest {
+
+ private StatsUtils statsUtils;
+
+ @Before
+ public void setUp() {
+ statsUtils = new StatsUtils();
+ }
+
+ @Test
+ public void testPopulateUserInfoPopulatesCorrectValues() {
+ CoreLibrary coreLibrary = Mockito.mock(CoreLibrary.class);
+ ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", coreLibrary);
+
+ Context context = Mockito.mock(Context.class);
+ UserService userService = Mockito.mock(UserService.class);
+ AllSharedPreferences sharedPreferences = Mockito.mock(AllSharedPreferences.class);
+
+ Mockito.doReturn(context).when(coreLibrary).context();
+ Mockito.doReturn(userService).when(context).userService();
+ Mockito.doReturn(sharedPreferences).when(userService).getAllSharedPreferences();
+ Mockito.doReturn("user").when(sharedPreferences).fetchRegisteredANM();
+ Mockito.doReturn("team").when(sharedPreferences).fetchDefaultTeam(Mockito.anyString());
+ Mockito.doReturn("locality").when(sharedPreferences).fetchCurrentLocality();
+
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateUserInfo");
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+
+ Assert.assertEquals("user", syncInfoMap.get(USER_NAME));
+ Assert.assertEquals("team", syncInfoMap.get(USER_TEAM));
+ Assert.assertEquals("locality", syncInfoMap.get(USER_LOCALITY));
+ }
+
+ @Test
+ public void testPopulateBuildInfoPopulatesCorrectValues() throws PackageManager.NameNotFoundException {
+ CoreLibrary coreLibrary = Mockito.mock(CoreLibrary.class);
+ ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", coreLibrary);
+
+ Context context = Mockito.mock(Context.class);
+ android.content.Context appContext = Mockito.spy(ApplicationProvider.getApplicationContext());
+
+ Mockito.doReturn(context).when(coreLibrary).context();
+ Mockito.doReturn(appContext).when(context).applicationContext();
+
+ PackageManager packageManager = Mockito.mock(PackageManager.class);
+ PackageInfo packageInfo = Mockito.mock(PackageInfo.class);
+ packageInfo.versionName = "v1.0.0";
+ packageInfo.versionCode = 1;
+ Mockito.doReturn(packageManager).when(appContext).getPackageManager();
+ Mockito.doReturn("org.smartregister").when(appContext).getPackageName();
+ Mockito.doReturn(packageInfo).when(packageManager).getPackageInfo(eq("org.smartregister"), eq(0));
+
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateBuildInfo");
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+
+ Assert.assertEquals("v1.0.0", syncInfoMap.get(APP_VERSION_NAME));
+ Assert.assertEquals("1", syncInfoMap.get(APP_VERSION_CODE));
+ Assert.assertEquals("1", syncInfoMap.get(DB_VERSION));
+ }
+
+ @Test
+ public void testPopulateDeviceInfoPopulatesCorrectValues() {
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateDeviceInfo");
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+
+ Assert.assertEquals("robolectric", syncInfoMap.get(MANUFACTURER));
+ Assert.assertEquals("robolectric", syncInfoMap.get(MODEL));
+ Assert.assertEquals("28 Apr 2020", syncInfoMap.get(APP_BUILD_DATE));
+ }
+
+ @Test
+ public void testPopulateValidatedEventsInfoAddValidEventsCountWhenStatusIsValid() {
+ Cursor cursor = Mockito.mock(Cursor.class);
+
+ Mockito.doReturn(1).when(cursor).getColumnIndex(eq(VALIDATION_STATUS));
+ Mockito.doReturn(BaseRepository.TYPE_Valid).when(cursor).getString(eq(1));
+ Mockito.doReturn(10).when(cursor).getInt(eq(0));
+
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateValidatedEventsInfo",
+ ReflectionHelpers.ClassParameter.from(Cursor.class, cursor));
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+ Assert.assertEquals("10", syncInfoMap.get(VALID_EVENTS));
+
+ }
+
+ @Test
+ public void testPopulateValidatedEventsInfoAddInvalidEventsCountWhenStatusIsInvalid() {
+ Cursor cursor = Mockito.mock(Cursor.class);
+
+ Mockito.doReturn(1).when(cursor).getColumnIndex(eq(VALIDATION_STATUS));
+ Mockito.doReturn(BaseRepository.TYPE_InValid).when(cursor).getString(eq(1));
+ Mockito.doReturn(10).when(cursor).getInt(eq(0));
+
+ ReflectionHelpers.callInstanceMethod(statsUtils, "populateValidatedEventsInfo",
+ ReflectionHelpers.ClassParameter.from(Cursor.class, cursor));
+
+ Map syncInfoMap = ReflectionHelpers.getField(statsUtils, "syncInfoMap");
+ Assert.assertEquals("10", syncInfoMap.get(INVALID_EVENTS));
+
+ }
+
+ @After
+ public void destroy() {
+ CoreLibrary.destroyInstance();
+ }
+}
diff --git a/opensrp-core/src/test/java/org/smartregister/util/UtilsTest.java b/opensrp-core/src/test/java/org/smartregister/util/UtilsTest.java
index 41fc50626..792ae7a4e 100644
--- a/opensrp-core/src/test/java/org/smartregister/util/UtilsTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/util/UtilsTest.java
@@ -753,5 +753,15 @@ public void testExtractTrabslatableValue() throws JSONException
assertEquals(result2,value);
}
+
+ @Test
+ public void testTryParseLongShouldParseCorrectly() {
+ assertEquals(123L, (Long) Utils.tryParseLong("123", 0), 0);
+ }
+
+ @Test
+ public void testTryParseLongShouldParseShoouldReturnDefaultValueOnException() {
+ assertEquals(0L, (Long) Utils.tryParseLong("xyz", 0), 0);
+ }
}
diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/BarcodeScanActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/BarcodeScanActivityTest.java
index 8bdf1c95a..4585c91fd 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/activity/BarcodeScanActivityTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/activity/BarcodeScanActivityTest.java
@@ -1,9 +1,13 @@
package org.smartregister.view.activity;
+import static org.mockito.Mockito.verify;
+
import android.content.Intent;
import android.util.Log;
import android.util.SparseArray;
+import androidx.test.core.app.ApplicationProvider;
+
import com.google.android.gms.vision.Detector;
import com.google.android.gms.vision.barcode.Barcode;
@@ -15,15 +19,11 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
-import androidx.test.core.app.ApplicationProvider;
import org.robolectric.android.controller.ActivityController;
-import org.robolectric.util.ReflectionHelpers;
import org.smartregister.BaseUnitTest;
import org.smartregister.CoreLibrary;
import org.smartregister.view.activity.mock.BarcodeScanActivityMock;
-import static org.mockito.Mockito.verify;
-
public class BarcodeScanActivityTest extends BaseUnitTest {
private BarcodeScanActivityMock barcodeScanActivity;
@@ -44,7 +44,7 @@ public class BarcodeScanActivityTest extends BaseUnitTest {
@BeforeClass
public static void resetCoreLibrary() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
@Before
diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/BaseLoginActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/BaseLoginActivityTest.java
index 8b22ebfe1..7c6867ab6 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/activity/BaseLoginActivityTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/activity/BaseLoginActivityTest.java
@@ -54,7 +54,7 @@ public class BaseLoginActivityTest extends BaseRobolectricUnitTest {
@BeforeClass
public static void resetCoreLibrary() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
@Before
diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/BaseRegisterActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/BaseRegisterActivityTest.java
index d532197c0..b77cb77dd 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/activity/BaseRegisterActivityTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/activity/BaseRegisterActivityTest.java
@@ -1,5 +1,22 @@
package org.smartregister.view.activity;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
+import static org.smartregister.view.activity.BaseRegisterActivity.BASE_REG_POSITION;
+
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
@@ -23,7 +40,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;
import org.robolectric.shadows.ShadowToast;
-import org.robolectric.util.ReflectionHelpers;
import org.smartregister.AllConstants;
import org.smartregister.AllConstants.BARCODE;
import org.smartregister.BaseRobolectricUnitTest;
@@ -44,23 +60,6 @@
import java.util.UUID;
import java.util.concurrent.Executors;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.timeout;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-import static org.robolectric.Shadows.shadowOf;
-import static org.smartregister.view.activity.BaseRegisterActivity.BASE_REG_POSITION;
-
/**
* Created by samuelgithengi on 6/30/20.
*/
@@ -93,7 +92,7 @@ public void setUp() {
@After
public void tearDown() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
@Test
diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/FormActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/FormActivityTest.java
index 2dc94823e..6ad6a1467 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/activity/FormActivityTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/activity/FormActivityTest.java
@@ -1,8 +1,16 @@
package org.smartregister.view.activity;
+import static org.mockito.Mockito.when;
+import static org.smartregister.AllConstants.ENTITY_ID_PARAM;
+import static org.smartregister.AllConstants.FIELD_OVERRIDES_PARAM;
+import static org.smartregister.AllConstants.FORM_NAME_PARAM;
+import static org.smartregister.view.activity.NativeECSmartRegisterActivityTest.locationJson;
+
import android.content.Context;
import android.content.Intent;
+import androidx.test.core.app.ApplicationProvider;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -10,21 +18,13 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
-import androidx.test.core.app.ApplicationProvider;
import org.robolectric.android.controller.ActivityController;
-import org.robolectric.util.ReflectionHelpers;
import org.smartregister.BaseUnitTest;
import org.smartregister.CoreLibrary;
import org.smartregister.service.ZiggyService;
import org.smartregister.view.activity.mock.FormActivityMock;
import org.smartregister.view.controller.ANMLocationController;
-import static org.mockito.Mockito.when;
-import static org.smartregister.AllConstants.ENTITY_ID_PARAM;
-import static org.smartregister.AllConstants.FIELD_OVERRIDES_PARAM;
-import static org.smartregister.AllConstants.FORM_NAME_PARAM;
-import static org.smartregister.view.activity.NativeECSmartRegisterActivityTest.locationJson;
-
/**
* Created by kaderchowdhury on 12/11/17.
*/
@@ -47,7 +47,7 @@ public class FormActivityTest extends BaseUnitTest {
@BeforeClass
public static void resetCoreLibrarySingleton() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
@Before
diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/SecuredActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/SecuredActivityTest.java
index 0c42a86c3..19c6090ba 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/activity/SecuredActivityTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/activity/SecuredActivityTest.java
@@ -64,7 +64,7 @@ public class SecuredActivityTest extends BaseRobolectricUnitTest {
@BeforeClass
public static void resetCoreLibrary() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
@Before
diff --git a/opensrp-core/src/test/java/org/smartregister/view/fragment/BaseRegisterFragmentTest.java b/opensrp-core/src/test/java/org/smartregister/view/fragment/BaseRegisterFragmentTest.java
index 5de3f7abf..0b4b8a00c 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/fragment/BaseRegisterFragmentTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/fragment/BaseRegisterFragmentTest.java
@@ -34,7 +34,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
-import androidx.test.core.app.ApplicationProvider;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.AllConstants;
import org.smartregister.BaseUnitTest;
@@ -151,7 +150,7 @@ public void setUp() {
@After
public void tearDown() {
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
+ CoreLibrary.destroyInstance();
}
@Test
diff --git a/opensrp-core/src/test/java/org/smartregister/view/fragment/StatsFragmentTest.java b/opensrp-core/src/test/java/org/smartregister/view/fragment/StatsFragmentTest.java
index 2bdc289cb..024d129a8 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/fragment/StatsFragmentTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/fragment/StatsFragmentTest.java
@@ -1,11 +1,13 @@
package org.smartregister.view.fragment;
-import static org.mockito.Mockito.doReturn;
import static org.smartregister.AllConstants.SyncInfo.SYNCED_CLIENTS;
import static org.smartregister.AllConstants.SyncInfo.SYNCED_EVENTS;
import static org.smartregister.AllConstants.SyncInfo.TASK_UNPROCESSED_EVENTS;
import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_CLIENTS;
import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_HEIGHT_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_VACCINE_EVENTS;
+import static org.smartregister.AllConstants.SyncInfo.UNSYNCED_WEIGHT_EVENTS;
import static org.smartregister.AllConstants.SyncInfo.VALID_CLIENTS;
import static org.smartregister.AllConstants.SyncInfo.VALID_EVENTS;
@@ -14,6 +16,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.FragmentManager;
@@ -24,14 +27,15 @@
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.Spy;
+import org.mockito.MockitoAnnotations;
import org.powermock.reflect.Whitebox;
-import androidx.test.core.app.ApplicationProvider;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.BaseUnitTest;
import org.smartregister.R;
-import org.smartregister.view.contract.StatsFragmentContract;
import org.smartregister.view.presenter.StatsFragmentPresenter;
+import org.smartregister.view.contract.StatsFragmentContract;
+
import java.util.HashMap;
import java.util.Map;
@@ -51,11 +55,9 @@ public class StatsFragmentTest extends BaseUnitTest {
@Mock
private Bundle savedInstanceState;
- @Spy
- private StatsFragmentContract.View view;
-
@Before
public void setUp() {
+ MockitoAnnotations.initMocks(this);
statsFragment = Mockito.mock(StatsFragment.class, Mockito.CALLS_REAL_METHODS);
}
@@ -82,7 +84,11 @@ public void onCreateViewInitsViewsAndReturnsCorrectView() {
View rootView = Mockito.spy(Mockito.mock(View.class));
statsFragment = Mockito.spy(statsFragment);
- presenter = Mockito.spy(new StatsFragmentPresenter(view));
+ StatsFragmentContract.Interactor interactor = Mockito.mock(StatsFragmentContract.Interactor.class);
+ Mockito.doNothing().when(interactor).fetchECSyncInfo();
+
+ presenter = Mockito.spy(Mockito.mock(StatsFragmentPresenter.class));
+ ReflectionHelpers.setField(presenter, "interactor", interactor);
ReflectionHelpers.setField(statsFragment, "presenter", presenter);
Mockito.doReturn(btnRefreshStats).when(rootView).findViewById(R.id.refresh_button);
@@ -95,19 +101,25 @@ public void onCreateViewInitsViewsAndReturnsCorrectView() {
@Test
public void refreshECSyncInfoUpdatesViews() {
- Map syncInfoMap = new HashMap<>();
- syncInfoMap.put(SYNCED_EVENTS, 2);
- syncInfoMap.put(UNSYNCED_EVENTS, 3);
- syncInfoMap.put(TASK_UNPROCESSED_EVENTS, 4);
- syncInfoMap.put(SYNCED_CLIENTS, 5);
- syncInfoMap.put(UNSYNCED_CLIENTS, 6);
- syncInfoMap.put(VALID_EVENTS, 7);
- syncInfoMap.put(VALID_CLIENTS, 8);
-
- View rootView = LayoutInflater.from(ApplicationProvider.getApplicationContext()).inflate(R.layout.fragment_stats, null);
+ Map syncInfoMap = new HashMap<>();
+ syncInfoMap.put(SYNCED_EVENTS, "2");
+ syncInfoMap.put(UNSYNCED_EVENTS, "3");
+ syncInfoMap.put(TASK_UNPROCESSED_EVENTS, "4");
+ syncInfoMap.put(SYNCED_CLIENTS, "5");
+ syncInfoMap.put(UNSYNCED_CLIENTS, "6");
+ syncInfoMap.put(VALID_EVENTS, "7");
+ syncInfoMap.put(VALID_CLIENTS, "8");
+ syncInfoMap.put(UNSYNCED_VACCINE_EVENTS, "1");
+ syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, "1");
+ syncInfoMap.put(UNSYNCED_HEIGHT_EVENTS, "1");
+
+ View rootView = LayoutInflater.from(RuntimeEnvironment.application).inflate(R.layout.fragment_stats, null);
+ Mockito.doReturn(rootView).when(statsFragment).getView();
TextView tvSyncedEvents = rootView.findViewById(R.id.synced_events);
TextView tvUnSyncedEvents = rootView.findViewById(R.id.unsynced_events);
+ TextView tvUnsyncedHeightEvents = rootView.findViewById(R.id.synced_height_events);
+ LinearLayout layoutUnsyncedHeightEvents = rootView.findViewById(R.id.height_stats);
ReflectionHelpers.setField(statsFragment, "tvSyncedEvents", tvSyncedEvents);
ReflectionHelpers.setField(statsFragment, "tvUnSyncedEvents", tvUnSyncedEvents);
@@ -116,10 +128,25 @@ public void refreshECSyncInfoUpdatesViews() {
ReflectionHelpers.setField(statsFragment, "tvUnSyncedClients", rootView.findViewById(R.id.unsynced_clients));
ReflectionHelpers.setField(statsFragment, "tvValidatedEvents", rootView.findViewById(R.id.validated_events));
ReflectionHelpers.setField(statsFragment, "tvValidatedClients", rootView.findViewById(R.id.validated_clients));
+ ReflectionHelpers.setField(statsFragment, "tvUserName", rootView.findViewById(R.id.user_value));
+ ReflectionHelpers.setField(statsFragment, "tvAppVersionName", rootView.findViewById(R.id.app_version_name_value));
+ ReflectionHelpers.setField(statsFragment, "tvAppVersionCode", rootView.findViewById(R.id.app_version_code_value));
+ ReflectionHelpers.setField(statsFragment, "tvDBVersion", rootView.findViewById(R.id.db_version_value));
+ ReflectionHelpers.setField(statsFragment, "tvTeam", rootView.findViewById(R.id.team_value));
+ ReflectionHelpers.setField(statsFragment, "tvLocality", rootView.findViewById(R.id.locality_value));
+ ReflectionHelpers.setField(statsFragment, "tvManufacturer", rootView.findViewById(R.id.manufacturer_value));
+ ReflectionHelpers.setField(statsFragment, "tvDevice", rootView.findViewById(R.id.device_value));
+ ReflectionHelpers.setField(statsFragment, "tvOS", rootView.findViewById(R.id.os_value));
+ ReflectionHelpers.setField(statsFragment, "tvBuildDate", rootView.findViewById(R.id.build_date_value));
+ ReflectionHelpers.setField(statsFragment, "tvCurrentDate", rootView.findViewById(R.id.date_value));
+ ReflectionHelpers.setField(statsFragment, "tvUnsyncedVaccineEvents", rootView.findViewById(R.id.synced_vaccine_events));
+ ReflectionHelpers.setField(statsFragment, "tvUnsyncedWeightEvents", rootView.findViewById(R.id.synced_weight_events));
+ ReflectionHelpers.setField(statsFragment, "tvUnsyncedHeightEvents", tvUnsyncedHeightEvents);
statsFragment.refreshECSyncInfo(syncInfoMap);
Assert.assertEquals("2", tvSyncedEvents.getText());
Assert.assertEquals("3", tvUnSyncedEvents.getText());
+ Assert.assertEquals(View.GONE, layoutUnsyncedHeightEvents.getVisibility());
}
@Test
@@ -129,7 +156,7 @@ public void assertStatsFragmentInitsCorrectly() {
@Test
public void assertTestLabels() {
- View rootView = LayoutInflater.from(ApplicationProvider.getApplicationContext()).inflate(R.layout.fragment_stats, null);
+ View rootView = LayoutInflater.from(RuntimeEnvironment.application).inflate(R.layout.fragment_stats, null);
TextView tvSyncedEventsLabel = rootView.findViewById(R.id.synced_events_label);
TextView tvUnsyncedEventsLabel = rootView.findViewById(R.id.unsynced_events_label);
TextView tvTaskUnprocessedEventsLabel = rootView.findViewById(R.id.task_unprocessed_events_label);
@@ -148,7 +175,7 @@ public void assertTestLabels() {
@Test
public void assertTestLabelsNotNull() {
- View rootView = LayoutInflater.from(ApplicationProvider.getApplicationContext()).inflate(R.layout.fragment_stats, null);
+ View rootView = LayoutInflater.from(RuntimeEnvironment.application).inflate(R.layout.fragment_stats, null);
TextView tvSyncedEventsLabel = rootView.findViewById(R.id.synced_events_label);
TextView tvUnsyncedEventsLabel = rootView.findViewById(R.id.unsynced_events_label);
TextView tvTaskUnprocessedEventsLabel = rootView.findViewById(R.id.task_unprocessed_events_label);
@@ -167,8 +194,8 @@ public void assertTestLabelsNotNull() {
@Test
public void testUpdatedLabels() {
- View parentLayout = LayoutInflater.from(ApplicationProvider.getApplicationContext().getApplicationContext()).inflate(R.layout.fragment_stats, null, false);
- doReturn(parentLayout).when(layoutInflater).inflate(R.layout.fragment_base_register, container, false);
+ View parentLayout = LayoutInflater.from(RuntimeEnvironment.application.getApplicationContext()).inflate(R.layout.fragment_stats, null, false);
+ Mockito.doReturn(parentLayout).when(layoutInflater).inflate(R.layout.fragment_base_register, container, false);
TextView tvSyncedEventsLabel = parentLayout.findViewById(R.id.synced_events_label);
TextView tvUnsyncedEventsLabel = parentLayout.findViewById(R.id.unsynced_events_label);
@@ -186,13 +213,13 @@ public void testUpdatedLabels() {
Assert.assertNotNull(tvValidatedEventsLabel);
Assert.assertNotNull(tvValidatedClientsLabel);
- String synced_events = ApplicationProvider.getApplicationContext().getResources().getString(R.string.synced_events);
- String unsynced_events = ApplicationProvider.getApplicationContext().getResources().getString(R.string.unsynced_events);
- String task_unprocessed_events = ApplicationProvider.getApplicationContext().getResources().getString(R.string.task_unprocessed_events);
- String synced_clients = ApplicationProvider.getApplicationContext().getResources().getString(R.string.synced_clients);
- String unsynced_clients = ApplicationProvider.getApplicationContext().getResources().getString(R.string.unsynced_clients);
- String validated_events = ApplicationProvider.getApplicationContext().getResources().getString(R.string.validated_events);
- String validated_clients = ApplicationProvider.getApplicationContext().getResources().getString(R.string.validated_clients);
+ String synced_events = RuntimeEnvironment.application.getResources().getString(R.string.synced_events);
+ String unsynced_events = RuntimeEnvironment.application.getResources().getString(R.string.unsynced_events);
+ String task_unprocessed_events = RuntimeEnvironment.application.getResources().getString(R.string.task_unprocessed_events);
+ String synced_clients = RuntimeEnvironment.application.getResources().getString(R.string.synced_clients);
+ String unsynced_clients = RuntimeEnvironment.application.getResources().getString(R.string.unsynced_clients);
+ String validated_events = RuntimeEnvironment.application.getResources().getString(R.string.validated_events);
+ String validated_clients = RuntimeEnvironment.application.getResources().getString(R.string.validated_clients);
Assert.assertEquals(synced_events, tvSyncedEventsLabel.getText().toString());
Assert.assertEquals(unsynced_events, tvUnsyncedEventsLabel.getText().toString());
diff --git a/opensrp-core/src/test/java/org/smartregister/view/receiver/ConnectivityChangeReceiverTest.java b/opensrp-core/src/test/java/org/smartregister/view/receiver/ConnectivityChangeReceiverTest.java
index 3e65fbe9f..5e8ad2eeb 100644
--- a/opensrp-core/src/test/java/org/smartregister/view/receiver/ConnectivityChangeReceiverTest.java
+++ b/opensrp-core/src/test/java/org/smartregister/view/receiver/ConnectivityChangeReceiverTest.java
@@ -6,12 +6,13 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
+import androidx.test.core.app.ApplicationProvider;
+
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
-import androidx.test.core.app.ApplicationProvider;
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowAlarmManager;
import org.robolectric.util.ReflectionHelpers;
@@ -44,8 +45,7 @@ public void tearDown(){
Session session = ReflectionHelpers.getField(CoreLibrary.getInstance().context().userService(), "session");
session.setPassword(null);
session.start(0);
- ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
-
+ CoreLibrary.destroyInstance();
}
@Test
diff --git a/sample/src/main/assets/app.properties b/sample/src/main/assets/app.properties
index 8f3a78921..d995c774a 100644
--- a/sample/src/main/assets/app.properties
+++ b/sample/src/main/assets/app.properties
@@ -5,4 +5,4 @@ SYNC_DOWNLOAD_BATCH_SIZE=10
system.toaster.centered=false
encrypt.shared.preferences=false
allow.offline.login.with.invalid.token=false
-ignore.location.deletion = false
+ignore.location.deletion = false
\ No newline at end of file
diff --git a/sample/src/main/java/org/smartregister/sample/MainActivity.java b/sample/src/main/java/org/smartregister/sample/MainActivity.java
index 07f052acc..183f39d70 100644
--- a/sample/src/main/java/org/smartregister/sample/MainActivity.java
+++ b/sample/src/main/java/org/smartregister/sample/MainActivity.java
@@ -1,5 +1,6 @@
package org.smartregister.sample;
+import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -29,7 +30,11 @@
import org.smartregister.util.AppHealthUtils;
import org.smartregister.util.DateUtil;
import org.smartregister.util.LangUtils;
+import org.smartregister.util.PermissionUtils;
+import org.smartregister.util.Utils;
+import org.smartregister.view.activity.DrishtiApplication;
import org.smartregister.view.activity.MultiLanguageActivity;
+import org.smartregister.view.activity.StatsActivity;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -41,13 +46,14 @@
import timber.log.Timber;
-public class MainActivity extends MultiLanguageActivity {
+public class MainActivity extends MultiLanguageActivity implements AppHealthUtils.HealthStatsView {
DatePicker picker;
Button btnGet;
TextView tvw;
CryptographicHelper cryptographicHelper = null;
TextView encDecTextView;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -173,10 +179,9 @@ public void onNothingSelected(AdapterView> parent) {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String keyAlias = "sample";
// Get or create a key with the Alias name sample or create one if id does not exist
- if(cryptographicHelper.getKey(keyAlias)==null)
- {
+ if (cryptographicHelper.getKey(keyAlias) == null) {
cryptographicHelper.generateKey(keyAlias);
- Timber.i("key with alias %s generated",keyAlias);
+ Timber.i("key with alias %s generated", keyAlias);
}
if (isChecked) {
@@ -188,7 +193,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
inputStream.read(inputBytes);
byte[] encryptedContents = CryptographicHelper.encrypt(inputBytes, keyAlias);
FileOutputStream fileOutputStream = openFileOutput(filename, Context.MODE_PRIVATE);
- Timber.i("encrypted stuff to write %S ",new String(encryptedContents));
+ Timber.i("encrypted stuff to write %S ", new String(encryptedContents));
encDecTextView.setText(new String(encryptedContents));
fileOutputStream.write((encryptedContents));
fileOutputStream.flush();
@@ -199,26 +204,26 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
} else {
- try {
- //
- FileInputStream inputStream = openFileInput(filename);
- byte[] inputBytes = new byte[inputStream.available()];
- inputStream.read(inputBytes);
- Timber.i("before decryption %s", new String(inputBytes));
+ try {
+ //
+ FileInputStream inputStream = openFileInput(filename);
+ byte[] inputBytes = new byte[inputStream.available()];
+ inputStream.read(inputBytes);
+ Timber.i("before decryption %s", new String(inputBytes));
- byte[] decryptedStuff = CryptographicHelper.decrypt(inputBytes, keyAlias);
- encDecTextView.setText(new String(decryptedStuff));
- Timber.i("decrypted content %s", new String(decryptedStuff));
+ byte[] decryptedStuff = CryptographicHelper.decrypt(inputBytes, keyAlias);
+ encDecTextView.setText(new String(decryptedStuff));
+ Timber.i("decrypted content %s", new String(decryptedStuff));
- FileOutputStream fileOutputStream = openFileOutput(filename, Context.MODE_PRIVATE);
- fileOutputStream.write((decryptedStuff));
- fileOutputStream.flush();
+ FileOutputStream fileOutputStream = openFileOutput(filename, Context.MODE_PRIVATE);
+ fileOutputStream.write((decryptedStuff));
+ fileOutputStream.flush();
- } catch (IOException e) {
- e.printStackTrace();
- // Error occurred when opening raw file for reading.
- }
+ } catch (IOException e) {
+ e.printStackTrace();
+ // Error occurred when opening raw file for reading.
+ }
}
@@ -258,4 +263,22 @@ protected void onDestroy() {
super.onDestroy();
cryptographicHelper = null;
}
+
+ @Override
+ public void performDatabaseDownload() {
+ if (PermissionUtils.isPermissionGranted(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, PermissionUtils.WRITE_EXTERNAL_STORAGE_REQUEST_CODE)) {
+ try {
+ AppHealthUtils.triggerDBCopying(this);
+ } catch (SecurityException e) {
+ Utils.showToast(this, this.getString(org.smartregister.R.string.permission_write_external_storage_rationale));
+ }
+ }
+ }
+
+ @Override
+ public void showSyncStats() {
+ DrishtiApplication.getInstance().setPassword("123".getBytes());
+ Intent statsActivityIntent = new Intent(this, StatsActivity.class);
+ this.startActivity(statsActivityIntent);
+ }
}