/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadPartialContentWithOffsetAndChunkSizeOk() throws Exception { String content = m_content; PartialContentConnection conn = new PartialContentConnection(content, false); ConnectionHandler handler = new TestConnectionHandler(conn); // 4752 + 48 = 4800, causing only one chunk to be returned... ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL, 48, 4752); assertEquals(slurpAsStringWithBuffer(is), content.substring(48)); }
/** * Tests that we can read partial content and return the expected contents. */ @Test public void testReadPartialContentWithUnknownChunkSizeOk() throws Exception { String content = m_content; ConnectionHandler handler = new TestConnectionHandler(new FailingContentConnection(content, Failure.PARTIAL_UNKNOWN_CHUNK_SIZE)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content.substring(48)); }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadPartialContentWithOffsetOk() throws Exception { String content = m_content; ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, false)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL, 48); assertEquals(slurpAsStringWithBuffer(is), content.substring(48)); }
/** * Tests that we can read partial content and return the expected contents. */ @Test public void testReadPartialContentWithDeferredTotalLengthOk() throws Exception { String content = m_content; ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, true)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadNonPartialEmptyContentOk() throws Exception { String content = ""; ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(content, true)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadNonPartialContentOk() throws Exception { String content = m_content; ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(content, true)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadNonPartialWithoutContentLengthOk() throws Exception { String content = ""; ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(content, false)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read partial content and return the expected contents. */ @Test public void testReadPartialEmptyContentOk() throws Exception { String content = ""; ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, false)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read partial content and return the expected contents. */ @Test public void testReadPartialContentOk() throws Exception { String content = m_content; ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, false)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadPartialContentWithChunkSizeOk() throws Exception { String content = m_content; PartialContentConnection conn = new PartialContentConnection(content, false); ConnectionHandler handler = new TestConnectionHandler(conn); // should cause chunks of 1024 bytes to be used, which means 4 complete chunks and one chunk of 704 bytes... ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL, 0, 1024); assertEquals(slurpAsStringWithBuffer(is), content); assertResponseHeader(conn, "Content-Range", "bytes 4096-4800/4800"); }