From dc4dabd019f13ed78637881f214c5dc34332e6c7 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 4 Nov 2023 22:08:28 +0800 Subject: [PATCH] restore java okhttp tests --- bin/utils/test_file_list.yaml | 6 + .../okhttp-gson/.openapi-generator-ignore | 2 +- .../java/okhttp-gson/.openapi-generator/FILES | 1 - .../client/petstore/java/okhttp-gson/pom.xml | 7 + .../openapitools/client/ApiClientTest.java | 350 +++++++++++ .../client/ConfigurationTest.java | 15 + .../org/openapitools/client/JSONTest.java | 579 ++++++++++++++++++ .../openapitools/client/StringUtilTest.java | 33 + .../client/api/AnotherFakeApiTest.java | 50 +- .../openapitools/client/api/FakeApiTest.java | 140 +++-- .../api/FakeClassnameTags123ApiTest.java | 27 +- .../openapitools/client/api/PetApiTest.java | 579 ++++++++++++++++++ .../openapitools/client/api/StoreApiTest.java | 39 +- .../openapitools/client/api/UserApiTest.java | 62 +- .../client/auth/ApiKeyAuthTest.java | 119 ++++ .../client/auth/HttpBasicAuthTest.java | 65 ++ .../client/auth/RetryingOAuthTest.java | 124 ++++ .../model/AdditionalPropertiesClassTest.java | 2 +- .../openapitools/client/model/AnimalTest.java | 4 +- .../client/model/AppleReqTest.java | 2 +- .../openapitools/client/model/AppleTest.java | 2 +- ...neAllOfArrayAllofDogPropertyInnerTest.java | 2 +- .../client/model/ArrayOfInlineAllOfTest.java | 2 +- .../client/model/ArrayOfNumberOnlyTest.java | 2 +- .../client/model/ArrayTestTest.java | 2 +- .../client/model/BananaReqTest.java | 2 +- .../openapitools/client/model/BananaTest.java | 2 +- .../client/model/BasquePigTest.java | 2 +- .../client/model/CapitalizationTest.java | 2 +- .../openapitools/client/model/CatTest.java | 2 +- .../client/model/CategoryTest.java | 2 +- .../client/model/ClassModelTest.java | 2 +- .../openapitools/client/model/ClientTest.java | 2 +- .../model/ComplexQuadrilateralTest.java | 2 +- .../client/model/DanishPigTest.java | 2 +- .../client/model/DeprecatedObjectTest.java | 2 +- .../openapitools/client/model/DogTest.java | 2 +- .../client/model/DrawingTest.java | 2 +- .../client/model/EnumArraysTest.java | 2 +- .../client/model/EnumClassTest.java | 1 + .../model/EnumStringDiscriminatorTest.java | 2 +- .../client/model/EnumTestTest.java | 2 +- .../client/model/EquilateralTriangleTest.java | 2 +- .../client/model/FileSchemaTestClassTest.java | 2 +- .../model/FooGetDefaultResponseTest.java | 2 +- .../openapitools/client/model/FooTest.java | 2 +- .../client/model/FormatTestTest.java | 2 +- .../client/model/FruitReqTest.java | 2 +- .../openapitools/client/model/FruitTest.java | 2 +- .../client/model/GmFruitTest.java | 2 +- .../client/model/GrandparentAnimalTest.java | 3 +- .../client/model/HasOnlyReadOnlyTest.java | 2 +- .../client/model/HealthCheckResultTest.java | 2 +- .../client/model/IsoscelesTriangleTest.java | 2 +- .../openapitools/client/model/MammalTest.java | 2 +- .../client/model/MapTestTest.java | 2 +- ...rtiesAndAdditionalPropertiesClassTest.java | 2 +- .../client/model/Model200ResponseTest.java | 2 +- .../client/model/ModelApiResponseTest.java | 2 +- .../client/model/ModelFileTest.java | 2 +- .../client/model/ModelListTest.java | 2 +- .../client/model/ModelReturnTest.java | 2 +- .../openapitools/client/model/NameTest.java | 2 +- .../client/model/NullableClassTest.java | 2 +- .../client/model/NullableShapeTest.java | 2 +- .../client/model/NumberOnlyTest.java | 2 +- .../model/ObjectWithDeprecatedFieldsTest.java | 2 +- .../openapitools/client/model/OrderTest.java | 2 +- .../client/model/OuterCompositeTest.java | 2 +- .../model/OuterEnumDefaultValueTest.java | 1 + .../OuterEnumIntegerDefaultValueTest.java | 1 + .../client/model/OuterEnumIntegerTest.java | 1 + .../client/model/OuterEnumTest.java | 1 + .../client/model/ParentPetTest.java | 2 +- .../openapitools/client/model/PetTest.java | 92 +++ .../client/model/PetWithRequiredTagsTest.java | 2 +- .../openapitools/client/model/PigTest.java | 2 +- .../model/QuadrilateralInterfaceTest.java | 2 +- .../client/model/QuadrilateralTest.java | 2 +- .../client/model/ReadOnlyFirstTest.java | 2 +- .../client/model/ScaleneTriangleTest.java | 2 +- .../client/model/ShapeInterfaceTest.java | 2 +- .../client/model/ShapeOrNullTest.java | 2 +- .../openapitools/client/model/ShapeTest.java | 2 +- .../client/model/SimpleQuadrilateralTest.java | 2 +- .../client/model/SpecialModelNameTest.java | 2 +- .../openapitools/client/model/TagTest.java | 2 +- .../client/model/TriangleInterfaceTest.java | 2 +- .../client/model/TriangleTest.java | 2 +- .../openapitools/client/model/UserTest.java | 2 +- .../openapitools/client/model/WhaleTest.java | 2 +- .../openapitools/client/model/ZebraTest.java | 2 +- 92 files changed, 2191 insertions(+), 245 deletions(-) create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ApiClientTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ConfigurationTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/StringUtilTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/RetryingOAuthTest.java create mode 100644 samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java diff --git a/bin/utils/test_file_list.yaml b/bin/utils/test_file_list.yaml index d2ed1a960c6b..1299004507c4 100644 --- a/bin/utils/test_file_list.yaml +++ b/bin/utils/test_file_list.yaml @@ -9,3 +9,9 @@ # java okhttp gson test files - filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java" sha256: db505f7801fef62c13a08a8e9ca1fc4c5c947ab46b46f12943139d353feacf17 +- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java" + sha256: 3371236d615e7fb79ed87d00c9fc486c31c379195a658781ac9440f0e3228d62 +- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java" + sha256: e930b2a9b6ca7510d6afe0494e22422976b4d21a4928e3d3af29a5965024bd0a +- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java" + sha256: 738176162cf43c354438f3905f7e2310934489953bbaee200b6f966bf2e028b0 diff --git a/samples/client/petstore/java/okhttp-gson/.openapi-generator-ignore b/samples/client/petstore/java/okhttp-gson/.openapi-generator-ignore index 6ba435b5655f..fcc3c36a6e5e 100644 --- a/samples/client/petstore/java/okhttp-gson/.openapi-generator-ignore +++ b/samples/client/petstore/java/okhttp-gson/.openapi-generator-ignore @@ -11,4 +11,4 @@ src/test/java/org/openapitools/client/model/PetTest.java src/test/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnlyTest.java src/test/java/org/openapitools/client/JSONTest.java src/test/java/org/openapitools/client/api/PetApiTest.java - +pom.xml diff --git a/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES b/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES index c164cd913e32..35fa91f4669b 100644 --- a/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES +++ b/samples/client/petstore/java/okhttp-gson/.openapi-generator/FILES @@ -105,7 +105,6 @@ gradle/wrapper/gradle-wrapper.jar gradle/wrapper/gradle-wrapper.properties gradlew gradlew.bat -pom.xml settings.gradle src/main/AndroidManifest.xml src/main/java/org/openapitools/client/ApiCallback.java diff --git a/samples/client/petstore/java/okhttp-gson/pom.xml b/samples/client/petstore/java/okhttp-gson/pom.xml index 0cadcd6a209a..e674adf75639 100644 --- a/samples/client/petstore/java/okhttp-gson/pom.xml +++ b/samples/client/petstore/java/okhttp-gson/pom.xml @@ -328,6 +328,13 @@ ${junit-platform-runner.version} test + + + org.mockito + mockito-core + 5.7.0 + test + 1.8 diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ApiClientTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ApiClientTest.java new file mode 100644 index 000000000000..05c47e82206e --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ApiClientTest.java @@ -0,0 +1,350 @@ +package org.openapitools.client; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.*; + +import okhttp3.OkHttpClient; +import org.junit.jupiter.api.*; +import org.openapitools.client.auth.*; + +public class ApiClientTest { + ApiClient apiClient; + JSON json; + + @BeforeEach + public void setup() { + apiClient = new ApiClient(); + json = apiClient.getJSON(); + } + + @Test + public void testIsJsonMime() { + assertFalse(apiClient.isJsonMime(null)); + assertFalse(apiClient.isJsonMime("")); + assertFalse(apiClient.isJsonMime("text/plain")); + assertFalse(apiClient.isJsonMime("application/xml")); + assertFalse(apiClient.isJsonMime("application/jsonp")); + assertFalse(apiClient.isJsonMime("example/json")); + assertFalse(apiClient.isJsonMime("example/foo+bar+jsonx")); + assertFalse(apiClient.isJsonMime("example/foo+bar+xjson")); + + assertTrue(apiClient.isJsonMime("application/json")); + assertTrue(apiClient.isJsonMime("application/json; charset=UTF8")); + assertTrue(apiClient.isJsonMime("APPLICATION/JSON")); + + assertTrue(apiClient.isJsonMime("application/problem+json")); + assertTrue(apiClient.isJsonMime("APPLICATION/PROBLEM+JSON")); + assertTrue(apiClient.isJsonMime("application/json\t")); + assertTrue(apiClient.isJsonMime("example/foo+bar+json")); + assertTrue(apiClient.isJsonMime("example/foo+json;x;y")); + assertTrue(apiClient.isJsonMime("example/foo+json\t;")); + assertTrue(apiClient.isJsonMime("Example/fOO+JSON")); + + assertTrue(apiClient.isJsonMime("application/json-patch+json")); + } + + @Test + public void testSelectHeaderAccept() { + String[] accepts = {"application/json", "application/xml"}; + assertEquals("application/json", apiClient.selectHeaderAccept(accepts)); + + accepts = new String[]{"APPLICATION/XML", "APPLICATION/JSON"}; + assertEquals("APPLICATION/JSON", apiClient.selectHeaderAccept(accepts)); + + accepts = new String[]{"application/xml", "application/json; charset=UTF8"}; + assertEquals("application/json; charset=UTF8", apiClient.selectHeaderAccept(accepts)); + + accepts = new String[]{"text/plain", "application/xml"}; + assertEquals("text/plain,application/xml", apiClient.selectHeaderAccept(accepts)); + + accepts = new String[]{}; + assertNull(apiClient.selectHeaderAccept(accepts)); + } + + @Test + public void testSelectHeaderContentType() { + String[] contentTypes = {"application/json", "application/xml"}; + assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes)); + + contentTypes = new String[]{"APPLICATION/JSON", "APPLICATION/XML"}; + assertEquals("APPLICATION/JSON", apiClient.selectHeaderContentType(contentTypes)); + + contentTypes = new String[]{"application/xml", "application/json; charset=UTF8"}; + assertEquals( + "application/json; charset=UTF8", apiClient.selectHeaderContentType(contentTypes)); + + contentTypes = new String[]{"text/plain", "application/xml"}; + assertEquals("text/plain", apiClient.selectHeaderContentType(contentTypes)); + + contentTypes = new String[]{}; + assertNull(apiClient.selectHeaderContentType(contentTypes)); + } + + @Test + public void testGetAuthentications() { + Map auths = apiClient.getAuthentications(); + + Authentication auth = auths.get("api_key"); + assertNotNull(auth); + assertTrue(auth instanceof ApiKeyAuth); + ApiKeyAuth apiKeyAuth = (ApiKeyAuth) auth; + assertEquals("header", apiKeyAuth.getLocation()); + assertEquals("api_key", apiKeyAuth.getParamName()); + + auth = auths.get("petstore_auth"); + assertTrue(auth instanceof OAuth); + assertSame(auth, apiClient.getAuthentication("petstore_auth")); + + assertNull(auths.get("unknown")); + + try { + auths.put("my_auth", new HttpBasicAuth()); + fail("the authentications returned should not be modifiable"); + } catch (UnsupportedOperationException e) { + } + } + + /* + @Test + public void testSetUsernameAndPassword() { + HttpBasicAuth auth = null; + for (Authentication _auth : apiClient.getAuthentications().values()) { + if (_auth instanceof HttpBasicAuth) { + auth = (HttpBasicAuth) _auth; + break; + } + } + auth.setUsername(null); + auth.setPassword(null); + + apiClient.setUsername("my-username"); + apiClient.setPassword("my-password"); + assertEquals("my-username", auth.getUsername()); + assertEquals("my-password", auth.getPassword()); + + // reset values + auth.setUsername(null); + auth.setPassword(null); + } + */ + + @Test + public void testSetApiKeyAndPrefix() { + ApiKeyAuth auth = null; + for (Authentication _auth : apiClient.getAuthentications().values()) { + if (_auth instanceof ApiKeyAuth) { + auth = (ApiKeyAuth) _auth; + break; + } + } + auth.setApiKey(null); + auth.setApiKeyPrefix(null); + + apiClient.setApiKey("my-api-key"); + apiClient.setApiKeyPrefix("Token"); + assertEquals("my-api-key", auth.getApiKey()); + assertEquals("Token", auth.getApiKeyPrefix()); + + // reset values + auth.setApiKey(null); + auth.setApiKeyPrefix(null); + } + + @Test + public void testGetAndSetConnectTimeout() { + // connect timeout defaults to 10 seconds + assertEquals(10000, apiClient.getConnectTimeout()); + assertEquals(10000, apiClient.getHttpClient().connectTimeoutMillis()); + + apiClient.setConnectTimeout(0); + assertEquals(0, apiClient.getConnectTimeout()); + assertEquals(0, apiClient.getHttpClient().connectTimeoutMillis()); + + apiClient.setConnectTimeout(10000); + } + + @Test + public void testGetAndSetReadTimeout() { + // read timeout defaults to 10 seconds + assertEquals(10000, apiClient.getReadTimeout()); + assertEquals(10000, apiClient.getHttpClient().readTimeoutMillis()); + + apiClient.setReadTimeout(0); + assertEquals(0, apiClient.getReadTimeout()); + assertEquals(0, apiClient.getHttpClient().readTimeoutMillis()); + + apiClient.setReadTimeout(10000); + } + + @Test + public void testGetAndSetWriteTimeout() { + // write timeout defaults to 10 seconds + assertEquals(10000, apiClient.getWriteTimeout()); + assertEquals(10000, apiClient.getHttpClient().writeTimeoutMillis()); + + apiClient.setWriteTimeout(0); + assertEquals(0, apiClient.getWriteTimeout()); + assertEquals(0, apiClient.getHttpClient().writeTimeoutMillis()); + + apiClient.setWriteTimeout(10000); + } + + @Test + public void testParameterToPairWhenNameIsInvalid() throws Exception { + List pairs_a = apiClient.parameterToPair(null, new Integer(1)); + List pairs_b = apiClient.parameterToPair("", new Integer(1)); + + assertTrue(pairs_a.isEmpty()); + assertTrue(pairs_b.isEmpty()); + } + + @Test + public void testParameterToPairWhenValueIsNull() throws Exception { + List pairs = apiClient.parameterToPair("param-a", null); + + assertTrue(pairs.isEmpty()); + } + + @Test + public void testParameterToPairWhenValueIsEmptyString() throws Exception { + // single empty string + List pairs = apiClient.parameterToPair("param-a", " "); + assertEquals(1, pairs.size()); + } + + @Test + public void testParameterToPairWhenValueIsNotCollection() throws Exception { + String name = "param-a"; + Integer value = 1; + + List pairs = apiClient.parameterToPair(name, value); + + assertEquals(1, pairs.size()); + assertEquals(value, Integer.valueOf(pairs.get(0).getValue())); + } + + @Test + public void testParameterToPairWhenValueIsCollection() throws Exception { + List values = new ArrayList(); + values.add("value-a"); + values.add(123); + values.add(new Date()); + + List pairs = apiClient.parameterToPair("param-a", values); + assertEquals(0, pairs.size()); + } + + @Test + public void testParameterToPairsWhenNameIsInvalid() throws Exception { + List objects = new ArrayList(); + objects.add(new Integer(1)); + + List pairs_a = apiClient.parameterToPairs("csv", null, objects); + List pairs_b = apiClient.parameterToPairs("csv", "", objects); + + assertTrue(pairs_a.isEmpty()); + assertTrue(pairs_b.isEmpty()); + } + + @Test + public void testParameterToPairsWhenValueIsNull() throws Exception { + List pairs = apiClient.parameterToPairs("csv", "param-a", null); + + assertTrue(pairs.isEmpty()); + } + + @Test + public void testParameterToPairsWhenValueIsEmptyStrings() throws Exception { + // list of empty strings + List strs = new ArrayList(); + strs.add(" "); + strs.add(" "); + strs.add(" "); + + List concatStrings = apiClient.parameterToPairs("csv", "param-a", strs); + + assertEquals(1, concatStrings.size()); + assertFalse(concatStrings.get(0).getValue().isEmpty()); // should contain some delimiters + } + + @Test + public void testParameterToPairsWhenValueIsCollection() throws Exception { + Map collectionFormatMap = new HashMap(); + collectionFormatMap.put("csv", ","); + collectionFormatMap.put("tsv", "\t"); + collectionFormatMap.put("ssv", " "); + collectionFormatMap.put("pipes", "|"); + collectionFormatMap.put("", ","); // no format, must default to csv + collectionFormatMap.put("unknown", ","); // all other formats, must default to csv + + String name = "param-a"; + + List values = new ArrayList(); + values.add("value-a"); + values.add(123); + values.add(new Date()); + + // check for multi separately + List multiPairs = apiClient.parameterToPairs("multi", name, values); + assertEquals(values.size(), multiPairs.size()); + for (int i = 0; i < values.size(); i++) { + assertEquals( + apiClient.escapeString(apiClient.parameterToString(values.get(i))), + multiPairs.get(i).getValue()); + } + + // all other formats + for (String collectionFormat : collectionFormatMap.keySet()) { + List pairs = apiClient.parameterToPairs(collectionFormat, name, values); + + assertEquals(1, pairs.size()); + + String delimiter = collectionFormatMap.get(collectionFormat); + if (!delimiter.equals(",")) { + // commas are not escaped because they are reserved characters in URIs + delimiter = apiClient.escapeString(delimiter); + } + String[] pairValueSplit = pairs.get(0).getValue().split(delimiter); + + // must equal input values + assertEquals(values.size(), pairValueSplit.length); + for (int i = 0; i < values.size(); i++) { + assertEquals( + apiClient.escapeString(apiClient.parameterToString(values.get(i))), + pairValueSplit[i]); + } + } + } + + @Test + public void testSanitizeFilename() { + assertEquals("sun", apiClient.sanitizeFilename("sun")); + assertEquals("sun.gif", apiClient.sanitizeFilename("sun.gif")); + assertEquals("sun.gif", apiClient.sanitizeFilename("../sun.gif")); + assertEquals("sun.gif", apiClient.sanitizeFilename("/var/tmp/sun.gif")); + assertEquals("sun.gif", apiClient.sanitizeFilename("./sun.gif")); + assertEquals("sun.gif", apiClient.sanitizeFilename("..\\sun.gif")); + assertEquals("sun.gif", apiClient.sanitizeFilename("\\var\\tmp\\sun.gif")); + assertEquals("sun.gif", apiClient.sanitizeFilename("c:\\var\\tmp\\sun.gif")); + assertEquals("sun.gif", apiClient.sanitizeFilename(".\\sun.gif")); + } + + @Test + public void testNewHttpClient() { + OkHttpClient oldClient = apiClient.getHttpClient(); + apiClient.setHttpClient(oldClient.newBuilder().build()); + assertNotSame(apiClient.getHttpClient(), oldClient); + } + + /** + * Tests the invariant that the HttpClient for the ApiClient must never be null + */ + @Test + public void testNullHttpClient() { + NullPointerException thrown = Assertions.assertThrows(NullPointerException.class, () -> { + apiClient.setHttpClient(null); + }); + Assertions.assertEquals("HttpClient must not be null!", thrown.getMessage()); + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ConfigurationTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ConfigurationTest.java new file mode 100644 index 000000000000..e5b9d146a4eb --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ConfigurationTest.java @@ -0,0 +1,15 @@ +package org.openapitools.client; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.*; + +public class ConfigurationTest { + @Test + public void testDefaultApiClient() { + ApiClient apiClient = Configuration.getDefaultApiClient(); + assertNotNull(apiClient); + assertEquals("http://petstore.swagger.io:80/v2", apiClient.getBasePath()); + assertFalse(apiClient.isDebugging()); + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java new file mode 100644 index 000000000000..b0d95e91926d --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java @@ -0,0 +1,579 @@ +package org.openapitools.client; + +import static org.junit.jupiter.api.Assertions.*; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.time.format.DateTimeFormatter; +import java.time.LocalDate; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.TimeZone; + +import okio.ByteString; +import org.junit.jupiter.api.*; +import org.openapitools.client.model.Order; + +import org.openapitools.client.model.*; + +public class JSONTest { + private ApiClient apiClient = null; + private JSON json = null; + private Order order = null; + + @BeforeEach + public void setup() { + apiClient = new ApiClient(); + json = apiClient.getJSON(); + order = new Order(); + } + + @Test + public void testSqlDateTypeAdapter() { + final String str = "\"2015-11-07\""; + final java.sql.Date date = java.sql.Date.valueOf("2015-11-07"); + + assertEquals(str, json.serialize(date)); + assertEquals(json.deserialize(str, java.sql.Date.class), date); + assertEquals( + json.deserialize( + "\"2015-11-07T03:49:09.356" + getCurrentTimezoneOffset() + "\"", + java.sql.Date.class) + .toString(), + date.toString()); + + // custom date format: without day + DateFormat format = new SimpleDateFormat("yyyy-MM", Locale.ROOT); + apiClient.setSqlDateFormat(format); + String dateStr = "\"2015-11\""; + assertEquals( + dateStr, + json.serialize(json.deserialize("\"2015-11-07T03:49:09Z\"", java.sql.Date.class))); + assertEquals(dateStr, json.serialize(json.deserialize("\"2015-11\"", java.sql.Date.class))); + } + + @Test + public void testDateTypeAdapter() { + Calendar cal = new GregorianCalendar(2015, 10, 7, 3, 49, 9); + cal.setTimeZone(TimeZone.getTimeZone("UTC")); + + assertEquals(json.deserialize("\"2015-11-07T05:49:09+02\"", Date.class), cal.getTime()); + + cal.set(Calendar.MILLISECOND, 300); + assertEquals(json.deserialize("\"2015-11-07T03:49:09.3Z\"", Date.class), cal.getTime()); + + cal.set(Calendar.MILLISECOND, 356); + Date date = cal.getTime(); + + final String utcDate = "\"2015-11-07T03:49:09.356Z\""; + assertEquals(json.deserialize(utcDate, Date.class), date); + assertEquals(json.deserialize("\"2015-11-07T03:49:09.356+00:00\"", Date.class), date); + assertEquals(json.deserialize("\"2015-11-07T05:49:09.356+02:00\"", Date.class), date); + assertEquals(json.deserialize("\"2015-11-07T02:49:09.356-01:00\"", Date.class), date); + assertEquals(json.deserialize("\"2015-11-07T03:49:09.356Z\"", Date.class), date); + assertEquals(json.deserialize("\"2015-11-07T03:49:09.356+00\"", Date.class), date); + assertEquals(json.deserialize("\"2015-11-07T02:49:09.356-0100\"", Date.class), date); + assertEquals(json.deserialize("\"2015-11-07T03:49:09.356456789Z\"", Date.class), date); + + assertEquals(utcDate, json.serialize(date)); + + // custom datetime format: without milli-seconds, custom time zone + DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT); + format.setTimeZone(TimeZone.getTimeZone("GMT+10")); + apiClient.setDateFormat(format); + + String dateStr = "\"2015-11-07T13:49:09+10:00\""; + assertEquals( + dateStr, + json.serialize(json.deserialize("\"2015-11-07T03:49:09+00:00\"", Date.class))); + assertEquals( + dateStr, json.serialize(json.deserialize("\"2015-11-07T03:49:09Z\"", Date.class))); + assertEquals( + dateStr, + json.serialize(json.deserialize("\"2015-11-07T00:49:09-03:00\"", Date.class))); + + try { + // invalid time zone format + json.deserialize("\"2015-11-07T03:49:09+00\"", Date.class); + fail("json parsing should fail"); + } catch (RuntimeException e) { + // OK + } + try { + // unexpected milliseconds + json.deserialize("\"2015-11-07T03:49:09.000Z\"", Date.class); + fail("json parsing should fail"); + } catch (RuntimeException e) { + // OK + } + } + + @Test + public void testOffsetDateTimeTypeAdapter() { + final String str = "\"2016-09-09T08:02:03.123-03:00\""; + OffsetDateTime date = + OffsetDateTime.of(2016, 9, 9, 8, 2, 3, 123000000, ZoneOffset.of("-3")); + + assertEquals(str, json.serialize(date)); + // Use toString() instead of isEqual to verify that the offset is preserved + assertEquals(json.deserialize(str, OffsetDateTime.class).toString(), date.toString()); + } + + @Test + public void testLocalDateTypeAdapter() { + final String str = "\"2016-09-09\""; + final LocalDate date = LocalDate.of(2016, 9, 9); + + assertEquals(str, json.serialize(date)); + assertEquals(json.deserialize(str, LocalDate.class), date); + } + + @Test + public void testDefaultDate() throws Exception { + final DateTimeFormatter datetimeFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + final String dateStr = "2015-11-07T14:11:05.267Z"; + order.setShipDate(OffsetDateTime.from(datetimeFormat.parse(dateStr))); + + String str = json.serialize(order); + Type type = new TypeToken() { + }.getType(); + Order o = json.deserialize(str, type); + assertEquals(dateStr, datetimeFormat.format(o.getShipDate())); + } + + @Test + public void testCustomDate() throws Exception { + final DateTimeFormatter datetimeFormat = + DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Etc/GMT+2")); + final String dateStr = "2015-11-07T14:11:05-02:00"; + order.setShipDate(OffsetDateTime.from(datetimeFormat.parse(dateStr))); + + String str = json.serialize(order); + Type type = new TypeToken() { + }.getType(); + Order o = json.deserialize(str, type); + assertEquals(dateStr, datetimeFormat.format(o.getShipDate())); + } + + @Test + public void testByteArrayTypeAdapterSerialization() { + // Arrange + final String expectedBytesAsString = "Let's pretend this a jpg or something"; + final byte[] expectedBytes = expectedBytesAsString.getBytes(StandardCharsets.UTF_8); + + // Act + String serializedBytesWithQuotes = json.serialize(expectedBytes); + + // Assert + String serializedBytes = + serializedBytesWithQuotes.substring(1, serializedBytesWithQuotes.length() - 1); + if (json.getGson().htmlSafe()) { + serializedBytes = serializedBytes.replaceAll("\\\\u003d", "="); + } + ByteString actualAsByteString = ByteString.decodeBase64(serializedBytes); + byte[] actualBytes = actualAsByteString.toByteArray(); + assertEquals(expectedBytesAsString, new String(actualBytes, StandardCharsets.UTF_8)); + } + + @Test + public void testByteArrayTypeAdapterDeserialization() { + // Arrange + final String expectedBytesAsString = "Let's pretend this a jpg or something"; + final byte[] expectedBytes = expectedBytesAsString.getBytes(StandardCharsets.UTF_8); + final ByteString expectedByteString = ByteString.of(expectedBytes); + final String serializedBytes = expectedByteString.base64(); + final String serializedBytesWithQuotes = "\"" + serializedBytes + "\""; + Type type = new TypeToken() { + }.getType(); + + // Act + byte[] actualDeserializedBytes = json.deserialize(serializedBytesWithQuotes, type); + + // Assert + assertEquals( + expectedBytesAsString, new String(actualDeserializedBytes, StandardCharsets.UTF_8)); + } + + @Test + public void testRequiredFieldException() { + IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> { + // test json string missing required field(s) to ensure exception is thrown + Gson gson = json.getGson(); + //Gson gson = new GsonBuilder() + // .registerTypeAdapter(Pet.class, new Pet.CustomDeserializer()) + // .create(); + String json = "{\"id\": 5847, \"name\":\"tag test 1\"}"; // missing photoUrls (required field) + //String json = "{\"id2\": 5847, \"name\":\"tag test 1\"}"; + //String json = "{\"id\": 5847}"; + Pet p = gson.fromJson(json, Pet.class); + }); + + Assertions.assertEquals("The required field `photoUrls` is not found in the JSON string: {\"id\":5847,\"name\":\"tag test 1\"}", thrown.getMessage()); + } + + @Test + @Disabled("No longer need the following test as additional field(s) should be stored in `additionalProperties`") + public void testAdditionalFieldException() { + IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> { + // test json string with additional field(s) to ensure exception is thrown + Gson gson = json.getGson(); + String json = "{\"id\": 5847, \"name\":\"tag test 1\", \"new-field\": true}"; + org.openapitools.client.model.Tag t = gson.fromJson(json, org.openapitools.client.model.Tag.class); + }); + + Assertions.assertEquals("The field `new-field` in the JSON string is not defined in the `Tag` properties. JSON: {\"id\":5847,\"name\":\"tag test 1\",\"new-field\":true}", thrown.getMessage()); + } + + @Test + public void testCustomDeserializer() { + // test the custom deserializer to ensure it can deserialize json payload into objects + Gson gson = json.getGson(); + //Gson gson = new GsonBuilder() + // .registerTypeAdapter(Tag.class, new Tag.CustomDeserializer()) + // .create(); + // id and name + String json = "{\"id\": 5847, \"name\":\"tag test 1\"}"; + org.openapitools.client.model.Tag t = gson.fromJson(json, org.openapitools.client.model.Tag.class); + assertEquals(t.getName(), "tag test 1"); + assertEquals(t.getId(), Long.valueOf(5847L)); + + // name only + String json2 = "{\"name\":\"tag test 1\"}"; + org.openapitools.client.model.Tag t2 = gson.fromJson(json2, org.openapitools.client.model.Tag.class); + assertEquals(t2.getName(), "tag test 1"); + assertEquals(t2.getId(), null); + + // with all required fields + String json3 = "{\"id\": 5847, \"name\":\"pet test 1\", \"photoUrls\": [\"https://a.com\", \"https://b.com\"]}"; + Pet t3 = gson.fromJson(json3, Pet.class); + assertEquals(t3.getName(), "pet test 1"); + assertEquals(t3.getId(), Long.valueOf(5847)); + + // with all required fields and tags (optional) + String json4 = "{\"id\": 5847, \"name\":\"pet test 1\", \"photoUrls\": [\"https://a.com\", \"https://b.com\"],\"tags\":[{\"id\":\"tag 123\"}]}"; + Pet t4 = gson.fromJson(json3, Pet.class); + assertEquals(t4.getName(), "pet test 1"); + assertEquals(t4.getId(), Long.valueOf(5847)); + } + + @Test + @Disabled("Unknown fields are now correctly deserialized into `additionalProperties`") + public void testUnknownFields() { + // test unknown fields in the payload + Gson gson = json.getGson(); + // test Tag + String json5 = "{\"unknown_field\": 543, \"id\":\"tag 123\"}"; + Exception exception5 = assertThrows(java.lang.IllegalArgumentException.class, () -> { + org.openapitools.client.model.Tag t5 = gson.fromJson(json5, org.openapitools.client.model.Tag.class); + }); + assertTrue(exception5.getMessage().contains("The field `unknown_field` in the JSON string is not defined in the `Tag` properties. JSON: {\"unknown_field\":543,\"id\":\"tag 123\"}")); + + // test Pet with invalid tags + String json6 = "{\"id\": 5847, \"name\":\"pet test 1\", \"photoUrls\": [\"https://a.com\", \"https://b.com\"],\"tags\":[{\"unknown_field\": 543, \"id\":\"tag 123\"}]}"; + Exception exception6 = assertThrows(java.lang.IllegalArgumentException.class, () -> { + Pet t6 = gson.fromJson(json6, Pet.class); + }); + assertTrue(exception6.getMessage().contains("The field `unknown_field` in the JSON string is not defined in the `Tag` properties. JSON: {\"unknown_field\":543,\"id\":\"tag 123\"}")); + + // test Pet with invalid tags (required) + String json7 = "{\"id\": 5847, \"name\":\"pet test 1\", \"photoUrls\": [\"https://a.com\", \"https://b.com\"],\"tags\":[{\"unknown_field\": 543, \"id\":\"tag 123\"}]}"; + Exception exception7 = assertThrows(java.lang.IllegalArgumentException.class, () -> { + PetWithRequiredTags t7 = gson.fromJson(json7, PetWithRequiredTags.class); + }); + assertTrue(exception7.getMessage().contains("The field `unknown_field` in the JSON string is not defined in the `Tag` properties. JSON: {\"unknown_field\":543,\"id\":\"tag 123\"}")); + + // test Pet with invalid tags (missing reqired) + String json8 = "{\"id\": 5847, \"name\":\"pet test 1\", \"photoUrls\": [\"https://a.com\", \"https://b.com\"]}"; + Exception exception8 = assertThrows(java.lang.IllegalArgumentException.class, () -> { + PetWithRequiredTags t8 = gson.fromJson(json8, PetWithRequiredTags.class); + }); + assertTrue(exception8.getMessage().contains("The required field `tags` is not found in the JSON string: {\"id\":5847,\"name\":\"pet test 1\",\"photoUrls\":[\"https://a.com\",\"https://b.com\"]}")); + } + + /** + * Model tests for Pet + */ + @Test + public void testPet() { + // test Pet + Pet model = new Pet(); + model.setId(1029L); + model.setName("Dog"); + + Pet model2 = new Pet(); + model2.setId(1029L); + model2.setName("Dog"); + + assertTrue(model.equals(model2)); + } + + // Obtained 22JAN2018 from stackoverflow answer by PuguaSoft + // https://stackoverflow.com/questions/11399491/java-timezone-offset + // Direct link https://stackoverflow.com/a/16680815/3166133 + public static String getCurrentTimezoneOffset() { + + TimeZone tz = TimeZone.getDefault(); + Calendar cal = GregorianCalendar.getInstance(tz, Locale.ROOT); + int offsetInMillis = tz.getOffset(cal.getTimeInMillis()); + + String offset = + String.format( + Locale.ROOT, + "%02d:%02d", + Math.abs(offsetInMillis / 3600000), + Math.abs((offsetInMillis / 60000) % 60)); + offset = (offsetInMillis >= 0 ? "+" : "-") + offset; + + return offset; + } + + /** + * Validate an anyOf schema can be deserialized into the expected class. + * The anyOf schema does not have a discriminator. + */ + @Test + public void testAnyOfSchemaWithoutDiscriminator() throws Exception { + { + String str = "{ \"cultivar\": \"golden delicious\", \"origin\": \"japan\" }"; + + // make sure deserialization works for pojo object + Apple a = json.getGson().fromJson(str, Apple.class); + assertEquals(a.getCultivar(), "golden delicious"); + assertEquals(a.getOrigin(), "japan"); + + GmFruit o = json.getGson().fromJson(str, GmFruit.class); + assertTrue(o.getActualInstance() instanceof Apple); + Apple inst = (Apple) o.getActualInstance(); + assertEquals(inst.getCultivar(), "golden delicious"); + assertEquals(inst.getOrigin(), "japan"); + assertEquals(json.getGson().toJson(inst), "{\"cultivar\":\"golden delicious\",\"origin\":\"japan\"}"); + assertEquals(inst.toJson(), "{\"cultivar\":\"golden delicious\",\"origin\":\"japan\"}"); + assertEquals(json.getGson().toJson(o), "{\"cultivar\":\"golden delicious\",\"origin\":\"japan\"}"); + assertEquals(o.toJson(), "{\"cultivar\":\"golden delicious\",\"origin\":\"japan\"}"); + + /* comment out the following as we've added "additionalProperties" support + String str2 = "{ \"origin_typo\": \"japan\" }"; + // no match + Exception exception = assertThrows(java.lang.IllegalArgumentException.class, () -> { + Apple o3 = json.getGson().fromJson(str2, Apple.class); + }); + + // no match + Exception exception3 = assertThrows(java.lang.IllegalArgumentException.class, () -> { + Banana o2 = json.getGson().fromJson(str2, Banana.class); + }); + + // no match + Exception exception4 = assertThrows(com.google.gson.JsonSyntaxException.class, () -> { + GmFruit o2 = json.getGson().fromJson(str2, GmFruit.class); + }); + */ + } + } + + /** + * Validate a oneOf schema can be deserialized into the expected class. + * The oneOf schema has a discriminator. + */ + @Test + public void testOneOfSchemaWithDiscriminator() throws Exception { + { + String str = "{ \"className\": \"whale\", \"hasBaleen\": false, \"hasTeeth\": false }"; + + // make sure deserialization works for pojo object + Whale w = json.getGson().fromJson(str, Whale.class); + assertEquals(w.getClassName(), "whale"); + assertEquals(w.getHasBaleen(), false); + assertEquals(w.getHasTeeth(), false); + + Mammal o = json.getGson().fromJson(str, Mammal.class); + assertTrue(o.getActualInstance() instanceof Whale); + Whale inst = (Whale) o.getActualInstance(); + assertEquals(inst.getClassName(), "whale"); + assertEquals(inst.getHasBaleen(), false); + assertEquals(inst.getHasTeeth(), false); + assertEquals(json.getGson().toJson(inst), "{\"hasBaleen\":false,\"hasTeeth\":false,\"className\":\"whale\"}"); + assertEquals(inst.toJson(), "{\"hasBaleen\":false,\"hasTeeth\":false,\"className\":\"whale\"}"); + assertEquals(json.getGson().toJson(o), "{\"hasBaleen\":false,\"hasTeeth\":false,\"className\":\"whale\"}"); + assertEquals(o.toJson(), "{\"hasBaleen\":false,\"hasTeeth\":false,\"className\":\"whale\"}"); + + String str2 = "{ \"className\": \"zebra\", \"type\": \"plains\" }"; + + // make sure deserialization works for pojo object + Zebra z = Zebra.fromJson(str2); + assertEquals(z.toJson(), "{\"type\":\"plains\",\"className\":\"zebra\"}"); + + Mammal o2 = json.getGson().fromJson(str2, Mammal.class); + assertTrue(o2.getActualInstance() instanceof Zebra); + Zebra inst2 = (Zebra) o2.getActualInstance(); + assertEquals(json.getGson().toJson(inst2), "{\"type\":\"plains\",\"className\":\"zebra\"}"); + assertEquals(inst2.toJson(), "{\"type\":\"plains\",\"className\":\"zebra\"}"); + assertEquals(json.getGson().toJson(o2), "{\"type\":\"plains\",\"className\":\"zebra\"}"); + assertEquals(o2.toJson(), "{\"type\":\"plains\",\"className\":\"zebra\"}"); + } + { + // incorrect payload results in exception + String str = "{ \"cultivar\": \"golden delicious\", \"mealy\": false, \"garbage_prop\": \"abc\" }"; + Exception exception = assertThrows(com.google.gson.JsonSyntaxException.class, () -> { + Mammal o = json.getGson().fromJson(str, Mammal.class); + }); + //assertEquals("java.io.IOException: Failed deserialization for Mammal: 0 classes match result, expected 1. Detailed failure message for oneOf schemas: [Deserialization for Pig failed with `The JSON string is invalid for Pig with oneOf schemas: BasquePig, DanishPig. 0 class(es) match the result, expected 1. Detailed failure message for oneOf schemas: [Deserialization for BasquePig failed with `The required field `className` is not found in the JSON string: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}`., Deserialization for DanishPig failed with `The required field `className` is not found in the JSON string: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}`.]. JSON: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}`., Deserialization for Whale failed with `The required field `className` is not found in the JSON string: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}`., Deserialization for Zebra failed with `The required field `className` is not found in the JSON string: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}`.]. JSON: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}", exception.getMessage()); + assertTrue(exception.getMessage().contains("java.io.IOException: Failed deserialization for Mammal")); + } + { + // Try to deserialize empty object. This should fail 'oneOf' because none will match + // whale or zebra. + String str = "{ }"; + Exception exception = assertThrows(com.google.gson.JsonSyntaxException.class, () -> { + json.getGson().fromJson(str, Mammal.class); + }); + //assertEquals("java.io.IOException: Failed deserialization for Mammal: 0 classes match result, expected 1. Detailed failure message for oneOf schemas: [Deserialization for Pig failed with `The JSON string is invalid for Pig with oneOf schemas: BasquePig, DanishPig. 0 class(es) match the result, expected 1. Detailed failure message for oneOf schemas: [Deserialization for BasquePig failed with `The required field `className` is not found in the JSON string: {}`., Deserialization for DanishPig failed with `The required field `className` is not found in the JSON string: {}`.]. JSON: {}`., Deserialization for Whale failed with `The required field `className` is not found in the JSON string: {}`., Deserialization for Zebra failed with `The required field `className` is not found in the JSON string: {}`.]. JSON: {}", exception.getMessage()); + assertTrue(exception.getMessage().contains("java.io.IOException: Failed deserialization for Mammal")); + } + } + + /** + * Test JSON validation method + */ + @Test + public void testJsonValidation() throws Exception { + String str = "{ \"cultivar\": [\"golden delicious\"], \"mealy\": false }"; + Exception exception = assertThrows(java.lang.IllegalArgumentException.class, () -> { + AppleReq a = json.getGson().fromJson(str, AppleReq.class); + }); + assertTrue(exception.getMessage().contains("Expected the field `cultivar` to be a primitive type in the JSON string but got `[\"golden delicious\"]`")); + + String str2 = "{ \"id\": 5847, \"name\":\"pet test 1\", \"photoUrls\": 123 }"; + Exception exception2 = assertThrows(java.lang.IllegalArgumentException.class, () -> { + Pet p1 = json.getGson().fromJson(str2, Pet.class); + }); + assertTrue(exception2.getMessage().contains("Expected the field `photoUrls` to be an array in the JSON string but got `123`")); + } + + /** + * Validate a oneOf schema can be deserialized into the expected class. + * The oneOf schema does not have a discriminator. + */ + @Test + public void testOneOfSchemaWithoutDiscriminator() throws Exception { + // BananaReq and AppleReq have explicitly defined properties that are different by name. + // There is no discriminator property. + { + String str = "{ \"cultivar\": \"golden delicious\", \"mealy\": false }"; + + // make sure deserialization works for pojo object + AppleReq a = json.getGson().fromJson(str, AppleReq.class); + assertEquals(a.getCultivar(), "golden delicious"); + assertEquals(a.getMealy(), false); + + FruitReq o = json.getGson().fromJson(str, FruitReq.class); + assertTrue(o.getActualInstance() instanceof AppleReq); + AppleReq inst = (AppleReq) o.getActualInstance(); + assertEquals(inst.getCultivar(), "golden delicious"); + assertEquals(inst.getMealy(), false); + assertEquals(json.getGson().toJson(inst), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + assertEquals(inst.toJson(), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + assertEquals(json.getGson().toJson(o), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + assertEquals(o.toJson(), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + + AppleReq inst2 = o.getAppleReq(); + assertEquals(inst2.getCultivar(), "golden delicious"); + assertEquals(inst2.getMealy(), false); + assertEquals(json.getGson().toJson(inst2), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + assertEquals(inst2.toJson(), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + + // test fromJson + FruitReq o3 = FruitReq.fromJson(str); + assertTrue(o3.getActualInstance() instanceof AppleReq); + AppleReq inst3 = (AppleReq) o3.getActualInstance(); + assertEquals(inst3.getCultivar(), "golden delicious"); + assertEquals(inst3.getMealy(), false); + assertEquals(json.getGson().toJson(inst3), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + assertEquals(inst3.toJson(), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + assertEquals(o3.toJson(), "{\"cultivar\":\"golden delicious\",\"mealy\":false}"); + } + { + // test to ensure the oneOf object can be serialized to "null" correctly + FruitReq o = new FruitReq(); + assertEquals(o.getActualInstance(), null); + assertEquals(json.getGson().toJson(o), "null"); + assertEquals(o.toJson(), "null"); + assertEquals(json.getGson().toJson(null), "null"); + } + { + // Same test, but this time with additional (undeclared) properties. + // Since FruitReq has additionalProperties: false, deserialization should fail. + String str = "{ \"cultivar\": \"golden delicious\", \"mealy\": false, \"garbage_prop\": \"abc\" }"; + Exception exception = assertThrows(com.google.gson.JsonSyntaxException.class, () -> { + FruitReq o = json.getGson().fromJson(str, FruitReq.class); + }); + assertEquals("java.io.IOException: Failed deserialization for FruitReq: 0 classes match result, expected 1. Detailed failure message for oneOf schemas: [Deserialization for AppleReq failed with `The field `garbage_prop` in the JSON string is not defined in the `AppleReq` properties. JSON: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}`., Deserialization for BananaReq failed with `The field `cultivar` in the JSON string is not defined in the `BananaReq` properties. JSON: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}`.]. JSON: {\"cultivar\":\"golden delicious\",\"mealy\":false,\"garbage_prop\":\"abc\"}", exception.getMessage()); + } + { + String str = "{ \"lengthCm\": 17 }"; + + // make sure deserialization works for pojo object + BananaReq b = json.getGson().fromJson(str, BananaReq.class); + assertEquals(b.getLengthCm(), new java.math.BigDecimal(17)); + + FruitReq o = json.getGson().fromJson(str, FruitReq.class); + assertTrue(o.getActualInstance() instanceof BananaReq); + BananaReq inst = (BananaReq) o.getActualInstance(); + assertEquals(inst.getLengthCm(), new java.math.BigDecimal(17)); + assertEquals(json.getGson().toJson(o), "{\"lengthCm\":17}"); + assertEquals(json.getGson().toJson(inst), "{\"lengthCm\":17}"); + } + { + // Try to deserialize empty object. This should fail 'oneOf' because none will match + // AppleReq or BananaReq. + String str = "{ }"; + Exception exception = assertThrows(com.google.gson.JsonSyntaxException.class, () -> { + json.getGson().fromJson(str, FruitReq.class); + }); + assertTrue(exception.getMessage().contains("Failed deserialization for FruitReq: 0 classes match result, expected 1")); + } + } + + + /** + * Test validateJsonObject with null object + */ + @Test + public void testValidateJsonObject() throws Exception { + JsonObject jsonObject = new JsonObject(); + Exception exception = assertThrows(java.lang.IllegalArgumentException.class, () -> { + Pet.validateJsonElement(jsonObject); + }); + assertEquals(exception.getMessage(), "The required field `photoUrls` is not found in the JSON string: {}"); + } + + /** + * Test additional properties. + */ + @Test + public void testAdditionalProperties() throws Exception { + String str = "{ \"className\": \"zebra\", \"type\": \"plains\", \"from_json\": 4567, \"from_json_map\": {\"nested_string\": \"nested_value\"} }"; + Zebra z = Zebra.fromJson(str); + z.putAdditionalProperty("new_key", "new_value"); + z.putAdditionalProperty("new_number", 1.23); + z.putAdditionalProperty("new_boolean", true); + org.openapitools.client.model.Tag t = new org.openapitools.client.model.Tag(); + t.setId(34L); + t.setName("just a tag"); + z.putAdditionalProperty("new_object", t); + assertEquals(z.toJson(), "{\"type\":\"plains\",\"className\":\"zebra\",\"new_key\":\"new_value\",\"new_boolean\":true,\"new_object\":{\"id\":34,\"name\":\"just a tag\"},\"from_json\":4567,\"from_json_map\":{\"nested_string\":\"nested_value\"},\"new_number\":1.23}"); + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/StringUtilTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/StringUtilTest.java new file mode 100644 index 000000000000..c946674e470a --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/StringUtilTest.java @@ -0,0 +1,33 @@ +package org.openapitools.client; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.*; + +public class StringUtilTest { + @Test + public void testContainsIgnoreCase() { + assertTrue(StringUtil.containsIgnoreCase(new String[]{"abc"}, "abc")); + assertTrue(StringUtil.containsIgnoreCase(new String[]{"abc"}, "ABC")); + assertTrue(StringUtil.containsIgnoreCase(new String[]{"ABC"}, "abc")); + assertTrue(StringUtil.containsIgnoreCase(new String[]{null, "abc"}, "ABC")); + assertTrue(StringUtil.containsIgnoreCase(new String[]{null, "abc"}, null)); + + assertFalse(StringUtil.containsIgnoreCase(new String[]{"abc"}, "def")); + assertFalse(StringUtil.containsIgnoreCase(new String[]{}, "ABC")); + assertFalse(StringUtil.containsIgnoreCase(new String[]{}, null)); + } + + @Test + public void testJoin() { + String[] array = {"aa", "bb", "cc"}; + assertEquals("aa,bb,cc", StringUtil.join(array, ",")); + assertEquals("aa, bb, cc", StringUtil.join(array, ", ")); + assertEquals("aabbcc", StringUtil.join(array, "")); + assertEquals("aa bb cc", StringUtil.join(array, " ")); + assertEquals("aa\nbb\ncc", StringUtil.join(array, "\n")); + + assertEquals("", StringUtil.join(new String[]{}, ",")); + assertEquals("abc", StringUtil.join(new String[]{"abc"}, ",")); + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/AnotherFakeApiTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/AnotherFakeApiTest.java index face3d9b785e..0f49c5e2e01c 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/AnotherFakeApiTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/AnotherFakeApiTest.java @@ -2,31 +2,23 @@ * OpenAPI Petstore * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * - * The version of the OpenAPI document: 1.0.0 - * + * OpenAPI spec version: 1.0.0 + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ - package org.openapitools.client.api; -import org.openapitools.client.ApiException; -import java.math.BigDecimal; -import org.openapitools.client.model.Client; + import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.openapitools.client.ApiException; +import org.openapitools.client.model.Client; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * API tests for AnotherFakeApi - */ +/** API tests for AnotherFakeApi */ @Disabled public class AnotherFakeApiTest { @@ -35,39 +27,15 @@ public class AnotherFakeApiTest { /** * To test special tags * - * To test special tags and operation ID starting with number + *

