Class TestMvcClient
- java.lang.Object
-
- org.activiti.cloud.services.test.rest.support.TestMvcClient
-
public class TestMvcClient extends java.lang.ObjectHelper 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.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(java.lang.String rel, org.springframework.mock.web.MockHttpServletResponse response)For a given servlet response, verify that the provided rel exists in its hypermedia.java.util.List<org.springframework.hateoas.Link>discover(java.lang.String rel)Discover list of URIs associated with a rel, starting at the root node ("/")java.util.List<org.springframework.hateoas.Link>discover(org.springframework.hateoas.Link root, java.lang.String rel)Given a URI (root), discover the URIs for a given rel.org.springframework.hateoas.LinkdiscoverUnique(java.lang.String rel)Discover single URI associated with a rel, starting at the root node ("/")org.springframework.hateoas.LinkdiscoverUnique(java.lang.String... rels)Traverses the given link relations from the root.org.springframework.hateoas.LinkdiscoverUnique(org.springframework.hateoas.Link root, java.lang.String rel)Given a URI (root), discover the unique URI for a given rel.org.springframework.hateoas.LinkdiscoverUnique(org.springframework.hateoas.Link root, java.lang.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(java.lang.String href)Follow URL supplied as a string.org.springframework.test.web.servlet.ResultActionsfollow(java.lang.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.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(java.lang.String rel)MockMvc matcher used to verify existence of rel with URI linkstatic voidinitWebTest()Initializes web tests.org.springframework.mock.web.MockHttpServletResponserequest(java.lang.String href)Convenience wrapper to GET [href] using the default media type.org.springframework.mock.web.MockHttpServletResponserequest(java.lang.String href, org.springframework.http.MediaType contentType)Perform GET [href] with an explicit Accept media type using MockMvc.org.springframework.mock.web.MockHttpServletResponserequest(java.lang.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(java.lang.String uri)Set base path uri.
-
-
-
Method Detail
-
setBasePath
public TestMvcClient setBasePath(java.lang.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(java.lang.String href, org.springframework.http.MediaType contentType) throws java.lang.ExceptionPerform 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:
java.lang.Exception
-
request
public org.springframework.mock.web.MockHttpServletResponse request(java.lang.String href, org.springframework.http.MediaType contentType, org.springframework.http.HttpHeaders httpHeaders) throws java.lang.ExceptionPerform 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:
java.lang.Exception
-
request
public org.springframework.mock.web.MockHttpServletResponse request(org.springframework.hateoas.Link link) throws java.lang.ExceptionConvenience wrapper that first expands the link using URI substitution before requesting with the default media type.- Parameters:
link-- Returns:
- Throws:
java.lang.Exception
-
request
public org.springframework.mock.web.MockHttpServletResponse request(org.springframework.hateoas.Link link, org.springframework.http.MediaType mediaType) throws java.lang.ExceptionConvenience wrapper that first expands the link using URI substitution and then GET [href] using an explicit media type- Parameters:
link-mediaType-- Returns:
- Throws:
java.lang.Exception
-
request
public org.springframework.mock.web.MockHttpServletResponse request(java.lang.String href) throws java.lang.ExceptionConvenience wrapper to GET [href] using the default media type.- Parameters:
href-- Returns:
- Throws:
java.lang.Exception
-
follow
public org.springframework.test.web.servlet.ResultActions follow(org.springframework.hateoas.Link link) throws java.lang.ExceptionFor a given link, expand the href using URI substitution and then do a simple GET.- Parameters:
link-- Returns:
- Throws:
java.lang.Exception
-
follow
public org.springframework.test.web.servlet.ResultActions follow(java.lang.String href) throws java.lang.ExceptionFollow URL supplied as a string. NOTE: Assumes no URI templates.- Parameters:
href-- Returns:
- Throws:
java.lang.Exception
-
follow
public org.springframework.test.web.servlet.ResultActions follow(org.springframework.hateoas.Link link, org.springframework.http.MediaType accept) throws java.lang.ExceptionFolow Link with a specific Accept header (media type).- Parameters:
link-accept-- Returns:
- Throws:
java.lang.Exception
-
follow
public org.springframework.test.web.servlet.ResultActions follow(java.lang.String href, org.springframework.http.MediaType accept) throws java.lang.ExceptionFollow URL supplied as a string with a specific Accept header.- Parameters:
href-accept-- Returns:
- Throws:
java.lang.Exception
-
discover
public java.util.List<org.springframework.hateoas.Link> discover(java.lang.String rel) throws java.lang.ExceptionDiscover list of URIs associated with a rel, starting at the root node ("/")- Parameters:
rel-- Returns:
- Throws:
java.lang.Exception
-
discoverUnique
public org.springframework.hateoas.Link discoverUnique(java.lang.String rel) throws java.lang.ExceptionDiscover single URI associated with a rel, starting at the root node ("/")- Parameters:
rel-- Returns:
- Throws:
java.lang.Exception
-
discoverUnique
public org.springframework.hateoas.Link discoverUnique(java.lang.String... rels) throws java.lang.ExceptionTraverses the given link relations from the root.- Parameters:
rels-- Returns:
- Throws:
java.lang.Exception
-
discover
public java.util.List<org.springframework.hateoas.Link> discover(org.springframework.hateoas.Link root, java.lang.String rel) throws java.lang.ExceptionGiven 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:
java.lang.Exception
-
discoverUnique
public org.springframework.hateoas.Link discoverUnique(org.springframework.hateoas.Link root, java.lang.String rel) throws java.lang.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:
java.lang.Exception
-
discoverUnique
public org.springframework.hateoas.Link discoverUnique(org.springframework.hateoas.Link root, java.lang.String rel, org.springframework.http.MediaType mediaType) throws java.lang.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:
java.lang.Exception
-
assertHasLinkWithRel
public org.springframework.hateoas.Link assertHasLinkWithRel(java.lang.String rel, org.springframework.mock.web.MockHttpServletResponse response) throws java.lang.ExceptionFor 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:
java.lang.Exception
-
hasLinkWithRel
public org.springframework.test.web.servlet.ResultMatcher hasLinkWithRel(java.lang.String rel)
MockMvc matcher used to verify existence of rel with URI link- Parameters:
rel-- Returns:
-
getDiscoverer
public org.springframework.hateoas.LinkDiscoverer getDiscoverer(org.springframework.mock.web.MockHttpServletResponse response)
Using the servlet response's content type, find the corresponding link discoverer.- Parameters:
response-- Returns:
LinkDiscoverer
-
-