From 3d3395fe4e3a00dd3b95751f1234c5fa8b04b7af Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Wed, 3 Jun 2020 17:48:00 +0200 Subject: [PATCH] Update to Jackson 2.11.0 * Make tests independent of YAML formatting (whitespace, quotes) --- .../JsonDeserializationTest.java | 6 +++-- .../annotations/AbstractAnnotationTest.java | 4 ++-- .../annotations/callbacks/CallbackTest.java | 6 +++-- .../annotations/examples/ExamplesTest.java | 6 +++-- .../v3/jaxrs2/annotations/info/InfoTest.java | 6 +++-- .../AnnotatedOperationMethodTest.java | 24 +++++++++---------- .../operations/MergedOperationTest.java | 14 ++++++----- .../parameters/ParametersTest.java | 13 +++++----- .../pathItems/OperationsWithLinksTest.java | 4 ++-- .../annotations/security/SecurityTest.java | 16 ++++++------- pom.xml | 2 +- 11 files changed, 56 insertions(+), 45 deletions(-) diff --git a/modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java b/modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java index 59e0643935..57ae877069 100644 --- a/modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java +++ b/modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/JsonDeserializationTest.java @@ -265,8 +265,10 @@ public void deserializeDateExample() throws IOException { final OpenAPI swagger = Yaml.mapper().readValue(jsonString, OpenAPI.class); assertNotNull(swagger); Map props = swagger.getComponents().getSchemas().get("MyModel").getProperties(); - assertTrue(Yaml.pretty().writeValueAsString(props.get("date")).contains("example: 2019-08-05")); - assertTrue(Yaml.pretty().writeValueAsString(props.get("dateTime")).contains("example: 2019-08-05T12:34:56Z")); + final String dateYaml = Yaml.mapper().writeValueAsString(props.get("date")); + assertEquals(Yaml.mapper().readTree(dateYaml).path("example").asText(), "2019-08-05"); + final String dateTimeYaml = Yaml.mapper().writeValueAsString(props.get("dateTime")); + assertEquals(Yaml.mapper().readTree(dateTimeYaml).path("example").asText(), "2019-08-05T12:34:56Z"); } diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/AbstractAnnotationTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/AbstractAnnotationTest.java index c1f9e7e289..c660a9663f 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/AbstractAnnotationTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/AbstractAnnotationTest.java @@ -48,11 +48,11 @@ public void compareAsYaml(final Class cls, final String yaml) throws IOExcept } public void compareAsYaml(final String actualYaml, final String expectedYaml) throws IOException { - SerializationMatchers.assertEqualsToYaml(Yaml.mapper().readValue(actualYaml, OpenAPI.class), expectedYaml); + SerializationMatchers.assertEqualsToYaml(Yaml.mapper().readValue(actualYaml, JsonNode.class), expectedYaml); } public void compareAsJson(final String actualJson, final String expectedJson) throws IOException { - SerializationMatchers.assertEqualsToJson(Yaml.mapper().readValue(actualJson, OpenAPI.class), expectedJson); + SerializationMatchers.assertEqualsToJson(Yaml.mapper().readValue(actualJson, JsonNode.class), expectedJson); } protected String getOpenAPIAsString(final String file) throws IOException { diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/callbacks/CallbackTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/callbacks/CallbackTest.java index a08cf25720..05704127e7 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/callbacks/CallbackTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/callbacks/CallbackTest.java @@ -17,11 +17,13 @@ import javax.ws.rs.Path; import javax.ws.rs.QueryParam; +import java.io.IOException; + import static org.testng.Assert.assertEquals; public class CallbackTest extends AbstractAnnotationTest { @Test - public void testSimpleCallback() { + public void testSimpleCallback() throws IOException { String openApiYAML = readIntoYaml(SimpleCallback.class); int start = openApiYAML.indexOf("/test:"); int end = openApiYAML.length() - 1; @@ -85,7 +87,7 @@ public void testSimpleCallback() { " properties:\n" + " subscriptionId:\n" + " type: string"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } static class SimpleCallback { diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/examples/ExamplesTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/examples/ExamplesTest.java index faf4e9d4cf..55ef0b8364 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/examples/ExamplesTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/examples/ExamplesTest.java @@ -17,6 +17,8 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; +import java.io.IOException; + import static org.testng.Assert.assertEquals; public class ExamplesTest extends AbstractAnnotationTest { @@ -342,7 +344,7 @@ public ExamplesTest.AnnotatedSubscription testAnnotatedModel( @Test - public void testFullExample() { + public void testFullExample() throws IOException { String openApiYAML = readIntoYaml(ExamplesTest.SimpleOperations.class); int start = openApiYAML.indexOf("/test:"); int end = openApiYAML.length() - 1; @@ -437,7 +439,7 @@ public void testFullExample() { " format: int32\n" + " xml:\n" + " name: User"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } static class SimpleOperations { diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/info/InfoTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/info/InfoTest.java index 692ee4c6b6..30d5701bd5 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/info/InfoTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/info/InfoTest.java @@ -7,11 +7,13 @@ import io.swagger.v3.oas.annotations.info.License; import org.testng.annotations.Test; +import java.io.IOException; + import static org.testng.Assert.assertEquals; public class InfoTest extends AbstractAnnotationTest { @Test - public void testSimpleInfoGet() { + public void testSimpleInfoGet() throws IOException { String openApiYAML = readIntoYaml(InfoTest.ClassWithInfoAnnotation.class); int start = openApiYAML.indexOf("info:"); int end = openApiYAML.length() - 1; @@ -29,7 +31,7 @@ public void testSimpleInfoGet() { " version: \"0.0\""; String extractedYAML = openApiYAML.substring(start, end); - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } @OpenAPIDefinition(info = @Info( diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/AnnotatedOperationMethodTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/AnnotatedOperationMethodTest.java index a2f06d679e..7679efacac 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/AnnotatedOperationMethodTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/AnnotatedOperationMethodTest.java @@ -98,7 +98,7 @@ public void simpleGet() { } @Test - public void testGetOperationWithResponsePayloadAndAlternateCodes() { + public void testGetOperationWithResponsePayloadAndAlternateCodes() throws IOException { String openApiYAML = readIntoYaml(GetOperationWithResponsePayloadAndAlternateCodes.class); int start = openApiYAML.indexOf("get:"); int end = openApiYAML.indexOf("components:"); @@ -128,7 +128,7 @@ public void testGetOperationWithResponsePayloadAndAlternateCodes() { " externalValue: example of external value\n" + " deprecated: true\n"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } static class GetOperationWithResponsePayloadAndAlternateCodes { @@ -177,7 +177,7 @@ static class GenericError { } @Test(description = "reads an operation with response examples defined") - public void testOperationWithResponseExamples() { + public void testOperationWithResponseExamples() throws IOException { String openApiYAML = readIntoYaml(GetOperationWithResponseExamples.class); int start = openApiYAML.indexOf("get:"); int end = openApiYAML.indexOf("components:"); @@ -199,11 +199,11 @@ public void testOperationWithResponseExamples() { " description: basic\n" + " value: '{id: 19877734}'\n" + " deprecated: true\n"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } @Test(description = "reads an operation with response examples defined") - public void testOperationWithParameterExample() { + public void testOperationWithParameterExample() throws IOException { String openApiYAML = readIntoYaml(GetOperationWithParameterExample.class); int start = openApiYAML.indexOf("get:"); int end = openApiYAML.indexOf("components:"); @@ -231,7 +231,7 @@ public void testOperationWithParameterExample() { " description: basic\n" + " value: '{id: 19877734}'\n" + " deprecated: true\n"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } static class GetOperationWithResponseExamples { @@ -1055,7 +1055,7 @@ public void testHiddenAnnotatedUserResource() throws IOException { } @Test - public void testSimpleGetOperationWithSecurity() { + public void testSimpleGetOperationWithSecurity() throws IOException { String openApiYAML = readIntoYaml(SimpleGetOperationWithSecurity.class); int start = openApiYAML.indexOf("get:"); @@ -1073,7 +1073,7 @@ public void testSimpleGetOperationWithSecurity() { " - write:pets"; String extractedYAML = openApiYAML.substring(start, end); - assertEquals(expectedYAML, extractedYAML); + compareAsYaml(expectedYAML, extractedYAML); } static class SimpleGetOperationWithSecurity { @@ -1096,7 +1096,7 @@ public void simpleGet() { } @Test - public void testSimpleGetOperationWithMultipleSecurity() { + public void testSimpleGetOperationWithMultipleSecurity() throws IOException { String openApiYAML = readIntoYaml(SimpleGetOperationWithMultipleSecurityScopes.class); int start = openApiYAML.indexOf("get:"); @@ -1115,7 +1115,7 @@ public void testSimpleGetOperationWithMultipleSecurity() { " - read:pets"; String extractedYAML = openApiYAML.substring(start, end); - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } static class SimpleGetOperationWithMultipleSecurityScopes { @@ -1138,7 +1138,7 @@ public void simpleGet() { } @Test - public void testSimpleGetOperationWithMultipleSecurityAnnotations() { + public void testSimpleGetOperationWithMultipleSecurityAnnotations() throws IOException { String openApiYAML = readIntoYaml(SimpleGetOperationWithMultipleSecurityAnnotations.class); int start = openApiYAML.indexOf("get:"); @@ -1160,7 +1160,7 @@ public void testSimpleGetOperationWithMultipleSecurityAnnotations() { " - api_key: []"; String extractedYAML = openApiYAML.substring(start, end); - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } static class SimpleGetOperationWithMultipleSecurityAnnotations { diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/MergedOperationTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/MergedOperationTest.java index 5d8b65d810..35bc23cd47 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/MergedOperationTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/operations/MergedOperationTest.java @@ -12,6 +12,8 @@ import javax.ws.rs.Path; import javax.ws.rs.QueryParam; +import java.io.IOException; + import static org.testng.Assert.assertEquals; public class MergedOperationTest extends AbstractAnnotationTest { @@ -34,10 +36,10 @@ static class SimpleResponse { } @Test(description = "shows how a method with parameters and no special annotations is processed") - public void testAnnotatedParameters() { + public void testAnnotatedParameters() throws IOException { String yaml = readIntoYaml(MethodWithParameters.class); - assertEquals(yaml, + compareAsYaml(yaml, "openapi: 3.0.1\n" + "paths:\n" + " /findAll:\n" + @@ -80,7 +82,7 @@ public SimpleResponse getSimpleResponseWithParameters( } @Test(description = "shows how annotations can decorate an operation") - public void testPartiallyAnnotatedMethod() { + public void testPartiallyAnnotatedMethod() throws IOException { String yaml = readIntoYaml(MethodWithPartialAnnotation.class); String expectedYaml = "openapi: 3.0.1\n" + "paths:\n" + @@ -114,7 +116,7 @@ public void testPartiallyAnnotatedMethod() { " SimpleResponse:\n" + " type: object\n"; - assertEquals(yaml, expectedYaml); + compareAsYaml(yaml, expectedYaml); } static class MethodWithPartialAnnotation { @@ -134,7 +136,7 @@ public SimpleResponse getSimpleResponseWithParameters( } @Test(description = "shows how a request body is passed") - public void testRequestBody() { + public void testRequestBody() throws IOException { String yaml = readIntoYaml(MethodWithRequestBody.class); String expectedYaml = "openapi: 3.0.1\n" + "paths:\n" + @@ -155,7 +157,7 @@ public void testRequestBody() { " InputValue:\n" + " type: object\n"; - assertEquals(yaml, expectedYaml); + compareAsYaml(yaml, expectedYaml); } static class MethodWithRequestBody { diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/parameters/ParametersTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/parameters/ParametersTest.java index a2c17b594f..7de9296a08 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/parameters/ParametersTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/parameters/ParametersTest.java @@ -19,6 +19,7 @@ import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; +import java.io.IOException; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -41,7 +42,7 @@ public void scanClassAndFieldLevelAnnotations() { } @Test - public void testParameters() { + public void testParameters() throws IOException { String openApiYAML = readIntoYaml(ParametersTest.SimpleOperations.class); int start = openApiYAML.indexOf("/test:"); int end = openApiYAML.length() - 1; @@ -129,11 +130,11 @@ public void testParameters() { " properties:\n" + " subscriptionId:\n" + " type: string"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } @Test - public void testArraySchemaParameters() { + public void testArraySchemaParameters() throws IOException { String openApiYAML = readIntoYaml(ParametersTest.ArraySchemaOperations.class); int start = openApiYAML.indexOf("/test:"); int end = openApiYAML.length() - 1; @@ -169,11 +170,11 @@ public void testArraySchemaParameters() { " properties:\n" + " subscriptionId:\n" + " type: string"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } @Test - public void testRepeatableParameters() { + public void testRepeatableParameters() throws IOException { String openApiYAML = readIntoYaml(ParametersTest.RepeatableParametersOperations.class); int start = openApiYAML.indexOf("/test:"); int end = openApiYAML.length() - 1; @@ -261,7 +262,7 @@ public void testRepeatableParameters() { " properties:\n" + " subscriptionId:\n" + " type: string"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } @Test(description = "JsonUnwrapped, JsonIgnore, JsonValue should be honoured") diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/pathItems/OperationsWithLinksTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/pathItems/OperationsWithLinksTest.java index 94f50fa6e6..9ba6c82e0f 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/pathItems/OperationsWithLinksTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/pathItems/OperationsWithLinksTest.java @@ -292,7 +292,7 @@ public void setZip(String zip) { } @Test(description = "Shows creating simple links") - public void createOperationWithLinkReferences() { + public void createOperationWithLinkReferences() throws IOException { String openApiYAML = readIntoYaml(ClassWithOperationAndLinkReferences.class); int start = openApiYAML.indexOf("/users:"); int end = openApiYAML.length() - 1; @@ -327,7 +327,7 @@ public void createOperationWithLinkReferences() { " username:\n" + " type: string"; String extractedYAML = openApiYAML.substring(start, end); - assertEquals(extractedYAML, expectedYaml); + compareAsYaml(extractedYAML, expectedYaml); } static class ClassWithOperationAndLinkReferences { diff --git a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/security/SecurityTest.java b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/security/SecurityTest.java index bdaba471fa..5b25fc2f56 100644 --- a/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/security/SecurityTest.java +++ b/modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/annotations/security/SecurityTest.java @@ -19,7 +19,7 @@ public class SecurityTest extends AbstractAnnotationTest { @Test - public void testSecuritySheme() { + public void testSecuritySheme() throws IOException { String openApiYAML = readIntoYaml(SecurityTest.OAuth2SchemeOnClass.class); int start = openApiYAML.indexOf("components:"); String extractedYAML = openApiYAML.substring(start, openApiYAML.length() - 1); @@ -33,7 +33,7 @@ public void testSecuritySheme() { " authorizationUrl: http://url.com/auth\n" + " scopes:\n" + " write:pets: modify pets in your account"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } @@ -90,7 +90,7 @@ public void testSecurityRequirement() throws IOException { } @Test - public void testMultipleSecurityShemes() { + public void testMultipleSecurityShemes() throws IOException { String openApiYAML = readIntoYaml(SecurityTest.MultipleSchemesOnClass.class); int start = openApiYAML.indexOf("components:"); String extractedYAML = openApiYAML.substring(start, openApiYAML.length() - 1); @@ -108,12 +108,12 @@ public void testMultipleSecurityShemes() { " authorizationUrl: http://url.com/auth\n" + " scopes:\n" + " write:pets: modify pets in your account"; - assertEquals(extractedYAML, expectedYAML); + compareAsYaml(extractedYAML, expectedYAML); } @Test - public void testTicket2767() { + public void testTicket2767() throws IOException { String openApiYAML = readIntoYaml(SecurityTest.Ticket2767.class); String expectedYAML = "openapi: 3.0.1\n" + "info:\n" + @@ -126,12 +126,12 @@ public void testTicket2767() { " basicAuth:\n" + " type: http\n" + " scheme: basic\n"; - assertEquals(openApiYAML, expectedYAML); + compareAsYaml(openApiYAML, expectedYAML); } @Test - public void testTicket2767_2() { + public void testTicket2767_2() throws IOException { String openApiYAML = readIntoYaml(SecurityTest.Ticket2767_2.class); String expectedYAML = "openapi: 3.0.1\n" + "info:\n" + @@ -144,7 +144,7 @@ public void testTicket2767_2() { " api_key:\n" + " type: apiKey\n" + " name: API_KEY\n"; - assertEquals(openApiYAML, expectedYAML); + compareAsYaml(openApiYAML, expectedYAML); } diff --git a/pom.xml b/pom.xml index cef6c4608e..74f97daf7f 100644 --- a/pom.xml +++ b/pom.xml @@ -508,7 +508,7 @@ 4.2.1 4.0.3 2.26 - 2.10.1 + 2.11.0 1.2.3 4.8.65 27.0.1-jre