To test special tags and operation ID starting with number * * @throws ApiException if the Api call fails */ @Test public void call123testSpecialTagsTest() throws ApiException { - Client client = null; - Client response = api.call123testSpecialTags(client); - // TODO: test validations - } + Client body = null; + Client response = api.call123testSpecialTags(body); - /** - * parameter array number default value - * - * @throws ApiException if the Api call fails - */ - @Test - public void getParameterArrayNumberTest() throws ApiException { - List array = null; - api.getParameterArrayNumber(array); - // TODO: test validations - } - - /** - * parameter string number - * - * @throws ApiException if the Api call fails - */ - @Test - public void getParameterStringNumberTest() throws ApiException { - BigDecimal stringNumber = null; - api.getParameterStringNumber(stringNumber); // TODO: test validations } - } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/FakeApiTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/FakeApiTest.java index badfac3b4cc2..4dea80f5e403 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/FakeApiTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/FakeApiTest.java @@ -24,8 +24,8 @@ import org.openapitools.client.model.OuterComposite; import org.openapitools.client.model.OuterEnum; import org.openapitools.client.model.User; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Disabled; import java.util.ArrayList; import java.util.HashMap; @@ -40,133 +40,148 @@ public class FakeApiTest { private final FakeApi api = new FakeApi(); + /** * Health check endpoint * - * @throws ApiException if the Api call fails + * + * + * @throws ApiException + * if the Api call fails */ @Test public void fakeHealthGetTest() throws ApiException { - HealthCheckResult response = api.fakeHealthGet(); + HealthCheckResult response = api.fakeHealthGet(); // TODO: test validations } - + /** + * + * * Test serialization of outer boolean types * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void fakeOuterBooleanSerializeTest() throws ApiException { Boolean body = null; - Boolean response = api.fakeOuterBooleanSerialize(body); + Boolean response = api.fakeOuterBooleanSerialize(body); // TODO: test validations } - + /** + * + * * Test serialization of object with outer number type * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void fakeOuterCompositeSerializeTest() throws ApiException { OuterComposite outerComposite = null; - OuterComposite response = api.fakeOuterCompositeSerialize(outerComposite); + OuterComposite response = api.fakeOuterCompositeSerialize(outerComposite); // TODO: test validations } - + /** + * + * * Test serialization of outer number types * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void fakeOuterNumberSerializeTest() throws ApiException { BigDecimal body = null; - BigDecimal response = api.fakeOuterNumberSerialize(body); + BigDecimal response = api.fakeOuterNumberSerialize(body); // TODO: test validations } - + /** + * + * * Test serialization of outer string types * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void fakeOuterStringSerializeTest() throws ApiException { String body = null; - String response = api.fakeOuterStringSerialize(body); + String response = api.fakeOuterStringSerialize(body); // TODO: test validations } - + /** * Array of Enums * - * @throws ApiException if the Api call fails + * + * + * @throws ApiException + * if the Api call fails */ @Test public void getArrayOfEnumsTest() throws ApiException { - List response = api.getArrayOfEnums(); + List response = api.getArrayOfEnums(); // TODO: test validations } - + /** - * parameter name mapping test + * * - * @throws ApiException if the Api call fails - */ - @Test - public void getParameterNameMappingTest() throws ApiException { - Long underscoreType = null; - String type = null; - String typeWithUnderscore = null; - api.getParameterNameMapping(underscoreType, type, typeWithUnderscore); - // TODO: test validations - } - - /** * For this test, the body for this request much reference a schema named `File`. * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void testBodyWithFileSchemaTest() throws ApiException { FileSchemaTestClass fileSchemaTestClass = null; - api.testBodyWithFileSchema(fileSchemaTestClass); + api.testBodyWithFileSchema(fileSchemaTestClass); // TODO: test validations } - + /** - * @throws ApiException if the Api call fails + * + * + * + * + * @throws ApiException + * if the Api call fails */ @Test public void testBodyWithQueryParamsTest() throws ApiException { String query = null; User user = null; - api.testBodyWithQueryParams(query, user); + api.testBodyWithQueryParams(query, user); // TODO: test validations } - + /** * To test \"client\" model * * To test \"client\" model * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void testClientModelTest() throws ApiException { Client client = null; - Client response = api.testClientModel(client); + Client response = api.testClientModel(client); // TODO: test validations } - + /** * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void testEndpointParametersTest() throws ApiException { @@ -184,16 +199,17 @@ public void testEndpointParametersTest() throws ApiException { OffsetDateTime dateTime = null; String password = null; String paramCallback = null; - api.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback); + api.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback); // TODO: test validations } - + /** * To test enum parameters * * To test enum parameters * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void testEnumParametersTest() throws ApiException { @@ -205,16 +221,17 @@ public void testEnumParametersTest() throws ApiException { Double enumQueryDouble = null; List enumFormStringArray = null; String enumFormString = null; - api.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString); + api.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString); // TODO: test validations } - + /** * Fake endpoint to test group parameters (optional) * * Fake endpoint to test group parameters (optional) * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void testGroupParametersTest() throws ApiException { @@ -224,47 +241,52 @@ public void testGroupParametersTest() throws ApiException { Integer stringGroup = null; Boolean booleanGroup = null; Long int64Group = null; - api.testGroupParameters(requiredStringGroup, requiredBooleanGroup, requiredInt64Group) + api.testGroupParameters(requiredStringGroup, requiredBooleanGroup, requiredInt64Group) .stringGroup(stringGroup) .booleanGroup(booleanGroup) .int64Group(int64Group) .execute(); // TODO: test validations } - + /** * test inline additionalProperties * * * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void testInlineAdditionalPropertiesTest() throws ApiException { Map requestBody = null; - api.testInlineAdditionalProperties(requestBody); + api.testInlineAdditionalProperties(requestBody); // TODO: test validations } - + /** * test json serialization of form data * * * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void testJsonFormDataTest() throws ApiException { String param = null; String param2 = null; - api.testJsonFormData(param, param2); + api.testJsonFormData(param, param2); // TODO: test validations } - + /** + * + * * To test the collection format in query parameters * - * @throws ApiException if the Api call fails + * @throws ApiException + * if the Api call fails */ @Test public void testQueryParameterCollectionFormatTest() throws ApiException { @@ -273,8 +295,8 @@ public void testQueryParameterCollectionFormatTest() throws ApiException { List http = null; List url = null; List context = null; - api.testQueryParameterCollectionFormat(pipe, ioutil, http, url, context); + api.testQueryParameterCollectionFormat(pipe, ioutil, http, url, context); // TODO: test validations } - + } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/FakeClassnameTags123ApiTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/FakeClassnameTags123ApiTest.java index aa1b824dd5a2..3eb19491b9b0 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/FakeClassnameTags123ApiTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/FakeClassnameTags123ApiTest.java @@ -2,30 +2,23 @@ * OpenAPI Petstore * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * - * The version of the OpenAPI document: 1.0.0 - * + * OpenAPI spec version: 1.0.0 + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ - package org.openapitools.client.api; -import org.openapitools.client.ApiException; -import org.openapitools.client.model.Client; + import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.openapitools.client.ApiException; +import org.openapitools.client.model.Client; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * API tests for FakeClassnameTags123Api - */ +/** API tests for FakeClassnameTags123Api */ @Disabled public class FakeClassnameTags123ApiTest { @@ -34,15 +27,15 @@ public class FakeClassnameTags123ApiTest { /** * To test class name in snake case * - * To test class name in snake case + *

To test class name in snake case * * @throws ApiException if the Api call fails */ @Test public void testClassnameTest() throws ApiException { - Client client = null; - Client response = api.testClassname(client); + Client body = null; + Client response = api.testClassname(body); + // TODO: test validations } - } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java new file mode 100644 index 000000000000..89fe1d01c460 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java @@ -0,0 +1,579 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client.api; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.*; +import org.openapitools.client.*; +import org.openapitools.client.ApiException; +import org.openapitools.client.auth.*; +import org.openapitools.client.model.*; +import org.openapitools.client.model.Pet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * API tests for PetApi + */ +public class PetApiTest { + + private PetApi api = new PetApi(); + private final Logger LOG = LoggerFactory.getLogger(PetApiTest.class); + // In the circle.yml file, /etc/host is configured with an entry to resolve petstore.swagger.io + // to 127.0.0.1 + private static String basePath = "http://petstore.swagger.io:80/v2"; + + @BeforeEach + public void setup() { + // setup authentication + ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key"); + apiKeyAuth.setApiKey("special-key"); + api.getApiClient().setBasePath(basePath); + } + + @Test + public void testApiClient() { + // the default api client is used + assertEquals(Configuration.getDefaultApiClient(), api.getApiClient()); + assertNotNull(api.getApiClient()); + assertEquals(basePath, api.getApiClient().getBasePath()); + assertFalse(api.getApiClient().isDebugging()); + + ApiClient oldClient = api.getApiClient(); + + ApiClient newClient = new ApiClient(); + newClient.setVerifyingSsl(true); + newClient.setBasePath("http://example.com"); + newClient.setDebugging(true); + + // set api client via constructor + api = new PetApi(newClient); + assertNotNull(api.getApiClient()); + assertEquals("http://example.com", api.getApiClient().getBasePath()); + assertTrue(api.getApiClient().isDebugging()); + + // set api client via setter method + api.setApiClient(oldClient); + assertNotNull(api.getApiClient()); + assertEquals(basePath, api.getApiClient().getBasePath()); + assertFalse(api.getApiClient().isDebugging()); + } + + @Test + public void testCreateAndGetPet() throws Exception { + Pet pet = createPet(); + api.addPet(pet); + + Pet fetched = api.getPetById(pet.getId()); + assertPetMatches(pet, fetched); + api.deletePet(pet.getId(), null); + } + + @Test + public void testCreateAndGetPetWithHttpInfo() throws Exception { + Pet pet = createPet(); + api.addPetWithHttpInfo(pet); + + ApiResponse resp = api.getPetByIdWithHttpInfo(pet.getId()); + assertEquals(200, resp.getStatusCode()); + assertEquals("application/json", resp.getHeaders().get("Content-Type").get(0)); + Pet fetched = resp.getData(); + + assertPetMatches(pet, fetched); + api.deletePet(pet.getId(), null); + } + + @Test + public void testCreateAndGetPetAsync() throws Exception { + Pet pet = createPet(); + api.addPet(pet); + // to store returned Pet or error message/exception + final Map result = new HashMap(); + + api.getPetByIdAsync( + pet.getId(), + new ApiCallback() { + @Override + public void onFailure( + ApiException e, + int statusCode, + Map> responseHeaders) { + result.put("error", e.getMessage()); + } + + @Override + public void onSuccess( + Pet pet, int statusCode, Map> responseHeaders) { + result.put("pet", pet); + } + + @Override + public void onUploadProgress( + long bytesWritten, long contentLength, boolean done) { + // empty + } + + @Override + public void onDownloadProgress( + long bytesRead, long contentLength, boolean done) { + // empty + } + }); + + // wait for the asynchronous call to finish (at most 10 seconds) + final int maxTry = 10; + int tryCount = 1; + Pet fetched = null; + do { + if (tryCount > maxTry) fail("have not got result of getPetByIdAsync after 10 seconds"); + Thread.sleep(1000); + tryCount += 1; + if (result.get("error") != null) fail((String) result.get("error")); + if (result.get("pet") != null) { + fetched = (Pet) result.get("pet"); + break; + } + } while (result.isEmpty()); + assertPetMatches(pet, fetched); + api.deletePet(pet.getId(), null); + } + + @Test + public void testCreateAndGetPetAsyncInvalidID() throws Exception { + Pet pet = createPet(); + api.addPet(pet); + // to store returned Pet or error message/exception + final Map result = new HashMap(); + + // test getting a nonexistent pet + result.clear(); + api.getPetByIdAsync( + -10000L, + new ApiCallback() { + @Override + public void onFailure( + ApiException e, + int statusCode, + Map> responseHeaders) { + result.put("exception", e); + } + + @Override + public void onSuccess( + Pet pet, int statusCode, Map> responseHeaders) { + result.put("pet", pet); + } + + @Override + public void onUploadProgress( + long bytesWritten, long contentLength, boolean done) { + // empty + } + + @Override + public void onDownloadProgress( + long bytesRead, long contentLength, boolean done) { + // empty + } + }); + + // wait for the asynchronous call to finish (at most 10 seconds) + final int maxTry = 10; + int tryCount = 1; + Pet fetched = null; + ApiException exception = null; + + do { + if (tryCount > maxTry) fail("have not got result of getPetByIdAsync after 10 seconds"); + Thread.sleep(1000); + tryCount += 1; + if (result.get("pet") != null) fail("expected an error"); + if (result.get("exception") != null) { + exception = (ApiException) result.get("exception"); + break; + } + } while (result.isEmpty()); + assertNotNull(exception); + assertEquals(404, exception.getCode()); + String pattern = "^Message: Not Found\\RHTTP response code: 404\\RHTTP response body: .*\\RHTTP response headers: .*$"; + assertTrue(exception.getMessage().matches(pattern)); + assertEquals("application/json", exception.getResponseHeaders().get("Content-Type").get(0)); + api.deletePet(pet.getId(), null); + } + + @Test + public void testCreateAndGetMultiplePetsAsync() throws Exception { + Pet pet1 = createPet(); + Pet pet2 = createPet(); + + final CountDownLatch addLatch = new CountDownLatch(2); + final TestApiCallback addCallback1 = new TestApiCallback(addLatch); + final TestApiCallback addCallback2 = new TestApiCallback(addLatch); + + // Make 2 simultaneous calls + api.addPetAsync(pet1, addCallback1); + api.addPetAsync(pet2, addCallback2); + + // wait for both asynchronous calls to finish (at most 10 seconds) + assertTrue(addLatch.await(10, TimeUnit.SECONDS)); + + assertTrue(addCallback1.isDone()); + assertTrue(addCallback2.isDone()); + + if (!addCallback1.isSuccess()) throw addCallback1.getException(); + if (!addCallback2.isSuccess()) throw addCallback2.getException(); + + assertValidProgress(addCallback1.getUploadProgress()); + assertValidProgress(addCallback2.getUploadProgress()); + + final CountDownLatch getLatch = new CountDownLatch(3); + final TestApiCallback getCallback1 = new TestApiCallback(getLatch); + final TestApiCallback getCallback2 = new TestApiCallback(getLatch); + final TestApiCallback getCallback3 = new TestApiCallback(getLatch); + + api.getPetByIdAsync(pet1.getId(), getCallback1); + api.getPetByIdAsync(pet2.getId(), getCallback2); + // Get nonexistent pet + api.getPetByIdAsync(-10000L, getCallback3); + + // wait for all asynchronous calls to finish (at most 10 seconds) + assertTrue(getLatch.await(10, TimeUnit.SECONDS)); + + assertTrue(getCallback1.isDone()); + assertTrue(getCallback2.isDone()); + assertTrue(getCallback3.isDone()); + + if (!getCallback1.isSuccess()) throw getCallback1.getException(); + if (!getCallback2.isSuccess()) throw getCallback2.getException(); + + assertPetMatches(pet1, getCallback1.getResult()); + assertPetMatches(pet2, getCallback2.getResult()); + + assertValidProgress(getCallback1.getDownloadProgress()); + assertValidProgress(getCallback2.getDownloadProgress()); + + // Last callback should fail with ApiException + assertFalse(getCallback3.isSuccess()); + final ApiException exception = getCallback3.getException(); + assertNotNull(exception); + assertEquals(404, exception.getCode()); + api.deletePet(pet1.getId(), null); + api.deletePet(pet2.getId(), null); + } + + @Test + public void testUpdatePet() throws Exception { + Pet pet = createPet(); + api.addPet(pet); + pet.setName("programmer"); + + api.updatePet(pet); + + Pet fetched = api.getPetById(pet.getId()); + assertPetMatches(pet, fetched); + api.deletePet(pet.getId(), null); + } + + @Test + public void testFindPetsByStatus() throws Exception { + assertEquals(basePath, api.getApiClient().getBasePath()); + Pet pet = createPet(); + api.addPet(pet); + pet.setName("programmer"); + pet.setStatus(Pet.StatusEnum.PENDING); + api.updatePet(pet); + + List pets = api.findPetsByStatus(Arrays.asList("pending")); + assertNotNull(pets); + + boolean found = false; + for (Pet fetched : pets) { + if (fetched.getId().equals(pet.getId())) { + found = true; + break; + } + } + + assertTrue(found); + + api.deletePet(pet.getId(), null); + } + + @Test + @Disabled + public void testFindPetsByTags() throws Exception { + Pet pet = createPet(); + pet.setName("monster"); + pet.setStatus(Pet.StatusEnum.AVAILABLE); + + List tags = new ArrayList(); + org.openapitools.client.model.Tag tag1 = new org.openapitools.client.model.Tag(); + tag1.setName("friendly"); + tags.add(tag1); + pet.setTags(tags); + + api.updatePet(pet); + + List pets = api.findPetsByTags((Arrays.asList("friendly"))); + assertNotNull(pets); + + boolean found = false; + for (Pet fetched : pets) { + if (fetched.getId().equals(pet.getId())) { + found = true; + break; + } + } + assertTrue(found); + + api.deletePet(pet.getId(), null); + } + + @Test + public void testUpdatePetWithForm() throws Exception { + Pet pet = createPet(); + pet.setName("frank"); + api.addPet(pet); + + Pet fetched = api.getPetById(pet.getId()); + + api.updatePetWithForm(fetched.getId(), "furt", null); + Pet updated = api.getPetById(fetched.getId()); + + assertEquals(updated.getName(), "furt"); + api.deletePet(pet.getId(), null); + } + + @Test + @Disabled + public void testDeletePet() throws Exception { + Pet pet = createPet(); + api.addPet(pet); + + Pet fetched = api.getPetById(pet.getId()); + api.deletePet(pet.getId(), null); + + try { + fetched = api.getPetById(fetched.getId()); + fail("expected an error"); + } catch (ApiException e) { + LOG.info("Code: {}. Message: {}", e.getCode(), e.getMessage()); + assertEquals(404, e.getCode()); + } + } + + @Test + public void testUploadFile() throws Exception { + Pet pet = createPet(); + api.addPet(pet); + + File file = new File("hello.txt"); + BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + writer.write("Hello world!"); + writer.close(); + + api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath())); + api.deletePet(pet.getId(), null); + } + + @Test + public void testEqualsAndHashCode() { + Pet pet1 = new Pet(); + Pet pet2 = new Pet(); + assertTrue(pet1.equals(pet2)); + assertTrue(pet2.equals(pet1)); + assertTrue(pet1.hashCode() == pet2.hashCode()); + assertTrue(pet1.equals(pet1)); + assertTrue(pet1.hashCode() == pet1.hashCode()); + + pet2.setName("really-happy"); + pet2.setPhotoUrls( + (Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2"))); + assertFalse(pet1.equals(pet2)); + assertFalse(pet2.equals(pet1)); + assertFalse(pet1.hashCode() == (pet2.hashCode())); + assertTrue(pet2.equals(pet2)); + assertTrue(pet2.hashCode() == pet2.hashCode()); + + pet1.setName("really-happy"); + pet1.setPhotoUrls( + (Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2"))); + assertTrue(pet1.equals(pet2)); + assertTrue(pet2.equals(pet1)); + assertTrue(pet1.hashCode() == pet2.hashCode()); + assertTrue(pet1.equals(pet1)); + assertTrue(pet1.hashCode() == pet1.hashCode()); + } + + private Pet createPet() { + Pet pet = new Pet(); + pet.setId(ThreadLocalRandom.current().nextLong(Long.MAX_VALUE)); + pet.setName("gorilla"); + + Category category = new Category(); + category.setName("really-happy"); + + pet.setCategory(category); + pet.setStatus(Pet.StatusEnum.AVAILABLE); + List photos = + (Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2")); + pet.setPhotoUrls(photos); + + return pet; + } + + private String serializeJson(Object o, ApiClient apiClient) { + return apiClient.getJSON().serialize(o); + } + + private T deserializeJson(String json, Type type, ApiClient apiClient) { + return (T) apiClient.getJSON().deserialize(json, type); + } + + private void assertPetMatches(Pet expected, Pet actual) { + assertNotNull(actual); + assertEquals(expected.getId(), actual.getId()); + assertNotNull(actual.getCategory()); + assertEquals(expected.getCategory().getName(), actual.getCategory().getName()); + } + + /** + * Assert that the given upload/download progress list satisfies the following constraints: + * + *

- List is not empty - Byte count should be nondecreasing - The last element, and only the + * last element, should have done=true + */ + private void assertValidProgress(List progressList) { + assertFalse(progressList.isEmpty()); + + Progress prev = null; + int index = 0; + for (Progress progress : progressList) { + if (prev != null) { + if (prev.done || prev.bytes > progress.bytes) { + fail("Progress list out of order at index " + index + ": " + progressList); + } + } + prev = progress; + index += 1; + } + + if (!prev.done) { + fail("Last progress item should have done=true: " + progressList); + } + } + + private static class TestApiCallback implements ApiCallback { + + private final CountDownLatch latch; + private final ConcurrentLinkedQueue uploadProgress = + new ConcurrentLinkedQueue(); + private final ConcurrentLinkedQueue downloadProgress = + new ConcurrentLinkedQueue(); + + private boolean done; + private boolean success; + private ApiException exception; + private T result; + + public TestApiCallback(CountDownLatch latch) { + this.latch = latch; + this.done = false; + } + + @Override + public void onFailure( + ApiException e, int statusCode, Map> responseHeaders) { + exception = e; + this.done = true; + this.success = false; + latch.countDown(); + } + + @Override + public void onSuccess(T result, int statusCode, Map> responseHeaders) { + this.result = result; + this.done = true; + this.success = true; + latch.countDown(); + } + + @Override + public void onUploadProgress(long bytesWritten, long contentLength, boolean done) { + uploadProgress.add(new Progress(bytesWritten, contentLength, done)); + } + + @Override + public void onDownloadProgress(long bytesRead, long contentLength, boolean done) { + downloadProgress.add(new Progress(bytesRead, contentLength, done)); + } + + public boolean isDone() { + return done; + } + + public boolean isSuccess() { + return success; + } + + public ApiException getException() { + return exception; + } + + public T getResult() { + return result; + } + + public List getUploadProgress() { + return new ArrayList(uploadProgress); + } + + public List getDownloadProgress() { + return new ArrayList(downloadProgress); + } + } + + private static class Progress { + public final long bytes; + public final long contentLength; + public final boolean done; + + public Progress(long bytes, long contentLength, boolean done) { + this.bytes = bytes; + this.contentLength = contentLength; + this.done = done; + } + + @Override + public String toString() { + return ""; + } + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/StoreApiTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/StoreApiTest.java index 98354ba10c08..b9c5785e5ca3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/StoreApiTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/StoreApiTest.java @@ -2,30 +2,24 @@ * OpenAPI Petstore * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * - * The version of the OpenAPI document: 1.0.0 - * + * OpenAPI spec version: 1.0.0 + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ - package org.openapitools.client.api; -import org.openapitools.client.ApiException; -import org.openapitools.client.model.Order; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.openapitools.client.ApiException; +import org.openapitools.client.model.Order; -/** - * API tests for StoreApi - */ +/** API tests for StoreApi */ @Disabled public class StoreApiTest { @@ -34,7 +28,8 @@ public class StoreApiTest { /** * Delete purchase order by ID * - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + *

For valid response try integer IDs with value < 1000. Anything above 1000 or + * nonintegers will generate API errors * * @throws ApiException if the Api call fails */ @@ -42,26 +37,29 @@ public class StoreApiTest { public void deleteOrderTest() throws ApiException { String orderId = null; api.deleteOrder(orderId); + // TODO: test validations } /** * Returns pet inventories by status * - * Returns a map of status codes to quantities + *

Returns a map of status codes to quantities * * @throws ApiException if the Api call fails */ @Test public void getInventoryTest() throws ApiException { Map response = api.getInventory(); + // TODO: test validations } /** * Find purchase order by ID * - * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + *

For valid response try integer IDs with value <= 5 or > 10. Other values will + * generated exceptions * * @throws ApiException if the Api call fails */ @@ -69,21 +67,20 @@ public void getInventoryTest() throws ApiException { public void getOrderByIdTest() throws ApiException { Long orderId = null; Order response = api.getOrderById(orderId); + // TODO: test validations } /** * Place an order for a pet * - * - * * @throws ApiException if the Api call fails */ @Test public void placeOrderTest() throws ApiException { - Order order = null; - Order response = api.placeOrder(order); + Order body = null; + Order response = api.placeOrder(body); + // TODO: test validations } - } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/UserApiTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/UserApiTest.java index aa9aff49b4df..50a958f2fd01 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/UserApiTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/UserApiTest.java @@ -2,31 +2,24 @@ * OpenAPI Petstore * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ * - * The version of the OpenAPI document: 1.0.0 - * + * OpenAPI spec version: 1.0.0 + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ - package org.openapitools.client.api; -import org.openapitools.client.ApiException; -import java.time.OffsetDateTime; -import org.openapitools.client.model.User; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.openapitools.client.ApiException; +import org.openapitools.client.model.User; -/** - * API tests for UserApi - */ +/** API tests for UserApi */ @Disabled public class UserApiTest { @@ -35,49 +28,48 @@ public class UserApiTest { /** * Create user * - * This can only be done by the logged in user. + *

This can only be done by the logged in user. * * @throws ApiException if the Api call fails */ @Test public void createUserTest() throws ApiException { - User user = null; - api.createUser(user); + User body = null; + api.createUser(body); + // TODO: test validations } /** * Creates list of users with given input array * - * - * * @throws ApiException if the Api call fails */ @Test public void createUsersWithArrayInputTest() throws ApiException { - List user = null; - api.createUsersWithArrayInput(user); + List body = null; + api.createUsersWithArrayInput(body); + // TODO: test validations } /** * Creates list of users with given input array * - * - * * @throws ApiException if the Api call fails */ @Test public void createUsersWithListInputTest() throws ApiException { - List user = null; - api.createUsersWithListInput(user); + List body = null; + api.createUsersWithListInput(body); + // TODO: test validations } /** * Delete user * - * This can only be done by the logged in user. + *

This can only be done by the logged in user. * * @throws ApiException if the Api call fails */ @@ -85,28 +77,26 @@ public void createUsersWithListInputTest() throws ApiException { public void deleteUserTest() throws ApiException { String username = null; api.deleteUser(username); + // TODO: test validations } /** * Get user by user name * - * - * * @throws ApiException if the Api call fails */ @Test public void getUserByNameTest() throws ApiException { String username = null; User response = api.getUserByName(username); + // TODO: test validations } /** * Logs user into the system * - * - * * @throws ApiException if the Api call fails */ @Test @@ -114,35 +104,35 @@ public void loginUserTest() throws ApiException { String username = null; String password = null; String response = api.loginUser(username, password); + // TODO: test validations } /** * Logs out current logged in user session * - * - * * @throws ApiException if the Api call fails */ @Test public void logoutUserTest() throws ApiException { api.logoutUser(); + // TODO: test validations } /** * Updated user * - * This can only be done by the logged in user. + *

This can only be done by the logged in user. * * @throws ApiException if the Api call fails */ @Test public void updateUserTest() throws ApiException { String username = null; - User user = null; - api.updateUser(username, user); + User body = null; + api.updateUser(username, body); + // TODO: test validations } - } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java new file mode 100644 index 000000000000..c4b8362967d0 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java @@ -0,0 +1,119 @@ +package org.openapitools.client.auth; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.*; +import org.openapitools.client.ApiException; +import org.openapitools.client.Pair; + +public class ApiKeyAuthTest { + @Test + public void testApplyToParamsInQuery() throws ApiException { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + Map cookieParams = new HashMap(); + + ApiKeyAuth auth = new ApiKeyAuth("query", "api_key"); + auth.setApiKey("my-api-key"); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + + assertEquals(1, queryParams.size()); + for (Pair queryParam : queryParams) { + assertEquals("my-api-key", queryParam.getValue()); + } + + // no changes to header or cookie parameters + assertEquals(0, headerParams.size()); + assertEquals(0, cookieParams.size()); + } + + @Test + public void testApplyToParamsInQueryWithNullValue() throws ApiException { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + Map cookieParams = new HashMap(); + + ApiKeyAuth auth = new ApiKeyAuth("query", "api_key"); + auth.setApiKey(null); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + + // no changes to parameters + assertEquals(0, queryParams.size()); + assertEquals(0, headerParams.size()); + assertEquals(0, cookieParams.size()); + } + + @Test + public void testApplyToParamsInHeaderWithPrefix() throws ApiException { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + Map cookieParams = new HashMap(); + + ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN"); + auth.setApiKey("my-api-token"); + auth.setApiKeyPrefix("Token"); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + + // no changes to query or cookie parameters + assertEquals(0, queryParams.size()); + assertEquals(0, cookieParams.size()); + assertEquals(1, headerParams.size()); + assertEquals("Token my-api-token", headerParams.get("X-API-TOKEN")); + } + + @Test + public void testApplyToParamsInHeaderWithNullValue() throws ApiException { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + Map cookieParams = new HashMap(); + + ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN"); + auth.setApiKey(null); + auth.setApiKeyPrefix("Token"); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + + // no changes to parameters + assertEquals(0, queryParams.size()); + assertEquals(0, cookieParams.size()); + assertEquals(0, headerParams.size()); + } + + @Test + public void testApplyToParamsInCookieWithPrefix() throws ApiException { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + Map cookieParams = new HashMap(); + + ApiKeyAuth auth = new ApiKeyAuth("cookie", "X-API-TOKEN"); + auth.setApiKey("my-api-token"); + auth.setApiKeyPrefix("Token"); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + + // no changes to query or header parameters + assertEquals(0, queryParams.size()); + assertEquals(0, headerParams.size()); + assertEquals(1, cookieParams.size()); + assertEquals("Token my-api-token", cookieParams.get("X-API-TOKEN")); + } + + @Test + public void testApplyToParamsInCookieWithNullValue() throws ApiException { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + Map cookieParams = new HashMap(); + + ApiKeyAuth auth = new ApiKeyAuth("cookie", "X-API-TOKEN"); + auth.setApiKey(null); + auth.setApiKeyPrefix("Token"); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + + // no changes to parameters + assertEquals(0, queryParams.size()); + assertEquals(0, cookieParams.size()); + assertEquals(0, headerParams.size()); + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java new file mode 100644 index 000000000000..1230a9d9d2e9 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java @@ -0,0 +1,65 @@ +package org.openapitools.client.auth; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.*; +import org.openapitools.client.ApiException; +import org.openapitools.client.Pair; + +public class HttpBasicAuthTest { + HttpBasicAuth auth = null; + + @BeforeEach + public void setup() { + auth = new HttpBasicAuth(); + } + + @Test + public void testApplyToParams() throws ApiException { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + Map cookieParams = new HashMap(); + + auth.setUsername("my-username"); + auth.setPassword("my-password"); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + + // no changes to query or cookie parameters + assertEquals(0, queryParams.size()); + assertEquals(0, cookieParams.size()); + assertEquals(1, headerParams.size()); + // the string below is base64-encoded result of "my-username:my-password" with the "Basic " + // prefix + String expected = "Basic bXktdXNlcm5hbWU6bXktcGFzc3dvcmQ="; + assertEquals(expected, headerParams.get("Authorization")); + + // null username should be treated as empty string + auth.setUsername(null); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + // the string below is base64-encoded result of ":my-password" with the "Basic " prefix + expected = "Basic Om15LXBhc3N3b3Jk"; + assertEquals(expected, headerParams.get("Authorization")); + + // null password should be treated as empty string + auth.setUsername("my-username"); + auth.setPassword(null); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + // the string below is base64-encoded result of "my-username:" with the "Basic " prefix + expected = "Basic bXktdXNlcm5hbWU6"; + assertEquals(expected, headerParams.get("Authorization")); + + // null username and password should be ignored + queryParams = new ArrayList(); + headerParams = new HashMap(); + auth.setUsername(null); + auth.setPassword(null); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); + // no changes to parameters + assertEquals(0, queryParams.size()); + assertEquals(0, headerParams.size()); + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/RetryingOAuthTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/RetryingOAuthTest.java new file mode 100644 index 000000000000..13d9276a7874 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/auth/RetryingOAuthTest.java @@ -0,0 +1,124 @@ +package org.openapitools.client.auth; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.util.Collections; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import okhttp3.*; +import okhttp3.Interceptor.Chain; +import okhttp3.Response.Builder; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +public class RetryingOAuthTest { + + private RetryingOAuth oauth; + + @BeforeEach + public void setUp() throws Exception { + oauth = + new RetryingOAuth( + "_clientId", + "_clientSecret", + OAuthFlow.ACCESS_CODE, + "https://token.example.com", + Collections.emptyMap()); + oauth.setAccessToken("expired-access-token"); + FieldUtils.writeField(oauth, "oAuthClient", mockOAuthClient(), true); + } + + @Test + public void testSingleRequestUnauthorized() throws Exception { + Response response = oauth.intercept(mockChain()); + assertEquals(HttpURLConnection.HTTP_OK, response.code()); + } + + @Test + public void testTwoConcurrentRequestsUnauthorized() throws Exception { + + Callable callable = + new Callable() { + @Override + public Response call() throws Exception { + return oauth.intercept(mockChain()); + } + }; + ExecutorService executor = Executors.newFixedThreadPool(2); + try { + Future response1 = executor.submit(callable); + Future response2 = executor.submit(callable); + + assertEquals(HttpURLConnection.HTTP_OK, response1.get().code()); + assertEquals(HttpURLConnection.HTTP_OK, response2.get().code()); + } finally { + executor.shutdown(); + } + } + + private OAuthClient mockOAuthClient() throws OAuthProblemException, OAuthSystemException { + OAuthJSONAccessTokenResponse response = mock(OAuthJSONAccessTokenResponse.class); + when(response.getAccessToken()) + .thenAnswer( + new Answer() { + @Override + public String answer(InvocationOnMock invocation) throws Throwable { + // sleep ensures that the bug is triggered. + Thread.sleep(1000); + return "new-access-token"; + } + }); + + OAuthClient client = mock(OAuthClient.class); + when(client.accessToken(any(OAuthClientRequest.class))).thenReturn(response); + return client; + } + + private Chain mockChain() throws IOException { + Chain chain = mock(Chain.class); + + final Request request = new Request.Builder().url("https://api.example.com").build(); + when(chain.request()).thenReturn(request); + + when(chain.proceed(any(Request.class))) + .thenAnswer( + new Answer() { + @Override + public Response answer(InvocationOnMock inv) { + Request r = inv.getArgument(0); + int responseCode = + "Bearer new-access-token".equals(r.header("Authorization")) + ? HttpURLConnection.HTTP_OK + : HttpURLConnection.HTTP_UNAUTHORIZED; + return new Builder() + .protocol(Protocol.HTTP_1_0) + .message("sup") + .request(request) + .body( + ResponseBody.create( + new byte[0], + MediaType.get("application/test"))) + .code(responseCode) + .build(); + } + }); + + return chain; + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AdditionalPropertiesClassTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AdditionalPropertiesClassTest.java index 4d17345a18e7..074e6add3cc7 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AdditionalPropertiesClassTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AdditionalPropertiesClassTest.java @@ -19,13 +19,13 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import org.openapitools.jackson.nullable.JsonNullable; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for AdditionalPropertiesClass */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AnimalTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AnimalTest.java index f30075833858..cc4678583018 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AnimalTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AnimalTest.java @@ -19,10 +19,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; +import org.openapitools.client.model.Cat; +import org.openapitools.client.model.Dog; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Animal */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AppleReqTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AppleReqTest.java index ab1caf49d1bb..772c2ac24bf3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AppleReqTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AppleReqTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for AppleReq */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AppleTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AppleTest.java index 0cde246f3dd8..1b9fd1706d46 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AppleTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/AppleTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Apple */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInnerTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInnerTest.java index 0be94bcc3466..15817f98e222 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInnerTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInnerTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ArrayOfInlineAllOfArrayAllofDogPropertyInner */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfInlineAllOfTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfInlineAllOfTest.java index 385ead61ffe5..c887d6b4bc39 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfInlineAllOfTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfInlineAllOfTest.java @@ -20,12 +20,12 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.openapitools.client.model.ArrayOfInlineAllOfArrayAllofDogPropertyInner; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ArrayOfInlineAllOf */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfNumberOnlyTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfNumberOnlyTest.java index 7121b15da89f..8eb0bf5acd59 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfNumberOnlyTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayOfNumberOnlyTest.java @@ -21,11 +21,11 @@ import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ArrayOfNumberOnly */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayTestTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayTestTest.java index da72462ec73d..63a98fbeff6d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayTestTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ArrayTestTest.java @@ -20,12 +20,12 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.openapitools.client.model.ReadOnlyFirst; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ArrayTest */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BananaReqTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BananaReqTest.java index cf02d90b8c2c..30568207995f 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BananaReqTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BananaReqTest.java @@ -20,10 +20,10 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.math.BigDecimal; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for BananaReq */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BananaTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BananaTest.java index 889087a653d4..10f407730718 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BananaTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BananaTest.java @@ -20,10 +20,10 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.math.BigDecimal; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Banana */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BasquePigTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BasquePigTest.java index b4e3ebde1882..0d9eec8e0f0b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BasquePigTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/BasquePigTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for BasquePig */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CapitalizationTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CapitalizationTest.java index c3c69e049af7..51745e8a2214 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CapitalizationTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CapitalizationTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Capitalization */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CatTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CatTest.java index 73309d4bec1f..23ab7c6c9045 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CatTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CatTest.java @@ -19,11 +19,11 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.Animal; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Cat */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CategoryTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CategoryTest.java index 03f1c7ec1d53..30e7328449c0 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CategoryTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/CategoryTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Category */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ClassModelTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ClassModelTest.java index 1666ebc79969..0e6956b33269 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ClassModelTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ClassModelTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ClassModel */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ClientTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ClientTest.java index 140143b9573d..22c1e8596146 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ClientTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ClientTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Client */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ComplexQuadrilateralTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ComplexQuadrilateralTest.java index ae249afb2a59..c544a3da00cb 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ComplexQuadrilateralTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ComplexQuadrilateralTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ComplexQuadrilateral */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DanishPigTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DanishPigTest.java index f1a269899574..2a265236c260 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DanishPigTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DanishPigTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for DanishPig */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DeprecatedObjectTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DeprecatedObjectTest.java index 1b298f1bd159..bf3e5f6e21da 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DeprecatedObjectTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DeprecatedObjectTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for DeprecatedObject */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DogTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DogTest.java index 844e3e06f5e1..99c282235ce9 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DogTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DogTest.java @@ -19,11 +19,11 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.Animal; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Dog */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DrawingTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DrawingTest.java index d6834d1985e3..8232c871009b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DrawingTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/DrawingTest.java @@ -20,7 +20,6 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.openapitools.client.model.Fruit; import org.openapitools.client.model.NullableShape; @@ -30,6 +29,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Drawing */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumArraysTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumArraysTest.java index 02954e6a6839..9ca44c3d5e53 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumArraysTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumArraysTest.java @@ -20,11 +20,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for EnumArrays */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumClassTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumClassTest.java index bed8681219e8..88c982a61df2 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumClassTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumClassTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for EnumClass */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumStringDiscriminatorTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumStringDiscriminatorTest.java index ef8bbbfac3f2..9d4c8e553954 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumStringDiscriminatorTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumStringDiscriminatorTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for EnumStringDiscriminator */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumTestTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumTestTest.java index 320df9ad3ebf..79bd51ad8532 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumTestTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EnumTestTest.java @@ -19,7 +19,6 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.OuterEnum; import org.openapitools.client.model.OuterEnumDefaultValue; import org.openapitools.client.model.OuterEnumInteger; @@ -28,6 +27,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for EnumTest */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EquilateralTriangleTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EquilateralTriangleTest.java index 181c439fa18c..edd7afe14210 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EquilateralTriangleTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/EquilateralTriangleTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for EquilateralTriangle */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FileSchemaTestClassTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FileSchemaTestClassTest.java index 79eccbf4beef..75af6c26a264 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FileSchemaTestClassTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FileSchemaTestClassTest.java @@ -20,12 +20,12 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.openapitools.client.model.ModelFile; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for FileSchemaTestClass */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FooGetDefaultResponseTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FooGetDefaultResponseTest.java index 83fc00cea450..4e9ebc39952c 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FooGetDefaultResponseTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FooGetDefaultResponseTest.java @@ -19,11 +19,11 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.Foo; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for FooGetDefaultResponse */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FooTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FooTest.java index 8dd27992bc1c..562b545ffb65 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FooTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FooTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Foo */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FormatTestTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FormatTestTest.java index e2b6ed61d88b..9e091ac1614d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FormatTestTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FormatTestTest.java @@ -23,11 +23,11 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.time.OffsetDateTime; -import java.util.Arrays; import java.util.UUID; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for FormatTest */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FruitReqTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FruitReqTest.java index d4bdb5f312ff..95ea123b1399 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FruitReqTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FruitReqTest.java @@ -20,12 +20,12 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.math.BigDecimal; -import java.util.Arrays; import org.openapitools.client.model.AppleReq; import org.openapitools.client.model.BananaReq; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for FruitReq */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FruitTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FruitTest.java index bc4e5e54130d..bd7cd5827a4b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FruitTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/FruitTest.java @@ -20,12 +20,12 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.math.BigDecimal; -import java.util.Arrays; import org.openapitools.client.model.Apple; import org.openapitools.client.model.Banana; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Fruit */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/GmFruitTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/GmFruitTest.java index 68c8179498de..03b9a54d490a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/GmFruitTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/GmFruitTest.java @@ -20,12 +20,12 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.math.BigDecimal; -import java.util.Arrays; import org.openapitools.client.model.Apple; import org.openapitools.client.model.Banana; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for GmFruit */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/GrandparentAnimalTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/GrandparentAnimalTest.java index 8247ad12829b..dccfda8c772d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/GrandparentAnimalTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/GrandparentAnimalTest.java @@ -19,10 +19,11 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; +import org.openapitools.client.model.ParentPet; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for GrandparentAnimal */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/HasOnlyReadOnlyTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/HasOnlyReadOnlyTest.java index f63bf66b1775..12879ebf3951 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/HasOnlyReadOnlyTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/HasOnlyReadOnlyTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for HasOnlyReadOnly */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/HealthCheckResultTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/HealthCheckResultTest.java index a6e06e3dbd8c..c424fb717e8e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/HealthCheckResultTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/HealthCheckResultTest.java @@ -19,11 +19,11 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.jackson.nullable.JsonNullable; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for HealthCheckResult */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/IsoscelesTriangleTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/IsoscelesTriangleTest.java index 728d1af34f26..b45919dadadd 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/IsoscelesTriangleTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/IsoscelesTriangleTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for IsoscelesTriangle */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MammalTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MammalTest.java index af5250405311..a2682988c72e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MammalTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MammalTest.java @@ -19,13 +19,13 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.Pig; import org.openapitools.client.model.Whale; import org.openapitools.client.model.Zebra; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Mammal */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MapTestTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MapTestTest.java index 0587a961b146..f2515c398b94 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MapTestTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MapTestTest.java @@ -19,12 +19,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for MapTest */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MixedPropertiesAndAdditionalPropertiesClassTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MixedPropertiesAndAdditionalPropertiesClassTest.java index 1cc69bedcd83..03df28593f69 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MixedPropertiesAndAdditionalPropertiesClassTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/MixedPropertiesAndAdditionalPropertiesClassTest.java @@ -20,7 +20,6 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.time.OffsetDateTime; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -28,6 +27,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for MixedPropertiesAndAdditionalPropertiesClass */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/Model200ResponseTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/Model200ResponseTest.java index 01b44a53b4fa..aa3d6381861b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/Model200ResponseTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/Model200ResponseTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Model200Response */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelApiResponseTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelApiResponseTest.java index 9480c9ee0ff7..3f61010629ae 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelApiResponseTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelApiResponseTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ModelApiResponse */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelFileTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelFileTest.java index a84242272474..5e868346f88d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelFileTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelFileTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ModelFile */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelListTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelListTest.java index ea5a55185989..8ec190bf5446 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelListTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelListTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ModelList */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelReturnTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelReturnTest.java index 10c7841ba3c1..dae92f89a6c4 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelReturnTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ModelReturnTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ModelReturn */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NameTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NameTest.java index 52eae7974bc1..7086457d5cf7 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NameTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NameTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Name */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NullableClassTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NullableClassTest.java index 0a0595ca0e65..1f72849e9f2e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NullableClassTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NullableClassTest.java @@ -23,7 +23,6 @@ import java.time.LocalDate; import java.time.OffsetDateTime; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,6 +30,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for NullableClass */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NullableShapeTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NullableShapeTest.java index dbc420fae72d..0026a5188e53 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NullableShapeTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NullableShapeTest.java @@ -19,12 +19,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.Quadrilateral; import org.openapitools.client.model.Triangle; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for NullableShape */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NumberOnlyTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NumberOnlyTest.java index 774200c9f6bc..b01e135a260c 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NumberOnlyTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/NumberOnlyTest.java @@ -20,10 +20,10 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.math.BigDecimal; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for NumberOnly */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ObjectWithDeprecatedFieldsTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ObjectWithDeprecatedFieldsTest.java index 452495e83d31..0f59cf5baec5 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ObjectWithDeprecatedFieldsTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ObjectWithDeprecatedFieldsTest.java @@ -21,12 +21,12 @@ import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.openapitools.client.model.DeprecatedObject; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ObjectWithDeprecatedFields */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OrderTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OrderTest.java index adcfde4a33d0..9dff581d403e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OrderTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OrderTest.java @@ -20,10 +20,10 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.time.OffsetDateTime; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Order */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterCompositeTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterCompositeTest.java index 794328118065..3b6aa4c90338 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterCompositeTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterCompositeTest.java @@ -20,10 +20,10 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.math.BigDecimal; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for OuterComposite */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumDefaultValueTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumDefaultValueTest.java index 6b324784e1d6..57ed09918adc 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumDefaultValueTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumDefaultValueTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for OuterEnumDefaultValue */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumIntegerDefaultValueTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumIntegerDefaultValueTest.java index ffb20a97973b..70cae81500e3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumIntegerDefaultValueTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumIntegerDefaultValueTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for OuterEnumIntegerDefaultValue */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumIntegerTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumIntegerTest.java index be0665bb740e..fc666e9da3bb 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumIntegerTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumIntegerTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for OuterEnumInteger */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumTest.java index 8ab11b65cbde..61cb88bb3dba 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/OuterEnumTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for OuterEnum */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ParentPetTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ParentPetTest.java index 226366f49666..02011765f760 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ParentPetTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ParentPetTest.java @@ -19,11 +19,11 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.GrandparentAnimal; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ParentPet */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java new file mode 100644 index 000000000000..7939998e1a2f --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java @@ -0,0 +1,92 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client.model; + +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.openapitools.client.model.Category; +import org.openapitools.client.model.Tag; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + + +/** + * Model tests for Pet + */ +public class PetTest { + private final Pet model = new Pet(); + + /** + * Model tests for Pet + */ + @Test + public void testPet() { + // TODO: test Pet + } + + /** + * Test the property 'id' + */ + @Test + public void idTest() { + // TODO: test id + } + + /** + * Test the property 'category' + */ + @Test + public void categoryTest() { + // TODO: test category + } + + /** + * Test the property 'name' + */ + @Test + public void nameTest() { + // TODO: test name + } + + /** + * Test the property 'photoUrls' + */ + @Test + public void photoUrlsTest() { + // TODO: test photoUrls + } + + /** + * Test the property 'tags' + */ + @Test + public void tagsTest() { + // TODO: test tags + } + + /** + * Test the property 'status' + */ + @Test + public void statusTest() { + // TODO: test status + } + +} diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetWithRequiredTagsTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetWithRequiredTagsTest.java index a338a337dc6d..e511e57ccd11 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetWithRequiredTagsTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetWithRequiredTagsTest.java @@ -20,13 +20,13 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.openapitools.client.model.Category; import org.openapitools.client.model.Tag; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for PetWithRequiredTags */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PigTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PigTest.java index 43341a064965..c9682283bf91 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PigTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PigTest.java @@ -19,12 +19,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.BasquePig; import org.openapitools.client.model.DanishPig; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Pig */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/QuadrilateralInterfaceTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/QuadrilateralInterfaceTest.java index 09636aa063b8..ef395cadb635 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/QuadrilateralInterfaceTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/QuadrilateralInterfaceTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for QuadrilateralInterface */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/QuadrilateralTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/QuadrilateralTest.java index 9615c3cddbee..ff4674d4cd38 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/QuadrilateralTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/QuadrilateralTest.java @@ -19,12 +19,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.ComplexQuadrilateral; import org.openapitools.client.model.SimpleQuadrilateral; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Quadrilateral */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ReadOnlyFirstTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ReadOnlyFirstTest.java index c4b3c2a8d09d..28bbe600c7f3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ReadOnlyFirstTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ReadOnlyFirstTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ReadOnlyFirst */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ScaleneTriangleTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ScaleneTriangleTest.java index eaa8c5949fb2..38716e473983 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ScaleneTriangleTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ScaleneTriangleTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ScaleneTriangle */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeInterfaceTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeInterfaceTest.java index 5ca1df738506..bd20c12251af 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeInterfaceTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeInterfaceTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ShapeInterface */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeOrNullTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeOrNullTest.java index c6897d03888f..0164b509cfd8 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeOrNullTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeOrNullTest.java @@ -19,12 +19,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.Quadrilateral; import org.openapitools.client.model.Triangle; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for ShapeOrNull */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeTest.java index 90dcd3533662..3343750c59c1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ShapeTest.java @@ -19,12 +19,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.Quadrilateral; import org.openapitools.client.model.Triangle; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Shape */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/SimpleQuadrilateralTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/SimpleQuadrilateralTest.java index 4479450f2a90..b794d1cf052c 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/SimpleQuadrilateralTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/SimpleQuadrilateralTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for SimpleQuadrilateral */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/SpecialModelNameTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/SpecialModelNameTest.java index 49c1845b64ca..a61cb4663f26 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/SpecialModelNameTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/SpecialModelNameTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for SpecialModelName */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TagTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TagTest.java index 6f38d0223841..4642d1e931d2 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TagTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TagTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Tag */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TriangleInterfaceTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TriangleInterfaceTest.java index 51c68d94db47..832f887bcf92 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TriangleInterfaceTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TriangleInterfaceTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for TriangleInterface */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TriangleTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TriangleTest.java index 92acf4e566cb..26267f88100a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TriangleTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/TriangleTest.java @@ -19,13 +19,13 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.client.model.EquilateralTriangle; import org.openapitools.client.model.IsoscelesTriangle; import org.openapitools.client.model.ScaleneTriangle; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Triangle */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/UserTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/UserTest.java index eea5bbb3866d..225980e83662 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/UserTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/UserTest.java @@ -19,11 +19,11 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.openapitools.jackson.nullable.JsonNullable; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for User */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/WhaleTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/WhaleTest.java index 97bcae4987b4..5ef53c4ee1c9 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/WhaleTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/WhaleTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Whale */ diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ZebraTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ZebraTest.java index 73aa9b2b4e7a..a893fca3fe31 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ZebraTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/ZebraTest.java @@ -19,10 +19,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.util.Arrays; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; + /** * Model tests for Zebra */