Search in sources :

Example 71 with TestAccount

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

the class ChangeNotificationsIT method commentOnReviewableWipChangeByBotNotifyAll.

@Test
public void commentOnReviewableWipChangeByBotNotifyAll() throws Exception {
    StagedChange sc = stageWipChange();
    TestAccount bot = sc.testAccount("bot");
    review(bot, sc.changeId, ENABLED, ALL, "tag");
    assertThat(sender).sent("comment", sc).to(sc.owner).cc(sc.reviewer, sc.ccer).cc(StagedUsers.REVIEWER_BY_EMAIL, StagedUsers.CC_BY_EMAIL).bcc(sc.starrer).bcc(ALL_COMMENTS).noOneElse();
    assertThat(sender).didNotSend();
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) AbstractNotificationTest(com.google.gerrit.acceptance.AbstractNotificationTest) Test(org.junit.Test)

Example 72 with TestAccount

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

the class GroupsIT method addMultipleMembers.

@Test
public void addMultipleMembers() throws Exception {
    String g = createGroup("users");
    TestAccount u1 = accounts.create("u1", "u1@example.com", "Full Name 1");
    TestAccount u2 = accounts.create("u2", "u2@example.com", "Full Name 2");
    gApi.groups().id(g).addMembers(u1.username, u2.username);
    assertMembers(g, u1, u2);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 73 with TestAccount

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

the class ChangeReviewersIT method assertReviewers.

private static void assertReviewers(ChangeInfo c, ReviewerState reviewerState, TestAccount... accounts) throws Exception {
    List<TestAccount> accountList = new ArrayList<>(accounts.length);
    for (TestAccount a : accounts) {
        accountList.add(a);
    }
    assertReviewers(c, reviewerState, accountList);
}
Also used : ArrayList(java.util.ArrayList) TestAccount(com.google.gerrit.acceptance.TestAccount)

Example 74 with TestAccount

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

the class SuggestReviewersIT method reviewerRankingProjectIsolation.

@Test
public void reviewerRankingProjectIsolation() throws Exception {
    // Create new project
    Project.NameKey newProject = createProject("test");
    // Create users who review changes in both the default and the new project
    String fullName = "Primum Finalis";
    TestAccount userWhoOwns = user("customuser1", fullName);
    TestAccount reviewer1 = user("customuser2", fullName);
    TestAccount reviewer2 = user("customuser3", fullName);
    setApiUser(userWhoOwns);
    String changeId1 = createChangeFromApi();
    setApiUser(reviewer1);
    reviewChange(changeId1);
    setApiUser(userWhoOwns);
    String changeId2 = createChangeFromApi(newProject);
    setApiUser(reviewer2);
    reviewChange(changeId2);
    setApiUser(userWhoOwns);
    String changeId3 = createChangeFromApi(newProject);
    setApiUser(reviewer2);
    reviewChange(changeId3);
    setApiUser(userWhoOwns);
    List<SuggestedReviewerInfo> reviewers = suggestReviewers(createChangeFromApi(), "Prim", 4);
    // Assert that reviewer1 is on top, even though reviewer2 has more reviews
    // in other projects
    assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer1.id.get(), reviewer2.id.get()).inOrder();
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 75 with TestAccount

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

the class PostReviewIT method deletingReviewers.

@Test
public void deletingReviewers() throws Exception {
    PushOneCommit.Result r = createChange();
    TestAccount user2 = accountCreator.user2();
    // add user and user2
    gApi.changes().id(r.getChangeId()).current().review(ReviewInput.create().reviewer(user.email()).reviewer(user2.email()));
    sender.clear();
    TestReviewerDeletedListener testReviewerDeletedListener = new TestReviewerDeletedListener();
    try (Registration registration = extensionRegistry.newRegistration().add(testReviewerDeletedListener)) {
        // remove user and user2
        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));
        assertThat(reviewResult.reviewers.values().stream().map(a -> a.removed.name).collect(toImmutableSet())).containsExactly(user.fullName(), user2.fullName());
    }
    assertThat(gApi.changes().id(r.getChangeId()).reviewers()).isEmpty();
    // Ensure only one batch email was sent for this operation
    FakeEmailSender.Message message = Iterables.getOnlyElement(sender.getMessages());
    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:
    // * 2 events for removing user and user2 as reviewers (one event per removed reviewer, batch
    // event not available for reviewer removal)
    assertThat(testReviewerDeletedListener.receivedEvents).hasSize(2);
    assertThat(testReviewerDeletedListener.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)

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