|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -233,6 +233,36 @@ void withBasicAuthShouldUseNoOpErrorHandler() throws Exception {
|
233 | 233 | Class.forName("org.springframework.boot.test.web.client.TestRestTemplate$NoOpResponseErrorHandler"));
|
234 | 234 | }
|
235 | 235 |
|
| 236 | + @Test |
| 237 | + void exchangeWithRelativeTemplatedUrlRequestEntity() throws Exception { |
| 238 | + RequestEntity<Void> entity = RequestEntity.get("/a/b/c.{ext}", "txt").build(); |
| 239 | + TestRestTemplate template = new TestRestTemplate(); |
| 240 | + ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class); |
| 241 | + MockClientHttpRequest request = new MockClientHttpRequest(); |
| 242 | + request.setResponse(new MockClientHttpResponse(new byte[0], HttpStatus.OK)); |
| 243 | + URI absoluteUri = URI.create("http://localhost:8080/a/b/c.txt"); |
| 244 | + given(requestFactory.createRequest(eq(absoluteUri), eq(HttpMethod.GET))).willReturn(request); |
| 245 | + template.getRestTemplate().setRequestFactory(requestFactory); |
| 246 | + LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(new MockEnvironment()); |
| 247 | + template.setUriTemplateHandler(uriTemplateHandler); |
| 248 | + template.exchange(entity, String.class); |
| 249 | + verify(requestFactory).createRequest(eq(absoluteUri), eq(HttpMethod.GET)); |
| 250 | + } |
| 251 | + |
| 252 | + @Test |
| 253 | + void exchangeWithAbsoluteTemplatedUrlRequestEntity() throws Exception { |
| 254 | + RequestEntity<Void> entity = RequestEntity.get("https://api.example.com/a/b/c.{ext}", "txt").build(); |
| 255 | + TestRestTemplate template = new TestRestTemplate(); |
| 256 | + ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class); |
| 257 | + MockClientHttpRequest request = new MockClientHttpRequest(); |
| 258 | + request.setResponse(new MockClientHttpResponse(new byte[0], HttpStatus.OK)); |
| 259 | + URI absoluteUri = URI.create("https://api.example.com/a/b/c.txt"); |
| 260 | + given(requestFactory.createRequest(eq(absoluteUri), eq(HttpMethod.GET))).willReturn(request); |
| 261 | + template.getRestTemplate().setRequestFactory(requestFactory); |
| 262 | + template.exchange(entity, String.class); |
| 263 | + verify(requestFactory).createRequest(eq(absoluteUri), eq(HttpMethod.GET)); |
| 264 | + } |
| 265 | + |
236 | 266 | @Test
|
237 | 267 | void deleteHandlesRelativeUris() throws IOException {
|
238 | 268 | verifyRelativeUriHandling(TestRestTemplate::delete);
|
|
0 commit comments