56
56
public class SpringAnnotationProcessorTest {
57
57
58
58
@ Test
59
- public void getHttpMethod () throws NoSuchMethodException {
60
- SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
59
+ public void methodOfRequestMapping () throws NoSuchMethodException {
61
60
61
+ // class level
62
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
62
63
OasContext oasContext = new OasContext (parser );
63
64
Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
64
65
RequestMapping requestMappingClassAnnotation = httpMethodResourceClass .getAnnotation (RequestMapping .class );
65
66
RequestMappingClassAnnotationProcessor requestMappingClassAnnotationProcessor = new RequestMappingClassAnnotationProcessor ();
66
67
requestMappingClassAnnotationProcessor .process (requestMappingClassAnnotation , oasContext );
67
- Assert .assertEquals (requestMappingClassAnnotation .value ()[0 ], oasContext .getBasePath ());
68
68
Assert .assertEquals (RequestMethod .GET .name (), oasContext .getHttpMethod ());
69
69
70
+ // method level
70
71
RequestMappingMethodAnnotationProcessor requestMappingMethodAnnotationProcessor = new RequestMappingMethodAnnotationProcessor ();
71
72
Method requestMethod = httpMethodResourceClass .getMethod ("request" );
72
73
RequestMapping requestMappingMethodAnnotation = requestMethod .getAnnotation (RequestMapping .class );
73
74
OperationContext requestOperationContext = new OperationContext (requestMethod , oasContext );
74
75
requestMappingMethodAnnotationProcessor .process (requestMappingMethodAnnotation , requestOperationContext );
75
- Assert
76
- .assertEquals (requestMappingMethodAnnotation .value ()[0 ],
77
- requestOperationContext .getPath ());
78
76
Assert .assertEquals (RequestMethod .POST .name (), requestOperationContext .getHttpMethod ());
79
77
78
+ // default
80
79
Method getRequestMethod = httpMethodResourceClass .getMethod ("getRequest" );
81
80
RequestMapping getRequestMappingMethodAnnotation = getRequestMethod .getAnnotation (RequestMapping .class );
82
81
OperationContext getRequestOperationContext = new OperationContext (getRequestMethod , oasContext );
83
82
requestMappingMethodAnnotationProcessor .process (getRequestMappingMethodAnnotation , getRequestOperationContext );
84
- Assert
85
- .assertEquals (getRequestMappingMethodAnnotation .value ()[0 ],
86
- getRequestOperationContext .getPath ());
87
83
Assert .assertEquals (RequestMethod .GET .name (), getRequestOperationContext .getHttpMethod ());
84
+ }
85
+
86
+ @ Test
87
+ public void pathOfRequestMapping () {
88
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
89
+ OasContext oasContext = new OasContext (parser );
90
+ Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
91
+ RequestMapping requestMappingClassAnnotation = httpMethodResourceClass .getAnnotation (RequestMapping .class );
92
+ RequestMappingClassAnnotationProcessor requestMappingClassAnnotationProcessor = new RequestMappingClassAnnotationProcessor ();
93
+ requestMappingClassAnnotationProcessor .process (requestMappingClassAnnotation , oasContext );
94
+ Assert .assertEquals (requestMappingClassAnnotation .value ()[0 ], oasContext .getBasePath ());
95
+ }
96
+
97
+ @ Test
98
+ public void headersOfRequestMapping () throws NoSuchMethodException {
99
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
100
+ OasContext oasContext = new OasContext (parser );
101
+ Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
102
+ RequestMappingMethodAnnotationProcessor requestMappingMethodAnnotationProcessor = new RequestMappingMethodAnnotationProcessor ();
103
+ Method requestMethod = httpMethodResourceClass .getMethod ("request" );
104
+ RequestMapping requestMappingMethodAnnotation = requestMethod .getAnnotation (RequestMapping .class );
105
+ OperationContext requestOperationContext = new OperationContext (requestMethod , oasContext );
106
+ requestMappingMethodAnnotationProcessor .process (requestMappingMethodAnnotation , requestOperationContext );
107
+ Assert .assertArrayEquals (requestMappingMethodAnnotation .headers (), requestOperationContext .getHeaders ());
108
+ }
109
+
110
+ @ Test
111
+ public void consumesOfRequestMapping () throws NoSuchMethodException {
112
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
113
+ OasContext oasContext = new OasContext (parser );
114
+ Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
115
+ RequestMappingMethodAnnotationProcessor requestMappingMethodAnnotationProcessor = new RequestMappingMethodAnnotationProcessor ();
116
+ Method requestMethod = httpMethodResourceClass .getMethod ("request" );
117
+ RequestMapping requestMappingMethodAnnotation = requestMethod .getAnnotation (RequestMapping .class );
118
+ OperationContext requestOperationContext = new OperationContext (requestMethod , oasContext );
119
+ requestMappingMethodAnnotationProcessor .process (requestMappingMethodAnnotation , requestOperationContext );
120
+ Assert .assertArrayEquals (requestMappingMethodAnnotation .consumes (), requestOperationContext .getConsumers ());
121
+ }
122
+
123
+ @ Test
124
+ public void producesOfRequestMapping () throws NoSuchMethodException {
125
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
126
+ OasContext oasContext = new OasContext (parser );
127
+ Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
128
+ RequestMappingMethodAnnotationProcessor requestMappingMethodAnnotationProcessor = new RequestMappingMethodAnnotationProcessor ();
129
+ Method requestMethod = httpMethodResourceClass .getMethod ("request" );
130
+ RequestMapping requestMappingMethodAnnotation = requestMethod .getAnnotation (RequestMapping .class );
131
+ OperationContext requestOperationContext = new OperationContext (requestMethod , oasContext );
132
+ requestMappingMethodAnnotationProcessor .process (requestMappingMethodAnnotation , requestOperationContext );
133
+ Assert .assertArrayEquals (requestMappingMethodAnnotation .produces (), requestOperationContext .getProduces ());
134
+ }
135
+
136
+
137
+ @ Test
138
+ public void methodOfGetMapping () throws NoSuchMethodException {
139
+
140
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
141
+ OasContext oasContext = new OasContext (parser );
142
+ Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
88
143
89
144
GetMappingMethodAnnotationProcessor getMappingMethodAnnotationProcessor = new GetMappingMethodAnnotationProcessor ();
90
145
Method getMethod = httpMethodResourceClass .getMethod ("get" );
@@ -93,6 +148,14 @@ public void getHttpMethod() throws NoSuchMethodException {
93
148
getMappingMethodAnnotationProcessor .process (getMappingAnnotation , getOperationContext );
94
149
Assert
95
150
.assertEquals (getMappingAnnotation .value ()[0 ], getOperationContext .getPath ());
151
+ }
152
+
153
+ @ Test
154
+ public void methodOfPostMapping () throws NoSuchMethodException {
155
+
156
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
157
+ OasContext oasContext = new OasContext (parser );
158
+ Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
96
159
97
160
PostMappingMethodAnnotationProcessor postMappingMethodAnnotationProcessor = new PostMappingMethodAnnotationProcessor ();
98
161
Method postMethod = httpMethodResourceClass .getMethod ("post" );
@@ -101,6 +164,14 @@ public void getHttpMethod() throws NoSuchMethodException {
101
164
postMappingMethodAnnotationProcessor .process (postMappingAnnotation , postOperationContext );
102
165
Assert
103
166
.assertEquals (postMappingAnnotation .value ()[0 ], postOperationContext .getPath ());
167
+ }
168
+
169
+ @ Test
170
+ public void methodOfPutMapping () throws NoSuchMethodException {
171
+
172
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
173
+ OasContext oasContext = new OasContext (parser );
174
+ Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
104
175
105
176
PutMappingMethodAnnotationProcessor putMappingMethodAnnotationProcessor = new PutMappingMethodAnnotationProcessor ();
106
177
Method putMethod = httpMethodResourceClass .getMethod ("put" );
@@ -109,6 +180,13 @@ public void getHttpMethod() throws NoSuchMethodException {
109
180
putMappingMethodAnnotationProcessor .process (putMappingAnnotation , putOperationContext );
110
181
Assert
111
182
.assertEquals (putMappingAnnotation .value ()[0 ], putOperationContext .getPath ());
183
+ }
184
+
185
+ @ Test
186
+ public void methodOfDeleteMapping () throws NoSuchMethodException {
187
+ SpringmvcAnnotationParser parser = new SpringmvcAnnotationParser ();
188
+ OasContext oasContext = new OasContext (parser );
189
+ Class <HttpMethodResource > httpMethodResourceClass = HttpMethodResource .class ;
112
190
113
191
DeleteMappingMethodAnnotationProcessor deleteMappingMethodAnnotationProcessor = new DeleteMappingMethodAnnotationProcessor ();
114
192
Method deleteMethod = httpMethodResourceClass .getMethod ("delete" );
@@ -195,7 +273,7 @@ public void interceptorModel() {
195
273
@ RequestMapping (value = "/path" , method = RequestMethod .GET )
196
274
class HttpMethodResource {
197
275
198
- @ RequestMapping (value = "/request" , method = RequestMethod .POST , headers = "cookie=1" )
276
+ @ RequestMapping (value = "/request" , method = RequestMethod .POST , headers = "cookie=1" , consumes = "application/json" , produces = "application/json" )
199
277
public String request () {
200
278
return "request" ;
201
279
}
0 commit comments