Search in sources :

Example 1 with LabService

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();
}
Also used : LabService(com.jakdor.labday.common.network.LabService) LastUpdate(com.jakdor.labday.common.model.LastUpdate) Test(org.junit.Test)

Example 2 with LabService

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());
}
Also used : Response(okhttp3.Response) LabService(com.jakdor.labday.common.network.LabService) InOrder(org.mockito.InOrder) AppData(com.jakdor.labday.common.model.AppData) RetrofitBuilder(com.jakdor.labday.common.network.RetrofitBuilder) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 3 with LabService

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();
}
Also used : LabService(com.jakdor.labday.common.network.LabService) AppData(com.jakdor.labday.common.model.AppData) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 4 with LabService

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();
}
Also used : LabService(com.jakdor.labday.common.network.LabService) AccessToken(com.jakdor.labday.common.model.AccessToken) Test(org.junit.Test)

Aggregations

LabService (com.jakdor.labday.common.network.LabService)4 Test (org.junit.Test)4 AppData (com.jakdor.labday.common.model.AppData)2 Gson (com.google.gson.Gson)1 AccessToken (com.jakdor.labday.common.model.AccessToken)1 LastUpdate (com.jakdor.labday.common.model.LastUpdate)1 RetrofitBuilder (com.jakdor.labday.common.network.RetrofitBuilder)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 ResponseBody (okhttp3.ResponseBody)1 InOrder (org.mockito.InOrder)1