Search in sources :

Example 71 with BadRequestException

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

the class AgreementsIT method signAgreementNoAutoVerify.

@Test
public void signAgreementNoAutoVerify() throws Exception {
    assume().that(isContributorAgreementsEnabled()).isTrue();
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.accounts().self().signAgreement(caNoAutoVerify.getName()));
    assertThat(thrown).hasMessageThat().contains("cannot enter a non-autoVerify agreement");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 72 with BadRequestException

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

the class PluginOperatorsIT method getChangeWithIsOperator.

@Test
public void getChangeWithIsOperator() throws Exception {
    QueryChanges queryChanges = queryChangesProvider.get();
    queryChanges.addQuery("is:changeNumberEven_myplugin");
    String oddChangeId = createChange().getChangeId();
    String evenChangeId = createChange().getChangeId();
    BadRequestException exception = assertThrows(BadRequestException.class, () -> getChanges(queryChanges));
    assertThat(exception).hasMessageThat().isEqualTo("Unrecognized value: changeNumberEven_myplugin");
    try (AutoCloseable ignored = installPlugin("myplugin", IsOperatorModule.class)) {
        List<?> changes = getChanges(queryChanges);
        assertThat(changes).hasSize(1);
        ChangeInfo c = (ChangeInfo) changes.get(0);
        String outputChangeId = c.changeId;
        assertThat(outputChangeId).isEqualTo(evenChangeId);
        assertThat(outputChangeId).isNotEqualTo(oddChangeId);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) QueryChanges(com.google.gerrit.server.restapi.change.QueryChanges) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 73 with BadRequestException

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

the class PrivateChangeIT method cannotSetMergedChangePrivate.

@Test
public void cannotSetMergedChangePrivate() throws Exception {
    PushOneCommit.Result result = createChange();
    approve(result.getChangeId());
    merge(result);
    String changeId = result.getChangeId();
    assertThat(gApi.changes().id(changeId).get().isPrivate).isNull();
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(changeId).setPrivate(true));
    assertThat(thrown).hasMessageThat().contains("cannot set merged change to private");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 74 with BadRequestException

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

the class SuggestReviewersIT method suggestReviewersTooManyQueryTerms.

@Test
@GerritConfig(name = "index.maxTerms", value = "10")
public void suggestReviewersTooManyQueryTerms() throws Exception {
    String changeId = createChange().getChangeId();
    // Do a query which doesn't exceed index.maxTerms succeeds (add only 9 terms, since on
    // 'inactive:1' term is implicitly added) and assert that a result is returned
    StringBuilder query = new StringBuilder();
    for (int i = 1; i <= 9; i++) {
        query.append(name("u")).append(" ");
    }
    assertThat(suggestReviewers(changeId, query.toString())).isNotEmpty();
    // Do a query which exceed index.maxTerms succeeds (10 terms plus 'inactive:1' term which is
    // implicitly added).
    query.append(name("u"));
    BadRequestException exception = assertThrows(BadRequestException.class, () -> suggestReviewers(changeId, query.toString()));
    assertThat(exception).hasMessageThat().isEqualTo("too many terms in query");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 75 with BadRequestException

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

the class HashtagsIT method addInvalidHashtag.

@Test
public void addInvalidHashtag() throws Exception {
    PushOneCommit.Result r = createChange();
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> addHashtags(r, "invalid,hashtag"));
    assertThat(thrown).hasMessageThat().contains("hashtags may not contain commas");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)310 Test (org.junit.Test)154 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)146 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)56 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)51 AuthException (com.google.gerrit.extensions.restapi.AuthException)46 Repository (org.eclipse.jgit.lib.Repository)30 IdString (com.google.gerrit.extensions.restapi.IdString)29 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)29 LabelDefinitionInput (com.google.gerrit.extensions.common.LabelDefinitionInput)28 ArrayList (java.util.ArrayList)28 RevCommit (org.eclipse.jgit.revwalk.RevCommit)28 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)27 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)27 IOException (java.io.IOException)25 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)24 RevWalk (org.eclipse.jgit.revwalk.RevWalk)22 ObjectId (org.eclipse.jgit.lib.ObjectId)20 Map (java.util.Map)19 Change (com.google.gerrit.entities.Change)18