use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class ReceiveCommitsCommentValidationIT method limitCumulativeCommentSize.
@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "500")
public void limitCumulativeCommentSize() throws Exception {
when(mockCommentValidator.validateComments(any(), any())).thenReturn(ImmutableList.of());
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
String revId = result.getCommit().getName();
String filePath = result.getChange().currentFilePaths().get(0);
String commentText400Bytes = new String(new char[400]).replace("\0", "x");
DraftInput draftInline = testCommentHelper.newDraft(filePath, Side.REVISION, 1, commentText400Bytes);
testCommentHelper.addDraft(changeId, revId, draftInline);
amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).hasSize(1);
draftInline = testCommentHelper.newDraft(filePath, Side.REVISION, 1, commentText400Bytes);
testCommentHelper.addDraft(changeId, revId, draftInline);
Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).hasSize(1);
amendResult.assertMessage("exceeding maximum cumulative size of comments");
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class ReceiveCommitsCommentValidationIT method validateComments_enforceLimits_commentTooLarge.
@Test
@GerritConfig(name = "change.commentSizeLimit", value = "" + COMMENT_SIZE_LIMIT)
public void validateComments_enforceLimits_commentTooLarge() throws Exception {
when(mockCommentValidator.validateComments(any(), any())).thenReturn(ImmutableList.of());
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
int commentLength = COMMENT_SIZE_LIMIT + 1;
DraftInput comment = testCommentHelper.newDraft(new String(new char[commentLength]).replace("\0", "x"));
testCommentHelper.addDraft(changeId, result.getCommit().getName(), comment);
assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).isEmpty();
Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
amendResult.assertOkStatus();
amendResult.assertMessage(String.format("Comment size exceeds limit (%d > %d)", commentLength, COMMENT_SIZE_LIMIT));
assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).isEmpty();
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class ReceiveCommitsLimitsIT method limitFileCount_merge.
@Test
@GerritConfig(name = "change.maxFiles", value = "1")
public void limitFileCount_merge() throws Exception {
// Create the parents.
RevCommit commitFoo = commitBuilder().add("foo.txt", "same old, same old").message("blah").create();
RevCommit commitBar = testRepo.branch("branch").commit().insertChangeId().add("bar.txt", "bar").message("blah").create();
testRepo.reset(commitFoo);
// By convention we diff against the first parent.
// commitFoo is first -> 1 file changed -> OK
pushFactory.create(admin.newIdent(), testRepo, "blah", ImmutableMap.of("foo.txt", "same old, same old", "bar.txt", "changed file")).setParents(ImmutableList.of(commitFoo, commitBar)).to("refs/for/master").assertOkStatus();
// commitBar is first -> 2 files changed -> rejected
pushFactory.create(admin.newIdent(), testRepo, "blah", ImmutableMap.of("foo.txt", "same old, same old", "bar.txt", "changed file")).setParents(ImmutableList.of(commitBar, commitFoo)).to("refs/for/master").assertErrorStatus("Exceeding maximum number of files per change (2 > 1)");
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class GetRelatedIT method getRelatedForStaleChange.
@Test
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
public void getRelatedForStaleChange() throws Exception {
RevCommit c1_1 = commitBuilder().add("a.txt", "1").message("subject: 1").create();
RevCommit c2_1 = commitBuilder().add("b.txt", "1").message("subject: 1").create();
pushHead(testRepo, "refs/for/master", false);
RevCommit c2_2 = testRepo.amend(c2_1).add("b.txt", "2").create();
testRepo.reset(c2_2);
disableChangeIndexWrites();
try {
pushHead(testRepo, "refs/for/master", false);
} finally {
enableChangeIndexWrites();
}
PatchSet.Id psId1_1 = getPatchSetId(c1_1);
PatchSet.Id psId2_1 = getPatchSetId(c2_1);
PatchSet.Id psId2_2 = PatchSet.id(psId2_1.changeId(), psId2_1.get() + 1);
assertRelated(psId2_2, changeAndCommit(psId2_2, c2_2, 2), changeAndCommit(psId1_1, c1_1, 1));
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class ListMailFilterIT method listFilterAllowFiltersNotListedUser.
@Test
@GerritConfig(name = "receiveemail.filter.mode", value = "ALLOW")
@GerritConfig(name = "receiveemail.filter.patterns", values = { ".+@gerritcodereview\\.com", "a@b\\.com" })
public void listFilterAllowFiltersNotListedUser() throws Exception {
ChangeInfo changeInfo = createChangeAndReplyByEmail();
// Check that the comments from the email have NOT been persisted
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
assertThat(messages).hasSize(2);
// Check that no emails were sent because of this error
assertThat(sender.getMessages()).isEmpty();
}
Aggregations