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);
}
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);
}
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);
}
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);
}
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);
});
}
Aggregations