-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1347 from lugaru1234/issue1337
Fixes #1337: ModelWithReferenceTest, ResponseExamplesTest and SecurityDefinitionTest have been migrated
- Loading branch information
Showing
10 changed files
with
340 additions
and
137 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
modules/swagger-core/src/test/java/io/swagger/ModelWithReferenceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.swagger; | ||
|
||
import io.swagger.converter.ModelConverters; | ||
import io.swagger.matchers.SerializationMatchers; | ||
import io.swagger.models.Model; | ||
import io.swagger.models.ModelContainingModelWithReference; | ||
import io.swagger.models.ModelWithReference; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class ModelWithReferenceTest { | ||
|
||
@Test(description = "it should convert a model with reference property") | ||
public void convertModelWithReferenceProperty() throws IOException { | ||
final Map<String, Model> schemas = ModelConverters.getInstance().read(ModelWithReference.class); | ||
final String json = "{\n" + | ||
" \"ModelWithReference\":{\n" + | ||
" \"type\":\"object\",\n" + | ||
" \"properties\":{\n" + | ||
" \"description\":{\n" + | ||
" \"$ref\":\"http://swagger.io/schemas.json#/Models/Description\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"; | ||
SerializationMatchers.assertEqualsToJson(schemas, json); | ||
} | ||
|
||
@Test(description = "it should convert a model with reference and reference property") | ||
public void convertModelWithReferenceAndReferenceProperty() throws IOException { | ||
final Map<String, Model> schemas = ModelConverters.getInstance().read(ModelContainingModelWithReference.class); | ||
final String json = "{\n" + | ||
" \"ModelContainingModelWithReference\":{\n" + | ||
" \"type\":\"object\",\n" + | ||
" \"properties\":{\n" + | ||
" \"model\":{\n" + | ||
" \"$ref\":\"http://swagger.io/schemas.json#/Models\"\n" + | ||
" },\n" + | ||
" \"anotherModel\":{\n" + | ||
" \"$ref\":\"http://swagger.io/schemas.json#/Models/AnotherModel\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"; | ||
SerializationMatchers.assertEqualsToJson(schemas, json); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
modules/swagger-core/src/test/java/io/swagger/ResponseExamplesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.swagger; | ||
|
||
import io.swagger.matchers.SerializationMatchers; | ||
import io.swagger.models.Response; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
|
||
public class ResponseExamplesTest { | ||
|
||
@Test(description = "it should create a response") | ||
public void createResponse() throws IOException { | ||
final Response response = new Response() | ||
.example("application/json", "{\"name\":\"Fred\",\"id\":123456\"}"); | ||
final String json = "{\n" + | ||
" \"examples\":{\n" + | ||
" \"application/json\":\"{\\\"name\\\":\\\"Fred\\\",\\\"id\\\":123456\\\"}\"\n" + | ||
" }\n" + | ||
"}"; | ||
SerializationMatchers.assertEqualsToJson(response, json); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
modules/swagger-core/src/test/java/io/swagger/SecurityDefinitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package io.swagger; | ||
|
||
import io.swagger.converter.ModelConverters; | ||
import io.swagger.matchers.SerializationMatchers; | ||
import io.swagger.models.Contact; | ||
import io.swagger.models.Info; | ||
import io.swagger.models.Model; | ||
import io.swagger.models.Operation; | ||
import io.swagger.models.Path; | ||
import io.swagger.models.Person; | ||
import io.swagger.models.Response; | ||
import io.swagger.models.Scheme; | ||
import io.swagger.models.Error; | ||
import io.swagger.models.SecurityRequirement; | ||
import io.swagger.models.Swagger; | ||
import io.swagger.models.auth.OAuth2Definition; | ||
import io.swagger.models.parameters.PathParameter; | ||
import io.swagger.models.parameters.QueryParameter; | ||
import io.swagger.models.properties.LongProperty; | ||
import io.swagger.models.properties.RefProperty; | ||
import io.swagger.models.properties.StringProperty; | ||
import io.swagger.util.ResourceUtils; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
|
||
public class SecurityDefinitionTest { | ||
|
||
@Test(description = "it should create a model with security requirements") | ||
public void createModelWithSecurityRequirements() throws IOException{ | ||
final Model personModel = ModelConverters.getInstance().read(Person.class).get("Person"); | ||
final Model errorModel = ModelConverters.getInstance().read(Error.class).get("Error"); | ||
|
||
final Info info = new Info() | ||
.version("1.0.0") | ||
.title("Swagger Petstore"); | ||
|
||
final Contact contact = new Contact() | ||
.name("Swagger API Team") | ||
.email("foo@bar.baz") | ||
.url("http://swagger.io"); | ||
info.setContact(contact); | ||
|
||
final Swagger swagger = new Swagger() | ||
.info(info) | ||
.host("petstore.swagger.io") | ||
.scheme(Scheme.HTTP) | ||
.consumes("application/json") | ||
.produces("application/json") | ||
.model("Person", personModel) | ||
.model("Error", errorModel); | ||
|
||
swagger.securityDefinition("githubAccessCode", | ||
new OAuth2Definition() | ||
.accessCode("http://foo.com/accessCode", "http://foo.com/tokenUrl") | ||
.scope("user:email", "Grants read access to a user’s email addresses.")); | ||
|
||
final Operation get = new Operation() | ||
.produces("application/json") | ||
.summary("finds pets in the system") | ||
.description("a longer description") | ||
.tag("Pet Operations") | ||
.operationId("get pet by id"); | ||
|
||
get.parameter(new QueryParameter() | ||
.name("tags") | ||
.description("tags to filter by") | ||
.required(false) | ||
.property(new StringProperty()) | ||
); | ||
get.parameter(new PathParameter() | ||
.name("petId") | ||
.description("pet to fetch") | ||
.property(new LongProperty()) | ||
); | ||
|
||
final Response response = new Response() | ||
.description("pets returned") | ||
.schema(new RefProperty().asDefault("Person")); | ||
|
||
final Response errorResponse = new Response() | ||
.description("error response") | ||
.schema(new RefProperty().asDefault("Error")); | ||
|
||
get.response(200, response) | ||
.defaultResponse(errorResponse) | ||
.security(new SecurityRequirement("internal_oauth2") | ||
.scope("user:email")) | ||
.security(new SecurityRequirement("api_key")); | ||
|
||
swagger.path("/pets", new Path().get(get)); | ||
|
||
final String json = ResourceUtils.loadClassResource(getClass(), "ModelWithSecurityRequirements.json"); | ||
SerializationMatchers.assertEqualsToJson(swagger, json); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
modules/swagger-core/src/test/java/io/swagger/models/Error.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.swagger.models; | ||
|
||
public class Error { | ||
int code; | ||
String message; | ||
|
||
public Error() { | ||
} | ||
|
||
public Error(int code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(int code) { | ||
this.code = code; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ls/ModelContainingModelWithReference.java → ...ls/ModelContainingModelWithReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package models; | ||
package io.swagger.models; | ||
|
||
import io.swagger.annotations.ApiModelProperty; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...test/scala/models/ModelWithReference.java → ...io/swagger/models/ModelWithReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
modules/swagger-core/src/test/resources/ModelWithSecurityRequirements.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
{ | ||
"swagger":"2.0", | ||
"info":{ | ||
"version":"1.0.0", | ||
"title":"Swagger Petstore", | ||
"contact":{ | ||
"name":"Swagger API Team", | ||
"url":"http://swagger.io", | ||
"email":"foo@bar.baz" | ||
} | ||
}, | ||
"host":"petstore.swagger.io", | ||
"schemes":[ | ||
"http" | ||
], | ||
"consumes":[ | ||
"application/json" | ||
], | ||
"produces":[ | ||
"application/json" | ||
], | ||
"paths":{ | ||
"/pets":{ | ||
"get":{ | ||
"tags":[ | ||
"Pet Operations" | ||
], | ||
"summary":"finds pets in the system", | ||
"description":"a longer description", | ||
"operationId":"get pet by id", | ||
"produces":[ | ||
"application/json" | ||
], | ||
"parameters":[ | ||
{ | ||
"name":"tags", | ||
"in":"query", | ||
"description":"tags to filter by", | ||
"required":false, | ||
"type":"string" | ||
}, | ||
{ | ||
"name":"petId", | ||
"in":"path", | ||
"description":"pet to fetch", | ||
"required":true, | ||
"type":"integer", | ||
"format":"int64" | ||
} | ||
], | ||
"responses":{ | ||
"default":{ | ||
"description":"error response", | ||
"schema":{ | ||
"$ref":"#/definitions/Error" | ||
} | ||
}, | ||
"200":{ | ||
"description":"pets returned", | ||
"schema":{ | ||
"$ref":"#/definitions/Person" | ||
} | ||
} | ||
}, | ||
"security":[ | ||
{ | ||
"internal_oauth2":[ | ||
"user:email" | ||
] | ||
}, | ||
{ | ||
"api_key":[ | ||
|
||
] | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"securityDefinitions":{ | ||
"githubAccessCode":{ | ||
"type":"oauth2", | ||
"authorizationUrl":"http://foo.com/accessCode", | ||
"tokenUrl":"http://foo.com/tokenUrl", | ||
"flow":"accessCode", | ||
"scopes":{ | ||
"user:email":"Grants read access to a user’s email addresses." | ||
} | ||
} | ||
}, | ||
"definitions":{ | ||
"Error":{ | ||
"type":"object", | ||
"properties":{ | ||
"code":{ | ||
"type":"integer", | ||
"format":"int32" | ||
}, | ||
"message":{ | ||
"type":"string" | ||
} | ||
} | ||
}, | ||
"Person":{ | ||
"type":"object", | ||
"properties":{ | ||
"id":{ | ||
"type":"integer", | ||
"format":"int64" | ||
}, | ||
"firstName":{ | ||
"type":"string" | ||
}, | ||
"address":{ | ||
"$ref":"#/definitions/Address" | ||
}, | ||
"properties":{ | ||
"type":"object", | ||
"additionalProperties":{ | ||
"type":"string" | ||
} | ||
}, | ||
"birthDate":{ | ||
"type":"string", | ||
"format":"date-time" | ||
}, | ||
"float":{ | ||
"type":"number", | ||
"format":"float" | ||
}, | ||
"double":{ | ||
"type":"number", | ||
"format":"double" | ||
} | ||
} | ||
} | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
modules/swagger-core/src/test/scala/ModelWithReferenceTest.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.