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
269bb914
Commit
269bb914
authored
Aug 22, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add methods to RestTemplateBuilder for configuring interceptors
Closes gh-6701
parent
32d0021e
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
153 additions
and
16 deletions
+153
-16
RestTemplateBuilder.java
.../springframework/boot/web/client/RestTemplateBuilder.java
+94
-16
RestTemplateBuilderTests.java
...ngframework/boot/web/client/RestTemplateBuilderTests.java
+59
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java
View file @
269bb914
This diff is collapsed.
Click to expand it.
spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java
View file @
269bb914
...
@@ -72,6 +72,9 @@ public class RestTemplateBuilderTests {
...
@@ -72,6 +72,9 @@ public class RestTemplateBuilderTests {
@Mock
@Mock
private
HttpMessageConverter
<
Object
>
messageConverter
;
private
HttpMessageConverter
<
Object
>
messageConverter
;
@Mock
private
ClientHttpRequestInterceptor
interceptor
;
@Before
@Before
public
void
setup
()
{
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
MockitoAnnotations
.
initMocks
(
this
);
...
@@ -203,6 +206,62 @@ public class RestTemplateBuilderTests {
...
@@ -203,6 +206,62 @@ public class RestTemplateBuilderTests {
.
hasSameSizeAs
(
new
RestTemplate
().
getMessageConverters
());
.
hasSameSizeAs
(
new
RestTemplate
().
getMessageConverters
());
}
}
@Test
public
void
interceptorsWhenInterceptorsAreNullShouldThrowException
()
throws
Exception
{
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expectMessage
(
"interceptors must not be null"
);
this
.
builder
.
interceptors
((
ClientHttpRequestInterceptor
[])
null
);
}
@Test
public
void
interceptorsCollectionWhenInterceptorsAreNullShouldThrowException
()
throws
Exception
{
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expectMessage
(
"interceptors must not be null"
);
this
.
builder
.
interceptors
((
Set
<
ClientHttpRequestInterceptor
>)
null
);
}
@Test
public
void
interceptorsShouldApply
()
throws
Exception
{
RestTemplate
template
=
this
.
builder
.
interceptors
(
this
.
interceptor
).
build
();
assertThat
(
template
.
getInterceptors
()).
containsOnly
(
this
.
interceptor
);
}
@Test
public
void
interceptorsShouldReplaceExisting
()
throws
Exception
{
RestTemplate
template
=
this
.
builder
.
interceptors
(
mock
(
ClientHttpRequestInterceptor
.
class
))
.
interceptors
(
Collections
.
singleton
(
this
.
interceptor
)).
build
();
assertThat
(
template
.
getInterceptors
()).
containsOnly
(
this
.
interceptor
);
}
@Test
public
void
additionalInterceptorsWhenInterceptorsAreNullShouldThrowException
()
throws
Exception
{
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expectMessage
(
"interceptors must not be null"
);
this
.
builder
.
additionalInterceptors
((
ClientHttpRequestInterceptor
[])
null
);
}
@Test
public
void
additionalInterceptorsCollectionWhenInterceptorsAreNullShouldThrowException
()
throws
Exception
{
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expectMessage
(
"interceptors must not be null"
);
this
.
builder
.
additionalInterceptors
((
Set
<
ClientHttpRequestInterceptor
>)
null
);
}
@Test
public
void
additionalInterceptorsShouldAddToExisting
()
throws
Exception
{
ClientHttpRequestInterceptor
interceptor
=
mock
(
ClientHttpRequestInterceptor
.
class
);
RestTemplate
template
=
this
.
builder
.
interceptors
(
interceptor
)
.
additionalInterceptors
(
this
.
interceptor
).
build
();
assertThat
(
template
.
getInterceptors
()).
containsOnly
(
interceptor
,
this
.
interceptor
);
}
@Test
@Test
public
void
requestFactoryClassWhenFactoryIsNullShouldThrowException
()
public
void
requestFactoryClassWhenFactoryIsNullShouldThrowException
()
throws
Exception
{
throws
Exception
{
...
...
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