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
c1205c32
Commit
c1205c32
authored
Oct 14, 2017
by
tinexw
Committed by
Andy Wilkinson
Nov 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide access to root URI from TestRestTemplate
Closes gh-10641
parent
e92e56dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
TestRestTemplate.java
...pringframework/boot/test/web/client/TestRestTemplate.java
+10
-0
TestRestTemplateTests.java
...framework/boot/test/web/client/TestRestTemplateTests.java
+26
-0
No files found.
spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java
View file @
c1205c32
...
@@ -78,6 +78,7 @@ import org.springframework.web.util.UriTemplateHandler;
...
@@ -78,6 +78,7 @@ import org.springframework.web.util.UriTemplateHandler;
* @author Dave Syer
* @author Dave Syer
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Kristine Jetzke
* @since 1.4.0
* @since 1.4.0
*/
*/
public
class
TestRestTemplate
{
public
class
TestRestTemplate
{
...
@@ -165,6 +166,15 @@ public class TestRestTemplate {
...
@@ -165,6 +166,15 @@ public class TestRestTemplate {
this
.
restTemplate
.
setUriTemplateHandler
(
handler
);
this
.
restTemplate
.
setUriTemplateHandler
(
handler
);
}
}
public
String
getRootUri
()
{
UriTemplateHandler
uriTemplateHandler
=
this
.
restTemplate
.
getUriTemplateHandler
();
if
(
RootUriTemplateHandler
.
class
.
isAssignableFrom
(
uriTemplateHandler
.
getClass
()))
{
return
((
RootUriTemplateHandler
)
uriTemplateHandler
).
getRootUri
();
}
return
""
;
}
/**
/**
* Retrieve a representation by doing a GET on the specified URL. The response (if
* Retrieve a representation by doing a GET on the specified URL. The response (if
* any) is converted and returned.
* any) is converted and returned.
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java
View file @
c1205c32
...
@@ -63,6 +63,7 @@ import static org.mockito.Mockito.verify;
...
@@ -63,6 +63,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Kristine Jetzke
*/
*/
public
class
TestRestTemplateTests
{
public
class
TestRestTemplateTests
{
...
@@ -81,6 +82,31 @@ public class TestRestTemplateTests {
...
@@ -81,6 +82,31 @@ public class TestRestTemplateTests {
.
isInstanceOf
(
HttpComponentsClientHttpRequestFactory
.
class
);
.
isInstanceOf
(
HttpComponentsClientHttpRequestFactory
.
class
);
}
}
@Test
public
void
getRootUriRootUriSetViaRestTemplateBuilder
()
{
String
rootUri
=
"http://example.com"
;
RestTemplate
delegate
=
new
RestTemplateBuilder
().
rootUri
(
rootUri
).
build
();
assertThat
(
new
TestRestTemplate
(
delegate
).
getRootUri
()).
isEqualTo
(
rootUri
);
}
@Test
public
void
getRootUriRootUriSetViaLocalHostUriTemplateHandler
()
{
String
rootUri
=
"http://example.com"
;
TestRestTemplate
template
=
new
TestRestTemplate
();
LocalHostUriTemplateHandler
templateHandler
=
mock
(
LocalHostUriTemplateHandler
.
class
);
given
(
templateHandler
.
getRootUri
()).
willReturn
(
rootUri
);
template
.
setUriTemplateHandler
(
templateHandler
);
assertThat
(
template
.
getRootUri
()).
isEqualTo
(
rootUri
);
}
@Test
public
void
getRootUriRootUriNotSet
()
{
assertThat
(
new
TestRestTemplate
().
getRootUri
()).
isEqualTo
(
""
);
}
@Test
@Test
public
void
authenticated
()
{
public
void
authenticated
()
{
assertThat
(
new
TestRestTemplate
(
"user"
,
"password"
).
getRestTemplate
()
assertThat
(
new
TestRestTemplate
(
"user"
,
"password"
).
getRestTemplate
()
...
...
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