mirror of
				https://github.com/OpenAPITools/openapi-generator.git
				synced 2025-10-31 08:43:45 +00:00 
			
		
		
		
	add joda support to retrofit clients and use it in samples
also adds back the petstore tests
This commit is contained in:
		
							parent
							
								
									b978914c96
								
							
						
					
					
						commit
						acf17c85ad
					
				| @ -26,6 +26,6 @@ fi | |||||||
| 
 | 
 | ||||||
| # if you've executed sbt assembly previously it will use that instead. | # if you've executed sbt assembly previously it will use that instead. | ||||||
| export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" | export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" | ||||||
| ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -c bin/java-petstore-retrofit2.json -o samples/client/petstore/java/retrofit2" | ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -c bin/java-petstore-retrofit2.json -o samples/client/petstore/java/retrofit2 -DdateLibrary=joda" | ||||||
| 
 | 
 | ||||||
| java $JAVA_OPTS -jar $executable $ags | java $JAVA_OPTS -jar $executable $ags | ||||||
|  | |||||||
| @ -26,6 +26,6 @@ fi | |||||||
| 
 | 
 | ||||||
| # if you've executed sbt assembly previously it will use that instead. | # if you've executed sbt assembly previously it will use that instead. | ||||||
| export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" | export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" | ||||||
| ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -c bin/java-petstore-retrofit2rx.json -o samples/client/petstore/java/retrofit2rx -DuseRxJava=true" | ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java -c bin/java-petstore-retrofit2rx.json -o samples/client/petstore/java/retrofit2rx -DuseRxJava=true,dateLibrary=joda" | ||||||
| 
 | 
 | ||||||
| java $JAVA_OPTS -jar $executable $ags | java $JAVA_OPTS -jar $executable $ags | ||||||
|  | |||||||
| @ -9,6 +9,10 @@ import java.util.Map; | |||||||
| 
 | 
 | ||||||
| import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; | import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; | ||||||
| import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; | import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; | ||||||
|  | import org.joda.time.DateTime; | ||||||
|  | import org.joda.time.LocalDate; | ||||||
|  | import org.joda.time.format.DateTimeFormatter; | ||||||
|  | import org.joda.time.format.ISODateTimeFormat; | ||||||
| 
 | 
 | ||||||
| import retrofit2.Converter; | import retrofit2.Converter; | ||||||
| import retrofit2.Retrofit; | import retrofit2.Retrofit; | ||||||
| @ -19,6 +23,9 @@ import retrofit2.converter.scalars.ScalarsConverterFactory; | |||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import com.google.gson.GsonBuilder; | import com.google.gson.GsonBuilder; | ||||||
| import com.google.gson.JsonParseException; | import com.google.gson.JsonParseException; | ||||||
|  | import com.google.gson.TypeAdapter; | ||||||
|  | import com.google.gson.stream.JsonReader; | ||||||
|  | import com.google.gson.stream.JsonWriter; | ||||||
| import okhttp3.Interceptor; | import okhttp3.Interceptor; | ||||||
| import okhttp3.OkHttpClient; | import okhttp3.OkHttpClient; | ||||||
| import okhttp3.RequestBody; | import okhttp3.RequestBody; | ||||||
| @ -108,6 +115,8 @@ public class ApiClient { | |||||||
|    public void createDefaultAdapter() { |    public void createDefaultAdapter() { | ||||||
|         Gson gson = new GsonBuilder() |         Gson gson = new GsonBuilder() | ||||||
|                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") |                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") | ||||||
|  |                 .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter()) | ||||||
|  |                 .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()) | ||||||
|                 .create(); |                 .create(); | ||||||
| 
 | 
 | ||||||
