Search in sources :

Example 11 with BinaryResult

use of com.google.gerrit.extensions.restapi.BinaryResult in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method assertContent.

protected void assertContent(PushOneCommit.Result pushResult, String path, String expectedContent) throws Exception {
    BinaryResult bin = gApi.changes().id(pushResult.getChangeId()).revision(pushResult.getCommit().name()).file(path).content();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    bin.writeTo(os);
    String res = new String(os.toByteArray(), UTF_8);
    assertThat(res).isEqualTo(expectedContent);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IdString(com.google.gerrit.extensions.restapi.IdString) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult)

Example 12 with BinaryResult

use of com.google.gerrit.extensions.restapi.BinaryResult in project gerrit by GerritCodeReview.

the class FileBranchIT method getFileContent.

@Test
public void getFileContent() throws Exception {
    BinaryResult content = branch().file(PushOneCommit.FILE_NAME);
    assertThat(content.asString()).isEqualTo(PushOneCommit.FILE_CONTENT);
}
Also used : BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with BinaryResult

use of com.google.gerrit.extensions.restapi.BinaryResult in project gerrit by GerritCodeReview.

the class RestApiServlet method stackBase64.

private static BinaryResult stackBase64(HttpServletResponse res, final BinaryResult src) throws IOException {
    BinaryResult b64;
    long len = src.getContentLength();
    if (0 <= len && len <= (7 << 20)) {
        b64 = base64(src);
    } else {
        b64 = new BinaryResult() {

            @Override
            public void writeTo(OutputStream out) throws IOException {
                try (OutputStreamWriter w = new OutputStreamWriter(new FilterOutputStream(out) {

                    @Override
                    public void close() {
                    // Do not close out, but only w and e.
                    }
                }, ISO_8859_1);
                    OutputStream e = BaseEncoding.base64().encodingStream(w)) {
                    src.writeTo(e);
                }
            }
        };
    }
    res.setHeader("X-FYI-Content-Encoding", "base64");
    res.setHeader("X-FYI-Content-Type", src.getContentType());
    return b64.setContentType("text/plain").setCharacterEncoding(ISO_8859_1);
}
Also used : FilterOutputStream(java.io.FilterOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) CountingOutputStream(com.google.common.io.CountingOutputStream) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult)

Example 14 with BinaryResult

use of com.google.gerrit.extensions.restapi.BinaryResult in project gerrit by GerritCodeReview.

the class MergeListIT method getMergeListContent.

@Test
public void getMergeListContent() throws Exception {
    BinaryResult bin = current(changeId).file(MERGE_LIST).content();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    bin.writeTo(os);
    String content = new String(os.toByteArray(), UTF_8);
    assertThat(content).isEqualTo(getMergeListContent(parent2, grandParent2));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 15 with BinaryResult

use of com.google.gerrit.extensions.restapi.BinaryResult in project gerrit by GerritCodeReview.

the class RobotCommentsIT method twoFixesOnSameFileCanBeApplied.

@Test
public void twoFixesOnSameFileCanBeApplied() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
    fixReplacementInfo1.path = FILE_NAME;
    fixReplacementInfo1.range = createRange(2, 0, 3, 0);
    fixReplacementInfo1.replacement = "First modification\n";
    FixSuggestionInfo fixSuggestionInfo1 = createFixSuggestionInfo(fixReplacementInfo1);
    FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
    fixReplacementInfo2.path = FILE_NAME;
    fixReplacementInfo2.range = createRange(8, 0, 9, 0);
    fixReplacementInfo2.replacement = "Some other modified content\n";
    FixSuggestionInfo fixSuggestionInfo2 = createFixSuggestionInfo(fixReplacementInfo2);
    RobotCommentInput robotCommentInput1 = createRobotCommentInput(fixSuggestionInfo1);
    RobotCommentInput robotCommentInput2 = createRobotCommentInput(fixSuggestionInfo2);
    addRobotComment(changeId, robotCommentInput1);
    addRobotComment(changeId, robotCommentInput2);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    List<String> fixIds = getFixIds(robotCommentInfos);
    gApi.changes().id(changeId).current().applyFix(fixIds.get(0));
    gApi.changes().id(changeId).current().applyFix(fixIds.get(1));
    Optional<BinaryResult> file = gApi.changes().id(changeId).edit().getFile(FILE_NAME);
    BinaryResultSubject.assertThat(file).value().asString().isEqualTo("First line\nFirst modification\nThird line\nFourth line\nFifth line\nSixth line\n" + "Seventh line\nSome other modified content\nNinth line\nTenth line\n");
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)23 Test (org.junit.Test)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)10 OutputStream (java.io.OutputStream)6 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)5 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)5 IOException (java.io.IOException)5 FixReplacementInfo (com.google.gerrit.extensions.common.FixReplacementInfo)4 FixSuggestionInfo (com.google.gerrit.extensions.common.FixSuggestionInfo)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 CountingOutputStream (com.google.common.io.CountingOutputStream)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 Project (com.google.gerrit.reviewdb.client.Project)3 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)2 IdString (com.google.gerrit.extensions.restapi.IdString)2 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)2