From 4f0e8a0845299e9ebca7fd0b0610f0d070b9d7ed Mon Sep 17 00:00:00 2001 From: Martin <2026226+martin-mfg@users.noreply.github.com> Date: Sun, 8 Dec 2024 21:23:58 +0100 Subject: [PATCH] add one sample to CircleCI, fix various Java tests --- CI/circle_parallel.sh | 1 + bin/utils/test_file_list.yaml | 6 ++--- .../org/openapitools/client/CustomTest.java | 22 +++++++--------- .../openapitools/client/api/AuthApiTest.java | 5 ++-- .../openapitools/client/ApiClientTest.java | 10 ++++--- .../org/openapitools/client/JSONTest.java | 9 ++++--- .../openapitools/client/api/PetApiTest.java | 5 ++-- .../client/auth/ApiKeyAuthTest.java | 26 +++++++++---------- .../client/auth/HttpBasicAuthTest.java | 11 ++++---- .../model/ArrayOfArrayOfNumberOnlyTest.java | 5 ++-- 10 files changed, 53 insertions(+), 47 deletions(-) diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh index 9d54203ba031..cc7e015f4c34 100755 --- a/CI/circle_parallel.sh +++ b/CI/circle_parallel.sh @@ -121,6 +121,7 @@ else (cd samples/client/others/java/okhttp-gson-streaming && mvn integration-test) (cd samples/client/petstore/java/okhttp-gson && mvn integration-test) (cd samples/client/petstore/java/okhttp-gson-3.1 && mvn integration-test) + (cd samples/client/petstore/java/okhttp-gson-dynamicOperations && mvn integration-test) (cd samples/client/petstore/java/resteasy && mvn integration-test) (cd samples/client/petstore/java-micronaut-client && mvn integration-test) (cd samples/client/petstore/java/apache-httpclient && mvn integration-test) diff --git a/bin/utils/test_file_list.yaml b/bin/utils/test_file_list.yaml index 77c439b0efe8..5c63f356e280 100644 --- a/bin/utils/test_file_list.yaml +++ b/bin/utils/test_file_list.yaml @@ -24,7 +24,7 @@ - filename: "samples/client/echo_api/java/resteasy/src/test/java/org/openapitools/client/api/BodyApiTest.java" sha256: 04715cabbe9bd27ff98dd56e3db489ebc9ffbf98d9af104a6707b0a40ab4f8fe - filename: "samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/api/AuthApiTest.java" - sha256: fa45f446111823f02b9c8e8d010e3c1a28fc0f00a325e674da14d0e12296ea96 + sha256: 38193bbad7f3eef087bc1474352e484178b14a2b8c0e0ba0cd4e4960516a14f9 - filename: "samples/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/api/PetApiTest.java" sha256: 24c6a39a9d7327d397dc038c368a19c84f14ed96a69fe28d53719b3eaf0a725c - filename: "samples/client/petstore/java/jersey3/src/test/java/org/openapitools/client/api/PetApiTest.java" @@ -36,9 +36,9 @@ - filename: "samples/client/petstore/java/okhttp-gson-3.1/src/test/java/org/openapitools/client/api/PetApiTest.java" sha256: d8f7fff724f81e666daf115cc25f8347e1fda4e861aa30df0dae3fa50c91404c - filename: "samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/api/PetApiTest.java" - sha256: 711a242b6257b87363c59b20dcaed45f9b146e2be246339a039a5d0338ad280c + sha256: 0cc079be64fe261b46f89976be2cbfad4fe5173dbe0d4b45303570299b0b5ecc - filename: "samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnlyTest.java" - sha256: 3a1add6f05f057c45b2ea489f619c3b455bf75e8e748fabd5487972b330ae2e6 + sha256: 3c41eb12d126f90392d97e3250b53ea9dce1663fb714a19339445b9da734d634 - filename: "samples/client/petstore/java/resteasy/src/test/java/org/openapitools/client/api/PetApiTest.java" sha256: 68ed9228c99ecf2ff3842074242d3be7565da3b702b7f46008a5e119ef15c167 - filename: "samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/test/java/org/openapitools/client/model/MySchemaNameCharactersTest.java" diff --git a/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/CustomTest.java b/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/CustomTest.java index fc98c24a1286..e23b3707c502 100644 --- a/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/CustomTest.java +++ b/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/CustomTest.java @@ -13,8 +13,8 @@ package org.openapitools.client; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.openapitools.client.api.BodyApi; import org.openapitools.client.api.QueryApi; import org.openapitools.client.model.Category; @@ -22,13 +22,11 @@ import java.util.Arrays; -import static org.junit.Assert.assertNotNull; - /** * API tests */ -public class CustomTest { +class CustomTest { private final QueryApi api = new QueryApi(); private final BodyApi bodyApi = new BodyApi(); @@ -40,22 +38,22 @@ public class CustomTest { * */ @Test - public void testEchoBodyPet() { + void testEchoBodyPet() { Pet pet = new Pet().id(12345L).name("Hello World"). photoUrls(Arrays.asList(new String[]{"http://a.com", "http://b.com"})).category(new Category().id(987L).name("new category")); Pet p = bodyApi.testEchoBodyPet(pet); - assertNotNull(p); - Assert.assertEquals("Hello World", p.getName()); - Assert.assertEquals(Long.valueOf(12345L), p.getId()); + Assertions.assertNotNull(p); + Assertions.assertEquals("Hello World", p.getName()); + Assertions.assertEquals(Long.valueOf(12345L), p.getId()); // response is empty body Pet p2 = bodyApi.testEchoBodyPet(null); - Assert.assertNull(p2); + Assertions.assertNull(p2); } @Test - public void testQueryParamsExploded_whenQueryParamIsNull() { - assertNotNull(api.testQueryStyleFormExplodeTrueObject(null)); + void testQueryParamsExploded_whenQueryParamIsNull() { + Assertions.assertNotNull(api.testQueryStyleFormExplodeTrueObject(null)); } } diff --git a/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/api/AuthApiTest.java b/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/api/AuthApiTest.java index cafc848c0a8c..ae4127e0b696 100644 --- a/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/api/AuthApiTest.java +++ b/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/api/AuthApiTest.java @@ -13,6 +13,7 @@ package org.openapitools.client.api; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.web.client.RestClientException; @@ -61,11 +62,11 @@ void testAuthHttpBearerTest() { String response; api.getApiClient().setBearerToken("fixed token"); response = api.testAuthHttpBearer(); - Assert.assertTrue(response.contains("Authorization: Bearer fixed token")); + Assertions.assertTrue(response.contains("Authorization: Bearer fixed token")); api.getApiClient().setBearerToken(() -> "dynamic token"); response = api.testAuthHttpBearer(); - Assert.assertTrue(response.contains("Authorization: Bearer dynamic token")); + Assertions.assertTrue(response.contains("Authorization: Bearer dynamic token")); } } diff --git a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/ApiClientTest.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/ApiClientTest.java index cee7d2db8d57..1cee2c7f930e 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/ApiClientTest.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/ApiClientTest.java @@ -17,7 +17,7 @@ public class ApiClientTest { ApiClient apiClient; JSON json; - @Before + @BeforeEach public void setup() { apiClient = new ApiClient(); json = apiClient.getJSON(); @@ -82,7 +82,7 @@ public void testSelectHeaderContentType() { assertEquals("text/plain", apiClient.selectHeaderContentType(contentTypes)); contentTypes = new String[]{}; - assertEquals("application/json", apiClient.selectHeaderContentType(contentTypes)); + assertNull(apiClient.selectHeaderContentType(contentTypes)); } @Test @@ -342,8 +342,10 @@ public void testNewHttpClient() { /** * Tests the invariant that the HttpClient for the ApiClient must never be null */ - @Test(expected = NullPointerException.class) + @Test public void testNullHttpClient() { - apiClient.setHttpClient(null); + assertThrows(NullPointerException.class, () -> { + apiClient.setHttpClient(null); + }); } } diff --git a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/JSONTest.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/JSONTest.java index 192c7e2b132d..af3a1c746984 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/JSONTest.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/JSONTest.java @@ -9,6 +9,9 @@ import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -27,7 +30,7 @@ public class JSONTest { private JSON json = null; private Order order = null; - @Before + @BeforeEach public void setup() { apiClient = new ApiClient(); json = apiClient.getJSON(); @@ -127,7 +130,7 @@ public void testLocalDateTypeAdapter() { public void testDefaultDate() throws Exception { final DateTimeFormatter datetimeFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME; final String dateStr = "2015-11-07T14:11:05.267Z"; - order.setShipDate(datetimeFormat.parse(dateStr, OffsetDateTime.FROM)); + order.setShipDate(datetimeFormat.parse(dateStr, OffsetDateTime::from)); String str = json.serialize(order); Type type = new TypeToken() { }.getType(); @@ -139,7 +142,7 @@ public void testDefaultDate() throws Exception { 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(datetimeFormat.parse(dateStr, OffsetDateTime.FROM)); + order.setShipDate(datetimeFormat.parse(dateStr, OffsetDateTime::from)); String str = json.serialize(order); Type type = new TypeToken() { }.getType(); diff --git a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/api/PetApiTest.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/api/PetApiTest.java index 2aa8a1881336..6590a3d91bfd 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/api/PetApiTest.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/api/PetApiTest.java @@ -50,7 +50,7 @@ public class PetApiTest { // 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"; - @Before + @BeforeEach public void setup() { // setup authentication ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key"); @@ -206,7 +206,8 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done) } while (result.isEmpty()); assertNotNull(exception); assertEquals(404, exception.getCode()); - assertEquals("Not Found", exception.getMessage()); + 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); } diff --git a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java index ed669e94797b..6975dcc92ecc 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/auth/ApiKeyAuthTest.java @@ -5,21 +5,21 @@ import java.util.Map; import java.util.List; +import org.openapitools.client.ApiException; import org.openapitools.client.Pair; import org.junit.jupiter.api.*; -import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.*; public class ApiKeyAuthTest { @Test - public void testApplyToParamsInQuery() { + 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); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); assertEquals(1, queryParams.size()); for (Pair queryParam : queryParams) { @@ -32,14 +32,14 @@ public void testApplyToParamsInQuery() { } @Test - public void testApplyToParamsInQueryWithNullValue() { + 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); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); // no changes to parameters assertEquals(0, queryParams.size()); @@ -48,7 +48,7 @@ public void testApplyToParamsInQueryWithNullValue() { } @Test - public void testApplyToParamsInHeaderWithPrefix() { + public void testApplyToParamsInHeaderWithPrefix() throws ApiException { List queryParams = new ArrayList(); Map headerParams = new HashMap(); Map cookieParams = new HashMap(); @@ -56,7 +56,7 @@ public void testApplyToParamsInHeaderWithPrefix() { ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN"); auth.setApiKey("my-api-token"); auth.setApiKeyPrefix("Token"); - auth.applyToParams(queryParams, headerParams, cookieParams); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); // no changes to query or cookie parameters assertEquals(0, queryParams.size()); @@ -66,7 +66,7 @@ public void testApplyToParamsInHeaderWithPrefix() { } @Test - public void testApplyToParamsInHeaderWithNullValue() { + public void testApplyToParamsInHeaderWithNullValue() throws ApiException { List queryParams = new ArrayList(); Map headerParams = new HashMap(); Map cookieParams = new HashMap(); @@ -74,7 +74,7 @@ public void testApplyToParamsInHeaderWithNullValue() { ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN"); auth.setApiKey(null); auth.setApiKeyPrefix("Token"); - auth.applyToParams(queryParams, headerParams, cookieParams); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); // no changes to parameters assertEquals(0, queryParams.size()); @@ -83,7 +83,7 @@ public void testApplyToParamsInHeaderWithNullValue() { } @Test - public void testApplyToParamsInCookieWithPrefix() { + public void testApplyToParamsInCookieWithPrefix() throws ApiException { List queryParams = new ArrayList(); Map headerParams = new HashMap(); Map cookieParams = new HashMap(); @@ -91,7 +91,7 @@ public void testApplyToParamsInCookieWithPrefix() { ApiKeyAuth auth = new ApiKeyAuth("cookie", "X-API-TOKEN"); auth.setApiKey("my-api-token"); auth.setApiKeyPrefix("Token"); - auth.applyToParams(queryParams, headerParams, cookieParams); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); // no changes to query or header parameters assertEquals(0, queryParams.size()); @@ -101,7 +101,7 @@ public void testApplyToParamsInCookieWithPrefix() { } @Test - public void testApplyToParamsInCookieWithNullValue() { + public void testApplyToParamsInCookieWithNullValue() throws ApiException { List queryParams = new ArrayList(); Map headerParams = new HashMap(); Map cookieParams = new HashMap(); @@ -109,7 +109,7 @@ public void testApplyToParamsInCookieWithNullValue() { ApiKeyAuth auth = new ApiKeyAuth("cookie", "X-API-TOKEN"); auth.setApiKey(null); auth.setApiKeyPrefix("Token"); - auth.applyToParams(queryParams, headerParams, cookieParams); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); // no changes to parameters assertEquals(0, queryParams.size()); diff --git a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java index 154dc61b352c..a09d0b869584 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/auth/HttpBasicAuthTest.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.List; +import org.openapitools.client.ApiException; import org.openapitools.client.Pair; import org.junit.jupiter.api.*; @@ -19,14 +20,14 @@ public void setup() { } @Test - public void testApplyToParams() { + 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); + auth.applyToParams(queryParams, headerParams, cookieParams, null, null, null); // no changes to query or cookie parameters assertEquals(0, queryParams.size()); @@ -38,7 +39,7 @@ public void testApplyToParams() { // null username should be treated as empty string auth.setUsername(null); - auth.applyToParams(queryParams, headerParams, cookieParams); + 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")); @@ -46,7 +47,7 @@ public void testApplyToParams() { // null password should be treated as empty string auth.setUsername("my-username"); auth.setPassword(null); - auth.applyToParams(queryParams, headerParams, cookieParams); + 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")); @@ -56,7 +57,7 @@ public void testApplyToParams() { headerParams = new HashMap(); auth.setUsername(null); auth.setPassword(null); - auth.applyToParams(queryParams, headerParams, cookieParams); + 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-dynamicOperations/src/test/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnlyTest.java b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnlyTest.java index dc2a20f163d4..df7aa2de613e 100644 --- a/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnlyTest.java +++ b/samples/client/petstore/java/okhttp-gson-dynamicOperations/src/test/java/org/openapitools/client/model/ArrayOfArrayOfNumberOnlyTest.java @@ -19,13 +19,12 @@ import com.google.gson.annotations.SerializedName; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -67,7 +66,7 @@ public void arrayArrayNumberTest() { model2.setArrayArrayNumber(new ArrayList>()); model2.getArrayArrayNumber().add(arrayArrayNumber2); - Assert.assertTrue(model2.equals(model)); + Assertions.assertTrue(model2.equals(model)); } }