Search in sources :

Example 66 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveKeepAllVotesCanMoveAllInRange.

@Test
public void moveKeepAllVotesCanMoveAllInRange() throws Exception {
    BranchNameKey destinationBranch = BranchNameKey.create(project, "dest");
    createBranch(destinationBranch);
    BranchNameKey sourceBranch = BranchNameKey.create(project, "source");
    createBranch(sourceBranch);
    // The non-block label has the range [-2; 2]
    String testLabelA = "Label-A";
    configLabel(project, testLabelA, LabelFunction.NO_BLOCK, value(2, "Passes"), value(1, "Mostly ok"), value(0, "No score"), value(-1, "Needs work"), value(-2, "Failed"));
    // Registered users have [-2; 2] permissions on all branches.
    projectOperations.project(project).forUpdate().add(allowLabel(testLabelA).ref("refs/heads/*").group(REGISTERED_USERS).range(-2, +2)).update();
    String changeId = createChangeInBranch(sourceBranch.branch()).getChangeId();
    for (int vote = -2; vote <= 2; vote++) {
        TestAccount testUser = accountCreator.create("TestUser" + vote);
        requestScopeOperations.setApiUser(testUser.id());
        ReviewInput userReviewInput = new ReviewInput();
        userReviewInput.label(testLabelA, vote);
        gApi.changes().id(changeId).current().review(userReviewInput);
    }
    assertThat(gApi.changes().id(changeId).current().votes().get(testLabelA).stream().map(approvalInfo -> approvalInfo.value).collect(ImmutableList.toImmutableList())).containsExactly(-2, -1, 1, 2);
    requestScopeOperations.setApiUser(admin.id());
    // Move the change to the destination branch.
    assertThat(info(changeId).branch).isEqualTo(sourceBranch.shortName());
    move(changeId, destinationBranch.shortName(), true);
    assertThat(info(changeId).branch).isEqualTo(destinationBranch.shortName());
    // All votes are kept
    assertThat(gApi.changes().id(changeId).current().votes().get(testLabelA).stream().map(approvalInfo -> approvalInfo.value).collect(ImmutableList.toImmutableList())).containsExactly(-2, -1, 1, 2);
    // Move the change back to the source, the label is kept.
    move(changeId, sourceBranch.shortName(), true);
    assertThat(info(changeId).branch).isEqualTo(sourceBranch.shortName());
    assertThat(gApi.changes().id(changeId).current().votes().get(testLabelA).stream().map(approvalInfo -> approvalInfo.value).collect(ImmutableList.toImmutableList())).containsExactly(-2, -1, 1, 2);
}
Also used : TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) Arrays(java.util.Arrays) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) TestLabels(com.google.gerrit.server.project.testing.TestLabels) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ImmutableList(com.google.common.collect.ImmutableList) LabelType(com.google.gerrit.entities.LabelType) LabelFunction(com.google.gerrit.entities.LabelFunction) AuthException(com.google.gerrit.extensions.restapi.AuthException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GitUtil(com.google.gerrit.acceptance.GitUtil) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) TestRepository(org.eclipse.jgit.junit.TestRepository) Permission(com.google.gerrit.entities.Permission) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) NoHttpd(com.google.gerrit.acceptance.NoHttpd) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) MoveInput(com.google.gerrit.extensions.api.changes.MoveInput) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) BranchNameKey(com.google.gerrit.entities.BranchNameKey) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 67 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveChangeWithShortRef.

@Test
public void moveChangeWithShortRef() throws Exception {
    // Move change to a different branch using short ref name
    PushOneCommit.Result r = createChange();
    BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
    createBranch(newBranch);
    move(r.getChangeId(), newBranch.shortName());
    assertThat(r.getChange().change().getDest()).isEqualTo(newBranch);
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 68 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveChangeWithMessage.

@Test
public void moveChangeWithMessage() throws Exception {
    // Provide a message using --message flag
    PushOneCommit.Result r = createChange();
    BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
    createBranch(newBranch);
    String moveMessage = "Moving for the move test";
    move(r.getChangeId(), newBranch.branch(), moveMessage);
    assertThat(r.getChange().change().getDest()).isEqualTo(newBranch);
    StringBuilder expectedMessage = new StringBuilder();
    expectedMessage.append("Change destination moved from master to moveTest");
    expectedMessage.append("\n\n");
    expectedMessage.append(moveMessage);
    assertThat(Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages).message).isEqualTo(expectedMessage.toString());
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 69 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveClosedChange.

@Test
public void moveClosedChange() throws Exception {
    // Move a change which is not open
    PushOneCommit.Result r = createChange();
    BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
    createBranch(newBranch);
    merge(r);
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> move(r.getChangeId(), newBranch.branch()));
    assertThat(thrown).hasMessageThat().contains("Change is merged");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 70 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveChangeFromBranchWithoutAbandonPerms.

@Test
public void moveChangeFromBranchWithoutAbandonPerms() throws Exception {
    // Move change for which user does not have abandon permissions
    PushOneCommit.Result r = createChange();
    BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
    createBranch(newBranch);
    projectOperations.project(project).forUpdate().add(block(Permission.ABANDON).ref(r.getChange().change().getDest().branch()).group(REGISTERED_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    AuthException thrown = assertThrows(AuthException.class, () -> move(r.getChangeId(), newBranch.branch()));
    assertThat(thrown).hasMessageThat().isEqualTo("move not permitted");
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) AuthException(com.google.gerrit.extensions.restapi.AuthException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

BranchNameKey (com.google.gerrit.entities.BranchNameKey)75 Test (org.junit.Test)48 Project (com.google.gerrit.entities.Project)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)25 Config (org.eclipse.jgit.lib.Config)19 SubmoduleSubscription (com.google.gerrit.entities.SubmoduleSubscription)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 AuthException (com.google.gerrit.extensions.restapi.AuthException)13 Change (com.google.gerrit.entities.Change)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 StorageException (com.google.gerrit.exceptions.StorageException)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Repository (org.eclipse.jgit.lib.Repository)9 PatchSet (com.google.gerrit.entities.PatchSet)8 CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)8 HashMap (java.util.HashMap)7 Ref (org.eclipse.jgit.lib.Ref)7