Search in sources :

Example 81 with BadRequestException

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

the class TestSubmitType method apply.

@Override
public Response<SubmitType> apply(RevisionResource rsrc, TestSubmitRuleInput input) throws AuthException, BadRequestException {
    if (input == null) {
        input = new TestSubmitRuleInput();
    }
    if (input.rule == null) {
        throw new BadRequestException("rule is required");
    }
    if (!rules.isProjectRulesEnabled()) {
        throw new AuthException("project rules are disabled");
    }
    input.filters = MoreObjects.firstNonNull(input.filters, filters);
    ChangeData cd = changeDataFactory.create(rsrc.getNotes());
    SubmitTypeRecord rec = prologRule.getSubmitType(cd, PrologOptions.dryRunOptions(input.rule, input.filters == Filters.SKIP));
    if (rec.status != SubmitTypeRecord.Status.OK) {
        throw new BadRequestException(String.format("rule produced invalid result: %s", rec));
    }
    return Response.ok(rec.type);
}
Also used : TestSubmitRuleInput(com.google.gerrit.extensions.common.TestSubmitRuleInput) SubmitTypeRecord(com.google.gerrit.entities.SubmitTypeRecord) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 82 with BadRequestException

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

the class CheckConsistency method apply.

@Override
public Response<ConsistencyCheckInfo> apply(ConfigResource resource, ConsistencyCheckInput input) throws RestApiException, IOException, PermissionBackendException, ConfigInvalidException {
    permissionBackend.currentUser().check(GlobalPermission.ACCESS_DATABASE);
    if (input == null || (input.checkAccounts == null && input.checkAccountExternalIds == null && input.checkGroups == null)) {
        throw new BadRequestException("input required");
    }
    ConsistencyCheckInfo consistencyCheckInfo = new ConsistencyCheckInfo();
    if (input.checkAccounts != null) {
        consistencyCheckInfo.checkAccountsResult = new CheckAccountsResultInfo(accountsConsistencyChecker.check());
    }
    if (input.checkAccountExternalIds != null) {
        consistencyCheckInfo.checkAccountExternalIdsResult = new CheckAccountExternalIdsResultInfo(externalIdsConsistencyChecker.check());
    }
    if (input.checkGroups != null) {
        consistencyCheckInfo.checkGroupsResult = new CheckGroupsResultInfo(groupsConsistencyChecker.check());
    }
    return Response.ok(consistencyCheckInfo);
}
Also used : CheckAccountsResultInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckAccountsResultInfo) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) CheckGroupsResultInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckGroupsResultInfo) CheckAccountExternalIdsResultInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckAccountExternalIdsResultInfo)

Example 83 with BadRequestException

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

the class RevisionIT method cherryPickMergeUsingInvalidParent.

@Test
public void cherryPickMergeUsingInvalidParent() throws Exception {
    String parent1FileName = "a.txt";
    String parent2FileName = "b.txt";
    PushOneCommit.Result mergeChangeResult = createCherryPickableMerge(parent1FileName, parent2FileName);
    String cherryPickBranchName = "branch_for_cherry_pick";
    createBranch(BranchNameKey.create(project, cherryPickBranchName));
    CherryPickInput cherryPickInput = new CherryPickInput();
    cherryPickInput.destination = cherryPickBranchName;
    cherryPickInput.message = "Cherry-pick a merge commit to another branch";
    cherryPickInput.parent = 0;
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(mergeChangeResult.getChangeId()).current().cherryPick(cherryPickInput));
    assertThat(thrown).hasMessageThat().contains("Cherry Pick: Parent 0 does not exist. Please specify a parent in range [1, 2].");
}
Also used : CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 84 with BadRequestException

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

the class RevisionIT method listFilesWithInvalidParent.

@Test
public void listFilesWithInvalidParent() throws Exception {
    PushOneCommit.Result result1 = createChange();
    String changeId = result1.getChangeId();
    PushOneCommit.Result result2 = amendChange(changeId, SUBJECT, "b.txt", "b");
    String revId2 = result2.getCommit().name();
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(changeId).revision(revId2).files(2));
    assertThat(thrown).hasMessageThat().isEqualTo("invalid parent number: 2");
    thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(changeId).revision(revId2).files(-1));
    assertThat(thrown).hasMessageThat().isEqualTo("invalid parent number: -1");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 85 with BadRequestException

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

the class RobotCommentsIT method robotCommentInvalidInReplyTo.

@Test
public void robotCommentInvalidInReplyTo() throws Exception {
    Change.Id changeId = changeOperations.newChange().create();
    RobotCommentInput input = TestCommentHelper.createRobotCommentInput(PATCHSET_LEVEL);
    input.inReplyTo = "invalid";
    BadRequestException ex = assertThrows(BadRequestException.class, () -> testCommentHelper.addRobotComment(changeId, input));
    assertThat(ex.getMessage()).contains("inReplyTo");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) Change(com.google.gerrit.entities.Change) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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