// PUT on a file that does not exist
request = new Request(Method.PUT, "http://localhost:" + TEST_PORT
+ "/testPut/essai.txt");
request.setEntity(new StringRepresentation("1234567890"));
request.setRanges(Arrays.asList(new Range(0, 10)));
response = client.handle(request);
assertEquals(Status.SUCCESS_OK, response.getStatus());
response = client.handle(new Request(Method.GET, request
.getResourceRef()));
assertEquals(Status.SUCCESS_OK, response.getStatus());
assertEquals("1234567890", response.getEntity().getText());
// Partial PUT on a file, the provided representation overflowed the
// existing file
request = new Request(Method.PUT, "http://localhost:" + TEST_PORT
+ "/testPut/essai.txt");
request.setEntity(new StringRepresentation("0000000000"));
request.setRanges(Arrays.asList(new Range(1, 10)));
response = client.handle(request);
System.out.println(response.getStatus() + " / "
+ response.getStatus().getThrowable());
assertEquals(Status.SUCCESS_OK, response.getStatus());
response = client.handle(new Request(Method.GET, request
.getResourceRef()));
assertEquals(Status.SUCCESS_OK, response.getStatus());
assertEquals("10000000000", response.getEntity().getText());
// Partial PUT on a file that does not exists, the provided range
// does not start at the 0 index.
request = new Request(Method.PUT, "http://localhost:" + TEST_PORT
+ "/testPut/essai2.txt");
request.setEntity(new StringRepresentation("0000000000"));
request.setRanges(Arrays.asList(new Range(1, 10)));
response = client.handle(request);
assertEquals(Status.SUCCESS_OK, response.getStatus());
request.setMethod(Method.GET);
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("0000000000", response.getEntity().getText());
// Partial PUT on a file, simple range
request = new Request(Method.PUT, "http://localhost:" + TEST_PORT
+ "/testPut/essai.txt");
request.setEntity(new StringRepresentation("22"));
request.setRanges(Arrays.asList(new Range(2, 2)));
response = client.handle(request);
assertEquals(Status.SUCCESS_OK, response.getStatus());
response = client.handle(new Request(Method.GET, request
.getResourceRef()));
assertEquals(Status.SUCCESS_OK, response.getStatus());
assertEquals("10220000000", response.getEntity().getText());
// Partial PUT on a file, the provided representation will be padded
// at the very end of the file.
request = new Request(Method.PUT, "http://localhost:" + TEST_PORT
+ "/testPut/essai.txt");
request.setEntity(new StringRepresentation("888"));
request.setRanges(Arrays.asList(new Range(8, Range.SIZE_MAX)));
response = client.handle(request);
assertEquals(Status.SUCCESS_OK, response.getStatus());
response = client.handle(new Request(Method.GET, request
.getResourceRef()));
assertEquals(Status.SUCCESS_OK, response.getStatus());
assertEquals("10220000888", response.getEntity().getText());
// Partial PUT on a file that does not exist, the range does not
// specify the range size.
request = new Request(Method.PUT, "http://localhost:" + TEST_PORT
+ "/testPut/essai3.txt");
request.setEntity(new StringRepresentation("888"));
request.setRanges(Arrays.asList(new Range(8, Range.SIZE_MAX)));
response = client.handle(request);
assertEquals(Status.SUCCESS_OK, response.getStatus());
request.setMethod(Method.GET);
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("888", response.getEntity().getText());
// Partial PUT on a file, the provided representation will be padded
// just before the end of the file.
request = new Request(Method.PUT, "http://localhost:" + TEST_PORT
+ "/testPut/essai.txt");
request.setEntity(new StringRepresentation("99"));
request.setRanges(Arrays.asList(new Range(8, Range.SIZE_MAX)));
response = client.handle(request);
assertEquals(Status.SUCCESS_OK, response.getStatus());
response = client.handle(new Request(Method.GET, request
.getResourceRef()));
assertEquals(Status.SUCCESS_OK, response.getStatus());
assertEquals("10220000998", response.getEntity().getText());
request = new Request(Method.GET, "http://localhost:" + TEST_PORT
+ "/testPut/essai.txt");
request.setRanges(Arrays.asList(new Range(3, Range.SIZE_MAX)));
response = client.handle(request);
assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
assertEquals("20000998", response.getEntity().getText());
BioUtils.delete(testDir, true);