[Java] Threetenbp dates support (#4029)

* [feign] add threetenbp support for feign clients

* [okhttp] add threetenbp support for okhttp clients

* [jersey] add threetenbp support for jersey clients

* [retrofit2] add threetenbp support for retrofit2 clients

* [spring] add threetenbp support for spring generators

* add a workaround in tests for a bug in the petstore

The petstore doesn't manage fractional digits of dates correctly when there are less than 3
This commit is contained in:
Christophe Bornet
2016-11-04 10:55:16 +01:00
committed by wing328
parent c1e6f00242
commit 70d93883cf
336 changed files with 6397 additions and 1821 deletions

View File

@@ -1,9 +1,10 @@
package io.swagger.client.api;
import io.swagger.client.ApiClient;
import org.joda.time.LocalDate;
import io.swagger.client.model.Client;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.LocalDate;
import java.math.BigDecimal;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
@@ -25,6 +26,19 @@ public class FakeApiTest {
}
/**
* To test \"client\" model
*
*
*/
@Test
public void testClientModelTest() {
Client body = null;
// Client response = api.testClientModel(body);
// TODO: test validations
}
/**
* Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*
@@ -34,17 +48,39 @@ public class FakeApiTest {
public void testEndpointParametersTest() {
BigDecimal number = null;
Double _double = null;
String string = null;
String patternWithoutDelimiter = null;
byte[] _byte = null;
Integer integer = null;
Integer int32 = null;
Long int64 = null;
Float _float = null;
String string = null;
byte[] binary = null;
LocalDate date = null;
DateTime dateTime = null;
OffsetDateTime dateTime = null;
String password = null;
// api.testEndpointParameters(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password);
String paramCallback = null;
// api.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback);
// TODO: test validations
}
/**
* To test enum parameters
*
*
*/
@Test
public void testEnumParametersTest() {
List<String> enumFormStringArray = null;
String enumFormString = null;
List<String> enumHeaderStringArray = null;
String enumHeaderString = null;
List<String> enumQueryStringArray = null;
String enumQueryString = null;
BigDecimal enumQueryInteger = null;
Double enumQueryDouble = null;
// api.testEnumParameters(enumFormStringArray, enumFormString, enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble);
// TODO: test validations
}

View File

@@ -0,0 +1,39 @@
package io.swagger.client.api;
import io.swagger.client.ApiClient;
import io.swagger.client.model.Client;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for FakeclassnametagsApi
*/
public class FakeclassnametagsApiTest {
private FakeclassnametagsApi api;
@Before
public void setup() {
api = new ApiClient().buildClient(FakeclassnametagsApi.class);
}
/**
* To test class name in snake case
*
*
*/
@Test
public void testClassnameTest() {
Client body = null;
// Client response = api.testClassname(body);
// TODO: test validations
}
}

View File

@@ -3,7 +3,6 @@ package io.swagger.client.api;
import io.swagger.TestUtils;
import io.swagger.client.ApiClient;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
import java.io.BufferedWriter;
@@ -11,14 +10,15 @@ import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.*;
import static org.junit.Assert.*;
public class PetApiTest {
ApiClient apiClient;
PetApi api;
private ApiClient apiClient;
private PetApi api;
@Before
public void setup() {
@@ -71,7 +71,7 @@ public class PetApiTest {
api.updatePet(pet);
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"}));
List<Pet> pets = api.findPetsByStatus(Collections.singletonList("available"));
assertNotNull(pets);
boolean found = false;
@@ -91,7 +91,7 @@ public class PetApiTest {
pet.setName("monster");
pet.setStatus(Pet.StatusEnum.AVAILABLE);
List<Tag> tags = new ArrayList<Tag>();
List<Tag> tags = new ArrayList<>();
Tag tag1 = new Tag();
tag1.setName("friendly");
tags.add(tag1);
@@ -99,7 +99,7 @@ public class PetApiTest {
api.updatePet(pet);
List<Pet> pets = api.findPetsByTags(Arrays.asList(new String[]{"friendly"}));
List<Pet> pets = api.findPetsByTags(Collections.singletonList("friendly"));
assertNotNull(pets);
boolean found = false;
@@ -135,7 +135,7 @@ public class PetApiTest {
api.deletePet(fetched.getId(), null);
try {
fetched = api.getPetById(fetched.getId());
api.getPetById(fetched.getId());
fail("expected an error");
} catch (Exception e) {
// assertEquals(404, e.getCode());
@@ -166,7 +166,7 @@ public class PetApiTest {
assertTrue(pet1.hashCode() == pet1.hashCode());
pet2.setName("really-happy");
pet2.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}));
pet2.setPhotoUrls(Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2"));
assertFalse(pet1.equals(pet2));
assertFalse(pet2.equals(pet1));
assertFalse(pet1.hashCode() == (pet2.hashCode()));
@@ -174,7 +174,7 @@ public class PetApiTest {
assertTrue(pet2.hashCode() == pet2.hashCode());
pet1.setName("really-happy");
pet1.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}));
pet1.setPhotoUrls(Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2"));
assertTrue(pet1.equals(pet2));
assertTrue(pet2.equals(pet1));
assertTrue(pet1.hashCode() == pet2.hashCode());
@@ -192,7 +192,7 @@ public class PetApiTest {
pet.setCategory(category);
pet.setStatus(Pet.StatusEnum.AVAILABLE);
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"});
List<String> photos = Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2");
pet.setPhotoUrls(photos);
return pet;

View File

@@ -11,15 +11,16 @@ import java.lang.reflect.Field;
import java.util.Map;
import org.junit.*;
import org.threeten.bp.OffsetDateTime;
import static org.junit.Assert.*;
public class StoreApiTest {
ApiClient apiClient;
StoreApi api;
private StoreApi api;
@Before
public void setup() {
apiClient = new ApiClient();
ApiClient apiClient = new ApiClient();
api = apiClient.buildClient(StoreApi.class);
}
@@ -38,7 +39,7 @@ public class StoreApiTest {
assertEquals(order.getId(), fetched.getId());
assertEquals(order.getPetId(), fetched.getPetId());
assertEquals(order.getQuantity(), fetched.getQuantity());
assertEquals(order.getShipDate().toInstant(), fetched.getShipDate().toInstant());
assertTrue(order.getShipDate().isEqual(fetched.getShipDate()));
}
@Test
@@ -61,9 +62,10 @@ public class StoreApiTest {
private Order createOrder() {
Order order = new Order();
order.setPetId(new Long(200));
order.setQuantity(new Integer(13));
order.setShipDate(org.joda.time.DateTime.now());
order.setPetId(200L);
order.setQuantity(13);
//Ensure 3 fractional digits because of a bug in the petstore server
order.setShipDate(OffsetDateTime.now().withNano(123000000));
order.setStatus(Order.StatusEnum.PLACED);
order.setComplete(true);

View File

@@ -3,7 +3,6 @@ package io.swagger.client.api;
import io.swagger.TestUtils;
import io.swagger.client.ApiClient;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
import java.util.Arrays;
@@ -12,12 +11,11 @@ import org.junit.*;
import static org.junit.Assert.*;
public class UserApiTest {
ApiClient apiClient;
UserApi api;
private UserApi api;
@Before
public void setup() {
apiClient = new ApiClient();
ApiClient apiClient = new ApiClient();
api = apiClient.buildClient(UserApi.class);
}
@@ -38,7 +36,7 @@ public class UserApiTest {
User user2 = createUser();
user2.setUsername("user" + user2.getId());
api.createUsersWithArrayInput(Arrays.asList(new User[]{user1, user2}));
api.createUsersWithArrayInput(Arrays.asList(user1, user2));
User fetched = api.getUserByName(user1.getUsername());
assertEquals(user1.getId(), fetched.getId());
@@ -51,7 +49,7 @@ public class UserApiTest {
User user2 = createUser();
user2.setUsername("user" + user2.getId());
api.createUsersWithListInput(Arrays.asList(new User[]{user1, user2}));
api.createUsersWithListInput(Arrays.asList(user1, user2));
User fetched = api.getUserByName(user1.getUsername());
assertEquals(user1.getId(), fetched.getId());