34
34
*/
35
35
public class CorsConfigurationTests {
36
36
37
- private CorsConfiguration config = new CorsConfiguration ();
38
-
39
37
@ Test
40
38
public void setNullValues () {
39
+ CorsConfiguration config = new CorsConfiguration ();
41
40
config .setAllowedOrigins (null );
42
41
assertNull (config .getAllowedOrigins ());
43
42
config .setAllowedHeaders (null );
@@ -54,6 +53,7 @@ public void setNullValues() {
54
53
55
54
@ Test
56
55
public void setValues () {
56
+ CorsConfiguration config = new CorsConfiguration ();
57
57
config .addAllowedOrigin ("*" );
58
58
assertEquals (Arrays .asList ("*" ), config .getAllowedOrigins ());
59
59
config .addAllowedHeader ("*" );
@@ -71,23 +71,27 @@ public void setValues() {
71
71
72
72
@ Test (expected = IllegalArgumentException .class )
73
73
public void asteriskWildCardOnAddExposedHeader () {
74
+ CorsConfiguration config = new CorsConfiguration ();
74
75
config .addExposedHeader ("*" );
75
76
}
76
77
77
78
@ Test (expected = IllegalArgumentException .class )
78
79
public void asteriskWildCardOnSetExposedHeaders () {
80
+ CorsConfiguration config = new CorsConfiguration ();
79
81
config .setExposedHeaders (Arrays .asList ("*" ));
80
82
}
81
83
82
84
@ Test
83
85
public void combineWithNull () {
86
+ CorsConfiguration config = new CorsConfiguration ();
84
87
config .setAllowedOrigins (Arrays .asList ("*" ));
85
88
config .combine (null );
86
89
assertEquals (Arrays .asList ("*" ), config .getAllowedOrigins ());
87
90
}
88
91
89
92
@ Test
90
93
public void combineWithNullProperties () {
94
+ CorsConfiguration config = new CorsConfiguration ();
91
95
config .addAllowedOrigin ("*" );
92
96
config .addAllowedHeader ("header1" );
93
97
config .addExposedHeader ("header3" );
@@ -106,6 +110,7 @@ public void combineWithNullProperties() {
106
110
107
111
@ Test
108
112
public void combineWithAsteriskWildCard () {
113
+ CorsConfiguration config = new CorsConfiguration ();
109
114
config .addAllowedOrigin ("*" );
110
115
config .addAllowedHeader ("*" );
111
116
config .addAllowedMethod ("*" );
@@ -128,6 +133,7 @@ public void combineWithAsteriskWildCard() {
128
133
129
134
@ Test
130
135
public void combine () {
136
+ CorsConfiguration config = new CorsConfiguration ();
131
137
config .addAllowedOrigin ("http://domain1.com" );
132
138
config .addAllowedHeader ("header1" );
133
139
config .addExposedHeader ("header3" );
@@ -152,6 +158,7 @@ public void combine() {
152
158
153
159
@ Test
154
160
public void checkOriginAllowed () {
161
+ CorsConfiguration config = new CorsConfiguration ();
155
162
config .setAllowedOrigins (Arrays .asList ("*" ));
156
163
assertEquals ("*" , config .checkOrigin ("http://domain.com" ));
157
164
config .setAllowCredentials (true );
@@ -164,6 +171,7 @@ public void checkOriginAllowed() {
164
171
165
172
@ Test
166
173
public void checkOriginNotAllowed () {
174
+ CorsConfiguration config = new CorsConfiguration ();
167
175
assertNull (config .checkOrigin (null ));
168
176
assertNull (config .checkOrigin ("http://domain.com" ));
169
177
config .addAllowedOrigin ("*" );
@@ -176,6 +184,7 @@ public void checkOriginNotAllowed() {
176
184
177
185
@ Test
178
186
public void checkMethodAllowed () {
187
+ CorsConfiguration config = new CorsConfiguration ();
179
188
assertEquals (Arrays .asList (HttpMethod .GET , HttpMethod .HEAD ), config .checkHttpMethod (HttpMethod .GET ));
180
189
config .addAllowedMethod ("GET" );
181
190
assertEquals (Arrays .asList (HttpMethod .GET ), config .checkHttpMethod (HttpMethod .GET ));
@@ -186,6 +195,7 @@ public void checkMethodAllowed() {
186
195
187
196
@ Test
188
197
public void checkMethodNotAllowed () {
198
+ CorsConfiguration config = new CorsConfiguration ();
189
199
assertNull (config .checkHttpMethod (null ));
190
200
assertNull (config .checkHttpMethod (HttpMethod .DELETE ));
191
201
config .setAllowedMethods (new ArrayList <>());
@@ -194,6 +204,7 @@ public void checkMethodNotAllowed() {
194
204
195
205
@ Test
196
206
public void checkHeadersAllowed () {
207
+ CorsConfiguration config = new CorsConfiguration ();
197
208
assertEquals (Collections .emptyList (), config .checkHeaders (Collections .emptyList ()));
198
209
config .addAllowedHeader ("header1" );
199
210
config .addAllowedHeader ("header2" );
@@ -204,13 +215,11 @@ public void checkHeadersAllowed() {
204
215
205
216
@ Test
206
217
public void checkHeadersNotAllowed () {
218
+ CorsConfiguration config = new CorsConfiguration ();
207
219
assertNull (config .checkHeaders (null ));
208
-
209
220
assertNull (config .checkHeaders (Arrays .asList ("header1" )));
210
-
211
221
config .setAllowedHeaders (Collections .emptyList ());
212
222
assertNull (config .checkHeaders (Arrays .asList ("header1" )));
213
-
214
223
config .addAllowedHeader ("header2" );
215
224
config .addAllowedHeader ("header3" );
216
225
assertNull (config .checkHeaders (Arrays .asList ("header1" )));
0 commit comments