Search in sources :

Example 76 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class PostReviewIT method addingReviewers.

@Test
public void addingReviewers() throws Exception {
    PushOneCommit.Result r = createChange();
    TestAccount user2 = accountCreator.user2();
    TestReviewerAddedListener testReviewerAddedListener = new TestReviewerAddedListener();
    try (Registration registration = extensionRegistry.newRegistration().add(testReviewerAddedListener)) {
        // add user and user2
        ReviewResult reviewResult = gApi.changes().id(r.getChangeId()).current().review(ReviewInput.create().reviewer(user.email()).reviewer(user2.email()));
        assertThat(reviewResult.reviewers.values().stream().filter(a -> a.reviewers != null).map(a -> Iterables.getOnlyElement(a.reviewers).name).collect(toImmutableSet())).containsExactly(user.fullName(), user2.fullName());
    }
    assertThat(gApi.changes().id(r.getChangeId()).reviewers().stream().map(a -> a.name).collect(toImmutableSet())).containsExactly(user.fullName(), user2.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", user.fullName(), user2.fullName())) + "|" + Pattern.quote(String.format("%s, %s", user2.fullName(), user.fullName())) + ")");
    assertThat(message.htmlBody()).containsMatch("(" + Pattern.quote(String.format("%s and %s", user.fullName(), user2.fullName())) + "|" + Pattern.quote(String.format("%s and %s", user2.fullName(), user.fullName())) + ")" + Pattern.quote(" to <strong>review</strong> this change"));
    // Ensure that a batch event has been sent:
    // * 1 batch event for adding user and user2 as reviewers
    assertThat(testReviewerAddedListener.receivedEvents).hasSize(1);
    assertThat(testReviewerAddedListener.getReviewerIds()).containsExactly(user.id(), user2.id());
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Module(com.google.inject.Module) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) ReviewerDeletedListener(com.google.gerrit.extensions.events.ReviewerDeletedListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Map(java.util.Map) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) Side(com.google.gerrit.extensions.client.Side) PostReview(com.google.gerrit.server.restapi.change.PostReview) ImmutableSet(com.google.common.collect.ImmutableSet) Mockito.clearInvocations(org.mockito.Mockito.clearInvocations) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Account(com.google.gerrit.entities.Account) SubmitRecord(com.google.gerrit.entities.SubmitRecord) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Exports(com.google.gerrit.extensions.annotations.Exports) Pattern(java.util.regex.Pattern) Mockito.mock(org.mockito.Mockito.mock) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Iterables(com.google.common.collect.Iterables) CommentValidationContext(com.google.gerrit.extensions.validators.CommentValidationContext) LabelId(com.google.gerrit.entities.LabelId) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) CommentAddedListener(com.google.gerrit.extensions.events.CommentAddedListener) CommentForValidation(com.google.gerrit.extensions.validators.CommentForValidation) Captor(org.mockito.Captor) ReviewerAddedListener(com.google.gerrit.extensions.events.ReviewerAddedListener) ArrayList(java.util.ArrayList) CommentsRejectedException(com.google.gerrit.server.update.CommentsRejectedException) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) TestCommentHelper(com.google.gerrit.testing.TestCommentHelper) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) OnPostReview(com.google.gerrit.server.restapi.change.OnPostReview) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) SubmitRule(com.google.gerrit.server.rules.SubmitRule) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) Correspondence(com.google.common.truth.Correspondence) Collectors.toList(java.util.stream.Collectors.toList) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) CommentValidator(com.google.gerrit.extensions.validators.CommentValidator) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 77 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method stickyOnCopyValues.

@Test
public void stickyOnCopyValues() throws Exception {
    TestAccount user2 = accountCreator.user2();
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().updateLabelType(LabelId.CODE_REVIEW, b -> b.setCopyValues(ImmutableList.of((short) -1, (short) 1)));
        u.save();
    }
    for (ChangeKind changeKind : EnumSet.of(REWORK, TRIVIAL_REBASE, NO_CODE_CHANGE, MERGE_FIRST_PARENT_UPDATE, NO_CHANGE)) {
        testRepo.reset(projectOperations.project(project).getHead("master"));
        String changeId = changeKindCreator.createChange(changeKind, testRepo, admin);
        vote(admin, changeId, -1, 1);
        vote(user, changeId, -2, -1);
        vote(user2, changeId, 1, -1);
        changeKindCreator.updateChange(changeId, changeKind, testRepo, admin, project);
        ChangeInfo c = detailedChange(changeId);
        assertVotes(c, admin, -1, 0, changeKind);
        assertVotes(c, user, 0, 0, changeKind);
        assertVotes(c, user2, 1, 0, changeKind);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) ChangeKind(com.google.gerrit.extensions.client.ChangeKind) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 78 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithReviewerGroup.

