[JAVA][KOTLIN][SPRING] upgrade dependencies (#16759)

* upgrade spring-boot-starter-parent

* upgrade springdoc and swagger-ui

* upgrade v3 swagger-annotations

* generate samples

* upgrade jackson

* fix spring cloud, remove temp comment

Putting "8" instead of "1.8" should be ok, because Spring Boot 3 requires Java 17 anyway, so it should be able to understand that 8 is the same as 1.8.

* generate samples

* upgrade JUnit 5, remove commons-io dependency, remove outdated samples/client/petstore/java/feign/feign10x/ files, generate samples

commons-io dependency was introduced in https://github.com/OpenAPITools/openapi-generator/pull/8484, but I don't see why it would be needed now or back then.

* update gson, generate samples

* update logback

* update feign

* update scribejava

* generate samples

* update httpmime

* okhttp-gson: update commons-lang & okhttp & junit-platform, remove mockito; generate samples

It seems Mockito is not used at all there.

* okhttp-gson: remove unnecessary sample files, generate sample files

* upgrade google-api-client & jersey-common, restore ClientTest, generate samples

* misc. upgrades in jersey2 and jersey3

jersey 3.1.3 is available already, but IntelliJ reports security problems in 3.1.3 and 3.1.2, so I used 3.1.1 instead.

* align some gradle&sbt files with poms, generate samples

* whitespace fix
This commit is contained in:
martin-mfg
2023-10-09 08:55:32 +02:00
committed by GitHub
parent 48f454cf72
commit e3db882ed4
468 changed files with 970 additions and 21758 deletions

View File

@@ -1,105 +0,0 @@
/*
* 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 java.util.Objects;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* CatAllOf
*/
@JsonPropertyOrder({
CatAllOf.JSON_PROPERTY_DECLAWED
})
@JsonTypeName("Cat_allOf")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class CatAllOf {
public static final String JSON_PROPERTY_DECLAWED = "declawed";
private Boolean declawed;
public CatAllOf() {
}
public CatAllOf declawed(Boolean declawed) {
this.declawed = declawed;
return this;
}
/**
* Get declawed
* @return declawed
**/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_DECLAWED)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public Boolean isDeclawed() {
return declawed;
}
@JsonProperty(JSON_PROPERTY_DECLAWED)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setDeclawed(Boolean declawed) {
this.declawed = declawed;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CatAllOf catAllOf = (CatAllOf) o;
return Objects.equals(this.declawed, catAllOf.declawed);
}
@Override
public int hashCode() {
return Objects.hash(declawed);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CatAllOf {\n");
sb.append(" declawed: ").append(toIndentedString(declawed)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@@ -1,105 +0,0 @@
/*
* 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 java.util.Objects;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* DogAllOf
*/
@JsonPropertyOrder({
DogAllOf.JSON_PROPERTY_BREED
})
@JsonTypeName("Dog_allOf")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class DogAllOf {
public static final String JSON_PROPERTY_BREED = "breed";
private String breed;
public DogAllOf() {
}
public DogAllOf breed(String breed) {
this.breed = breed;
return this;
}
/**
* Get breed
* @return breed
**/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_BREED)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public String getBreed() {
return breed;
}
@JsonProperty(JSON_PROPERTY_BREED)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setBreed(String breed) {
this.breed = breed;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DogAllOf dogAllOf = (DogAllOf) o;
return Objects.equals(this.breed, dogAllOf.breed);
}
@Override
public int hashCode() {
return Objects.hash(breed);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class DogAllOf {\n");
sb.append(" breed: ").append(toIndentedString(breed)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@@ -1,9 +1,16 @@
package org.openapitools.client.api;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.model.Client;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for AnotherFakeApi
@@ -13,7 +20,7 @@ class AnotherFakeApiTest {
private AnotherFakeApi api;
@BeforeEach
void setup() {
public void setup() {
api = new ApiClient().buildClient(AnotherFakeApi.class);
}
@@ -25,8 +32,8 @@ class AnotherFakeApiTest {
*/
@Test
void call123testSpecialTagsTest() {
Client body = null;
// Client response = api.call123testSpecialTags(body);
Client client = null;
// Client response = api.call123testSpecialTags(client);
// TODO: test validations
}

View File

@@ -1,110 +0,0 @@
package org.openapitools.client.api;
import com.github.tomakehurst.wiremock.WireMockServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.auth.ApiKeyAuth;
import java.util.Map;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class ApiKeyAuthTest {
private static StoreApi api;
private static WireMockServer wm = new WireMockServer(options().dynamicPort());
@BeforeAll
static void setup() {
wm.start();
}
@AfterAll
static void shutdown() {
wm.shutdown();
}
@Test
void keyInQueryParameter() {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
ApiKeyAuth apiKeyAuth = new ApiKeyAuth("query", "api_key");
apiClient.addAuthorization("api_key", apiKeyAuth);
apiClient.setApiKey("MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3");
api = apiClient.buildClient(StoreApi.class);
wm.stubFor(get(urlPathEqualTo("/store/inventory"))
.withQueryParam("api_key", equalTo("MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"))
.withHeader("Accept", equalTo("application/json"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
}
@Test
void keyInHeader() {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
ApiKeyAuth apiKeyAuth = new ApiKeyAuth("header", "api_key");
apiClient.addAuthorization("api_key", apiKeyAuth);
apiClient.setApiKey("MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3");
api = apiClient.buildClient(StoreApi.class);
wm.stubFor(get(urlEqualTo("/store/inventory"))
.withHeader("Accept", equalTo("application/json"))
.withHeader("api_key", equalTo("MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
}
@Test
void keyInCookie() {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
ApiKeyAuth apiKeyAuth = new ApiKeyAuth("cookie", "api_key");
apiClient.addAuthorization("api_key", apiKeyAuth);
apiClient.setApiKey("MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3");
api = apiClient.buildClient(StoreApi.class);
wm.stubFor(get(urlEqualTo("/store/inventory"))
.withHeader("Accept", equalTo("application/json"))
.withCookie("api_key", equalTo("MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
}
}

View File

@@ -2,7 +2,10 @@ package org.openapitools.client.api;
import org.openapitools.client.ApiClient;
import java.math.BigDecimal;
import org.openapitools.client.model.ChildWithNullable;
import org.openapitools.client.model.Client;
import org.openapitools.client.model.EnumClass;
import org.openapitools.client.model.FakeBigDecimalMap200Response;
import java.io.File;
import org.openapitools.client.model.FileSchemaTestClass;
import org.openapitools.client.model.HealthCheckResult;
@@ -15,6 +18,8 @@ import org.openapitools.client.model.User;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -33,6 +38,19 @@ class FakeApiTest {
}
/**
*
*
* for Java apache and Java native, test toUrlQueryString for maps with BegDecimal keys
*/
@Test
void fakeBigDecimalMapTest() {
// FakeBigDecimalMap200Response response = api.fakeBigDecimalMap();
// TODO: test validations
}
/**
* Health check endpoint
*
@@ -264,9 +282,10 @@ class FakeApiTest {
String enumQueryString = null;
Integer enumQueryInteger = null;
Double enumQueryDouble = null;
List<EnumClass> enumQueryModelArray = null;
List<String> enumFormStringArray = null;
String enumFormString = null;
// api.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString);
// api.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString);
// TODO: test validations
}
@@ -289,7 +308,8 @@ class FakeApiTest {
.enumQueryStringArray(null)
.enumQueryString(null)
.enumQueryInteger(null)
.enumQueryDouble(null);
.enumQueryDouble(null)
.enumQueryModelArray(null);
// api.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumFormStringArray, enumFormString, queryParams);
// TODO: test validations
@@ -364,6 +384,20 @@ class FakeApiTest {
}
/**
* test nullable parent property
*
*
*/
@Test
void testNullableTest() {
ChildWithNullable childWithNullable = null;
// api.testNullable(childWithNullable);
// TODO: test validations
}
/**
*
*

View File

@@ -1,66 +1,42 @@
package org.openapitools.client.api;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.model.Client;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for FakeClassnameTags123Api
*/
class FakeClassnameTags123ApiTest {
private static WireMockServer wm = new WireMockServer(options().dynamicPort().notifier(new Slf4jNotifier(true)));
private FakeClassnameTags123Api api;
private FakeClassnameTags123Api api;
@BeforeEach
public void setup() {
api = new ApiClient().buildClient(FakeClassnameTags123Api.class);
}
@BeforeAll
static void startWireMock() {
wm.start();
}
@AfterAll
static void stopWireMock() {
wm.shutdown();
}
@BeforeEach
void setUp() {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
api = apiClient.buildClient(FakeClassnameTags123Api.class);
}
/**
* To test class name in snake case
* <p>
* To test class name in snake case
*/
@Test
void testClassnameTest() {
String responseBody = "{\n" +
" \"client\":\"Bruce\"\n" +
"}";
wm.stubFor(patch(urlEqualTo("/fake_classname_test"))
.withHeader("Content-Type", equalTo("application/json"))
.withHeader("Accept", equalTo("application/json"))
.willReturn(ok(responseBody)));
Client client = new Client();
client.setClient("Bruce");
Client response = api.testClassname(client);
assertThat(response, is(client));
}
/**
* To test class name in snake case
*
* To test class name in snake case
*/
@Test
void testClassnameTest() {
Client client = null;
// Client response = api.testClassname(client);
// TODO: test validations
}
}

View File

@@ -1,58 +0,0 @@
package org.openapitools.client.api;
import com.github.tomakehurst.wiremock.WireMockServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.auth.HttpBasicAuth;
import java.util.Map;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class HttpBasicAuthTest {
private static StoreApi api;
private static WireMockServer wm = new WireMockServer(options().dynamicPort());
@BeforeAll
static void setup() {
wm.start();
}
@AfterAll
static void shutdown() {
wm.shutdown();
}
@Test
void httpBasicAuth() {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
HttpBasicAuth httpBasicAuth = new HttpBasicAuth();
apiClient.addAuthorization("basic", httpBasicAuth);
apiClient.setCredentials("username", "password");
api = apiClient.buildClient(StoreApi.class);
wm.stubFor(get(urlPathEqualTo("/store/inventory"))
.withHeader("Authorization", equalTo("Basic dXNlcm5hbWU6cGFzc3dvcmQ="))
.withHeader("Accept", equalTo("application/json"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
}
}

View File

@@ -1,58 +0,0 @@
package org.openapitools.client.api;
import com.github.tomakehurst.wiremock.WireMockServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.auth.HttpBearerAuth;
import java.util.Map;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class HttpBearerAuthTest {
private static StoreApi api;
private static WireMockServer wm = new WireMockServer(options().dynamicPort());
@BeforeAll
static void setup() {
wm.start();
}
@AfterAll
static void shutdown() {
wm.shutdown();
}
@Test
void httpBearer() {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
HttpBearerAuth httpBearerAuth = new HttpBearerAuth("Bearer");
apiClient.addAuthorization("bearer", httpBearerAuth);
apiClient.setBearerToken("MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3");
api = apiClient.buildClient(StoreApi.class);
wm.stubFor(get(urlPathEqualTo("/store/inventory"))
.withHeader("Authorization", equalTo("Bearer MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"))
.withHeader("Accept", equalTo("application/json"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
}
}

View File

@@ -1,72 +0,0 @@
package org.openapitools.client.api;
import com.github.tomakehurst.wiremock.WireMockServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.auth.OauthClientCredentialsGrant;
import java.util.Map;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class OauthClientCredentialsGrantTest {
private static StoreApi api;
private static WireMockServer wm = new WireMockServer(options().dynamicPort());
@BeforeAll
static void setup() {
wm.start();
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
OauthClientCredentialsGrant oauthClientCredentialsGrant = new OauthClientCredentialsGrant(wm.baseUrl() + "/auth", wm.baseUrl() + "/token", "read");
oauthClientCredentialsGrant.configure("client_id", "client_secret");
apiClient.addAuthorization("oauth", oauthClientCredentialsGrant);
api = apiClient.buildClient(StoreApi.class);
}
@AfterAll
static void shutdown() {
wm.shutdown();
}
@Test
void oauthClientCredentialsTest() {
wm.stubFor(post(urlEqualTo("/token"))
.withRequestBody(equalTo("client_id=client_id&client_secret=client_secret&scope=read&grant_type=client_credentials"))
.willReturn(ok("{\n" +
" \"access_token\":\"MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3\",\n" +
" \"token_type\":\"bearer\",\n" +
" \"expires_in\":3600,\n" +
" \"refresh_token\":\"IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk\",\n" +
" \"scope\":\"read\"\n" +
"}")));
wm.stubFor(get(urlEqualTo("/store/inventory"))
.withHeader("Accept", equalTo("application/json"))
.withHeader("Authorization", equalTo("Bearer MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
wm.verify(exactly(1), getRequestedFor(urlEqualTo("/store/inventory")));
wm.verify(exactly(1), postRequestedFor(urlEqualTo("/token")));
assertThat(wm.getAllServeEvents().size(), is(2));
}
}

View File

@@ -1,71 +0,0 @@
package org.openapitools.client.api;
import com.github.tomakehurst.wiremock.WireMockServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.auth.OauthPasswordGrant;
import java.util.Map;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class OauthPasswordGrantTest {
private static StoreApi api;
private static WireMockServer wm = new WireMockServer(options().dynamicPort());
@BeforeAll
static void setup() {
wm.start();
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
OauthPasswordGrant oauthPasswordGrant = new OauthPasswordGrant(wm.baseUrl() + "/token", "read");
oauthPasswordGrant.configure("username", "password", "client_id", "client_secret");
apiClient.addAuthorization("oauth", oauthPasswordGrant);
api = apiClient.buildClient(StoreApi.class);
}
@AfterAll
static void shutdown() {
wm.shutdown();
}
@Test
void oauthPasswordGrant() {
wm.stubFor(post(urlEqualTo("/token"))
.withRequestBody(equalTo("username=username&password=password&scope=read&grant_type=password&client_id=client_id&client_secret=client_secret"))
.willReturn(ok("{\n" +
" \"access_token\":\"MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3\",\n" +
" \"token_type\":\"bearer\",\n" +
" \"expires_in\":3600,\n" +
" \"refresh_token\":\"IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk\",\n" +
" \"scope\":\"read\"\n" +
"}")));
wm.stubFor(get(urlEqualTo("/store/inventory"))
.withHeader("Accept", equalTo("application/json"))
.withHeader("Authorization", equalTo("Bearer MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
wm.verify(exactly(1), getRequestedFor(urlEqualTo("/store/inventory")));
wm.verify(exactly(1), postRequestedFor(urlEqualTo("/token")));
}
}

View File

@@ -1,160 +0,0 @@
package org.openapitools.client.api;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.stubbing.Scenario;
import feign.FeignException;
import feign.RetryableException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.auth.OauthClientCredentialsGrant;
import java.util.Map;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class OauthRetryAuthErrorsTest {
private static StoreApi api;
private WireMockServer wm = new WireMockServer(options().dynamicPort());
@BeforeEach
void setup() {
wm.start();
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
OauthClientCredentialsGrant oauthClientCredentialsGrant = new OauthClientCredentialsGrant(null, wm.baseUrl() + "/token", "read");
oauthClientCredentialsGrant.configure("client_id", "client_secret");
apiClient.addAuthorization("oauth", oauthClientCredentialsGrant);
api = apiClient.buildClient(StoreApi.class);
}
@AfterEach
void shutdown() {
wm.shutdown();
}
@Test
void retryableAuthenticationException() {
//First request to fetch the token returns an already expired token
//Just to mock the scenario where already have a token in memory but it expires before the request reaches the server
wm.stubFor(post(urlEqualTo("/token"))
.withRequestBody(equalTo("client_id=client_id&client_secret=client_secret&scope=read&grant_type=client_credentials"))
.inScenario("Retry token")
.whenScenarioStateIs(Scenario.STARTED)
.willReturn(ok("{\n" +
" \"access_token\":\"EXPIRED_TOKEN\",\n" +
" \"token_type\":\"bearer\",\n" +
" \"expires_in\":0,\n" +
" \"refresh_token\":\"IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk\",\n" +
" \"scope\":\"read\"\n" +
"}")));
//This token request will be triggered by the RetryableException
wm.stubFor(post(urlEqualTo("/token"))
.withRequestBody(equalTo("client_id=client_id&client_secret=client_secret&scope=read&grant_type=client_credentials"))
.inScenario("Retry token")
.whenScenarioStateIs("After fetching new token")
.willReturn(ok("{\n" +
" \"access_token\":\"MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3\",\n" +
" \"token_type\":\"bearer\",\n" +
" \"expires_in\":3600,\n" +
" \"refresh_token\":\"IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk\",\n" +
" \"scope\":\"read\"\n" +
"}")));
//First request will fail with a 401
//Simulates a token that expired before reaching the server
wm.stubFor(get(urlEqualTo("/store/inventory"))
.inScenario("Retry token")
.whenScenarioStateIs(Scenario.STARTED)
.willSetStateTo("After fetching new token")
.withHeader("Accept", equalTo("application/json"))
.withHeader("Authorization", equalTo("Bearer EXPIRED_TOKEN"))
.willReturn(aResponse().withStatus(401)));
//The second request sends a newly generated token
wm.stubFor(get(urlEqualTo("/store/inventory"))
.inScenario("Retry token")
.whenScenarioStateIs("After fetching new token")
.withHeader("Accept", equalTo("application/json"))
.withHeader("Authorization", equalTo("Bearer MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
wm.verify(exactly(2), getRequestedFor(urlEqualTo("/store/inventory")));
wm.verify(exactly(2), postRequestedFor(urlEqualTo("/token")));
}
@Test
void retryableAuthenticationExhaustedRetries() {
//First request to fetch the token returns an already expired token
//Just to mock the scenario where already have a token in memory but it expires before the request reaches the server
wm.stubFor(post(urlEqualTo("/token"))
.withRequestBody(equalTo("client_id=client_id&client_secret=client_secret&scope=read&grant_type=client_credentials"))
.inScenario("Retry token")
.whenScenarioStateIs(Scenario.STARTED)
.willReturn(ok("{\n" +
" \"access_token\":\"EXPIRED_TOKEN\",\n" +
" \"token_type\":\"bearer\",\n" +
" \"expires_in\":0,\n" +
" \"refresh_token\":\"IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk\",\n" +
" \"scope\":\"read\"\n" +
"}")));
//This token request will be triggered by the RetryableException
wm.stubFor(post(urlEqualTo("/token"))
.withRequestBody(equalTo("client_id=client_id&client_secret=client_secret&scope=read&grant_type=client_credentials"))
.inScenario("Retry token")
.whenScenarioStateIs("After fetching new token")
.willReturn(ok("{\n" +
" \"access_token\":\"MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3\",\n" +
" \"token_type\":\"bearer\",\n" +
" \"expires_in\":3600,\n" +
" \"refresh_token\":\"IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk\",\n" +
" \"scope\":\"read\"\n" +
"}")));
//First request will fail with a 401
//Simulates a token that expired before reaching the server
wm.stubFor(get(urlEqualTo("/store/inventory"))
.inScenario("Retry token")
.whenScenarioStateIs(Scenario.STARTED)
.willSetStateTo("After fetching new token")
.withHeader("Accept", equalTo("application/json"))
.withHeader("Authorization", equalTo("Bearer EXPIRED_TOKEN"))
.willReturn(aResponse().withStatus(401)));
//Second request also fails with a 401, in this case the 401 is not related with an expired token
wm.stubFor(get(urlEqualTo("/store/inventory"))
.inScenario("Retry token")
.whenScenarioStateIs("After fetching new token")
.withHeader("Accept", equalTo("application/json"))
.withHeader("Authorization", equalTo("Bearer MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"))
.willReturn(aResponse().withStatus(401)));
RetryableException retryableException = assertThrows(RetryableException.class, () -> api.getInventory());
assertThat(retryableException.getCause(), is(instanceOf(FeignException.Unauthorized.class)));
wm.verify(exactly(2), getRequestedFor(urlEqualTo("/store/inventory")));
wm.verify(exactly(2), postRequestedFor(urlEqualTo("/token")));
}
}

View File

@@ -1,210 +1,196 @@
package org.openapitools.client.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder;
import com.google.common.collect.Sets;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.model.Pet;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.openapitools.client.model.ModelApiResponse;
import org.openapitools.client.model.Pet;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for PetAp
* API tests for PetApi
*/
class PetApiTest {
private static PetApi api;
private PetApi api;
private static WireMockServer wm = new WireMockServer(options().dynamicPort());
private static String petJson;
private static String petListJson;
@BeforeEach
public void setup() {
api = new ApiClient().buildClient(PetApi.class);
}
private ObjectMapper objectMapper = new ObjectMapper();
/**
* Add a new pet to the store
*
*
*/
@Test
void addPetTest() {
Pet pet = null;
// api.addPet(pet);
@BeforeAll
static void setup() throws IOException {
wm.start();
// TODO: test validations
}
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
api = apiClient.buildClient(PetApi.class);
/**
* Deletes a pet
*
*
*/
@Test
void deletePetTest() {
Long petId = null;
String apiKey = null;
// api.deletePet(petId, apiKey);
petJson = IOUtils.toString(PetApiTest.class.getResourceAsStream("/pet.json"), "UTF-8");
petListJson = IOUtils.toString(PetApiTest.class.getResourceAsStream("/pet_list.json"), "UTF-8");
}
// TODO: test validations
}
@AfterAll
static void shutdown() {
wm.shutdown();
}
/**
* Finds Pets by status
*
* Multiple status values can be provided with comma separated strings
*/
@Test
void findPetsByStatusTest() {
List<String> status = null;
// List<Pet> response = api.findPetsByStatus(status);
@Test
void addPet() throws JsonProcessingException {
wm.stubFor(post(urlEqualTo("/pet"))
.willReturn(aResponse().withBody(petJson)));
// TODO: test validations
}
Pet pet = objectMapper.readValue(petJson, Pet.class);
/**
* Finds Pets by status
*
* Multiple status values can be provided with comma separated strings
*
* This tests the overload of the method that uses a Map for query parameters instead of
* listing them out individually.
*/
@Test
void findPetsByStatusTestQueryMap() {
PetApi.FindPetsByStatusQueryParams queryParams = new PetApi.FindPetsByStatusQueryParams()
.status(null);
// List<Pet> response = api.findPetsByStatus(queryParams);
api.addPet(pet);
// TODO: test validations
}
/**
* Finds Pets by tags
*
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*/
@Test
void findPetsByTagsTest() {
Set<String> tags = null;
// Set<Pet> response = api.findPetsByTags(tags);
wm.verify(postRequestedFor(urlEqualTo("/pet"))
.withHeader("Content-Type", equalTo("application/json"))
.withHeader("Accept", equalTo("application/json"))
.withRequestBody(equalToJson(petJson)));
}
// TODO: test validations
}
@Test
void deletedPet() {
wm.stubFor(delete(urlEqualTo("/pet/85"))
.willReturn(aResponse()));
/**
* Finds Pets by tags
*
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*
* This tests the overload of the method that uses a Map for query parameters instead of
* listing them out individually.
*/
@Test
void findPetsByTagsTestQueryMap() {
PetApi.FindPetsByTagsQueryParams queryParams = new PetApi.FindPetsByTagsQueryParams()
.tags(null);
// Set<Pet> response = api.findPetsByTags(queryParams);
api.deletePet(85L, "API_KEY");
// TODO: test validations
}
/**
* Find pet by ID
*
* Returns a single pet
*/
@Test
void getPetByIdTest() {
Long petId = null;
// Pet response = api.getPetById(petId);
wm.verify(deleteRequestedFor(urlEqualTo("/pet/85"))
.withHeader("api_key", equalTo("API_KEY"))
.withHeader("Accept", equalTo("application/json")));
}
// TODO: test validations
}
@Test
void findPetsByStatus() {
wm.stubFor(get(urlEqualTo("/pet/findByStatus?status=available&status=sold"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(petListJson)));
/**
* Update an existing pet
*
*
*/
@Test
void updatePetTest() {
Pet pet = null;
// api.updatePet(pet);
List<Pet> petList = api.findPetsByStatus(Arrays.asList("available", "sold"));
assertThat(petList.size(), is(2));
// TODO: test validations
}
validatePet1(petList.get(0));
validatePet2(petList.get(1));
}
/**
* Updates a pet in the store with form data
*
*
*/
@Test
void updatePetWithFormTest() {
Long petId = null;
String name = null;
String status = null;
// api.updatePetWithForm(petId, name, status);
@Test
void findPetsByStatusQueryMap() {
wm.stubFor(get(urlEqualTo("/pet/findByStatus?status=available,sold"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(petListJson)));
// TODO: test validations
}
PetApi.FindPetsByStatusQueryParams findPetsByStatusQueryParams = new PetApi.FindPetsByStatusQueryParams();
findPetsByStatusQueryParams.status(Arrays.asList("available", "sold"));
/**
* uploads an image
*
*
*/
@Test
void uploadFileTest() {
Long petId = null;
String additionalMetadata = null;
File file = null;
// ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file);
List<Pet> petList = api.findPetsByStatus(findPetsByStatusQueryParams);
assertThat(petList.size(), is(2));
// TODO: test validations
}
validatePet1(petList.get(0));
validatePet2(petList.get(1));
}
/**
* uploads an image (required)
*
*
*/
@Test
void uploadFileWithRequiredFileTest() {
Long petId = null;
File requiredFile = null;
String additionalMetadata = null;
// ModelApiResponse response = api.uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata);
@Test
void findPetsByTags() {
wm.stubFor(get(urlEqualTo("/pet/findByTags?tags=tag1&tags=tag2"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(petListJson)));
// TODO: test validations
}
Set<Pet> petList = api.findPetsByTags(Sets.newHashSet("tag1", "tag2"));
assertThat(petList.size(), is(2));
}
@Test
void getPetById() {
wm.stubFor(get(urlEqualTo("/pet/85"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(petJson)));
Pet pet = api.getPetById(85L);
validatePet1(pet);
}
@Test
void updatePet() throws JsonProcessingException {
wm.stubFor(put(urlEqualTo("/pet"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(petJson)));
Pet pet = objectMapper.readValue(petJson, Pet.class);
api.updatePet(pet);
wm.verify(putRequestedFor(urlEqualTo("/pet"))
.withHeader("Accept", equalTo("application/json"))
.withHeader("Content-Type", equalTo("application/json"))
.withRequestBody(equalToJson(petJson)));
}
@Test
void updatePetWithForm() {
wm.stubFor(post(anyUrl()).willReturn(aResponse()));
api.updatePetWithForm(85L, "Rex", "sold");
wm.verify(postRequestedFor(urlEqualTo("/pet/85"))
.withHeader("Accept", equalTo("application/json"))
.withHeader("Content-Type", containing("application/x-www-form-urlencoded"))
.withRequestBody(containing("name=Rex"))
.withRequestBody(containing("status=sold")));
}
@Test
void uploadFile() throws IOException {
wm.stubFor(post("/pet/85/uploadImage").willReturn(aResponse()));
File file = File.createTempFile("test", ".tmp");
IOUtils.write("ABCD".getBytes(), new FileOutputStream(file));
api.uploadFile(85L, "metadata", file);
wm.verify(postRequestedFor(urlEqualTo("/pet/85/uploadImage"))
.withHeader("Content-Type", containing("multipart/form-data"))
.withHeader("Accept", containing("application/json"))
.withRequestBodyPart(new MultipartValuePatternBuilder()
.withName("additionalMetadata").build())
.withRequestBodyPart(new MultipartValuePatternBuilder()
.withName("file").withBody(binaryEqualTo("ABCD".getBytes())).build())
);
}
private void validatePet1(Pet pet) {
assertThat(pet.getId(), is(85L));
assertThat(pet.getCategory().getName(), is("Dogs"));
assertThat(pet.getCategory().getId(), is(1L));
assertThat(pet.getName(), is("LvRcat"));
assertThat(pet.getPhotoUrls().size(), is(1));
assertThat(pet.getPhotoUrls().stream().findAny().get(), is("string"));
assertThat(pet.getTags().size(), is(1));
assertThat(pet.getTags().get(0).getId(), is(10L));
assertThat(pet.getTags().get(0).getName(), is("tag"));
assertThat(pet.getStatus(), is(Pet.StatusEnum.AVAILABLE));
}
private void validatePet2(Pet pet) {
assertThat(pet.getId(), is(42L));
assertThat(pet.getCategory().getName(), is("Dogs"));
assertThat(pet.getCategory().getId(), is(1L));
assertThat(pet.getName(), is("Louise"));
assertThat(pet.getPhotoUrls().size(), is(1));
assertThat(pet.getPhotoUrls().stream().findAny().get(), is("photo"));
assertThat(pet.getTags().size(), is(1));
assertThat(pet.getTags().get(0).getId(), is(0L));
assertThat(pet.getTags().get(0).getName(), is("obedient"));
assertThat(pet.getStatus(), is(Pet.StatusEnum.SOLD));
}
}

View File

@@ -1,153 +1,83 @@
package org.openapitools.client.api;
import com.github.tomakehurst.wiremock.WireMockServer;
import feign.FeignException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import org.openapitools.client.model.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* API tests for StoreApi
*/
public class StoreApiTest {
class StoreApiTest {
private static StoreApi api;
private StoreApi api;
private static WireMockServer wm = new WireMockServer(options().dynamicPort());
@BeforeEach
public void setup() {
api = new ApiClient().buildClient(StoreApi.class);
}
@BeforeAll
static void setup() {
wm.start();
/**
* Delete purchase order by ID
*
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
*/
@Test
void deleteOrderTest() {
String orderId = null;
// api.deleteOrder(orderId);
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(wm.baseUrl());
api = apiClient.buildClient(StoreApi.class);
// TODO: test validations
}
}
/**
* Returns pet inventories by status
*
* Returns a map of status codes to quantities
*/
@Test
void getInventoryTest() {
// Map<String, Integer> response = api.getInventory();
@AfterAll
static void shutdown() {
wm.shutdown();
}
// TODO: test validations
}
/**
* Find purchase order by ID
*
* For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generate exceptions
*/
@Test
void getOrderByIdTest() {
Long orderId = null;
// Order response = api.getOrderById(orderId);
/**
* Delete purchase order by ID
* <p>
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
*/
@Test
void deleteOrderTest() {
wm.stubFor(delete(urlEqualTo("/store/order/1234"))
.withHeader("Accept", equalTo("application/json"))
.willReturn(ok()));
// TODO: test validations
}
api.deleteOrder("1234");
}
/**
* Place an order for a pet
*
*
*/
@Test
void placeOrderTest() {
Order order = null;
// Order response = api.placeOrder(order);
@Test
void deleteOrderTestInvalid() {
wm.stubFor(delete(urlEqualTo("/store/order/abc"))
.withHeader("Accept", equalTo("application/json"))
.willReturn(aResponse().withStatus(400)));
assertThrows(FeignException.BadRequest.class, () -> api.deleteOrder("abc"));
}
/**
* Returns pet inventories by status
* <p>
* Returns a map of status codes to quantities
*/
@Test
void getInventoryTest() {
wm.stubFor(get(urlEqualTo("/store/inventory"))
.withHeader("Accept", equalTo("application/json"))
.willReturn(ok("{\n" +
" \"prop1\": 1,\n" +
" \"prop2\": 2\n" +
"}")));
Map<String, Integer> inventory = api.getInventory();
assertThat(inventory.keySet().size(), is(2));
assertThat(inventory.get("prop1"), is(1));
assertThat(inventory.get("prop2"), is(2));
}
/**
* Find purchase order by ID
* <p>
* For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generate exceptions
*/
@Test
void getOrderByIdTest() {
String responseBody = "{\n" +
" \"id\": 1,\n" +
" \"petId\": 1,\n" +
" \"quantity\": 10,\n" +
" \"shipDate\": \"2120-03-23T01:23:44.000000009+0000\",\n" +
" \"status\": \"placed\",\n" +
" \"complete\": true\n" +
"}";
wm.stubFor(get(urlEqualTo("/store/order/123"))
.withHeader("Accept", equalTo("application/json"))
.willReturn(ok(responseBody)));
Order order = api.getOrderById(123L);
assertThat(order.getId(), is(1L));
assertThat(order.getPetId(), is(1L));
assertThat(order.getQuantity(), is(10));
assertThat(order.getShipDate(), is(OffsetDateTime.of(2120, 03, 23, 01, 23, 44, 9, ZoneOffset.UTC)));
assertThat(order.getStatus(), is(Order.StatusEnum.PLACED));
assertThat(order.isComplete(), is(true));
}
/**
* Place an order for a pet
*/
@Test
void placeOrderTest() {
String responseBody = "{\n" +
" \"id\": 1,\n" +
" \"petId\": 1,\n" +
" \"quantity\": 10,\n" +
" \"shipDate\": \"2120-03-23T01:23:44.000000009+0000\",\n" +
" \"status\": \"placed\",\n" +
" \"complete\": true\n" +
"}";
Order newOrder = new Order();
newOrder.setId(1L);
newOrder.setPetId(1L);
newOrder.setQuantity(10);
newOrder.shipDate(OffsetDateTime.of(2120, 03, 23, 01, 23, 44, 9, ZoneOffset.UTC));
newOrder.setStatus(Order.StatusEnum.PLACED);
newOrder.setComplete(Boolean.TRUE);
wm.stubFor(post(urlEqualTo("/store/order"))
.withHeader("Accept", equalTo("application/json"))
.willReturn(ok(responseBody)));
Order order = api.placeOrder(newOrder);
assertThat(order, is(newOrder));
}
// TODO: test validations
}
}

View File

@@ -1,11 +1,17 @@
package org.openapitools.client.api;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openapitools.client.ApiClient;
import java.time.OffsetDateTime;
import org.openapitools.client.model.User;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for UserApi
@@ -15,7 +21,7 @@ class UserApiTest {
private UserApi api;
@BeforeEach
void setup() {
public void setup() {
api = new ApiClient().buildClient(UserApi.class);
}
@@ -27,8 +33,8 @@ class UserApiTest {
*/
@Test
void createUserTest() {
User body = null;
// api.createUser(body);
User user = null;
// api.createUser(user);
// TODO: test validations
}
@@ -41,8 +47,8 @@ class UserApiTest {
*/
@Test
void createUsersWithArrayInputTest() {
List<User> body = null;
// api.createUsersWithArrayInput(body);
List<User> user = null;
// api.createUsersWithArrayInput(user);
// TODO: test validations
}
@@ -55,8 +61,8 @@ class UserApiTest {
*/
@Test
void createUsersWithListInputTest() {
List<User> body = null;
// api.createUsersWithListInput(body);
List<User> user = null;
// api.createUsersWithListInput(user);
// TODO: test validations
}
@@ -143,8 +149,8 @@ class UserApiTest {
@Test
void updateUserTest() {
String username = null;
User body = null;
// api.updateUser(username, body);
User user = null;
// api.updateUser(username, user);
// TODO: test validations
}

View File

@@ -1,46 +0,0 @@
package org.openapitools.client.auth;
import feign.FeignException;
import feign.Request;
import feign.Response;
import feign.RetryableException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
class ApiErrorDecoderTest {
private final ApiErrorDecoder apiErrorDecoder = new ApiErrorDecoder();
@Test
void decode400() {
Response response = getDummyResponse(400);
FeignException.BadRequest badRequest = (FeignException.BadRequest) apiErrorDecoder.decode("GET", response);
assertThat(badRequest.status(), is(400));
}
@ParameterizedTest
@ValueSource(ints = {401, 403})
void decodeAuthorizationErrors(Integer httpStatus) {
Response response = getDummyResponse(httpStatus);
RetryableException retryableException = (RetryableException) apiErrorDecoder.decode("GET", response);
assertThat(retryableException.status(), is(httpStatus));
assertThat(retryableException.retryAfter(), is(nullValue()));
}
private Response getDummyResponse(Integer httpStatus) {
Request request = Request.create(Request.HttpMethod.GET, "http://localhost", Collections.emptyMap(), Request.Body.empty(), null);
return Response.builder()
.status(httpStatus)
.request(request)
.build();
}
}

View File

@@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
/**
* Model tests for AdditionalPropertiesClass
*/

View File

@@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.client.model.SingleRefType;
import org.junit.jupiter.api.Test;
/**
* Model tests for AllOfWithSingleRef
*/

View File

@@ -21,11 +21,8 @@ import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.client.model.Cat;
import org.openapitools.client.model.Dog;
import org.junit.jupiter.api.Test;
/**
* Model tests for Animal
*/

View File

@@ -20,10 +20,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
/**
* Model tests for ArrayOfArrayOfNumberOnly
*/

View File

@@ -20,10 +20,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
/**
* Model tests for ArrayOfNumberOnly
*/

View File

@@ -19,11 +19,11 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openapitools.client.model.ReadOnlyFirst;
import org.junit.jupiter.api.Test;
/**
* Model tests for ArrayTest
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for Capitalization
*/

View File

@@ -24,7 +24,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.client.model.Animal;
import org.junit.jupiter.api.Test;
/**
* Model tests for Cat
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for Category
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for ClassModel
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for Client
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for DeprecatedObject
*/

View File

@@ -24,7 +24,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.client.model.Animal;
import org.junit.jupiter.api.Test;
/**
* Model tests for Dog
*/

View File

@@ -19,10 +19,10 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
/**
* Model tests for EnumArrays
*/

View File

@@ -15,7 +15,6 @@ package org.openapitools.client.model;
import org.junit.jupiter.api.Test;
/**
* Model tests for EnumClass
*/

View File

@@ -28,7 +28,6 @@ import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import org.junit.jupiter.api.Test;
/**
* Model tests for EnumTest
*/

View File

@@ -20,10 +20,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
/**
* Model tests for FileSchemaTestClass
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for File
*/

View File

@@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.client.model.Foo;
import org.junit.jupiter.api.Test;
/**
* Model tests for FooGetDefaultResponse
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for Foo
*/

View File

@@ -25,7 +25,6 @@ import java.time.OffsetDateTime;
import java.util.UUID;
import org.junit.jupiter.api.Test;
/**
* Model tests for FormatTest
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for HasOnlyReadOnly
*/

View File

@@ -24,7 +24,6 @@ import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import org.junit.jupiter.api.Test;
/**
* Model tests for HealthCheckResult
*/

View File

@@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
/**
* Model tests for MapTest
*/

View File

@@ -25,7 +25,6 @@ import java.util.UUID;
import org.openapitools.client.model.Animal;
import org.junit.jupiter.api.Test;
/**
* Model tests for MixedPropertiesAndAdditionalPropertiesClass
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for Model200Response
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for ModelApiResponse
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for ModelList
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for ModelReturn
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for Name
*/

View File

@@ -22,6 +22,7 @@ import java.math.BigDecimal;
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,7 +32,6 @@ import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import org.junit.jupiter.api.Test;
/**
* Model tests for NullableClass
*/

View File

@@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;
/**
* Model tests for NumberOnly
*/

View File

@@ -20,11 +20,11 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
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.Test;
/**
* Model tests for ObjectWithDeprecatedFields
*/

View File

@@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import java.time.OffsetDateTime;
import org.junit.jupiter.api.Test;
/**
* Model tests for Order
*/

View File

@@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;
/**
* Model tests for OuterComposite
*/

View File

@@ -15,7 +15,6 @@ package org.openapitools.client.model;
import org.junit.jupiter.api.Test;
/**
* Model tests for OuterEnumDefaultValue
*/

View File

@@ -15,7 +15,6 @@ package org.openapitools.client.model;
import org.junit.jupiter.api.Test;
/**
* Model tests for OuterEnumIntegerDefaultValue
*/

View File

@@ -15,7 +15,6 @@ package org.openapitools.client.model;
import org.junit.jupiter.api.Test;
/**
* Model tests for OuterEnumInteger
*/

View File

@@ -15,7 +15,6 @@ package org.openapitools.client.model;
import org.junit.jupiter.api.Test;
/**
* Model tests for OuterEnum
*/

View File

@@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.client.model.OuterEnumInteger;
import org.junit.jupiter.api.Test;
/**
* Model tests for OuterObjectWithEnumProperty
*/

View File

@@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -27,7 +28,6 @@ import org.openapitools.client.model.Category;
import org.openapitools.client.model.Tag;
import org.junit.jupiter.api.Test;
/**
* Model tests for Pet
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for ReadOnlyFirst
*/

View File

@@ -15,7 +15,6 @@ package org.openapitools.client.model;
import org.junit.jupiter.api.Test;
/**
* Model tests for SingleRefType
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for SpecialModelName
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for Tag
*/

View File

@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.junit.jupiter.api.Test;
/**
* Model tests for User
*/

View File

@@ -1,10 +0,0 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@@ -1,18 +0,0 @@
{
"id": 85,
"category": {
"id": 1,
"name": "Dogs"
},
"name": "LvRcat",
"photoUrls": [
"string"
],
"tags": [
{
"id": 10,
"name": "tag"
}
],
"status": "available"
}

View File

@@ -1,38 +0,0 @@
[
{
"id": 85,
"category": {
"id": 1,
"name": "Dogs"
},
"name": "LvRcat",
"photoUrls": [
"string"
],
"tags": [
{
"id": 10,
"name": "tag"
}
],
"status": "available"
},
{
"id": 42,
"category": {
"id": 1,
"name": "Dogs"
},
"name": "Louise",
"photoUrls": [
"photo"
],
"tags": [
{
"id": 0,
"name": "obedient"
}
],
"status": "sold"
}
]