Search in sources :

Example 36 with Result

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();
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Result(com.google.gerrit.acceptance.PushOneCommit.Result) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 37 with Result

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);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) BasicHeader(org.apache.http.message.BasicHeader) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 38 with Result

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();
}
Also used : Patch(com.google.gerrit.entities.Patch) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Collectors.toMap(java.util.stream.Collectors.toMap) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Locale(java.util.Locale) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) FileInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.FileInfoSubject.assertThat) ImmutableMap(com.google.common.collect.ImmutableMap) BufferedImage(java.awt.image.BufferedImage) Collectors(java.util.stream.Collectors) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) Collectors.joining(java.util.stream.Collectors.joining) Result(com.google.gerrit.acceptance.PushOneCommit.Result) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) DiffOperations(com.google.gerrit.server.patch.DiffOperations) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Joiner(com.google.common.base.Joiner) IntStream(java.util.stream.IntStream) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RawInputUtil(com.google.gerrit.common.RawInputUtil) MERGE_LIST(com.google.gerrit.entities.Patch.MERGE_LIST) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) EditWebLink(com.google.gerrit.extensions.webui.EditWebLink) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) DiffInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat) ImmutableList(com.google.common.collect.ImmutableList) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) GitUtil(com.google.gerrit.acceptance.GitUtil) FileApi(com.google.gerrit.extensions.api.changes.FileApi) FileInfo(com.google.gerrit.extensions.common.FileInfo) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) Permission(com.google.gerrit.entities.Permission) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeType(com.google.gerrit.extensions.common.ChangeType) DiffOptions(com.google.gerrit.server.patch.DiffOptions) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) Ignore(org.junit.Ignore) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) DateTimeFormatter(java.time.format.DateTimeFormatter) Result(com.google.gerrit.acceptance.PushOneCommit.Result) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 39 with Result

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);
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) FileInfo(com.google.gerrit.extensions.common.FileInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 40 with Result

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);
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Aggregations

Result (com.google.gerrit.acceptance.PushOneCommit.Result)75 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)59 Test (org.junit.Test)59 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)28 RestResponse (com.google.gerrit.acceptance.RestResponse)17 ObjectId (org.eclipse.jgit.lib.ObjectId)11 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)9 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)8 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)7 BasicHeader (org.apache.http.message.BasicHeader)7 Request (org.apache.http.client.fluent.Request)6 FileInfo (com.google.gerrit.extensions.common.FileInfo)5 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)4 TagInput (com.google.gerrit.extensions.api.projects.TagInput)4 Project (com.google.gerrit.entities.Project)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)3 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)3 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Before (org.junit.Before)3