use of com.jakdor.labday.common.network.LabService in project LabDayApp by jakdor.
the class RetrofitAPICallsIntegrationTest method lastUpdateTest.
/**
* Tests API response to last_update call
*/
@Test
public void lastUpdateTest() throws Exception {
LabService labService = retrofitBuilder.createService(dummyApiUrl, LabService.class);
TestObserver<LastUpdate> testObserver = labService.getLastUpdate().test();
testObserver.assertSubscribed();
testObserver.awaitCount(1);
testObserver.assertNoErrors();
testObserver.assertValue(s -> {
assertNotNull(s);
assertNotNull(s.getUpdatedAt());
assertFalse(s.getUpdatedAt().isEmpty());
return true;
});
testObserver.onComplete();
}
use of com.jakdor.labday.common.network.LabService in project LabDayApp by jakdor.
the class RetrofitBuilderTest method createServiceWithInterceptor.
/**
* test RetrofitBuilder in isolation from AuthenticationInterceptor
*/
@Test
public void createServiceWithInterceptor() throws Exception {
Request request = new Request.Builder().header("Authorization", dummyToken).get().url(dummyApiUrl).build();
ResponseBody dummyResponse = new ResponseBody() {
@Override
public MediaType contentType() {
return null;
}
@Override
public long contentLength() {
return 0;
}
@Override
public BufferedSource source() {
return null;
}
};
when(authenticationInterceptor.intercept(any())).thenReturn(new Response.Builder().request(request).protocol(Protocol.HTTP_2).code(200).body(dummyResponse).message(message).build());
LabService labService = retrofitBuilder.createService(dummyApiUrl, LabService.class, dummyToken);
TestObserver<AppData> testObserver = labService.getAppData().test();
testObserver.assertSubscribed();
testObserver.onComplete();
InOrder order = inOrder(authenticationInterceptor);
order.verify(authenticationInterceptor, calls(1)).setAuthToken(dummyToken);
order.verify(authenticationInterceptor, calls(1)).intercept(any());
}
use of com.jakdor.labday.common.network.LabService in project LabDayApp by jakdor.
the class RetrofitAPICallsIntegrationTest method appDataTokenTest.
/**
* Tests response from AppData API call with token authorization
*/
@Test
public void appDataTokenTest() throws Exception {
Gson gson = new Gson();
AppData appData = gson.fromJson(readFile(appDataJsonPath), AppData.class);
LabService labService = retrofitBuilder.createService(dummyApiUrl, LabService.class, dummyToken);
TestObserver<AppData> testObserver = labService.getAppData().test();
testObserver.assertSubscribed();
testObserver.awaitCount(1);
testObserver.assertNoErrors();
testObserver.assertValue(appData1 -> {
assertEquals(appData, appData1);
assertEquals(appData.hashCode(), appData1.hashCode());
return true;
});
testObserver.onComplete();
}
use of com.jakdor.labday.common.network.LabService in project LabDayApp by jakdor.
the class RetrofitAPICallsIntegrationTest method loginTest.
/**
* Tests login API call
*/
@Test
public void loginTest() throws Exception {
LabService labService = retrofitBuilder.createService(dummyApiUrl, LabService.class);
TestObserver<AccessToken> testObserver = labService.getAccessToken(dummyLogin, dummyPassword).test();
testObserver.assertSubscribed();
testObserver.awaitCount(1);
testObserver.assertNoErrors();
testObserver.assertValue(accessToken1 -> {
assertNotNull(accessToken1);
assertNotNull(accessToken1.getAccessToken());
return true;
});
testObserver.onComplete();
}
Aggregations