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);
}
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);
}
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);
}
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));
}
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");
}
Aggregations