From 3dc3ee08bc067498eb743c7e2697070de532ed17 Mon Sep 17 00:00:00 2001 From: Nicklas Wiegandt Date: Wed, 17 Jul 2024 06:19:31 +0200 Subject: [PATCH] test (JAVA SPRING RESTCLIENT) Add echo tests for the Spring 6 RestClient (#19145) * test (JAVA SPRING RESTTEMPLATE) 17571: Add echo-api multipart form single file test * feat (JAVA SPRING RESTCLIENT) 18522: Add RestClient to README * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo all of Pet test * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo body free form object response string test * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo body pet test * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo body pet response string test * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo body string enum test * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo body tag response test * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo form tests * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo header test * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo path test * test (JAVA SPRING RESTCLIENT) 18522: Add RestClient echo query tests * feat (JAVA SPRING RESTCLIENT) 18522: Regenerasted API Clients for RestClient with fixed import indentation --- README.md | 15 +- .../libraries/restclient/ApiClient.mustache | 4 +- .../org/openapitools/client/ApiClient.java | 4 +- .../openapitools/client/api/BodyApiTest.java | 115 +++++- .../openapitools/client/api/FormApiTest.java | 208 +++++++---- .../client/api/HeaderApiTest.java | 76 ++-- .../openapitools/client/api/PathApiTest.java | 64 ++-- .../openapitools/client/api/QueryApiTest.java | 347 ++++++++++-------- .../org/openapitools/client/ApiClient.java | 4 +- .../org/openapitools/client/ApiClient.java | 4 +- .../org/openapitools/client/ApiClient.java | 4 +- .../org/openapitools/client/ApiClient.java | 4 +- 12 files changed, 530 insertions(+), 319 deletions(-) diff --git a/README.md b/README.md index 61e07db46c63..68195c874354 100644 --- a/README.md +++ b/README.md @@ -84,13 +84,13 @@ If you find OpenAPI Generator useful for work, please consider asking your compa OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification) (both 2.0 and 3.0 are supported). Currently, the following languages/frameworks are supported: -| | Languages/Frameworks | -| -------------------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.1, .NET Core 3.1, .NET 5.0. Libraries: RestSharp, GenericHost, HttpClient), **C++** (Arduino, cpp-restsdk, Qt5, Tizen, Unreal Engine 4), **Clojure**, **Crystal**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Apache HttpClient 4.x, Apache HttpClient 5.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, MicroProfile Rest Client, Helidon), **Jetbrains HTTP Client**, **Julia**, **k6**, **Kotlin**, **Lua**, **N4JS**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types, Apollo GraphQL DataStore), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (hyper, reqwest, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient, pekko), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (AngularJS, Angular (9.x - 18.x), Aurelia, Axios, Fetch, Inversify, jQuery, Nestjs, Node, redux-query, Rxjs), **XoJo**, **Zapier** | -| **Server stubs** | **Ada**, **C#** (ASP.NET Core, Azure Functions), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant, Yesod), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/), [Apache Camel](https://camel.apache.org/), [Helidon](https://helidon.io/)), **Julia**, **Kotlin** (Spring Boot, [Ktor](https://github.com/ktorio/ktor), [Vert.x](https://vertx.io/)), **PHP** ([Flight](https://docs.flightphp.com/), Laravel, Lumen, [Mezzio (fka Zend Expressive)](https://github.com/mezzio/mezzio), Slim, Silex, [Symfony](https://symfony.com/)), **Python** (FastAPI, Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** ([rust-server](https://openapi-generator.tech/docs/generators/rust-server/)), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), [Cask](https://github.com/com-lihaoyi/cask), Scalatra) | -| **API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**, **Markdown**, **PlantUML** | -| **Configuration files** | [**Apache2**](https://httpd.apache.org/) | -| **Others** | **GraphQL**, **JMeter**, **Ktorm**, **MySQL Schema**, **Postman Collection**, **Protocol Buffer**, **WSDL** | +| | Languages/Frameworks | +| -------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.1, .NET Core 3.1, .NET 5.0. Libraries: RestSharp, GenericHost, HttpClient), **C++** (Arduino, cpp-restsdk, Qt5, Tizen, Unreal Engine 4), **Clojure**, **Crystal**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Apache HttpClient 4.x, Apache HttpClient 5.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, Spring 6 RestClient, MicroProfile Rest Client, Helidon), **Jetbrains HTTP Client**, **Julia**, **k6**, **Kotlin**, **Lua**, **N4JS**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types, Apollo GraphQL DataStore), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (hyper, reqwest, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient, pekko), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (AngularJS, Angular (9.x - 18.x), Aurelia, Axios, Fetch, Inversify, jQuery, Nestjs, Node, redux-query, Rxjs), **XoJo**, **Zapier** | +| **Server stubs** | **Ada**, **C#** (ASP.NET Core, Azure Functions), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant, Yesod), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/), [Apache Camel](https://camel.apache.org/), [Helidon](https://helidon.io/)), **Julia**, **Kotlin** (Spring Boot, [Ktor](https://github.com/ktorio/ktor), [Vert.x](https://vertx.io/)), **PHP** ([Flight](https://docs.flightphp.com/), Laravel, Lumen, [Mezzio (fka Zend Expressive)](https://github.com/mezzio/mezzio), Slim, Silex, [Symfony](https://symfony.com/)), **Python** (FastAPI, Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** ([rust-server](https://openapi-generator.tech/docs/generators/rust-server/)), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), [Cask](https://github.com/com-lihaoyi/cask), Scalatra) | +| **API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**, **Markdown**, **PlantUML** | +| **Configuration files** | [**Apache2**](https://httpd.apache.org/) | +| **Others** | **GraphQL**, **JMeter**, **Ktorm**, **MySQL Schema**, **Postman Collection**, **Protocol Buffer**, **WSDL** | ## Table of contents @@ -998,6 +998,7 @@ Here is a list of template creators: * Java (okhttp-gson): @xhh * Java (RestTemplate): @nbruno * Java (Spring 5 WebClient): @daonomic + * Java (Spring 6 RestClient): @nicklas2751 * Java (RESTEasy): @gayathrigs * Java (Vertx): @lopesmcc * Java (Google APIs Client Library): @charlescapps diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache index d6e0baeaee0e..a55ae95070a9 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache @@ -12,8 +12,8 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; - import org.springframework.http.converter.HttpMessageConverter; - import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; {{#withXml}} import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; {{/withXml}} diff --git a/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java index f65f1252309d..13ab8c39940f 100644 --- a/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java @@ -10,8 +10,8 @@ import org.springframework.http.HttpMethod; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; - import org.springframework.http.converter.HttpMessageConverter; - import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/BodyApiTest.java b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/BodyApiTest.java index 61840f4251bf..42145cd9d3b2 100644 --- a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/BodyApiTest.java +++ b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/BodyApiTest.java @@ -15,17 +15,22 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.junit.Test; import org.openapitools.client.ApiClient; import org.openapitools.client.GifHttpMessageConverter; import org.openapitools.client.OctetStreamHttpMessageConverter; +import org.openapitools.client.model.Category; import org.openapitools.client.model.Pet; +import org.openapitools.client.model.Pet.StatusEnum; import org.openapitools.client.model.StringEnumRef; import org.openapitools.client.model.Tag; @@ -117,11 +122,18 @@ public void testBodyMultipartFormdataArrayOfBinaryTest() throws IOException { *

Test single binary in multipart mime */ @Test - public void testBodyMultipartFormdataSingleBinaryTest() { - File myFile = null; - String response = api.testBodyMultipartFormdataSingleBinary(myFile); + public void testBodyMultipartFormdataSingleBinaryTest() throws IOException { + // given + var testFile = Files.createTempFile("test", ".txt"); + String testFileContent = "Lorem ipsum dolor sit amet"; + Files.writeString(testFile, testFileContent); + + // when + String response = api.testBodyMultipartFormdataSingleBinary(testFile.toFile()); - // TODO: test validations + // then + assertThat(response, containsString("Content-Type: multipart/form-data")); + assertThat(response, containsString(testFileContent)); } /** @@ -131,10 +143,26 @@ public void testBodyMultipartFormdataSingleBinaryTest() { */ @Test public void testEchoBodyAllOfPetTest() { - Pet pet = null; + // given + // The content length must be set to disable the Transfer-Encoding: chunked which would lead to + // unparsable response because the echo server is replying them as body. + api.getApiClient().addDefaultHeader("Content-Length", "192"); + + Pet pet = + new Pet() + .id(42L) + .name("Corgi") + .category(new Category().id(1L).name("Dogs")) + .status(StatusEnum.SOLD) + .addPhotoUrlsItem( + "https://cdn.pixabay.com/photo/2021/10/13/09/01/corgi-6705821_1280.jpg") + .addTagsItem(new Tag().id(1L).name("cute")); + + // when Pet response = api.testEchoBodyAllOfPet(pet); - // TODO: test validations + // then + assertThat(response, is(pet)); } /** @@ -144,10 +172,22 @@ public void testEchoBodyAllOfPetTest() { */ @Test public void testEchoBodyFreeFormObjectResponseStringTest() { - Object body = null; - String response = api.testEchoBodyFreeFormObjectResponseString(body); + // given + // The content length must be set to disable the Transfer-Encoding: chunked which would lead to + // unparsable response because the echo server is replying them as body. + api.getApiClient().addDefaultHeader("Content-Length", "51"); - // TODO: test validations + Object mapAsObject = + new HashMap<>( + Map.of( + "firstKey", "firstValue", + "secondKey", "secondValue")); + + // when + String response = api.testEchoBodyFreeFormObjectResponseString(mapAsObject); + + // then + assertThat(response, is("{\"firstKey\":\"firstValue\",\"secondKey\":\"secondValue\"}")); } /** @@ -157,10 +197,26 @@ public void testEchoBodyFreeFormObjectResponseStringTest() { */ @Test public void testEchoBodyPetTest() { - Pet pet = null; + // given + // The content length must be set to disable the Transfer-Encoding: chunked which would lead to + // unparsable response because the echo server is replying them as body. + api.getApiClient().addDefaultHeader("Content-Length", "192"); + + Pet pet = + new Pet() + .id(42L) + .name("Corgi") + .category(new Category().id(1L).name("Dogs")) + .status(StatusEnum.SOLD) + .addPhotoUrlsItem( + "https://cdn.pixabay.com/photo/2021/10/13/09/01/corgi-6705821_1280.jpg") + .addTagsItem(new Tag().id(1L).name("cute")); + + // when Pet response = api.testEchoBodyPet(pet); - // TODO: test validations + // then + assertThat(response, is(pet)); } /** @@ -170,10 +226,29 @@ public void testEchoBodyPetTest() { */ @Test public void testEchoBodyPetResponseStringTest() { - Pet pet = null; + // given + // The content length must be set to disable the Transfer-Encoding: chunked which would lead to + // unparsable response because the echo server is replying them as body. + api.getApiClient().addDefaultHeader("Content-Length", "192"); + + Pet pet = + new Pet() + .id(42L) + .name("Corgi") + .category(new Category().id(1L).name("Dogs")) + .status(StatusEnum.SOLD) + .addPhotoUrlsItem( + "https://cdn.pixabay.com/photo/2021/10/13/09/01/corgi-6705821_1280.jpg") + .addTagsItem(new Tag().id(1L).name("cute")); + + // when String response = api.testEchoBodyPetResponseString(pet); - // TODO: test validations + // then + assertThat( + response, + is( + "{\"id\":42,\"name\":\"Corgi\",\"category\":{\"id\":1,\"name\":\"Dogs\"},\"photoUrls\":[\"https://cdn.pixabay.com/photo/2021/10/13/09/01/corgi-6705821_1280.jpg\"],\"tags\":[{\"id\":1,\"name\":\"cute\"}],\"status\":\"sold\"}")); } /** @@ -183,10 +258,14 @@ public void testEchoBodyPetResponseStringTest() { */ @Test public void testEchoBodyStringEnumTest() { - String body = null; + // given + String body = "\"failure\""; + + // when StringEnumRef response = api.testEchoBodyStringEnum(body); - // TODO: test validations + // then + assertThat(response, is(StringEnumRef.FAILURE)); } /** @@ -196,9 +275,13 @@ public void testEchoBodyStringEnumTest() { */ @Test public void testEchoBodyTagResponseStringTest() { + // given Tag tag = null; + + // when String response = api.testEchoBodyTagResponseString(tag); - // TODO: test validations + // then + assertThat(response, nullValue()); } } diff --git a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/FormApiTest.java b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/FormApiTest.java index 2db712c5dd78..140bca8e3dea 100644 --- a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/FormApiTest.java +++ b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/FormApiTest.java @@ -10,72 +10,154 @@ * Do not edit the class manually. */ - package org.openapitools.client.api; -import org.openapitools.client.model.TestFormObjectMultipartRequestMarker; -import org.junit.Test; -import org.junit.Ignore; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +import org.junit.Test; +import org.openapitools.client.model.TestFormObjectMultipartRequestMarker; -/** - * API tests for FormApi - */ -@Ignore +/** API tests for FormApi */ public class FormApiTest { - private final FormApi api = new FormApi(); - - - /** - * Test form parameter(s) - * - * Test form parameter(s) - */ - @Test - public void testFormIntegerBooleanStringTest() { - Integer integerForm = null; - Boolean booleanForm = null; - String stringForm = null; - String response = api.testFormIntegerBooleanString(integerForm, booleanForm, stringForm); - - // TODO: test validations - } - - /** - * Test form parameter(s) for multipart schema - * - * Test form parameter(s) for multipart schema - */ - @Test - public void testFormObjectMultipartTest() { - TestFormObjectMultipartRequestMarker marker = null; - String response = api.testFormObjectMultipart(marker); - - // TODO: test validations - } - - /** - * Test form parameter(s) for oneOf schema - * - * Test form parameter(s) for oneOf schema - */ - @Test - public void testFormOneofTest() { - String form1 = null; - Integer form2 = null; - String form3 = null; - Boolean form4 = null; - Long id = null; - String name = null; - String response = api.testFormOneof(form1, form2, form3, form4, id, name); - - // TODO: test validations - } - -} \ No newline at end of file + private final FormApi api = new FormApi(); + + /** + * Test form parameter(s) + * + *

Test form parameter(s) + */ + @Test + public void testFormIntegerBooleanStringTest() { + // Given + // The content length must be set to disable the Transfer-Encoding: chunked which would lead to + // unparsable response because the echo server is replying them as body. + api.getApiClient().addDefaultHeader("Content-Length", "53"); + + Integer integerForm = 42; + Boolean booleanForm = true; + String stringForm = "Test123"; + + // When + String response = api.testFormIntegerBooleanString(integerForm, booleanForm, stringForm); + + // Then + assertThat(response, containsString("integer_form=42&boolean_form=true&string_form=Test123")); + } + + /** + * Test form parameter(s) for multipart schema + * + *

Test form parameter(s) for multipart schema + */ + @Test + public void testFormObjectMultipartTest() { + // Given + TestFormObjectMultipartRequestMarker marker = + new TestFormObjectMultipartRequestMarker().name("Test Marker"); + + // When + String response = api.testFormObjectMultipart(marker); + + // Then + assertThat(response, containsString("{\"name\":\"Test Marker\"}")); + } + + /** + * Test form parameter(s) for oneOf schema with only the first parameters filled + * + *

Test form parameter(s) for oneOf schema + */ + @Test + public void testFormOneofTest_first() { + // Given + String form1 = "test12"; + Integer form2 = 12; + + String form3 = null; + Boolean form4 = null; + + Long id = null; + String name = null; + + // When + String response = api.testFormOneof(form1, form2, form3, form4, id, name); + + // Then + assertThat(response, containsString("form1=test12&form2=12")); + } + + /** + * Test form parameter(s) for oneOf schema with only the second parameters filled + * + *

Test form parameter(s) for oneOf schema + */ + @Test + public void testFormOneofTest_second() { + // Given + String form1 = null; + Integer form2 = null; + + String form3 = "34test"; + Boolean form4 = false; + + Long id = null; + String name = null; + + // When + String response = api.testFormOneof(form1, form2, form3, form4, id, name); + + // Then + assertThat(response, containsString("form3=34test&form4=false")); + } + + /** + * Test form parameter(s) for oneOf schema with only the third parameters filled + * + *

Test form parameter(s) for oneOf schema + */ + @Test + public void testFormOneofTest_third() { + // Given + String form1 = null; + Integer form2 = null; + + String form3 = null; + Boolean form4 = null; + + Long id = 21L; + String name = "Hans"; + + // When + String response = api.testFormOneof(form1, form2, form3, form4, id, name); + + // Then + assertThat(response, containsString("id=21&name=Hans")); + } + + /** + * Test form parameter(s) for oneOf schema with all parameters filled + * + *

Test form parameter(s) for oneOf schema + */ + @Test + public void testFormOneofTest_all() { + // Given + String form1 = "test12"; + Integer form2 = 12; + + String form3 = "34test"; + Boolean form4 = false; + + Long id = 21L; + String name = "Hans"; + + // When + String response = api.testFormOneof(form1, form2, form3, form4, id, name); + + // Then + assertThat( + response, containsString("form1=test12&form2=12&form3=34test&form4=false&id=21&name=Hans")); + } +} diff --git a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/HeaderApiTest.java b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/HeaderApiTest.java index bc92762bfc85..c0230e6b003d 100644 --- a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/HeaderApiTest.java +++ b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/HeaderApiTest.java @@ -10,43 +10,51 @@ * Do not edit the class manually. */ - package org.openapitools.client.api; -import org.openapitools.client.model.StringEnumRef; -import org.junit.Test; -import org.junit.Ignore; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +import org.junit.Test; +import org.openapitools.client.model.StringEnumRef; -/** - * API tests for HeaderApi - */ -@Ignore +/** API tests for HeaderApi */ public class HeaderApiTest { - private final HeaderApi api = new HeaderApi(); - - - /** - * Test header parameter(s) - * - * Test header parameter(s) - */ - @Test - public void testHeaderIntegerBooleanStringEnumsTest() { - Integer integerHeader = null; - Boolean booleanHeader = null; - String stringHeader = null; - String enumNonrefStringHeader = null; - StringEnumRef enumRefStringHeader = null; - String response = api.testHeaderIntegerBooleanStringEnums(integerHeader, booleanHeader, stringHeader, enumNonrefStringHeader, enumRefStringHeader); - - // TODO: test validations - } - -} \ No newline at end of file + private final HeaderApi api = new HeaderApi(); + + /** + * Test header parameter(s) + * + *

Test header parameter(s) + */ + @Test + public void testHeaderIntegerBooleanStringEnumsTest() { + // Given + Integer integerHeader = 11; + Boolean booleanHeader = true; + String stringHeader = "simple String Header"; + String enumNonrefStringHeader = "false"; + StringEnumRef enumRefStringHeader = StringEnumRef.UNCLASSIFIED; + + // When + String response = + api.testHeaderIntegerBooleanStringEnums( + integerHeader, + booleanHeader, + stringHeader, + enumNonrefStringHeader, + enumRefStringHeader); + + // Then + assertThat( + response, + allOf( + containsString("integer_header: 11"), + containsString("boolean_header: true"), + containsString("string_header: simple String Header"), + containsString("enum_nonref_string_header: false"), + containsString("enum_ref_string_header: unclassified"))); + } +} diff --git a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/PathApiTest.java b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/PathApiTest.java index dfb396727f46..d9381c9c2f3e 100644 --- a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/PathApiTest.java +++ b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/PathApiTest.java @@ -10,42 +10,40 @@ * Do not edit the class manually. */ - package org.openapitools.client.api; -import org.openapitools.client.model.StringEnumRef; -import org.junit.Test; -import org.junit.Ignore; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +import org.junit.Test; +import org.openapitools.client.model.StringEnumRef; -/** - * API tests for PathApi - */ -@Ignore +/** API tests for PathApi */ public class PathApiTest { - private final PathApi api = new PathApi(); - - - /** - * Test path parameter(s) - * - * Test path parameter(s) - */ - @Test - public void testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathTest() { - String pathString = null; - Integer pathInteger = null; - String enumNonrefStringPath = null; - StringEnumRef enumRefStringPath = null; - String response = api.testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(pathString, pathInteger, enumNonrefStringPath, enumRefStringPath); - - // TODO: test validations - } - -} \ No newline at end of file + private final PathApi api = new PathApi(); + + /** + * Test path parameter(s) + * + *

Test path parameter(s) + */ + @Test + public void + testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathTest() { + // Given + String pathString = "simple String Path"; + Integer pathInteger = 50; + String enumNonrefStringPath = "true"; + StringEnumRef enumRefStringPath = StringEnumRef.SUCCESS; + + // When + String response = + api.testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath( + pathString, pathInteger, enumNonrefStringPath, enumRefStringPath); + + // Then + assertThat( + response, containsString("/path/string/simple%20String%20Path/integer/50/true/success")); + } +} diff --git a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/QueryApiTest.java b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/QueryApiTest.java index 72e47f93f69f..827ef91367e0 100644 --- a/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/QueryApiTest.java +++ b/samples/client/echo_api/java/restclient/src/test/java/org/openapitools/client/api/QueryApiTest.java @@ -10,167 +10,206 @@ * Do not edit the class manually. */ - package org.openapitools.client.api; -import org.openapitools.client.model.DataQuery; -import java.time.LocalDate; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; + import java.time.Instant; +import java.time.LocalDate; +import java.util.List; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.openapitools.client.model.DataQuery; import org.openapitools.client.model.Pet; import org.openapitools.client.model.StringEnumRef; import org.openapitools.client.model.TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter; import org.openapitools.client.model.TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter; -import org.junit.Test; -import org.junit.Ignore; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * API tests for QueryApi - */ -@Ignore +/** API tests for QueryApi */ public class QueryApiTest { - private final QueryApi api = new QueryApi(); - - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testEnumRefStringTest() { - String enumNonrefStringQuery = null; - StringEnumRef enumRefStringQuery = null; - String response = api.testEnumRefString(enumNonrefStringQuery, enumRefStringQuery); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryDatetimeDateStringTest() { - Instant datetimeQuery = null; - LocalDate dateQuery = null; - String stringQuery = null; - String response = api.testQueryDatetimeDateString(datetimeQuery, dateQuery, stringQuery); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryIntegerBooleanStringTest() { - Integer integerQuery = null; - Boolean booleanQuery = null; - String stringQuery = null; - String response = api.testQueryIntegerBooleanString(integerQuery, booleanQuery, stringQuery); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryStyleDeepObjectExplodeTrueObjectTest() { - Pet queryObject = null; - String response = api.testQueryStyleDeepObjectExplodeTrueObject(queryObject); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryStyleDeepObjectExplodeTrueObjectAllOfTest() { - TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter queryObject = null; - String response = api.testQueryStyleDeepObjectExplodeTrueObjectAllOf(queryObject); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryStyleFormExplodeFalseArrayIntegerTest() { - List queryObject = null; - String response = api.testQueryStyleFormExplodeFalseArrayInteger(queryObject); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryStyleFormExplodeFalseArrayStringTest() { - List queryObject = null; - String response = api.testQueryStyleFormExplodeFalseArrayString(queryObject); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryStyleFormExplodeTrueArrayStringTest() { - TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter queryObject = null; - String response = api.testQueryStyleFormExplodeTrueArrayString(queryObject); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryStyleFormExplodeTrueObjectTest() { - Pet queryObject = null; - String response = api.testQueryStyleFormExplodeTrueObject(queryObject); - - // TODO: test validations - } - - /** - * Test query parameter(s) - * - * Test query parameter(s) - */ - @Test - public void testQueryStyleFormExplodeTrueObjectAllOfTest() { - DataQuery queryObject = null; - String response = api.testQueryStyleFormExplodeTrueObjectAllOf(queryObject); - - // TODO: test validations - } - -} \ No newline at end of file + private final QueryApi api = new QueryApi(); + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + public void testEnumRefStringTest() { + // Given + String enumNonrefStringQuery = "false"; + StringEnumRef enumRefStringQuery = StringEnumRef.SUCCESS; + + // When + String response = api.testEnumRefString(enumNonrefStringQuery, enumRefStringQuery); + + // Then + assertThat( + response, containsString("?enum_nonref_string_query=false&enum_ref_string_query=success")); + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + public void testQueryDatetimeDateStringTest() { + // Given + Instant datetimeQuery = Instant.ofEpochMilli(1720361075); + LocalDate dateQuery = LocalDate.of(2024, 7, 7); + String stringQuery = "2024-07-07T16:05:59Z"; + + // When + String response = api.testQueryDatetimeDateString(datetimeQuery, dateQuery, stringQuery); + + // Then + assertThat( + response, + containsString( + "?datetime_query=1970-01-20T21%3A52%3A41.075Z&date_query=2024-07-07&string_query=2024-07-07T16%3A05%3A59Z")); + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + public void testQueryIntegerBooleanStringTest() { + // Given + Integer integerQuery = 42; + Boolean booleanQuery = false; + String stringQuery = "Hello World!"; + + // When + String response = api.testQueryIntegerBooleanString(integerQuery, booleanQuery, stringQuery); + + // Then + assertThat( + response, + containsString("?integer_query=42&boolean_query=false&string_query=Hello%20World%21")); + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + @Disabled("The deep object style and the whole dynamic operations are currently not supported") + public void testQueryStyleDeepObjectExplodeTrueObjectTest() { + Pet queryObject = null; + String response = api.testQueryStyleDeepObjectExplodeTrueObject(queryObject); + + // Like Spring WebClient and RestTemplate, the deep object style is currently not + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + @Disabled("The deep object style and the whole dynamic operations are currently not supported") + public void testQueryStyleDeepObjectExplodeTrueObjectAllOfTest() { + TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter queryObject = null; + String response = api.testQueryStyleDeepObjectExplodeTrueObjectAllOf(queryObject); + + // Like Spring WebClient and RestTemplate, the deep object style and the whole dynamic + // operations are currently not supported + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + public void testQueryStyleFormExplodeFalseArrayIntegerTest() { + // Given + List queryObject = List.of(1, 6, 2, 5, 3, 4); + + // When + String response = api.testQueryStyleFormExplodeFalseArrayInteger(queryObject); + + // Then + assertThat(response, containsString("?query_object=1%2C6%2C2%2C5%2C3%2C4")); + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + public void testQueryStyleFormExplodeFalseArrayStringTest() { + // Given + List queryObject = List.of("Hello", "World"); + + // When + String response = api.testQueryStyleFormExplodeFalseArrayString(queryObject); + + // Then + assertThat(response, containsString("?query_object=Hello%2CWorld")); + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + @Disabled("The deep object style and the whole dynamic operations are currently not supported") + public void testQueryStyleFormExplodeTrueArrayStringTest() { + // Given + TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter queryObject = + new TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter() + .addValuesItem("Hello") + .addValuesItem("Hallo") + .addValuesItem("Bonjour"); + + // When + String response = api.testQueryStyleFormExplodeTrueArrayString(queryObject); + + // Then + // Like Spring WebClient and RestTemplate, the deep object style and the whole dynamic + // operations are currently not supported + assertThat( + response, containsString("?query_object=Hello&query_object=Hallo&query_object=Bonjour")); + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + @Disabled("The deep object style and the whole dynamic operations are currently not supported") + public void testQueryStyleFormExplodeTrueObjectTest() { + Pet queryObject = null; + String response = api.testQueryStyleFormExplodeTrueObject(queryObject); + + // TODO: test validations + // Like Spring WebClient and RestTemplate, the deep object style and the whole dynamic + // operations are currently not supported + } + + /** + * Test query parameter(s) + * + *

Test query parameter(s) + */ + @Test + @Disabled("The deep object style and the whole dynamic operations are currently not supported") + public void testQueryStyleFormExplodeTrueObjectAllOfTest() { + DataQuery queryObject = null; + String response = api.testQueryStyleFormExplodeTrueObjectAllOf(queryObject); + + // TODO: test validations + // Like Spring WebClient and RestTemplate, the deep object style and the whole dynamic + // operations are currently not supported + } +} diff --git a/samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java index 016560282476..bfa3ff1fa5bf 100644 --- a/samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java @@ -10,8 +10,8 @@ import org.springframework.http.HttpMethod; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; - import org.springframework.http.converter.HttpMessageConverter; - import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java index 016560282476..bfa3ff1fa5bf 100644 --- a/samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java @@ -10,8 +10,8 @@ import org.springframework.http.HttpMethod; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; - import org.springframework.http.converter.HttpMessageConverter; - import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java index 3a18efd062b1..20b9ece9bc9c 100644 --- a/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -10,8 +10,8 @@ import org.springframework.http.HttpMethod; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; - import org.springframework.http.converter.HttpMessageConverter; - import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java index 3a18efd062b1..20b9ece9bc9c 100644 --- a/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java @@ -10,8 +10,8 @@ import org.springframework.http.HttpMethod; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; - import org.springframework.http.converter.HttpMessageConverter; - import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap;