@@ -150,8 +150,7 @@ public void handle(Request request, Response response) {
150150 }
151151
152152 // Create a temporary directory for the tests
153- private static final File testDir = new File (
154- System .getProperty ("java.io.tmpdir" ), "rangeTestCase" );
153+ private static final File testDir = new File (System .getProperty ("java.io.tmpdir" ), "rangeTestCase" );
155154
156155 // Sample string.
157156 private static String str1000 ;
@@ -168,11 +167,9 @@ protected void setUp() throws Exception {
168167 component .getDefaultHost ().attach (new TestRangeApplication ());
169168 component .start ();
170169
171- StringBuilder sb = new StringBuilder ();
172- for (int i = 0 ; i < 1000 ; i ++) {
173- sb .append ("1" );
174- }
175- str1000 = sb .toString ();
170+ char [] tab = new char [1000 ];
171+ Arrays .fill (tab , '1' );
172+ str1000 = new String (tab );
176173 }
177174
178175 @ Override
@@ -191,8 +188,7 @@ public void testGet() throws Exception {
191188 Client client = new Client (Protocol .HTTP );
192189
193190 // Test partial Get.
194- Request request = new Request (Method .GET , "http://localhost:"
195- + TEST_PORT + "/testGet" );
191+ Request request = new Request (Method .GET , "http://localhost:" + TEST_PORT + "/testGet" );
196192 Response response ;
197193
198194 response = client .handle (request );
@@ -201,8 +197,7 @@ public void testGet() throws Exception {
201197 assertEquals (10 , response .getEntity ().getSize ());
202198 assertEquals (10 , response .getEntity ().getAvailableSize ());
203199
204- request = new Request (Method .GET , "http://localhost:" + TEST_PORT
205- + "/testGet" );
200+ request = new Request (Method .GET , "http://localhost:" + TEST_PORT + "/testGet" );
206201 request .setRanges (Arrays .asList (new Range (0 , 10 )));
207202 response = client .handle (request );
208203 assertEquals (Status .SUCCESS_PARTIAL_CONTENT , response .getStatus ());
@@ -278,8 +273,7 @@ public void testConditionalRanges() throws Exception {
278273 Client client = new Client (Protocol .HTTP );
279274
280275 // Test partial Get.
281- Request request = new Request (Method .GET , "http://localhost:"
282- + TEST_PORT + "/testGet" );
276+ Request request = new Request (Method .GET , "http://localhost:" + TEST_PORT + "/testGet" );
283277 Response response = client .handle (request );
284278 Tag entityTag = response .getEntity ().getTag ();
285279
@@ -317,34 +311,29 @@ public void testPut() throws Exception {
317311 client .getContext ().getParameters ().add ("tracing" , "true" );
318312
319313 // PUT on a file that does not exist
320- request = new Request (Method .PUT , "http://localhost:" + TEST_PORT
321- + "/testPut/essai.txt" );
314+ request = new Request (Method .PUT , "http://localhost:" + TEST_PORT + "/testPut/essai.txt" );
322315 request .setEntity (new StringRepresentation ("1234567890" ));
323316 request .setRanges (Arrays .asList (new Range (0 , 10 )));
324317 response = client .handle (request );
325318 assertTrue (response .getStatus ().isSuccess ());
326- response = client .handle (new Request (Method .GET , request
327- .getResourceRef ()));
319+ response = client .handle (new Request (Method .GET , request .getResourceRef ()));
328320 assertEquals (Status .SUCCESS_OK , response .getStatus ());
329321 assertEquals ("1234567890" , response .getEntity ().getText ());
330322
331323 // Partial PUT on a file, the provided representation overflowed the
332324 // existing file
333- request = new Request (Method .PUT , "http://localhost:" + TEST_PORT
334- + "/testPut/essai.txt" );
325+ request = new Request (Method .PUT , "http://localhost:" + TEST_PORT + "/testPut/essai.txt" );
335326 request .setEntity (new StringRepresentation ("0000000000" ));
336327 request .setRanges (Arrays .asList (new Range (1 , 10 )));
337328 response = client .handle (request );
338329 assertTrue (response .getStatus ().isSuccess ());
339- response = client .handle (new Request (Method .GET , request
340- .getResourceRef ()));
330+ response = client .handle (new Request (Method .GET , request .getResourceRef ()));
341331 assertEquals (Status .SUCCESS_OK , response .getStatus ());
342332 assertEquals ("10000000000" , response .getEntity ().getText ());
343333
344334 // Partial PUT on a file that does not exists, the provided range
345335 // does not start at the 0 index.
346- request = new Request (Method .PUT , "http://localhost:" + TEST_PORT
347- + "/testPut/essai2.txt" );
336+ request = new Request (Method .PUT , "http://localhost:" + TEST_PORT + "/testPut/essai2.txt" );
348337 request .setEntity (new StringRepresentation ("0000000000" ));
349338 request .setRanges (Arrays .asList (new Range (1 , 10 )));
350339 response = client .handle (request );
@@ -355,34 +344,29 @@ public void testPut() throws Exception {
355344 assertEquals ("0000000000" , response .getEntity ().getText ());
356345
357346 // Partial PUT on a file, simple range
358- request = new Request (Method .PUT , "http://localhost:" + TEST_PORT
359- + "/testPut/essai.txt" );
347+ request = new Request (Method .PUT , "http://localhost:" + TEST_PORT + "/testPut/essai.txt" );
360348 request .setEntity (new StringRepresentation ("22" ));
361349 request .setRanges (Arrays .asList (new Range (2 , 2 )));
362350 response = client .handle (request );
363351 assertTrue (response .getStatus ().isSuccess ());
364- response = client .handle (new Request (Method .GET , request
365- .getResourceRef ()));
352+ response = client .handle (new Request (Method .GET , request .getResourceRef ()));
366353 assertEquals (Status .SUCCESS_OK , response .getStatus ());
367354 assertEquals ("10220000000" , response .getEntity ().getText ());
368355
369356 // Partial PUT on a file, the provided representation will be padded
370357 // at the very end of the file.
371- request = new Request (Method .PUT , "http://localhost:" + TEST_PORT
372- + "/testPut/essai.txt" );
358+ request = new Request (Method .PUT , "http://localhost:" + TEST_PORT + "/testPut/essai.txt" );
373359 request .setEntity (new StringRepresentation ("888" ));
374360 request .setRanges (Arrays .asList (new Range (8 , Range .SIZE_MAX )));
375361 response = client .handle (request );
376362 assertTrue (response .getStatus ().isSuccess ());
377- response = client .handle (new Request (Method .GET , request
378- .getResourceRef ()));
363+ response = client .handle (new Request (Method .GET , request .getResourceRef ()));
379364 assertEquals (Status .SUCCESS_OK , response .getStatus ());
380365 assertEquals ("10220000888" , response .getEntity ().getText ());
381366
382367 // Partial PUT on a file that does not exist, the range does not
383368 // specify the range size.
384- request = new Request (Method .PUT , "http://localhost:" + TEST_PORT
385- + "/testPut/essai3.txt" );
369+ request = new Request (Method .PUT , "http://localhost:" + TEST_PORT + "/testPut/essai3.txt" );
386370 request .setEntity (new StringRepresentation ("888" ));
387371 request .setRanges (Arrays .asList (new Range (8 , Range .SIZE_MAX )));
388372 response = client .handle (request );
@@ -394,24 +378,32 @@ public void testPut() throws Exception {
394378
395379 // Partial PUT on a file, the provided representation will be padded
396380 // just before the end of the file.
397- request = new Request (Method .PUT , "http://localhost:" + TEST_PORT
398- + "/testPut/essai.txt" );
381+ request = new Request (Method .PUT , "http://localhost:" + TEST_PORT + "/testPut/essai.txt" );
399382 request .setEntity (new StringRepresentation ("99" ));
400383 request .setRanges (Arrays .asList (new Range (8 , Range .SIZE_MAX )));
401384 response = client .handle (request );
402385 assertTrue (response .getStatus ().isSuccess ());
403- response = client .handle (new Request (Method .GET , request
404- .getResourceRef ()));
386+ response = client .handle (new Request (Method .GET , request .getResourceRef ()));
405387 assertEquals (Status .SUCCESS_OK , response .getStatus ());
406388 assertEquals ("10220000998" , response .getEntity ().getText ());
407389
408- request = new Request (Method .GET , "http://localhost:" + TEST_PORT
409- + "/testPut/essai.txt" );
390+ request = new Request (Method .GET , "http://localhost:" + TEST_PORT + "/testPut/essai.txt" );
410391 request .setRanges (Arrays .asList (new Range (3 , Range .SIZE_MAX )));
411392 response = client .handle (request );
412393 assertEquals (Status .SUCCESS_PARTIAL_CONTENT , response .getStatus ());
413394 assertEquals ("20000998" , response .getEntity ().getText ());
414395
396+
397+ // Partial PUT on a file, with a non-bytes range, not taken into account
398+ request = new Request (Method .PUT , "http://localhost:" + TEST_PORT + "/testPut/essai.txt" );
399+ request .setEntity (new StringRepresentation ("1234567890" ));
400+ request .setRanges (Arrays .asList (new Range (8 , Range .SIZE_MAX , 10 , "test" )));
401+ response = client .handle (request );
402+ assertTrue (response .getStatus ().isSuccess ());
403+ response = client .handle (new Request (Method .GET , request .getResourceRef ()));
404+ assertEquals (Status .SUCCESS_OK , response .getStatus ());
405+ assertEquals ("1234567890" , response .getEntity ().getText ());
406+
415407 IoUtils .delete (testDir , true );
416408 client .stop ();
417409 }
0 commit comments