diff --git a/src/test/java/itest/UploadRecordingTest.java b/src/test/java/itest/UploadRecordingTest.java index ac0f32ecf..437b87e9a 100644 --- a/src/test/java/itest/UploadRecordingTest.java +++ b/src/test/java/itest/UploadRecordingTest.java @@ -67,7 +67,9 @@ public static void createRecording() throws Exception { CREATE_RECORDING_URL = String.format("/api/v1/targets/%s/recordings", getSelfReferenceConnectUrlEncoded()); HttpResponse resp = - webClient.post(CREATE_RECORDING_URL, true, form, RECORDING_DURATION_SECONDS); + webClient + .extensions() + .post(CREATE_RECORDING_URL, true, form, RECORDING_DURATION_SECONDS); MatcherAssert.assertThat(resp.statusCode(), Matchers.equalTo(201)); Thread.sleep( Long.valueOf( @@ -78,12 +80,14 @@ public static void createRecording() throws Exception { public static void deleteRecording() throws Exception { try { HttpResponse resp = - webClient.delete( - String.format( - "/api/v1/targets/%s/recordings/%s", - getSelfReferenceConnectUrlEncoded(), RECORDING_NAME), - true, - REQUEST_TIMEOUT_SECONDS); + webClient + .extensions() + .delete( + String.format( + "/api/v1/targets/%s/recordings/%s", + getSelfReferenceConnectUrlEncoded(), RECORDING_NAME), + true, + REQUEST_TIMEOUT_SECONDS); MatcherAssert.assertThat(resp.statusCode(), Matchers.equalTo(204)); } catch (InterruptedException | ExecutionException | TimeoutException e) { logger.error( @@ -97,13 +101,15 @@ public static void deleteRecording() throws Exception { public void shouldLoadRecordingToDatasource() throws Exception { HttpResponse resp = - webClient.post( - String.format( - "/api/v1/targets/%s/recordings/%s/upload", - getSelfReferenceConnectUrlEncoded(), RECORDING_NAME), - true, - null, - 0); + webClient + .extensions() + .post( + String.format( + "/api/v1/targets/%s/recordings/%s/upload", + getSelfReferenceConnectUrlEncoded(), RECORDING_NAME), + true, + null, + 0); MatcherAssert.assertThat(resp.statusCode(), Matchers.equalTo(200)); diff --git a/src/test/java/itest/util/Utils.java b/src/test/java/itest/util/Utils.java index 4af7dd51a..8363a263d 100644 --- a/src/test/java/itest/util/Utils.java +++ b/src/test/java/itest/util/Utils.java @@ -82,66 +82,80 @@ public static FileSystem getFileSystem() { return VERTX.fileSystem(); } + public interface RedirectExtensions { + HttpResponse post(String url, boolean authentication, MultiMap form, int timeout) + throws InterruptedException, ExecutionException, TimeoutException; + + HttpResponse delete(String url, boolean authentication, int timeout) + throws InterruptedException, ExecutionException, TimeoutException; + } + public static class TestWebClient extends WebClientBase { + public TestWebClient(HttpClient client, WebClientOptions options) { super(client, options); } - public HttpResponse post( - String url, boolean authentication, MultiMap form, int timeout) - throws InterruptedException, ExecutionException, TimeoutException { - CompletableFuture> future = new CompletableFuture<>(); - RequestOptions options = new RequestOptions().setURI(url); - HttpRequest req = this.request(HttpMethod.POST, options); - if (authentication) { - req.basicAuthentication("user", "pass"); - } - if (form != null) { - req.sendForm( - form, - ar -> { - if (ar.succeeded()) { - future.complete(ar.result()); - } else { - future.completeExceptionally(ar.cause()); - } - }); - } else { - req.send( - ar -> { - if (ar.succeeded()) { - future.complete(ar.result()); - } else { - future.completeExceptionally(ar.cause()); - } - }); - } - if (future.get().statusCode() == 308) { - return post(future.get().getHeader("Location"), true, form, timeout); - } - return future.get(timeout, TimeUnit.SECONDS); - } + public RedirectExtensions extensions() { + return new RedirectExtensions() { + public HttpResponse post( + String url, boolean authentication, MultiMap form, int timeout) + throws InterruptedException, ExecutionException, TimeoutException { + CompletableFuture> future = new CompletableFuture<>(); + RequestOptions options = new RequestOptions().setURI(url); + HttpRequest req = TestWebClient.this.request(HttpMethod.POST, options); + if (authentication) { + req.basicAuthentication("user", "pass"); + } + if (form != null) { + req.sendForm( + form, + ar -> { + if (ar.succeeded()) { + future.complete(ar.result()); + } else { + future.completeExceptionally(ar.cause()); + } + }); + } else { + req.send( + ar -> { + if (ar.succeeded()) { + future.complete(ar.result()); + } else { + future.completeExceptionally(ar.cause()); + } + }); + } + if (future.get().statusCode() == 308) { + return post(future.get().getHeader("Location"), true, form, timeout); + } + return future.get(timeout, TimeUnit.SECONDS); + } - public HttpResponse delete(String url, boolean authentication, int timeout) - throws InterruptedException, ExecutionException, TimeoutException { - CompletableFuture> future = new CompletableFuture<>(); - RequestOptions options = new RequestOptions().setURI(url); - HttpRequest req = this.request(HttpMethod.DELETE, options); - if (authentication) { - req.basicAuthentication("user", "pass"); - } - req.send( - ar -> { - if (ar.succeeded()) { - future.complete(ar.result()); - } else { - future.completeExceptionally(ar.cause()); - } - }); - if (future.get().statusCode() == 308) { - return delete(future.get().getHeader("Location"), true, timeout); - } - return future.get(timeout, TimeUnit.SECONDS); + public HttpResponse delete(String url, boolean authentication, int timeout) + throws InterruptedException, ExecutionException, TimeoutException { + CompletableFuture> future = new CompletableFuture<>(); + RequestOptions options = new RequestOptions().setURI(url); + HttpRequest req = + TestWebClient.this.request(HttpMethod.DELETE, options); + if (authentication) { + req.basicAuthentication("user", "pass"); + } + req.send( + ar -> { + if (ar.succeeded()) { + future.complete(ar.result()); + } else { + future.completeExceptionally(ar.cause()); + } + }); + if (future.get().statusCode() == 308) { + return delete(future.get().getHeader("Location"), true, timeout); + } + return future.get(timeout, TimeUnit.SECONDS); + } + }; } } }