@Test public void read_document_as_stream() throws Exception { // content type is really json but it doesn't matter here. ResponseOnFileStub rsp = ResponseOnFileStub.newInstance(200, "attachment.txt"); when(httpClient.get("/test_db/some_doc_id")).thenReturn(rsp); InputStream data = dbCon.getAsStream("some_doc_id"); assertNotNull(data); assertFalse(rsp.isConnectionReleased()); assertEquals("detta är ett påhäng med ett ö i", IOUtils.toString(data, "UTF-8")); }
@Test public void return_attachment_with_open_data_stream() throws Exception { ResponseOnFileStub rsp = ResponseOnFileStub.newInstance(200, "attachment.txt", "text", 12); when(httpClient.get("/test_db/some_doc_id/some_attachment")).thenReturn(rsp); AttachmentInputStream a = dbCon.getAttachment("some_doc_id", "some_attachment"); assertNotNull(a); assertFalse(rsp.isConnectionReleased()); assertEquals("detta är ett påhäng med ett ö i", IOUtils.toString(a, "UTF-8")); assertEquals(rsp.getContentType(), a.getContentType()); assertEquals(rsp.getContentLength(), a.getContentLength()); }