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. | ||||
| 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 | ||||
|  | ||||
| @ -26,6 +26,6 @@ fi | ||||
| 
 | ||||
| # 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" | ||||
| 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 | ||||
|  | ||||
| @ -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.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.Retrofit; | ||||
| @ -19,6 +23,9 @@ import retrofit2.converter.scalars.ScalarsConverterFactory; | ||||
| import com.google.gson.Gson; | ||||
| import com.google.gson.GsonBuilder; | ||||
| 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.OkHttpClient; | ||||
| import okhttp3.RequestBody; | ||||
| @ -108,6 +115,8 @@ public class ApiClient { | ||||
|    public void createDefaultAdapter() { | ||||
|         Gson gson = new GsonBuilder() | ||||
|                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") | ||||
|                 .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter()) | ||||
|                 .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()) | ||||
|                 .create(); | ||||
| 
 | ||||
|         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" | ||||
|     retrofit_version = "2.0.2" | ||||
|     swagger_annotations_version = "1.5.8" | ||||
|     junit_version = "4.12" | ||||
| {{#useRxJava}} | ||||
|     rx_java_version = "1.1.3" | ||||
| {{/useRxJava}} | ||||
| {{^useRxJava}}{{/useRxJava}} | ||||
|     junit_version = "4.12"{{#useRxJava}} | ||||
|     rx_java_version = "1.1.3"{{/useRxJava}} | ||||
|     jodatime_version = "2.9.3" | ||||
| } | ||||
| 
 | ||||
| dependencies { | ||||
|     compile "com.squareup.retrofit2:retrofit:$retrofit_version" | ||||
|     compile "com.squareup.retrofit2:converter-scalars:$retrofit_version" | ||||
|     compile "com.squareup.retrofit2:converter-gson:$retrofit_version" | ||||
| {{#useRxJava}} | ||||
|     compile "com.squareup.retrofit2:converter-gson:$retrofit_version"{{#useRxJava}} | ||||
|     compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version" | ||||
|     compile "io.reactivex:rxjava:$rx_java_version" | ||||
| {{/useRxJava}} | ||||
| {{^useRxJava}}{{/useRxJava}} | ||||
| 
 | ||||
|     compile "io.reactivex:rxjava:$rx_java_version"{{/useRxJava}} | ||||
|     compile "io.swagger:swagger-annotations:$swagger_annotations_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" | ||||
| } | ||||
|  | ||||
| @ -11,13 +11,12 @@ lazy val root = (project in file(".")). | ||||
|     libraryDependencies ++= Seq( | ||||
|       "com.squareup.retrofit2" % "retrofit" % "2.0.2" % "compile", | ||||
|       "com.squareup.retrofit2" % "converter-scalars" % "2.0.2" % "compile", | ||||
|       "com.squareup.retrofit2" % "converter-gson" % "2.0.2" % "compile", | ||||
|       {{#useRxJava}} | ||||
|       "com.squareup.retrofit2" % "converter-gson" % "2.0.2" % "compile",{{#useRxJava}} | ||||
|       "com.squareup.retrofit2" % "adapter-rxjava" % "2.0.2" % "compile", | ||||
|       "io.reactivex" % "rxjava" % "1.1.3" % "compile", | ||||
|       {{/useRxJava}} | ||||
|       "io.reactivex" % "rxjava" % "1.1.3" % "compile",{{/useRxJava}} | ||||
|       "io.swagger" % "swagger-annotations" % "1.5.8" % "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", | ||||
|       "com.novocode" % "junit-interface" % "0.10" % "test" | ||||
|     ) | ||||
|  | ||||
| @ -131,6 +131,11 @@ | ||||
|       <groupId>org.apache.oltu.oauth2</groupId> | ||||
|       <artifactId>org.apache.oltu.oauth2.client</artifactId> | ||||
|       <version>${oltu-version}</version> | ||||
|     </dependency> | ||||
|     <dependency> | ||||
|       <groupId>joda-time</groupId> | ||||
|       <artifactId>joda-time</artifactId> | ||||
|       <version>${jodatime-version}</version> | ||||
|     </dependency>{{#useRxJava}} | ||||
|     <dependency> | ||||
|       <groupId>io.reactivex</groupId> | ||||
| @ -153,9 +158,9 @@ | ||||
|   </dependencies> | ||||
|   <properties> | ||||
|     <swagger-core-version>1.5.8</swagger-core-version> | ||||
|     <retrofit-version>2.0.2</retrofit-version> | ||||
|     {{#useRxJava}}<rxjava-version>1.1.3</rxjava-version>{{/useRxJava}} | ||||
|     <okhttp-version>3.2.0</okhttp-version> | ||||
|     <retrofit-version>2.0.2</retrofit-version>{{#useRxJava}} | ||||
|     <rxjava-version>1.1.3</rxjava-version>{{/useRxJava}} | ||||
|     <jodatime-version>2.9.3</jodatime-version> | ||||
|     <oltu-version>1.0.1</oltu-version> | ||||
|     <maven-plugin-version>1.0.0</maven-plugin-version> | ||||
|     <junit-version>4.12</junit-version> | ||||
|  | ||||
| @ -98,17 +98,16 @@ ext { | ||||
|     retrofit_version = "2.0.2" | ||||
|     swagger_annotations_version = "1.5.8" | ||||
|     junit_version = "4.12" | ||||
| 
 | ||||
|     jodatime_version = "2.9.3" | ||||
| } | ||||
| 
 | ||||
| dependencies { | ||||
|     compile "com.squareup.retrofit2:retrofit:$retrofit_version" | ||||
|     compile "com.squareup.retrofit2:converter-scalars:$retrofit_version" | ||||
|     compile "com.squareup.retrofit2:converter-gson:$retrofit_version" | ||||
| 
 | ||||
| 
 | ||||
|     compile "io.swagger:swagger-annotations:$swagger_annotations_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" | ||||
| } | ||||
|  | ||||
| @ -14,6 +14,7 @@ lazy val root = (project in file(".")). | ||||
|       "com.squareup.retrofit2" % "converter-gson" % "2.0.2" % "compile", | ||||
|       "io.swagger" % "swagger-annotations" % "1.5.8" % "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", | ||||
|       "com.novocode" % "junit-interface" % "0.10" % "test" | ||||
|     ) | ||||
|  | ||||
| @ -32,8 +32,8 @@ Integer int32 = 56; // Integer | None | ||||
| Long int64 = 789L; // Long | None | ||||
| Float _float = 3.4F; // Float | None | ||||
| byte[] binary = B; // byte[] | None | ||||
| Date date = new Date(); // Date | None | ||||
| Date dateTime = new Date(); // Date | None | ||||
| LocalDate date = new LocalDate(); // LocalDate | None | ||||
| DateTime dateTime = new DateTime(); // DateTime | None | ||||
| String password = "password_example"; // String | None | ||||
| try { | ||||
|     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] | ||||
|  **_float** | **Float**| None | [optional] | ||||
|  **binary** | **byte[]**| None | [optional] | ||||
|  **date** | **Date**| None | [optional] | ||||
|  **dateTime** | **Date**| None | [optional] | ||||
|  **date** | **LocalDate**| None | [optional] | ||||
|  **dateTime** | **DateTime**| None | [optional] | ||||
|  **password** | **String**| None | [optional] | ||||
| 
 | ||||
| ### Return type | ||||
|  | ||||
| @ -13,8 +13,8 @@ Name | Type | Description | Notes | ||||
| **string** | **String** |  |  [optional] | ||||
| **_byte** | **byte[]** |  |  | ||||
| **binary** | **byte[]** |  |  [optional] | ||||
| **date** | [**Date**](Date.md) |  |  | ||||
| **dateTime** | [**Date**](Date.md) |  |  [optional] | ||||
| **date** | [**LocalDate**](LocalDate.md) |  |  | ||||
| **dateTime** | [**DateTime**](DateTime.md) |  |  [optional] | ||||
| **uuid** | **String** |  |  [optional] | ||||
| **password** | **String** |  |  | ||||
| 
 | ||||
|  | ||||
| @ -5,7 +5,7 @@ | ||||
| Name | Type | Description | Notes | ||||
| ------------ | ------------- | ------------- | ------------- | ||||
| **uuid** | **String** |  |  [optional] | ||||
| **dateTime** | [**Date**](Date.md) |  |  [optional] | ||||
| **dateTime** | [**DateTime**](DateTime.md) |  |  [optional] | ||||
| **map** | [**Map<String, Animal>**](Animal.md) |  |  [optional] | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -7,7 +7,7 @@ Name | Type | Description | Notes | ||||
| **id** | **Long** |  |  [optional] | ||||
| **petId** | **Long** |  |  [optional] | ||||
| **quantity** | **Integer** |  |  [optional] | ||||
| **shipDate** | [**Date**](Date.md) |  |  [optional] | ||||
| **shipDate** | [**DateTime**](DateTime.md) |  |  [optional] | ||||
| **status** | [**StatusEnum**](#StatusEnum) | Order Status |  [optional] | ||||
| **complete** | **Boolean** |  |  [optional] | ||||
| 
 | ||||
|  | ||||
| @ -132,6 +132,11 @@ | ||||
|       <artifactId>org.apache.oltu.oauth2.client</artifactId> | ||||
|       <version>${oltu-version}</version> | ||||
|     </dependency> | ||||
|     <dependency> | ||||
|       <groupId>joda-time</groupId> | ||||
|       <artifactId>joda-time</artifactId> | ||||
|       <version>${jodatime-version}</version> | ||||
|     </dependency> | ||||
| 
 | ||||
|     <!-- test dependencies --> | ||||
|     <dependency> | ||||
| @ -144,8 +149,7 @@ | ||||
|   <properties> | ||||
|     <swagger-core-version>1.5.8</swagger-core-version> | ||||
|     <retrofit-version>2.0.2</retrofit-version> | ||||
|      | ||||
|     <okhttp-version>3.2.0</okhttp-version> | ||||
|     <jodatime-version>2.9.3</jodatime-version> | ||||
|     <oltu-version>1.0.1</oltu-version> | ||||
|     <maven-plugin-version>1.0.0</maven-plugin-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.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.Retrofit; | ||||
| @ -19,6 +23,9 @@ import retrofit2.converter.scalars.ScalarsConverterFactory; | ||||
| import com.google.gson.Gson; | ||||
| import com.google.gson.GsonBuilder; | ||||
| 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.OkHttpClient; | ||||
| import okhttp3.RequestBody; | ||||
| @ -107,6 +114,8 @@ public class ApiClient { | ||||
|    public void createDefaultAdapter() { | ||||
|         Gson gson = new GsonBuilder() | ||||
|                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") | ||||
|                 .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter()) | ||||
|                 .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()) | ||||
|                 .create(); | ||||
| 
 | ||||
|         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; | ||||
| 
 | ||||
| @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 { | ||||
|   /** | ||||
|    * Check if the given array contains the given value (with case-insensitive comparison). | ||||
|  | ||||
| @ -8,8 +8,9 @@ import retrofit2.http.*; | ||||
| 
 | ||||
| import okhttp3.RequestBody; | ||||
| 
 | ||||
| import org.joda.time.LocalDate; | ||||
| import java.math.BigDecimal; | ||||
| import java.util.Date; | ||||
| import org.joda.time.DateTime; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| @ -38,7 +39,7 @@ public interface FakeApi { | ||||
|   @FormUrlEncoded | ||||
|   @POST("fake") | ||||
|   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.ApiModelProperty; | ||||
| import java.math.BigDecimal; | ||||
| import java.util.Date; | ||||
| import org.joda.time.DateTime; | ||||
| import org.joda.time.LocalDate; | ||||
| 
 | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| 
 | ||||
| @ -42,10 +43,10 @@ public class FormatTest   { | ||||
|   private byte[] binary = null; | ||||
| 
 | ||||
|   @SerializedName("date") | ||||
|   private Date date = null; | ||||
|   private LocalDate date = null; | ||||
| 
 | ||||
|   @SerializedName("dateTime") | ||||
|   private Date dateTime = null; | ||||
|   private DateTime dateTime = null; | ||||
| 
 | ||||
|   @SerializedName("uuid") | ||||
|   private String uuid = null; | ||||
| @ -156,20 +157,20 @@ public class FormatTest   { | ||||
|   /** | ||||
|    **/ | ||||
|   @ApiModelProperty(required = true, value = "") | ||||
|   public Date getDate() { | ||||
|   public LocalDate getDate() { | ||||
|     return date; | ||||
|   } | ||||
|   public void setDate(Date date) { | ||||
|   public void setDate(LocalDate date) { | ||||
|     this.date = date; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    **/ | ||||
|   @ApiModelProperty(value = "") | ||||
|   public Date getDateTime() { | ||||
|   public DateTime getDateTime() { | ||||
|     return dateTime; | ||||
|   } | ||||
|   public void setDateTime(Date dateTime) { | ||||
|   public void setDateTime(DateTime dateTime) { | ||||
|     this.dateTime = dateTime; | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -4,10 +4,10 @@ import java.util.Objects; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import io.swagger.client.model.Animal; | ||||
| import java.util.Date; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import org.joda.time.DateTime; | ||||
| 
 | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| 
 | ||||
| @ -21,7 +21,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass   { | ||||
|   private String uuid = null; | ||||
| 
 | ||||
|   @SerializedName("dateTime") | ||||
|   private Date dateTime = null; | ||||
|   private DateTime dateTime = null; | ||||
| 
 | ||||
|   @SerializedName("map") | ||||
|   private Map<String, Animal> map = new HashMap<String, Animal>(); | ||||
| @ -39,10 +39,10 @@ public class MixedPropertiesAndAdditionalPropertiesClass   { | ||||
|   /** | ||||
|    **/ | ||||
|   @ApiModelProperty(value = "") | ||||
|   public Date getDateTime() { | ||||
|   public DateTime getDateTime() { | ||||
|     return dateTime; | ||||
|   } | ||||
|   public void setDateTime(Date dateTime) { | ||||
|   public void setDateTime(DateTime dateTime) { | ||||
|     this.dateTime = dateTime; | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -3,7 +3,7 @@ package io.swagger.client.model; | ||||
| import java.util.Objects; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import java.util.Date; | ||||
| import org.joda.time.DateTime; | ||||
| 
 | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| 
 | ||||
| @ -23,7 +23,7 @@ public class Order   { | ||||
|   private Integer quantity = null; | ||||
| 
 | ||||
|   @SerializedName("shipDate") | ||||
|   private Date shipDate = null; | ||||
|   private DateTime shipDate = null; | ||||
| 
 | ||||
| 
 | ||||
|   /** | ||||
| @ -90,10 +90,10 @@ public class Order   { | ||||
|   /** | ||||
|    **/ | ||||
|   @ApiModelProperty(value = "") | ||||
|   public Date getShipDate() { | ||||
|   public DateTime getShipDate() { | ||||
|     return shipDate; | ||||
|   } | ||||
|   public void setShipDate(Date shipDate) { | ||||
|   public void setShipDate(DateTime 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; | ||||
| 
 | ||||
| import io.swagger.TestUtils; | ||||
| 
 | ||||
| import io.swagger.client.ApiClient; | ||||
| import io.swagger.client.model.Pet; | ||||
| import io.swagger.client.model.ModelApiResponse; | ||||
| import io.swagger.client.CollectionFormats.*; | ||||
| import io.swagger.client.api.*; | ||||
| import io.swagger.client.model.*; | ||||
| 
 | ||||
| import java.io.BufferedWriter; | ||||
| import java.io.File; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import java.io.FileWriter; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * API tests for PetApi | ||||
|  */ | ||||
| import org.junit.*; | ||||
| 
 | ||||
| import retrofit2.Response; | ||||
| 
 | ||||
| import okhttp3.MediaType; | ||||
| import okhttp3.RequestBody; | ||||
| 
 | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| public class PetApiTest { | ||||
| 
 | ||||
|     private PetApi api; | ||||
|     PetApi api = null; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setup() { | ||||
|         api = new ApiClient().createService(PetApi.class); | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     /** | ||||
|      * Add a new pet to the store | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void addPetTest() { | ||||
|         Pet body = null; | ||||
|         // Void response = api.addPet(body); | ||||
|     public void testCreateAndGetPet() throws Exception { | ||||
|         Pet pet = createRandomPet(); | ||||
|         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 | ||||
|     public void deletePetTest() { | ||||
|         Long petId = null; | ||||
|         String apiKey = null; | ||||
|         // Void response = api.deletePet(petId, apiKey); | ||||
|     public void testUpdatePet() throws Exception { | ||||
|         Pet pet = createRandomPet(); | ||||
|         pet.setName("programmer"); | ||||
| 
 | ||||
|         // 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 | ||||
|     public void findPetsByStatusTest() { | ||||
|         List<String> status = null; | ||||
|         // List<Pet> response = api.findPetsByStatus(status); | ||||
|     public void testFindPetsByStatus() throws Exception { | ||||
|         Pet pet = createRandomPet(); | ||||
|         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); | ||||
|     public void testFindPetsByTags() throws Exception { | ||||
|         Pet pet = createRandomPet(); | ||||
|         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); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Find pet by ID | ||||
|      * | ||||
|      * Returns a single pet | ||||
|      */ | ||||
|     @Test | ||||
|     public void getPetByIdTest() { | ||||
|         Long petId = null; | ||||
|         // Pet response = api.getPetById(petId); | ||||
|     public void testUpdatePetWithForm() throws Exception { | ||||
|         Pet pet = createRandomPet(); | ||||
|         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"); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Update an existing pet | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void updatePetTest() { | ||||
|         Pet body = null; | ||||
|         // Void response = api.updatePet(body); | ||||
|     public void testDeletePet() throws Exception { | ||||
|         Pet pet = createRandomPet(); | ||||
|         api.addPet(pet).execute(); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|         Pet fetched = api.getPetById(pet.getId()).execute().body(); | ||||
|         api.deletePet(fetched.getId(), null).execute(); | ||||
| 
 | ||||
|         assertFalse(api.getPetById(fetched.getId()).execute().isSuccessful()); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Updates a pet in the store with form data | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void updatePetWithFormTest() { | ||||
|         Long petId = null; | ||||
|         String name = null; | ||||
|         String status = null; | ||||
|         // Void response = api.updatePetWithForm(petId, name, status); | ||||
|     public void testUploadFile() throws Exception { | ||||
|         Pet pet = createRandomPet(); | ||||
|         api.addPet(pet).execute(); | ||||
| 
 | ||||
|         // 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(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * uploads an image | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void uploadFileTest() { | ||||
|         Long petId = null; | ||||
|         String additionalMetadata = null; | ||||
|         File file = null; | ||||
|         // ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file); | ||||
|     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()); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|         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; | ||||
| 
 | ||||
| import io.swagger.client.ApiClient; | ||||
| import io.swagger.client.model.Order; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import io.swagger.TestUtils; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import io.swagger.client.ApiClient; | ||||
| import io.swagger.client.api.*; | ||||
| import io.swagger.client.model.*; | ||||
| 
 | ||||
| import java.lang.reflect.Field; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * API tests for StoreApi | ||||
|  */ | ||||
| public class StoreApiTest { | ||||
| import org.joda.time.DateTime; | ||||
| import org.joda.time.DateTimeZone; | ||||
| import org.junit.*; | ||||
| 
 | ||||
|     private StoreApi api; | ||||
| import retrofit2.Response; | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| public class StoreApiTest { | ||||
|     StoreApi api = null; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setup() { | ||||
|         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 | ||||
|     public void deleteOrderTest() { | ||||
|         String orderId = null; | ||||
|         // Void response = api.deleteOrder(orderId); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|     public void testGetInventory() throws Exception { | ||||
|         Map<String, Integer> inventory = api.getInventory().execute().body(); | ||||
|         assertTrue(inventory.keySet().size() > 0); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Returns pet inventories by status | ||||
|      * | ||||
|      * Returns a map of status codes to quantities | ||||
|      */ | ||||
|     @Test | ||||
|     public void getInventoryTest() { | ||||
|         // Map<String, Integer> response = api.getInventory(); | ||||
|     public void testPlaceOrder() throws Exception { | ||||
|         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 | ||||
|     public void getOrderByIdTest() { | ||||
|         Long orderId = null; | ||||
|         // Order response = api.getOrderById(orderId); | ||||
|     public void testDeleteOrder() throws Exception { | ||||
|         Order order = createOrder(); | ||||
|         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. | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Place an order for a pet | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void placeOrderTest() { | ||||
|         Order body = null; | ||||
|         // Order response = api.placeOrder(body); | ||||
|     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); | ||||
| 
 | ||||
|         // 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; | ||||
| 
 | ||||
| import io.swagger.TestUtils; | ||||
| 
 | ||||
| import io.swagger.client.ApiClient; | ||||
| import io.swagger.client.model.User; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import io.swagger.client.api.*; | ||||
| import io.swagger.client.model.*; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * API tests for UserApi | ||||
|  */ | ||||
| import java.util.Arrays; | ||||
| 
 | ||||
| import org.junit.*; | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| public class UserApiTest { | ||||
| 
 | ||||
|     private UserApi api; | ||||
|     UserApi api = null; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setup() { | ||||
|         api = new ApiClient().createService(UserApi.class); | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     /** | ||||
|      * Create user | ||||
|      * | ||||
|      * This can only be done by the logged in user. | ||||
|      */ | ||||
|     @Test | ||||
|     public void createUserTest() { | ||||
|         User body = null; | ||||
|         // Void response = api.createUser(body); | ||||
|     public void testCreateUser() throws Exception { | ||||
|         User user = createUser(); | ||||
| 
 | ||||
|         // 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 | ||||
|     public void createUsersWithArrayInputTest() { | ||||
|         List<User> body = null; | ||||
|         // Void response = api.createUsersWithArrayInput(body); | ||||
|     public void testCreateUsersWithArray() throws Exception { | ||||
|         User user1 = createUser(); | ||||
|         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 | ||||
|     public void createUsersWithListInputTest() { | ||||
|         List<User> body = null; | ||||
|         // Void response = api.createUsersWithListInput(body); | ||||
|     public void testCreateUsersWithList() throws Exception { | ||||
|         User user1 = createUser(); | ||||
|         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 | ||||
|     public void deleteUserTest() { | ||||
|         String username = null; | ||||
|         // Void response = api.deleteUser(username); | ||||
|     public void testLoginUser() throws Exception { | ||||
|         User user = createUser(); | ||||
|         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 | ||||
|     public void getUserByNameTest() { | ||||
|         String username = null; | ||||
|         // User response = api.getUserByName(username); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|     public void logoutUser() throws Exception { | ||||
|         api.logoutUser().execute(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Logs user into the system | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void loginUserTest() { | ||||
|         String username = null; | ||||
|         String password = null; | ||||
|         // String response = api.loginUser(username, password); | ||||
|     private User createUser() { | ||||
|         User user = new User(); | ||||
|         user.setId(TestUtils.nextId()); | ||||
|         user.setUsername("fred"); | ||||
|         user.setFirstName("Fred"); | ||||
|         user.setLastName("Meyer"); | ||||
|         user.setEmail("fred@fredmeyer.com"); | ||||
|         user.setPassword("xxXXxx"); | ||||
|         user.setPhone("408-867-5309"); | ||||
|         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" | ||||
|     junit_version = "4.12" | ||||
|     rx_java_version = "1.1.3" | ||||
| 
 | ||||
|     jodatime_version = "2.9.3" | ||||
| } | ||||
| 
 | ||||
| dependencies { | ||||
| @ -108,10 +108,9 @@ dependencies { | ||||
|     compile "com.squareup.retrofit2:converter-gson:$retrofit_version" | ||||
|     compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version" | ||||
|     compile "io.reactivex:rxjava:$rx_java_version" | ||||
| 
 | ||||
| 
 | ||||
|     compile "io.swagger:swagger-annotations:$swagger_annotations_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" | ||||
| } | ||||
|  | ||||
| @ -16,6 +16,7 @@ lazy val root = (project in file(".")). | ||||
|       "io.reactivex" % "rxjava" % "1.1.3" % "compile", | ||||
|       "io.swagger" % "swagger-annotations" % "1.5.8" % "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", | ||||
|       "com.novocode" % "junit-interface" % "0.10" % "test" | ||||
|     ) | ||||
|  | ||||
| @ -32,8 +32,8 @@ Integer int32 = 56; // Integer | None | ||||
| Long int64 = 789L; // Long | None | ||||
| Float _float = 3.4F; // Float | None | ||||
| byte[] binary = B; // byte[] | None | ||||
| Date date = new Date(); // Date | None | ||||
| Date dateTime = new Date(); // Date | None | ||||
| LocalDate date = new LocalDate(); // LocalDate | None | ||||
| DateTime dateTime = new DateTime(); // DateTime | None | ||||
| String password = "password_example"; // String | None | ||||
| try { | ||||
|     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] | ||||
|  **_float** | **Float**| None | [optional] | ||||
|  **binary** | **byte[]**| None | [optional] | ||||
|  **date** | **Date**| None | [optional] | ||||
|  **dateTime** | **Date**| None | [optional] | ||||
|  **date** | **LocalDate**| None | [optional] | ||||
|  **dateTime** | **DateTime**| None | [optional] | ||||
|  **password** | **String**| None | [optional] | ||||
| 
 | ||||
| ### Return type | ||||
|  | ||||
| @ -13,8 +13,8 @@ Name | Type | Description | Notes | ||||
| **string** | **String** |  |  [optional] | ||||
| **_byte** | **byte[]** |  |  | ||||
| **binary** | **byte[]** |  |  [optional] | ||||
| **date** | [**Date**](Date.md) |  |  | ||||
| **dateTime** | [**Date**](Date.md) |  |  [optional] | ||||
| **date** | [**LocalDate**](LocalDate.md) |  |  | ||||
| **dateTime** | [**DateTime**](DateTime.md) |  |  [optional] | ||||
| **uuid** | **String** |  |  [optional] | ||||
| **password** | **String** |  |  | ||||
| 
 | ||||
|  | ||||
| @ -5,7 +5,7 @@ | ||||
| Name | Type | Description | Notes | ||||
| ------------ | ------------- | ------------- | ------------- | ||||
| **uuid** | **String** |  |  [optional] | ||||
| **dateTime** | [**Date**](Date.md) |  |  [optional] | ||||
| **dateTime** | [**DateTime**](DateTime.md) |  |  [optional] | ||||
| **map** | [**Map<String, Animal>**](Animal.md) |  |  [optional] | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -7,7 +7,7 @@ Name | Type | Description | Notes | ||||
| **id** | **Long** |  |  [optional] | ||||
| **petId** | **Long** |  |  [optional] | ||||
| **quantity** | **Integer** |  |  [optional] | ||||
| **shipDate** | [**Date**](Date.md) |  |  [optional] | ||||
| **shipDate** | [**DateTime**](DateTime.md) |  |  [optional] | ||||
| **status** | [**StatusEnum**](#StatusEnum) | Order Status |  [optional] | ||||
| **complete** | **Boolean** |  |  [optional] | ||||
| 
 | ||||
|  | ||||
| @ -132,6 +132,11 @@ | ||||
|       <artifactId>org.apache.oltu.oauth2.client</artifactId> | ||||
|       <version>${oltu-version}</version> | ||||
|     </dependency> | ||||
|     <dependency> | ||||
|       <groupId>joda-time</groupId> | ||||
|       <artifactId>joda-time</artifactId> | ||||
|       <version>${jodatime-version}</version> | ||||
|     </dependency> | ||||
|     <dependency> | ||||
|       <groupId>io.reactivex</groupId> | ||||
|       <artifactId>rxjava</artifactId> | ||||
| @ -155,7 +160,7 @@ | ||||
|     <swagger-core-version>1.5.8</swagger-core-version> | ||||
|     <retrofit-version>2.0.2</retrofit-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> | ||||
|     <maven-plugin-version>1.0.0</maven-plugin-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.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.Retrofit; | ||||
| @ -19,6 +23,9 @@ import retrofit2.converter.scalars.ScalarsConverterFactory; | ||||
| import com.google.gson.Gson; | ||||
| import com.google.gson.GsonBuilder; | ||||
| 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.OkHttpClient; | ||||
| import okhttp3.RequestBody; | ||||
| @ -107,6 +114,8 @@ public class ApiClient { | ||||
|    public void createDefaultAdapter() { | ||||
|         Gson gson = new GsonBuilder() | ||||
|                 .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") | ||||
|                 .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter()) | ||||
|                 .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()) | ||||
|                 .create(); | ||||
| 
 | ||||
|         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; | ||||
| 
 | ||||
| @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 { | ||||
|   /** | ||||
|    * Check if the given array contains the given value (with case-insensitive comparison). | ||||
|  | ||||
| @ -8,8 +8,9 @@ import retrofit2.http.*; | ||||
| 
 | ||||
| import okhttp3.RequestBody; | ||||
| 
 | ||||
| import org.joda.time.LocalDate; | ||||
| import java.math.BigDecimal; | ||||
| import java.util.Date; | ||||
| import org.joda.time.DateTime; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| @ -38,7 +39,7 @@ public interface FakeApi { | ||||
|   @FormUrlEncoded | ||||
|   @POST("fake") | ||||
|   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.ApiModelProperty; | ||||
| import java.math.BigDecimal; | ||||
| import java.util.Date; | ||||
| import org.joda.time.DateTime; | ||||
| import org.joda.time.LocalDate; | ||||
| 
 | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| 
 | ||||
| @ -42,10 +43,10 @@ public class FormatTest   { | ||||
|   private byte[] binary = null; | ||||
| 
 | ||||
|   @SerializedName("date") | ||||
|   private Date date = null; | ||||
|   private LocalDate date = null; | ||||
| 
 | ||||
|   @SerializedName("dateTime") | ||||
|   private Date dateTime = null; | ||||
|   private DateTime dateTime = null; | ||||
| 
 | ||||
|   @SerializedName("uuid") | ||||
|   private String uuid = null; | ||||
| @ -156,20 +157,20 @@ public class FormatTest   { | ||||
|   /** | ||||
|    **/ | ||||
|   @ApiModelProperty(required = true, value = "") | ||||
|   public Date getDate() { | ||||
|   public LocalDate getDate() { | ||||
|     return date; | ||||
|   } | ||||
|   public void setDate(Date date) { | ||||
|   public void setDate(LocalDate date) { | ||||
|     this.date = date; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    **/ | ||||
|   @ApiModelProperty(value = "") | ||||
|   public Date getDateTime() { | ||||
|   public DateTime getDateTime() { | ||||
|     return dateTime; | ||||
|   } | ||||
|   public void setDateTime(Date dateTime) { | ||||
|   public void setDateTime(DateTime dateTime) { | ||||
|     this.dateTime = dateTime; | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -4,10 +4,10 @@ import java.util.Objects; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import io.swagger.client.model.Animal; | ||||
| import java.util.Date; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import org.joda.time.DateTime; | ||||
| 
 | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| 
 | ||||
| @ -21,7 +21,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass   { | ||||
|   private String uuid = null; | ||||
| 
 | ||||
|   @SerializedName("dateTime") | ||||
|   private Date dateTime = null; | ||||
|   private DateTime dateTime = null; | ||||
| 
 | ||||
|   @SerializedName("map") | ||||
|   private Map<String, Animal> map = new HashMap<String, Animal>(); | ||||
| @ -39,10 +39,10 @@ public class MixedPropertiesAndAdditionalPropertiesClass   { | ||||
|   /** | ||||
|    **/ | ||||
|   @ApiModelProperty(value = "") | ||||
|   public Date getDateTime() { | ||||
|   public DateTime getDateTime() { | ||||
|     return dateTime; | ||||
|   } | ||||
|   public void setDateTime(Date dateTime) { | ||||
|   public void setDateTime(DateTime dateTime) { | ||||
|     this.dateTime = dateTime; | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -3,7 +3,7 @@ package io.swagger.client.model; | ||||
| import java.util.Objects; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import java.util.Date; | ||||
| import org.joda.time.DateTime; | ||||
| 
 | ||||
| import com.google.gson.annotations.SerializedName; | ||||
| 
 | ||||
| @ -23,7 +23,7 @@ public class Order   { | ||||
|   private Integer quantity = null; | ||||
| 
 | ||||
|   @SerializedName("shipDate") | ||||
|   private Date shipDate = null; | ||||
|   private DateTime shipDate = null; | ||||
| 
 | ||||
| 
 | ||||
|   /** | ||||
| @ -90,10 +90,10 @@ public class Order   { | ||||
|   /** | ||||
|    **/ | ||||
|   @ApiModelProperty(value = "") | ||||
|   public Date getShipDate() { | ||||
|   public DateTime getShipDate() { | ||||
|     return shipDate; | ||||
|   } | ||||
|   public void setShipDate(Date shipDate) { | ||||
|   public void setShipDate(DateTime shipDate) { | ||||
|     this.shipDate = shipDate; | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -1,137 +1,254 @@ | ||||
| package io.swagger.client.api; | ||||
| 
 | ||||
| import io.swagger.client.ApiClient; | ||||
| import io.swagger.client.model.Pet; | ||||
| import io.swagger.client.model.ModelApiResponse; | ||||
| import io.swagger.client.CollectionFormats.*; | ||||
| import io.swagger.client.model.*; | ||||
| 
 | ||||
| import java.io.BufferedWriter; | ||||
| import java.io.File; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import java.io.FileWriter; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.Arrays; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * API tests for PetApi | ||||
|  */ | ||||
| import org.junit.*; | ||||
| 
 | ||||
| import okhttp3.MediaType; | ||||
| import okhttp3.RequestBody; | ||||
| 
 | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| public class PetApiTest { | ||||
| 
 | ||||
|     private PetApi api; | ||||
|     PetApi api = null; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setup() { | ||||
|         api = new ApiClient().createService(PetApi.class); | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     /** | ||||
|      * Add a new pet to the store | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void addPetTest() { | ||||
|         Pet body = null; | ||||
|         // Void response = api.addPet(body); | ||||
|     public void testCreateAndGetPet() throws Exception { | ||||
|         final Pet pet = createRandomPet(); | ||||
|         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 | ||||
|     public void deletePetTest() { | ||||
|         Long petId = null; | ||||
|         String apiKey = null; | ||||
|         // Void response = api.deletePet(petId, apiKey); | ||||
|     public void testUpdatePet() throws Exception { | ||||
|         final Pet pet = createRandomPet(); | ||||
|         pet.setName("programmer"); | ||||
| 
 | ||||
|         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 | ||||
|     public void findPetsByStatusTest() { | ||||
|         List<String> status = null; | ||||
|         // List<Pet> response = api.findPetsByStatus(status); | ||||
|     public void testFindPetsByStatus() throws Exception { | ||||
|         final Pet pet = createRandomPet(); | ||||
|         pet.setName("programmer"); | ||||
|         pet.setStatus(Pet.StatusEnum.AVAILABLE); | ||||
| 
 | ||||
|         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); | ||||
|                     } | ||||
|                 }); | ||||
| 
 | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 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); | ||||
|     public void testFindPetsByTags() throws Exception { | ||||
|         final Pet pet = createRandomPet(); | ||||
|         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 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Find pet by ID | ||||
|      * | ||||
|      * Returns a single pet | ||||
|      */ | ||||
|     @Test | ||||
|     public void getPetByIdTest() { | ||||
|         Long petId = null; | ||||
|         // Pet response = api.getPetById(petId); | ||||
|     public void testUpdatePetWithForm() throws Exception { | ||||
|         final Pet pet = createRandomPet(); | ||||
|         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 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Update an existing pet | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void updatePetTest() { | ||||
|         Pet body = null; | ||||
|         // Void response = api.updatePet(body); | ||||
|     public void testDeletePet() throws Exception { | ||||
|         Pet pet = createRandomPet(); | ||||
|         api.addPet(pet).subscribe(SkeletonSubscriber.failTestOnError()); | ||||
| 
 | ||||
|         // 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 | ||||
|                     public void onError(Throwable e) { | ||||
|                         // expected, because the pet has been deleted. | ||||
|                     } | ||||
|                 }); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Updates a pet in the store with form data | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void updatePetWithFormTest() { | ||||
|         Long petId = null; | ||||
|         String name = null; | ||||
|         String status = null; | ||||
|         // Void response = api.updatePetWithForm(petId, name, status); | ||||
|     public void testUploadFile() throws Exception { | ||||
|         File file = File.createTempFile("test", "hello.txt"); | ||||
|         BufferedWriter writer = new BufferedWriter(new FileWriter(file)); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|         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... | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * uploads an image | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void uploadFileTest() { | ||||
|         Long petId = null; | ||||
|         String additionalMetadata = null; | ||||
|         File file = null; | ||||
|         // ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file); | ||||
|     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()); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|         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; | ||||
| 
 | ||||
| import io.swagger.client.ApiClient; | ||||
| import io.swagger.client.model.Order; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import io.swagger.client.model.*; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.lang.reflect.Field; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * API tests for StoreApi | ||||
|  */ | ||||
| public class StoreApiTest { | ||||
| import org.joda.time.DateTime; | ||||
| import org.joda.time.DateTimeZone; | ||||
| import org.junit.*; | ||||
| 
 | ||||
|     private StoreApi api; | ||||
| import retrofit2.Response; | ||||
| 
 | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| public class StoreApiTest { | ||||
|     StoreApi api = null; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setup() { | ||||
|         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 | ||||
|     public void deleteOrderTest() { | ||||
|         String orderId = null; | ||||
|         // Void response = api.deleteOrder(orderId); | ||||
|     public void testGetInventory() throws Exception { | ||||
|         api.getInventory().subscribe(new SkeletonSubscriber<Map<String, Integer>>() { | ||||
|             @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 | ||||
|     public void getInventoryTest() { | ||||
|         // Map<String, Integer> response = api.getInventory(); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|     public void testPlaceOrder() throws Exception { | ||||
|         final Order order = createOrder(); | ||||
|         api.placeOrder(order).subscribe(SkeletonSubscriber.failTestOnError()); | ||||
|         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 | ||||
|     public void getOrderByIdTest() { | ||||
|         Long orderId = null; | ||||
|         // Order response = api.getOrderById(orderId); | ||||
|     public void testDeleteOrder() throws Exception { | ||||
|         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(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 | ||||
|                                public void onError(Throwable e) { | ||||
|                                    // should not find deleted order. | ||||
|                                } | ||||
|                            } | ||||
|                 ); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Place an order for a pet | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void placeOrderTest() { | ||||
|         Order body = null; | ||||
|         // Order response = api.placeOrder(body); | ||||
|     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); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|         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; | ||||
| 
 | ||||
| import io.swagger.client.ApiClient; | ||||
| import io.swagger.client.model.User; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import io.swagger.client.model.*; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import java.util.Arrays; | ||||
| 
 | ||||
| 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 { | ||||
| 
 | ||||
|     private UserApi api; | ||||
|     UserApi api = null; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setup() { | ||||
|         api = new ApiClient().createService(UserApi.class); | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     /** | ||||
|      * Create user | ||||
|      * | ||||
|      * This can only be done by the logged in user. | ||||
|      */ | ||||
|     @Test | ||||
|     public void createUserTest() { | ||||
|         User body = null; | ||||
|         // Void response = api.createUser(body); | ||||
|     public void testCreateUser() throws Exception { | ||||
|         final User user = createUser(); | ||||
| 
 | ||||
|         // 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 | ||||
|     public void createUsersWithArrayInputTest() { | ||||
|         List<User> body = null; | ||||
|         // Void response = api.createUsersWithArrayInput(body); | ||||
|     public void testCreateUsersWithArray() throws Exception { | ||||
|         final User user1 = createUser(); | ||||
|         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 | ||||
|     public void createUsersWithListInputTest() { | ||||
|         List<User> body = null; | ||||
|         // Void response = api.createUsersWithListInput(body); | ||||
|     public void testCreateUsersWithList() throws Exception { | ||||
|         final User user1 = createUser(); | ||||
|         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 | ||||
|     public void deleteUserTest() { | ||||
|         String username = null; | ||||
|         // Void response = api.deleteUser(username); | ||||
|     public void testLoginUser() throws Exception { | ||||
|         User user = createUser(); | ||||
|         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 | ||||
|     public void getUserByNameTest() { | ||||
|         String username = null; | ||||
|         // User response = api.getUserByName(username); | ||||
| 
 | ||||
|         // TODO: test validations | ||||
|     public void logoutUser() throws Exception { | ||||
|         api.logoutUser(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Logs user into the system | ||||
|      * | ||||
|      *  | ||||
|      */ | ||||
|     @Test | ||||
|     public void loginUserTest() { | ||||
|         String username = null; | ||||
|         String password = null; | ||||
|         // String response = api.loginUser(username, password); | ||||
|     private User createUser() { | ||||
|         User user = new User(); | ||||
|         user.setId(System.currentTimeMillis()); | ||||
|         user.setUsername("fred"); | ||||
|         user.setFirstName("Fred"); | ||||
|         user.setLastName("Meyer"); | ||||
|         user.setEmail("fred@fredmeyer.com"); | ||||
|         user.setPassword("xxXXxx"); | ||||
|         user.setPhone("408-867-5309"); | ||||
|         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