4848import java .net .URI ;
4949import java .nio .ByteBuffer ;
5050import java .nio .charset .StandardCharsets ;
51- import java .util .Locale ;
5251import java .util .UUID ;
5352import java .util .concurrent .atomic .AtomicLong ;
5453import org .checkerframework .checker .nullness .qual .NonNull ;
@@ -95,14 +94,14 @@ public void emptyObjectHappyPath() throws Exception {
9594 };
9695
9796 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
98- URI endpoint = fakeHttpServer . getEndpoint ();
99- String uploadUrl =
100- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
97+ URI uri =
98+ fakeHttpServer . createUri (
99+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
101100
102101 JsonResumableSessionPutTask task =
103102 new JsonResumableSessionPutTask (
104103 httpClientContext ,
105- jsonResumableWrite (uploadUrl ),
104+ jsonResumableWrite (uri ),
106105 RewindableContent .empty (),
107106 HttpContentRange .of (ByteRangeSpec .explicitClosed (0L , 0L ), 0 ));
108107
@@ -142,16 +141,16 @@ public void scenario7() throws Exception {
142141 };
143142
144143 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
145- URI endpoint = fakeHttpServer . getEndpoint ();
146- String uploadUrl =
147- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
144+ URI uri =
145+ fakeHttpServer . createUri (
146+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
148147
149148 AtomicLong confirmedBytes = new AtomicLong (-1L );
150149
151150 JsonResumableSessionPutTask task =
152151 new JsonResumableSessionPutTask (
153152 httpClientContext ,
154- jsonResumableWrite (uploadUrl ),
153+ jsonResumableWrite (uri ),
155154 RewindableContent .empty (),
156155 HttpContentRange .of (ByteRangeSpec .explicitClosed (0L , 10L )));
157156
@@ -224,16 +223,16 @@ public void scenario1() throws Exception {
224223 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler );
225224 TmpFile tmpFile =
226225 DataGenerator .base64Characters ().tempFile (temp .newFolder ().toPath (), _256KiBL )) {
227- URI endpoint = fakeHttpServer . getEndpoint ();
228- String uploadUrl =
229- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
226+ URI uri =
227+ fakeHttpServer . createUri (
228+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
230229
231230 AtomicLong confirmedBytes = new AtomicLong (-1L );
232231
233232 JsonResumableSessionPutTask task =
234233 new JsonResumableSessionPutTask (
235234 httpClientContext ,
236- jsonResumableWrite (uploadUrl ),
235+ jsonResumableWrite (uri ),
237236 RewindableContent .of (tmpFile .getPath ()),
238237 HttpContentRange .of (ByteRangeSpec .explicit (0L , _256KiBL )));
239238
@@ -294,16 +293,16 @@ public void scenario2() throws Exception {
294293 };
295294
296295 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
297- URI endpoint = fakeHttpServer . getEndpoint ();
298- String uploadUrl =
299- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
296+ URI uri =
297+ fakeHttpServer . createUri (
298+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
300299
301300 AtomicLong confirmedBytes = new AtomicLong (-1L );
302301
303302 JsonResumableSessionPutTask task =
304303 new JsonResumableSessionPutTask (
305304 httpClientContext ,
306- jsonResumableWrite (uploadUrl ),
305+ jsonResumableWrite (uri ),
307306 RewindableContent .empty (),
308307 HttpContentRange .of (_256KiBL ));
309308
@@ -364,16 +363,16 @@ public void scenario3() throws Exception {
364363 };
365364
366365 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
367- URI endpoint = fakeHttpServer . getEndpoint ();
368- String uploadUrl =
369- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
366+ URI uri =
367+ fakeHttpServer . createUri (
368+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
370369
371370 AtomicLong confirmedBytes = new AtomicLong (-1L );
372371
373372 JsonResumableSessionPutTask task =
374373 new JsonResumableSessionPutTask (
375374 httpClientContext ,
376- jsonResumableWrite (uploadUrl ),
375+ jsonResumableWrite (uri ),
377376 RewindableContent .empty (),
378377 HttpContentRange .of (_512KiBL ));
379378
@@ -445,22 +444,21 @@ public void scenario4() throws Exception {
445444 };
446445
447446 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
448- URI endpoint = fakeHttpServer . getEndpoint ();
449- String uploadUrl =
450- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
447+ URI uri =
448+ fakeHttpServer . createUri (
449+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
451450
452451 JsonResumableSessionPutTask task =
453452 new JsonResumableSessionPutTask (
454453 httpClientContext ,
455- jsonResumableWrite (uploadUrl ),
454+ jsonResumableWrite (uri ),
456455 RewindableContent .empty (),
457456 HttpContentRange .of (_256KiBL ));
458457
459458 ResumableOperationResult <@ Nullable StorageObject > operationResult = task .call ();
460459 StorageObject call = operationResult .getObject ();
461460 assertThat (call ).isNotNull ();
462- assertThat (call .getMetadata ())
463- .containsEntry ("upload_id" , uploadUrl .substring (endpoint .toString ().length () - 1 ));
461+ assertThat (call .getMetadata ()).containsEntry ("upload_id" , uri .getPath ());
464462 assertThat (operationResult .getPersistedSize ()).isEqualTo (_256KiBL );
465463 }
466464 }
@@ -526,16 +524,16 @@ public void scenario4_1() throws Exception {
526524 };
527525
528526 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
529- URI endpoint = fakeHttpServer . getEndpoint ();
530- String uploadUrl =
531- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
527+ URI uri =
528+ fakeHttpServer . createUri (
529+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
532530
533531 AtomicLong confirmedBytes = new AtomicLong (-1L );
534532
535533 JsonResumableSessionPutTask task =
536534 new JsonResumableSessionPutTask (
537535 httpClientContext ,
538- jsonResumableWrite (uploadUrl ),
536+ jsonResumableWrite (uri ),
539537 RewindableContent .empty (),
540538 HttpContentRange .of (_512KiBL ));
541539
@@ -607,16 +605,16 @@ public void scenario4_2() throws Exception {
607605 };
608606
609607 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
610- URI endpoint = fakeHttpServer . getEndpoint ();
611- String uploadUrl =
612- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
608+ URI uri =
609+ fakeHttpServer . createUri (
610+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
613611
614612 AtomicLong confirmedBytes = new AtomicLong (-1L );
615613
616614 JsonResumableSessionPutTask task =
617615 new JsonResumableSessionPutTask (
618616 httpClientContext ,
619- jsonResumableWrite (uploadUrl ),
617+ jsonResumableWrite (uri ),
620618 RewindableContent .empty (),
621619 HttpContentRange .of (_128KiBL ));
622620
@@ -686,16 +684,16 @@ public void scenario5() throws Exception {
686684 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler );
687685 TmpFile tmpFile =
688686 DataGenerator .base64Characters ().tempFile (temp .newFolder ().toPath (), _256KiBL )) {
689- URI endpoint = fakeHttpServer . getEndpoint ();
690- String uploadUrl =
691- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
687+ URI uri =
688+ fakeHttpServer . createUri (
689+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
692690
693691 AtomicLong confirmedBytes = new AtomicLong (-1L );
694692
695693 JsonResumableSessionPutTask task =
696694 new JsonResumableSessionPutTask (
697695 httpClientContext ,
698- jsonResumableWrite (uploadUrl ),
696+ jsonResumableWrite (uri ),
699697 RewindableContent .of (tmpFile .getPath ()),
700698 HttpContentRange .of (ByteRangeSpec .explicit (_512KiBL , _768KiBL )));
701699
@@ -719,16 +717,16 @@ public void _503_emptyBody() throws Exception {
719717 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler );
720718 TmpFile tmpFile =
721719 DataGenerator .base64Characters ().tempFile (temp .newFolder ().toPath (), _256KiBL )) {
722- URI endpoint = fakeHttpServer . getEndpoint ();
723- String uploadUrl =
724- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
720+ URI uri =
721+ fakeHttpServer . createUri (
722+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
725723
726724 AtomicLong confirmedBytes = new AtomicLong (-1L );
727725
728726 JsonResumableSessionPutTask task =
729727 new JsonResumableSessionPutTask (
730728 httpClientContext ,
731- jsonResumableWrite (uploadUrl ),
729+ jsonResumableWrite (uri ),
732730 RewindableContent .of (tmpFile .getPath ()),
733731 HttpContentRange .of (ByteRangeSpec .explicit (_512KiBL , _768KiBL )));
734732
@@ -761,16 +759,16 @@ public void jsonParseFailure() throws Exception {
761759 };
762760
763761 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
764- URI endpoint = fakeHttpServer . getEndpoint ();
765- String uploadUrl =
766- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
762+ URI uri =
763+ fakeHttpServer . createUri (
764+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
767765
768766 AtomicLong confirmedBytes = new AtomicLong (-1L );
769767
770768 JsonResumableSessionPutTask task =
771769 new JsonResumableSessionPutTask (
772770 httpClientContext ,
773- jsonResumableWrite (uploadUrl ),
771+ jsonResumableWrite (uri ),
774772 RewindableContent .empty (),
775773 HttpContentRange .of (0 ));
776774
@@ -802,14 +800,14 @@ public void jsonDeserializationOnlyAttemptedWhenContentPresent() throws Exceptio
802800 };
803801
804802 try (FakeHttpServer fakeHttpServer = FakeHttpServer .of (handler )) {
805- URI endpoint = fakeHttpServer . getEndpoint ();
806- String uploadUrl =
807- String . format ( Locale . US , "%s /upload/%s " , endpoint . toString () , UUID .randomUUID ());
803+ URI uri =
804+ fakeHttpServer . createUri (
805+ " /upload/{uploadId} " , ImmutableMap . of ( "uploadId" , UUID .randomUUID (). toString () ));
808806
809807 JsonResumableSessionPutTask task =
810808 new JsonResumableSessionPutTask (
811809 httpClientContext ,
812- jsonResumableWrite (uploadUrl ),
810+ jsonResumableWrite (uri ),
813811 RewindableContent .empty (),
814812 HttpContentRange .of (0 ));
815813
@@ -878,7 +876,7 @@ public void repeatedRewindsToTheSameLocationWork() {
878876 assertThat (buf2 .position ()).isEqualTo (13 );
879877 }
880878
881- static @ NonNull JsonResumableWrite jsonResumableWrite (String uploadUrl ) {
882- return JsonResumableWrite .of (new StorageObject (), ImmutableMap .of (), uploadUrl , 0 );
879+ static @ NonNull JsonResumableWrite jsonResumableWrite (URI uploadUrl ) {
880+ return JsonResumableWrite .of (new StorageObject (), ImmutableMap .of (), uploadUrl . toString () , 0 );
883881 }
884882}
0 commit comments