/** * 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 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 the "Range" header is correctly set. */ @Test public void testRangeHeadersCorrectlySetOk() throws Exception { String content = m_content; PartialContentConnection conn; ContentRangeInputStream is; conn = new PartialContentConnection(content, false); // no offset causes no Range header to be set (initially)... is = new ContentRangeInputStream(new TestConnectionHandler(conn), m_testURL); is.read(); // read one byte... is.close(); // Make sure the proper request header is NOT set... assertRequestHeader(conn, "Range", null); conn = new PartialContentConnection(content, false); // start at 48 bytes and return the next complete chunk... is = new ContentRangeInputStream(new TestConnectionHandler(conn), m_testURL, 48); is.read(); // read one byte... is.close(); // Make sure the proper request header is set... assertRequestHeader(conn, "Range", "bytes=48-"); conn = new PartialContentConnection(content, false); // 4752 + 48 = 4800, causing only one chunk to be returned... is = new ContentRangeInputStream(new TestConnectionHandler(conn), m_testURL, 48, 4752); is.read(); // read one byte... is.close(); // Make sure the proper request header is set... assertRequestHeader(conn, "Range", "bytes=48-4800"); }
/** * 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"); }
/** * Tests that we can read partial content and return the expected contents. */ @Test public void testReadPartialEmptyContentByteForByteOk() throws Exception { String content = ""; ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, false)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringByteForByte(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 partial content and return the expected contents. */ @Test public void testReadPartialContentByteForByteOk() throws Exception { String content = m_content; ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, false)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringByteForByte(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); }