Search in sources :

Example 46 with ReviewerInput

use of com.google.gerrit.extensions.api.changes.ReviewerInput in project gerrit by GerritCodeReview.

the class ChangeIT method addGroupAsReviewersWhenANotPerfectMatchedUserExists.

@Test
@UseClockStep
public void addGroupAsReviewersWhenANotPerfectMatchedUserExists() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Instant oldTs = rsrc.getChange().getLastUpdatedOn();
    // create a group named "kobe" with one user: lee
    String testUserFullname = "kobebryant";
    accountOperations.newAccount().username("kobebryant").preferredEmail("kobebryant@example.com").fullname(testUserFullname).create();
    String myGroupUserEmail = "lee@example.com";
    String myGroupUserFullname = "lee";
    Account.Id accountIdOfGroupUser = accountOperations.newAccount().username("lee").preferredEmail(myGroupUserEmail).fullname(myGroupUserFullname).create();
    String testGroup = groupOperations.newGroup().name("kobe").create().get();
    GroupApi groupApi = gApi.groups().id(testGroup);
    groupApi.description("test group");
    groupApi.addMembers(myGroupUserFullname);
    // ensure that user "user" is not in the group
    groupApi.removeMembers(testUserFullname);
    ReviewerInput in = new ReviewerInput();
    in.reviewer = testGroup;
    gApi.changes().id(r.getChangeId()).addReviewer(in.reviewer);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(Address.create(myGroupUserFullname, myGroupUserEmail));
    assertThat(m.body()).contains("Hello " + myGroupUserFullname + ",\n");
    assertThat(m.body()).contains("I'd like you to do a code review.");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertMailReplyTo(m, myGroupUserEmail);
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    // Adding a reviewer records that user as reviewer.
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(accountIdOfGroupUser.get());
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Instant(java.time.Instant) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeResource(com.google.gerrit.server.change.ChangeResource) GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 47 with ReviewerInput

use of com.google.gerrit.extensions.api.changes.ReviewerInput in project gerrit by GerritCodeReview.

the class ChangeIT method addReviewerThatIsNotPerfectMatch.

@Test
@UseClockStep
public void addReviewerThatIsNotPerfectMatch() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Instant oldTs = rsrc.getChange().getLastUpdatedOn();
    // create a group named "ab" with one user: testUser
    String email = "abcd@example.com";
    String fullname = "abcd";
    Account.Id accountIdOfTestUser = accountOperations.newAccount().username("abcd").preferredEmail(email).fullname(fullname).create();
    String testGroup = groupOperations.newGroup().name("ab").create().get();
    GroupApi groupApi = gApi.groups().id(testGroup);
    groupApi.description("test group");
    groupApi.addMembers(user.fullName());
    ReviewerInput in = new ReviewerInput();
    in.reviewer = "abc";
    gApi.changes().id(r.getChangeId()).addReviewer(in.reviewer);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(Address.create(fullname, email));
    assertThat(m.body()).contains("Hello " + fullname + ",\n");
    assertThat(m.body()).contains("I'd like you to do a code review.");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertMailReplyTo(m, email);
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    // Adding a reviewer records that user as reviewer.
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(accountIdOfTestUser.get());
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Instant(java.time.Instant) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeResource(com.google.gerrit.server.change.ChangeResource) GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 48 with ReviewerInput

use of com.google.gerrit.extensions.api.changes.ReviewerInput in project gerrit by GerritCodeReview.

the class ChangeIT method listReviewers.

@Test
public void listReviewers() throws Exception {
    PushOneCommit.Result r = createChange();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    assertThat(gApi.changes().id(r.getChangeId()).reviewers()).hasSize(1);
    String username1 = name("user1");
    String email1 = username1 + "@example.com";
    accountOperations.newAccount().username(username1).preferredEmail(email1).fullname("User1").create();
    in.reviewer = email1;
    in.state = ReviewerState.CC;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    assertThat(gApi.changes().id(r.getChangeId()).reviewers().stream().map(a -> a.username)).containsExactly(user.username(), username1);
}
Also used : PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 49 with ReviewerInput

use of com.google.gerrit.extensions.api.changes.ReviewerInput in project gerrit by GerritCodeReview.

the class ChangeIT method checkReviewedFlagBeforeAndAfterReview.

@Test
public void checkReviewedFlagBeforeAndAfterReview() throws Exception {
    PushOneCommit.Result r = createChange();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    requestScopeOperations.setApiUser(user.id());
    assertThat(get(r.getChangeId(), REVIEWED).reviewed).isNull();
    revision(r).review(ReviewInput.recommend());
    assertThat(get(r.getChangeId(), REVIEWED).reviewed).isTrue();
}
Also used : PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 50 with ReviewerInput

use of com.google.gerrit.extensions.api.changes.ReviewerInput in project gerrit by GerritCodeReview.

the class ChangeIT method addReviewerThatCannotSeeChange.

@Test
public void addReviewerThatCannotSeeChange() throws Exception {
    // create hidden project that is only visible to administrators
    Project.NameKey p = projectOperations.newProject().create();
    projectOperations.project(p).forUpdate().add(allow(Permission.READ).ref("refs/*").group(adminGroupUuid())).add(block(Permission.READ).ref("refs/*").group(REGISTERED_USERS)).update();
    // create change
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(admin.newIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    // check the user cannot see the change
    requestScopeOperations.setApiUser(user.id());
    assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(result.getChangeId()).get());
    // try to add user as reviewer
    requestScopeOperations.setApiUser(admin.id());
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    ReviewerResult r = gApi.changes().id(result.getChangeId()).addReviewer(in);
    assertThat(r.input).isEqualTo(user.email());
    assertThat(r.error).contains("does not have permission to see this change");
    assertThat(r.reviewers).isNull();
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)72 Test (org.junit.Test)67 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)60 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)46 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)25 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)22 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)20 TestAccount (com.google.gerrit.acceptance.TestAccount)14 Message (com.google.gerrit.testing.FakeEmailSender.Message)14 ReviewerResult (com.google.gerrit.extensions.api.changes.ReviewerResult)13 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)11 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 Account (com.google.gerrit.entities.Account)10 Change (com.google.gerrit.entities.Change)7 UseClockStep (com.google.gerrit.acceptance.UseClockStep)5 ReviewerInfo (com.google.gerrit.extensions.api.changes.ReviewerInfo)5 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)5 Instant (java.time.Instant)5 ArrayList (java.util.ArrayList)5