Skip to content

Commit

Permalink
Merge pull request #142 from swagger-api/issue-133
Browse files Browse the repository at this point in the history
content type tests
  • Loading branch information
fehguy authored Jul 30, 2016
2 parents 560955c + c77499a commit 53e2b70
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
30 changes: 25 additions & 5 deletions src/test/java/io/swagger/test/examples/ExampleBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.HashMap;
import java.util.Map;

import static org.testng.Assert.assertEquals;

public class ExampleBuilderTest {
static {
// register the JSON serializer
Expand Down Expand Up @@ -99,7 +101,7 @@ public void testXmlJackson() throws Exception {

definitions.put("Address", address);

Example rep = (Example) ExampleBuilder.fromProperty(new RefProperty("User"), definitions);
Example rep = ExampleBuilder.fromProperty(new RefProperty("User"), definitions);

String xmlString = new XmlExampleSerializer().serialize(rep);
assertEqualsIgnoreLineEnding(xmlString, "<?xml version='1.1' encoding='UTF-8'?><user><userName>fehguy</userName><addressess><address><street>12345 El Monte Blvd</street><city>Los Altos Hills</city><state>CA</state><zip>94022</zip></address></addressess><managers><key>key</key><value>SVP Engineering</value></managers><kidsAges>9</kidsAges></user>");
Expand Down Expand Up @@ -256,21 +258,21 @@ public void testRecursiveModel() throws Exception {
public void testEmptyStringArrayJsonModel() throws Exception {
ArrayExample example = new ArrayExample();
example.add(new StringExample());
Assert.assertEquals(Json.pretty(example), "[ null ]");
assertEquals(Json.pretty(example), "[ null ]");
}

@Test
public void testEmptyDoubleArrayJsonModel() throws Exception {
ArrayExample example = new ArrayExample();
example.add(new DoubleExample());
Assert.assertEquals(Json.pretty(example), "[ 4.56 ]");
assertEquals(Json.pretty(example), "[ 4.56 ]");
}

@Test
public void testDoubleArrayModelAsString() throws Exception {
ArrayExample example = new ArrayExample();
example.add(new DoubleExample());
Assert.assertEquals(example.asString(), "[4.56]");
assertEquals(example.asString(), "[4.56]");
}

@Test
Expand All @@ -283,7 +285,25 @@ public void testEmptyArrayXmlModel() throws Exception {
Assert.assertNull(xmlString);
}

@Test
public void testIssue133() throws Exception {
IntegerProperty integerProperty = new IntegerProperty();
integerProperty.setFormat("int64");
integerProperty.setExample(new Long(4321));
Model model = new ModelImpl()
.property("int64", integerProperty);

Map<String, Model> definitions = new HashMap<>();
definitions.put("Address", model);

Example rep = ExampleBuilder.fromProperty(new RefProperty("Address"), definitions);
assertEquals(Json.pretty(rep),
"{\n" +
" \"int64\" : 4321\n" +
"}");
}

private void assertEqualsIgnoreLineEnding(String actual, String expected) {
Assert.assertEquals(actual.replace("\n", System.getProperty("line.separator")), expected);
assertEquals(actual.replace("\n", System.getProperty("line.separator")), expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testIssue130() throws Exception {
public void testResponseHeaders() throws Exception {
Map<String, Object> body = new HashMap<String, Object>();
try {
client.invokeAPI("/issue-133.2", "GET", new HashMap<String, String>(), body,
client.invokeAPI("/issue-132.2", "GET", new HashMap<String, String>(), body,
new HashMap<String, String>(), null, null, null, new String[0]);
Assert.fail("Exception was expected!");
}
Expand Down
20 changes: 17 additions & 3 deletions src/test/swagger/sample1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,33 @@ paths:
type: integer
format: int32
example: 99
/issue-133:
/issue-132:
get:
parameters: []
responses:
303:
description: issue 133
description: issue 132
headers:
Location:
type: string
format: url
example: 'http://foo.bar/other'
description: URI of the entity affected by the property change
/issue-133.2:
/issue-132.2:
get:
parameters: []
responses:
303:
description: issue 132, alternate example
headers:
_links:
description: array of locations
type: array
items:
type: string
format: url
example: 'http://foo.bar/other'
/issue-132.2:
get:
parameters: []
responses:
Expand Down

0 comments on commit 53e2b70

Please sign in to comment.