@Test(expected = IllegalArgumentException.class) public void testWriteToWithNullOutput() throws Exception { ParseFileHttpBody body = new ParseFileHttpBody(makeTestFile(temporaryFolder.getRoot())); body.writeTo(null); } }
@Test public void testInitializeWithFileAndContentType() throws IOException { String contentType = "text/plain"; File file = makeTestFile(temporaryFolder.getRoot()); ParseFileHttpBody body = new ParseFileHttpBody(file, contentType); assertEquals(file.length(), body.getContentLength()); assertEquals(contentType, body.getContentType()); // Verify file content InputStream content = body.getContent(); byte[] contentBytes = ParseIOUtils.toByteArray(content); ParseIOUtils.closeQuietly(content); verifyTestFileContent(contentBytes); }
@Override protected ParseHttpBody newBody(final ProgressCallback progressCallback) { // TODO(mengyan): Delete ParseByteArrayHttpBody when we change input byte array to staged file // in ParseFileController if (progressCallback == null) { return data != null ? new ParseByteArrayHttpBody(data, contentType) : new ParseFileHttpBody(file, contentType); } return data != null ? new ParseCountingByteArrayHttpBody(data, contentType, progressCallback) : new ParseCountingFileHttpBody(file, contentType, progressCallback); }
@Test public void testInitializeWithFile() throws IOException { File file = makeTestFile(temporaryFolder.getRoot()); ParseFileHttpBody body = new ParseFileHttpBody(file); assertEquals(file.length(), body.getContentLength()); assertNull(body.getContentType()); // Verify file content InputStream content = body.getContent(); byte[] contentBytes = ParseIOUtils.toByteArray(content); ParseIOUtils.closeQuietly(content); verifyTestFileContent(contentBytes); }
@Test public void testWriteTo() throws IOException { File file = makeTestFile(temporaryFolder.getRoot()); ParseFileHttpBody body = new ParseFileHttpBody(file); // Check content ByteArrayOutputStream output = new ByteArrayOutputStream(); body.writeTo(output); verifyTestFileContent(output.toByteArray()); }