Search in sources :

Example 81 with PushOneCommit

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

the class AccessIT method unknownPermissionRemainsUnchanged.

@Test
public void unknownPermissionRemainsUnchanged() throws Exception {
    String access = "access";
    String unknownPermission = "unknownPermission";
    String registeredUsers = "group Registered Users";
    String refsFor = "refs/for/*";
    // Clone repository to forcefully add permission
    TestRepository<InMemoryRepository> allProjectsRepo = cloneProject(allProjects, admin);
    // Fetch permission ref
    GitUtil.fetch(allProjectsRepo, "refs/meta/config:cfg");
    allProjectsRepo.reset("cfg");
    // Load current permissions
    String config = gApi.projects().name(allProjects.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
    // Append and push unknown permission
    Config cfg = new Config();
    cfg.fromText(config);
    cfg.setString(access, refsFor, unknownPermission, registeredUsers);
    config = cfg.toText();
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), allProjectsRepo, "Subject", "project.config", config);
    push.to(RefNames.REFS_CONFIG).assertOkStatus();
    // Verify that unknownPermission is present
    config = gApi.projects().name(allProjects.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
    cfg.fromText(config);
    assertThat(cfg.getString(access, refsFor, unknownPermission)).isEqualTo(registeredUsers);
    // Make permission change through API
    ProjectAccessInput accessInput = newProjectAccessInput();
    AccessSectionInfo accessSectionInfo = createDefaultAccessSectionInfo();
    accessInput.add.put(refsFor, accessSectionInfo);
    gApi.projects().name(allProjects.get()).access(accessInput);
    accessInput.add.clear();
    accessInput.remove.put(refsFor, accessSectionInfo);
    gApi.projects().name(allProjects.get()).access(accessInput);
    // Verify that unknownPermission is still present
    config = gApi.projects().name(allProjects.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
    cfg.fromText(config);
    assertThat(cfg.getString(access, refsFor, unknownPermission)).isEqualTo(registeredUsers);
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Config(org.eclipse.jgit.lib.Config) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) ProjectAccessInput(com.google.gerrit.extensions.api.access.ProjectAccessInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 82 with PushOneCommit

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

the class CommentsIT method insertCommentsWithHistoricTimestamp.

@Test
public void insertCommentsWithHistoricTimestamp() throws Exception {
    Timestamp timestamp = new Timestamp(0);
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        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();
        Timestamp origLastUpdated = r.getChange().change().getLastUpdatedOn();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        comment.updated = timestamp;
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        ChangeResource changeRsrc = changes.get().parse(TopLevelResource.INSTANCE, IdString.fromDecoded(changeId));
        RevisionResource revRsrc = revisions.parse(changeRsrc, IdString.fromDecoded(revId));
        postReview.get().apply(batchUpdateFactory, revRsrc, input, timestamp);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        assertThat(result).isNotEmpty();
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        CommentInput ci = infoToInput(file).apply(actual);
        ci.updated = comment.updated;
        assertThat(comment).isEqualTo(ci);
        assertThat(actual.updated).isEqualTo(gApi.changes().id(r.getChangeId()).info().created);
        // Updating historic comments doesn't cause lastUpdatedOn to regress.
        assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
    }
}
Also used : RevisionResource(com.google.gerrit.server.change.RevisionResource) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Timestamp(java.sql.Timestamp) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeResource(com.google.gerrit.server.change.ChangeResource) 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 83 with PushOneCommit

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

the class CommentsIT method postCommentWithReply.

@Test
public void postCommentWithReply() throws Exception {
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        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();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        input = new ReviewInput();
        comment = newComment(file, Side.REVISION, line, "comment 1 reply", false);
        comment.inReplyTo = actual.id;
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
        result = getPublishedComments(changeId, revId);
        actual = result.get(comment.path).get(1);
        assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
        assertThat(comment).isEqualTo(infoToInput(file).apply(getPublishedComment(changeId, revId, actual.id)));
    }
}
Also used : 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) 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) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 84 with PushOneCommit

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

the class CommentsIT method postComment.

@Test
public void postComment() throws Exception {
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        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();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        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();
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
        assertThat(comment).isEqualTo(infoToInput(file).apply(getPublishedComment(changeId, revId, actual.id)));
    }
}
Also used : 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) 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) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 85 with PushOneCommit

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

the class CommentsIT method postCommentWithUnresolved.

@Test
public void postCommentWithUnresolved() throws Exception {
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        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();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", true);
        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();
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
        assertThat(comment).isEqualTo(infoToInput(file).apply(getPublishedComment(changeId, revId, actual.id)));
    }
}
Also used : 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) 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) 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