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);
}
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);
}
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());
}
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");
}
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");
}
Aggregations