Skip to content

Commit

Permalink
add one sample to CircleCI, fix various Java tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-mfg committed Dec 11, 2024
1 parent 178d47b commit 4f0e8a0
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 47 deletions.
1 change: 1 addition & 0 deletions CI/circle_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions bin/utils/test_file_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@

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;
import org.openapitools.client.model.Pet;

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();
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ApiClientTest {
ApiClient apiClient;
JSON json;

@Before
@BeforeEach
public void setup() {
apiClient = new ApiClient();
json = apiClient.getJSON();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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<Order>() { }.getType();
Expand All @@ -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<Order>() { }.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> cookieParams = new HashMap<String, String>();

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) {
Expand All @@ -32,14 +32,14 @@ public void testApplyToParamsInQuery() {
}

@Test
public void testApplyToParamsInQueryWithNullValue() {
public void testApplyToParamsInQueryWithNullValue() throws ApiException {
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> cookieParams = new HashMap<String, String>();

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());
Expand All @@ -48,15 +48,15 @@ public void testApplyToParamsInQueryWithNullValue() {
}

@Test
public void testApplyToParamsInHeaderWithPrefix() {
public void testApplyToParamsInHeaderWithPrefix() throws ApiException {
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> cookieParams = new HashMap<String, String>();

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());
Expand All @@ -66,15 +66,15 @@ public void testApplyToParamsInHeaderWithPrefix() {
}

@Test
public void testApplyToParamsInHeaderWithNullValue() {
public void testApplyToParamsInHeaderWithNullValue() throws ApiException {
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> cookieParams = new HashMap<String, String>();

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());
Expand All @@ -83,15 +83,15 @@ public void testApplyToParamsInHeaderWithNullValue() {
}

@Test
public void testApplyToParamsInCookieWithPrefix() {
public void testApplyToParamsInCookieWithPrefix() throws ApiException {
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> cookieParams = new HashMap<String, String>();

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());
Expand All @@ -101,15 +101,15 @@ public void testApplyToParamsInCookieWithPrefix() {
}

@Test
public void testApplyToParamsInCookieWithNullValue() {
public void testApplyToParamsInCookieWithNullValue() throws ApiException {
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> cookieParams = new HashMap<String, String>();

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -19,14 +20,14 @@ public void setup() {
}

@Test
public void testApplyToParams() {
public void testApplyToParams() throws ApiException {
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> cookieParams = new HashMap<String, String>();

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());
Expand All @@ -38,15 +39,15 @@ 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"));

// 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"));
Expand All @@ -56,7 +57,7 @@ public void testApplyToParams() {
headerParams = new HashMap<String, String>();
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +66,7 @@ public void arrayArrayNumberTest() {
model2.setArrayArrayNumber(new ArrayList<List<BigDecimal>>());
model2.getArrayArrayNumber().add(arrayArrayNumber2);

Assert.assertTrue(model2.equals(model));
Assertions.assertTrue(model2.equals(model));
}

}

0 comments on commit 4f0e8a0

Please sign in to comment.