Search in sources :

Example 91 with BadRequestException

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

the class RevisionIT method cherryPickMergeUsingNonExistentParent.

@Test
public void cherryPickMergeUsingNonExistentParent() 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 = 3;
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(mergeChangeResult.getChangeId()).current().cherryPick(cherryPickInput));
    assertThat(thrown).hasMessageThat().contains("Cherry Pick: Parent 3 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 92 with BadRequestException

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

the class RevisionIT method cherryPickToExistingMergedChange.

@Test
public void cherryPickToExistingMergedChange() throws Exception {
    PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "a").to("refs/for/master");
    BranchInput bin = new BranchInput();
    bin.revision = r1.getCommit().getParent(0).name();
    gApi.projects().name(project.get()).branch("foo").create(bin);
    PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "b", r1.getChangeId()).to("refs/for/foo");
    String t2 = project.get() + "~foo~" + r2.getChangeId();
    gApi.changes().id(t2).current().review(ReviewInput.approve());
    gApi.changes().id(t2).current().submit();
    CherryPickInput in = new CherryPickInput();
    in.destination = "foo";
    in.message = r1.getCommit().getFullMessage();
    in.allowConflicts = true;
    in.allowEmpty = true;
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(t2).current().cherryPick(in));
    assertThat(thrown).hasMessageThat().isEqualTo(String.format("Cherry-pick with Change-Id %s could not update the existing change %d in " + "destination branch refs/heads/foo of project %s, because " + "the change was closed (MERGED)", r1.getChangeId(), info(t2)._number, project.get()));
}
Also used : CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 93 with BadRequestException

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

the class ChangeEditIT method updateCommitMessageByEditingMagicCommitMsgFileWithoutContent.

@Test
public void updateCommitMessageByEditingMagicCommitMsgFileWithoutContent() throws Exception {
    createEmptyEditFor(changeId);
    BadRequestException ex = assertThrows(BadRequestException.class, () -> gApi.changes().id(changeId).edit().modifyFile(Patch.COMMIT_MSG, (RawInput) null));
    assertThat(ex).hasMessageThat().isEqualTo("either content or binary_content is required");
}
Also used : RawInput(com.google.gerrit.extensions.restapi.RawInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 94 with BadRequestException

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

the class RobotCommentsIT method rangeOfFixReplacementIsMandatory.

@Test
public void rangeOfFixReplacementIsMandatory() {
    fixReplacementInfo.range = null;
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput));
    assertThat(thrown).hasMessageThat().contains(String.format("A range must be given for the replacement of the robot comment on %s", withFixRobotCommentInput.path));
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 95 with BadRequestException

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

the class ParameterParserTest method rejectDuplicateMethod.

@Test
public void rejectDuplicateMethod() {
    FakeHttpServletRequest req = new FakeHttpServletRequest();
    req.setQueryString("$m=PUT&$m=DELETE");
    BadRequestException bad = assertThrows(BadRequestException.class, () -> ParameterParser.getQueryParams(req));
    assertThat(bad).hasMessageThat().isEqualTo("duplicate $m");
}
Also used : FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) 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