Search in sources :

Example 11 with UseClockStep

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

the class AbandonIT method notAbandonedIfMergeableWhenMergeableOperatorIsEnabled.

@Test
@UseClockStep
@GerritConfig(name = "changeCleanup.abandonAfter", value = "1w")
@GerritConfig(name = "changeCleanup.abandonIfMergeable", value = "false")
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "API_REF_UPDATED_AND_CHANGE_REINDEX")
public void notAbandonedIfMergeableWhenMergeableOperatorIsEnabled() throws Exception {
    ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
    // create 2 changes
    int id1 = createChange().getChange().getId().get();
    int id2 = createChange().getChange().getId().get();
    // create 2 changes that conflict with each other
    testRepo.reset(initial);
    int id3 = createChange("change 3", "file.txt", "content").getChange().getId().get();
    testRepo.reset(initial);
    int id4 = createChange("change 4", "file.txt", "other content").getChange().getId().get();
    // make all 4 previously created changes older than 1 week
    TestTimeUtil.incrementClock(7 * 24, HOURS);
    // create 1 new change that will not be abandoned because it is not older than 1 week
    testRepo.reset(initial);
    ChangeData cd = createChange().getChange();
    int id5 = cd.getId().get();
    assertThat(toChangeNumbers(query("is:open"))).containsExactly(id1, id2, id3, id4, id5);
    assertThat(query("is:abandoned")).isEmpty();
    // submit one of the conflicting changes
    gApi.changes().id(id3).current().review(ReviewInput.approve());
    gApi.changes().id(id3).current().submit();
    assertThat(toChangeNumbers(query("is:merged"))).containsExactly(id3);
    assertThat(toChangeNumbers(query("-is:mergeable"))).containsExactly(id4);
    abandonUtil.abandonInactiveOpenChanges(batchUpdateFactory);
    assertThat(toChangeNumbers(query("is:open"))).containsExactly(id5, id2, id1);
    assertThat(toChangeNumbers(query("is:abandoned"))).containsExactly(id4);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeData(com.google.gerrit.server.query.change.ChangeData) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 12 with UseClockStep

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

the class AbandonIT method abandonedIfMergeableWhenMergeableOperatorIsDisabled.

/**
 * When indexing mergeable is disabled then the abandonIfMergeable option is ineffective and the
 * auto abandon behaves as though it were set to its default value (true).
 */
@Test
@UseClockStep
@GerritConfig(name = "changeCleanup.abandonAfter", value = "1w")
@GerritConfig(name = "changeCleanup.abandonIfMergeable", value = "false")
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "NEVER")
public void abandonedIfMergeableWhenMergeableOperatorIsDisabled() throws Exception {
    ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
    // create 2 changes
    int id1 = createChange().getChange().getId().get();
    int id2 = createChange().getChange().getId().get();
    // create 2 changes that conflict with each other
    testRepo.reset(initial);
    int id3 = createChange("change 3", "file.txt", "content").getChange().getId().get();
    testRepo.reset(initial);
    int id4 = createChange("change 4", "file.txt", "other content").getChange().getId().get();
    // make all 4 previously created changes older than 1 week
    TestTimeUtil.incrementClock(7 * 24, HOURS);
    // create 1 new change that will not be abandoned because it is not older than 1 week
    testRepo.reset(initial);
    ChangeData cd = createChange().getChange();
    int id5 = cd.getId().get();
    assertThat(toChangeNumbers(query("is:open"))).containsExactly(id1, id2, id3, id4, id5);
    assertThat(query("is:abandoned")).isEmpty();
    // submit one of the conflicting changes
    gApi.changes().id(id3).current().review(ReviewInput.approve());
    gApi.changes().id(id3).current().submit();
    assertThat(toChangeNumbers(query("is:merged"))).containsExactly(id3);
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> query("-is:mergeable"));
    assertThat(thrown).hasMessageThat().contains("operator is not supported");
    abandonUtil.abandonInactiveOpenChanges(batchUpdateFactory);
    assertThat(toChangeNumbers(query("is:open"))).containsExactly(id5);
    assertThat(toChangeNumbers(query("is:abandoned"))).containsExactly(id4, id2, id1);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ChangeData(com.google.gerrit.server.query.change.ChangeData) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 13 with UseClockStep

use of com.google.gerrit.acceptance.UseClockStep 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 14 with UseClockStep

use of com.google.gerrit.acceptance.UseClockStep 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 15 with UseClockStep

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

the class ChangeIT method addReviewer.

@Test
@UseClockStep
public void addReviewer() throws Exception {
    testAddReviewerViaPostReview((changeId, reviewer) -> {
        ReviewerInput in = new ReviewerInput();
        in.reviewer = reviewer;
        gApi.changes().id(changeId).addReviewer(in);
    });
}
Also used : 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)

Aggregations

UseClockStep (com.google.gerrit.acceptance.UseClockStep)16 Test (org.junit.Test)16 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)11 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)8 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)7 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)6 Project (com.google.gerrit.entities.Project)5 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)5 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)4 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)4 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ImmutableList (com.google.common.collect.ImmutableList)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Account (com.google.gerrit.entities.Account)3 GerritJUnit.assertThrows (com.google.gerrit.testing.GerritJUnit.assertThrows)3 Inject (com.google.inject.Inject)3 Config (org.eclipse.jgit.lib.Config)3 PersonIdent (org.eclipse.jgit.lib.PersonIdent)3 ImmutableMap (com.google.common.collect.ImmutableMap)2