Search in sources :

Example 1 with UseClockStep

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);
}
Also used : 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 2 with UseClockStep

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);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Patch(com.google.gerrit.entities.Patch) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Map(java.util.Map) Side(com.google.gerrit.extensions.client.Side) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.RobotCommentInfoSubject.assertThatList) ChangeOperations(com.google.gerrit.acceptance.testsuite.change.ChangeOperations) ImmutableMap(com.google.common.collect.ImmutableMap) IntraLineStatus(com.google.gerrit.extensions.common.DiffInfo.IntraLineStatus) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) Objects(java.util.Objects) UseClockStep(com.google.gerrit.acceptance.UseClockStep) List(java.util.List) BinaryResultSubject(com.google.gerrit.extensions.restapi.testing.BinaryResultSubject) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) EditInfo(com.google.gerrit.extensions.common.EditInfo) Iterables(com.google.common.collect.Iterables) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) Comment(com.google.gerrit.extensions.client.Comment) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) DiffInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) TestCommentHelper(com.google.gerrit.testing.TestCommentHelper) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) TestTimeUtil(com.google.gerrit.testing.TestTimeUtil) Before(org.junit.Before) FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) TimeUnit(java.util.concurrent.TimeUnit) ChangeType(com.google.gerrit.extensions.common.ChangeType) Collectors.toList(java.util.stream.Collectors.toList) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Collections(java.util.Collections) EditInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.EditInfoSubject.assertThat) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.RobotCommentInfoSubject.assertThatList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 3 with UseClockStep

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();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 4 with UseClockStep

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());
}
Also used : Project(com.google.gerrit.entities.Project) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Config(org.eclipse.jgit.lib.Config) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 5 with UseClockStep

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());
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Config(org.eclipse.jgit.lib.Config) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) 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