@Test public void shouldReturnFailureIfDownloadFails() throws PatientController.PatientDownloadException, PatientController.PatientSaveException { Patient patient1 = patient("patientUUID1"); String[] patientUUIDs = new String[]{"patientUUID1"}; when(patientController.downloadPatientByUUID("patientUUID1")).thenReturn(patient1); doThrow(new PatientController.PatientSaveException(new Throwable())).when(patientController).savePatients(Collections.singletonList(patient1)); int[] result = muzimaSyncService.downloadPatients(patientUUIDs); assertThat(result[0], is(SyncStatusConstants.DOWNLOAD_ERROR)); assertThat(result[1], is(0)); verify(patientController).savePatients(Collections.singletonList(patient1)); }
public int[] downloadPatients(String[] patientUUIDs) { int[] result = new int[2]; List<Patient> downloadedPatients; try { downloadedPatients = downloadPatientsByUUID(patientUUIDs); patientController.savePatients(downloadedPatients); Log.e(getClass().getSimpleName(), "DOWNLOADED PATIENTS."); result[0] = SUCCESS; result[1] = downloadedPatients.size(); } catch (PatientController.PatientDownloadException e) { Log.e(getClass().getSimpleName(), "Error while downloading patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Error while saving patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } return result; }
MuzimaSyncService { public int[] downloadPatients(String[] patientUUIDs) { int[] result = new int[2]; List<Patient> downloadedPatients; try { downloadedPatients = downloadPatientsByUUID(patientUUIDs); patientController.savePatients(downloadedPatients); Log.e(getClass().getSimpleName(), "DOWNLOADED PATIENTS."); result[0] = SUCCESS; result[1] = downloadedPatients.size(); } catch (PatientController.PatientDownloadException e) { Log.e(getClass().getSimpleName(), "Error while downloading patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Error while saving patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } return result; } }
MuzimaSyncService { public int[] downloadPatients(String[] patientUUIDs) { int[] result = new int[2]; List<Patient> downloadedPatients; try { downloadedPatients = downloadPatientsByUUID(patientUUIDs); patientController.savePatients(downloadedPatients); Log.e(getClass().getSimpleName(), "DOWNLOADED PATIENTS."); result[0] = SUCCESS; result[1] = downloadedPatients.size(); } catch (PatientController.PatientDownloadException e) { Log.e(getClass().getSimpleName(), "Error while downloading patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Error while saving patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); }
MuzimaSyncService { public int[] downloadPatients(String[] patientUUIDs) { int[] result = new int[2]; List<Patient> downloadedPatients; try { downloadedPatients = downloadPatientsByUUID(patientUUIDs); patientController.savePatients(downloadedPatients); Log.e(getClass().getSimpleName(), "DOWNLOADED PATIENTS."); result[0] = SUCCESS; result[1] = downloadedPatients.size(); } catch (PatientController.PatientDownloadException e) { Log.e(getClass().getSimpleName(), "Error while downloading patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Error while saving patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } 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[] downloadPatients(String[] patientUUIDs) { int[] result = new int[2]; List<Patient> downloadedPatients; try { downloadedPatients = downloadPatientsByUUID(patientUUIDs); patientController.savePatients(downloadedPatients); Log.e(getClass().getSimpleName(), "DOWNLOADED PATIENTS."); result[0] = SUCCESS; result[1] = downloadedPatients.size(); } catch (PatientController.PatientDownloadException e) { Log.e(getClass().getSimpleName(), "Error while downloading patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Error while saving patients.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } 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();  }