Search in sources :

Example 1 with BuildCancelRequest

use of com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest in project TeamCityApp by vase4kin.

the class CancelBuildTest method testUserCanNotReAddBuildToQueueWhenRemovingItFromQueue.

@Test
public void testUserCanNotReAddBuildToQueueWhenRemovingItFromQueue() {
    // Prepare mocks
    when(mTeamCityService.build(anyString())).thenReturn(Observable.just(mBuild)).thenReturn(Observable.just(Mocks.queuedBuild2()));
    when(mTeamCityService.cancelBuild(anyString(), Matchers.any(BuildCancelRequest.class))).thenReturn(Observable.just(Mocks.queuedBuild2()));
    // Prepare intent
    // <! ---------------------------------------------------------------------- !>
    // Passing build object to activity, had to create it for real, Can't pass mock object as serializable in bundle :(
    // <! ---------------------------------------------------------------------- !>
    Intent intent = new Intent();
    Bundle b = new Bundle();
    b.putSerializable(BundleExtractorValues.BUILD, Mocks.queuedBuild1());
    b.putString(BundleExtractorValues.NAME, NAME);
    intent.putExtras(b);
    // Start activity
    mActivityRule.launchActivity(intent);
    // Opening context menu
    openContextualActionModeOverflowMenu();
    // Click on context menu option
    onView(withText(R.string.text_menu_remove_build_from_queue)).perform(click());
    // Check re-add text is displayed and click on it
    onView(withText(R.string.text_re_add_build)).check(doesNotExist());
    // Click on cancel build
    onView(withText(R.string.text_remove_from_queue_button)).perform(click());
    // Check snack bar is displayed
    onView(withText(R.string.text_build_is_removed_from_queue)).check(matches(isDisplayed()));
    // Checking Result was changed
    onView(withRecyclerView(R.id.overview_recycler_view).atPositionOnView(0, R.id.itemTitle)).check(matches(withText("This build will not start because there are no compatible agents which can run it")));
    // Verify build wasn't re-added
    verify(mTeamCityService).cancelBuild(anyString(), mBuildCancelRequestArgumentCaptor.capture());
    BuildCancelRequest buildCancelRequest = mBuildCancelRequestArgumentCaptor.getValue();
    assertThat(buildCancelRequest.isReaddIntoQueue(), is(equalTo(false)));
}
Also used : BuildCancelRequest(com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest) Bundle(android.os.Bundle) Intent(android.content.Intent) Test(org.junit.Test)

Example 2 with BuildCancelRequest

use of com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest in project TeamCityApp by vase4kin.

the class BuildDetailsInteractorImpl method cancelBuild.

/**
 * {@inheritDoc}
 */
@Override
public void cancelBuild(final LoadingListenerWithForbiddenSupport<Build> loadingListener, boolean isReAddToTheQueue) {
    mSubscription.clear();
    Subscription queueBuildSubscription = mRepository.cancelBuild(mValueExtractor.getBuildDetails().getHref(), new BuildCancelRequest(isReAddToTheQueue)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Build>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            if (e instanceof HttpException) {
                HttpException exception = (HttpException) e;
                if (exception.code() == CODE_FORBIDDEN) {
                    loadingListener.onForbiddenError();
                } else {
                    loadingListener.onFail(e.getMessage());
                }
            } else {
                loadingListener.onFail(e.getMessage());
            }
        }

        @Override
        public void onNext(Build build) {
            loadingListener.onSuccess(build);
        }
    });
    mSubscription.add(queueBuildSubscription);
}
Also used : BuildCancelRequest(com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest) Build(com.github.vase4kin.teamcityapp.buildlist.api.Build) HttpException(retrofit2.adapter.rxjava.HttpException) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 3 with BuildCancelRequest

use of com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest in project TeamCityApp by vase4kin.

the class CancelBuildTest method testUserCanReAddBuildWhenStoppingIt.

@Test
public void testUserCanReAddBuildWhenStoppingIt() {
    // Prepare mocks
    when(mTeamCityService.build(anyString())).thenReturn(Observable.just(Mocks.runningBuild())).thenReturn(Observable.just(Mocks.failedBuild()));
    when(mTeamCityService.cancelBuild(anyString(), Matchers.any(BuildCancelRequest.class))).thenReturn(Observable.just(Mocks.failedBuild()));
    // Prepare intent
    // <! ---------------------------------------------------------------------- !>
    // Passing build object to activity, had to create it for real, Can't pass mock object as serializable in bundle :(
    // <! ---------------------------------------------------------------------- !>
    Intent intent = new Intent();
    Bundle b = new Bundle();
    b.putSerializable(BundleExtractorValues.BUILD, Mocks.runningBuild());
    b.putString(BundleExtractorValues.NAME, NAME);
    intent.putExtras(b);
    // Start activity
    mActivityRule.launchActivity(intent);
    // Opening context menu
    openContextualActionModeOverflowMenu();
    // Click on context menu option
    onView(withText(R.string.text_menu_stop_build)).perform(click());
    // Check re-add text is displayed and click on it
    onView(withText(R.string.text_re_add_build)).check(matches(isDisplayed())).perform(click());
    // Click on cancel build
    onView(withText(R.string.text_stop_button)).perform(click());
    // Check snack bar is displayed
    onView(withText(R.string.text_build_is_stopped)).check(matches(isDisplayed()));
    // Checking Result was changed
    onView(withRecyclerView(R.id.overview_recycler_view).atPositionOnView(0, R.id.itemTitle)).check(matches(withText("Error with smth")));
    // Verify build was re-added
    verify(mTeamCityService).cancelBuild(anyString(), mBuildCancelRequestArgumentCaptor.capture());
    BuildCancelRequest buildCancelRequest = mBuildCancelRequestArgumentCaptor.getValue();
    assertThat(buildCancelRequest.isReaddIntoQueue(), is(equalTo(true)));
}
Also used : BuildCancelRequest(com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest) Bundle(android.os.Bundle) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

BuildCancelRequest (com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Test (org.junit.Test)2 Build (com.github.vase4kin.teamcityapp.buildlist.api.Build)1 HttpException (retrofit2.adapter.rxjava.HttpException)1 Subscription (rx.Subscription)1 CompositeSubscription (rx.subscriptions.CompositeSubscription)1