|         okClient = new OkHttpClient(); |         okClient = new OkHttpClient(); | ||||||
| @ -346,3 +355,58 @@ class GsonCustomConverterFactory extends Converter.Factory | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Gson TypeAdapter for Joda DateTime type | ||||||
|  |  */ | ||||||
|  | class DateTimeTypeAdapter extends TypeAdapter<DateTime> { | ||||||
|  | 
 | ||||||
|  |     private final DateTimeFormatter formatter = ISODateTimeFormat.dateTime(); | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void write(JsonWriter out, DateTime date) throws IOException { | ||||||
|  |         if (date == null) { | ||||||
|  |             out.nullValue(); | ||||||
|  |         } else { | ||||||
|  |             out.value(formatter.print(date)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DateTime read(JsonReader in) throws IOException { | ||||||
|  |         switch (in.peek()) { | ||||||
|  |             case NULL: | ||||||
|  |                 in.nextNull(); | ||||||
|  |                 return null; | ||||||
|  |             default: | ||||||
|  |                 String date = in.nextString(); | ||||||
|  |                 return formatter.parseDateTime(date); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class LocalDateTypeAdapter extends TypeAdapter<LocalDate> { | ||||||
|  | 
 | ||||||
|  |     private final DateTimeFormatter formatter = ISODateTimeFormat.date(); | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void write(JsonWriter out, LocalDate date) throws IOException { | ||||||
|  |         if (date == null) { | ||||||
|  |             out.nullValue(); | ||||||
|  |         } else { | ||||||
|  |             out.value(formatter.print(date)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public LocalDate read(JsonReader in) throws IOException { | ||||||
|  |         switch (in.peek()) { | ||||||
|  |             case NULL: | ||||||
|  |                 in.nextNull(); | ||||||
|  |                 return null; | ||||||
|  |             default: | ||||||
|  |                 String date = in.nextString(); | ||||||
|  |                 return formatter.parseLocalDate(date); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -97,25 +97,20 @@ ext { | |||||||
|     oltu_version = "1.0.1" |     oltu_version = "1.0.1" | ||||||
|     retrofit_version = "2.0.2" |     retrofit_version = "2.0.2" | ||||||
|     swagger_annotations_version = "1.5.8" |     swagger_annotations_version = "1.5.8" | ||||||
|     junit_version = "4.12" |     junit_version = "4.12"{{#useRxJava}} | ||||||
| {{#useRxJava}} |     rx_java_version = "1.1.3"{{/useRxJava}} | ||||||
|     rx_java_version = "1.1.3" |     jodatime_version = "2.9.3" | ||||||
| {{/useRxJava}} |  | ||||||
| {{^useRxJava}}{{/useRxJava}} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| dependencies { | dependencies { | ||||||
|     compile "com.squareup.retrofit2:retrofit:$retrofit_version" |     compile "com.squareup.retrofit2:retrofit:$retrofit_version" | ||||||
|     compile "com.squareup.retrofit2:converter-scalars:$retrofit_version" |     compile "com.squareup.retrofit2:converter-scalars:$retrofit_version" | ||||||
|     compile "com.squareup.retrofit2:converter-gson:$retrofit_version" |     compile "com.squareup.retrofit2:converter-gson:$retrofit_version"{{#useRxJava}} | ||||||
| {{#useRxJava}} |  | ||||||
|     compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version" |     compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version" | ||||||
|     compile "io.reactivex:rxjava:$rx_java_version" |     compile "io.reactivex:rxjava:$rx_java_version"{{/useRxJava}} | ||||||
| {{/useRxJava}} |  | ||||||
| {{^useRxJava}}{{/useRxJava}} |  | ||||||
| 
 |  | ||||||
|     compile "io.swagger:swagger-annotations:$swagger_annotations_version" |     compile "io.swagger:swagger-annotations:$swagger_annotations_version" | ||||||
|     compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" |     compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" | ||||||
|  |     compile "joda-time:joda-time:$jodatime_version" | ||||||
| 
 | 
 | ||||||
|     testCompile "junit:junit:$junit_version" |     testCompile "junit:junit:$junit_version" | ||||||
| } | } | ||||||
|  | |||||||
| @ -11,13 +11,12 @@ lazy val root = (project in file(".")). | |||||||
|     libraryDependencies ++= Seq( |     libraryDependencies ++= Seq( | ||||||
|       "com.squareup.retrofit2" % "retrofit" % "2.0.2" % "compile", |       "com.squareup.retrofit2" % "retrofit" % "2.0.2" % "compile", | ||||||
|       "com.squareup.retrofit2" % "converter-scalars" % "2.0.2" % "compile", |       "com.squareup.retrofit2" % "converter-scalars" % "2.0.2" % "compile", | ||||||
|       "com.squareup.retrofit2" % "converter-gson" % "2.0.2" % "compile", |       "com.squareup.retrofit2" % "converter-gson" % "2.0.2" % "compile",{{#useRxJava}} | ||||||
|       {{#useRxJava}} |  | ||||||
|       "com.squareup.retrofit2" % "adapter-rxjava" % "2.0.2" % "compile", |       "com.squareup.retrofit2" % "adapter-rxjava" % "2.0.2" % "compile", | ||||||
|       "io.reactivex" % "rxjava" % "1.1.3" % "compile", |       "io.reactivex" % "rxjava" % "1.1.3" % "compile",{{/useRxJava}} | ||||||
|       {{/useRxJava}} |  | ||||||
|       "io.swagger" % "swagger-annotations" % "1.5.8" % "compile", |       "io.swagger" % "swagger-annotations" % "1.5.8" % "compile", | ||||||
|       "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", |       "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", | ||||||
|  |       "joda-time" % "joda-time" % "2.9.3" % "compile", | ||||||
|       "junit" % "junit" % "4.12" % "test", |       "junit" % "junit" % "4.12" % "test", | ||||||
|       "com.novocode" % "junit-interface" % "0.10" % "test" |       "com.novocode" % "junit-interface" % "0.10" % "test" | ||||||
|     ) |     ) | ||||||
|  | |||||||
| @ -131,6 +131,11 @@ | |||||||
|       <groupId>org.apache.oltu.oauth2</groupId> |       <groupId>org.apache.oltu.oauth2</groupId> | ||||||
|       <artifactId>org.apache.oltu.oauth2.client</artifactId> |       <artifactId>org.apache.oltu.oauth2.client</artifactId> | ||||||
|       <version>${oltu-version}</version> |       <version>${oltu-version}</version> | ||||||
|  |     </dependency> | ||||||
|  |     <dependency> | ||||||
|  |       <groupId>joda-time</groupId> | ||||||
|  |       <artifactId>joda-time</artifactId> | ||||||
|  |       <version>${jodatime-version}</version> | ||||||
|     </dependency>{{#useRxJava}} |     </dependency>{{#useRxJava}} | ||||||
|     <dependency> |     <dependency> | ||||||
|       <groupId>io.reactivex</groupId> |       <groupId>io.reactivex</groupId> | ||||||
| @ -153,9 +158,9 @@ | |||||||
|   </dependencies> |   </dependencies> | ||||||
|   <properties> |   <properties> | ||||||
|     <swagger-core-version>1.5.8</swagger-core-version> |     <swagger-core-version>1.5.8</swagger-core-version> | ||||||
|     <retrofit-version>2.0.2</retrofit-version> |     <retrofit-version>2.0.2</retrofit-version>{{#useRxJava}} | ||||||
|     {{#useRxJava}}<rxjava-version>1.1.3</rxjava-version>{{/useRxJava}} |     <rxjava-version>1.1.3</rxjava-version>{{/useRxJava}} | ||||||
|     <okhttp-version>3.2.0</okhttp-version> |     <jodatime-version>2.9.3</jodatime-version> | ||||||
|     <oltu-version>1.0.1</oltu-version> |     <oltu-version>1.0.1</oltu-version> | ||||||
|     <maven-plugin-version>1.0.0</maven-plugin-version> |     <maven-plugin-version>1.0.0</maven-plugin-version> | ||||||
|     <junit-version>4.12</junit-version> |     <junit-version>4.12</junit-version> | ||||||
|  | |||||||
| @ -98,17 +98,16 @@ ext { | |||||||
|     retrofit_version = "2.0.2" |     retrofit_version = "2.0.2" | ||||||
|     swagger_annotations_version = "1.5.8" |     swagger_annotations_version = "1.5.8" | ||||||
|     junit_version = "4.12" |     junit_version = "4.12" | ||||||
| 
 |     jodatime_version = "2.9.3" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| dependencies { | dependencies { | ||||||
|     compile "com.squareup.retrofit2:retrofit:$retrofit_version" |     compile "com.squareup.retrofit2:retrofit:$retrofit_version" | ||||||
|     compile "com.squareup.retrofit2:converter-scalars:$retrofit_version" |     compile "com.squareup.retrofit2:converter-scalars:$retrofit_version" | ||||||
|     compile "com.squareup.retrofit2:converter-gson:$retrofit_version" |     compile "com.squareup.retrofit2:converter-gson:$retrofit_version" | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     compile "io.swagger:swagger-annotations:$swagger_annotations_version" |     compile "io.swagger:swagger-annotations:$swagger_annotations_version" | ||||||
|     compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" |     compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" | ||||||
|  |     compile "joda-time:joda-time:$jodatime_version" | ||||||
| 
 | 
 | ||||||
|     testCompile "junit:junit:$junit_version" |     testCompile "junit:junit:$junit_version" | ||||||
| } | } | ||||||
|  | |||||||
| @ -14,6 +14,7 @@ lazy val root = (project in file(".")). | |||||||
|       "com.squareup.retrofit2" % "converter-gson" % "2.0.2" % "compile", |       "com.squareup.retrofit2" % "converter-gson" % "2.0.2" % "compile", | ||||||
|       "io.swagger" % "swagger-annotations" % "1.5.8" % "compile", |       "io.swagger" % "swagger-annotations" % "1.5.8" % "compile", | ||||||
|       "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", |       "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", | ||||||
|  |       "joda-time" % "joda-time" % "2.9.3" % "compile", | ||||||
|       "junit" % "junit" % "4.12" % "test", |       "junit" % "junit" % "4.12" % "test", | ||||||
|       "com.novocode" % "junit-interface" % "0.10" % "test" |       "com.novocode" % "junit-interface" % "0.10" % "test" | ||||||
|     ) |     ) | ||||||
|  | |||||||
| @ -32,8 +32,8 @@ Integer int32 = 56; // Integer | None | |||||||
| Long int64 = 789L; // Long | None | Long int64 = 789L; // Long | None | ||||||
| Float _float = 3.4F; // Float | None | Float _float = 3.4F; // Float | None | ||||||
| byte[] binary = B; // byte[] | None | byte[] binary = B; // byte[] | None | ||||||
| Date date = new Date(); // Date | None | LocalDate date = new LocalDate(); // LocalDate | None | ||||||
| Date dateTime = new Date(); // Date | None | DateTime dateTime = new DateTime(); // DateTime | None | ||||||
| String password = "password_example"; // String | None | String password = "password_example"; // String | None | ||||||
| try { | try { | ||||||
|     Void result = apiInstance.testEndpointParameters(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password); |     Void result = apiInstance.testEndpointParameters(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password); | ||||||
| @ -57,8 +57,8 @@ Name | Type | Description  | Notes | |||||||
|  **int64** | **Long**| None | [optional] |  **int64** | **Long**| None | [optional] | ||||||
|  **_float** | **Float**| None | [optional] |  **_float** | **Float**| None | [optional] | ||||||
|  **binary** | **byte[]**| None | [optional] |  **binary** | **byte[]**| None | [optional] | ||||||
|  **date** | **Date**| None | [optional] |  **date** | **LocalDate**| None | [optional] | ||||||
|  **dateTime** | **Date**| None | [optional] |  **dateTime** | **DateTime**| None | [optional] | ||||||
|  **password** | **String**| None | [optional] |  **password** | **String**| None | [optional] | ||||||
| 
 | 
 | ||||||
| ### Return type | ### Return type | ||||||
|  | |||||||
| @ -13,8 +13,8 @@ Name | Type | Description | Notes | |||||||
| **string** | **String** |  |  [optional] | **string** | **String** |  |  [optional] | ||||||
| **_byte** | **byte[]** |  |  | **_byte** | **byte[]** |  |  | ||||||
| **binary** | **byte[]** |  |  [optional] | **binary** | **byte[]** |  |  [optional] | ||||||
| **date** | [**Date**](Date.md) |  |  | **date** | [**LocalDate**](LocalDate.md) |  |  | ||||||
| **dateTime** | [**Date**](Date.md) |  |  [optional] | **dateTime** | [**DateTime**](DateTime.md) |  |  [optional] | ||||||
| **uuid** | **String** |  |  [optional] | **uuid** | **String** |  |  [optional] | ||||||
| **password** | **String** |  |  | **password** | **String** |  |  | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ | |||||||
| Name | Type | Description | Notes | Name | Type | Description | Notes | ||||||
| ------------ | ------------- | ------------- | ------------- | ------------ | ------------- | ------------- | ------------- | ||||||
| **uuid** | **String** |  |  [optional] | **uuid** | **String** |  |  [optional] | ||||||
| **dateTime** | [**Date**](Date.md) |  |  [optional] | **dateTime** | [**DateTime**](DateTime.md) |  |  [optional] | ||||||
| **map** | [**Map<String, Animal>**](Animal.md) |  |  [optional] | **map** | [**Map<String, Animal>**](Animal.md) |  |  [optional] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ Name | Type | Description | Notes | |||||||
| **id** | **Long** |  |  [optional] | **id** | **Long** |  |  [optional] | ||||||
| **petId** | **Long** |  |  [optional] | **petId** | **Long** |  |  [optional] | ||||||
| **quantity** | **Integer** |  |  [optional] | **quantity** | **Integer** |  |  [optional] | ||||||
| **shipDate** | [**Date**](Date.md) |  |  [optional] | **shipDate** | [**DateTime**](DateTime.md) |  |  [optional] | ||||||
| **status** | [**StatusEnum**](#StatusEnum) | Order Status |  [optional] | **status** | [**StatusEnum**](#StatusEnum) | Order Status |  [optional] | ||||||
| **complete** | **Boolean** |  |  [optional] | **complete** | **Boolean** |  |  [optional] | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -132,6 +132,11 @@ | |||||||
|       <artifactId>org.apache.oltu.oauth2.client</artifactId> |       <artifactId>org.apache.oltu.oauth2.client</artifactId> | ||||||
|       <version>${oltu-version}</version> |       <version>${oltu-version}</version> | ||||||
|     </dependency> |     </dependency> | ||||||
|  |     <dependency> | ||||||
|  |       <groupId>joda-time</groupId> | ||||||
|  |       <artifactId>joda-time</artifactId> | ||||||
|  |       <version>${jodatime-version}</version> | ||||||
|  |     </dependency> | ||||||
| 
 | 
 | ||||||
|     <!-- test dependencies --> |     <!-- test dependencies --> | ||||||
|     <dependency> |     <dependency> | ||||||
| @ -144,8 +149,7 @@ | |||||||
|   <properties> |   <properties> | ||||||
|     <swagger-core-version>1.5.8</swagger-core-version> |     <swagger-core-version>1.5.8</swagger-core-version> | ||||||
|     <retrofit-version>2.0.2</retrofit-version> |     <retrofit-version>2.0.2</retrofit-version> | ||||||
|      |     <jodatime-version>2.9.3</jodatime-version> | ||||||
|     <okhttp-version>3.2.0</okhttp-version> |  | ||||||
|     <oltu-version>1.0.1</oltu-version> |     <oltu-version>1.0.1</oltu-version> | ||||||
|     <maven-plugin-version>1.0.0</maven-plugin-version> |     <maven-plugin-version>1.0.0</maven-plugin-version> | ||||||
|     <junit-version>4.12</junit-version> |     <junit-version>4.12</junit-version> | ||||||
|  | |||||||
| @ -9,6 +9,10 @@ import java.util.Map; | |||||||
| 
 | 
 | ||||||
| import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; | import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; | ||||||
| import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; | import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; | ||||||
|  | import org.joda.time.DateTime; | ||||||
|  | import org.joda.time.LocalDate; | ||||||
|  | import org.joda.time.format.DateTimeFormatter; | ||||||
|  | import org.joda.time.format.ISODateTimeFormat; | ||||||
| 
 | 
 | ||||||
| import retrofit2.Converter; | import retrofit2.Converter; | ||||||
| import retrofit2.Retrofit; | import retrofit2.Retrofit; | ||||||
| @ -19,6 +23,9 @@ import retrofit2.converter.scalars.ScalarsConverterFactory; | |||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import com.google.gson.GsonBuilder; | import com.google.gson.GsonBuilder; | ||||||
| import com.google.gson.JsonParseException; | import com.google.gson.JsonParseException; | ||||||
|  | import com.google.gson.TypeAdapter; | ||||||
|  | import com.google.gson.stream.JsonReader; | ||||||
|  | import com.google.gson.stream.JsonWriter; | ||||||
| import okhttp3.Interceptor; | import okhttp3.Interceptor; | ||||||
| import okhttp3.OkHttpClient; | import okhttp3.OkHttpClient; | ||||||
| import okhttp3.RequestBody; | import okhttp3.RequestBody; | ||||||
| @ -107,6 +114,8 @@ public class ApiClient { | |||||||
|    public void createDefaultAdapter() { |    public void createDefaultAdapter() { | ||||||
|         Gson gson = new GsonBuilder() |         Gson gson = new GsonBuilder() | ||||||
|                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") |                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") | ||||||
|  |                 .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter()) | ||||||
|  |                 .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()) | ||||||
|                 .create(); |                 .create(); | ||||||
| 
 | 
 | ||||||
|         okClient = new OkHttpClient(); |         okClient = new OkHttpClient(); | ||||||
| @ -345,3 +354,58 @@ class GsonCustomConverterFactory extends Converter.Factory | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Gson TypeAdapter for Joda DateTime type | ||||||
|  |  */ | ||||||
|  | class DateTimeTypeAdapter extends TypeAdapter<DateTime> { | ||||||
|  | 
 | ||||||
|  |     private final DateTimeFormatter formatter = ISODateTimeFormat.dateTime(); | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void write(JsonWriter out, DateTime date) throws IOException { | ||||||
|  |         if (date == null) { | ||||||
|  |             out.nullValue(); | ||||||
|  |         } else { | ||||||
|  |             out.value(formatter.print(date)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DateTime read(JsonReader in) throws IOException { | ||||||
|  |         switch (in.peek()) { | ||||||
|  |             case NULL: | ||||||
|  |                 in.nextNull(); | ||||||
|  |                 return null; | ||||||
|  |             default: | ||||||
|  |                 String date = in.nextString(); | ||||||
|  |                 return formatter.parseDateTime(date); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class LocalDateTypeAdapter extends TypeAdapter<LocalDate> { | ||||||
|  | 
 | ||||||
|  |     private final DateTimeFormatter formatter = ISODateTimeFormat.date(); | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void write(JsonWriter out, LocalDate date) throws IOException { | ||||||
|  |         if (date == null) { | ||||||
|  |             out.nullValue(); | ||||||
|  |         } else { | ||||||
|  |             out.value(formatter.print(date)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public LocalDate read(JsonReader in) throws IOException { | ||||||
|  |         switch (in.peek()) { | ||||||
|  |             case NULL: | ||||||
|  |                 in.nextNull(); | ||||||
|  |                 return null; | ||||||
|  |             default: | ||||||
|  |                 String date = in.nextString(); | ||||||
|  |                 return formatter.parseLocalDate(date); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,6 +1,6 @@ | |||||||
| package io.swagger.client; | package io.swagger.client; | ||||||
| 
 | 
 | ||||||
| @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-04T21:04:39.523+08:00") | @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-08T18:45:27.896+02:00") | ||||||
| public class StringUtil { | public class StringUtil { | ||||||
|   /** |   /** | ||||||
|    * Check if the given array contains the given value (with case-insensitive comparison). |    * Check if the given array contains the given value (with case-insensitive comparison). | ||||||
|  | |||||||
| @ -8,8 +8,9 @@ import retrofit2.http.*; | |||||||
| 
 | 
 | ||||||
| import okhttp3.RequestBody; | import okhttp3.RequestBody; | ||||||
| 
 | 
 | ||||||
|  | import org.joda.time.LocalDate; | ||||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||||
| import java.util.Date; | import org.joda.time.DateTime; | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| @ -38,7 +39,7 @@ public interface FakeApi { | |||||||
|   @FormUrlEncoded |   @FormUrlEncoded | ||||||
|   @POST("fake") |   @POST("fake") | ||||||
|   Call<Void> testEndpointParameters( |   Call<Void> testEndpointParameters( | ||||||
|     @Field("number") BigDecimal number, @Field("double") Double _double, @Field("string") String string, @Field("byte") byte[] _byte, @Field("integer") Integer integer, @Field("int32") Integer int32, @Field("int64") Long int64, @Field("float") Float _float, @Field("binary") byte[] binary, @Field("date") Date date, @Field("dateTime") Date dateTime, @Field("password") String password |     @Field("number") BigDecimal number, @Field("double") Double _double, @Field("string") String string, @Field("byte") byte[] _byte, @Field("integer") Integer integer, @Field("int32") Integer int32, @Field("int64") Long int64, @Field("float") Float _float, @Field("binary") byte[] binary, @Field("date") LocalDate date, @Field("dateTime") DateTime dateTime, @Field("password") String password | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -4,7 +4,8 @@ import java.util.Objects; | |||||||
| import io.swagger.annotations.ApiModel; | import io.swagger.annotations.ApiModel; | ||||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||||
| import java.util.Date; | import org.joda.time.DateTime; | ||||||
|  | import org.joda.time.LocalDate; | ||||||
| 
 | 
 | ||||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||||
| 
 | 
 | ||||||
| @ -42,10 +43,10 @@ public class FormatTest   { | |||||||
|   private byte[] binary = null; |   private byte[] binary = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("date") |   @SerializedName("date") | ||||||
|   private Date date = null; |   private LocalDate date = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("dateTime") |   @SerializedName("dateTime") | ||||||
|   private Date dateTime = null; |   private DateTime dateTime = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("uuid") |   @SerializedName("uuid") | ||||||
|   private String uuid = null; |   private String uuid = null; | ||||||
| @ -156,20 +157,20 @@ public class FormatTest   { | |||||||
|   /** |   /** | ||||||
|    **/ |    **/ | ||||||
|   @ApiModelProperty(required = true, value = "") |   @ApiModelProperty(required = true, value = "") | ||||||
|   public Date getDate() { |   public LocalDate getDate() { | ||||||
|     return date; |     return date; | ||||||
|   } |   } | ||||||
|   public void setDate(Date date) { |   public void setDate(LocalDate date) { | ||||||
|     this.date = date; |     this.date = date; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    **/ |    **/ | ||||||
|   @ApiModelProperty(value = "") |   @ApiModelProperty(value = "") | ||||||
|   public Date getDateTime() { |   public DateTime getDateTime() { | ||||||
|     return dateTime; |     return dateTime; | ||||||
|   } |   } | ||||||
|   public void setDateTime(Date dateTime) { |   public void setDateTime(DateTime dateTime) { | ||||||
|     this.dateTime = dateTime; |     this.dateTime = dateTime; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,10 +4,10 @@ import java.util.Objects; | |||||||
| import io.swagger.annotations.ApiModel; | import io.swagger.annotations.ApiModel; | ||||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import io.swagger.client.model.Animal; | import io.swagger.client.model.Animal; | ||||||
| import java.util.Date; |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  | import org.joda.time.DateTime; | ||||||
| 
 | 
 | ||||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||||
| 
 | 
 | ||||||
| @ -21,7 +21,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass   { | |||||||
|   private String uuid = null; |   private String uuid = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("dateTime") |   @SerializedName("dateTime") | ||||||
|   private Date dateTime = null; |   private DateTime dateTime = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("map") |   @SerializedName("map") | ||||||
|   private Map<String, Animal> map = new HashMap<String, Animal>(); |   private Map<String, Animal> map = new HashMap<String, Animal>(); | ||||||
| @ -39,10 +39,10 @@ public class MixedPropertiesAndAdditionalPropertiesClass   { | |||||||
|   /** |   /** | ||||||
|    **/ |    **/ | ||||||
|   @ApiModelProperty(value = "") |   @ApiModelProperty(value = "") | ||||||
|   public Date getDateTime() { |   public DateTime getDateTime() { | ||||||
|     return dateTime; |     return dateTime; | ||||||
|   } |   } | ||||||
|   public void setDateTime(Date dateTime) { |   public void setDateTime(DateTime dateTime) { | ||||||
|     this.dateTime = dateTime; |     this.dateTime = dateTime; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ package io.swagger.client.model; | |||||||
| import java.util.Objects; | import java.util.Objects; | ||||||
| import io.swagger.annotations.ApiModel; | import io.swagger.annotations.ApiModel; | ||||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import java.util.Date; | import org.joda.time.DateTime; | ||||||
| 
 | 
 | ||||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||||
| 
 | 
 | ||||||
| @ -23,7 +23,7 @@ public class Order   { | |||||||
|   private Integer quantity = null; |   private Integer quantity = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("shipDate") |   @SerializedName("shipDate") | ||||||
|   private Date shipDate = null; |   private DateTime shipDate = null; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
| @ -90,10 +90,10 @@ public class Order   { | |||||||
|   /** |   /** | ||||||
|    **/ |    **/ | ||||||
|   @ApiModelProperty(value = "") |   @ApiModelProperty(value = "") | ||||||
|   public Date getShipDate() { |   public DateTime getShipDate() { | ||||||
|     return shipDate; |     return shipDate; | ||||||
|   } |   } | ||||||
|   public void setShipDate(Date shipDate) { |   public void setShipDate(DateTime shipDate) { | ||||||
|     this.shipDate = shipDate; |     this.shipDate = shipDate; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -0,0 +1,17 @@ | |||||||
|  | package io.swagger; | ||||||
|  | 
 | ||||||
|  | import java.util.Random; | ||||||
|  | import java.util.concurrent.atomic.AtomicLong; | ||||||
|  | 
 | ||||||
|  | public class TestUtils { | ||||||
|  |     private static final AtomicLong atomicId = createAtomicId(); | ||||||
|  | 
 | ||||||
|  |     public static long nextId() { | ||||||
|  |         return atomicId.getAndIncrement(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private static AtomicLong createAtomicId() { | ||||||
|  |         int baseId = new Random(System.currentTimeMillis()).nextInt(1000000) + 20000; | ||||||
|  |         return new AtomicLong((long) baseId); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,137 +1,190 @@ | |||||||
| package io.swagger.client.api; | package io.swagger.client.api; | ||||||
| 
 | 
 | ||||||
|  | import io.swagger.TestUtils; | ||||||
|  | 
 | ||||||
| import io.swagger.client.ApiClient; | import io.swagger.client.ApiClient; | ||||||
| import io.swagger.client.model.Pet; | import io.swagger.client.CollectionFormats.*; | ||||||
| import io.swagger.client.model.ModelApiResponse; | import io.swagger.client.api.*; | ||||||
|  | import io.swagger.client.model.*; | ||||||
|  | 
 | ||||||
|  | import java.io.BufferedWriter; | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import org.junit.Before; | import java.io.FileWriter; | ||||||
| import org.junit.Test; |  | ||||||
| 
 |  | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.HashMap; | import java.util.Arrays; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; |  | ||||||
| 
 | 
 | ||||||
| /** | import org.junit.*; | ||||||
|  * API tests for PetApi | 
 | ||||||
|  */ | import retrofit2.Response; | ||||||
|  | 
 | ||||||
|  | import okhttp3.MediaType; | ||||||
|  | import okhttp3.RequestBody; | ||||||
|  | 
 | ||||||
|  | import static org.junit.Assert.*; | ||||||
|  | 
 | ||||||
| public class PetApiTest { | public class PetApiTest { | ||||||
| 
 |     PetApi api = null; | ||||||
|     private PetApi api; |  | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void setup() { |     public void setup() { | ||||||
|         api = new ApiClient().createService(PetApi.class); |         api = new ApiClient().createService(PetApi.class); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Add a new pet to the store |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void addPetTest() { |     public void testCreateAndGetPet() throws Exception { | ||||||
|         Pet body = null; |         Pet pet = createRandomPet(); | ||||||
|         // Void response = api.addPet(body); |         Response<Void> rp2 = api.addPet(pet).execute(); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         Response<Pet> rp = api.getPetById(pet.getId()).execute(); | ||||||
|  |         Pet fetched = rp.body(); | ||||||
|  |         assertNotNull(fetched); | ||||||
|  |         assertEquals(pet.getId(), fetched.getId()); | ||||||
|  |         assertNotNull(fetched.getCategory()); | ||||||
|  |         assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Deletes a pet |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void deletePetTest() { |     public void testUpdatePet() throws Exception { | ||||||
|         Long petId = null; |         Pet pet = createRandomPet(); | ||||||
|         String apiKey = null; |         pet.setName("programmer"); | ||||||
|         // Void response = api.deletePet(petId, apiKey); |  | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.updatePet(pet).execute(); | ||||||
|  | 
 | ||||||
|  |         Pet fetched = api.getPetById(pet.getId()).execute().body(); | ||||||
|  |         assertNotNull(fetched); | ||||||
|  |         assertEquals(pet.getId(), fetched.getId()); | ||||||
|  |         assertNotNull(fetched.getCategory()); | ||||||
|  |         assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Finds Pets by status |  | ||||||
|      * |  | ||||||
|      * Multiple status values can be provided with comma separated strings |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void findPetsByStatusTest() { |     public void testFindPetsByStatus() throws Exception { | ||||||
|         List<String> status = null; |         Pet pet = createRandomPet(); | ||||||
|         // List<Pet> response = api.findPetsByStatus(status); |         pet.setName("programmer"); | ||||||
|  |         pet.setStatus(Pet.StatusEnum.AVAILABLE); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.updatePet(pet).execute(); | ||||||
|  | 
 | ||||||
|  |         List<Pet> pets = api.findPetsByStatus(new CSVParams("available")).execute().body(); | ||||||
|  |         assertNotNull(pets); | ||||||
|  | 
 | ||||||
|  |         boolean found = false; | ||||||
|  |         for (Pet fetched : pets) { | ||||||
|  |             if (fetched.getId().equals(pet.getId())) { | ||||||
|  |                 found = true; | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     /** |         assertTrue(found); | ||||||
|      * Finds Pets by tags |  | ||||||
|      * |  | ||||||
|      * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. |  | ||||||
|      */ |  | ||||||
|     @Test |  | ||||||
|     public void findPetsByTagsTest() { |  | ||||||
|         List<String> tags = null; |  | ||||||
|         // List<Pet> response = api.findPetsByTags(tags); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Find pet by ID |  | ||||||
|      * |  | ||||||
|      * Returns a single pet |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void getPetByIdTest() { |     public void testFindPetsByTags() throws Exception { | ||||||
|         Long petId = null; |         Pet pet = createRandomPet(); | ||||||
|         // Pet response = api.getPetById(petId); |         pet.setName("monster"); | ||||||
|  |         pet.setStatus(Pet.StatusEnum.AVAILABLE); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         List<Tag> tags = new ArrayList<Tag>(); | ||||||
|  |         Tag tag1 = new Tag(); | ||||||
|  |         tag1.setName("friendly"); | ||||||
|  |         tags.add(tag1); | ||||||
|  |         pet.setTags(tags); | ||||||
|  | 
 | ||||||
|  |         api.updatePet(pet).execute(); | ||||||
|  | 
 | ||||||
|  |         List<Pet> pets = api.findPetsByTags(new CSVParams("friendly")).execute().body(); | ||||||
|  |         assertNotNull(pets); | ||||||
|  | 
 | ||||||
|  |         boolean found = false; | ||||||
|  |         for (Pet fetched : pets) { | ||||||
|  |             if (fetched.getId().equals(pet.getId())) { | ||||||
|  |                 found = true; | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         assertTrue(found); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Update an existing pet |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void updatePetTest() { |     public void testUpdatePetWithForm() throws Exception { | ||||||
|         Pet body = null; |         Pet pet = createRandomPet(); | ||||||
|         // Void response = api.updatePet(body); |         pet.setName("frank"); | ||||||
|  |         api.addPet(pet).execute(); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         Pet fetched = api.getPetById(pet.getId()).execute().body(); | ||||||
|  | 
 | ||||||
|  |         api.updatePetWithForm(fetched.getId(), "furt", null).execute(); | ||||||
|  |         Pet updated = api.getPetById(fetched.getId()).execute().body(); | ||||||
|  | 
 | ||||||
|  |         assertEquals(updated.getName(), "furt"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Updates a pet in the store with form data |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void updatePetWithFormTest() { |     public void testDeletePet() throws Exception { | ||||||
|         Long petId = null; |         Pet pet = createRandomPet(); | ||||||
|         String name = null; |         api.addPet(pet).execute(); | ||||||
|         String status = null; |  | ||||||
|         // Void response = api.updatePetWithForm(petId, name, status); |  | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         Pet fetched = api.getPetById(pet.getId()).execute().body(); | ||||||
|  |         api.deletePet(fetched.getId(), null).execute(); | ||||||
|  | 
 | ||||||
|  |         assertFalse(api.getPetById(fetched.getId()).execute().isSuccessful()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * uploads an image |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void uploadFileTest() { |     public void testUploadFile() throws Exception { | ||||||
|         Long petId = null; |         Pet pet = createRandomPet(); | ||||||
|         String additionalMetadata = null; |         api.addPet(pet).execute(); | ||||||
|         File file = null; |  | ||||||
|         // ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file); |  | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         File file = new File("hello.txt"); | ||||||
|  |         BufferedWriter writer = new BufferedWriter(new FileWriter(file)); | ||||||
|  |         writer.write("Hello world!"); | ||||||
|  |         writer.close(); | ||||||
|  | 
 | ||||||
|  |         api.uploadFile(pet.getId(), null, RequestBody.create(MediaType.parse("text/plain"), file)).execute(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Test | ||||||
|  |     public void testEqualsAndHashCode() { | ||||||
|  |         Pet pet1 = new Pet(); | ||||||
|  |         Pet pet2 = new Pet(); | ||||||
|  |         assertTrue(pet1.equals(pet2)); | ||||||
|  |         assertTrue(pet2.equals(pet1)); | ||||||
|  |         assertTrue(pet1.hashCode() == pet2.hashCode()); | ||||||
|  |         assertTrue(pet1.equals(pet1)); | ||||||
|  |         assertTrue(pet1.hashCode() == pet1.hashCode()); | ||||||
|  | 
 | ||||||
|  |         pet2.setName("really-happy"); | ||||||
|  |         pet2.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"})); | ||||||
|  |         assertFalse(pet1.equals(pet2)); | ||||||
|  |         assertFalse(pet2.equals(pet1)); | ||||||
|  |         assertFalse(pet1.hashCode() == (pet2.hashCode())); | ||||||
|  |         assertTrue(pet2.equals(pet2)); | ||||||
|  |         assertTrue(pet2.hashCode() == pet2.hashCode()); | ||||||
|  | 
 | ||||||
|  |         pet1.setName("really-happy"); | ||||||
|  |         pet1.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"})); | ||||||
|  |         assertTrue(pet1.equals(pet2)); | ||||||
|  |         assertTrue(pet2.equals(pet1)); | ||||||
|  |         assertTrue(pet1.hashCode() == pet2.hashCode()); | ||||||
|  |         assertTrue(pet1.equals(pet1)); | ||||||
|  |         assertTrue(pet1.hashCode() == pet1.hashCode()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private Pet createRandomPet() { | ||||||
|  |         Pet pet = new Pet(); | ||||||
|  |         pet.setId(TestUtils.nextId()); | ||||||
|  |         pet.setName("gorilla"); | ||||||
|  | 
 | ||||||
|  |         Category category = new Category(); | ||||||
|  |         category.setName("really-happy"); | ||||||
|  | 
 | ||||||
|  |         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"}); | ||||||
|  |         pet.setPhotoUrls(photos); | ||||||
|  | 
 | ||||||
|  |         return pet; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,77 +1,77 @@ | |||||||
| package io.swagger.client.api; | package io.swagger.client.api; | ||||||
| 
 | 
 | ||||||
| import io.swagger.client.ApiClient; | import io.swagger.TestUtils; | ||||||
| import io.swagger.client.model.Order; |  | ||||||
| import org.junit.Before; |  | ||||||
| import org.junit.Test; |  | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; | import io.swagger.client.ApiClient; | ||||||
| import java.util.HashMap; | import io.swagger.client.api.*; | ||||||
| import java.util.List; | import io.swagger.client.model.*; | ||||||
|  | 
 | ||||||
|  | import java.lang.reflect.Field; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| /** | import org.joda.time.DateTime; | ||||||
|  * API tests for StoreApi | import org.joda.time.DateTimeZone; | ||||||
|  */ | import org.junit.*; | ||||||
| public class StoreApiTest { |  | ||||||
| 
 | 
 | ||||||
|     private StoreApi api; | import retrofit2.Response; | ||||||
|  | import static org.junit.Assert.*; | ||||||
|  | 
 | ||||||
|  | public class StoreApiTest { | ||||||
|  |     StoreApi api = null; | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void setup() { |     public void setup() { | ||||||
|         api = new ApiClient().createService(StoreApi.class); |         api = new ApiClient().createService(StoreApi.class); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Delete purchase order by ID |  | ||||||
|      * |  | ||||||
|      * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void deleteOrderTest() { |     public void testGetInventory() throws Exception { | ||||||
|         String orderId = null; |         Map<String, Integer> inventory = api.getInventory().execute().body(); | ||||||
|         // Void response = api.deleteOrder(orderId); |         assertTrue(inventory.keySet().size() > 0); | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Returns pet inventories by status |  | ||||||
|      * |  | ||||||
|      * Returns a map of status codes to quantities |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void getInventoryTest() { |     public void testPlaceOrder() throws Exception { | ||||||
|         // Map<String, Integer> response = api.getInventory(); |         Order order = createOrder(); | ||||||
|  |         api.placeOrder(order).execute(); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         Order fetched = api.getOrderById(order.getId()).execute().body(); | ||||||
|  |         assertEquals(order.getId(), fetched.getId()); | ||||||
|  |         assertEquals(order.getPetId(), fetched.getPetId()); | ||||||
|  |         assertEquals(order.getQuantity(), fetched.getQuantity()); | ||||||
|  |         assertEquals(order.getShipDate().withZone(DateTimeZone.UTC), fetched.getShipDate().withZone(DateTimeZone.UTC)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Find purchase order by ID |  | ||||||
|      * |  | ||||||
|      * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void getOrderByIdTest() { |     public void testDeleteOrder() throws Exception { | ||||||
|         Long orderId = null; |         Order order = createOrder(); | ||||||
|         // Order response = api.getOrderById(orderId); |         Response<Order> aa = api.placeOrder(order).execute(); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         Order fetched = api.getOrderById(order.getId()).execute().body(); | ||||||
|  |         assertEquals(fetched.getId(), order.getId()); | ||||||
|  | 
 | ||||||
|  |         api.deleteOrder(String.valueOf(order.getId())).execute(); | ||||||
|  | 
 | ||||||
|  |         api.getOrderById(order.getId()).execute(); | ||||||
|  |         //also in retrofit 1 should return an error but don't, check server api impl. | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     private Order createOrder() { | ||||||
|      * Place an order for a pet |         Order order = new Order(); | ||||||
|      * |         order.setPetId(new Long(200)); | ||||||
|      *  |         order.setQuantity(new Integer(13)); | ||||||
|      */ |         order.setShipDate(DateTime.now()); | ||||||
|     @Test |         order.setStatus(Order.StatusEnum.PLACED); | ||||||
|     public void placeOrderTest() { |         order.setComplete(true); | ||||||
|         Order body = null; |  | ||||||
|         // Order response = api.placeOrder(body); |  | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         try { | ||||||
|  |             Field idField = Order.class.getDeclaredField("id"); | ||||||
|  |             idField.setAccessible(true); | ||||||
|  |             idField.set(order, TestUtils.nextId()); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             throw new RuntimeException(e); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         return order; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,131 +1,86 @@ | |||||||
| package io.swagger.client.api; | package io.swagger.client.api; | ||||||
| 
 | 
 | ||||||
|  | import io.swagger.TestUtils; | ||||||
|  | 
 | ||||||
| import io.swagger.client.ApiClient; | import io.swagger.client.ApiClient; | ||||||
| import io.swagger.client.model.User; | import io.swagger.client.api.*; | ||||||
| import org.junit.Before; | import io.swagger.client.model.*; | ||||||
| import org.junit.Test; |  | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; |  | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.List; |  | ||||||
| import java.util.Map; |  | ||||||
| 
 | 
 | ||||||
| /** | import java.util.Arrays; | ||||||
|  * API tests for UserApi | 
 | ||||||
|  */ | import org.junit.*; | ||||||
|  | import static org.junit.Assert.*; | ||||||
|  | 
 | ||||||
| public class UserApiTest { | public class UserApiTest { | ||||||
| 
 |     UserApi api = null; | ||||||
|     private UserApi api; |  | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void setup() { |     public void setup() { | ||||||
|         api = new ApiClient().createService(UserApi.class); |         api = new ApiClient().createService(UserApi.class); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Create user |  | ||||||
|      * |  | ||||||
|      * This can only be done by the logged in user. |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void createUserTest() { |     public void testCreateUser() throws Exception { | ||||||
|         User body = null; |         User user = createUser(); | ||||||
|         // Void response = api.createUser(body); |  | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.createUser(user).execute(); | ||||||
|  | 
 | ||||||
|  |         User fetched = api.getUserByName(user.getUsername()).execute().body(); | ||||||
|  |         assertEquals(user.getId(), fetched.getId()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Creates list of users with given input array |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void createUsersWithArrayInputTest() { |     public void testCreateUsersWithArray() throws Exception { | ||||||
|         List<User> body = null; |         User user1 = createUser(); | ||||||
|         // Void response = api.createUsersWithArrayInput(body); |         user1.setUsername("user" + user1.getId()); | ||||||
|  |         User user2 = createUser(); | ||||||
|  |         user2.setUsername("user" + user2.getId()); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.createUsersWithArrayInput(Arrays.asList(new User[]{user1, user2})).execute(); | ||||||
|  | 
 | ||||||
|  |         User fetched = api.getUserByName(user1.getUsername()).execute().body(); | ||||||
|  |         assertEquals(user1.getId(), fetched.getId()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Creates list of users with given input array |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void createUsersWithListInputTest() { |     public void testCreateUsersWithList() throws Exception { | ||||||
|         List<User> body = null; |         User user1 = createUser(); | ||||||
|         // Void response = api.createUsersWithListInput(body); |         user1.setUsername("user" + user1.getId()); | ||||||
|  |         User user2 = createUser(); | ||||||
|  |         user2.setUsername("user" + user2.getId()); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.createUsersWithListInput(Arrays.asList(new User[]{user1, user2})).execute(); | ||||||
|  | 
 | ||||||
|  |         User fetched = api.getUserByName(user1.getUsername()).execute().body(); | ||||||
|  |         assertEquals(user1.getId(), fetched.getId()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Delete user |  | ||||||
|      * |  | ||||||
|      * This can only be done by the logged in user. |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void deleteUserTest() { |     public void testLoginUser() throws Exception { | ||||||
|         String username = null; |         User user = createUser(); | ||||||
|         // Void response = api.deleteUser(username); |         api.createUser(user).execute(); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         String token = api.loginUser(user.getUsername(), user.getPassword()).execute().body(); | ||||||
|  |         assertTrue(token.startsWith("logged in user session:")); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Get user by user name |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void getUserByNameTest() { |     public void logoutUser() throws Exception { | ||||||
|         String username = null; |         api.logoutUser().execute(); | ||||||
|         // User response = api.getUserByName(username); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     private User createUser() { | ||||||
|      * Logs user into the system |         User user = new User(); | ||||||
|      * |         user.setId(TestUtils.nextId()); | ||||||
|      *  |         user.setUsername("fred"); | ||||||
|      */ |         user.setFirstName("Fred"); | ||||||
|     @Test |         user.setLastName("Meyer"); | ||||||
|     public void loginUserTest() { |         user.setEmail("fred@fredmeyer.com"); | ||||||
|         String username = null; |         user.setPassword("xxXXxx"); | ||||||
|         String password = null; |         user.setPhone("408-867-5309"); | ||||||
|         // String response = api.loginUser(username, password); |         user.setUserStatus(123); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         return user; | ||||||
|     } |     } | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Logs out current logged in user session |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |  | ||||||
|     public void logoutUserTest() { |  | ||||||
|         // Void response = api.logoutUser(); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Updated user |  | ||||||
|      * |  | ||||||
|      * This can only be done by the logged in user. |  | ||||||
|      */ |  | ||||||
|     @Test |  | ||||||
|     public void updateUserTest() { |  | ||||||
|         String username = null; |  | ||||||
|         User body = null; |  | ||||||
|         // Void response = api.updateUser(username, body); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |  | ||||||
|      |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -99,7 +99,7 @@ ext { | |||||||
|     swagger_annotations_version = "1.5.8" |     swagger_annotations_version = "1.5.8" | ||||||
|     junit_version = "4.12" |     junit_version = "4.12" | ||||||
|     rx_java_version = "1.1.3" |     rx_java_version = "1.1.3" | ||||||
| 
 |     jodatime_version = "2.9.3" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| dependencies { | dependencies { | ||||||
| @ -108,10 +108,9 @@ dependencies { | |||||||
|     compile "com.squareup.retrofit2:converter-gson:$retrofit_version" |     compile "com.squareup.retrofit2:converter-gson:$retrofit_version" | ||||||
|     compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version" |     compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version" | ||||||
|     compile "io.reactivex:rxjava:$rx_java_version" |     compile "io.reactivex:rxjava:$rx_java_version" | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     compile "io.swagger:swagger-annotations:$swagger_annotations_version" |     compile "io.swagger:swagger-annotations:$swagger_annotations_version" | ||||||
|     compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" |     compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version" | ||||||
|  |     compile "joda-time:joda-time:$jodatime_version" | ||||||
| 
 | 
 | ||||||
|     testCompile "junit:junit:$junit_version" |     testCompile "junit:junit:$junit_version" | ||||||
| } | } | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ lazy val root = (project in file(".")). | |||||||
|       "io.reactivex" % "rxjava" % "1.1.3" % "compile", |       "io.reactivex" % "rxjava" % "1.1.3" % "compile", | ||||||
|       "io.swagger" % "swagger-annotations" % "1.5.8" % "compile", |       "io.swagger" % "swagger-annotations" % "1.5.8" % "compile", | ||||||
|       "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", |       "org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1" % "compile", | ||||||
|  |       "joda-time" % "joda-time" % "2.9.3" % "compile", | ||||||
|       "junit" % "junit" % "4.12" % "test", |       "junit" % "junit" % "4.12" % "test", | ||||||
|       "com.novocode" % "junit-interface" % "0.10" % "test" |       "com.novocode" % "junit-interface" % "0.10" % "test" | ||||||
|     ) |     ) | ||||||
|  | |||||||
| @ -32,8 +32,8 @@ Integer int32 = 56; // Integer | None | |||||||
| Long int64 = 789L; // Long | None | Long int64 = 789L; // Long | None | ||||||
| Float _float = 3.4F; // Float | None | Float _float = 3.4F; // Float | None | ||||||
| byte[] binary = B; // byte[] | None | byte[] binary = B; // byte[] | None | ||||||
| Date date = new Date(); // Date | None | LocalDate date = new LocalDate(); // LocalDate | None | ||||||
| Date dateTime = new Date(); // Date | None | DateTime dateTime = new DateTime(); // DateTime | None | ||||||
| String password = "password_example"; // String | None | String password = "password_example"; // String | None | ||||||
| try { | try { | ||||||
|     Void result = apiInstance.testEndpointParameters(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password); |     Void result = apiInstance.testEndpointParameters(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password); | ||||||
| @ -57,8 +57,8 @@ Name | Type | Description  | Notes | |||||||
|  **int64** | **Long**| None | [optional] |  **int64** | **Long**| None | [optional] | ||||||
|  **_float** | **Float**| None | [optional] |  **_float** | **Float**| None | [optional] | ||||||
|  **binary** | **byte[]**| None | [optional] |  **binary** | **byte[]**| None | [optional] | ||||||
|  **date** | **Date**| None | [optional] |  **date** | **LocalDate**| None | [optional] | ||||||
|  **dateTime** | **Date**| None | [optional] |  **dateTime** | **DateTime**| None | [optional] | ||||||
|  **password** | **String**| None | [optional] |  **password** | **String**| None | [optional] | ||||||
| 
 | 
 | ||||||
| ### Return type | ### Return type | ||||||
|  | |||||||
| @ -13,8 +13,8 @@ Name | Type | Description | Notes | |||||||
| **string** | **String** |  |  [optional] | **string** | **String** |  |  [optional] | ||||||
| **_byte** | **byte[]** |  |  | **_byte** | **byte[]** |  |  | ||||||
| **binary** | **byte[]** |  |  [optional] | **binary** | **byte[]** |  |  [optional] | ||||||
| **date** | [**Date**](Date.md) |  |  | **date** | [**LocalDate**](LocalDate.md) |  |  | ||||||
| **dateTime** | [**Date**](Date.md) |  |  [optional] | **dateTime** | [**DateTime**](DateTime.md) |  |  [optional] | ||||||
| **uuid** | **String** |  |  [optional] | **uuid** | **String** |  |  [optional] | ||||||
| **password** | **String** |  |  | **password** | **String** |  |  | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ | |||||||
| Name | Type | Description | Notes | Name | Type | Description | Notes | ||||||
| ------------ | ------------- | ------------- | ------------- | ------------ | ------------- | ------------- | ------------- | ||||||
| **uuid** | **String** |  |  [optional] | **uuid** | **String** |  |  [optional] | ||||||
| **dateTime** | [**Date**](Date.md) |  |  [optional] | **dateTime** | [**DateTime**](DateTime.md) |  |  [optional] | ||||||
| **map** | [**Map<String, Animal>**](Animal.md) |  |  [optional] | **map** | [**Map<String, Animal>**](Animal.md) |  |  [optional] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ Name | Type | Description | Notes | |||||||
| **id** | **Long** |  |  [optional] | **id** | **Long** |  |  [optional] | ||||||
| **petId** | **Long** |  |  [optional] | **petId** | **Long** |  |  [optional] | ||||||
| **quantity** | **Integer** |  |  [optional] | **quantity** | **Integer** |  |  [optional] | ||||||
| **shipDate** | [**Date**](Date.md) |  |  [optional] | **shipDate** | [**DateTime**](DateTime.md) |  |  [optional] | ||||||
| **status** | [**StatusEnum**](#StatusEnum) | Order Status |  [optional] | **status** | [**StatusEnum**](#StatusEnum) | Order Status |  [optional] | ||||||
| **complete** | **Boolean** |  |  [optional] | **complete** | **Boolean** |  |  [optional] | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -132,6 +132,11 @@ | |||||||
|       <artifactId>org.apache.oltu.oauth2.client</artifactId> |       <artifactId>org.apache.oltu.oauth2.client</artifactId> | ||||||
|       <version>${oltu-version}</version> |       <version>${oltu-version}</version> | ||||||
|     </dependency> |     </dependency> | ||||||
|  |     <dependency> | ||||||
|  |       <groupId>joda-time</groupId> | ||||||
|  |       <artifactId>joda-time</artifactId> | ||||||
|  |       <version>${jodatime-version}</version> | ||||||
|  |     </dependency> | ||||||
|     <dependency> |     <dependency> | ||||||
|       <groupId>io.reactivex</groupId> |       <groupId>io.reactivex</groupId> | ||||||
|       <artifactId>rxjava</artifactId> |       <artifactId>rxjava</artifactId> | ||||||
| @ -155,7 +160,7 @@ | |||||||
|     <swagger-core-version>1.5.8</swagger-core-version> |     <swagger-core-version>1.5.8</swagger-core-version> | ||||||
|     <retrofit-version>2.0.2</retrofit-version> |     <retrofit-version>2.0.2</retrofit-version> | ||||||
|     <rxjava-version>1.1.3</rxjava-version> |     <rxjava-version>1.1.3</rxjava-version> | ||||||
|     <okhttp-version>3.2.0</okhttp-version> |     <jodatime-version>2.9.3</jodatime-version> | ||||||
|     <oltu-version>1.0.1</oltu-version> |     <oltu-version>1.0.1</oltu-version> | ||||||
|     <maven-plugin-version>1.0.0</maven-plugin-version> |     <maven-plugin-version>1.0.0</maven-plugin-version> | ||||||
|     <junit-version>4.12</junit-version> |     <junit-version>4.12</junit-version> | ||||||
|  | |||||||
| @ -9,6 +9,10 @@ import java.util.Map; | |||||||
| 
 | 
 | ||||||
| import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; | import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; | ||||||
| import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; | import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; | ||||||
|  | import org.joda.time.DateTime; | ||||||
|  | import org.joda.time.LocalDate; | ||||||
|  | import org.joda.time.format.DateTimeFormatter; | ||||||
|  | import org.joda.time.format.ISODateTimeFormat; | ||||||
| 
 | 
 | ||||||
| import retrofit2.Converter; | import retrofit2.Converter; | ||||||
| import retrofit2.Retrofit; | import retrofit2.Retrofit; | ||||||
| @ -19,6 +23,9 @@ import retrofit2.converter.scalars.ScalarsConverterFactory; | |||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import com.google.gson.GsonBuilder; | import com.google.gson.GsonBuilder; | ||||||
| import com.google.gson.JsonParseException; | import com.google.gson.JsonParseException; | ||||||
|  | import com.google.gson.TypeAdapter; | ||||||
|  | import com.google.gson.stream.JsonReader; | ||||||
|  | import com.google.gson.stream.JsonWriter; | ||||||
| import okhttp3.Interceptor; | import okhttp3.Interceptor; | ||||||
| import okhttp3.OkHttpClient; | import okhttp3.OkHttpClient; | ||||||
| import okhttp3.RequestBody; | import okhttp3.RequestBody; | ||||||
| @ -107,6 +114,8 @@ public class ApiClient { | |||||||
|    public void createDefaultAdapter() { |    public void createDefaultAdapter() { | ||||||
|         Gson gson = new GsonBuilder() |         Gson gson = new GsonBuilder() | ||||||
|                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") |                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") | ||||||
|  |                 .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter()) | ||||||
|  |                 .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()) | ||||||
|                 .create(); |                 .create(); | ||||||
| 
 | 
 | ||||||
|         okClient = new OkHttpClient(); |         okClient = new OkHttpClient(); | ||||||
| @ -345,3 +354,58 @@ class GsonCustomConverterFactory extends Converter.Factory | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Gson TypeAdapter for Joda DateTime type | ||||||
|  |  */ | ||||||
|  | class DateTimeTypeAdapter extends TypeAdapter<DateTime> { | ||||||
|  | 
 | ||||||
|  |     private final DateTimeFormatter formatter = ISODateTimeFormat.dateTime(); | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void write(JsonWriter out, DateTime date) throws IOException { | ||||||
|  |         if (date == null) { | ||||||
|  |             out.nullValue(); | ||||||
|  |         } else { | ||||||
|  |             out.value(formatter.print(date)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DateTime read(JsonReader in) throws IOException { | ||||||
|  |         switch (in.peek()) { | ||||||
|  |             case NULL: | ||||||
|  |                 in.nextNull(); | ||||||
|  |                 return null; | ||||||
|  |             default: | ||||||
|  |                 String date = in.nextString(); | ||||||
|  |                 return formatter.parseDateTime(date); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class LocalDateTypeAdapter extends TypeAdapter<LocalDate> { | ||||||
|  | 
 | ||||||
|  |     private final DateTimeFormatter formatter = ISODateTimeFormat.date(); | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void write(JsonWriter out, LocalDate date) throws IOException { | ||||||
|  |         if (date == null) { | ||||||
|  |             out.nullValue(); | ||||||
|  |         } else { | ||||||
|  |             out.value(formatter.print(date)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public LocalDate read(JsonReader in) throws IOException { | ||||||
|  |         switch (in.peek()) { | ||||||
|  |             case NULL: | ||||||
|  |                 in.nextNull(); | ||||||
|  |                 return null; | ||||||
|  |             default: | ||||||
|  |                 String date = in.nextString(); | ||||||
|  |                 return formatter.parseLocalDate(date); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,6 +1,6 @@ | |||||||
| package io.swagger.client; | package io.swagger.client; | ||||||
| 
 | 
 | ||||||
| @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-04T21:05:33.279+08:00") | @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-06-08T18:44:17.529+02:00") | ||||||
| public class StringUtil { | public class StringUtil { | ||||||
|   /** |   /** | ||||||
|    * Check if the given array contains the given value (with case-insensitive comparison). |    * Check if the given array contains the given value (with case-insensitive comparison). | ||||||
|  | |||||||
| @ -8,8 +8,9 @@ import retrofit2.http.*; | |||||||
| 
 | 
 | ||||||
| import okhttp3.RequestBody; | import okhttp3.RequestBody; | ||||||
| 
 | 
 | ||||||
|  | import org.joda.time.LocalDate; | ||||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||||
| import java.util.Date; | import org.joda.time.DateTime; | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| @ -38,7 +39,7 @@ public interface FakeApi { | |||||||
|   @FormUrlEncoded |   @FormUrlEncoded | ||||||
|   @POST("fake") |   @POST("fake") | ||||||
|   Observable<Void> testEndpointParameters( |   Observable<Void> testEndpointParameters( | ||||||
|     @Field("number") BigDecimal number, @Field("double") Double _double, @Field("string") String string, @Field("byte") byte[] _byte, @Field("integer") Integer integer, @Field("int32") Integer int32, @Field("int64") Long int64, @Field("float") Float _float, @Field("binary") byte[] binary, @Field("date") Date date, @Field("dateTime") Date dateTime, @Field("password") String password |     @Field("number") BigDecimal number, @Field("double") Double _double, @Field("string") String string, @Field("byte") byte[] _byte, @Field("integer") Integer integer, @Field("int32") Integer int32, @Field("int64") Long int64, @Field("float") Float _float, @Field("binary") byte[] binary, @Field("date") LocalDate date, @Field("dateTime") DateTime dateTime, @Field("password") String password | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -4,7 +4,8 @@ import java.util.Objects; | |||||||
| import io.swagger.annotations.ApiModel; | import io.swagger.annotations.ApiModel; | ||||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||||
| import java.util.Date; | import org.joda.time.DateTime; | ||||||
|  | import org.joda.time.LocalDate; | ||||||
| 
 | 
 | ||||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||||
| 
 | 
 | ||||||
| @ -42,10 +43,10 @@ public class FormatTest   { | |||||||
|   private byte[] binary = null; |   private byte[] binary = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("date") |   @SerializedName("date") | ||||||
|   private Date date = null; |   private LocalDate date = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("dateTime") |   @SerializedName("dateTime") | ||||||
|   private Date dateTime = null; |   private DateTime dateTime = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("uuid") |   @SerializedName("uuid") | ||||||
|   private String uuid = null; |   private String uuid = null; | ||||||
| @ -156,20 +157,20 @@ public class FormatTest   { | |||||||
|   /** |   /** | ||||||
|    **/ |    **/ | ||||||
|   @ApiModelProperty(required = true, value = "") |   @ApiModelProperty(required = true, value = "") | ||||||
|   public Date getDate() { |   public LocalDate getDate() { | ||||||
|     return date; |     return date; | ||||||
|   } |   } | ||||||
|   public void setDate(Date date) { |   public void setDate(LocalDate date) { | ||||||
|     this.date = date; |     this.date = date; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    **/ |    **/ | ||||||
|   @ApiModelProperty(value = "") |   @ApiModelProperty(value = "") | ||||||
|   public Date getDateTime() { |   public DateTime getDateTime() { | ||||||
|     return dateTime; |     return dateTime; | ||||||
|   } |   } | ||||||
|   public void setDateTime(Date dateTime) { |   public void setDateTime(DateTime dateTime) { | ||||||
|     this.dateTime = dateTime; |     this.dateTime = dateTime; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,10 +4,10 @@ import java.util.Objects; | |||||||
| import io.swagger.annotations.ApiModel; | import io.swagger.annotations.ApiModel; | ||||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import io.swagger.client.model.Animal; | import io.swagger.client.model.Animal; | ||||||
| import java.util.Date; |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  | import org.joda.time.DateTime; | ||||||
| 
 | 
 | ||||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||||
| 
 | 
 | ||||||
| @ -21,7 +21,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass   { | |||||||
|   private String uuid = null; |   private String uuid = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("dateTime") |   @SerializedName("dateTime") | ||||||
|   private Date dateTime = null; |   private DateTime dateTime = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("map") |   @SerializedName("map") | ||||||
|   private Map<String, Animal> map = new HashMap<String, Animal>(); |   private Map<String, Animal> map = new HashMap<String, Animal>(); | ||||||
| @ -39,10 +39,10 @@ public class MixedPropertiesAndAdditionalPropertiesClass   { | |||||||
|   /** |   /** | ||||||
|    **/ |    **/ | ||||||
|   @ApiModelProperty(value = "") |   @ApiModelProperty(value = "") | ||||||
|   public Date getDateTime() { |   public DateTime getDateTime() { | ||||||
|     return dateTime; |     return dateTime; | ||||||
|   } |   } | ||||||
|   public void setDateTime(Date dateTime) { |   public void setDateTime(DateTime dateTime) { | ||||||
|     this.dateTime = dateTime; |     this.dateTime = dateTime; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ package io.swagger.client.model; | |||||||
| import java.util.Objects; | import java.util.Objects; | ||||||
| import io.swagger.annotations.ApiModel; | import io.swagger.annotations.ApiModel; | ||||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import java.util.Date; | import org.joda.time.DateTime; | ||||||
| 
 | 
 | ||||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||||
| 
 | 
 | ||||||
| @ -23,7 +23,7 @@ public class Order   { | |||||||
|   private Integer quantity = null; |   private Integer quantity = null; | ||||||
| 
 | 
 | ||||||
|   @SerializedName("shipDate") |   @SerializedName("shipDate") | ||||||
|   private Date shipDate = null; |   private DateTime shipDate = null; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
| @ -90,10 +90,10 @@ public class Order   { | |||||||
|   /** |   /** | ||||||
|    **/ |    **/ | ||||||
|   @ApiModelProperty(value = "") |   @ApiModelProperty(value = "") | ||||||
|   public Date getShipDate() { |   public DateTime getShipDate() { | ||||||
|     return shipDate; |     return shipDate; | ||||||
|   } |   } | ||||||
|   public void setShipDate(Date shipDate) { |   public void setShipDate(DateTime shipDate) { | ||||||
|     this.shipDate = shipDate; |     this.shipDate = shipDate; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,137 +1,254 @@ | |||||||
| package io.swagger.client.api; | package io.swagger.client.api; | ||||||
| 
 | 
 | ||||||
| import io.swagger.client.ApiClient; | import io.swagger.client.ApiClient; | ||||||
| import io.swagger.client.model.Pet; | import io.swagger.client.CollectionFormats.*; | ||||||
| import io.swagger.client.model.ModelApiResponse; | import io.swagger.client.model.*; | ||||||
|  | 
 | ||||||
|  | import java.io.BufferedWriter; | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import org.junit.Before; | import java.io.FileWriter; | ||||||
| import org.junit.Test; |  | ||||||
| 
 |  | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.HashMap; | import java.util.Arrays; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; |  | ||||||
| 
 | 
 | ||||||
| /** | import org.junit.*; | ||||||
|  * API tests for PetApi | 
 | ||||||
|  */ | import okhttp3.MediaType; | ||||||
|  | import okhttp3.RequestBody; | ||||||
|  | 
 | ||||||
|  | import static org.junit.Assert.*; | ||||||
|  | 
 | ||||||
| public class PetApiTest { | public class PetApiTest { | ||||||
| 
 |     PetApi api = null; | ||||||
|     private PetApi api; |  | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void setup() { |     public void setup() { | ||||||
|         api = new ApiClient().createService(PetApi.class); |         api = new ApiClient().createService(PetApi.class); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Add a new pet to the store |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void addPetTest() { |     public void testCreateAndGetPet() throws Exception { | ||||||
|         Pet body = null; |         final Pet pet = createRandomPet(); | ||||||
|         // Void response = api.addPet(body); |         api.addPet(pet).subscribe(new SkeletonSubscriber<Void>() { | ||||||
|  |             @Override | ||||||
|  |             public void onCompleted() { | ||||||
|  |                 api.getPetById(pet.getId()).subscribe(new SkeletonSubscriber<Pet>() { | ||||||
|  |                     @Override | ||||||
|  |                     public void onNext(Pet fetched) { | ||||||
|  |                         assertNotNull(fetched); | ||||||
|  |                         assertEquals(pet.getId(), fetched.getId()); | ||||||
|  |                         assertNotNull(fetched.getCategory()); | ||||||
|  |                         assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); | ||||||
|  |                     } | ||||||
|  |                 }); | ||||||
|  | 
 | ||||||
|  |             } | ||||||
|  |         }); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Deletes a pet |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void deletePetTest() { |     public void testUpdatePet() throws Exception { | ||||||
|         Long petId = null; |         final Pet pet = createRandomPet(); | ||||||
|         String apiKey = null; |         pet.setName("programmer"); | ||||||
|         // Void response = api.deletePet(petId, apiKey); | 
 | ||||||
|  |         api.updatePet(pet).subscribe(new SkeletonSubscriber<Void>() { | ||||||
|  |             @Override | ||||||
|  |             public void onCompleted() { | ||||||
|  |                 api.getPetById(pet.getId()).subscribe(new SkeletonSubscriber<Pet>() { | ||||||
|  |                     @Override | ||||||
|  |                     public void onNext(Pet fetched) { | ||||||
|  |                         assertNotNull(fetched); | ||||||
|  |                         assertEquals(pet.getId(), fetched.getId()); | ||||||
|  |                         assertNotNull(fetched.getCategory()); | ||||||
|  |                         assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); | ||||||
|  |                     } | ||||||
|  |                 }); | ||||||
|  | 
 | ||||||
|  |             } | ||||||
|  |         }); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Finds Pets by status |  | ||||||
|      * |  | ||||||
|      * Multiple status values can be provided with comma separated strings |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void findPetsByStatusTest() { |     public void testFindPetsByStatus() throws Exception { | ||||||
|         List<String> status = null; |         final Pet pet = createRandomPet(); | ||||||
|         // List<Pet> response = api.findPetsByStatus(status); |         pet.setName("programmer"); | ||||||
|  |         pet.setStatus(Pet.StatusEnum.AVAILABLE); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.updatePet(pet).subscribe(new SkeletonSubscriber<Void>() { | ||||||
|  |             @Override | ||||||
|  |             public void onCompleted() { | ||||||
|  |                 api.findPetsByStatus(new CSVParams("available")).subscribe(new SkeletonSubscriber<List<Pet>>() { | ||||||
|  |                     @Override | ||||||
|  |                     public void onNext(List<Pet> pets) { | ||||||
|  |                         assertNotNull(pets); | ||||||
|  | 
 | ||||||
|  |                         boolean found = false; | ||||||
|  |                         for (Pet fetched : pets) { | ||||||
|  |                             if (fetched.getId().equals(pet.getId())) { | ||||||
|  |                                 found = true; | ||||||
|  |                                 break; | ||||||
|  |                             } | ||||||
|                         } |                         } | ||||||
| 
 | 
 | ||||||
|     /** |                         assertTrue(found); | ||||||
|      * Finds Pets by tags |                     } | ||||||
|      * |                 }); | ||||||
|      * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. | 
 | ||||||
|      */ |             } | ||||||
|     @Test |         }); | ||||||
|     public void findPetsByTagsTest() { |  | ||||||
|         List<String> tags = null; |  | ||||||
|         // List<Pet> response = api.findPetsByTags(tags); |  | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Find pet by ID |  | ||||||
|      * |  | ||||||
|      * Returns a single pet |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void getPetByIdTest() { |     public void testFindPetsByTags() throws Exception { | ||||||
|         Long petId = null; |         final Pet pet = createRandomPet(); | ||||||
|         // Pet response = api.getPetById(petId); |         pet.setName("monster"); | ||||||
|  |         pet.setStatus(Pet.StatusEnum.AVAILABLE); | ||||||
|  | 
 | ||||||
|  |         List<Tag> tags = new ArrayList<Tag>(); | ||||||
|  |         Tag tag1 = new Tag(); | ||||||
|  |         tag1.setName("friendly"); | ||||||
|  |         tags.add(tag1); | ||||||
|  |         pet.setTags(tags); | ||||||
|  | 
 | ||||||
|  |         api.updatePet(pet).subscribe(new SkeletonSubscriber<Void>() { | ||||||
|  |             @Override | ||||||
|  |             public void onCompleted() { | ||||||
|  |                 api.findPetsByTags(new CSVParams("friendly")).subscribe(new SkeletonSubscriber<List<Pet>>() { | ||||||
|  |                     @Override | ||||||
|  |                     public void onNext(List<Pet> pets) { | ||||||
|  |                         assertNotNull(pets); | ||||||
|  | 
 | ||||||
|  |                         boolean found = false; | ||||||
|  |                         for (Pet fetched : pets) { | ||||||
|  |                             if (fetched.getId().equals(pet.getId())) { | ||||||
|  |                                 found = true; | ||||||
|  |                                 break; | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         assertTrue(found); | ||||||
|  |                     } | ||||||
|  |                 }); | ||||||
|  | 
 | ||||||
|  |             } | ||||||
|  |         }); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Update an existing pet |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void updatePetTest() { |     public void testUpdatePetWithForm() throws Exception { | ||||||
|         Pet body = null; |         final Pet pet = createRandomPet(); | ||||||
|         // Void response = api.updatePet(body); |         pet.setName("frank"); | ||||||
|  |         api.addPet(pet).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
|  |         api.getPetById(pet.getId()).subscribe(new SkeletonSubscriber<Pet>() { | ||||||
|  |             @Override | ||||||
|  |             public void onNext(final Pet fetched) { | ||||||
|  |                 api.updatePetWithForm(fetched.getId(), "furt", null) | ||||||
|  |                         .subscribe(new SkeletonSubscriber<Void>() { | ||||||
|  |                             @Override | ||||||
|  |                             public void onCompleted() { | ||||||
|  |                                 api.getPetById(fetched.getId()).subscribe(new SkeletonSubscriber<Pet>() { | ||||||
|  |                                     @Override | ||||||
|  |                                     public void onNext(Pet updated) { | ||||||
|  |                                         assertEquals(updated.getName(), "furt"); | ||||||
|  |                                     } | ||||||
|  |                                 }); | ||||||
|  | 
 | ||||||
|  |                             } | ||||||
|  |                         }); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Updates a pet in the store with form data |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void updatePetWithFormTest() { |     public void testDeletePet() throws Exception { | ||||||
|         Long petId = null; |         Pet pet = createRandomPet(); | ||||||
|         String name = null; |         api.addPet(pet).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
|         String status = null; |  | ||||||
|         // Void response = api.updatePetWithForm(petId, name, status); |  | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.getPetById(pet.getId()).subscribe(new SkeletonSubscriber<Pet>() { | ||||||
|  |             @Override | ||||||
|  |             public void onNext(Pet fetched) { | ||||||
|  | 
 | ||||||
|  |                 api.deletePet(fetched.getId(), null).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
|  |                 api.getPetById(fetched.getId()).subscribe(new SkeletonSubscriber<Pet>() { | ||||||
|  |                     @Override | ||||||
|  |                     public void onNext(Pet deletedPet) { | ||||||
|  |                         fail("Should not have found deleted pet."); | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|     /** |                     @Override | ||||||
|      * uploads an image |                     public void onError(Throwable e) { | ||||||
|      * |                         // expected, because the pet has been deleted. | ||||||
|      *  |                     } | ||||||
|      */ |                 }); | ||||||
|     @Test |             } | ||||||
|     public void uploadFileTest() { |         }); | ||||||
|         Long petId = null; |  | ||||||
|         String additionalMetadata = null; |  | ||||||
|         File file = null; |  | ||||||
|         // ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Test | ||||||
|  |     public void testUploadFile() throws Exception { | ||||||
|  |         File file = File.createTempFile("test", "hello.txt"); | ||||||
|  |         BufferedWriter writer = new BufferedWriter(new FileWriter(file)); | ||||||
|  | 
 | ||||||
|  |         writer.write("Hello world!"); | ||||||
|  |         writer.close(); | ||||||
|  | 
 | ||||||
|  |         Pet pet = createRandomPet(); | ||||||
|  |         api.addPet(pet).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
|  | 
 | ||||||
|  |         RequestBody body = RequestBody.create(MediaType.parse("text/plain"), file); | ||||||
|  |         api.uploadFile(pet.getId(), "a test file", body).subscribe(new SkeletonSubscriber<ModelApiResponse>() { | ||||||
|  |             @Override | ||||||
|  |             public void onError(Throwable e) { | ||||||
|  |                 // this also yields a 400 for other tests, so I guess it's okay... | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     public void testEqualsAndHashCode() { | ||||||
|  |         Pet pet1 = new Pet(); | ||||||
|  |         Pet pet2 = new Pet(); | ||||||
|  |         assertTrue(pet1.equals(pet2)); | ||||||
|  |         assertTrue(pet2.equals(pet1)); | ||||||
|  |         assertTrue(pet1.hashCode() == pet2.hashCode()); | ||||||
|  |         assertTrue(pet1.equals(pet1)); | ||||||
|  |         assertTrue(pet1.hashCode() == pet1.hashCode()); | ||||||
|  | 
 | ||||||
|  |         pet2.setName("really-happy"); | ||||||
|  |         pet2.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"})); | ||||||
|  |         assertFalse(pet1.equals(pet2)); | ||||||
|  |         assertFalse(pet2.equals(pet1)); | ||||||
|  |         assertFalse(pet1.hashCode() == (pet2.hashCode())); | ||||||
|  |         assertTrue(pet2.equals(pet2)); | ||||||
|  |         assertTrue(pet2.hashCode() == pet2.hashCode()); | ||||||
|  | 
 | ||||||
|  |         pet1.setName("really-happy"); | ||||||
|  |         pet1.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"})); | ||||||
|  |         assertTrue(pet1.equals(pet2)); | ||||||
|  |         assertTrue(pet2.equals(pet1)); | ||||||
|  |         assertTrue(pet1.hashCode() == pet2.hashCode()); | ||||||
|  |         assertTrue(pet1.equals(pet1)); | ||||||
|  |         assertTrue(pet1.hashCode() == pet1.hashCode()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private Pet createRandomPet() { | ||||||
|  |         Pet pet = new Pet(); | ||||||
|  |         pet.setId(System.currentTimeMillis()); | ||||||
|  |         pet.setName("gorilla"); | ||||||
|  | 
 | ||||||
|  |         Category category = new Category(); | ||||||
|  |         category.setName("really-happy"); | ||||||
|  | 
 | ||||||
|  |         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"}); | ||||||
|  |         pet.setPhotoUrls(photos); | ||||||
|  | 
 | ||||||
|  |         return pet; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -0,0 +1,30 @@ | |||||||
|  | package io.swagger.client.api; | ||||||
|  | 
 | ||||||
|  | import junit.framework.TestFailure; | ||||||
|  | import rx.Subscriber; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Skeleton subscriber for tests that will fail when onError() is called unexpectedly. | ||||||
|  |  */ | ||||||
|  | public abstract class SkeletonSubscriber<T> extends Subscriber<T> { | ||||||
|  | 
 | ||||||
|  |     public static <T> SkeletonSubscriber<T> failTestOnError() { | ||||||
|  |         return new SkeletonSubscriber<T>() { | ||||||
|  |         }; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void onCompleted() { | ||||||
|  |         // space for rent | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void onNext(T t) { | ||||||
|  |         // space for rent | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void onError(Throwable e) { | ||||||
|  |         throw new RuntimeException("Subscriber onError() called with unhandled exception!", e); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,77 +1,98 @@ | |||||||
| package io.swagger.client.api; | package io.swagger.client.api; | ||||||
| 
 | 
 | ||||||
| import io.swagger.client.ApiClient; | import io.swagger.client.ApiClient; | ||||||
| import io.swagger.client.model.Order; | import io.swagger.client.model.*; | ||||||
| import org.junit.Before; |  | ||||||
| import org.junit.Test; |  | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; | import java.lang.reflect.Field; | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.List; |  | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| /** | import org.joda.time.DateTime; | ||||||
|  * API tests for StoreApi | import org.joda.time.DateTimeZone; | ||||||
|  */ | import org.junit.*; | ||||||
| public class StoreApiTest { |  | ||||||
| 
 | 
 | ||||||
|     private StoreApi api; | import retrofit2.Response; | ||||||
|  | 
 | ||||||
|  | import static org.junit.Assert.*; | ||||||
|  | 
 | ||||||
|  | public class StoreApiTest { | ||||||
|  |     StoreApi api = null; | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void setup() { |     public void setup() { | ||||||
|         api = new ApiClient().createService(StoreApi.class); |         api = new ApiClient().createService(StoreApi.class); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Delete purchase order by ID |  | ||||||
|      * |  | ||||||
|      * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void deleteOrderTest() { |     public void testGetInventory() throws Exception { | ||||||
|         String orderId = null; |         api.getInventory().subscribe(new SkeletonSubscriber<Map<String, Integer>>() { | ||||||
|         // Void response = api.deleteOrder(orderId); |             @Override | ||||||
|  |             public void onNext(Map<String, Integer> inventory) { | ||||||
|  |                 assertTrue(inventory.keySet().size() > 0); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Returns pet inventories by status |  | ||||||
|      * |  | ||||||
|      * Returns a map of status codes to quantities |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void getInventoryTest() { |     public void testPlaceOrder() throws Exception { | ||||||
|         // Map<String, Integer> response = api.getInventory(); |         final Order order = createOrder(); | ||||||
| 
 |         api.placeOrder(order).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
|         // TODO: test validations |         api.getOrderById(order.getId()).subscribe(new SkeletonSubscriber<Order>() { | ||||||
|  |             @Override | ||||||
|  |             public void onNext(Order fetched) { | ||||||
|  |                 assertEquals(order.getId(), fetched.getId()); | ||||||
|  |                 assertEquals(order.getPetId(), fetched.getPetId()); | ||||||
|  |                 assertEquals(order.getQuantity(), fetched.getQuantity()); | ||||||
|  |                 assertEquals(order.getShipDate().withZone(DateTimeZone.UTC), fetched.getShipDate().withZone(DateTimeZone.UTC)); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Find purchase order by ID |  | ||||||
|      * |  | ||||||
|      * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void getOrderByIdTest() { |     public void testDeleteOrder() throws Exception { | ||||||
|         Long orderId = null; |         final Order order = createOrder(); | ||||||
|         // Order response = api.getOrderById(orderId); |         api.placeOrder(order).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.getOrderById(order.getId()).subscribe(new SkeletonSubscriber<Order>() { | ||||||
|  |             @Override | ||||||
|  |             public void onNext(Order fetched) { | ||||||
|  |                 assertEquals(fetched.getId(), order.getId()); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         api.deleteOrder(String.valueOf(order.getId())).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
|  |         api.getOrderById(order.getId()) | ||||||
|  |                 .subscribe(new SkeletonSubscriber<Order>() { | ||||||
|  |                                @Override | ||||||
|  |                                public void onNext(Order order) { | ||||||
|  |                                    throw new RuntimeException("Should not have found deleted order."); | ||||||
|                                } |                                } | ||||||
| 
 | 
 | ||||||
|     /** |                                @Override | ||||||
|      * Place an order for a pet |                                public void onError(Throwable e) { | ||||||
|      * |                                    // should not find deleted order. | ||||||
|      *  |                                } | ||||||
|      */ |                            } | ||||||
|     @Test |                 ); | ||||||
|     public void placeOrderTest() { |  | ||||||
|         Order body = null; |  | ||||||
|         // Order response = api.placeOrder(body); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private Order createOrder() { | ||||||
|  |         Order order = new Order(); | ||||||
|  |         order.setPetId(new Long(200)); | ||||||
|  |         order.setQuantity(new Integer(13)); | ||||||
|  |         order.setShipDate(DateTime.now()); | ||||||
|  |         order.setStatus(Order.StatusEnum.PLACED); | ||||||
|  |         order.setComplete(true); | ||||||
|  | 
 | ||||||
|  |         try { | ||||||
|  |             Field idField = Order.class.getDeclaredField("id"); | ||||||
|  |             idField.setAccessible(true); | ||||||
|  |             idField.set(order, System.currentTimeMillis()); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             throw new RuntimeException(e); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return order; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,131 +1,107 @@ | |||||||
| package io.swagger.client.api; | package io.swagger.client.api; | ||||||
| 
 | 
 | ||||||
| import io.swagger.client.ApiClient; | import io.swagger.client.ApiClient; | ||||||
| import io.swagger.client.model.User; | import io.swagger.client.model.*; | ||||||
| import org.junit.Before; |  | ||||||
| import org.junit.Test; |  | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; | 
 | ||||||
| import java.util.HashMap; | import java.util.Arrays; | ||||||
| import java.util.List; | 
 | ||||||
| import java.util.Map; | import org.junit.*; | ||||||
|  | 
 | ||||||
|  | import static org.junit.Assert.*; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * API tests for UserApi |  * NOTE: This serves as a sample and test case for the generator, which is why this is java-7 code. | ||||||
|  |  * Much looks much nicer with no anonymous classes. | ||||||
|  */ |  */ | ||||||
| public class UserApiTest { | public class UserApiTest { | ||||||
| 
 |     UserApi api = null; | ||||||
|     private UserApi api; |  | ||||||
| 
 | 
 | ||||||
|     @Before |     @Before | ||||||
|     public void setup() { |     public void setup() { | ||||||
|         api = new ApiClient().createService(UserApi.class); |         api = new ApiClient().createService(UserApi.class); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Create user |  | ||||||
|      * |  | ||||||
|      * This can only be done by the logged in user. |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void createUserTest() { |     public void testCreateUser() throws Exception { | ||||||
|         User body = null; |         final User user = createUser(); | ||||||
|         // Void response = api.createUser(body); |  | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.createUser(user).subscribe(new SkeletonSubscriber<Void>() { | ||||||
|  |             @Override | ||||||
|  |             public void onCompleted() { | ||||||
|  |                 api.getUserByName(user.getUsername()).subscribe(new SkeletonSubscriber<User>() { | ||||||
|  |                     @Override | ||||||
|  |                     public void onNext(User fetched) { | ||||||
|  |                         assertEquals(user.getId(), fetched.getId()); | ||||||
|  |                     } | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Creates list of users with given input array |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void createUsersWithArrayInputTest() { |     public void testCreateUsersWithArray() throws Exception { | ||||||
|         List<User> body = null; |         final User user1 = createUser(); | ||||||
|         // Void response = api.createUsersWithArrayInput(body); |         user1.setUsername("abc123"); | ||||||
|  |         User user2 = createUser(); | ||||||
|  |         user2.setUsername("123abc"); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.createUsersWithArrayInput(Arrays.asList(new User[]{user1, user2})).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
|  | 
 | ||||||
|  |         api.getUserByName(user1.getUsername()).subscribe(new SkeletonSubscriber<User>() { | ||||||
|  |             @Override | ||||||
|  |             public void onNext(User fetched) { | ||||||
|  |                 assertEquals(user1.getId(), fetched.getId()); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Creates list of users with given input array |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void createUsersWithListInputTest() { |     public void testCreateUsersWithList() throws Exception { | ||||||
|         List<User> body = null; |         final User user1 = createUser(); | ||||||
|         // Void response = api.createUsersWithListInput(body); |         user1.setUsername("abc123"); | ||||||
|  |         User user2 = createUser(); | ||||||
|  |         user2.setUsername("123abc"); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.createUsersWithListInput(Arrays.asList(new User[]{user1, user2})).subscribe(SkeletonSubscriber.failTestOnError()); | ||||||
|  | 
 | ||||||
|  |         api.getUserByName(user1.getUsername()).subscribe(new SkeletonSubscriber<User>() { | ||||||
|  |             @Override | ||||||
|  |             public void onNext(User fetched) { | ||||||
|  |                 assertEquals(user1.getId(), fetched.getId()); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Delete user |  | ||||||
|      * |  | ||||||
|      * This can only be done by the logged in user. |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void deleteUserTest() { |     public void testLoginUser() throws Exception { | ||||||
|         String username = null; |         User user = createUser(); | ||||||
|         // Void response = api.deleteUser(username); |         api.createUser(user); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         api.loginUser(user.getUsername(), user.getPassword()).subscribe(new SkeletonSubscriber<String>() { | ||||||
|  |             @Override | ||||||
|  |             public void onNext(String token) { | ||||||
|  |                 assertTrue(token.startsWith("logged in user session:")); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Get user by user name |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |     @Test | ||||||
|     public void getUserByNameTest() { |     public void logoutUser() throws Exception { | ||||||
|         String username = null; |         api.logoutUser(); | ||||||
|         // User response = api.getUserByName(username); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     private User createUser() { | ||||||
|      * Logs user into the system |         User user = new User(); | ||||||
|      * |         user.setId(System.currentTimeMillis()); | ||||||
|      *  |         user.setUsername("fred"); | ||||||
|      */ |         user.setFirstName("Fred"); | ||||||
|     @Test |         user.setLastName("Meyer"); | ||||||
|     public void loginUserTest() { |         user.setEmail("fred@fredmeyer.com"); | ||||||
|         String username = null; |         user.setPassword("xxXXxx"); | ||||||
|         String password = null; |         user.setPhone("408-867-5309"); | ||||||
|         // String response = api.loginUser(username, password); |         user.setUserStatus(123); | ||||||
| 
 | 
 | ||||||
|         // TODO: test validations |         return user; | ||||||
|     } |     } | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Logs out current logged in user session |  | ||||||
|      * |  | ||||||
|      *  |  | ||||||
|      */ |  | ||||||
|     @Test |  | ||||||
|     public void logoutUserTest() { |  | ||||||
|         // Void response = api.logoutUser(); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     /** |  | ||||||
|      * Updated user |  | ||||||
|      * |  | ||||||
|      * This can only be done by the logged in user. |  | ||||||
|      */ |  | ||||||
|     @Test |  | ||||||
|     public void updateUserTest() { |  | ||||||
|         String username = null; |  | ||||||
|         User body = null; |  | ||||||
|         // Void response = api.updateUser(username, body); |  | ||||||
| 
 |  | ||||||
|         // TODO: test validations |  | ||||||
|     } |  | ||||||
|      |  | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user