@Test public void downloadCohort_shouldReturnDownloadErrorIfDownloadExceptionOccurs() throws CohortController.CohortDownloadException { when(muzimaApplication.getSharedPreferences(COHORT_PREFIX_PREF, android.content.Context.MODE_PRIVATE)).thenReturn(sharedPref); when(sharedPref.getStringSet(Constants.COHORT_PREFIX_PREF_KEY, new HashSet<String>())).thenReturn(new HashSet<String>()); doThrow(new CohortController.CohortDownloadException(null)).when(cohortController).downloadAllCohorts(null); assertThat(muzimaSyncService.downloadCohorts()[0], is(SyncStatusConstants.DOWNLOAD_ERROR)); }
public int[] downloadCohorts() { int[] result = new int[3]; try { List<Cohort> cohorts = downloadCohortsList(); List<Cohort> voidedCohorts = deleteVoidedCohorts(cohorts); cohorts.removeAll(voidedCohorts); cohortController.saveOrUpdateCohorts(cohorts); Log.i(getClass().getSimpleName(), "New cohorts are saved"); result[0] = SUCCESS; result[1] = cohorts.size(); result[2] = voidedCohorts.size(); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download cohorts", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } catch (CohortController.CohortSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save cohorts", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (CohortController.CohortDeleteException e) { Log.e(getClass().getSimpleName(), "Exception occurred while deleting voided cohorts", e); result[0] = SyncStatusConstants.DELETE_ERROR; return result; } return result; }
MuzimaSyncService { public int[] downloadCohorts() { int[] result = new int[3]; try { List<Cohort> cohorts = downloadCohortsList(); List<Cohort> voidedCohorts = deleteVoidedCohorts(cohorts); cohorts.removeAll(voidedCohorts); cohortController.saveOrUpdateCohorts(cohorts); Log.i(getClass().getSimpleName(), "New cohorts are saved"); result[0] = SUCCESS; result[1] = cohorts.size(); result[2] = voidedCohorts.size(); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download cohorts", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } catch (CohortController.CohortSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save cohorts", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (CohortController.CohortDeleteException e) { Log.e(getClass().getSimpleName(), "Exception occurred while deleting voided cohorts", e); result[0] = SyncStatusConstants.DELETE_ERROR; return result; } return result; } }
MuzimaSyncService { public int[] downloadCohorts() { int[] result = new int[3]; try { List<Cohort> cohorts = downloadCohortsList(); List<Cohort> voidedCohorts = deleteVoidedCohorts(cohorts); cohorts.removeAll(voidedCohorts); cohortController.saveOrUpdateCohorts(cohorts); Log.i(getClass().getSimpleName(), "New cohorts are saved"); result[0] = SUCCESS; result[1] = cohorts.size(); result[2] = voidedCohorts.size(); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download cohorts", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } catch (CohortController.CohortSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save cohorts", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (CohortController.CohortDeleteException e) { Log.e(getClass().getSimpleName(), "Exception occurred while deleting voided cohorts", e); result[0] = SyncStatusConstants.DELETE_ERROR; return result; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); }
MuzimaSyncService { public int[] downloadCohorts() { int[] result = new int[3]; try { List<Cohort> cohorts = downloadCohortsList(); List<Cohort> voidedCohorts = deleteVoidedCohorts(cohorts); cohorts.removeAll(voidedCohorts); cohortController.saveOrUpdateCohorts(cohorts); Log.i(getClass().getSimpleName(), "New cohorts are saved"); result[0] = SUCCESS; result[1] = cohorts.size(); result[2] = voidedCohorts.size(); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download cohorts", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } catch (CohortController.CohortSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save cohorts", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (CohortController.CohortDeleteException e) { Log.e(getClass().getSimpleName(), "Exception occurred while deleting voided cohorts", e); result[0] = SyncStatusConstants.DELETE_ERROR; return result; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); int authenticate(String[] credentials); int authenticate(String[] credentials, boolean isUpdatePasswordRequired); int[] downloadForms(); int[] downloadFormTemplatesAndRelatedMetadata(String[] formIds, boolean replaceExistingTemplates); int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates); int[] downloadLocations(String[] locationIds); int[] downloadProviders(String[] providerIds); int[] downloadConcepts(String[] conceptIds); int[] downloadCohorts(); int[] downloadCohorts(String[] cohortUuids); int[] downloadPatientsForCohortsWithUpdatesAvailable(); int[] downloadRemovedCohortMembershipData(String[] cohortUuids); int[] downloadPatientsForCohorts(String[] cohortUuids); int[] downloadPatients(String[] patientUUIDs); int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation); int[] downloadObservationsForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingObservations); int[] downloadEncountersForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingEncounters); int[] downloadEncountersForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingEncounters); int[] uploadAllCompletedForms(); void consolidatePatients(); List<FormData> getArchivedFormData(); int[] checkAndDeleteTemporaryDataForProcessedFormData(List<FormData> archivedFormData); List<String> getUuidsForAllPatientsFromLocalStorage(); List<Patient> updatePatientsNotPartOfCohorts(); int[] downloadNotifications(String receiverUuid); int[] downloadPatientReportHeaders(String patientUuid); int[] downloadAllPatientReportHeadersAndReports(); int[] downloadPatientReportsByUuid(String[] reportUuids); void downloadSetupConfigurations(); int[] downloadSetupConfigurationTemplate(String uuid); int[] downloadAndSaveUpdatedSetupConfigurationTemplate(String uuid); int[] updateSetupConfigurationTemplates(); int[] downloadSetting(String property); int[] downloadNewSettings(); void updateSettingsPreferences(List<MuzimaSetting> muzimaSettings); int[] downloadRelationshipsTypes(); int[] downloadRelationshipsForPatientsByPatientUUIDs(List<String> patientUuids); int[] downloadRelationshipsForPatientsByCohortUUIDs(String[] cohortUuids); String getDefaultLocation(); }
MuzimaSyncService { public int[] downloadCohorts() { int[] result = new int[3]; try { List<Cohort> cohorts = downloadCohortsList(); List<Cohort> voidedCohorts = deleteVoidedCohorts(cohorts); cohorts.removeAll(voidedCohorts); cohortController.saveOrUpdateCohorts(cohorts); Log.i(getClass().getSimpleName(), "New cohorts are saved"); result[0] = SUCCESS; result[1] = cohorts.size(); result[2] = voidedCohorts.size(); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception when trying to download cohorts", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; return result; } catch (CohortController.CohortSaveException e) { Log.e(getClass().getSimpleName(), "Exception when trying to save cohorts", e); result[0] = SyncStatusConstants.SAVE_ERROR; return result; } catch (CohortController.CohortDeleteException e) { Log.e(getClass().getSimpleName(), "Exception occurred while deleting voided cohorts", e); result[0] = SyncStatusConstants.DELETE_ERROR; return result; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); int authenticate(String[] credentials); int authenticate(String[] credentials, boolean isUpdatePasswordRequired); int[] downloadForms(); int[] downloadFormTemplatesAndRelatedMetadata(String[] formIds, boolean replaceExistingTemplates); int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates); int[] downloadLocations(String[] locationIds); int[] downloadProviders(String[] providerIds); int[] downloadConcepts(String[] conceptIds); int[] downloadCohorts(); int[] downloadCohorts(String[] cohortUuids); int[] downloadPatientsForCohortsWithUpdatesAvailable(); int[] downloadRemovedCohortMembershipData(String[] cohortUuids); int[] downloadPatientsForCohorts(String[] cohortUuids); int[] downloadPatients(String[] patientUUIDs); int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation); int[] downloadObservationsForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingObservations); int[] downloadEncountersForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingEncounters); int[] downloadEncountersForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingEncounters); int[] uploadAllCompletedForms(); void consolidatePatients(); List<FormData> getArchivedFormData(); int[] checkAndDeleteTemporaryDataForProcessedFormData(List<FormData> archivedFormData); List<String> getUuidsForAllPatientsFromLocalStorage(); List<Patient> updatePatientsNotPartOfCohorts(); int[] downloadNotifications(String receiverUuid); int[] downloadPatientReportHeaders(String patientUuid); int[] downloadAllPatientReportHeadersAndReports(); int[] downloadPatientReportsByUuid(String[] reportUuids); void downloadSetupConfigurations(); int[] downloadSetupConfigurationTemplate(String uuid); int[] downloadAndSaveUpdatedSetupConfigurationTemplate(String uuid); int[] updateSetupConfigurationTemplates(); int[] downloadSetting(String property); int[] downloadNewSettings(); void updateSettingsPreferences(List<MuzimaSetting> muzimaSettings); int[] downloadRelationshipsTypes(); int[] downloadRelationshipsForPatientsByPatientUUIDs(List<String> patientUuids); int[] downloadRelationshipsForPatientsByCohortUUIDs(String[] cohortUuids); String getDefaultLocation();  }