Class TestMvcClient
- java.lang.Object
-
- org.activiti.cloud.services.test.rest.support.TestMvcClient
-
public class TestMvcClient extends Object
Helper methods for rest api web integration testing from spring-data-rest-tests-core module
-
-
Field Summary
Fields Modifier and Type Field Description static org.springframework.http.MediaTypeDEFAULT_MEDIA_TYPE
-
Constructor Summary
Constructors Constructor Description TestMvcClient(org.springframework.test.web.servlet.MockMvc mvc, org.springframework.hateoas.client.LinkDiscoverers discoverers)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidassertAllowHeaders(org.springframework.http.HttpEntity<?> response, org.springframework.http.HttpMethod... methods)org.springframework.hateoas.LinkassertHasLinkWithRel(String rel, org.springframework.mock.web.MockHttpServletResponse response)For a given servlet response, verify that the provided rel exists in its hypermedia.List<org.springframework.hateoas.Link>discover(String rel)Discover list of URIs associated with a rel, starting at the root node ("/")List<org.springframework.hateoas.Link>discover(org.springframework.hateoas.Link root, String rel)Given a URI (root), discover the URIs for a given rel.org.springframework.hateoas.LinkdiscoverUnique(String rel)Discover single URI associated with a rel, starting at the root node ("/")org.springframework.hateoas.LinkdiscoverUnique(String... rels)Traverses the given link relations from the root.org.springframework.hateoas.LinkdiscoverUnique(org.springframework.hateoas.Link root, String rel)Given a URI (root), discover the unique URI for a given rel.org.springframework.hateoas.LinkdiscoverUnique(org.springframework.hateoas.Link root, String rel, org.springframework.http.MediaType mediaType)Given a URI (root), discover the unique URI for a given rel.org.springframework.test.web.servlet.ResultActionsfollow(String href)Follow URL supplied as a string.org.springframework.test.web.servlet.ResultActionsfollow(String href, org.springframework.http.MediaType accept)Follow URL supplied as a string with a specific Accept header.org.springframework.test.web.servlet.ResultActionsfollow(org.springframework.hateoas.Link link)For a given link, expand the href using URI substitution and then do a simple GET.org.springframework.test.web.servlet.ResultActionsfollow(org.springframework.hateoas.Link link, org.springframework.http.MediaType accept)Folow Link with a specific Accept header (media type).org.springframework.hateoas.client.LinkDiscoverergetDiscoverer(org.springframework.mock.web.MockHttpServletResponse response)Using the servlet response's content type, find the corresponding link discoverer.org.springframework.test.web.servlet.ResultMatcherhasLinkWithRel(String rel)MockMvc matcher used to verify existence of rel with URI linkstatic voidinitWebTest()Initializes web tests.org.springframework.mock.web.MockHttpServletResponserequest(String href)Convenience wrapper to GET [href] using the default media type.org.springframework.mock.web.MockHttpServletResponserequest(String href, org.springframework.http.MediaType contentType)Perform GET [href] with an explicit Accept media type using MockMvc.org.springframework.mock.web.MockHttpServletResponserequest(String href, org.springframework.http.MediaType contentType, org.springframework.http.HttpHeaders httpHeaders)Perform GET [href] with an explicit Accept media type using MockMvc.org.springframework.mock.web.MockHttpServletResponserequest(org.springframework.hateoas.Link link)Convenience wrapper that first expands the link using URI substitution before requesting with the default media type.org.springframework.mock.web.MockHttpServletResponserequest(org.springframework.hateoas.Link link, org.springframework.http.MediaType mediaType)Convenience wrapper that first expands the link using URI substitution and then GET [href] using an explicit media typeTestMvcClientsetBasePath(String uri)Set base path uri.
-
-
-
Method Detail
-
setBasePath
public TestMvcClient setBasePath(String uri)
Set base path uri. Default value is "/"- Parameters:
uri- basePath- Returns:
- TestMvcClient instance
-
initWebTest
public static void initWebTest()
Initializes web tests. Will register aMockHttpServletRequestfor the current thread.
-
assertAllowHeaders
public static void assertAllowHeaders(org.springframework.http.HttpEntity<?> response, org.springframework.http.HttpMethod... methods)
-
request
public org.springframework.mock.web.MockHttpServletResponse request(String href, org.springframework.http.MediaType contentType) throws Exception
Perform GET [href] with an explicit Accept media type using MockMvc. Verify the requests succeeded and also came back as the Accept type.- Parameters:
href-contentType-- Returns:
- a mocked servlet response with results from GET [href]
- Throws:
Exception
-
request
public org.springframework.mock.web.MockHttpServletResponse request(String href, org.springframework.http.MediaType contentType, org.springframework.http.HttpHeaders httpHeaders) throws Exception
Perform GET [href] with an explicit Accept media type using MockMvc. Verify the requests succeeded and also came back as the Accept type.- Parameters:
href-contentType-- Returns:
- a mocked servlet response with results from GET [href]
- Throws:
Exception
-
request
public org.springframework.mock.web.MockHttpServletResponse request(org.springframework.hateoas.Link link) throws ExceptionConvenience wrapper that first expands the link using URI substitution before requesting with the default media type.- Parameters:
link-- Returns:
- Throws:
Exception
-
request
public org.springframework.mock.web.MockHttpServletResponse request(org.springframework.hateoas.Link link, org.springframework.http.MediaType mediaType) throws ExceptionConvenience wrapper that first expands the link using URI substitution and then GET [href] using an explicit media type- Parameters:
link-mediaType-- Returns:
- Throws:
Exception
-
request
public org.springframework.mock.web.MockHttpServletResponse request(String href) throws Exception
Convenience wrapper to GET [href] using the default media type.- Parameters:
href-- Returns:
- Throws:
Exception
-
follow
public org.springframework.test.web.servlet.ResultActions follow(org.springframework.hateoas.Link link) throws ExceptionFor a given link, expand the href using URI substitution and then do a simple GET.- Parameters:
link-- Returns:
- Throws:
Exception
-
follow
public org.springframework.test.web.servlet.ResultActions follow(String href) throws Exception
Follow URL supplied as a string. NOTE: Assumes no URI templates.- Parameters:
href-- Returns:
- Throws:
Exception
-
follow
public org.springframework.test.web.servlet.ResultActions follow(org.springframework.hateoas.Link link, org.springframework.http.MediaType accept) throws ExceptionFolow Link with a specific Accept header (media type).- Parameters:
link-accept-- Returns:
- Throws:
Exception
-
follow
public org.springframework.test.web.servlet.ResultActions follow(String href, org.springframework.http.MediaType accept) throws Exception
Follow URL supplied as a string with a specific Accept header.- Parameters:
href-accept-- Returns:
- Throws:
Exception
-
discover
public List<org.springframework.hateoas.Link> discover(String rel) throws Exception
Discover list of URIs associated with a rel, starting at the root node ("/")- Parameters:
rel-- Returns:
- Throws:
Exception
-
discoverUnique
public org.springframework.hateoas.Link discoverUnique(String rel) throws Exception
Discover single URI associated with a rel, starting at the root node ("/")- Parameters:
rel-- Returns:
- Throws:
Exception
-
discoverUnique
public org.springframework.hateoas.Link discoverUnique(String... rels) throws Exception
Traverses the given link relations from the root.- Parameters:
rels-- Returns:
- Throws:
Exception
-
discover
public List<org.springframework.hateoas.Link> discover(org.springframework.hateoas.Link root, String rel) throws Exception
Given a URI (root), discover the URIs for a given rel.- Parameters:
root- - URI to start fromrel- - name of the relationship to seek links- Returns:
- list of
Linkobjects associated with the rel - Throws:
Exception
-
discoverUnique
public org.springframework.hateoas.Link discoverUnique(org.springframework.hateoas.Link root, String rel) throws ExceptionGiven a URI (root), discover the unique URI for a given rel. NOTE: Assumes there is only one URI- Parameters:
root-rel-- Returns:
Linktied to a given rel- Throws:
Exception
-
discoverUnique
public org.springframework.hateoas.Link discoverUnique(org.springframework.hateoas.Link root, String rel, org.springframework.http.MediaType mediaType) throws ExceptionGiven a URI (root), discover the unique URI for a given rel. NOTE: Assumes there is only one URI- Parameters:
root- the link to the resource to access.rel- the link relation to discover in the response.mediaType- theMediaTypeto request.- Returns:
Linktied to a given rel- Throws:
Exception
-
assertHasLinkWithRel
public org.springframework.hateoas.Link assertHasLinkWithRel(String rel, org.springframework.mock.web.MockHttpServletResponse response) throws Exception
For a given servlet response, verify that the provided rel exists in its hypermedia. If so, return the URI link.- Parameters:
rel-response-- Returns:
Linkof the rel found in the response- Throws:
Exception
-
hasLinkWithRel
public org.springframework.test.web.servlet.ResultMatcher hasLinkWithRel(String rel)
MockMvc matcher used to verify existence of rel with URI link- Parameters:
rel-- Returns:
-
getDiscoverer
public org.springframework.hateoas.client.LinkDiscoverer getDiscoverer(org.springframework.mock.web.MockHttpServletResponse response)
Using the servlet response's content type, find the corresponding link discoverer.- Parameters:
response-- Returns:
LinkDiscoverer
-
-