Skip to content

Commit

Permalink
added tests for #330
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy committed Oct 27, 2016
1 parent 47947c0 commit 9c2db79
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.swagger.models.auth.AuthorizationValue;
import io.swagger.parser.util.RemoteUrl;
import io.swagger.parser.util.SwaggerDeserializationResult;
import io.swagger.util.Json;
import mockit.Expectations;
import mockit.Mocked;
import org.testng.annotations.Test;
Expand All @@ -21,18 +22,24 @@ public class NetworkReferenceTests {

private static String issue_323_yaml, issue_323_events_yaml, issue_323_paging_yaml, issue_323_bar_yaml;
private static String issue_328_yaml, issue_328_events_yaml, issue_328_paging_yaml, issue_328_bar_yaml;
private static String issue_330_yaml, issue_330_users_yaml, issue_330_paging_yaml, issue_330_entities_yaml;

static {
try {
issue_323_yaml = readFile("src/test/resources/nested-file-references/issue-323.yaml");
issue_323_events_yaml = readFile("src/test/resources/nested-file-references/eventsCase9.yaml");
issue_323_paging_yaml = readFile("src/test/resources/nested-file-references/common/pagingWithFolderRef.yaml");
issue_323_bar_yaml = readFile("src/test/resources/nested-file-references/common/common2/bar.yaml");

issue_328_yaml = readFile("src/test/resources/nested-file-references/issue-328.yaml");
issue_328_events_yaml = readFile("src/test/resources/nested-file-references/issue-328-events.yaml");
issue_328_paging_yaml = readFile("src/test/resources/nested-file-references/common/issue-328-paging.yaml");
issue_328_bar_yaml = readFile("src/test/resources/nested-file-references/common/common2/issue-328-bar.yaml");
issue_323_yaml = readFile("src/test/resources/nested-file-references/issue-323.yaml");
issue_323_events_yaml = readFile("src/test/resources/nested-file-references/eventsCase9.yaml");
issue_323_paging_yaml = readFile("src/test/resources/nested-file-references/common/pagingWithFolderRef.yaml");
issue_323_bar_yaml = readFile("src/test/resources/nested-file-references/common/common2/bar.yaml");

issue_328_yaml = readFile("src/test/resources/nested-file-references/issue-328.yaml");
issue_328_events_yaml = readFile("src/test/resources/nested-file-references/issue-328-events.yaml");
issue_328_paging_yaml = readFile("src/test/resources/nested-file-references/common/issue-328-paging.yaml");
issue_328_bar_yaml = readFile("src/test/resources/nested-file-references/common/common2/issue-328-bar.yaml");

issue_330_yaml = readFile("src/test/resources/nested-network-references/issue-330.yaml");
issue_330_paging_yaml = readFile("src/test/resources/nested-network-references/common/issue-330-paging.yaml");
issue_330_users_yaml = readFile("src/test/resources/nested-network-references/common/issue-330-users.yaml");
issue_330_entities_yaml = readFile("src/test/resources/nested-network-references/common/issue-330-entities.yaml");
}
catch(Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -66,7 +73,6 @@ public void testIssue323() throws Exception {
assertNotNull(swagger.getDefinitions().get("Foobar"));
}


@Test
public void testIssue328() throws Exception {
new Expectations() {{
Expand All @@ -93,6 +99,34 @@ public void testIssue328() throws Exception {
assertNotNull(swagger.getDefinitions().get("Foobar"));
}

@Test
public void testIssue330() throws Exception {
new Expectations() {{
remoteUrl.urlToString("http://server1/resources/swagger.yaml", new ArrayList<AuthorizationValue>());
result = issue_330_yaml;

remoteUrl.urlToString("http://server1/resources/common/paging.yaml", new ArrayList<AuthorizationValue>());
result = issue_330_paging_yaml;

remoteUrl.urlToString("http://server1/resources/common/users.yaml", new ArrayList<AuthorizationValue>());
result = issue_330_users_yaml;

remoteUrl.urlToString("http://server2/resources/common/entities.yaml", new ArrayList<AuthorizationValue>());
result = issue_330_entities_yaml;
}};
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("http://server1/resources/swagger.yaml", null, true);
Json.prettyPrint(result);

assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getPath("/events"));

assertNotNull(swagger.getDefinitions().get("Address"));
assertNotNull(swagger.getDefinitions().get("Paging"));
assertNotNull(swagger.getDefinitions().get("users"));
assertNotNull(swagger.getDefinitions().get("Phone"));
}

static String readFile(String name) {
try {
return new String(Files.readAllBytes(new File(name).toPath()), Charset.forName("UTF-8"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
definitions:
Address:
title: the address
properties:
street:
type: string
phone:
$ref: '#/definitions/Phone'
Phone:
title: the phone number
type: string
example: '408-867-5309'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Paging:
properties:
total_items:
type: integer
user:
$ref: './users.yaml'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: object
title: the user
properties:
name:
type: string
address:
$ref: 'http://server2/resources/common/entities.yaml#/definitions/Address'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
swagger: '2.0'
info:
title: Test API
version: '1'
host: example.com
basePath: /api/v1
schemes:
- https
consumes:
- application/json; charset=utf-8
produces:
- application/json; charset=utf-8
paths:
/events:
get:
description: A list of events
operationId: getEvents
responses:
200:
description: OK
schema:
type: object
properties:
paging:
$ref: 'http://server1/resources/common/paging.yaml#/Paging'

0 comments on commit 9c2db79

Please sign in to comment.