Search in sources :

Example 91 with RestApiException

use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.

the class RefOperationValidationIT method rejectRefCreation.

@Test
public void rejectRefCreation() throws Exception {
    try (Registration registration = testValidator(CREATE)) {
        RestApiException expected = assertThrows(RestApiException.class, () -> gApi.projects().name(project.get()).branch(TEST_REF).create(new BranchInput()));
        assertThat(expected).hasMessageThat().contains(CREATE.name());
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 92 with RestApiException

use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.

the class AbstractSubmit method submit.

protected void submit(String changeId, SubmitInput input, @Nullable Class<? extends RestApiException> expectedExceptionType, String expectedExceptionMsg) throws Throwable {
    approve(changeId);
    if (expectedExceptionType == null) {
        assertSubmittable(changeId);
    } else {
        requireNonNull(expectedExceptionMsg);
    }
    ThrowingRunnable submit = () -> gApi.changes().id(changeId).current().submit(input);
    if (expectedExceptionType != null) {
        RestApiException thrown = assertThrows(expectedExceptionType, submit);
        assertThat(thrown).hasMessageThat().isEqualTo(expectedExceptionMsg);
        return;
    }
    submit.run();
    ChangeInfo change = gApi.changes().id(changeId).info();
    assertMerged(change.changeId);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ThrowingRunnable(com.google.gerrit.testing.GerritJUnit.ThrowingRunnable)

Example 93 with RestApiException

use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.

the class CreateBranchIT method assertCreateFails.

private void assertCreateFails(BranchNameKey branch, String revision, Class<? extends RestApiException> errType, String errMsg) throws Exception {
    BranchInput in = new BranchInput();
    in.revision = revision;
    RestApiException thrown = assertThrows(errType, () -> branch(branch).create(in));
    if (errMsg != null) {
        assertThat(thrown).hasMessageThat().contains(errMsg);
    }
}
Also used : BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Aggregations

RestApiException (com.google.gerrit.extensions.restapi.RestApiException)93 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)38 IOException (java.io.IOException)31 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)24 UpdateException (com.google.gerrit.server.update.UpdateException)23 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)22 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)20 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)19 AuthException (com.google.gerrit.extensions.restapi.AuthException)18 StorageException (com.google.gerrit.exceptions.StorageException)17 List (java.util.List)17 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)16 Inject (com.google.inject.Inject)15 ArrayList (java.util.ArrayList)15 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)14 ChangeContext (com.google.gerrit.server.update.ChangeContext)14 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)14 Provider (com.google.inject.Provider)12 Change (com.google.gerrit.entities.Change)11