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();
}
}
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);
}
}
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();
}
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());
}
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();
}
Aggregations