From 2b59c119eb9804fa9107183da8f4685e0b54543b Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Mon, 25 Oct 2021 10:52:52 -0700 Subject: [PATCH 1/3] Support HttpMethod OPTIONS --- .../com/azure/autorest/mapper/MethodGroupMapper.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/javagen/src/main/java/com/azure/autorest/mapper/MethodGroupMapper.java b/javagen/src/main/java/com/azure/autorest/mapper/MethodGroupMapper.java index 3daa846e81..44b369bb2e 100644 --- a/javagen/src/main/java/com/azure/autorest/mapper/MethodGroupMapper.java +++ b/javagen/src/main/java/com/azure/autorest/mapper/MethodGroupMapper.java @@ -78,11 +78,7 @@ private MethodGroupClient createMethodGroupClient(OperationGroup methodGroup) { List restAPIMethods = new ArrayList<>(); for (Operation method : methodGroup.getOperations()) { - // azure-core does not support OPTIONS HTTP method. - // https://github.com/Azure/autorest.java/issues/453 - if (!"options".equals(method.getRequests().get(0).getProtocol().getHttp().getMethod())) { - restAPIMethods.addAll(Mappers.getProxyMethodMapper().map(method).values()); - } + restAPIMethods.addAll(Mappers.getProxyMethodMapper().map(method).values()); } proxyBuilder.methods(restAPIMethods); @@ -119,11 +115,7 @@ private MethodGroupClient createMethodGroupClient(OperationGroup methodGroup) { List clientMethods = new ArrayList<>(); for (Operation operation : methodGroup.getOperations()) { - // "options" is not supported in HttpMethod in azure-core - // https://github.com/Azure/autorest.java/issues/453 - if (!"options".equals(operation.getRequests().get(0).getProtocol().getHttp().getMethod())) { - clientMethods.addAll(Mappers.getClientMethodMapper().map(operation)); - } + clientMethods.addAll(Mappers.getClientMethodMapper().map(operation)); } builder.clientMethods(clientMethods); builder.supportedInterfaces(supportedInterfaces(methodGroup, clientMethods)); From 0baa0dfa8255c919ccd9ff146e6074f5cfa94de7 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 11 Nov 2021 16:30:28 -0800 Subject: [PATCH 2/3] Finish supporting OPTIONS --- .../HttpClientFailureAsyncClient.java | 42 +++ .../HttpClientFailureClient.java | 42 +++ .../HttpRedirectsAsyncClient.java | 14 + .../HttpRedirectsClient.java | 14 + .../HttpRetryAsyncClient.java | 20 ++ .../httpinfrastructure/HttpRetryClient.java | 20 ++ .../HttpSuccessAsyncClient.java | 20 ++ .../httpinfrastructure/HttpSuccessClient.java | 20 ++ .../HttpClientFailuresImpl.java | 133 ++++++++ .../implementation/HttpRedirectsImpl.java | 45 +++ .../implementation/HttpRetriesImpl.java | 63 ++++ .../implementation/HttpSuccessImpl.java | 63 ++++ vanilla-tests/pom.xml | 28 +- .../HttpClientFailures.java | 136 ++++++++ .../httpinfrastructure/HttpRedirects.java | 51 ++- .../httpinfrastructure/HttpRetries.java | 61 ++++ .../httpinfrastructure/HttpSuccess.java | 61 ++++ .../HttpClientFailureTests.java | 295 ++++-------------- .../httpinfrastructure/HttpFailureTests.java | 44 ++- .../httpinfrastructure/HttpRedirectTests.java | 117 +++---- .../httpinfrastructure/HttpRetryTests.java | 133 +++----- .../HttpServerFailureTests.java | 72 ++--- .../httpinfrastructure/HttpSuccessTests.java | 147 +++------ 23 files changed, 1067 insertions(+), 574 deletions(-) diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailureAsyncClient.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailureAsyncClient.java index 2467c0f677..417b9aac0f 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailureAsyncClient.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailureAsyncClient.java @@ -57,6 +57,20 @@ public Mono> get400WithResponse(RequestOptions requestOptions) { return this.serviceClient.get400WithResponseAsync(requestOptions); } + /** + * Return 400 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options400WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options400WithResponseAsync(requestOptions); + } + /** * Return 400 status code - should be represented in the client as an error. * @@ -165,6 +179,20 @@ public Mono> get402WithResponse(RequestOptions requestOptions) { return this.serviceClient.get402WithResponseAsync(requestOptions); } + /** + * Return 403 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options403WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options403WithResponseAsync(requestOptions); + } + /** * Return 403 status code - should be represented in the client as an error. * @@ -307,6 +335,20 @@ public Mono> get411WithResponse(RequestOptions requestOptions) { return this.serviceClient.get411WithResponseAsync(requestOptions); } + /** + * Return 412 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options412WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options412WithResponseAsync(requestOptions); + } + /** * Return 412 status code - should be represented in the client as an error. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailureClient.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailureClient.java index c4d2ca39b0..1e1ca0341c 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailureClient.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailureClient.java @@ -56,6 +56,20 @@ public Response get400WithResponse(RequestOptions requestOptions) { return this.serviceClient.get400WithResponse(requestOptions); } + /** + * Return 400 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options400WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options400WithResponse(requestOptions); + } + /** * Return 400 status code - should be represented in the client as an error. * @@ -164,6 +178,20 @@ public Response get402WithResponse(RequestOptions requestOptions) { return this.serviceClient.get402WithResponse(requestOptions); } + /** + * Return 403 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options403WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options403WithResponse(requestOptions); + } + /** * Return 403 status code - should be represented in the client as an error. * @@ -306,6 +334,20 @@ public Response get411WithResponse(RequestOptions requestOptions) { return this.serviceClient.get411WithResponse(requestOptions); } + /** + * Return 412 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options412WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options412WithResponse(requestOptions); + } + /** * Return 412 status code - should be represented in the client as an error. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirectsAsyncClient.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirectsAsyncClient.java index 7c7dc02fb6..193e89c286 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirectsAsyncClient.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirectsAsyncClient.java @@ -213,6 +213,20 @@ public Mono> get307WithResponse(RequestOptions requestOptions) { return this.serviceClient.get307WithResponseAsync(requestOptions); } + /** + * options redirected with 307, resulting in a 200 after redirect. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options307WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options307WithResponseAsync(requestOptions); + } + /** * Put redirected with 307, resulting in a 200 after redirect. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirectsClient.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirectsClient.java index d7f06dd597..bac71ced0b 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirectsClient.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirectsClient.java @@ -212,6 +212,20 @@ public Response get307WithResponse(RequestOptions requestOptions) { return this.serviceClient.get307WithResponse(requestOptions); } + /** + * options redirected with 307, resulting in a 200 after redirect. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options307WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options307WithResponse(requestOptions); + } + /** * Put redirected with 307, resulting in a 200 after redirect. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRetryAsyncClient.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRetryAsyncClient.java index 797fe4ba08..6f87e7abfa 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRetryAsyncClient.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRetryAsyncClient.java @@ -97,6 +97,26 @@ public Mono> get502WithResponse(RequestOptions requestOptions) { return this.serviceClient.get502WithResponseAsync(requestOptions); } + /** + * Return 502 status code, then 200 after retry. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options502WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options502WithResponseAsync(requestOptions); + } + /** * Return 503 status code, then 200 after retry. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRetryClient.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRetryClient.java index 84101fe5e6..71f15167e6 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRetryClient.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpRetryClient.java @@ -96,6 +96,26 @@ public Response get502WithResponse(RequestOptions requestOptions) { return this.serviceClient.get502WithResponse(requestOptions); } + /** + * Return 502 status code, then 200 after retry. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options502WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options502WithResponse(requestOptions); + } + /** * Return 503 status code, then 200 after retry. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccessAsyncClient.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccessAsyncClient.java index cbdb08f6fd..5b7545c9fa 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccessAsyncClient.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccessAsyncClient.java @@ -63,6 +63,26 @@ public Mono> get200WithResponse(RequestOptions requestOptions) return this.serviceClient.get200WithResponseAsync(requestOptions); } + /** + * Options 200 success. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options200WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options200WithResponseAsync(requestOptions); + } + /** * Put boolean value true returning 200 success. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccessClient.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccessClient.java index 5d8148bc7c..5782e960f9 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccessClient.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccessClient.java @@ -62,6 +62,26 @@ public Response get200WithResponse(RequestOptions requestOptions) { return this.serviceClient.get200WithResponse(requestOptions); } + /** + * Options 200 success. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options200WithResponse(RequestOptions requestOptions) { + return this.serviceClient.options200WithResponse(requestOptions); + } + /** * Put boolean value true returning 200 success. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpClientFailuresImpl.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpClientFailuresImpl.java index f4e0ccc0c3..aaf085016f 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpClientFailuresImpl.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpClientFailuresImpl.java @@ -9,6 +9,7 @@ import com.azure.core.annotation.Head; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Options; import com.azure.core.annotation.Patch; import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; @@ -56,6 +57,10 @@ private interface HttpClientFailuresService { @Get("/http/failure/client/400") Mono> get400(@HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Options("/http/failure/client/400") + Mono> options400( + @HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Put("/http/failure/client/400") Mono> put400(@HostParam("$host") String host, RequestOptions requestOptions, Context context); @@ -74,6 +79,10 @@ private interface HttpClientFailuresService { @Get("/http/failure/client/402") Mono> get402(@HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Options("/http/failure/client/403") + Mono> options403( + @HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Get("/http/failure/client/403") Mono> get403(@HostParam("$host") String host, RequestOptions requestOptions, Context context); @@ -98,6 +107,10 @@ private interface HttpClientFailuresService { @Get("/http/failure/client/411") Mono> get411(@HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Options("/http/failure/client/412") + Mono> options412( + @HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Get("/http/failure/client/412") Mono> get412(@HostParam("$host") String host, RequestOptions requestOptions, Context context); @@ -200,6 +213,46 @@ public Response get400WithResponse(RequestOptions requestOptions) { return get400WithResponseAsync(requestOptions).block(); } + /** + * Return 400 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options400WithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.options400(this.client.getHost(), requestOptions, context)); + } + + /** + * Return 400 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options400WithResponseAsync(RequestOptions requestOptions, Context context) { + return service.options400(this.client.getHost(), requestOptions, context); + } + + /** + * Return 400 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options400WithResponse(RequestOptions requestOptions) { + return options400WithResponseAsync(requestOptions).block(); + } + /** * Return 400 status code - should be represented in the client as an error. * @@ -512,6 +565,46 @@ public Response get402WithResponse(RequestOptions requestOptions) { return get402WithResponseAsync(requestOptions).block(); } + /** + * Return 403 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options403WithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.options403(this.client.getHost(), requestOptions, context)); + } + + /** + * Return 403 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options403WithResponseAsync(RequestOptions requestOptions, Context context) { + return service.options403(this.client.getHost(), requestOptions, context); + } + + /** + * Return 403 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options403WithResponse(RequestOptions requestOptions) { + return options403WithResponseAsync(requestOptions).block(); + } + /** * Return 403 status code - should be represented in the client as an error. * @@ -922,6 +1015,46 @@ public Response get411WithResponse(RequestOptions requestOptions) { return get411WithResponseAsync(requestOptions).block(); } + /** + * Return 412 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options412WithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.options412(this.client.getHost(), requestOptions, context)); + } + + /** + * Return 412 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options412WithResponseAsync(RequestOptions requestOptions, Context context) { + return service.options412(this.client.getHost(), requestOptions, context); + } + + /** + * Return 412 status code - should be represented in the client as an error. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options412WithResponse(RequestOptions requestOptions) { + return options412WithResponseAsync(requestOptions).block(); + } + /** * Return 412 status code - should be represented in the client as an error. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpRedirectsImpl.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpRedirectsImpl.java index f96b4fc396..ff7e39e44f 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpRedirectsImpl.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpRedirectsImpl.java @@ -9,6 +9,7 @@ import com.azure.core.annotation.Head; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Options; import com.azure.core.annotation.Patch; import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; @@ -84,6 +85,10 @@ Mono> get300( @Get("/http/redirect/307") Mono> get307(@HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Options("/http/redirect/307") + Mono> options307( + @HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Put("/http/redirect/307") Mono> put307(@HostParam("$host") String host, RequestOptions requestOptions, Context context); @@ -624,6 +629,46 @@ public Response get307WithResponse(RequestOptions requestOptions) { return get307WithResponseAsync(requestOptions).block(); } + /** + * options redirected with 307, resulting in a 200 after redirect. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options307WithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.options307(this.client.getHost(), requestOptions, context)); + } + + /** + * options redirected with 307, resulting in a 200 after redirect. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options307WithResponseAsync(RequestOptions requestOptions, Context context) { + return service.options307(this.client.getHost(), requestOptions, context); + } + + /** + * options redirected with 307, resulting in a 200 after redirect. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return the response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options307WithResponse(RequestOptions requestOptions) { + return options307WithResponseAsync(requestOptions).block(); + } + /** * Put redirected with 307, resulting in a 200 after redirect. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpRetriesImpl.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpRetriesImpl.java index a0742e38dc..448be353e0 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpRetriesImpl.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpRetriesImpl.java @@ -9,6 +9,7 @@ import com.azure.core.annotation.Head; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Options; import com.azure.core.annotation.Patch; import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; @@ -61,6 +62,10 @@ private interface HttpRetriesService { @Get("/http/retry/502") Mono> get502(@HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Options("/http/retry/502") + Mono> options502( + @HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Post("/http/retry/503") Mono> post503(@HostParam("$host") String host, RequestOptions requestOptions, Context context); @@ -270,6 +275,64 @@ public Response get502WithResponse(RequestOptions requestOptions) { return get502WithResponseAsync(requestOptions).block(); } + /** + * Return 502 status code, then 200 after retry. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options502WithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.options502(this.client.getHost(), requestOptions, context)); + } + + /** + * Return 502 status code, then 200 after retry. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options502WithResponseAsync(RequestOptions requestOptions, Context context) { + return service.options502(this.client.getHost(), requestOptions, context); + } + + /** + * Return 502 status code, then 200 after retry. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options502WithResponse(RequestOptions requestOptions) { + return options502WithResponseAsync(requestOptions).block(); + } + /** * Return 503 status code, then 200 after retry. * diff --git a/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpSuccessImpl.java b/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpSuccessImpl.java index 358441202b..7a4b676863 100644 --- a/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpSuccessImpl.java +++ b/protocol-tests/src/main/java/fixtures/httpinfrastructure/implementation/HttpSuccessImpl.java @@ -9,6 +9,7 @@ import com.azure.core.annotation.Head; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Options; import com.azure.core.annotation.Patch; import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; @@ -55,6 +56,10 @@ private interface HttpSuccessService { @Get("/http/success/200") Mono> get200(@HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Options("/http/success/200") + Mono> options200( + @HostParam("$host") String host, RequestOptions requestOptions, Context context); + @Put("/http/success/200") Mono> put200(@HostParam("$host") String host, RequestOptions requestOptions, Context context); @@ -203,6 +208,64 @@ public Response get200WithResponse(RequestOptions requestOptions) { return get200WithResponseAsync(requestOptions).block(); } + /** + * Options 200 success. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options200WithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.options200(this.client.getHost(), requestOptions, context)); + } + + /** + * Options 200 success. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options200WithResponseAsync(RequestOptions requestOptions, Context context) { + return service.options200(this.client.getHost(), requestOptions, context); + } + + /** + * Options 200 success. + * + *

Response Body Schema + * + *

{@code
+     * boolean
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if status code is 400 or above, if throwOnError in requestOptions is not + * false. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response options200WithResponse(RequestOptions requestOptions) { + return options200WithResponseAsync(requestOptions).block(); + } + /** * Put boolean value true returning 200 success. * diff --git a/vanilla-tests/pom.xml b/vanilla-tests/pom.xml index 8dc754c466..1316158009 100644 --- a/vanilla-tests/pom.xml +++ b/vanilla-tests/pom.xml @@ -46,7 +46,31 @@ junit junit - 4.13.1 + 4.13.2 + test + + + org.junit.jupiter + junit-jupiter-api + 5.7.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.7.2 + test + + + org.junit.jupiter + junit-jupiter-params + 5.7.2 + test + + + io.projectreactor + reactor-test + 3.4.10 test @@ -71,7 +95,7 @@ node - ${session.executionRootDirectory}/node_modules/@microsoft.azure/autorest.testserver + ${project.basedir}/../node_modules/@microsoft.azure/autorest.testserver . diff --git a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailures.java b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailures.java index 8b2bc07e89..4f9f06820b 100644 --- a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailures.java +++ b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpClientFailures.java @@ -7,6 +7,7 @@ import com.azure.core.annotation.HeaderParam; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Options; import com.azure.core.annotation.Patch; import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; @@ -58,6 +59,11 @@ Mono> head400( Mono> get400( @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Options("/http/failure/client/400") + @UnexpectedResponseExceptionType(ErrorException.class) + Mono> options400( + @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Put("/http/failure/client/400") @UnexpectedResponseExceptionType(ErrorException.class) Mono> put400( @@ -100,6 +106,11 @@ Mono> head401( Mono> get402( @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Options("/http/failure/client/403") + @UnexpectedResponseExceptionType(ErrorException.class) + Mono> options403( + @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Get("/http/failure/client/403") @UnexpectedResponseExceptionType(ErrorException.class) Mono> get403( @@ -155,6 +166,11 @@ Mono> head410( Mono> get411( @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Options("/http/failure/client/412") + @UnexpectedResponseExceptionType(ErrorException.class) + Mono> options412( + @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Get("/http/failure/client/412") @UnexpectedResponseExceptionType(ErrorException.class) Mono> get412( @@ -283,6 +299,46 @@ public void get400() { get400Async().block(); } + /** + * Return 400 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options400WithResponseAsync() { + if (this.client.getHost() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.options400(this.client.getHost(), accept, context)); + } + + /** + * Return 400 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono options400Async() { + return options400WithResponseAsync().flatMap((Response res) -> Mono.empty()); + } + + /** + * Return 400 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void options400() { + options400Async().block(); + } + /** * Return 400 status code - should be represented in the client as an error. * @@ -527,6 +583,46 @@ public void get402() { get402Async().block(); } + /** + * Return 403 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options403WithResponseAsync() { + if (this.client.getHost() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.options403(this.client.getHost(), accept, context)); + } + + /** + * Return 403 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono options403Async() { + return options403WithResponseAsync().flatMap((Response res) -> Mono.empty()); + } + + /** + * Return 403 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void options403() { + options403Async().block(); + } + /** * Return 403 status code - should be represented in the client as an error. * @@ -852,6 +948,46 @@ public void get411() { get411Async().block(); } + /** + * Return 412 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options412WithResponseAsync() { + if (this.client.getHost() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.options412(this.client.getHost(), accept, context)); + } + + /** + * Return 412 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono options412Async() { + return options412WithResponseAsync().flatMap((Response res) -> Mono.empty()); + } + + /** + * Return 412 status code - should be represented in the client as an error. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void options412() { + options412Async().block(); + } + /** * Return 412 status code - should be represented in the client as an error. * diff --git a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java index 09883e7f9f..49db270b01 100644 --- a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java +++ b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java @@ -8,6 +8,7 @@ import com.azure.core.annotation.HeaderParam; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Options; import com.azure.core.annotation.Patch; import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; @@ -28,15 +29,17 @@ import fixtures.httpinfrastructure.models.HttpRedirectsHead301Response; import fixtures.httpinfrastructure.models.HttpRedirectsHead302Response; import fixtures.httpinfrastructure.models.HttpRedirectsHead307Response; +import fixtures.httpinfrastructure.models.HttpRedirectsOptions307Response; import fixtures.httpinfrastructure.models.HttpRedirectsPatch302Response; import fixtures.httpinfrastructure.models.HttpRedirectsPatch307Response; import fixtures.httpinfrastructure.models.HttpRedirectsPost303Response; import fixtures.httpinfrastructure.models.HttpRedirectsPost307Response; import fixtures.httpinfrastructure.models.HttpRedirectsPut301Response; import fixtures.httpinfrastructure.models.HttpRedirectsPut307Response; -import java.util.List; import reactor.core.publisher.Mono; +import java.util.List; + /** An instance of this class provides access to all the operations defined in HttpRedirects. */ public final class HttpRedirects { /** The proxy service used to perform REST calls. */ @@ -138,6 +141,12 @@ Mono head307( Mono get307( @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Options("/http/redirect/307") + @ExpectedResponses({200, 307}) + @UnexpectedResponseExceptionType(ErrorException.class) + Mono options307( + @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Put("/http/redirect/307") @ExpectedResponses({200, 307}) @UnexpectedResponseExceptionType(ErrorException.class) @@ -636,6 +645,46 @@ public void get307() { get307Async().block(); } + /** + * options redirected with 307, resulting in a 200 after redirect. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono options307WithResponseAsync() { + if (this.client.getHost() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.options307(this.client.getHost(), accept, context)); + } + + /** + * options redirected with 307, resulting in a 200 after redirect. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the completion. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono options307Async() { + return options307WithResponseAsync().flatMap((HttpRedirectsOptions307Response res) -> Mono.empty()); + } + + /** + * options redirected with 307, resulting in a 200 after redirect. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void options307() { + options307Async().block(); + } + /** * Put redirected with 307, resulting in a 200 after redirect. * diff --git a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRetries.java b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRetries.java index b646615411..1a1e00c10a 100644 --- a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRetries.java +++ b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRetries.java @@ -8,6 +8,7 @@ import com.azure.core.annotation.HeaderParam; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Options; import com.azure.core.annotation.Patch; import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; @@ -78,6 +79,12 @@ Mono> patch500( Mono> get502( @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Options("/http/retry/502") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(ErrorException.class) + Mono> options502( + @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Post("/http/retry/503") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) @@ -277,6 +284,60 @@ public void get502() { get502Async().block(); } + /** + * Return 502 status code, then 200 after retry. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options502WithResponseAsync() { + if (this.client.getHost() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.options502(this.client.getHost(), accept, context)); + } + + /** + * Return 502 status code, then 200 after retry. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono options502Async() { + return options502WithResponseAsync() + .flatMap( + (Response res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Return 502 status code, then 200 after retry. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public boolean options502() { + Boolean value = options502Async().block(); + if (value != null) { + return value; + } else { + throw new NullPointerException(); + } + } + /** * Return 503 status code, then 200 after retry. * diff --git a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccess.java b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccess.java index c3079b1920..5f5793640f 100644 --- a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccess.java +++ b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpSuccess.java @@ -8,6 +8,7 @@ import com.azure.core.annotation.HeaderParam; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Options; import com.azure.core.annotation.Patch; import com.azure.core.annotation.Post; import com.azure.core.annotation.Put; @@ -60,6 +61,12 @@ Mono> head200( Mono> get200( @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Options("/http/success/200") + @ExpectedResponses({200}) + @UnexpectedResponseExceptionType(ErrorException.class) + Mono> options200( + @HostParam("$host") String host, @HeaderParam("Accept") String accept, Context context); + @Put("/http/success/200") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(ErrorException.class) @@ -293,6 +300,60 @@ public boolean get200() { } } + /** + * Options 200 success. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> options200WithResponseAsync() { + if (this.client.getHost() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.options200(this.client.getHost(), accept, context)); + } + + /** + * Options 200 success. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono options200Async() { + return options200WithResponseAsync() + .flatMap( + (Response res) -> { + if (res.getValue() != null) { + return Mono.just(res.getValue()); + } else { + return Mono.empty(); + } + }); + } + + /** + * Options 200 success. + * + * @throws ErrorException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return simple boolean. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public boolean options200() { + Boolean value = options200Async().block(); + if (value != null) { + return value; + } else { + throw new NullPointerException(); + } + } + /** * Put boolean value true returning 200 success. * diff --git a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpClientFailureTests.java b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpClientFailureTests.java index d335fae07b..cf1882f966 100644 --- a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpClientFailureTests.java +++ b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpClientFailureTests.java @@ -1,247 +1,64 @@ package fixtures.httpinfrastructure; import fixtures.httpinfrastructure.models.ErrorException; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -import static org.junit.Assert.fail; +import java.util.stream.Stream; -public class HttpClientFailureTests { - private static AutoRestHttpInfrastructureTestService client; - - @BeforeClass - public static void setup() { - client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); - } - - @Test - public void head400() throws Exception { - try { - client.getHttpClientFailures().head400(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(400, ex.getResponse().getStatusCode()); - } - } - - @Test - public void get400() throws Exception { - try { - client.getHttpClientFailures().get400(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(400, ex.getResponse().getStatusCode()); - } - } - - @Test - public void put400() throws Exception { - try { - client.getHttpClientFailures().put400(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(400, ex.getResponse().getStatusCode()); - } - } - - @Test - public void patch400() throws Exception { - try { - client.getHttpClientFailures().patch400(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(400, ex.getResponse().getStatusCode()); - } - } - - @Test - public void post400() throws Exception { - try { - client.getHttpClientFailures().post400(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(400, ex.getResponse().getStatusCode()); - } - } - - @Test - public void delete400() throws Exception { - try { - client.getHttpClientFailures().delete400(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(400, ex.getResponse().getStatusCode()); - } - } - - @Test - public void head401() throws Exception { - try { - client.getHttpClientFailures().head401(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(401, ex.getResponse().getStatusCode()); - } - } - - @Test - public void get402() throws Exception { - try { - client.getHttpClientFailures().get402(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(402, ex.getResponse().getStatusCode()); - } - } - - @Test - public void get403() throws Exception { - try { - client.getHttpClientFailures().get403(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(403, ex.getResponse().getStatusCode()); - } - } - - @Test - public void put404() throws Exception { - try { - client.getHttpClientFailures().put404(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(404, ex.getResponse().getStatusCode()); - } - } - - @Test - public void patch405() throws Exception { - try { - client.getHttpClientFailures().patch405(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(405, ex.getResponse().getStatusCode()); - } - } +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; - @Test - public void post406() throws Exception { - try { - client.getHttpClientFailures().post406(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(406, ex.getResponse().getStatusCode()); - } - } - - @Test - public void delete407() throws Exception { - try { - client.getHttpClientFailures().delete407(); - fail(); - } catch (RuntimeException ex) { - Assert.assertTrue(ex.getMessage().contains("Status code 407")); - } - } - - @Test - public void put409() throws Exception { - try { - client.getHttpClientFailures().put409(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(409, ex.getResponse().getStatusCode()); - } - } - - @Test - public void head410() throws Exception { - try { - client.getHttpClientFailures().head410(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(410, ex.getResponse().getStatusCode()); - } - } - - @Test - public void get411() throws Exception { - try { - client.getHttpClientFailures().get411(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(411, ex.getResponse().getStatusCode()); - } - } - - @Test - public void get412() throws Exception { - try { - client.getHttpClientFailures().get412(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(412, ex.getResponse().getStatusCode()); - } - } - - @Test - public void put413() throws Exception { - try { - client.getHttpClientFailures().put413(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(413, ex.getResponse().getStatusCode()); - } - } - - @Test - public void patch414() throws Exception { - try { - client.getHttpClientFailures().patch414(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(414, ex.getResponse().getStatusCode()); - } - } - - @Test - public void post415() throws Exception { - try { - client.getHttpClientFailures().post415(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(415, ex.getResponse().getStatusCode()); - } - } - - @Test - public void get416() throws Exception { - try { - client.getHttpClientFailures().get416(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(416, ex.getResponse().getStatusCode()); - } - } - - @Test - public void delete417() throws Exception { - try { - client.getHttpClientFailures().delete417(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(417, ex.getResponse().getStatusCode()); - } - } - - @Test - public void head429() throws Exception { - try { - client.getHttpClientFailures().head429(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(429, ex.getResponse().getStatusCode()); +public class HttpClientFailureTests { + private static AutoRestHttpInfrastructureTestService client; + + @BeforeAll + public static void setup() { + client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); + } + + @ParameterizedTest + @MethodSource("httpClientFailureSupplier") + public void httpClientFailure(Executable executable, int expectedStatusCode) { + ErrorException ex = assertThrows(ErrorException.class, executable); + assertEquals(expectedStatusCode, ex.getResponse().getStatusCode()); + } + + public static Stream httpClientFailureSupplier() { + return Stream.of( + Arguments.of(createExecution(() -> client.getHttpClientFailures().head400()), 400), + Arguments.of(createExecution(() -> client.getHttpClientFailures().get400()), 400), + Arguments.of(createExecution(() -> client.getHttpClientFailures().options400()), 400), + Arguments.of(createExecution(() -> client.getHttpClientFailures().put400()), 400), + Arguments.of(createExecution(() -> client.getHttpClientFailures().patch400()), 400), + Arguments.of(createExecution(() -> client.getHttpClientFailures().post400()), 400), + Arguments.of(createExecution(() -> client.getHttpClientFailures().delete400()), 400), + Arguments.of(createExecution(() -> client.getHttpClientFailures().head401()), 401), + Arguments.of(createExecution(() -> client.getHttpClientFailures().get402()), 402), + Arguments.of(createExecution(() -> client.getHttpClientFailures().options403()), 403), + Arguments.of(createExecution(() -> client.getHttpClientFailures().get403()), 403), + Arguments.of(createExecution(() -> client.getHttpClientFailures().put404()), 404), + Arguments.of(createExecution(() -> client.getHttpClientFailures().patch405()), 405), + Arguments.of(createExecution(() -> client.getHttpClientFailures().post406()), 406), + Arguments.of(createExecution(() -> client.getHttpClientFailures().delete407()), 407), + Arguments.of(createExecution(() -> client.getHttpClientFailures().put409()), 409), + Arguments.of(createExecution(() -> client.getHttpClientFailures().head410()), 410), + Arguments.of(createExecution(() -> client.getHttpClientFailures().get411()), 411), + Arguments.of(createExecution(() -> client.getHttpClientFailures().options412()), 412), + Arguments.of(createExecution(() -> client.getHttpClientFailures().get412()), 412), + Arguments.of(createExecution(() -> client.getHttpClientFailures().put413()), 413), + Arguments.of(createExecution(() -> client.getHttpClientFailures().patch414()), 414), + Arguments.of(createExecution(() -> client.getHttpClientFailures().post415()), 415), + Arguments.of(createExecution(() -> client.getHttpClientFailures().get416()), 416), + Arguments.of(createExecution(() -> client.getHttpClientFailures().delete417()), 417), + Arguments.of(createExecution(() -> client.getHttpClientFailures().head429()), 429) + ); + } + + private static Executable createExecution(Runnable runnable) { + return runnable::run; } - } } diff --git a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpFailureTests.java b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpFailureTests.java index 7c35f863eb..3309e4c078 100644 --- a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpFailureTests.java +++ b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpFailureTests.java @@ -2,38 +2,30 @@ import com.azure.core.exception.HttpResponseException; import fixtures.httpinfrastructure.models.ErrorException; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.Assert.fail; public class HttpFailureTests { - private static AutoRestHttpInfrastructureTestService client; + private static AutoRestHttpInfrastructureTestService client; - @BeforeClass - public static void setup() { - client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); - } + @BeforeAll + public static void setup() { + client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); + } - @Test - public void getEmptyError() throws Exception { - try { - client.getHttpFailures().getEmptyError(); - fail(); - } catch (ErrorException ex) { - Assert.assertEquals(400, ex.getResponse().getStatusCode()); + @Test + public void getEmptyError() { + ErrorException ex = assertThrows(ErrorException.class, () -> client.getHttpFailures().getEmptyError()); + assertEquals(400, ex.getResponse().getStatusCode()); } - } - @Test - public void getNoModelError() throws Exception { - try { - client.getHttpFailures().getNoModelError(); - fail(); - } catch (HttpResponseException ex) { - Assert.assertEquals(400, ex.getResponse().getStatusCode()); - //Assert.assertTrue(ex.getgetResponse().raw().toString().contains("NoErrorModel")); + @Test + public void getNoModelError() { + HttpResponseException ex = assertThrows(HttpResponseException.class, () -> client.getHttpFailures().getNoModelError()); + assertEquals(400, ex.getResponse().getStatusCode()); } - } } diff --git a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpRedirectTests.java b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpRedirectTests.java index 4f8bb3f658..244765cdb5 100644 --- a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpRedirectTests.java +++ b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpRedirectTests.java @@ -1,88 +1,53 @@ package fixtures.httpinfrastructure; -import org.junit.BeforeClass; -import org.junit.Test; +import com.azure.core.http.rest.Response; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import java.time.Duration; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class HttpRedirectTests { private static AutoRestHttpInfrastructureTestService client; - @BeforeClass + @BeforeAll public static void setup() { client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); } - @Test - public void head300() throws Exception { - client.getHttpRedirects().head300(); - } - - @Test - public void get300() throws Exception { - client.getHttpRedirects().get300(); - } - - @Test - public void head301() throws Exception { - client.getHttpRedirects().head301(); - } - - @Test - public void get301() throws Exception { - client.getHttpRedirects().get301(); - } - - @Test - public void put301() throws Exception { - client.getHttpRedirects().put301(); - } - - @Test - public void head302() throws Exception { - client.getHttpRedirects().head302(); - } - - @Test - public void get302() throws Exception { - client.getHttpRedirects().get302(); - } - - @Test - public void patch302() throws Exception { - client.getHttpRedirects().patch302(); - } - - @Test - public void post303() throws Exception { - client.getHttpRedirects().post303(); - } - - @Test - public void head307() throws Exception { - client.getHttpRedirects().head307(); - } - - @Test - public void get307() throws Exception { - client.getHttpRedirects().get307(); - } - - @Test - public void put307() throws Exception { - client.getHttpRedirects().put307(); - } - - @Test - public void patch307() throws Exception { - client.getHttpRedirects().patch307(); - } - - @Test - public void post307() throws Exception { - client.getHttpRedirects().post307(); - } - - @Test - public void delete307() throws Exception { - client.getHttpRedirects().delete307(); + @ParameterizedTest + @MethodSource("httpRedirectSupplier") + public void httpRedirect(Mono> call, int expectedStatusCode) { + StepVerifier.create(call) + .assertNext(response -> assertEquals(expectedStatusCode, response.getStatusCode())) + .expectComplete() + .verify(Duration.ofSeconds(10)); + } + + public static Stream httpRedirectSupplier() { + return Stream.of( + Arguments.of(Mono.defer(() -> client.getHttpRedirects().head300WithResponseAsync()), 300), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().get300WithResponseAsync()), 300), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().head301WithResponseAsync()), 301), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().get301WithResponseAsync()), 301), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().put301WithResponseAsync()), 301), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().head302WithResponseAsync()), 302), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().get302WithResponseAsync()), 302), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().patch302WithResponseAsync()), 302), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().post303WithResponseAsync()), 303), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().head307WithResponseAsync()), 307), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().get307WithResponseAsync()), 307), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().options307WithResponseAsync()), 307), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().put307WithResponseAsync()), 307), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().patch307WithResponseAsync()), 307), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().post307WithResponseAsync()), 307), + Arguments.of(Mono.defer(() -> client.getHttpRedirects().delete307WithResponseAsync()), 307) + ); } } diff --git a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpRetryTests.java b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpRetryTests.java index 5a3563b8de..72e85cdfc2 100644 --- a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpRetryTests.java +++ b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpRetryTests.java @@ -3,99 +3,48 @@ import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.CookiePolicy; import com.azure.core.http.policy.RetryPolicy; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import com.azure.core.http.rest.Response; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; -public class HttpRetryTests { - private static AutoRestHttpInfrastructureTestService client; - private CountDownLatch lock = new CountDownLatch(1); - - @BeforeClass - public static void setup() { - client = new AutoRestHttpInfrastructureTestServiceBuilder() - .pipeline(new HttpPipelineBuilder().policies(new RetryPolicy(), new CookiePolicy()).build()).buildClient(); - } - - @Test - public void head408() throws Exception { - client.getHttpRetries().head408WithResponseAsync() - .subscribe(response -> { - Assert.assertEquals(200, response.getStatusCode()); - lock.countDown(); - }); - Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS)); - } - - @Test - public void put500() throws Exception { - client.getHttpRetries().put500WithResponseAsync() - .subscribe(response -> { - Assert.assertEquals(200, response.getStatusCode()); - lock.countDown(); - }); - Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS)); - } - - @Test - public void patch500() throws Exception { - client.getHttpRetries().patch500WithResponseAsync() - .subscribe(response -> { - Assert.assertEquals(200, response.getStatusCode()); - lock.countDown(); - }); - Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS)); - } +import java.time.Duration; +import java.util.stream.Stream; - @Test - public void get502() throws Exception { - client.getHttpRetries().get502WithResponseAsync() - .subscribe(response -> { - Assert.assertEquals(200, response.getStatusCode()); - lock.countDown(); - }); - Assert.assertTrue(lock.await(50000, TimeUnit.MILLISECONDS)); - } +import static org.junit.jupiter.api.Assertions.assertEquals; - @Test - public void post503() throws Exception { - client.getHttpRetries().post503WithResponseAsync() - .subscribe(response -> { - Assert.assertEquals(200, response.getStatusCode()); - lock.countDown(); - }); - Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS)); - } - - @Test - public void delete503() throws Exception { - client.getHttpRetries().delete503WithResponseAsync() - .subscribe(response -> { - Assert.assertEquals(200, response.getStatusCode()); - lock.countDown(); - }); - Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS)); - } - - @Test - public void put504() throws Exception { - client.getHttpRetries().put504WithResponseAsync() - .subscribe(response -> { - Assert.assertEquals(200, response.getStatusCode()); - lock.countDown(); - }); - Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS)); - } - - @Test - public void patch504() throws Exception { - client.getHttpRetries().patch504WithResponseAsync() - .subscribe(response -> { - Assert.assertEquals(200, response.getStatusCode()); - lock.countDown(); - }); - Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS)); - } +public class HttpRetryTests { + private static AutoRestHttpInfrastructureTestService client; + + @BeforeAll + public static void setup() { + client = new AutoRestHttpInfrastructureTestServiceBuilder() + .pipeline(new HttpPipelineBuilder().policies(new RetryPolicy(), new CookiePolicy()).build()).buildClient(); + } + + @ParameterizedTest + @MethodSource("httpRetrySupplier") + public void httpRetry(Mono> call, int expectedStatusCode) { + StepVerifier.create(call) + .assertNext(response -> assertEquals(expectedStatusCode, response.getStatusCode())) + .expectComplete() + .verify(Duration.ofSeconds(1)); + } + + public static Stream httpRetrySupplier() { + return Stream.of( + Arguments.of(Mono.defer(() -> client.getHttpRetries().head408WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpRetries().put500WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpRetries().patch500WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpRetries().get502WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpRetries().options502WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpRetries().post503WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpRetries().delete503WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpRetries().put504WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpRetries().patch504WithResponseAsync()), 200) + ); + } } diff --git a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpServerFailureTests.java b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpServerFailureTests.java index 187d9cec75..ffad95ce8d 100644 --- a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpServerFailureTests.java +++ b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpServerFailureTests.java @@ -1,51 +1,41 @@ package fixtures.httpinfrastructure; import fixtures.httpinfrastructure.models.ErrorException; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class HttpServerFailureTests { - private static AutoRestHttpInfrastructureTestService client; - - @BeforeClass - public static void setup() { - client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); - } - - @Test - public void head501() throws Exception { - try { - client.getHttpServerFailures().head501(); - } catch (ErrorException ex) { - Assert.assertEquals(501, ex.getResponse().getStatusCode()); + private static AutoRestHttpInfrastructureTestService client; + + @BeforeAll + public static void setup() { + client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); } - } - - @Test - public void get501() throws Exception { - try { - client.getHttpServerFailures().get501(); - } catch (ErrorException ex) { - Assert.assertEquals(501, ex.getResponse().getStatusCode()); + + @Test + public void head501() { + ErrorException ex = assertThrows(ErrorException.class, () -> client.getHttpServerFailures().head501()); + assertEquals(501, ex.getResponse().getStatusCode()); } - } - - @Test - public void post505() throws Exception { - try { - client.getHttpServerFailures().post505(); - } catch (ErrorException ex) { - Assert.assertEquals(505, ex.getResponse().getStatusCode()); + + @Test + public void get501() { + ErrorException ex = assertThrows(ErrorException.class, () -> client.getHttpServerFailures().get501()); + assertEquals(501, ex.getResponse().getStatusCode()); } - } - - @Test - public void delete505() throws Exception { - try { - client.getHttpServerFailures().delete505(); - } catch (ErrorException ex) { - Assert.assertEquals(505, ex.getResponse().getStatusCode()); + + @Test + public void post505() { + ErrorException ex = assertThrows(ErrorException.class, () -> client.getHttpServerFailures().post505()); + assertEquals(505, ex.getResponse().getStatusCode()); + } + + @Test + public void delete505() { + ErrorException ex = assertThrows(ErrorException.class, () -> client.getHttpServerFailures().delete505()); + assertEquals(505, ex.getResponse().getStatusCode()); } - } } diff --git a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpSuccessTests.java b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpSuccessTests.java index 917fa2e566..f8f1457c39 100644 --- a/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpSuccessTests.java +++ b/vanilla-tests/src/test/java/fixtures/httpinfrastructure/HttpSuccessTests.java @@ -1,103 +1,56 @@ package fixtures.httpinfrastructure; -import org.junit.BeforeClass; -import org.junit.Test; +import com.azure.core.http.rest.Response; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; -public class HttpSuccessTests { - private static AutoRestHttpInfrastructureTestService client; - - @BeforeClass - public static void setup() { - client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); - } - - @Test - public void head200() throws Exception { - client.getHttpSuccess().head200(); - } - - @Test - public void get200() throws Exception { - client.getHttpSuccess().get200(); - } - - @Test - public void put200() throws Exception { - client.getHttpSuccess().put200(); - } - - @Test - public void patch200() throws Exception { - client.getHttpSuccess().patch200(); - } - - @Test - public void post200() throws Exception { - client.getHttpSuccess().post200(); - } - - @Test - public void delete200() throws Exception { - client.getHttpSuccess().delete200(); - } - - @Test - public void put201() throws Exception { - client.getHttpSuccess().put201(); - } - - @Test - public void post201() throws Exception { - client.getHttpSuccess().post201(); - } +import java.time.Duration; +import java.util.stream.Stream; - @Test - public void put202() throws Exception { - client.getHttpSuccess().put202(); - } +import static org.junit.jupiter.api.Assertions.assertEquals; - @Test - public void patch202() throws Exception { - client.getHttpSuccess().patch202(); - } - - @Test - public void post202() throws Exception { - client.getHttpSuccess().post202(); - } - - @Test - public void delete202() throws Exception { - client.getHttpSuccess().delete202(); - } - - @Test - public void head204() throws Exception { - client.getHttpSuccess().head204(); - } - - @Test - public void put204() throws Exception { - client.getHttpSuccess().put204(); - } - - @Test - public void patch204() throws Exception { - client.getHttpSuccess().patch204(); - } - - @Test - public void post204() throws Exception { - client.getHttpSuccess().post204(); - } - - @Test - public void delete204() throws Exception { - client.getHttpSuccess().delete204(); - } - - @Test - public void head404() throws Exception { - client.getHttpSuccess().head404(); - } +public class HttpSuccessTests { + private static AutoRestHttpInfrastructureTestService client; + + @BeforeAll + public static void setup() { + client = new AutoRestHttpInfrastructureTestServiceBuilder().buildClient(); + } + + @ParameterizedTest + @MethodSource("httpSuccessSupplier") + public void httpSuccess(Mono> call, int expectedStatusCode) { + StepVerifier.create(call) + .assertNext(response -> assertEquals(expectedStatusCode, response.getStatusCode())) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + public static Stream httpSuccessSupplier() { + return Stream.of( + Arguments.of(Mono.defer(() -> client.getHttpSuccess().head200WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().get200WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().options200WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().put200WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().patch200WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().post200WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().delete200WithResponseAsync()), 200), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().put201WithResponseAsync()), 201), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().post201WithResponseAsync()), 201), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().put202WithResponseAsync()), 202), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().patch202WithResponseAsync()), 202), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().post202WithResponseAsync()), 202), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().delete202WithResponseAsync()), 202), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().head204WithResponseAsync()), 204), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().put204WithResponseAsync()), 204), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().patch204WithResponseAsync()), 204), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().post204WithResponseAsync()), 204), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().delete204WithResponseAsync()), 204), + Arguments.of(Mono.defer(() -> client.getHttpSuccess().head404WithResponseAsync()), 404) + ); + } } From 79d084e8af314254a0a830cacc6104ed51b7d362 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 12 Nov 2021 09:30:06 -0800 Subject: [PATCH 3/3] Fix diff checking --- .../main/java/fixtures/httpinfrastructure/HttpRedirects.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java index 49db270b01..37661a4261 100644 --- a/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java +++ b/vanilla-tests/src/main/java/fixtures/httpinfrastructure/HttpRedirects.java @@ -36,9 +36,8 @@ import fixtures.httpinfrastructure.models.HttpRedirectsPost307Response; import fixtures.httpinfrastructure.models.HttpRedirectsPut301Response; import fixtures.httpinfrastructure.models.HttpRedirectsPut307Response; -import reactor.core.publisher.Mono; - import java.util.List; +import reactor.core.publisher.Mono; /** An instance of this class provides access to all the operations defined in HttpRedirects. */ public final class HttpRedirects {