Class TestMvcClient
java.lang.Object
org.activiti.cloud.services.test.rest.support.TestMvcClient
Helper methods for rest api web integration testing from spring-data-rest-tests-core module
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTestMvcClient(org.springframework.test.web.servlet.MockMvc mvc, org.springframework.hateoas.client.LinkDiscoverers discoverers) -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 list of URIs associated with a rel, starting at the root node ("/")List<org.springframework.hateoas.Link> 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 URL supplied as a string.org.springframework.test.web.servlet.ResultActionsFollow 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 voidInitializes web tests.org.springframework.mock.web.MockHttpServletResponseConvenience wrapper to GET [href] using the default media type.org.springframework.mock.web.MockHttpServletResponsePerform 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 typesetBasePath(String uri) Set base path uri.
-
Field Details
-
DEFAULT_MEDIA_TYPE
public static org.springframework.http.MediaType DEFAULT_MEDIA_TYPE
-
-
Constructor Details
-
TestMvcClient
public TestMvcClient(org.springframework.test.web.servlet.MockMvc mvc, org.springframework.hateoas.client.LinkDiscoverers discoverers) - Parameters:
mvc- must not be null.discoverers- must not be null.
-
-
Method Details
-
setBasePath
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 Exception Convenience 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 Exception Convenience 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
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 Exception For a given link, expand the href using URI substitution and then do a simple GET.- Parameters:
link-- Returns:
- Throws:
Exception
-
follow
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 Exception Folow 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
Discover list of URIs associated with a rel, starting at the root node ("/")- Parameters:
rel-- Returns:
- Throws:
Exception
-
discoverUnique
Discover single URI associated with a rel, starting at the root node ("/")- Parameters:
rel-- Returns:
- Throws:
Exception
-
discoverUnique
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 Exception Given 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 Exception Given 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
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
-