Search in sources :

Example 11 with TaskError

use of com.khmelenko.lab.varis.task.TaskError in project Varis-Android by dkhmelenko.

the class TestRepoDetailsPresenter method testLoadBuildsHistoryFailed.

@Test
public void testLoadBuildsHistoryFailed() {
    final String slug = "test";
    final int errorCode = 401;
    final String errorMsg = "error";
    TaskError error = spy(new TaskError(errorCode, errorMsg));
    TaskException exception = spy(new TaskException(error));
    when(mTravisRestClient.getApiService().getBuilds(slug)).thenThrow(exception);
    mRepoDetailsPresenter.setRepoSlug(slug);
    mRepoDetailsPresenter.loadBuildsHistory();
    verify(mTaskManager).getBuildHistory(slug);
    verify(mRepoDetailsView).showBuildHistoryLoadingError(error.getMessage());
}
Also used : TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 12 with TaskError

use of com.khmelenko.lab.varis.task.TaskError 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

TaskError (com.khmelenko.lab.varis.task.TaskError)12 Test (org.junit.Test)12 TaskException (com.khmelenko.lab.varis.task.TaskException)11 AuthorizationRequest (com.khmelenko.lab.varis.network.request.AuthorizationRequest)3 Response (retrofit.client.Response)3 AccessTokenRequest (com.khmelenko.lab.varis.network.request.AccessTokenRequest)2 Authorization (com.khmelenko.lab.varis.network.response.Authorization)2 TypedOutput (retrofit.mime.TypedOutput)2 AccessToken (com.khmelenko.lab.varis.network.response.AccessToken)1 Request (com.squareup.okhttp.Request)1 ArrayList (java.util.ArrayList)1 Header (retrofit.client.Header)1