forked from loafle/openapi-generator-original
Merge branch 'develop_2.0' into develop_2.0_objc_jsonmodel
Conflicts: pom.xml
This commit is contained in:
commit
19c05eefab
@ -1,3 +1,4 @@
|
||||
sudo: false
|
||||
language: java
|
||||
script: mvn verify
|
||||
jdk:
|
||||
|
@ -11,6 +11,7 @@ import java.util.*;
|
||||
{{/imports}}
|
||||
|
||||
import com.sun.jersey.multipart.FormDataMultiPart;
|
||||
import com.sun.jersey.multipart.file.FileDataBodyPart;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@ -77,7 +78,8 @@ public class {{classname}} {
|
||||
mp.field("{{baseName}}", ApiInvoker.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
{{/notFile}}{{#isFile}}
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
mp.field("{{baseName}}", file.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
{{/isFile}}{{/formParams}}
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
@ -96,14 +98,9 @@ public class {{classname}} {
|
||||
return {{#returnType}}null{{/returnType}};
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return {{#returnType}} null{{/returnType}};
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
@ -16,6 +16,7 @@ import com.sun.jersey.multipart.FormDataMultiPart;
|
||||
import javax.ws.rs.core.Response.Status.Family;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -83,11 +84,19 @@ public class ApiInvoker {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDateTime((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(Object o : (Collection)param) {
|
||||
if(b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
|
||||
public void enableDebug() {
|
||||
isDebug = true;
|
||||
}
|
||||
@ -217,7 +226,7 @@ public class ApiInvoker {
|
||||
}
|
||||
else if ("DELETE".equals(method)) {
|
||||
if(body == null)
|
||||
response = builder.delete(ClientResponse.class, serialize(body));
|
||||
response = builder.delete(ClientResponse.class);
|
||||
else
|
||||
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
|
||||
}
|
||||
@ -228,12 +237,26 @@ public class ApiInvoker {
|
||||
return null;
|
||||
}
|
||||
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
|
||||
if(response.hasEntity()) {
|
||||
return (String) response.getEntity(String.class);
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = "error";
|
||||
if(response.hasEntity()) {
|
||||
try{
|
||||
message = String.valueOf(response.getEntity(String.class));
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new ApiException(
|
||||
response.getClientResponseStatus().getStatusCode(),
|
||||
response.getEntity(String.class));
|
||||
message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,11 +157,10 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0-M1</swagger-annotations-version>
|
||||
<jersey-version>1.7</jersey-version>
|
||||
<jackson-version>2.1.4</jackson-version>
|
||||
<swagger-annotations-version>1.5.3-M1</swagger-annotations-version>
|
||||
<jersey-version>1.18</jersey-version>
|
||||
<jackson-version>2.4.2</jackson-version>
|
||||
<jodatime-version>2.3</jodatime-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
</properties>
|
||||
|
@ -104,7 +104,7 @@
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
@ -226,7 +226,7 @@
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<zip-version>1.3.2</zip-version>
|
||||
<jetty-version>9.0.7.v20131107</jetty-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey2-version>2.4.1</jersey2-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
3
pom.xml
3
pom.xml
@ -288,6 +288,7 @@
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/client/petstore/objc</module>
|
||||
<module>samples/client/petstore/java</module>
|
||||
</modules>
|
||||
</profile>
|
||||
</profiles>
|
||||
@ -363,7 +364,7 @@
|
||||
<swagger-parser-version>1.0.3</swagger-parser-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>2.3.4</felix-version>
|
||||
<swagger-core-version>1.5.4-M1-SNAPSHOT</swagger-core-version>
|
||||
<swagger-core-version>1.5.3-M1</swagger-core-version>
|
||||
<scala-test-version>2.1.4</scala-test-version>
|
||||
<commons-io-version>2.3</commons-io-version>
|
||||
<commons-cli-version>1.2</commons-cli-version>
|
||||
|
@ -157,11 +157,10 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0-M1</swagger-annotations-version>
|
||||
<jersey-version>1.7</jersey-version>
|
||||
<jackson-version>2.1.4</jackson-version>
|
||||
<swagger-annotations-version>1.5.3-M1</swagger-annotations-version>
|
||||
<jersey-version>1.18</jersey-version>
|
||||
<jackson-version>2.4.2</jackson-version>
|
||||
<jodatime-version>2.3</jodatime-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
</properties>
|
||||
|
@ -16,6 +16,7 @@ import com.sun.jersey.multipart.FormDataMultiPart;
|
||||
import javax.ws.rs.core.Response.Status.Family;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -83,11 +84,19 @@ public class ApiInvoker {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDateTime((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(Object o : (Collection)param) {
|
||||
if(b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
|
||||
public void enableDebug() {
|
||||
isDebug = true;
|
||||
}
|
||||
@ -217,7 +226,7 @@ public class ApiInvoker {
|
||||
}
|
||||
else if ("DELETE".equals(method)) {
|
||||
if(body == null)
|
||||
response = builder.delete(ClientResponse.class, serialize(body));
|
||||
response = builder.delete(ClientResponse.class);
|
||||
else
|
||||
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
|
||||
}
|
||||
@ -228,12 +237,26 @@ public class ApiInvoker {
|
||||
return null;
|
||||
}
|
||||
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
|
||||
if(response.hasEntity()) {
|
||||
return (String) response.getEntity(String.class);
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = "error";
|
||||
if(response.hasEntity()) {
|
||||
try{
|
||||
message = String.valueOf(response.getEntity(String.class));
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new ApiException(
|
||||
response.getClientResponseStatus().getStatusCode(),
|
||||
response.getEntity(String.class));
|
||||
message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
|
||||
import com.sun.jersey.multipart.FormDataMultiPart;
|
||||
import com.sun.jersey.multipart.file.FileDataBodyPart;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@ -76,14 +77,9 @@ public class PetApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addPet (Pet body) throws ApiException {
|
||||
@ -126,14 +122,9 @@ public class PetApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Pet> findPetsByStatus (List<String> status) throws ApiException {
|
||||
@ -178,14 +169,9 @@ public class PetApi {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Pet> findPetsByTags (List<String> tags) throws ApiException {
|
||||
@ -230,14 +216,9 @@ public class PetApi {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Pet getPetById (Long petId) throws ApiException {
|
||||
@ -281,14 +262,9 @@ public class PetApi {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
|
||||
@ -340,14 +316,9 @@ public class PetApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deletePet (String apiKey, Long petId) throws ApiException {
|
||||
@ -392,14 +363,9 @@ public class PetApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException {
|
||||
@ -431,7 +397,8 @@ public class PetApi {
|
||||
mp.field("additionalMetadata", ApiInvoker.parameterToString(additionalMetadata), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
|
||||
hasFields = true;
|
||||
mp.field("file", file, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
mp.field("file", file.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
@ -451,13 +418,8 @@ public class PetApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.util.Map;
|
||||
import io.swagger.client.model.Order;
|
||||
|
||||
import com.sun.jersey.multipart.FormDataMultiPart;
|
||||
import com.sun.jersey.multipart.file.FileDataBodyPart;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@ -76,14 +77,9 @@ public class StoreApi {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Order placeOrder (Order body) throws ApiException {
|
||||
@ -126,14 +122,9 @@ public class StoreApi {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Order getOrderById (String orderId) throws ApiException {
|
||||
@ -177,14 +168,9 @@ public class StoreApi {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteOrder (String orderId) throws ApiException {
|
||||
@ -228,13 +214,8 @@ public class StoreApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import io.swagger.client.model.User;
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.jersey.multipart.FormDataMultiPart;
|
||||
import com.sun.jersey.multipart.file.FileDataBodyPart;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@ -76,14 +77,9 @@ public class UserApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createUsersWithArrayInput (List<User> body) throws ApiException {
|
||||
@ -126,14 +122,9 @@ public class UserApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createUsersWithListInput (List<User> body) throws ApiException {
|
||||
@ -176,14 +167,9 @@ public class UserApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String loginUser (String username, String password) throws ApiException {
|
||||
@ -230,14 +216,9 @@ public class UserApi {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void logoutUser () throws ApiException {
|
||||
@ -280,14 +261,9 @@ public class UserApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public User getUserByName (String username) throws ApiException {
|
||||
@ -331,14 +307,9 @@ public class UserApi {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateUser (String username, User body) throws ApiException {
|
||||
@ -382,14 +353,9 @@ public class UserApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteUser (String username) throws ApiException {
|
||||
@ -433,13 +399,8 @@ public class UserApi {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package io.swagger.client.model;
|
||||
|
||||
|
||||
import com.wordnik.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
@ApiModel(description = "")
|
||||
public class ApiResponse {
|
||||
|
||||
private Integer code = null;
|
||||
private String type = null;
|
||||
private String message = null;
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(required = false, value = "")
|
||||
@JsonProperty("code")
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(required = false, value = "")
|
||||
@JsonProperty("type")
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**/
|
||||
@ApiModelProperty(required = false, value = "")
|
||||
@JsonProperty("message")
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ApiResponse {\n");
|
||||
|
||||
sb.append(" code: ").append(code).append("\n");
|
||||
sb.append(" type: ").append(type).append("\n");
|
||||
sb.append(" message: ").append(message).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
package io.swagger.petstore.test;
|
||||
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.api.*;
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.*;
|
||||
|
||||
public class PetApiTest {
|
||||
PetApi api = null;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
api = new PetApi();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndGetPet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
api.addPet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
assertNotNull(fetched);
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertNotNull(fetched.getCategory());
|
||||
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("programmer");
|
||||
|
||||
api.updatePet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
assertNotNull(fetched);
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertNotNull(fetched.getCategory());
|
||||
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindPetsByStatus() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("programmer");
|
||||
pet.setStatus(Pet.StatusEnum.available);
|
||||
|
||||
api.updatePet(pet);
|
||||
|
||||
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"}));
|
||||
assertNotNull(pets);
|
||||
|
||||
boolean found = false;
|
||||
for(Pet fetched : pets) {
|
||||
if(fetched.getId().equals(pet.getId())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(found);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindPetsByTags() throws Exception {
|
||||
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);
|
||||
|
||||
List<Pet> pets = api.findPetsByTags(Arrays.asList(new String[]{"friendly"}));
|
||||
assertNotNull(pets);
|
||||
|
||||
boolean found = false;
|
||||
for(Pet fetched : pets) {
|
||||
if(fetched.getId().equals(pet.getId())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePetWithForm() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("frank");
|
||||
api.addPet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
|
||||
api.updatePetWithForm(String.valueOf(fetched.getId()), "furt", null);
|
||||
Pet updated = api.getPetById(fetched.getId());
|
||||
|
||||
assertEquals(updated.getName(), fetched.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
api.addPet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
api.deletePet(null, fetched.getId());
|
||||
|
||||
try {
|
||||
fetched = api.getPetById(fetched.getId());
|
||||
fail("expected an error");
|
||||
}
|
||||
catch (ApiException e) {
|
||||
assertEquals(404, e.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadFile() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
api.addPet(pet);
|
||||
|
||||
File file = new File("hello.txt");
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||
writer.write("Hello world!");
|
||||
writer.close();
|
||||
|
||||
api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath()));
|
||||
}
|
||||
|
||||
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,68 @@
|
||||
package io.swagger.petstore.test;
|
||||
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.api.*;
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.*;
|
||||
|
||||
public class StoreApiTest {
|
||||
StoreApi api = null;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
api = new StoreApi();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInventory() throws Exception {
|
||||
Map<String, Integer> inventory = api.getInventory();
|
||||
assertTrue(inventory.keySet().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlaceOrder() throws Exception {
|
||||
Order order = createOrder();
|
||||
api.placeOrder(order);
|
||||
|
||||
Order fetched = api.getOrderById(String.valueOf(order.getId()));
|
||||
assertEquals(order.getId(), fetched.getId());
|
||||
assertEquals(order.getPetId(), fetched.getPetId());
|
||||
assertEquals(order.getQuantity(), fetched.getQuantity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteOrder() throws Exception {
|
||||
Order order = createOrder();
|
||||
api.placeOrder(order);
|
||||
|
||||
Order fetched = api.getOrderById(String.valueOf(order.getId()));
|
||||
assertEquals(fetched.getId(), order.getId());
|
||||
|
||||
api.deleteOrder(String.valueOf(order.getId()));
|
||||
|
||||
try {
|
||||
api.getOrderById(String.valueOf(order.getId()));
|
||||
// fail("expected an error");
|
||||
}
|
||||
catch (ApiException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
private Order createOrder() {
|
||||
Order order = new Order();
|
||||
order.setId(new Long(System.currentTimeMillis()));
|
||||
order.setPetId(new Long(200));
|
||||
order.setQuantity(new Integer(13));
|
||||
order.setShipDate(new java.util.Date());
|
||||
order.setStatus(Order.StatusEnum.placed);
|
||||
order.setComplete(true);
|
||||
|
||||
return order;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package io.swagger.petstore.test;
|
||||
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.api.*;
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.*;
|
||||
|
||||
public class UserApiTest {
|
||||
UserApi api = null;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
api = new UserApi();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUser() throws Exception {
|
||||
User user = createUser();
|
||||
|
||||
api.createUser(user);
|
||||
|
||||
User fetched = api.getUserByName(user.getUsername());
|
||||
assertEquals(user.getId(), fetched.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUsersWithArray() throws Exception {
|
||||
User user1 = createUser();
|
||||
user1.setUsername("abc123");
|
||||
User user2 = createUser();
|
||||
user2.setUsername("123abc");
|
||||
|
||||
api.createUsersWithArrayInput(Arrays.asList(new User[]{user1, user2}));
|
||||
|
||||
User fetched = api.getUserByName(user1.getUsername());
|
||||
assertEquals(user1.getId(), fetched.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUsersWithList() throws Exception {
|
||||
User user1 = createUser();
|
||||
user1.setUsername("abc123");
|
||||
User user2 = createUser();
|
||||
user2.setUsername("123abc");
|
||||
|
||||
api.createUsersWithListInput(Arrays.asList(new User[]{user1, user2}));
|
||||
|
||||
User fetched = api.getUserByName(user1.getUsername());
|
||||
assertEquals(user1.getId(), fetched.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginUser() throws Exception {
|
||||
User user = createUser();
|
||||
api.createUser(user);
|
||||
|
||||
String token = api.loginUser(user.getUsername(), user.getPassword());
|
||||
assertTrue(token.startsWith("logged in user session:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logoutUser() throws Exception {
|
||||
api.logoutUser();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
@ -6,8 +6,7 @@
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
api = [[SWGPetApi alloc ]init];
|
||||
// [[SWGApiClient sharedClientFromPool]setLoggingEnabled:true];
|
||||
[SWGPetApi setBasePath:@"http://localhost:8002/api"];
|
||||
[SWGPetApi setBasePath:@"http://localhost:8080/api"];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
|
@ -30,7 +30,7 @@
|
||||
<stopKey>alpha</stopKey>
|
||||
<stopPort>9099</stopPort>
|
||||
<httpConnector>
|
||||
<port>8002</port>
|
||||
<port>8080</port>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
@ -1,197 +0,0 @@
|
||||
require "uri"
|
||||
|
||||
class StoreApi
|
||||
basePath = "http://petstore.swagger.io/v2"
|
||||
# apiInvoker = APIInvoker
|
||||
|
||||
def self.escapeString(string)
|
||||
URI.encode(string.to_s)
|
||||
end
|
||||
|
||||
|
||||
def self.getInventory ( opts={})
|
||||
query_param_keys = []
|
||||
|
||||
|
||||
|
||||
# set default values and merge with input
|
||||
options = {
|
||||
|
||||
}.merge(opts)
|
||||
|
||||
#resource path
|
||||
path = "/store/inventory".sub('{format}','json')
|
||||
|
||||
# pull querystring keys from options
|
||||
queryopts = options.select do |key,value|
|
||||
query_param_keys.include? key
|
||||
end
|
||||
|
||||
# header parameters, if any
|
||||
headers = {}
|
||||
|
||||
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
|
||||
|
||||
# form parameters
|
||||
form_parameter_hash = {}
|
||||
|
||||
|
||||
|
||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||
|
||||
response.map {|response| map.new(response) }
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
def self.placeOrder (body, opts={})
|
||||
query_param_keys = []
|
||||
|
||||
|
||||
|
||||
# set default values and merge with input
|
||||
options = {
|
||||
:'body' => body
|
||||
|
||||
}.merge(opts)
|
||||
|
||||
#resource path
|
||||
path = "/store/order".sub('{format}','json')
|
||||
|
||||
# pull querystring keys from options
|
||||
queryopts = options.select do |key,value|
|
||||
query_param_keys.include? key
|
||||
end
|
||||
|
||||
# header parameters, if any
|
||||
headers = {}
|
||||
|
||||
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
|
||||
if body != nil
|
||||
if body.is_a?(Array)
|
||||
array = Array.new
|
||||
body.each do |item|
|
||||
if item.respond_to?("to_body".to_sym)
|
||||
array.push item.to_body
|
||||
else
|
||||
array.push item
|
||||
end
|
||||
end
|
||||
post_body = array
|
||||
|
||||
else
|
||||
if body.respond_to?("to_body".to_sym)
|
||||
post_body = body.to_body
|
||||
else
|
||||
post_body = body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# form parameters
|
||||
form_parameter_hash = {}
|
||||
|
||||
|
||||
|
||||
response = Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||
Order.new(response)
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
def self.getOrderById (order_id, opts={})
|
||||
query_param_keys = []
|
||||
|
||||
|
||||
|
||||
# set default values and merge with input
|
||||
options = {
|
||||
:'order_id' => order_id
|
||||
|
||||
}.merge(opts)
|
||||
|
||||
#resource path
|
||||
path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id))
|
||||
|
||||
|
||||
# pull querystring keys from options
|
||||
queryopts = options.select do |key,value|
|
||||
query_param_keys.include? key
|
||||
end
|
||||
|
||||
# header parameters, if any
|
||||
headers = {}
|
||||
|
||||
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
|
||||
|
||||
# form parameters
|
||||
form_parameter_hash = {}
|
||||
|
||||
|
||||
|
||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||
Order.new(response)
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
def self.deleteOrder (order_id, opts={})
|
||||
query_param_keys = []
|
||||
|
||||
|
||||
|
||||
# set default values and merge with input
|
||||
options = {
|
||||
:'order_id' => order_id
|
||||
|
||||
}.merge(opts)
|
||||
|
||||
#resource path
|
||||
path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id))
|
||||
|
||||
|
||||
# pull querystring keys from options
|
||||
queryopts = options.select do |key,value|
|
||||
query_param_keys.include? key
|
||||
end
|
||||
|
||||
# header parameters, if any
|
||||
headers = {}
|
||||
|
||||
|
||||
|
||||
# http body (model)
|
||||
post_body = nil
|
||||
|
||||
|
||||
# form parameters
|
||||
form_parameter_hash = {}
|
||||
|
||||
|
||||
|
||||
|
||||
Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user