Search in sources :

Example 26 with PushOneCommit

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

the class CommentsIT method listComments.

@Test
public void listComments() throws Exception {
    String file = "file";
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "first subject", file, "contents");
    PushOneCommit.Result r = push.to("refs/for/master");
    String changeId = r.getChangeId();
    String revId = r.getCommit().getName();
    assertThat(getPublishedComments(changeId, revId)).isEmpty();
    List<CommentInput> expectedComments = new ArrayList<>();
    for (Integer line : lines) {
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment " + line, false);
        expectedComments.add(comment);
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
    }
    Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
    assertThat(result).isNotEmpty();
    List<CommentInfo> actualComments = result.get(file);
    assertThat(Lists.transform(actualComments, infoToInput(file))).containsExactlyElementsIn(expectedComments);
}
Also used : ArrayList(java.util.ArrayList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 27 with PushOneCommit

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

the class ProjectLevelConfigIT method accessProjectSpecificConfig.

@Test
public void accessProjectSpecificConfig() throws Exception {
    String configName = "test.config";
    Config cfg = new Config();
    cfg.setString("s1", null, "k1", "v1");
    cfg.setString("s2", "ss", "k2", "v2");
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "Create Project Level Config", configName, cfg.toText());
    push.to(RefNames.REFS_CONFIG);
    ProjectState state = projectCache.get(project);
    assertThat(state.getConfig(configName).get().toText()).isEqualTo(cfg.toText());
}
Also used : Config(org.eclipse.jgit.lib.Config) ProjectState(com.google.gerrit.server.project.ProjectState) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 28 with PushOneCommit

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

the class TagsIT method lightweightTag.

@Test
public void lightweightTag() throws Exception {
    grantTagPermissions();
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo);
    PushOneCommit.Result r = push.to("refs/heads/master");
    r.assertOkStatus();
    TagInput input = new TagInput();
    input.ref = "v1.0";
    input.revision = r.getCommit().getName();
    TagInfo result = tag(input.ref).create(input).get();
    assertThat(result.ref).isEqualTo(R_TAGS + input.ref);
    assertThat(result.revision).isEqualTo(input.revision);
    assertThat(result.canDelete).isTrue();
    input.ref = "refs/tags/v2.0";
    result = tag(input.ref).create(input).get();
    assertThat(result.ref).isEqualTo(input.ref);
    assertThat(result.revision).isEqualTo(input.revision);
    assertThat(result.canDelete).isTrue();
    setApiUser(user);
    result = tag(input.ref).get();
    assertThat(result.canDelete).isFalse();
    eventRecorder.assertRefUpdatedEvents(project.get(), result.ref, null, result.revision);
}
Also used : TagInfo(com.google.gerrit.extensions.api.projects.TagInfo) TagInput(com.google.gerrit.extensions.api.projects.TagInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 29 with PushOneCommit

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

the class ChangeIT method createNewPatchSetOnInvisibleDraftPatchSet.

@Test
public void createNewPatchSetOnInvisibleDraftPatchSet() throws Exception {
    // Clone separate repositories of the same project as admin and as user
    TestRepository<InMemoryRepository> adminTestRepo = cloneProject(project, admin);
    TestRepository<InMemoryRepository> userTestRepo = cloneProject(project, user);
    // Create change as admin
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), adminTestRepo);
    PushOneCommit.Result r1 = push.to("refs/for/master");
    r1.assertOkStatus();
    // Amend draft as admin
    PushOneCommit.Result r2 = amendChange(r1.getChangeId(), "refs/drafts/master", admin, adminTestRepo);
    r2.assertOkStatus();
    // Fetch change
    GitUtil.fetch(userTestRepo, r1.getPatchSet().getRefName() + ":ps");
    userTestRepo.reset("ps");
    // Amend change as user
    PushOneCommit.Result r3 = amendChange(r1.getChangeId(), "refs/for/master", user, userTestRepo);
    r3.assertErrorStatus("cannot add patch set to " + r3.getChange().change().getChangeId() + ".");
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 30 with PushOneCommit

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

the class ChangeIT method pushCommitOfOtherUser.

@Test
public void pushCommitOfOtherUser() throws Exception {
    // admin pushes commit of user
    PushOneCommit push = pushFactory.create(db, user.getIdent(), testRepo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id.get());
    CommitInfo commit = change.revisions.get(change.currentRevision).commit;
    assertThat(commit.author.email).isEqualTo(user.email);
    assertThat(commit.committer.email).isEqualTo(user.email);
    // check that the author/committer was added as reviewer
    Collection<AccountInfo> reviewers = change.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.getId().get());
    assertThat(change.reviewers.get(CC)).isNull();
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.emailAddress);
    assertThat(m.body()).contains(admin.fullName + " has uploaded this change for review");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertMailReplyTo(m, admin.email);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testutil.FakeEmailSender.Message) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)91 Test (org.junit.Test)76 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)72 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)17 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)14 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)13 Project (com.google.gerrit.reviewdb.client.Project)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)9 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)7 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)6 ImmutableList (com.google.common.collect.ImmutableList)5 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)5 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)5 IdString (com.google.gerrit.extensions.restapi.IdString)5 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)5 ArrayList (java.util.ArrayList)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)4 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)4