use of com.jakdor.labday.rx.RxResponse in project LabDayApp by jakdor.
the class LocalDbHandler method getAppDataFromDb.
/**
* Creates {@link RxResponse<AppData>} from local db zipped responses
* @return RxResponse<AppData>
*/
public Observable<RxResponse<AppData>> getAppDataFromDb() {
return Observable.zip(EventDao.getAllEvents(db), MapOtherDao.getMapOthers(db), PathDao.getAllPaths(db), TimetableDao.getAllTimetables(db), SpeakerDao.getAllSpeakers(db), ((events, mapOthers, paths, timetables, speakers) -> {
AppData appData = new AppData(events, mapOthers, paths, timetables, speakers);
Timber.i("Retrieved AppData from local db");
return RxResponse.successDb(appData);
})).onErrorReturn(RxResponse::error);
}
use of com.jakdor.labday.rx.RxResponse in project LabDayApp by jakdor.
the class LocalDbIntegrationTests method integrationTestSaveAndLoad.
/**
* Save and load {@link com.jakdor.labday.common.model.AppData} to local db
*/
@Test
public void integrationTestSaveAndLoad() throws Exception {
Gson gson = new Gson();
AppData appData = gson.fromJson(readAssetFile(InstrumentationRegistry.getInstrumentation().getContext(), "api/app_data.json"), AppData.class);
localDbHandler.pushAppDataToDb(appData);
TestObserver<RxResponse<AppData>> testObserver = localDbHandler.getAppDataFromDb().test();
testObserver.assertSubscribed();
testObserver.awaitCount(1);
testObserver.assertNoErrors();
testObserver.assertValue(appDataRxResponse -> {
Assert.assertEquals(RxStatus.SUCCESS_DB, appDataRxResponse.status);
Assert.assertNotNull(appDataRxResponse.data);
Assert.assertNull(appDataRxResponse.error);
Assert.assertEquals(appData, appDataRxResponse.data);
Assert.assertEquals(appData.hashCode(), appDataRxResponse.data.hashCode());
Assert.assertNotNull(appDataRxResponse.data.getEvents());
Assert.assertNotNull(appDataRxResponse.data.getMapOthers());
Assert.assertNotNull(appDataRxResponse.data.getPaths());
Assert.assertNotNull(appDataRxResponse.data.getSpeakers());
Assert.assertNotNull(appDataRxResponse.data.getTimetables());
return true;
});
testObserver.onComplete();
}
use of com.jakdor.labday.rx.RxResponse in project LabDayApp by jakdor.
the class LocalDbIntegrationTests method integrationTestSaveAndLoad.
/**
* Save and load {@link com.jakdor.labday.common.model.AppData} to local db
*/
@Test
public void integrationTestSaveAndLoad() throws Exception {
Gson gson = new Gson();
AppData appData = gson.fromJson(readFile(appDataJsonPath), AppData.class);
localDbHandler.pushAppDataToDb(appData);
TestObserver<RxResponse<AppData>> testObserver = localDbHandler.getAppDataFromDb().test();
testObserver.assertSubscribed();
testObserver.awaitCount(1);
testObserver.assertNoErrors();
testObserver.assertValue(appDataRxResponse -> {
Assert.assertEquals(RxStatus.SUCCESS_DB, appDataRxResponse.status);
Assert.assertNotNull(appDataRxResponse.data);
Assert.assertNull(appDataRxResponse.error);
Assert.assertEquals(appData, appDataRxResponse.data);
Assert.assertEquals(appData.hashCode(), appDataRxResponse.data.hashCode());
Assert.assertNotNull(appDataRxResponse.data.getEvents());
Assert.assertNotNull(appDataRxResponse.data.getMapOthers());
Assert.assertNotNull(appDataRxResponse.data.getPaths());
Assert.assertNotNull(appDataRxResponse.data.getSpeakers());
Assert.assertNotNull(appDataRxResponse.data.getTimetables());
return true;
});
testObserver.onComplete();
}
use of com.jakdor.labday.rx.RxResponse in project LabDayApp by jakdor.
the class ProjectRepositoryIntegrationTest method integrationUpdateTestScenario1.
/**
* {@link ProjectRepository} getUpdate() integration test scenario 1
* - local last update id doesn't match API id
* - get API last update id
* - get appData API response (successful)
* - check ProjectRepository after successful call
*/
@Test
public void integrationUpdateTestScenario1() throws Exception {
SharedPreferences sharedPreferences = targetContext.getSharedPreferences(targetContext.getString(R.string.pref_file_name), Context.MODE_PRIVATE);
sharedPreferences.edit().putString(targetContext.getString(R.string.pref_api_last_update_id), "0").commit();
Assert.assertEquals(projectRepository.getRepositoryState(), ProjectRepository.repositoryStates.INIT);
Assert.assertNull(projectRepository.getData());
projectRepository.setAccessToken(dummyToken);
Gson gson = new Gson();
AppData appData = gson.fromJson(readAssetFile(testContext, "api/app_data.json"), AppData.class);
TestObserver<RxResponse<AppData>> testObserver = projectRepository.getUpdate(dummyApiUrl, targetContext).subscribeOn(Schedulers.io()).doOnError(throwable -> Assert.fail()).test();
testObserver.assertSubscribed();
testObserver.awaitCount(1);
testObserver.assertNoErrors();
testObserver.assertValue(appDataRxResponse -> {
Assert.assertNotNull(appDataRxResponse);
Assert.assertNotNull(appDataRxResponse.data);
Assert.assertNull(appDataRxResponse.error);
Assert.assertEquals(RxStatus.SUCCESS, appDataRxResponse.status);
Assert.assertEquals(appData, appDataRxResponse.data);
Assert.assertEquals(appData.hashCode(), appDataRxResponse.data.hashCode());
Assert.assertEquals(projectRepository.getRepositoryState(), ProjectRepository.repositoryStates.READY);
Assert.assertNotNull(projectRepository.getData());
Assert.assertEquals(projectRepository.getData().data, appData);
LastUpdate expectedLastUpdate = gson.fromJson(readAssetFile(testContext, "api/last_update.json"), LastUpdate.class);
Assert.assertNotNull(expectedLastUpdate.getUpdatedAt());
Assert.assertEquals(new String(expectedLastUpdate.getUpdatedAt().toCharArray()), sharedPreferences.getString(targetContext.getString(R.string.pref_api_last_update_id), null));
return true;
});
testObserver.onComplete();
}
Aggregations