use of com.khmelenko.lab.varis.network.response.BuildDetails in project Varis-Android by dkhmelenko.
the class TestBuildDetailsPresenter method testStartLoadingDataManyJobs.
@Test
public void testStartLoadingDataManyJobs() {
final long buildId = 1L;
final String slug = "test";
final Build build = new Build();
final Commit commit = new Commit();
final List<Job> jobs = new ArrayList<>();
final Job job1 = new Job();
jobs.add(job1);
final Job job2 = new Job();
jobs.add(job2);
BuildDetails buildDetails = new BuildDetails();
buildDetails.setBuild(build);
buildDetails.setCommit(commit);
buildDetails.setJobs(jobs);
when(mTravisRestClient.getApiService().getBuild(slug, buildId)).thenReturn(buildDetails);
mBuildsDetailsPresenter.startLoadingData(null, slug, buildId);
verify(mTaskManager).getBuildDetails(slug, buildId);
verify(mBuildDetailsView).showProgress();
verify(mBuildDetailsView).hideProgress();
verify(mBuildDetailsView).updateBuildDetails(buildDetails);
verify(mBuildDetailsView).showBuildJobs(jobs);
}
use of com.khmelenko.lab.varis.network.response.BuildDetails in project Varis-Android by dkhmelenko.
the class TestBuildDetailsPresenter method testStartLoadingDataSingleJob.
@Test
public void testStartLoadingDataSingleJob() {
final long buildId = 1L;
final String slug = "test";
final Build build = new Build();
final Commit commit = new Commit();
final List<Job> jobs = new ArrayList<>();
final Job job = new Job();
jobs.add(job);
BuildDetails buildDetails = new BuildDetails();
buildDetails.setBuild(build);
buildDetails.setCommit(commit);
buildDetails.setJobs(jobs);
final String expectedUrl = "https://sample.org";
Response response = new Response(expectedUrl, 200, "", Collections.<Header>emptyList(), null);
final String accessToken = "test";
final String authToken = "token " + accessToken;
AppSettings.putAccessToken("test");
when(mRawClient.getApiService().getLog(authToken, String.valueOf(job.getId()))).thenReturn(response);
when(mTravisRestClient.getApiService().getBuild(slug, buildId)).thenReturn(buildDetails);
mBuildsDetailsPresenter.startLoadingData(null, slug, buildId);
verify(mTaskManager).getBuildDetails(slug, buildId);
verify(mBuildDetailsView).showProgress();
verify(mBuildDetailsView).hideProgress();
verify(mBuildDetailsView).updateBuildDetails(buildDetails);
verify(mBuildDetailsView).showBuildLogs();
verify(mBuildDetailsView).showAdditionalActionsForBuild(buildDetails);
}
use of com.khmelenko.lab.varis.network.response.BuildDetails in project Varis-Android by dkhmelenko.
the class BuildsDetailsPresenter method restartBuild.
/**
* Restarts build process
*/
public void restartBuild() {
RequestBody emptyBody = RequestBody.create(MediaType.parse("application/json"), "");
Disposable subscription = mTravisRestClient.getApiService().restartBuild(mBuildId, emptyBody).onErrorReturn(throwable -> new Object()).flatMap(new Function<Object, SingleSource<BuildDetails>>() {
@Override
public SingleSource<BuildDetails> apply(@NonNull Object o) throws Exception {
return mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((buildDetails, throwable) -> {
if (throwable == null) {
handleBuildDetails(buildDetails);
} else {
handleLoadingFailed(throwable);
}
});
mSubscriptions.add(subscription);
}
use of com.khmelenko.lab.varis.network.response.BuildDetails in project Varis-Android by dkhmelenko.
the class BuildsDetailsPresenter method startLoadingData.
/**
* Starts loading data
*
* @param intentUrl Intent URL
* @param repoSlug Repository slug
* @param buildId Build ID
*/
public void startLoadingData(String intentUrl, String repoSlug, long buildId) {
mRepoSlug = repoSlug;
mBuildId = buildId;
Single<BuildDetails> buildDetailsSingle;
if (!TextUtils.isEmpty(intentUrl)) {
buildDetailsSingle = mRawClient.singleRequest(intentUrl).doOnSuccess(response -> {
String redirectUrl = intentUrl;
if (response.isRedirect()) {
redirectUrl = response.header("Location", "");
}
parseIntentUrl(redirectUrl);
}).flatMap(new Function<okhttp3.Response, SingleSource<BuildDetails>>() {
@Override
public SingleSource<BuildDetails> apply(@NonNull okhttp3.Response response) throws Exception {
return mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
}
});
} else {
buildDetailsSingle = mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
}
Disposable subscription = buildDetailsSingle.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((buildDetails, throwable) -> {
if (throwable == null) {
handleBuildDetails(buildDetails);
} else {
handleLoadingFailed(throwable);
}
});
mSubscriptions.add(subscription);
getView().showProgress();
}
use of com.khmelenko.lab.varis.network.response.BuildDetails in project Varis-Android by dkhmelenko.
the class BuildsDetailsPresenter method cancelBuild.
/**
* Cancels build process
*/
public void cancelBuild() {
RequestBody emptyBody = RequestBody.create(MediaType.parse("application/json"), "");
Disposable subscription = mTravisRestClient.getApiService().cancelBuild(mBuildId, emptyBody).onErrorReturn(throwable -> new Object()).flatMap(new Function<Object, SingleSource<BuildDetails>>() {
@Override
public SingleSource<BuildDetails> apply(@NonNull Object o) throws Exception {
return mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((buildDetails, throwable) -> {
if (throwable == null) {
handleBuildDetails(buildDetails);
} else {
handleLoadingFailed(throwable);
}
});
mSubscriptions.add(subscription);
}
Aggregations