Search in sources :

Example 1 with BuildDetails

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);
}
Also used : Commit(com.khmelenko.lab.varis.network.response.Commit) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) Build(com.khmelenko.lab.varis.network.response.Build) ArrayList(java.util.ArrayList) Job(com.khmelenko.lab.varis.network.response.Job) Test(org.junit.Test)

Example 2 with BuildDetails

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);
}
Also used : Response(retrofit.client.Response) Commit(com.khmelenko.lab.varis.network.response.Commit) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) Build(com.khmelenko.lab.varis.network.response.Build) ArrayList(java.util.ArrayList) Job(com.khmelenko.lab.varis.network.response.Job) Test(org.junit.Test)

Example 3 with 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);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) NonNull(io.reactivex.annotations.NonNull) RequestBody(okhttp3.RequestBody)

Example 4 with BuildDetails

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();
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) NonNull(io.reactivex.annotations.NonNull)

Example 5 with BuildDetails

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);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) NonNull(io.reactivex.annotations.NonNull) RequestBody(okhttp3.RequestBody)

Aggregations

BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)5 NonNull (io.reactivex.annotations.NonNull)3 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)3 Disposable (io.reactivex.disposables.Disposable)3 Function (io.reactivex.functions.Function)3 Build (com.khmelenko.lab.varis.network.response.Build)2 Commit (com.khmelenko.lab.varis.network.response.Commit)2 Job (com.khmelenko.lab.varis.network.response.Job)2 ArrayList (java.util.ArrayList)2 RequestBody (okhttp3.RequestBody)2 Test (org.junit.Test)2 Response (retrofit.client.Response)1