use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class ProjectIT method createAndDeleteBranchByPush.
@Test
public void createAndDeleteBranchByPush() throws Exception {
ProjectIndexedCounter projectIndexedCounter = new ProjectIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(projectIndexedCounter)) {
projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref("refs/*").group(adminGroupUuid()).force(true)).update();
projectIndexedCounter.clear();
assertThat(hasHead(project, "foo")).isFalse();
PushOneCommit.Result r = pushTo("refs/heads/foo");
r.assertOkStatus();
assertThat(getRemoteHead(project.get(), "foo")).isEqualTo(r.getCommit());
projectIndexedCounter.assertNoReindex();
PushResult r2 = GitUtil.pushOne(testRepo, null, "refs/heads/foo", false, true, null);
assertThat(r2.getRemoteUpdate("refs/heads/foo").getStatus()).isEqualTo(Status.OK);
assertThat(hasHead(project, "foo")).isFalse();
projectIndexedCounter.assertNoReindex();
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class PostReviewIT method onPostReviewExtensionThatDoesntExtendTheChangeMessage.
@Test
public void onPostReviewExtensionThatDoesntExtendTheChangeMessage() throws Exception {
PushOneCommit.Result r = createChange();
TestOnPostReview testOnPostReview = new TestOnPostReview(/* message= */
null);
try (Registration registration = extensionRegistry.newRegistration().add(testOnPostReview)) {
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
gApi.changes().id(r.getChangeId()).current().review(input);
Collection<ChangeMessageInfo> messages = gApi.changes().id(r.getChangeId()).get().messages;
assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1: Code-Review+1");
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class PostReviewIT method votingTheSameVoteSecondTimeDoesNotFireOnCommentAdded.
@Test
public void votingTheSameVoteSecondTimeDoesNotFireOnCommentAdded() throws Exception {
PushOneCommit.Result r = createChange();
// Add a new vote.
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
assertThat(r.getChange().approvals().values()).hasSize(1);
TestListener testListener = new TestListener();
try (Registration registration = extensionRegistry.newRegistration().add(testListener)) {
// Post without changing the vote.
input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
// Event not fired.
assertThat(testListener.lastCommentAddedEvent).isNull();
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class PostReviewIT method addingAndDeletingReviewers.
@Test
public void addingAndDeletingReviewers() throws Exception {
PushOneCommit.Result r = createChange();
TestAccount user2 = accountCreator.user2();
TestAccount user3 = accountCreator.create("user3", "user3@email.com", "user3", "user3");
TestAccount user4 = accountCreator.create("user4", "user4@email.com", "user4", "user4");
// add user and user2
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.create().reviewer(user.email()).reviewer(user2.email()));
sender.clear();
TestReviewerAddedListener testReviewerAddedListener = new TestReviewerAddedListener();
TestReviewerDeletedListener testReviewerDeletedListener = new TestReviewerDeletedListener();
try (Registration registration = extensionRegistry.newRegistration().add(testReviewerAddedListener).add(testReviewerDeletedListener)) {
// remove user and user2 while adding user3 and user4
ReviewResult reviewResult = gApi.changes().id(r.getChangeId()).current().review(ReviewInput.create().reviewer(user.email(), ReviewerState.REMOVED, /* confirmed= */
true).reviewer(user2.email(), ReviewerState.REMOVED, /* confirmed= */
true).reviewer(user3.email()).reviewer(user4.email()));
assertThat(reviewResult.reviewers.values().stream().filter(a -> a.removed != null).map(a -> a.removed.name).collect(toImmutableSet())).containsExactly(user.fullName(), user2.fullName());
assertThat(reviewResult.reviewers.values().stream().filter(a -> a.reviewers != null).map(a -> Iterables.getOnlyElement(a.reviewers).name).collect(toImmutableSet())).containsExactly(user3.fullName(), user4.fullName());
}
assertThat(gApi.changes().id(r.getChangeId()).reviewers().stream().map(a -> a.name).collect(toImmutableSet())).containsExactly(user3.fullName(), user4.fullName());
// Ensure only one batch email was sent for this operation
FakeEmailSender.Message message = Iterables.getOnlyElement(sender.getMessages());
assertThat(message.body()).containsMatch(Pattern.quote("Hello ") + "(" + Pattern.quote(String.format("%s, %s", user3.fullName(), user4.fullName())) + "|" + Pattern.quote(String.format("%s, %s", user4.fullName(), user3.fullName())) + ")");
assertThat(message.htmlBody()).containsMatch("(" + Pattern.quote(String.format("%s and %s", user3.fullName(), user4.fullName())) + "|" + Pattern.quote(String.format("%s and %s", user4.fullName(), user3.fullName())) + ")" + Pattern.quote(" to <strong>review</strong> this change"));
assertThat(message.body()).containsMatch(Pattern.quote("removed ") + "(" + Pattern.quote(String.format("%s, %s", user.fullName(), user2.fullName())) + "|" + Pattern.quote(String.format("%s, %s", user2.fullName(), user.fullName())) + ")");
assertThat(message.htmlBody()).containsMatch(Pattern.quote("removed ") + "(" + Pattern.quote(String.format("%s and %s", user.fullName(), user2.fullName())) + "|" + Pattern.quote(String.format("%s and %s", user2.fullName(), user.fullName())) + ")");
// Ensure that events have been sent:
// * 1 batch event for adding user3 and user4 as reviewers
// * 2 events for removing user and user2 as reviewers (one event per removed reviewer, batch
// event not available for reviewer removal)
assertThat(testReviewerAddedListener.receivedEvents).hasSize(1);
assertThat(testReviewerAddedListener.getReviewerIds()).containsExactly(user3.id(), user4.id());
assertThat(testReviewerDeletedListener.receivedEvents).hasSize(2);
assertThat(testReviewerDeletedListener.getReviewerIds()).containsExactly(user.id(), user2.id());
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class PostReviewIT method submitRulesAreInvokedOnlyOnce.
@Test
public void submitRulesAreInvokedOnlyOnce() throws Exception {
PushOneCommit.Result r = createChange();
TestSubmitRule testSubmitRule = new TestSubmitRule();
try (Registration registration = extensionRegistry.newRegistration().add(testSubmitRule)) {
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
gApi.changes().id(r.getChangeId()).current().review(input);
}
assertThat(testSubmitRule.count).isEqualTo(1);
}
Aggregations