Search in sources :

Example 11 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byComment.

@Test
public void byComment() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins = newChange(repo);
    Change change = insert(repo, ins);
    ReviewInput input = new ReviewInput();
    input.message = "toplevel";
    ReviewInput.CommentInput commentInput = new ReviewInput.CommentInput();
    commentInput.line = 1;
    commentInput.message = "inline";
    input.comments = ImmutableMap.<String, List<ReviewInput.CommentInput>>of(Patch.COMMIT_MSG, ImmutableList.<ReviewInput.CommentInput>of(commentInput));
    gApi.changes().id(change.getId().get()).current().review(input);
    Map<String, List<CommentInfo>> comments = gApi.changes().id(change.getId().get()).current().comments();
    assertThat(comments).hasSize(1);
    CommentInfo comment = Iterables.getOnlyElement(comments.get(Patch.COMMIT_MSG));
    assertThat(comment.message).isEqualTo(commentInput.message);
    ChangeMessageInfo lastMsg = Iterables.getLast(gApi.changes().id(change.getId().get()).get().messages, null);
    assertThat(lastMsg.message).isEqualTo("Patch Set 1:\n\n(1 comment)\n\n" + input.message);
    assertQuery("comment:foo");
    assertQuery("comment:toplevel", change);
    assertQuery("comment:inline", change);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Change(com.google.gerrit.reviewdb.client.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test)

Example 12 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byLabel.

@Test
public void byLabel() throws Exception {
    accountManager.authenticate(AuthRequest.forUser("anotheruser"));
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins = newChange(repo, null, null, null, null);
    ChangeInserter ins2 = newChange(repo, null, null, null, null);
    ChangeInserter ins3 = newChange(repo, null, null, null, null);
    ChangeInserter ins4 = newChange(repo, null, null, null, null);
    ChangeInserter ins5 = newChange(repo, null, null, null, null);
    Change reviewMinus2Change = insert(repo, ins);
    gApi.changes().id(reviewMinus2Change.getId().get()).current().review(ReviewInput.reject());
    Change reviewMinus1Change = insert(repo, ins2);
    gApi.changes().id(reviewMinus1Change.getId().get()).current().review(ReviewInput.dislike());
    Change noLabelChange = insert(repo, ins3);
    Change reviewPlus1Change = insert(repo, ins4);
    gApi.changes().id(reviewPlus1Change.getId().get()).current().review(ReviewInput.recommend());
    Change reviewPlus2Change = insert(repo, ins5);
    gApi.changes().id(reviewPlus2Change.getId().get()).current().review(ReviewInput.approve());
    Map<String, Short> m = gApi.changes().id(reviewPlus1Change.getId().get()).reviewer(user.getAccountId().toString()).votes();
    assertThat(m).hasSize(1);
    assertThat(m).containsEntry("Code-Review", Short.valueOf((short) 1));
    Map<Integer, Change> changes = new LinkedHashMap<>(5);
    changes.put(2, reviewPlus2Change);
    changes.put(1, reviewPlus1Change);
    changes.put(0, noLabelChange);
    changes.put(-1, reviewMinus1Change);
    changes.put(-2, reviewMinus2Change);
    assertQuery("label:Code-Review=-2", reviewMinus2Change);
    assertQuery("label:Code-Review-2", reviewMinus2Change);
    assertQuery("label:Code-Review=-1", reviewMinus1Change);
    assertQuery("label:Code-Review-1", reviewMinus1Change);
    assertQuery("label:Code-Review=0", noLabelChange);
    assertQuery("label:Code-Review=+1", reviewPlus1Change);
    assertQuery("label:Code-Review=1", reviewPlus1Change);
    assertQuery("label:Code-Review+1", reviewPlus1Change);
    assertQuery("label:Code-Review=+2", reviewPlus2Change);
    assertQuery("label:Code-Review=2", reviewPlus2Change);
    assertQuery("label:Code-Review+2", reviewPlus2Change);
    assertQuery("label:Code-Review>-3", codeReviewInRange(changes, -2, 2));
    assertQuery("label:Code-Review>=-2", codeReviewInRange(changes, -2, 2));
    assertQuery("label:Code-Review>-2", codeReviewInRange(changes, -1, 2));
    assertQuery("label:Code-Review>=-1", codeReviewInRange(changes, -1, 2));
    assertQuery("label:Code-Review>-1", codeReviewInRange(changes, 0, 2));
    assertQuery("label:Code-Review>=0", codeReviewInRange(changes, 0, 2));
    assertQuery("label:Code-Review>0", codeReviewInRange(changes, 1, 2));
    assertQuery("label:Code-Review>=1", codeReviewInRange(changes, 1, 2));
    assertQuery("label:Code-Review>1", reviewPlus2Change);
    assertQuery("label:Code-Review>=2", reviewPlus2Change);
    assertQuery("label:Code-Review>2");
    assertQuery("label:Code-Review<=2", codeReviewInRange(changes, -2, 2));
    assertQuery("label:Code-Review<2", codeReviewInRange(changes, -2, 1));
    assertQuery("label:Code-Review<=1", codeReviewInRange(changes, -2, 1));
    assertQuery("label:Code-Review<1", codeReviewInRange(changes, -2, 0));
    assertQuery("label:Code-Review<=0", codeReviewInRange(changes, -2, 0));
    assertQuery("label:Code-Review<0", codeReviewInRange(changes, -2, -1));
    assertQuery("label:Code-Review<=-1", codeReviewInRange(changes, -2, -1));
    assertQuery("label:Code-Review<-1", reviewMinus2Change);
    assertQuery("label:Code-Review<=-2", reviewMinus2Change);
    assertQuery("label:Code-Review<-2");
    assertQuery("label:Code-Review=+1,anotheruser");
    assertQuery("label:Code-Review=+1,user", reviewPlus1Change);
    assertQuery("label:Code-Review=+1,user=user", reviewPlus1Change);
    assertQuery("label:Code-Review=+1,Administrators", reviewPlus1Change);
    assertQuery("label:Code-Review=+1,group=Administrators", reviewPlus1Change);
    assertQuery("label:Code-Review=+1,user=owner", reviewPlus1Change);
    assertQuery("label:Code-Review=+1,owner", reviewPlus1Change);
    assertQuery("label:Code-Review=+2,owner", reviewPlus2Change);
    assertQuery("label:Code-Review=-2,owner", reviewMinus2Change);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.reviewdb.client.Change) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 13 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byStatus.

