diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/FakeHttpServer.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/FakeHttpServer.java index 294a04536..71bf4a2da 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/FakeHttpServer.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/FakeHttpServer.java @@ -20,6 +20,7 @@ import static io.grpc.netty.shaded.io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; import static io.grpc.netty.shaded.io.netty.handler.codec.http.HttpHeaderValues.CLOSE; +import com.google.api.client.http.UriTemplate; import com.google.api.gax.retrying.RetrySettings; import com.google.cloud.NoCredentials; import com.google.cloud.storage.it.runner.registry.Registry; @@ -48,6 +49,7 @@ import java.net.InetSocketAddress; import java.net.URI; import java.time.Duration; +import java.util.Map; final class FakeHttpServer implements AutoCloseable { @@ -64,12 +66,24 @@ private FakeHttpServer( this.httpStorageOptions = httpStorageOptions; } - public HttpStorageOptions getHttpStorageOptions() { - return httpStorageOptions; + /** + * overload which calls {@link #createUri(String, Map, boolean)} with {@code createUri(template, + * params, false)} + */ + public URI createUri(String template, Map params) { + return createUri(template, params, false); } - public URI getEndpoint() { - return endpoint; + /** Decorator for {@link UriTemplate#expand(String, String, Object, boolean)} */ + public URI createUri( + String template, Map params, boolean addUnusedParamsAsQueryParams) { + String expand = + UriTemplate.expand(endpoint.toString(), template, params, addUnusedParamsAsQueryParams); + return URI.create(expand); + } + + public HttpStorageOptions getHttpStorageOptions() { + return httpStorageOptions; } @Override diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionPutTaskTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionPutTaskTest.java index a132d1329..5401a1df0 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionPutTaskTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionPutTaskTest.java @@ -48,7 +48,6 @@ import java.net.URI; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; -import java.util.Locale; import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; import org.checkerframework.checker.nullness.qual.NonNull; @@ -95,14 +94,14 @@ public void emptyObjectHappyPath() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(ByteRangeSpec.explicitClosed(0L, 0L), 0)); @@ -142,16 +141,16 @@ public void scenario7() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(ByteRangeSpec.explicitClosed(0L, 10L))); @@ -224,16 +223,16 @@ public void scenario1() throws Exception { try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler); TmpFile tmpFile = DataGenerator.base64Characters().tempFile(temp.newFolder().toPath(), _256KiBL)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.of(tmpFile.getPath()), HttpContentRange.of(ByteRangeSpec.explicit(0L, _256KiBL))); @@ -294,16 +293,16 @@ public void scenario2() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(_256KiBL)); @@ -364,16 +363,16 @@ public void scenario3() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(_512KiBL)); @@ -445,22 +444,21 @@ public void scenario4() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(_256KiBL)); ResumableOperationResult<@Nullable StorageObject> operationResult = task.call(); StorageObject call = operationResult.getObject(); assertThat(call).isNotNull(); - assertThat(call.getMetadata()) - .containsEntry("upload_id", uploadUrl.substring(endpoint.toString().length())); + assertThat(call.getMetadata()).containsEntry("upload_id", uri.getPath()); assertThat(operationResult.getPersistedSize()).isEqualTo(_256KiBL); } } @@ -526,16 +524,16 @@ public void scenario4_1() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(_512KiBL)); @@ -607,16 +605,16 @@ public void scenario4_2() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(_128KiBL)); @@ -686,16 +684,16 @@ public void scenario5() throws Exception { try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler); TmpFile tmpFile = DataGenerator.base64Characters().tempFile(temp.newFolder().toPath(), _256KiBL)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.of(tmpFile.getPath()), HttpContentRange.of(ByteRangeSpec.explicit(_512KiBL, _768KiBL))); @@ -719,16 +717,16 @@ public void _503_emptyBody() throws Exception { try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler); TmpFile tmpFile = DataGenerator.base64Characters().tempFile(temp.newFolder().toPath(), _256KiBL)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.of(tmpFile.getPath()), HttpContentRange.of(ByteRangeSpec.explicit(_512KiBL, _768KiBL))); @@ -761,16 +759,16 @@ public void jsonParseFailure() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); AtomicLong confirmedBytes = new AtomicLong(-1L); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(0)); @@ -802,14 +800,14 @@ public void jsonDeserializationOnlyAttemptedWhenContentPresent() throws Exceptio }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionPutTask task = new JsonResumableSessionPutTask( httpClientContext, - jsonResumableWrite(uploadUrl), + jsonResumableWrite(uri), RewindableContent.empty(), HttpContentRange.of(0)); @@ -878,7 +876,7 @@ public void repeatedRewindsToTheSameLocationWork() { assertThat(buf2.position()).isEqualTo(13); } - static @NonNull JsonResumableWrite jsonResumableWrite(String uploadUrl) { - return JsonResumableWrite.of(new StorageObject(), ImmutableMap.of(), uploadUrl, 0); + static @NonNull JsonResumableWrite jsonResumableWrite(URI uploadUrl) { + return JsonResumableWrite.of(new StorageObject(), ImmutableMap.of(), uploadUrl.toString(), 0); } } diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionQueryTaskTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionQueryTaskTest.java index a7d923743..c50c01783 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionQueryTaskTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionQueryTaskTest.java @@ -32,6 +32,7 @@ import com.google.cloud.storage.it.runner.annotations.Backend; import com.google.cloud.storage.it.runner.annotations.ParallelFriendly; import com.google.cloud.storage.it.runner.annotations.SingleBackend; +import com.google.common.collect.ImmutableMap; import io.grpc.netty.shaded.io.netty.buffer.ByteBuf; import io.grpc.netty.shaded.io.netty.buffer.Unpooled; import io.grpc.netty.shaded.io.netty.handler.codec.http.DefaultFullHttpResponse; @@ -41,7 +42,6 @@ import java.math.BigInteger; import java.net.URI; import java.nio.charset.StandardCharsets; -import java.util.Locale; import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.Before; @@ -82,12 +82,12 @@ public void successfulSession() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionQueryTask task = - new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uploadUrl)); + new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uri)); ResumableOperationResult<@Nullable StorageObject> result = task.call(); StorageObject object = result.getObject(); @@ -106,12 +106,12 @@ public void successfulSession_noObject() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionQueryTask task = - new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uploadUrl)); + new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uri)); ResumableOperationResult<@Nullable StorageObject> result = task.call(); StorageObject object = result.getObject(); @@ -134,12 +134,12 @@ public void incompleteSession() throws Exception { return response; }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionQueryTask task = - new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uploadUrl)); + new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uri)); ResumableOperationResult<@Nullable StorageObject> result = task.call(); assertThat(result.getPersistedSize()).isEqualTo(_256KiBL); @@ -151,12 +151,12 @@ public void incompleteSession_missingRangeHeader() throws Exception { HttpRequestHandler handler = req -> new DefaultFullHttpResponse(req.protocolVersion(), RESUME_INCOMPLETE); try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionQueryTask task = - new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uploadUrl)); + new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uri)); ResumableOperationResult<@Nullable StorageObject> result = task.call(); assertThat(result.getPersistedSize()).isEqualTo(0); @@ -169,12 +169,12 @@ public void successfulSession_noJson_noStoredContentLength() throws Exception { HttpRequestHandler handler = req -> new DefaultFullHttpResponse(req.protocolVersion(), OK); try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionQueryTask task = - new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uploadUrl)); + new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uri)); StorageException se = assertThrows(StorageException.class, task::call); assertThat(se.getCode()).isEqualTo(0); @@ -196,12 +196,12 @@ public void successfulSession_noSize() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionQueryTask task = - new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uploadUrl)); + new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uri)); StorageException se = assertThrows(StorageException.class, task::call); assertThat(se.getCode()).isEqualTo(0); @@ -225,12 +225,12 @@ public void query_badOffset() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionQueryTask task = - new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uploadUrl)); + new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uri)); StorageException se = assertThrows(StorageException.class, task::call); assertThat(se.getCode()).isEqualTo(0); @@ -249,12 +249,12 @@ public void _503_emptyBody() throws Exception { }; try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); - String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + URI uri = + fakeHttpServer.createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())); JsonResumableSessionQueryTask task = - new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uploadUrl)); + new JsonResumableSessionQueryTask(httpClientContext, jsonResumableWrite(uri)); StorageException se = assertThrows(StorageException.class, task::call); assertThat(se.getCode()).isEqualTo(503); diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionTest.java index e3c95a126..497b82e01 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITJsonResumableSessionTest.java @@ -41,12 +41,10 @@ import io.grpc.netty.shaded.io.netty.handler.codec.http.DefaultFullHttpResponse; import io.grpc.netty.shaded.io.netty.handler.codec.http.HttpRequest; import io.grpc.netty.shaded.io.netty.handler.codec.http.HttpResponseStatus; -import java.net.URI; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.UnaryOperator; @@ -105,9 +103,11 @@ public void rewindWillQueryStatusOnlyWhenDirty() throws Exception { try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler); TmpFile tmpFile = DataGenerator.base64Characters().tempFile(temp.newFolder().toPath(), _512KiBL)) { - URI endpoint = fakeHttpServer.getEndpoint(); String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + fakeHttpServer + .createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())) + .toString(); JsonResumableWrite resumableWrite = JsonResumableWrite.of(null, ImmutableMap.of(), uploadUrl, 0); @@ -160,9 +160,11 @@ public void retryAttemptWillReturnQueryResultIfPersistedSizeMatchesSpecifiedEndO ByteBuffer buf2 = DataGenerator.base64Characters().genByteBuffer(_256KiB); try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + fakeHttpServer + .createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())) + .toString(); JsonResumableWrite resumableWrite = JsonResumableWrite.of(null, ImmutableMap.of(), uploadUrl, 0); @@ -228,9 +230,11 @@ public void rewindOfContentIsRelativeToItsBeginOffsetOfTheOverallObject() throws ByteBuffer buf2 = DataGenerator.base64Characters().genByteBuffer(_256KiB); try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler)) { - URI endpoint = fakeHttpServer.getEndpoint(); String uploadUrl = - String.format(Locale.US, "%s/upload/%s", endpoint.toString(), UUID.randomUUID()); + fakeHttpServer + .createUri( + "/upload/{uploadId}", ImmutableMap.of("uploadId", UUID.randomUUID().toString())) + .toString(); JsonResumableWrite resumableWrite = JsonResumableWrite.of(null, ImmutableMap.of(), uploadUrl, 0);