14
14
import io .github .springwolf .core .asyncapi .schemas .SwaggerSchemaService ;
15
15
import io .github .springwolf .core .asyncapi .schemas .SwaggerSchemaUtil ;
16
16
import io .github .springwolf .core .configuration .properties .SpringwolfConfigProperties ;
17
+ import io .github .springwolf .core .fixtures .ClasspathUtil ;
17
18
import io .swagger .v3 .core .util .Json ;
18
19
import io .swagger .v3 .oas .annotations .media .Schema ;
19
20
import jakarta .annotation .Nullable ;
26
27
import org .junit .jupiter .api .Test ;
27
28
28
29
import java .io .IOException ;
29
- import java .io .InputStream ;
30
30
import java .math .BigInteger ;
31
- import java .nio .charset .StandardCharsets ;
32
31
import java .time .LocalDate ;
33
32
import java .time .OffsetDateTime ;
34
33
import java .util .ArrayList ;
@@ -60,7 +59,7 @@ void getSchemas() throws IOException {
60
59
componentsService .registerSchema (FooWithEnum .class , "text/xml" );
61
60
62
61
String actualDefinitions = objectMapper .writer (printer ).writeValueAsString (componentsService .getSchemas ());
63
- String expected = jsonResource ("/schemas/xml/definitions-xml.json" );
62
+ String expected = loadDefinition ("/schemas/xml/definitions-xml.json" , actualDefinitions );
64
63
65
64
System .out .println ("Got: " + actualDefinitions );
66
65
assertEquals (expected , actualDefinitions );
@@ -71,7 +70,7 @@ void getDocumentedDefinitions() throws IOException {
71
70
componentsService .registerSchema (DocumentedSimpleFoo .class , "text/xml" );
72
71
73
72
String actualDefinitions = objectMapper .writer (printer ).writeValueAsString (componentsService .getSchemas ());
74
- String expected = jsonResource ("/schemas/xml/documented-definitions-xml.json" );
73
+ String expected = loadDefinition ("/schemas/xml/documented-definitions-xml.json" , actualDefinitions );
75
74
76
75
System .out .println ("Got: " + actualDefinitions );
77
76
assertEquals (expected , actualDefinitions );
@@ -82,7 +81,7 @@ void getArrayDefinitions() throws IOException {
82
81
componentsService .registerSchema (ArrayFoo .class , "text/xml" );
83
82
84
83
String actualDefinitions = objectMapper .writer (printer ).writeValueAsString (componentsService .getSchemas ());
85
- String expected = jsonResource ("/schemas/xml/array-definitions-xml.json" );
84
+ String expected = loadDefinition ("/schemas/xml/array-definitions-xml.json" , actualDefinitions );
86
85
87
86
System .out .println ("Got: " + actualDefinitions );
88
87
assertEquals (expected , actualDefinitions );
@@ -93,7 +92,7 @@ void getComplexDefinitions() throws IOException {
93
92
componentsService .registerSchema (ComplexFoo .class , "text/xml" );
94
93
95
94
String actualDefinitions = objectMapper .writer (printer ).writeValueAsString (componentsService .getSchemas ());
96
- String expected = jsonResource ("/schemas/xml/complex-definitions-xml.json" );
95
+ String expected = loadDefinition ("/schemas/xml/complex-definitions-xml.json" , actualDefinitions );
97
96
98
97
System .out .println ("Got: " + actualDefinitions );
99
98
assertEquals (expected , actualDefinitions );
@@ -104,7 +103,8 @@ void getComplexDefinitionsWithAttributes() throws IOException {
104
103
componentsService .registerSchema (ComplexAttributesFoo .class , "text/xml" );
105
104
106
105
String actualDefinitions = objectMapper .writer (printer ).writeValueAsString (componentsService .getSchemas ());
107
- String expected = jsonResource ("/schemas/xml/complex-definitions-with-attributes-xml.json" );
106
+ String expected =
107
+ loadDefinition ("/schemas/xml/complex-definitions-with-attributes-xml.json" , actualDefinitions );
108
108
109
109
System .out .println ("Got: " + actualDefinitions );
110
110
assertEquals (expected , actualDefinitions );
@@ -115,16 +115,15 @@ void getListWrapperDefinitions() throws IOException {
115
115
componentsService .registerSchema (ListWrapper .class , "text/xml" );
116
116
117
117
String actualDefinitions = objectMapper .writer (printer ).writeValueAsString (componentsService .getSchemas ());
118
- String expected = jsonResource ("/schemas/xml/generics-wrapper-definitions-xml.json" );
118
+ String expected = loadDefinition ("/schemas/xml/generics-wrapper-definitions-xml.json" , actualDefinitions );
119
119
120
120
System .out .println ("Got: " + actualDefinitions );
121
121
assertEquals (expected , actualDefinitions );
122
122
}
123
123
124
- private String jsonResource (String path ) throws IOException {
125
- try (InputStream s = this .getClass ().getResourceAsStream (path )) {
126
- return new String (s .readAllBytes (), StandardCharsets .UTF_8 ).trim ();
127
- }
124
+ private String loadDefinition (String path , String content ) throws IOException {
125
+ ClasspathUtil .writeAsActual (path , content );
126
+ return ClasspathUtil .readAsString (path );
128
127
}
129
128
130
129
@ Data
@@ -246,7 +245,7 @@ void testSchemaWithOneOf() throws IOException {
246
245
componentsService .registerSchema (SchemaAnnotationFoo .class , "text/xml" );
247
246
248
247
String actualDefinitions = objectMapper .writer (printer ).writeValueAsString (componentsService .getSchemas ());
249
- String expected = jsonResource ("/schemas/xml/annotation-definitions-xml.json" );
248
+ String expected = loadDefinition ("/schemas/xml/annotation-definitions-xml.json" , actualDefinitions );
250
249
251
250
System .out .println ("Got: " + actualDefinitions );
252
251
assertEquals (expected , actualDefinitions );
@@ -346,7 +345,7 @@ void testSchemasWithSharedProperty() throws IOException {
346
345
componentsService .registerSchema (XmlSchemaName .ClassA .class , "text/xml" );
347
346
348
347
String actualDefinitions = objectMapper .writer (printer ).writeValueAsString (componentsService .getSchemas ());
349
- String expected = jsonResource ("/schemas/xml/schema-with-shared-property.json" );
348
+ String expected = loadDefinition ("/schemas/xml/schema-with-shared-property.json" , actualDefinitions );
350
349
351
350
System .out .println ("Got: " + actualDefinitions );
352
351
assertEquals (expected , actualDefinitions );
0 commit comments