@Test
public void pushForMasterWithReviewerGroup() throws Exception {
    TestAccount user2 = accountCreator.user2();
    String group = name("group");
    GroupInput gin = new GroupInput();
    gin.name = group;
    gin.members = ImmutableList.of(user.username(), user2.username());
    // TODO(dborowitz): Shouldn't be necessary; see ReviewerModifier.
    gin.visibleToAll = true;
    gApi.groups().create(gin);
    PushOneCommit.Result r = pushTo("refs/for/master%r=" + group);
    r.assertOkStatus();
    r.assertChange(Change.Status.NEW, null, ImmutableList.of(user, user2), ImmutableList.of());
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 79 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithNotify.

@Test
public void pushForMasterWithNotify() throws Exception {
    // create a user that watches the project
    TestAccount user3 = accountCreator.create("user3", "user3@example.com", "User3", null);
    List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
    ProjectWatchInfo pwi = new ProjectWatchInfo();
    pwi.project = project.get();
    pwi.filter = "*";
    pwi.notifyNewChanges = true;
    projectsToWatch.add(pwi);
    requestScopeOperations.setApiUser(user3.id());
    gApi.accounts().self().setWatchedProjects(projectsToWatch);
    TestAccount user2 = accountCreator.user2();
    String pushSpec = "refs/for/master%reviewer=" + user.email() + ",cc=" + user2.email();
    sender.clear();
    PushOneCommit.Result r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE);
    r.assertOkStatus();
    assertThat(sender.getMessages()).isEmpty();
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.OWNER);
    r.assertOkStatus();
    // no email notification about own changes
    assertThat(sender.getMessages()).isEmpty();
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.OWNER_REVIEWERS);
    r.assertOkStatus();
    assertThat(sender.getMessages()).hasSize(1);
    Message m = sender.getMessages().get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.ALL);
    r.assertOkStatus();
    assertThat(sender.getMessages()).hasSize(1);
    m = sender.getMessages().get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail(), user2.getNameEmail(), user3.getNameEmail());
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-to=" + user3.email());
    r.assertOkStatus();
    assertNotifyTo(user3);
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-cc=" + user3.email());
    r.assertOkStatus();
    assertNotifyCc(user3);
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-bcc=" + user3.email());
    r.assertOkStatus();
    assertNotifyBcc(user3);
    // request that sender gets notified as TO, CC and BCC, email should be sent
    // even if the sender is the only recipient
    sender.clear();
    pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-to=" + admin.email());
    assertNotifyTo(admin);
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-cc=" + admin.email());
    r.assertOkStatus();
    assertNotifyCc(admin);
    sender.clear();
    r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-bcc=" + admin.email());
    r.assertOkStatus();
    assertNotifyBcc(admin);
}
Also used : ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ChangeMessage(com.google.gerrit.entities.ChangeMessage) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) ArrayList(java.util.ArrayList) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 80 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithReviewer.

@Test
public void pushForMasterWithReviewer() throws Exception {
    // add one reviewer
    String topic = "my/topic";
    PushOneCommit.Result r = pushTo("refs/for/master%topic=" + topic + ",r=" + user.email());
    r.assertOkStatus();
    r.assertChange(Change.Status.NEW, topic, user);
    // add several reviewers
    TestAccount user2 = accountCreator.create("another-user", "another.user@example.com", "Another User", null);
    r = pushTo("refs/for/master%topic=" + topic + ",r=" + admin.email() + ",r=" + user.email() + ",r=" + user2.email());
    r.assertOkStatus();
    // admin is the owner of the change and should not appear as reviewer
    r.assertChange(Change.Status.NEW, topic, user, user2);
    // add non-existing user as reviewer
    String nonExistingEmail = "non.existing@example.com";
    r = pushTo("refs/for/master%topic=" + topic + ",r=" + admin.email() + ",r=" + nonExistingEmail + ",r=" + user.email());
    r.assertErrorStatus(nonExistingEmail + " does not identify a registered user or group");
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

TestAccount (com.google.gerrit.acceptance.TestAccount)137 Test (org.junit.Test)122 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)106 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)54 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)19 AbstractNotificationTest (com.google.gerrit.acceptance.AbstractNotificationTest)15 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)14 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)13 ArrayList (java.util.ArrayList)13 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)10 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)10 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)10 Message (com.google.gerrit.testing.FakeEmailSender.Message)10 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)9 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)9 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 AuthException (com.google.gerrit.extensions.restapi.AuthException)9 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)8 Change (com.google.gerrit.entities.Change)8