@@ -150,8 +150,7 @@ public void handle(Request request, Response response) {
150
150
}
151
151
152
152
// 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" );
155
154
156
155
// Sample string.
157
156
private static String str1000 ;
@@ -168,11 +167,9 @@ protected void setUp() throws Exception {
168
167
component .getDefaultHost ().attach (new TestRangeApplication ());
169
168
component .start ();
170
169
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 );
176
173
}
177
174
178
175
@ Override
@@ -191,8 +188,7 @@ public void testGet() throws Exception {
191
188
Client client = new Client (Protocol .HTTP );
192
189
193
190
// 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" );
196
192
Response response ;
197
193
198
194
response = client .handle (request );
@@ -201,8 +197,7 @@ public void testGet() throws Exception {
201
197
assertEquals (10 , response .getEntity ().getSize ());
202
198
assertEquals (10 , response .getEntity ().getAvailableSize ());
203
199
204
- request = new Request (Method .GET , "http://localhost:" + TEST_PORT
205
- + "/testGet" );
200
+ request = new Request (Method .GET , "http://localhost:" + TEST_PORT + "/testGet" );
206
201
request .setRanges (Arrays .asList (new Range (0 , 10 )));
207
202
response = client .handle (request );
208
203
assertEquals (Status .SUCCESS_PARTIAL_CONTENT , response .getStatus ());
@@ -278,8 +273,7 @@ public void testConditionalRanges() throws Exception {
278
273
Client client = new Client (Protocol .HTTP );
279
274
280
275
// 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" );
283
277
Response response = client .handle (request );
284
278
Tag entityTag = response .getEntity ().getTag ();
285
279
@@ -317,34 +311,29 @@ public void testPut() throws Exception {
317
311
client .getContext ().getParameters ().add ("tracing" , "true" );
318
312
319
313
// 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" );
322
315
request .setEntity (new StringRepresentation ("1234567890" ));
323
316
request .setRanges (Arrays .asList (new Range (0 , 10 )));
324
317
response = client .handle (request );
325
318
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 ()));
328
320
assertEquals (Status .SUCCESS_OK , response .getStatus ());
329
321
assertEquals ("1234567890" , response .getEntity ().getText ());
330
322
331
323
// Partial PUT on a file, the provided representation overflowed the
332
324
// 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" );
335
326
request .setEntity (new StringRepresentation ("0000000000" ));
336
327
request .setRanges (Arrays .asList (new Range (1 , 10 )));
337
328
response = client .handle (request );
338
329
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 ()));
341
331
assertEquals (Status .SUCCESS_OK , response .getStatus ());
342
332
assertEquals ("10000000000" , response .getEntity ().getText ());
343
333
344
334
// Partial PUT on a file that does not exists, the provided range
345
335
// 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" );
348
337
request .setEntity (new StringRepresentation ("0000000000" ));
349
338
request .setRanges (Arrays .asList (new Range (1 , 10 )));
350
339
response = client .handle (request );
@@ -355,34 +344,29 @@ public void testPut() throws Exception {
355
344
assertEquals ("0000000000" , response .getEntity ().getText ());
356
345
357
346
// 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" );
360
348
request .setEntity (new StringRepresentation ("22" ));
361
349
request .setRanges (Arrays .asList (new Range (2 , 2 )));
362
350
response = client .handle (request );
363
351
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 ()));
366
353
assertEquals (Status .SUCCESS_OK , response .getStatus ());
367
354
assertEquals ("10220000000" , response .getEntity ().getText ());
368
355
369
356
// Partial PUT on a file, the provided representation will be padded
370
357
// 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" );
373
359
request .setEntity (new StringRepresentation ("888" ));
374
360
request .setRanges (Arrays .asList (new Range (8 , Range .SIZE_MAX )));
375
361
response = client .handle (request );
376
362
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 ()));
379
364
assertEquals (Status .SUCCESS_OK , response .getStatus ());
380
365
assertEquals ("10220000888" , response .getEntity ().getText ());
381
366
382
367
// Partial PUT on a file that does not exist, the range does not
383
368
// 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" );
386
370
request .setEntity (new StringRepresentation ("888" ));
387
371
request .setRanges (Arrays .asList (new Range (8 , Range .SIZE_MAX )));
388
372
response = client .handle (request );
@@ -394,24 +378,32 @@ public void testPut() throws Exception {
394
378
395
379
// Partial PUT on a file, the provided representation will be padded
396
380
// 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" );
399
382
request .setEntity (new StringRepresentation ("99" ));
400
383
request .setRanges (Arrays .asList (new Range (8 , Range .SIZE_MAX )));
401
384
response = client .handle (request );
402
385
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 ()));
405
387
assertEquals (Status .SUCCESS_OK , response .getStatus ());
406
388
assertEquals ("10220000998" , response .getEntity ().getText ());
407
389
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" );
410
391
request .setRanges (Arrays .asList (new Range (3 , Range .SIZE_MAX )));
411
392
response = client .handle (request );
412
393
assertEquals (Status .SUCCESS_PARTIAL_CONTENT , response .getStatus ());
413
394
assertEquals ("20000998" , response .getEntity ().getText ());
414
395
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
+
415
407
IoUtils .delete (testDir , true );
416
408
client .stop ();
417
409
}
0 commit comments