Search in sources :

Example 36 with HttpException

use of retrofit2.HttpException in project TeamCityApp by vase4kin.

the class RestartBuildTest method testUserCanRestartBuildWithTheSameParametersButFailedToOpenItThen.

@Test
public void testUserCanRestartBuildWithTheSameParametersButFailedToOpenItThen() {
    // Prepare mocks
    HttpException httpException = new HttpException(Response.<Build>error(500, mResponseBody));
    when(mTeamCityService.build(anyString())).thenReturn(Observable.just(mBuild)).thenReturn(Observable.<Build>error(httpException)).thenReturn(Observable.<Build>error(httpException));
    when(mTeamCityService.queueBuild(Matchers.any(Build.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();
    Build buildToRestart = Mocks.failedBuild();
    Properties.Property property = new Properties.Property(PROPERTY_NAME, PROPERTY_VALUE);
    buildToRestart.setBranchName(BRANCH_NAME);
    buildToRestart.setProperties(new Properties(Collections.singletonList(property)));
    b.putSerializable(BundleExtractorValues.BUILD, buildToRestart);
    b.putString(BundleExtractorValues.NAME, BUILD_TYPE_NAME);
    intent.putExtras(b);
    // Start activity
    mActivityRule.launchActivity(intent);
    // Opening context menu
    openContextualActionModeOverflowMenu();
    // Click on context menu option
    onView(withText(R.string.text_menu_restart_build)).perform(click());
    // Click on restart button
    onView(withText(R.string.text_restart_button)).perform(click());
    // Check snack bar is displayed
    onView(withText(R.string.text_build_is_restarted)).check(matches(isDisplayed()));
    // Click on show button of queued build snack bar
    onView(withText(R.string.text_show_build)).perform(click());
    // Check error snack bar
    onView(withText(R.string.error_opening_build)).check(matches(isDisplayed()));
    // Click on retry button
    onView(withText(R.string.download_artifact_retry_snack_bar_retry_button)).perform(click());
    // Check error snack bar
    onView(withText(R.string.error_opening_build)).check(matches(isDisplayed()));
}
Also used : Build(com.github.vase4kin.teamcityapp.buildlist.api.Build) Bundle(android.os.Bundle) HttpException(retrofit2.adapter.rxjava.HttpException) Intent(android.content.Intent) Properties(com.github.vase4kin.teamcityapp.properties.api.Properties) Test(org.junit.Test)

Example 37 with HttpException

use of retrofit2.HttpException in project TeamCityApp by vase4kin.

the class CancelBuildTest method testUserCanSeeForbiddenErrorWhenStoppingBuild.

@Test
public void testUserCanSeeForbiddenErrorWhenStoppingBuild() {
    // Prepare mocks
    when(mTeamCityService.build(anyString())).thenReturn(Observable.just(Mocks.runningBuild()));
    HttpException httpException = new HttpException(Response.<Build>error(CODE_FORBIDDEN, mResponseBody));
    when(mTeamCityService.cancelBuild(anyString(), Matchers.any(BuildCancelRequest.class))).thenReturn(Observable.<Build>error(httpException));
    // 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());
    // Click on cancel build
    onView(withText(R.string.text_stop_button)).perform(click());
    // Check snack bar is displayed
    onView(withText(R.string.error_stop_build_forbidden_error)).check(matches(isDisplayed()));
}
Also used : BuildCancelRequest(com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest) Bundle(android.os.Bundle) HttpException(retrofit2.adapter.rxjava.HttpException) Intent(android.content.Intent) Test(org.junit.Test)

Example 38 with HttpException

use of retrofit2.HttpException in project TeamCityApp by vase4kin.

the class CancelBuildTest method testUserCanSeeServerErrorWhenRemovingBuildFromQueue.

@Test
public void testUserCanSeeServerErrorWhenRemovingBuildFromQueue() {
    // Prepare mocks
    when(mTeamCityService.build(anyString())).thenReturn(Observable.just(mBuild));
    HttpException httpException = new HttpException(Response.<Build>error(500, mResponseBody));
    when(mTeamCityService.cancelBuild(anyString(), Matchers.any(BuildCancelRequest.class))).thenReturn(Observable.<Build>error(httpException));
    // 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());
    // Click on cancel build
    onView(withText(R.string.text_remove_from_queue_button)).perform(click());
    // Check snack bar is displayed
    onView(withText(R.string.error_base_remove_build_from_queue_error)).check(matches(isDisplayed()));
}
Also used : BuildCancelRequest(com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest) Bundle(android.os.Bundle) HttpException(retrofit2.adapter.rxjava.HttpException) Intent(android.content.Intent) Test(org.junit.Test)

Example 39 with HttpException

use of retrofit2.HttpException in project TeamCityApp by vase4kin.

the class CancelBuildTest method testUserCanSeeForbiddenErrorWhenRemovingBuildFromQueue.

@Test
public void testUserCanSeeForbiddenErrorWhenRemovingBuildFromQueue() {
    // Prepare mocks
    when(mTeamCityService.build(anyString())).thenReturn(Observable.just(mBuild));
    HttpException httpException = new HttpException(Response.<Build>error(CODE_FORBIDDEN, mResponseBody));
    when(mTeamCityService.cancelBuild(anyString(), Matchers.any(BuildCancelRequest.class))).thenReturn(Observable.<Build>error(httpException));
    // 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());
    // Click on cancel build
    onView(withText(R.string.text_remove_from_queue_button)).perform(click());
    // Check snack bar is displayed
    onView(withText(R.string.error_remove_build_from_queue_forbidden_error)).check(matches(isDisplayed()));
}
Also used : BuildCancelRequest(com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest) Bundle(android.os.Bundle) HttpException(retrofit2.adapter.rxjava.HttpException) Intent(android.content.Intent) Test(org.junit.Test)

Example 40 with HttpException

use of retrofit2.HttpException in project TeamCityApp by vase4kin.

the class CancelBuildTest method testUserCanSeeServerErrorWhenStoppingBuild.

@Test
public void testUserCanSeeServerErrorWhenStoppingBuild() {
    // Prepare mocks
    when(mTeamCityService.build(anyString())).thenReturn(Observable.just(Mocks.runningBuild()));
    HttpException httpException = new HttpException(Response.<Build>error(500, mResponseBody));
    when(mTeamCityService.cancelBuild(anyString(), Matchers.any(BuildCancelRequest.class))).thenReturn(Observable.<Build>error(httpException));
    // 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());
    // Click on cancel build
    onView(withText(R.string.text_stop_button)).perform(click());
    // Check snack bar is displayed
    onView(withText(R.string.error_base_stop_build_error)).check(matches(isDisplayed()));
}
Also used : BuildCancelRequest(com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest) Bundle(android.os.Bundle) HttpException(retrofit2.adapter.rxjava.HttpException) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

HttpException (retrofit2.HttpException)32 HttpException (retrofit2.adapter.rxjava.HttpException)18 Test (org.junit.Test)14 JSONException (org.json.JSONException)12 Intent (android.content.Intent)11 JsonParseException (com.google.gson.JsonParseException)11 ConnectException (java.net.ConnectException)10 Bundle (android.os.Bundle)9 ParseException (android.net.ParseException)8 IOException (java.io.IOException)7 SocketTimeoutException (java.net.SocketTimeoutException)7 UnknownHostException (java.net.UnknownHostException)7 Response (retrofit2.Response)7 View (android.view.View)6 Build (com.github.vase4kin.teamcityapp.buildlist.api.Build)6 Disposable (io.reactivex.disposables.Disposable)6 List (java.util.List)6 TextView (android.widget.TextView)5 TextUtils (android.text.TextUtils)4 BuildCancelRequest (com.github.vase4kin.teamcityapp.build_details.api.BuildCancelRequest)4