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
87dd1150
Commit
87dd1150
authored
Jan 07, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor HypermediaAutoConfigurationTests
parent
ac10ebba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
53 deletions
+34
-53
HypermediaAutoConfigurationTests.java
...toconfigure/hateoas/HypermediaAutoConfigurationTests.java
+34
-53
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java
View file @
87dd1150
...
@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.hateoas;
...
@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.hateoas;
import
java.util.Optional
;
import
java.util.Optional
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
...
@@ -26,8 +25,7 @@ import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguratio
...
@@ -26,8 +25,7 @@ import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguratio
import
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration
;
import
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.hateoas.MediaTypes
;
import
org.springframework.hateoas.MediaTypes
;
import
org.springframework.hateoas.client.LinkDiscoverer
;
import
org.springframework.hateoas.client.LinkDiscoverer
;
...
@@ -39,7 +37,6 @@ import org.springframework.hateoas.server.EntityLinks;
...
@@ -39,7 +37,6 @@ import org.springframework.hateoas.server.EntityLinks;
import
org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter
;
import
org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
;
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -50,78 +47,62 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -50,78 +47,62 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Roy Clarkson
* @author Roy Clarkson
* @author Oliver Gierke
* @author Oliver Gierke
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Madhura Bhave
*/
*/
class
HypermediaAutoConfigurationTests
{
class
HypermediaAutoConfigurationTests
{
private
AnnotationConfigServletWebApplicationContext
context
;
private
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
.
withUserConfiguration
(
BaseConfig
.
class
);
@AfterEach
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
@Test
void
linkDiscoverersCreated
()
{
void
linkDiscoverersCreated
()
{
this
.
context
=
new
AnnotationConfigServletWebApplicationContext
();
this
.
contextRunner
.
run
((
context
)
->
{
this
.
context
.
setServletContext
(
new
MockServletContext
());
LinkDiscoverers
discoverers
=
context
.
getBean
(
LinkDiscoverers
.
class
);
this
.
context
.
register
(
BaseConfig
.
class
);
assertThat
(
discoverers
).
isNotNull
();
this
.
context
.
refresh
();
Optional
<
LinkDiscoverer
>
discoverer
=
discoverers
.
getLinkDiscovererFor
(
MediaTypes
.
HAL_JSON
);
LinkDiscoverers
discoverers
=
this
.
context
.
getBean
(
LinkDiscoverers
.
class
);
assertThat
(
discoverer
).
containsInstanceOf
(
HalLinkDiscoverer
.
class
);
assertThat
(
discoverers
).
isNotNull
();
});
Optional
<
LinkDiscoverer
>
discoverer
=
discoverers
.
getLinkDiscovererFor
(
MediaTypes
.
HAL_JSON
);
assertThat
(
discoverer
).
containsInstanceOf
(
HalLinkDiscoverer
.
class
);
}
}
@Test
@Test
void
entityLinksCreated
()
{
void
entityLinksCreated
()
{
this
.
context
=
new
AnnotationConfigServletWebApplicationContext
();
this
.
contextRunner
.
run
((
context
)
->
{
this
.
context
.
setServletContext
(
new
MockServletContext
());
EntityLinks
discoverers
=
context
.
getBean
(
EntityLinks
.
class
);
this
.
context
.
register
(
BaseConfig
.
class
);
assertThat
(
discoverers
).
isNotNull
();
this
.
context
.
refresh
();
});
EntityLinks
discoverers
=
this
.
context
.
getBean
(
EntityLinks
.
class
);
assertThat
(
discoverers
).
isNotNull
();
}
}
@Test
@Test
void
doesBackOffIfEnableHypermediaSupportIsDeclaredManually
()
{
void
doesBackOffIfEnableHypermediaSupportIsDeclaredManually
()
{
this
.
context
=
new
AnnotationConfigServletWebApplicationContext
();
this
.
contextRunner
.
withUserConfiguration
(
EnableHypermediaSupportConfig
.
class
)
this
.
context
.
setServletContext
(
new
MockServletContext
());
.
withPropertyValues
(
"spring.jackson.serialization.INDENT_OUTPUT:true"
)
this
.
context
.
register
(
EnableHypermediaSupportConfig
.
class
,
BaseConfig
.
class
);
.
run
((
context
)
->
assertThat
(
context
.
getBeansOfType
(
HypermediaConfiguration
.
class
)).
isEmpty
());
TestPropertyValues
.
of
(
"spring.jackson.serialization.INDENT_OUTPUT:true"
).
applyTo
(
this
.
context
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeansOfType
(
HypermediaConfiguration
.
class
)).
isEmpty
();
}
}
@Test
@Test
void
supportedMediaTypesOfTypeConstrainedConvertersIsCustomized
()
{
void
supportedMediaTypesOfTypeConstrainedConvertersIsCustomized
()
{
this
.
context
=
new
AnnotationConfigServletWebApplicationContext
();
this
.
contextRunner
.
run
((
context
)
->
{
this
.
context
.
setServletContext
(
new
MockServletContext
());
RequestMappingHandlerAdapter
handlerAdapter
=
context
.
getBean
(
RequestMappingHandlerAdapter
.
class
);
this
.
context
.
register
(
BaseConfig
.
class
);
for
(
HttpMessageConverter
<?>
converter
:
handlerAdapter
.
getMessageConverters
())
{
this
.
context
.
refresh
();
if
(
converter
instanceof
TypeConstrainedMappingJackson2HttpMessageConverter
)
{
RequestMappingHandlerAdapter
handlerAdapter
=
this
.
context
.
getBean
(
RequestMappingHandlerAdapter
.
class
);
assertThat
(
converter
.
getSupportedMediaTypes
()).
contains
(
MediaType
.
APPLICATION_JSON
,
for
(
HttpMessageConverter
<?>
converter
:
handlerAdapter
.
getMessageConverters
())
{
MediaTypes
.
HAL_JSON
);
if
(
converter
instanceof
TypeConstrainedMappingJackson2HttpMessageConverter
)
{
}
assertThat
(
converter
.
getSupportedMediaTypes
()).
contains
(
MediaType
.
APPLICATION_JSON
,
MediaTypes
.
HAL_JSON
);
}
}
}
}
);
}
}
@Test
@Test
void
customizationOfSupportedMediaTypesCanBeDisabled
()
{
void
customizationOfSupportedMediaTypesCanBeDisabled
()
{
this
.
context
=
new
AnnotationConfigServletWebApplicationContext
();
this
.
contextRunner
.
withPropertyValues
(
"spring.hateoas.use-hal-as-default-json-media-type:false"
)
this
.
context
.
setServletContext
(
new
MockServletContext
());
.
run
((
context
)
->
{
this
.
context
.
register
(
BaseConfig
.
class
);
RequestMappingHandlerAdapter
handlerAdapter
=
context
.
getBean
(
RequestMappingHandlerAdapter
.
class
);
TestPropertyValues
.
of
(
"spring.hateoas.use-hal-as-default-json-media-type:false"
).
applyTo
(
this
.
context
);
for
(
HttpMessageConverter
<?>
converter
:
handlerAdapter
.
getMessageConverters
())
{
this
.
context
.
refresh
();
if
(
converter
instanceof
TypeConstrainedMappingJackson2HttpMessageConverter
)
{
RequestMappingHandlerAdapter
handlerAdapter
=
this
.
context
.
getBean
(
RequestMappingHandlerAdapter
.
class
);
assertThat
(
converter
.
getSupportedMediaTypes
()).
containsExactly
(
MediaTypes
.
HAL_JSON
);
for
(
HttpMessageConverter
<?>
converter
:
handlerAdapter
.
getMessageConverters
())
{
}
if
(
converter
instanceof
TypeConstrainedMappingJackson2HttpMessageConverter
)
{
}
assertThat
(
converter
.
getSupportedMediaTypes
()).
containsExactly
(
MediaTypes
.
HAL_JSON
);
});
}
}
}
}
@ImportAutoConfiguration
({
HttpMessageConvertersAutoConfiguration
.
class
,
WebMvcAutoConfiguration
.
class
,
@ImportAutoConfiguration
({
HttpMessageConvertersAutoConfiguration
.
class
,
WebMvcAutoConfiguration
.
class
,
...
...
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