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