use of com.google.gerrit.acceptance.PushOneCommit.Result 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.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class CorsIT method putWithOriginRefused.
@Test
public void putWithOriginRefused() throws Exception {
Result change = createChange();
String origin = "http://example.com";
RestResponse r = adminRestSession.putWithHeader("/changes/" + change.getChangeId() + "/topic", new BasicHeader(ORIGIN, origin), "A");
r.assertOK();
checkCors(r, false, origin);
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class RevisionDiffIT method addCommitRemovingFiles.
private ObjectId addCommitRemovingFiles(ObjectId parentCommit, String... removedFilePaths) throws Exception {
testRepo.reset(parentCommit);
Map<String, String> files = Arrays.stream(removedFilePaths).collect(toMap(Function.identity(), path -> "Irrelevant content"));
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "Remove files from repo", files);
PushOneCommit.Result result = push.rm("refs/for/master");
return result.getCommit();
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class RevisionDiffIT method addDeleteByJgit_isIdentifiedAsRewritten.
@Test
public void addDeleteByJgit_isIdentifiedAsRewritten() throws Exception {
String target = "file.txt";
String symlink = "link.lnk";
// Create a change adding file "FileName" and a symlink "symLink" pointing to the file
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "Commit Subject", target, "content").addSymlink(symlink, target);
PushOneCommit.Result result = push.to("refs/for/master");
String initialRev = gApi.changes().id(result.getChangeId()).get().currentRevision;
String cId = result.getChangeId();
// Delete the symlink with PS2
gApi.changes().id(cId).edit().deleteFile(symlink);
gApi.changes().id(cId).edit().publish();
// Re-add the symlink as a regular file with PS3
gApi.changes().id(cId).edit().modifyFile(symlink, RawInputUtil.create("new content"));
gApi.changes().id(cId).edit().publish();
// Changed files: JGit returns two {DELETED/ADDED} entries for the file.
// The diff logic combines both into a single REWRITTEN entry.
Map<String, FileInfo> changedFiles = gApi.changes().id(cId).current().files(initialRev);
assertThat(changedFiles.keySet()).containsExactly("/COMMIT_MSG", symlink);
// Rewritten
assertThat(changedFiles.get(symlink).status).isEqualTo('W');
// Detailed diff: Old diff cache returns ADDED entry. New Diff Cache returns REWRITE.
DiffInfo diffInfo = gApi.changes().id(cId).current().file(symlink).diff(initialRev);
assertThat(diffInfo.content).hasSize(1);
assertThat(diffInfo).content().element(0).linesOfB().containsExactly("new content");
assertThat(diffInfo.changeType).isEqualTo(ChangeType.REWRITE);
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class RevisionDiffIT method addCommit.
private ObjectId addCommit(ObjectId parentCommit, String filePath, byte[] fileContent) throws Exception {
testRepo.reset(parentCommit);
PushOneCommit.Result result = createEmptyChange();
String changeId = result.getChangeId();
gApi.changes().id(changeId).edit().modifyFile(filePath, RawInputUtil.create(fileContent));
gApi.changes().id(changeId).edit().publish();
String currentRevision = gApi.changes().id(changeId).get().currentRevision;
GitUtil.fetch(testRepo, "refs/*:refs/*");
return ObjectId.fromString(currentRevision);
}
Aggregations