@Test
public void byStatus() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
    Change change1 = insert(repo, ins1);
    ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.MERGED);
    Change change2 = insert(repo, ins2);
    assertQuery("status:new", change1);
    assertQuery("status:NEW", change1);
    assertQuery("is:new", change1);
    assertQuery("status:merged", change2);
    assertQuery("is:merged", change2);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 14 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byLabelNotOwner.

@Test
public void byLabelNotOwner() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins = newChange(repo, null, null, null, null);
    Account.Id user1 = createAccount("user1");
    Change reviewPlus1Change = insert(repo, ins);
    // post a review with user1
    requestContext.setContext(newRequestContext(user1));
    gApi.changes().id(reviewPlus1Change.getId().get()).current().review(ReviewInput.recommend());
    assertQuery("label:Code-Review=+1,user=user1", reviewPlus1Change);
    assertQuery("label:Code-Review=+1,owner");
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 15 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byTopic.

@Test
public void byTopic() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins1 = newChangeWithTopic(repo, "feature1");
    Change change1 = insert(repo, ins1);
    ChangeInserter ins2 = newChangeWithTopic(repo, "feature2");
    Change change2 = insert(repo, ins2);
    ChangeInserter ins3 = newChangeWithTopic(repo, "Cherrypick-feature2");
    Change change3 = insert(repo, ins3);
    ChangeInserter ins4 = newChangeWithTopic(repo, "feature2-fixup");
    Change change4 = insert(repo, ins4);
    Change change5 = insert(repo, newChange(repo));
    assertQuery("intopic:foo");
    assertQuery("intopic:feature1", change1);
    assertQuery("intopic:feature2", change4, change3, change2);
    assertQuery("topic:feature2", change2);
    assertQuery("intopic:feature2", change4, change3, change2);
    assertQuery("intopic:fixup", change4);
    assertQuery("topic:\"\"", change5);
    assertQuery("intopic:\"\"", change5);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Aggregations

ChangeInserter (com.google.gerrit.server.change.ChangeInserter)16 Change (com.google.gerrit.reviewdb.client.Change)14 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)13 Test (org.junit.Test)13 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 ArrayList (java.util.ArrayList)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 ImmutableList (com.google.common.collect.ImmutableList)1 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)1 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)1 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)1 Account (com.google.gerrit.reviewdb.client.Account)1 Branch (com.google.gerrit.reviewdb.client.Branch)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1 TestChanges.newPatchSet (com.google.gerrit.testutil.TestChanges.newPatchSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1