11/*
2- * Copyright © 2020 https://github.com/openapi-processor/openapi-processor-micronaut
2+ * Copyright 2020 https://github.com/openapi-processor/openapi-processor-micronaut
33 * PDX-License-Identifier: Apache-2.0
44 */
55
@@ -13,23 +13,22 @@ import io.openapiprocessor.core.model.RequestBody
1313import io.openapiprocessor.core.model.Response
1414import io.openapiprocessor.core.model.datatypes.StringDataType
1515import io.openapiprocessor.core.model.parameters.MultipartParameter
16- import spock.lang.Ignore
16+ import io.openapiprocessor.micronaut.processor.MicronautFrameworkAnnotations
1717import spock.lang.Specification
1818
19- class MappingAnnotationWriterSpec extends Specification {
20- def writer = new MappingAnnotationWriter ()
21- def target = new StringWriter ()
19+ class MappingAnnotationFactorySpec extends Specification {
20+ def factory = new MappingAnnotationFactory (new MicronautFrameworkAnnotations ())
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,18 +43,18 @@ 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 ,
5150 null )
5251 ])
5352
5453 when :
55- writer . write (target, endpoint, endpoint. endpointResponses. first ())
54+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
5655
5756 then :
58- target . toString () == expected
57+ annotations . first () == expected
5958
6059 where :
6160 contentType | expected
@@ -64,17 +63,17 @@ class MappingAnnotationWriterSpec extends Specification {
6463 }
6564
6665 void " writes 'produces' parameter with response content type" () {
67- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
66+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
6867 ' 200' : [
6968 new Response (contentType, new StringDataType (), null )
7069 ],
7170 ])
7271
7372 when :
74- writer . write (target, endpoint, endpoint. endpointResponses. first ())
73+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
7574
7675 then :
77- target . toString () == expected
76+ annotations . first () == expected
7877
7978 where :
8079 contentType | expected
@@ -83,7 +82,7 @@ class MappingAnnotationWriterSpec extends Specification {
8382 }
8483
8584 void " writes 'consumes' & 'produces' parameters" () {
86- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
85+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
8786 ' 200' : [
8887 new Response (responseContentType, new StringDataType (), null )
8988 ]
@@ -93,18 +92,18 @@ class MappingAnnotationWriterSpec extends Specification {
9392 ])
9493
9594 when :
96- writer . write (target, endpoint, endpoint. endpointResponses. first ())
95+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
9796
9897 then :
99- target . toString () == expected
98+ annotations . first () == expected
10099
101100 where :
102101 requestContentType | responseContentType | expected
103102 ' foo/in' | ' foo/out' | """ @Get(uri = "/foo", consumes = {"foo/in"}, produces = {"foo/out"})"""
104103 }
105104
106105 void " writes mapping annotation with multiple result content types" () {
107- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
106+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
108107 ' 200' : [
109108 new Response (' application/json' , new StringDataType (), null )
110109 ],
@@ -114,15 +113,14 @@ class MappingAnnotationWriterSpec extends Specification {
114113 ])
115114
116115 when :
117- writer . write (target, endpoint, endpoint. endpointResponses. first ())
116+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
118117
119118 then :
120- target . toString () == """ @Get(uri = "${ endpoint.path} ", produces = {"${ endpoint.responses.'200'.first ().contentType} ", "${ endpoint.responses.'default'.first ().contentType} "})"""
119+ annotations . first () == """ @Get(uri = "${ endpoint.path} ", produces = {"${ endpoint.responses.'200'.first ().contentType} ", "${ endpoint.responses.'default'.first ().contentType} "})"""
121120 }
122121
123- @Ignore // todo
124122 void " writes 'consumes' of multipart/form-data" () {
125- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET ,
123+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET ,
126124 parameters : [
127125 new MultipartParameter (' mp1' , new StringDataType (), false , false , null ),
128126 new MultipartParameter (' mp2' , new StringDataType (), false , false , null )
@@ -133,14 +131,14 @@ class MappingAnnotationWriterSpec extends Specification {
133131 )
134132
135133 when :
136- writer . write (target, endpoint, endpoint. endpointResponses. first ())
134+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
137135
138136 then :
139- target . toString () == """ @Get(uri = "${ endpoint.path} ", consumes = {"multipart/form-data"})"""
137+ annotations . first () == """ @Get(uri = "${ endpoint.path} ", consumes = {"multipart/form-data"})"""
140138 }
141139
142140 void " writes unique 'consumes' parameter" () {
143- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
141+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
144142 ' 204' : [new EmptyResponse ()]
145143 ], requestBodies : [
146144 new RequestBody (' body' , ' foo/in' , new StringDataType (), false , false ,
@@ -152,14 +150,14 @@ class MappingAnnotationWriterSpec extends Specification {
152150 ])
153151
154152 when :
155- writer . write (target, endpoint, endpoint. endpointResponses. first ())
153+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
156154
157155 then :
158- target . toString (). contains (' consumes = {"foo/in"}' )
156+ annotations . first (). contains (' consumes = {"foo/in"}' )
159157 }
160158
161159 void " writes unique 'produces' parameters" () {
162- def endpoint = createEndpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
160+ def endpoint = endpoint (path : ' /foo' , method : HttpMethod . GET , responses : [
163161 ' 200' : [
164162 new Response (' foo/out' , new StringDataType (), null )
165163 ],
@@ -175,14 +173,13 @@ class MappingAnnotationWriterSpec extends Specification {
175173 ])
176174
177175 when :
178- writer . write (target, endpoint, endpoint. endpointResponses. first ())
176+ def annotations = factory . create ( endpoint, endpoint. endpointResponses. first ())
179177
180178 then :
181- target . toString (). contains (' produces = {"foo/out"}' )
179+ annotations . first (). contains (' produces = {"foo/out"}' )
182180 }
183181
184- @Deprecated
185- private Endpoint createEndpoint (Map properties ) {
182+ private Endpoint endpoint (Map properties ) {
186183 return new Endpoint (
187184 properties. path as String ?: ' ' ,
188185 properties. method as HttpMethod ?: HttpMethod . GET ,
0 commit comments