Search in sources :

Example 11 with Response

use of retrofit.client.Response in project android-test-demo by abdyer.

the class MockApiService method getEvents.

@Override
public void getEvents(@Path("organization") String organization, Callback<Events> callback) {
    try {
        String json = readFileFromAssets(EVENTS_RESPONSE_FILE);
        Response response = getMockResponse(HTTP_OK_STATUS, json);
        Events events = getMockResponseData(json, Events.class);
        callback.success(events, response);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Response(retrofit.client.Response) IOException(java.io.IOException)

Example 12 with Response

use of retrofit.client.Response in project cw-omnibus by commonsguy.

the class SOTests method fetchQuestions.

@Test(timeout = 30000)
public void fetchQuestions() throws InterruptedException {
    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("https://api.stackexchange.com").build();
    StackOverflowInterface so = restAdapter.create(StackOverflowInterface.class);
    so.questions("android", new Callback<SOQuestions>() {

        @Override
        public void success(SOQuestions soQuestions, Response response) {
            questions = soQuestions;
            responseLatch.countDown();
        }

        @Override
        public void failure(RetrofitError error) {
            responseLatch.countDown();
        }
    });
    responseLatch.await();
    Assert.assertNotNull(questions);
    Assert.assertEquals(30, questions.items.size());
    for (Item item : questions.items) {
        Assert.assertNotNull(item.title);
        Assert.assertNotNull(item.link);
    }
}
Also used : Response(retrofit.client.Response) RestAdapter(retrofit.RestAdapter) RetrofitError(retrofit.RetrofitError) Test(org.junit.Test)

Example 13 with Response

use of retrofit.client.Response in project Varis-Android by dkhmelenko.

the class TestBuildDetailsPresenter method testStartLoadingLogFailed.

@Test
public void testStartLoadingLogFailed() {
    final long jobId = 1L;
    final int errorCode = 401;
    final String errorMsg = "error";
    TaskError error = spy(new TaskError(errorCode, errorMsg));
    Response response = new Response("url", 200, "", Collections.<Header>emptyList(), null);
    error.setResponse(response);
    TaskException exception = spy(new TaskException(error));
    when(mRawClient.getApiService().getLog(String.valueOf(jobId))).thenThrow(exception);
    mBuildsDetailsPresenter.startLoadingLog(jobId);
    int loadLogInvocations = BuildsDetailsPresenter.LOAD_LOG_MAX_ATTEMPT + 1;
    verify(mTaskManager, times(loadLogInvocations)).getLogUrl(jobId);
    verify(mBuildDetailsView).showLoadingError(error.getMessage());
    verify(mBuildDetailsView).showLogError();
}
Also used : Response(retrofit.client.Response) TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 14 with Response

use of retrofit.client.Response in project Varis-Android by dkhmelenko.

the class TestBuildDetailsPresenter method testStartLoadingDataFailed.

@Test
public void testStartLoadingDataFailed() {
    final long buildId = 1L;
    final String slug = "test";
    final int errorCode = 401;
    final String errorMsg = "error";
    TaskError error = spy(new TaskError(errorCode, errorMsg));
    Response response = new Response("url", 200, "", Collections.<Header>emptyList(), null);
    error.setResponse(response);
    TaskException exception = spy(new TaskException(error));
    when(mTravisRestClient.getApiService().getBuild(slug, buildId)).thenThrow(exception);
    mBuildsDetailsPresenter.startLoadingData(null, slug, buildId);
    verify(mTaskManager).getBuildDetails(slug, buildId);
    verify(mBuildDetailsView).showProgress();
    verify(mBuildDetailsView).hideProgress();
    verify(mBuildDetailsView).updateBuildDetails(null);
    verify(mBuildDetailsView).showLoadingError(error.getMessage());
}
Also used : Response(retrofit.client.Response) TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 15 with Response

use of retrofit.client.Response in project Varis-Android by dkhmelenko.

the class TestAuthPresenter method testTwoFactorAuth.

@Test
public void testTwoFactorAuth() {
    final String login = "login";
    final String password = "password";
    String auth = EncryptionUtils.generateBasicAuthorization(login, password);
    // rules for throwing a request for 2-factor auth
    Header header = new Header(GithubApiService.TWO_FACTOR_HEADER, "required");
    List<Header> headers = new ArrayList<>();
    headers.add(header);
    Response response = new Response("https://github.com", 401, "twoFactorAuth", headers, null);
    TaskError taskError = new TaskError(401, "twoFactorAuth");
    taskError.setResponse(response);
    TaskException exception = new TaskException(taskError);
    when(mGitHubRestClient.getApiService().createNewAuthorization(eq(auth), any(AuthorizationRequest.class))).thenThrow(exception);
    mAuthPresenter.login(login, password);
    verify(mTaskManager).createNewAuthorization(eq(auth), any(AuthorizationRequest.class));
    verify(mAuthView).showTwoFactorAuth();
    // rules for handling 2-factor auth continuation
    final String securityCode = "123456";
    final String gitHubToken = "gitHubToken";
    Authorization authorization = new Authorization();
    authorization.setToken(gitHubToken);
    authorization.setId(1L);
    when(mGitHubRestClient.getApiService().createNewAuthorization(eq(auth), eq(securityCode), any(AuthorizationRequest.class))).thenReturn(authorization);
    final String accessToken = "token";
    AccessTokenRequest request = new AccessTokenRequest();
    request.setGithubToken(gitHubToken);
    AccessToken token = new AccessToken();
    token.setAccessToken(accessToken);
    when(mTravisRestClient.getApiService().auth(request)).thenReturn(token);
    when(mGitHubRestClient.getApiService().deleteAuthorization(auth, String.valueOf(authorization.getId()))).thenReturn(null);
    mAuthPresenter.twoFactorAuth(securityCode);
    verify(mTaskManager).startAuth(gitHubToken);
    verify(mTaskManager).deleteAuthorization(auth, String.valueOf(authorization.getId()), securityCode);
    verify(mAuthView, times(2)).hideProgress();
    verify(mAuthView).finishView();
}
Also used : Response(retrofit.client.Response) Authorization(com.khmelenko.lab.varis.network.response.Authorization) AuthorizationRequest(com.khmelenko.lab.varis.network.request.AuthorizationRequest) Header(retrofit.client.Header) TaskException(com.khmelenko.lab.varis.task.TaskException) AccessToken(com.khmelenko.lab.varis.network.response.AccessToken) ArrayList(java.util.ArrayList) TaskError(com.khmelenko.lab.varis.task.TaskError) AccessTokenRequest(com.khmelenko.lab.varis.network.request.AccessTokenRequest) Test(org.junit.Test)

Aggregations

Response (retrofit.client.Response)15 Test (org.junit.Test)7 RetrofitError (retrofit.RetrofitError)7 TaskError (com.khmelenko.lab.varis.task.TaskError)3 TaskException (com.khmelenko.lab.varis.task.TaskException)3 ArrayList (java.util.ArrayList)3 Callback (retrofit.Callback)3 Location (android.location.Location)2 RestAdapter (retrofit.RestAdapter)2 Header (retrofit.client.Header)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 MenuItem (android.view.MenuItem)1 AsynchronousApi (com.kdubb.retrofitexamples.api.AsynchronousApi)1 InterestingApi (com.kdubb.retrofitexamples.api.InterestingApi)1 AccessTokenRequest (com.khmelenko.lab.varis.network.request.AccessTokenRequest)1 AuthorizationRequest (com.khmelenko.lab.varis.network.request.AuthorizationRequest)1 AccessToken (com.khmelenko.lab.varis.network.response.AccessToken)1 Authorization (com.khmelenko.lab.varis.network.response.Authorization)1 Build (com.khmelenko.lab.varis.network.response.Build)1 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)1