Search in sources :

Example 1 with TaskException

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

the class TestAuthPresenter method testLoginAuthFailed.

@Test
public void testLoginAuthFailed() {
    final String login = "login";
    final String password = "password";
    String auth = EncryptionUtils.generateBasicAuthorization(login, password);
    final String gitHubToken = "gitHubToken";
    Authorization authorization = new Authorization();
    authorization.setToken(gitHubToken);
    authorization.setId(1L);
    when(mGitHubRestClient.getApiService().createNewAuthorization(eq(auth), any(AuthorizationRequest.class))).thenReturn(authorization);
    AccessTokenRequest request = new AccessTokenRequest();
    request.setGithubToken(gitHubToken);
    TaskError taskError = new TaskError(500, "error");
    TaskException exception = new TaskException(taskError);
    when(mTravisRestClient.getApiService().auth(request)).thenThrow(exception);
    mAuthPresenter.login(login, password);
    verify(mTaskManager).createNewAuthorization(eq(auth), any(AuthorizationRequest.class));
    verify(mTaskManager).startAuth(gitHubToken);
    verify(mAuthView).hideProgress();
    verify(mAuthView).showErrorMessage(taskError.getMessage());
}
Also used : Authorization(com.khmelenko.lab.varis.network.response.Authorization) AuthorizationRequest(com.khmelenko.lab.varis.network.request.AuthorizationRequest) TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) AccessTokenRequest(com.khmelenko.lab.varis.network.request.AccessTokenRequest) Test(org.junit.Test)

Example 2 with TaskException

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

the class TestAuthPresenter method testLoginGitHubAuthFailed.

@Test
public void testLoginGitHubAuthFailed() {
    final String login = "login";
    final String password = "password";
    String auth = EncryptionUtils.generateBasicAuthorization(login, password);
    TaskError taskError = new TaskError(500, "error");
    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).hideProgress();
    verify(mAuthView).showErrorMessage(taskError.getMessage());
}
Also used : AuthorizationRequest(com.khmelenko.lab.varis.network.request.AuthorizationRequest) TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 3 with TaskException

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

the class TestRepoDetailsPresenter method testLoadBranchesFailed.

@Test
public void testLoadBranchesFailed() {
    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().getBranches(slug)).thenThrow(exception);
    mRepoDetailsPresenter.setRepoSlug(slug);
    mRepoDetailsPresenter.loadBranches();
    verify(mTaskManager).getBranches(slug);
    verify(mRepoDetailsView).showBranchesLoadingError(error.getMessage());
}
Also used : TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 4 with TaskException

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

the class TestSearchResultsPresenter method testStartRepoSearchFailed.

@Test
public void testStartRepoSearchFailed() {
    final String searchQuery = "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().getRepos(searchQuery)).thenThrow(exception);
    mSearchResultsPresenter.startRepoSearch(searchQuery);
    verify(mTaskManager).findRepos(searchQuery);
    verify(mSearchResultsView).hideProgress();
    verify(mSearchResultsView).showLoadingError(eq(error.getMessage()));
}
Also used : TaskException(com.khmelenko.lab.varis.task.TaskException) TaskError(com.khmelenko.lab.varis.task.TaskError) Test(org.junit.Test)

Example 5 with TaskException

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

Aggregations

TaskError (com.khmelenko.lab.varis.task.TaskError)11 TaskException (com.khmelenko.lab.varis.task.TaskException)11 Test (org.junit.Test)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 ArrayList (java.util.ArrayList)1 Header (retrofit.client.Header)1