use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class AbandonIT method abandonInactiveOpenChanges.
@Test
@UseClockStep
@GerritConfig(name = "changeCleanup.abandonAfter", value = "1w")
public void abandonInactiveOpenChanges() throws Exception {
// create 2 changes which will be abandoned ...
int id1 = createChange().getChange().getId().get();
int id2 = createChange().getChange().getId().get();
// ... because they are older than 1 week
TestTimeUtil.incrementClock(7 * 24, HOURS);
// create 1 new change that will not be abandoned
ChangeData cd = createChange().getChange();
int id3 = cd.getId().get();
assertThat(toChangeNumbers(query("is:open"))).containsExactly(id1, id2, id3);
assertThat(query("is:abandoned")).isEmpty();
abandonUtil.abandonInactiveOpenChanges(batchUpdateFactory);
assertThat(toChangeNumbers(query("is:open"))).containsExactly(id3);
assertThat(toChangeNumbers(query("is:abandoned"))).containsExactly(id1, id2);
}
use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class RobotCommentsIT method addedRobotCommentsAreLinkedToChangeMessages.
@UseClockStep
@Test
public void addedRobotCommentsAreLinkedToChangeMessages() throws Exception {
// Advancing the time after creating the change so that the first robot comment is not in the
// same timestamp as with the change creation.
TestTimeUtil.incrementClock(10, TimeUnit.SECONDS);
RobotCommentInput c1 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
RobotCommentInput c2 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
RobotCommentInput c3 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
// Give the robot comments identifiable names for testing
c1.message = "robot comment 1";
c2.message = "robot comment 2";
c3.message = "robot comment 3";
testCommentHelper.addRobotComment(changeId, c1, "robot message 1");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
testCommentHelper.addRobotComment(changeId, c2, "robot message 2");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
testCommentHelper.addRobotComment(changeId, c3, "robot message 3");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
Map<String, List<RobotCommentInfo>> robotComments = gApi.changes().id(changeId).robotComments();
List<RobotCommentInfo> robotCommentsList = robotComments.values().stream().flatMap(List::stream).collect(toList());
List<ChangeMessageInfo> allMessages = gApi.changes().id(changeId).get(MESSAGES).messages.stream().collect(toList());
assertThat(allMessages.stream().map(cm -> cm.message).collect(toList())).containsExactly("Uploaded patch set 1.", "Patch Set 1:\n\n(1 comment)\n\nrobot message 1", "Patch Set 1:\n\n(1 comment)\n\nrobot message 2", "Patch Set 1:\n\n(1 comment)\n\nrobot message 3");
assertThat(robotCommentsList.stream().map(c -> c.message).collect(toList())).containsExactly("robot comment 1", "robot comment 2", "robot comment 3");
String message1ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 1")).collect(onlyElement()).id;
String message2ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 2")).collect(onlyElement()).id;
String message3ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 3")).collect(onlyElement()).id;
String comment1MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 1")).collect(onlyElement()).changeMessageId;
String comment2MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 2")).collect(onlyElement()).changeMessageId;
String comment3MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 3")).collect(onlyElement()).changeMessageId;
/**
* All change messages have the auto-generated tag. Robot comments can be linked to
* auto-generated messages where each comment is linked to the next nearest change message in
* timestamp
*/
assertThat(message1ChangeId).isEqualTo(comment1MessageId);
assertThat(message2ChangeId).isEqualTo(comment2MessageId);
assertThat(message3ChangeId).isEqualTo(comment3MessageId);
}
use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickSetsReadyChangeOnNewPatchset.
@Test
@UseClockStep
public void cherryPickSetsReadyChangeOnNewPatchset() throws Exception {
PushOneCommit.Result result = pushTo("refs/for/master");
CherryPickInput input = new CherryPickInput();
input.destination = "foo";
gApi.projects().name(project.get()).branch(input.destination).create(new BranchInput());
ChangeApi originalChange = gApi.changes().id(project.get() + "~master~" + result.getChangeId());
ChangeApi cherryPick = originalChange.revision(result.getCommit().name()).cherryPick(input);
String firstCherryPickChangeId = cherryPick.id();
cherryPick.setWorkInProgress();
gApi.changes().id(project.get() + "~master~" + result.getChangeId()).revision(result.getCommit().name()).cherryPick(input);
ChangeInfo secondCherryPickResult = gApi.changes().id(firstCherryPickChangeId).get(ALL_REVISIONS);
assertThat(secondCherryPickResult.revisions).hasSize(2);
assertThat(secondCherryPickResult.workInProgress).isNull();
}
use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class SubmoduleSubscriptionsIT method superRepoCommitHasSameAuthorAsSubmoduleCommits.
@Test
@UseClockStep
public void superRepoCommitHasSameAuthorAsSubmoduleCommits() throws Exception {
assume().that(isSubmitWholeTopicEnabled()).isTrue();
Project.NameKey proj2 = createProjectForPush(getSubmitType());
TestRepository<?> subRepo2 = cloneProject(proj2);
allowMatchingSubmoduleSubscription(subKey, "refs/heads/master", superKey, "refs/heads/master");
allowMatchingSubmoduleSubscription(proj2, "refs/heads/master", superKey, "refs/heads/master");
Config config = new Config();
prepareSubmoduleConfigEntry(config, subKey, subKey, "master");
prepareSubmoduleConfigEntry(config, proj2, proj2, "master");
pushSubmoduleConfig(superRepo, "master", config);
String topic = "foo";
PushOneCommit.Result pushResult1 = createChange(subRepo, "refs/heads/master", "Change 1", "a.txt", "some content", topic);
approve(pushResult1.getChangeId());
PushOneCommit.Result pushResult2 = createChange(subRepo2, "refs/heads/master", "Change 2", "b.txt", "other content", topic);
approve(pushResult2.getChangeId());
// Submit the topic, 2 changes with the same author.
gApi.changes().id(pushResult1.getChangeId()).current().submit();
// Expect that the author name/email is preserved for the superRepo commit, but a new author
// timestamp is used.
PersonIdent authorIdent = getAuthor(superRepo, "master");
assertThat(authorIdent.getName()).isEqualTo(admin.fullName());
assertThat(authorIdent.getEmailAddress()).isEqualTo(admin.email());
assertThat(authorIdent.getWhen()).isGreaterThan(pushResult1.getCommit().getAuthorIdent().getWhen());
assertThat(authorIdent.getWhen()).isGreaterThan(pushResult2.getCommit().getAuthorIdent().getWhen());
}
use of com.google.gerrit.acceptance.UseClockStep in project gerrit by GerritCodeReview.
the class SubmoduleSubscriptionsIT method superRepoCommitHasGerritAsAuthorIfAuthorsOfSubmoduleCommitsDiffer.
@Test
@UseClockStep
public void superRepoCommitHasGerritAsAuthorIfAuthorsOfSubmoduleCommitsDiffer() throws Exception {
assume().that(isSubmitWholeTopicEnabled()).isTrue();
Project.NameKey proj2 = createProjectForPush(getSubmitType());
TestRepository<InMemoryRepository> repo2 = cloneProject(proj2, user);
allowMatchingSubmoduleSubscription(subKey, "refs/heads/master", superKey, "refs/heads/master");
allowMatchingSubmoduleSubscription(proj2, "refs/heads/master", superKey, "refs/heads/master");
Config config = new Config();
prepareSubmoduleConfigEntry(config, subKey, subKey, "master");
prepareSubmoduleConfigEntry(config, proj2, proj2, "master");
pushSubmoduleConfig(superRepo, "master", config);
String topic = "foo";
// Create change as admin.
PushOneCommit.Result pushResult1 = createChange(subRepo, "refs/heads/master", "Change 1", "a.txt", "some content", topic);
approve(pushResult1.getChangeId());
// Create change as user.
PushOneCommit push = pushFactory.create(user.newIdent(), repo2, "Change 2", "b.txt", "other content");
PushOneCommit.Result pushResult2 = push.to("refs/for/master%topic=" + name(topic));
approve(pushResult2.getChangeId());
// Submit the topic, 2 changes with the different author.
gApi.changes().id(pushResult1.getChangeId()).current().submit();
// Expect that the Gerrit server identity is chosen as author for the superRepo commit and a
// new author timestamp is used.
PersonIdent authorIdent = getAuthor(superRepo, "master");
assertThat(authorIdent.getName()).isEqualTo(serverIdent.get().getName());
assertThat(authorIdent.getEmailAddress()).isEqualTo(serverIdent.get().getEmailAddress());
assertThat(authorIdent.getWhen()).isGreaterThan(pushResult1.getCommit().getAuthorIdent().getWhen());
assertThat(authorIdent.getWhen()).isGreaterThan(pushResult2.getCommit().getAuthorIdent().getWhen());
}
Aggregations