@@ -15,21 +15,20 @@ import io.openapiprocessor.core.model.datatypes.StringDataType
1515import io.openapiprocessor.spring.processor.SpringFrameworkAnnotations
1616import spock.lang.Specification
1717
18- class MappingAnnotationWriterSpec extends Specification {
18+ class MappingAnnotationFactorySpec extends Specification {
1919
20- def writer = new MappingAnnotationWriter (new SpringFrameworkAnnotations ())
21- def target = new StringWriter ()
20+ def factory = new MappingAnnotationFactory (new SpringFrameworkAnnotations ())
2221
2322 void " writes http method specific mapping annotation" () {
24- def endpoint = createEndpoint (path : path, method : httpMethod, responses : [
23+ def endpoint = endpoint (path : path, method : httpMethod, responses : [
2524 ' 204' : [new EmptyResponse ()]
2625 ])
2726
2827 when :
29- writer . write (target, endpoint, endpoint. endpointResponses. first ())
28+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
3029
3130 then :
32- target . toString () == expected
31+ annotations . first () == expected
3332
3433 where :
3534 httpMethod | path | expected
@@ -44,17 +43,17 @@ class MappingAnnotationWriterSpec extends Specification {
4443 }
4544
4645 void " writes 'consumes' parameter with body content type" () {
47- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
46+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
4847 ' 204' : [new EmptyResponse ()]
4948 ], requestBodies : [
5049 new RequestBody (' body' , contentType, new StringDataType (), false , false , null )
5150 ])
5251
5352 when :
54- writer . write (target, endpoint, endpoint. endpointResponses. first ())
53+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
5554
5655 then :
57- target . toString () == expected
56+ annotations . first () == expected
5857
5958 where :
6059 contentType | expected
@@ -63,15 +62,15 @@ class MappingAnnotationWriterSpec extends Specification {
6362 }
6463
6564 void " writes 'produces' parameter with response content type" () {
66- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
65+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
6766 ' 200' : [new Response (contentType, new StringDataType (), null )]
6867 ])
6968
7069 when :
71- writer . write (target, endpoint, endpoint. endpointResponses. first ())
70+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
7271
7372 then :
74- target . toString () == expected
73+ annotations . first () == expected
7574
7675 where :
7776 contentType | expected
@@ -80,7 +79,7 @@ class MappingAnnotationWriterSpec extends Specification {
8079 }
8180
8281 void " writes 'consumes' & 'produces' parameters" () {
83- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
82+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
8483 ' 200' : [
8584 new Response (responseContentType, new StringDataType (), null )
8685 ]
@@ -90,18 +89,18 @@ class MappingAnnotationWriterSpec extends Specification {
9089 ])
9190
9291 when :
93- writer . write (target, endpoint, endpoint. endpointResponses. first ())
92+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
9493
9594 then :
96- target . toString () == expected
95+ annotations . first () == expected
9796
9897 where :
9998 requestContentType | responseContentType | expected
10099 ' foo/in' | ' foo/out' | """ @GetMapping(path = "/foo", consumes = {"foo/in"}, produces = {"foo/out"})"""
101100 }
102101
103102 void " writes mapping annotation with multiple result content types" () {
104- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
103+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
105104 ' 200' : [
106105 new Response (' application/json' , new StringDataType (), null )
107106 ],
@@ -111,14 +110,14 @@ class MappingAnnotationWriterSpec extends Specification {
111110 ])
112111
113112 when :
114- writer . write (target, endpoint, endpoint. endpointResponses. first ())
113+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
115114
116115 then :
117- target . toString () == """ @GetMapping(path = "${ endpoint.path} ", produces = {"${ endpoint.responses.'200'.first ().contentType} ", "${ endpoint.responses.'default'.first ().contentType} "})"""
116+ annotations . first () == """ @GetMapping(path = "${ endpoint.path} ", produces = {"${ endpoint.responses.'200'.first ().contentType} ", "${ endpoint.responses.'default'.first ().contentType} "})"""
118117 }
119118
120119 void " writes unique 'consumes' parameter" () {
121- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
120+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
122121 ' 204' : [new EmptyResponse ()]
123122 ], requestBodies : [
124123 new RequestBody (' body' , ' foo/in' , new StringDataType (), false , false ,
@@ -130,14 +129,14 @@ class MappingAnnotationWriterSpec extends Specification {
130129 ])
131130
132131 when :
133- writer . write (target, endpoint, endpoint. endpointResponses. first ())
132+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
134133
135134 then :
136- target . toString (). contains (' consumes = {"foo/in"}' )
135+ annotations . first (). contains (' consumes = {"foo/in"}' )
137136 }
138137
139138 void " writes unique 'produces' parameters" () {
140- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
139+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
141140 ' 200' : [
142141 new Response (' foo/out' , new StringDataType (), null )
143142 ],
@@ -153,14 +152,13 @@ class MappingAnnotationWriterSpec extends Specification {
153152 ])
154153
155154 when :
156- writer . write (target, endpoint, endpoint. endpointResponses. first ())
155+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
157156
158157 then :
159- target . toString (). contains (' produces = {"foo/out"}' )
158+ annotations . first (). contains (' produces = {"foo/out"}' )
160159 }
161160
162- @Deprecated
163- private Endpoint createEndpoint (Map properties ) {
161+ private Endpoint endpoint (Map properties ) {
164162 return new Endpoint (
165163 properties. path as String ?: ' ' ,
166164 properties. method as HttpMethod ?: HttpMethod . GET ,
@@ -172,5 +170,4 @@ class MappingAnnotationWriterSpec extends Specification {
172170 new Documentation (null , properties. description as String ),
173171 )
174172 }
175-
176173}
0 commit comments