|
27 | 27 | import java.net.URL; |
28 | 28 | import java.util.Arrays; |
29 | 29 | import java.util.HashMap; |
| 30 | +import java.util.Map; |
30 | 31 |
|
31 | 32 | public class URLPathUtilsTest { |
32 | 33 |
|
@@ -204,4 +205,56 @@ public void useDefaultUrlWhenServerUrlIsNull() { |
204 | 205 | URL serverURL = URLPathUtils.getServerURL(server, null); |
205 | 206 | Assert.assertEquals(serverURL.toString(), "http://localhost"); |
206 | 207 | } |
| 208 | + |
| 209 | + @Test |
| 210 | + public void testPropertyUrl() { |
| 211 | + String[][] testData = { |
| 212 | + {"https://abc1.xyz:9999/some/${my.property}", "https://abc1.xyz:9999/some/${my.property}"}, |
| 213 | + {"HTTPS://abc2.xyz:9999/some/${my.property}", "https://abc2.xyz:9999/some/${my.property}"}, |
| 214 | + {"http://abc3.xyz:9999/${my.property}/path", "http://abc3.xyz:9999/${my.property}/path"}, |
| 215 | + {"HTTP://abc4.xyz:9999/some/${my.property}", "http://abc4.xyz:9999/some/${my.property}"}, |
| 216 | + {"//abc5.xyz:9999/some/${my.property}", "http://abc5.xyz:9999/some/${my.property}"}, |
| 217 | + {"abc6.xyz:9999/some/path", "http://abc6.xyz:9999/some/path"}, |
| 218 | + {"localhost:9000/${my.property}", "http://localhost:9000/${my.property}"}, |
| 219 | + {"/${my.property}/path", "http://localhost/${my.property}/path"}, |
| 220 | + {"https://abc1.xyz:9999/some/${my.property}/{version}", "https://abc1.xyz:9999/some/${my.property}/v1"}, |
| 221 | + {"HTTPS://abc2.xyz:9999/${my.property}/{version}", "https://abc2.xyz:9999/${my.property}/v1"}, |
| 222 | + {"https://abc1.xyz:9999/some/{version}/${my.property}", "https://abc1.xyz:9999/some/v1/${my.property}"}, |
| 223 | + {"HTTPS://abc2.xyz:9999/{version}/${my.property}", "https://abc2.xyz:9999/v1/${my.property}"} |
| 224 | + |
| 225 | + }; |
| 226 | + |
| 227 | + for (String[] t : testData) { |
| 228 | + OpenAPI openAPI = new OpenAPI(); |
| 229 | + openAPI.addServersItem(new Server().url(t[0])); |
| 230 | + |
| 231 | + Assert.assertEquals(URLPathUtils.getServerURL(openAPI, Map.of("version", "v1") ).toString(), t[1]); |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + @Test |
| 236 | + public void testPropertyUrlInVariable() { |
| 237 | + String[][] testData = { |
| 238 | + {"https://abc1.xyz:9999/some/{my.property}", "https://abc1.xyz:9999/some/${my.property}"}, |
| 239 | + {"HTTPS://abc2.xyz:9999/some/{my.property}", "https://abc2.xyz:9999/some/${my.property}"}, |
| 240 | + {"http://abc3.xyz:9999/{my.property}/path", "http://abc3.xyz:9999/${my.property}/path"}, |
| 241 | + {"HTTP://abc4.xyz:9999/some/{my.property}", "http://abc4.xyz:9999/some/${my.property}"}, |
| 242 | + {"//abc5.xyz:9999/some/{my.property}", "http://abc5.xyz:9999/some/${my.property}"}, |
| 243 | + {"abc6.xyz:9999/some/path", "http://abc6.xyz:9999/some/path"}, |
| 244 | + {"localhost:9000/{my.property}", "http://localhost:9000/${my.property}"}, |
| 245 | + {"/{my.property}/path", "http://localhost/${my.property}/path"}, |
| 246 | + {"https://abc1.xyz:9999/some/{my.property}/{version}", "https://abc1.xyz:9999/some/${my.property}/v1"}, |
| 247 | + {"HTTPS://abc2.xyz:9999/{my.property}/{version}", "https://abc2.xyz:9999/${my.property}/v1"}, |
| 248 | + {"https://abc1.xyz:9999/some/{version}/{my.property}", "https://abc1.xyz:9999/some/v1/${my.property}"}, |
| 249 | + {"HTTPS://abc2.xyz:9999/{version}/{my.property}", "https://abc2.xyz:9999/v1/${my.property}"} |
| 250 | + |
| 251 | + }; |
| 252 | + |
| 253 | + for (String[] t : testData) { |
| 254 | + OpenAPI openAPI = new OpenAPI(); |
| 255 | + openAPI.addServersItem(new Server().url(t[0])); |
| 256 | + |
| 257 | + Assert.assertEquals(URLPathUtils.getServerURL(openAPI, Map.of("version", "v1", "my.property", "${my.property}") ).toString(), t[1]); |
| 258 | + } |
| 259 | + } |
207 | 260 | } |
0 commit comments