Skip to content

Commit 8b98a92

Browse files
committed
adds tests, fixes for java templates
1 parent a2dc767 commit 8b98a92

File tree

9 files changed

+174
-206
lines changed

9 files changed

+174
-206
lines changed

modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.sun.jersey.multipart.FormDataMultiPart;
1616
import javax.ws.rs.core.Response.Status.Family;
1717
import javax.ws.rs.core.MediaType;
1818

19+
import java.util.Collection;
1920
import java.util.Map;
2021
import java.util.HashMap;
2122
import java.util.List;
@@ -83,11 +84,19 @@ public class ApiInvoker {
8384
return "";
8485
} else if (param instanceof Date) {
8586
return formatDateTime((Date) param);
87+
} else if (param instanceof Collection) {
88+
StringBuilder b = new StringBuilder();
89+
for(Object o : (Collection)param) {
90+
if(b.length() > 0) {
91+
b.append(",");
92+
}
93+
b.append(String.valueOf(o));
94+
}
95+
return b.toString();
8696
} else {
8797
return String.valueOf(param);
8898
}
8999
}
90-
91100
public void enableDebug() {
92101
isDebug = true;
93102
}

modules/swagger-generator/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<id>start-jetty</id>
105105
<phase>pre-integration-test</phase>
106106
<goals>
107-
<goal>run</goal>
107+
<goal>start</goal>
108108
</goals>
109109
<configuration>
110110
<scanIntervalSeconds>0</scanIntervalSeconds>
@@ -226,7 +226,7 @@
226226
<maven-plugin-version>1.0.0</maven-plugin-version>
227227
<servlet-api-version>2.5</servlet-api-version>
228228
<zip-version>1.3.2</zip-version>
229-
<jetty-version>9.0.7.v20131107</jetty-version>
229+
<jetty-version>9.2.9.v20150224</jetty-version>
230230
<jersey2-version>2.4.1</jersey2-version>
231231
</properties>
232232
</project>

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
</activation>
289289
<modules>
290290
<module>samples/client/petstore/objc</module>
291+
<module>samples/client/petstore/java</module>
291292
</modules>
292293
</profile>
293294
</profiles>

samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import javax.ws.rs.core.Response.Status.Family;
1717
import javax.ws.rs.core.MediaType;
1818

