* Tests partial Get requests.
*
* @throws Exception
*/
public void testGet() throws Exception {
Client client = new Client(Protocol.HTTP);
// Test partial Get.
Request request = new Request(Method.GET, "http://localhost:"
+ TEST_PORT + "/testGet");
Response response;
response = client.handle(request);
assertEquals(Status.SUCCESS_OK, response.getStatus());
assertEquals("1234567890", response.getEntity().getText());
assertEquals(10, response.getEntity().getSize());
assertEquals(10, response.getEntity().getAvailableSize());
request = new Request(Method.GET, "http://localhost:" + TEST_PORT
+ "/testGet");
request.setRanges(Arrays.asList(new Range(0, 10)));
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("1234567890", response.getEntity().getText());
assertEquals(10, response.getEntity().getSize());
assertEquals(10, response.getEntity().getAvailableSize());
assertEquals(0, response.getEntity().getRange().getIndex());
assertEquals(10, response.getEntity().getRange().getSize());
request.setRanges(Arrays.asList(new Range(Range.INDEX_FIRST, 2)));
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("12", response.getEntity().getText());
assertEquals(10, response.getEntity().getSize());
assertEquals(2, response.getEntity().getAvailableSize());
assertEquals(0, response.getEntity().getRange().getIndex());
assertEquals(2, response.getEntity().getRange().getSize());
request.setRanges(Arrays.asList(new Range(2, 2)));
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("34", response.getEntity().getText());
assertEquals(10, response.getEntity().getSize());
assertEquals(2, response.getEntity().getAvailableSize());
assertEquals(2, response.getEntity().getRange().getIndex());
assertEquals(2, response.getEntity().getRange().getSize());
request.setRanges(Arrays.asList(new Range(2, 7)));
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("3456789", response.getEntity().getText());
assertEquals(10, response.getEntity().getSize());
assertEquals(7, response.getEntity().getAvailableSize());
assertEquals(2, response.getEntity().getRange().getIndex());
assertEquals(7, response.getEntity().getRange().getSize());
request.setRanges(Arrays.asList(new Range(Range.INDEX_LAST, 7)));
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("4567890", response.getEntity().getText());
assertEquals(10, response.getEntity().getSize());
assertEquals(7, response.getEntity().getAvailableSize());
assertEquals(3, response.getEntity().getRange().getIndex());
assertEquals(7, response.getEntity().getRange().getSize());
request.setRanges(Arrays.asList(new Range(2, Range.SIZE_MAX)));
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("34567890", response.getEntity().getText());
assertEquals(10, response.getEntity().getSize());
assertEquals(8, response.getEntity().getAvailableSize());
assertEquals(2, response.getEntity().getRange().getIndex());
assertEquals(8, response.getEntity().getRange().getSize());
client.stop();
}