Java – pathparameters document exception (urltemplate not found)
•
Java
When using pathparameters to record URI path parameters, it is as follows
@Test public void documentGetRouteById() throws Exception { this.mockmvc.perform(get("/route/{id}","FooBar")).andExpect(status().isOk()) .andDo(document("api-getRouteById",pathParameters(parameterWithName("id").description("die Routen ID")))); }
I get the following interests
java.lang.IllegalArgumentException: urlTemplate not found. Did you use RestDocumentationRequestBuilders to build the request? at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.restdocs.request.PathParameteRSSnippet.extractUrlTemplate(PathParameteRSSnippet.java:95) at org.springframework.restdocs.request.PathParameteRSSnippet.extractActualParameters(PathParameteRSSnippet.java:82) at org.springframework.restdocs.request.AbstractParameteRSSnippet.verifyParameterDescriptors(AbstractParameteRSSnippet.java:77) at org.springframework.restdocs.request.AbstractParameteRSSnippet.createModel(AbstractParameteRSSnippet.java:65) at org.springframework.restdocs.request.PathParameteRSSnippet.createModel(PathParameteRSSnippet.java:67) at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:64) at org.springframework.restdocs.mockmvc.RestDocumentationResultHandler.handle(RestDocumentationResultHandler.java:101) at org.springframework.test.web.servlet.mockmvc$1.andDo(mockmvc.java:158)
I'm pretty sure I made the test settings, such as explaining here
What could I have done wrong?
(the spring rest document version is 1.0.0.build-snapshot)
Solution
The exception message is trying to point in the right direction:
You need to use restdocumentationrequestbuilders so that spring rest documents can capture URLs and extract parameters from them This is mentioned in the document, which says:
Statically import mockmvcrequebuilders Get is replaced by one for restdocumentationrequestbuilders Get should solve the problem
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码