Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
7ea87705
Commit
7ea87705
authored
Mar 19, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Fix request factory used with withBasicAuth"
Fixes gh-15982
parent
756bd890
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
5 deletions
+32
-5
TestRestTemplate.java
...pringframework/boot/test/web/client/TestRestTemplate.java
+2
-4
TestRestTemplateTests.java
...framework/boot/test/web/client/TestRestTemplateTests.java
+30
-1
No files found.
spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java
View file @
7ea87705
...
...
@@ -1027,10 +1027,8 @@ public class TestRestTemplate {
/**
* Creates a new {@code TestRestTemplate} with the same configuration as this one,
* except that it will send basic authorization headers using the given
* {@code username} and {@code password}. Note, that a new instance of
* {@link ClientHttpRequestFactory} will be created (if possible) based on the current
* factory class, otherwise {@link ClientHttpRequestFactorySupplier} will be used to
* instantiate a {@link ClientHttpRequestFactory}.
* {@code username} and {@code password}. The request factory used is a new instance
* of the underlying {@link RestTemplate}'s request factory type (when possible).
* @param username the username
* @param password the password
* @return the new template
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java
View file @
7ea87705
...
...
@@ -33,6 +33,7 @@ import org.springframework.http.HttpEntity;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.RequestEntity
;
import
org.springframework.http.client.ClientHttpRequest
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
...
...
@@ -97,7 +98,7 @@ public class TestRestTemplateTests {
public
void
useTheSameRequestFactoryClassWithBasicAuth
()
{
OkHttp3ClientHttpRequestFactory
customFactory
=
new
OkHttp3ClientHttpRequestFactory
();
RestTemplateBuilder
builder
=
new
RestTemplateBuilder
()
.
requestFactory
(
OkHttp3ClientHttpRequestFactory:
:
new
);
.
requestFactory
(
()
->
customFactory
);
TestRestTemplate
testRestTemplate
=
new
TestRestTemplate
(
builder
)
.
withBasicAuth
(
"test"
,
"test"
);
RestTemplate
restTemplate
=
testRestTemplate
.
getRestTemplate
();
...
...
@@ -107,6 +108,21 @@ public class TestRestTemplateTests {
.
hasSameClassAs
(
customFactory
);
}
@Test
public
void
withBasicAuthWhenRequestFactoryTypeCannotBeInstantiatedShouldFallback
()
{
TestClientHttpRequestFactory
customFactory
=
new
TestClientHttpRequestFactory
(
"my-request-factory"
);
RestTemplateBuilder
builder
=
new
RestTemplateBuilder
()
.
requestFactory
(()
->
customFactory
);
TestRestTemplate
testRestTemplate
=
new
TestRestTemplate
(
builder
)
.
withBasicAuth
(
"test"
,
"test"
);
RestTemplate
restTemplate
=
testRestTemplate
.
getRestTemplate
();
Object
requestFactory
=
ReflectionTestUtils
.
getField
(
restTemplate
.
getRequestFactory
(),
"requestFactory"
);
assertThat
(
requestFactory
).
isNotEqualTo
(
customFactory
)
.
isInstanceOf
(
CustomHttpComponentsClientHttpRequestFactory
.
class
);
}
@Test
public
void
getRootUriRootUriSetViaRestTemplateBuilder
()
{
String
rootUri
=
"http://example.com"
;
...
...
@@ -397,4 +413,17 @@ public class TestRestTemplateTests {
}
static
class
TestClientHttpRequestFactory
implements
ClientHttpRequestFactory
{
TestClientHttpRequestFactory
(
String
value
)
{
}
@Override
public
ClientHttpRequest
createRequest
(
URI
uri
,
HttpMethod
httpMethod
)
throws
IOException
{
return
null
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment