use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method notifyDetailsWorkOnPostReview.
@Test
public void notifyDetailsWorkOnPostReview() throws Exception {
PushOneCommit.Result r = createChange();
TestAccount userToNotify = createAccounts(1, "notify-details-post-review").get(0);
ReviewInput reviewInput = new ReviewInput();
reviewInput.reviewer(user.email(), ReviewerState.REVIEWER, true);
reviewInput.notify = NotifyHandling.NONE;
reviewInput.notifyDetails = ImmutableMap.of(RecipientType.TO, new NotifyInfo(ImmutableList.of(userToNotify.email())));
sender.clear();
gApi.changes().id(r.getChangeId()).current().review(reviewInput);
assertThat(sender.getMessages()).hasSize(1);
assertThat(sender.getMessages().get(0).rcpt()).containsExactly(userToNotify.getNameEmail());
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method removeReviewerWithoutVoteOnAMergedChangeWithPermissionSucceeds.
@Test
@Sandboxed
public void removeReviewerWithoutVoteOnAMergedChangeWithPermissionSucceeds() throws Exception {
PushOneCommit.Result r = createChange();
// This test creates a new user so that it can explicitly check the REMOVE_REVIEWER permission
// rather than bypassing the check because of project or ref ownership.
TestAccount newUser = createAccounts(1, name("foo")).get(0);
projectOperations.project(project).forUpdate().add(allow(Permission.REMOVE_REVIEWER).ref(RefNames.REFS + "*").group(REGISTERED_USERS)).update();
gApi.changes().id(r.getChangeId()).addReviewer(user.email());
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
gApi.changes().id(r.getChangeId()).current().submit();
requestScopeOperations.setApiUser(newUser.id());
// Ensures user is removable.
assertThat(gApi.changes().id(r.getChangeId()).get().removableReviewers.stream().filter(a -> user.email().equals(a.email)).findAny().isPresent()).isTrue();
gApi.changes().id(r.getChangeId()).reviewer(user.email()).remove();
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method addGroupAsReviewer.
@Test
public void addGroupAsReviewer() throws Exception {
// Set up two groups, one that is too large too add as reviewer, and one
// that is too large to add without confirmation.
String largeGroup = groupOperations.newGroup().name("largeGroup").create().get();
String mediumGroup = groupOperations.newGroup().name("mediumGroup").create().get();
int largeGroupSize = ReviewerModifier.DEFAULT_MAX_REVIEWERS + 1;
int mediumGroupSize = ReviewerModifier.DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK + 1;
List<TestAccount> users = createAccounts(largeGroupSize, "addGroupAsReviewer");
List<String> largeGroupUsernames = new ArrayList<>(mediumGroupSize);
for (TestAccount u : users) {
largeGroupUsernames.add(u.username());
}
List<String> mediumGroupUsernames = largeGroupUsernames.subList(0, mediumGroupSize);
gApi.groups().id(largeGroup).addMembers(largeGroupUsernames.toArray(new String[largeGroupSize]));
gApi.groups().id(mediumGroup).addMembers(mediumGroupUsernames.toArray(new String[mediumGroupSize]));
// Attempt to add overly large group as reviewers.
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
ReviewerResult result = addReviewer(changeId, largeGroup);
assertThat(result.input).isEqualTo(largeGroup);
assertThat(result.confirm).isNull();
assertThat(result.error).contains("has too many members to add them all as reviewers");
assertThat(result.reviewers).isNull();
// Attempt to add medium group without confirmation.
result = addReviewer(changeId, mediumGroup);
assertThat(result.input).isEqualTo(mediumGroup);
assertThat(result.confirm).isTrue();
assertThat(result.error).contains("has " + mediumGroupSize + " members. Do you want to add them all as reviewers?");
assertThat(result.reviewers).isNull();
// Add medium group with confirmation.
ReviewerInput in = new ReviewerInput();
in.reviewer = mediumGroup;
in.confirmed = true;
result = addReviewer(changeId, in);
assertThat(result.input).isEqualTo(mediumGroup);
assertThat(result.confirm).isNull();
assertThat(result.error).isNull();
assertThat(result.reviewers).hasSize(mediumGroupSize);
// Verify that group members were added as reviewers.
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
assertReviewers(c, REVIEWER, users.subList(0, mediumGroupSize));
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class AttentionSetIT method robotCommentDoesNotAddOwnerOnClosedChanges.
@Test
public void robotCommentDoesNotAddOwnerOnClosedChanges() throws Exception {
TestAccount robot = accountCreator.create("robot2", "robot2@example.com", "Ro Bot", "Ro", ServiceUserClassifier.SERVICE_USERS);
PushOneCommit.Result r = createChange();
gApi.changes().id(r.getChangeId()).abandon();
requestScopeOperations.setApiUser(robot.id());
ReviewInput reviewInput = new ReviewInput();
ReviewInput.RobotCommentInput robotCommentInput = TestCommentHelper.createRobotCommentInputWithMandatoryFields("a.txt");
reviewInput.robotComments = ImmutableMap.of("a.txt", ImmutableList.of(robotCommentInput));
change(r).current().review(reviewInput);
assertThat(r.getChange().attentionSet()).isEmpty();
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class AttentionSetIT method robotsNotAddedToAttentionSet.
@Test
public void robotsNotAddedToAttentionSet() throws Exception {
TestAccount robot = accountCreator.create("robot1", "robot1@example.com", "Ro Bot", "Ro", ServiceUserClassifier.SERVICE_USERS);
PushOneCommit.Result r = createChange();
// Make the robot active on the change.
change(r).addReviewer(robot.email());
// Throw an error when adding a robot explicitly.
BadRequestException exception = assertThrows(BadRequestException.class, () -> change(r).addToAttentionSet(new AttentionSetInput(robot.email(), "reason")));
assertThat(exception.getMessage()).isEqualTo("robot1@example.com is a robot, and robots can't be added to the attention set.");
// Robots are not added implicitly.
change(r).addReviewer(robot.email());
assertThat(r.getChange().attentionSet()).isEmpty();
}
Aggregations