19+
import java.util.Collection;
1920
import java.util.Map;
2021
import java.util.HashMap;
2122
import java.util.List;
@@ -83,11 +84,19 @@ public static String parameterToString(Object param) {
8384
return "";
8485
} else if (param instanceof Date) {
8586
return formatDateTime((Date) param);
87+
} else if (param instanceof Collection) {
88+
StringBuilder b = new StringBuilder();
89+
for(Object o : (Collection)param) {
90+
if(b.length() > 0) {
91+
b.append(",");
92+
}
93+
b.append(String.valueOf(o));
94+
}
95+
return b.toString();
8696
} else {
8797
return String.valueOf(param);
8898
}
8999
}
90-
91100
public void enableDebug() {
92101
isDebug = true;
93102
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package io.swagger.client.model;
2+
3+
4+
import com.wordnik.swagger.annotations.*;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
8+
@ApiModel(description = "")
9+
public class ApiResponse {
10+
11+
private Integer code = null;
12+
private String type = null;
13+
private String message = null;
14+
15+
16+
/**
17+
**/
18+
@ApiModelProperty(required = false, value = "")
19+
@JsonProperty("code")
20+
public Integer getCode() {
21+
return code;
22+
}
23+
public void setCode(Integer code) {
24+
this.code = code;
25+
}
26+
27+
28+
/**
29+
**/
30+
@ApiModelProperty(required = false, value = "")
31+
@JsonProperty("type")
32+
public String getType() {
33+
return type;
34+
}
35+
public void setType(String type) {
36+
this.type = type;
37+
}
38+
39+
40+
/**
41+
**/
42+
@ApiModelProperty(required = false, value = "")
43+
@JsonProperty("message")
44+
public String getMessage() {
45+
return message;
46+
}
47+
public void setMessage(String message) {
48+
this.message = message;
49+
}
50+
51+
52+
53+
@Override
54+
public String toString() {
55+
StringBuilder sb = new StringBuilder();
56+
sb.append("class ApiResponse {\n");
57+
58+
sb.append(" code: ").append(code).append("\n");
59+
sb.append(" type: ").append(type).append("\n");
60+
sb.append(" message: ").append(message).append("\n");
61+
sb.append("}\n");
62+
return sb.toString();
63+
}
64+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package io.swagger.petstore.test;
2+
3+
import io.swagger.client.api.*;
4+
import io.swagger.client.model.*;
5+
6+
import java.util.Arrays;
7+
import java.util.List;
8+
9+
import static org.junit.Assert.*;
10+
import org.junit.*;
11+
12+
public class PetApiTest {
13+
PetApi api = null;
14+
15+
@Before
16+
public void setup() {
17+
api = new PetApi();
18+
}
19+
20+
@Test
21+
public void testCreateAndGetPet() throws Exception {
22+
Pet pet = createRandomPet();
23+
api.addPet(pet);
24+
25+
Pet fetched = api.getPetById(pet.getId());
26+
assertNotNull(fetched);
27+
assertEquals(pet.getId(), fetched.getId());
28+
assertNotNull(fetched.getCategory());
29+
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
30+
}
31+
32+
@Test
33+
public void testUpdatePet() throws Exception {
34+
Pet pet = createRandomPet();
35+
pet.setName("programmer");
36+
37+
api.updatePet(pet);
38+
39+
Pet fetched = api.getPetById(pet.getId());
40+
assertNotNull(fetched);
41+
assertEquals(pet.getId(), fetched.getId());
42+
assertNotNull(fetched.getCategory());
43+
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
44+
}
45+
46+
@Test
47+
public void testFindPetByStatus() throws Exception {
48+
Pet pet = createRandomPet();
49+
pet.setName("programmer");
50+
pet.setStatus(Pet.StatusEnum.available);
51+
52+
api.updatePet(pet);
53+
54+
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"}));
55+
assertNotNull(pets);
56+
57+
boolean found = false;
58+
for(Pet fetched : pets) {
59+
if(fetched.getId().equals(pet.getId())) {
60+
found = true;
61+
break;
62+
}
63+
}
64+
65+
assertTrue(found);
66+
}
67+
68+
private Pet createRandomPet() {
69+
Pet pet = new Pet();
70+
pet.setId(System.currentTimeMillis());
71+
pet.setName("gorilla");
72+
73+
Category category = new Category();
74+
category.setName("really-happy");
75+
76+
pet.setCategory(category);
77+
pet.setStatus(Pet.StatusEnum.available);
78+
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"});
79+
pet.setPhotoUrls(photos);
80+
81+
return pet;
82+
}
83+
}

samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ @implementation PetApiTest
66
- (void)setUp {
77
[super setUp];
88
api = [[SWGPetApi alloc ]init];
9-
// [[SWGApiClient sharedClientFromPool]setLoggingEnabled:true];
10-
[SWGPetApi setBasePath:@"http://localhost:8002/api"];
9+
[SWGPetApi setBasePath:@"http://localhost:8080/api"];
1110
}
1211

1312
- (void)tearDown {

samples/client/petstore/objc/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<stopKey>alpha</stopKey>
3131
<stopPort>9099</stopPort>
3232
<httpConnector>
33-
<port>8002</port>
33+
<port>8080</port>
3434
</httpConnector>
3535
</configuration>
3636
<executions>
@@ -41,8 +41,8 @@
4141
<goal>deploy-war</goal>
4242
</goals>
4343
</execution>
44-
</executions>
45-
</plugin>
44+
</executions>
45+
</plugin>
4646
<plugin>
4747
<groupId>org.codehaus.mojo</groupId>
4848
<artifactId>exec-maven-plugin</artifactId>

0 commit comments

Comments
 (0)