org.springframework.restdocs.mockmvc.MockMvcRestDocumentation Java Examples
The following examples show how to use
org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkbasketControllerRestDocumentation.java From taskana with Apache License 2.0 | 7 votes |
@Test void getAllWorkbasketAccessItemsDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( restHelper.toUrl( Mapping.URL_WORKBASKET_ID_ACCESSITEMS, "WBI:100000000000000000000000000000000001")) .accept("application/hal+json") .header("Authorization", TEAMLEAD_1_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "GetAllWorkbasketAccessItemsDocTest", responseFields(allWorkbasketAccessItemsFieldDescriptors))); }
Example #2
Source File: RamlDocumentation.java From restdocs-raml with MIT License | 6 votes |
public static RestDocumentationResultHandler document(String identifier, String description, boolean privateResource, OperationRequestPreprocessor requestPreprocessor, OperationResponsePreprocessor responsePreprocessor, Function<List<Snippet>, List<Snippet>> snippetFilter, Snippet... snippets) { Snippet[] enhancedSnippets = enhanceSnippetsWithRaml(description, privateResource, snippetFilter, snippets); if (requestPreprocessor != null && responsePreprocessor != null) { return MockMvcRestDocumentation.document(identifier, requestPreprocessor, responsePreprocessor, enhancedSnippets); } else if (requestPreprocessor != null) { return MockMvcRestDocumentation.document(identifier, requestPreprocessor, enhancedSnippets); } else if (responsePreprocessor != null) { return MockMvcRestDocumentation.document(identifier, responsePreprocessor, enhancedSnippets); } return MockMvcRestDocumentation.document(identifier, enhancedSnippets); }
Example #3
Source File: SwaggerStaticDocTest.java From SwaggerOfflineDoc with Apache License 2.0 | 6 votes |
@Test public void TestApi() throws Exception { mockMvc.perform(get("/user/getUser").param("name", "FLY") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(MockMvcRestDocumentation.document("getUser", preprocessResponse(prettyPrint()))); User user = new User(); user.setId(123456); user.setName("FLY"); user.setAge(25); user.setAddress("河南郑州"); user.setSex("男"); mockMvc.perform(post("/user/addUser").contentType(MediaType.APPLICATION_JSON) .content(JSON.toJSONString(user)) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is2xxSuccessful()) .andDo(MockMvcRestDocumentation.document("addUser", preprocessResponse(prettyPrint()))); }
Example #4
Source File: TaskCommentControllerRestDocumentation.java From taskana with Apache License 2.0 | 6 votes |
@Test void getAllTaskCommentsForSpecificTaskDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( restHelper.toUrl( Mapping.URL_TASK_GET_POST_COMMENTS, "TKI:000000000000000000000000000000000000")) .accept(MediaTypes.HAL_JSON) .header("Authorization", ADMIN_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "GetAllTaskCommentsForSpecificTaskDocTest", responseFields(allTaskCommentsFieldDescriptors))); }
Example #5
Source File: WorkbasketControllerRestDocumentation.java From taskana with Apache License 2.0 | 6 votes |
@Test void createWorkbasketDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.post(restHelper.toUrl(Mapping.URL_WORKBASKET)) .contentType("application/json") .header("Authorization", TEAMLEAD_1_CREDENTIALS) .content( "{\"key\" : \"asdasdasd\", \"name\" : \"Gruppenpostkorb KSC\", " + "\"domain\" : \"DOMAIN_A\", \"type\" : \"GROUP\", " + "\"created\" : \"2018-02-01T11:00:00Z\",\r\n" + " \"modified\" : \"2018-02-01T11:00:00Z\"}")) .andExpect(MockMvcResultMatchers.status().isCreated()) .andDo( MockMvcRestDocumentation.document( "CreateWorkbasketDocTest", requestFields(createWorkbasketFieldDescriptors), responseFields(workbasketFieldDescriptors))) .andReturn(); }
Example #6
Source File: ProducerControllerTests.java From spring-cloud-contract-samples with Apache License 2.0 | 6 votes |
@Test public void should_grant_a_beer_when_person_is_old_enough() throws Exception { PersonToCheck personToCheck = new PersonToCheck(34); //remove::start[] this.mockMvc.perform(MockMvcRequestBuilders.post("/check") .contentType(MediaType.APPLICATION_JSON) .content(this.json.write(personToCheck).getJson())) .andExpect(jsonPath("$.status").value("OK")) .andDo(WireMockRestDocs.verify() .jsonPath("$[?(@.age >= 20)]") .contentType(MediaType.valueOf("application/json")) .stub("shouldGrantABeerIfOldEnough")) .andDo(MockMvcRestDocumentation.document("shouldGrantABeerIfOldEnough", SpringCloudContractRestDocs.dslContract())); //remove::end[] }
Example #7
Source File: ProducerControllerTests.java From spring-cloud-contract-samples with Apache License 2.0 | 6 votes |
@Test public void should_reject_a_beer_when_person_is_too_young() throws Exception { PersonToCheck personToCheck = new PersonToCheck(10); //remove::start[] this.mockMvc.perform(MockMvcRequestBuilders.post("/check") .contentType(MediaType.APPLICATION_JSON) .content(this.json.write(personToCheck).getJson())) .andExpect(jsonPath("$.status").value("NOT_OK")) .andDo(WireMockRestDocs.verify() .jsonPath("$[?(@.age < 20)]") .contentType(MediaType.valueOf("application/json")) .stub("shouldRejectABeerIfTooYoung")) .andDo(MockMvcRestDocumentation.document("shouldRejectABeerIfTooYoung", SpringCloudContractRestDocs.dslContract())); //remove::end[] }
Example #8
Source File: ClassificationControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void updateClassificationDocTest() throws Exception { URL url = new URL( restHelper.toUrl( Mapping.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009")); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Authorization", TEAMLEAD_1_CREDENTIALS); assertEquals(200, con.getResponseCode()); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), UTF_8)); String inputLine; StringBuilder content = new StringBuilder(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); con.disconnect(); String modifiedTask = content.toString(); this.mockMvc .perform( RestDocumentationRequestBuilders.put( restHelper.toUrl( Mapping.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009")) .header("Authorization", TEAMLEAD_1_CREDENTIALS) .contentType("application/json") .content(modifiedTask)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "UpdateClassificationDocTest", requestFields(classificationFieldDescriptors), responseFields(classificationFieldDescriptors))); }
Example #9
Source File: ControllerTestTemplate.java From coderadar with MIT License | 5 votes |
/** * Wraps the static document() method of RestDocs and configures it to pretty print request and * response JSON structures. */ protected RestDocumentationResultHandler document(String identifier, Snippet... snippets) { return MockMvcRestDocumentation.document( identifier, Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), snippets); }
Example #10
Source File: TaskanaEngineControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void getHistoryProviderIsEnabled() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get(restHelper.toUrl(Mapping.URL_HISTORY_ENABLED)) .accept("application/json") .header("Authorization", TEAMLEAD_1_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcRestDocumentation.document("GetHistoryProviderIsEnabled")); }
Example #11
Source File: ClassificationDefinitionControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void exportAllClassificationDefinitions() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( restHelper.toUrl(Mapping.URL_CLASSIFICATIONDEFINITIONS)) .accept("application/json") .header("Authorization", TEAMLEAD_1_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "ExportClassificationDefinitionsDocTest", responseFields(classificationDefinitionsFieldDescriptors))); }
Example #12
Source File: ControllerTestTemplate.java From coderadar with MIT License | 5 votes |
@BeforeEach public void setup(RestDocumentationContextProvider restDocumentation) { MockitoAnnotations.initMocks(this); mvc = MockMvcBuilders.webAppContextSetup(applicationContext) .apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation)) .build(); }
Example #13
Source File: TaskCommentControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void getSpecificTaskCommentDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( restHelper.toUrl( Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000")) .accept(MediaTypes.HAL_JSON) .header("Authorization", ADMIN_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "GetSpecificTaskCommentDocTest", responseFields(taskCommentFieldDescriptors))); }
Example #14
Source File: TaskCommentControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void updateTaskCommentDocTest() throws Exception { URL url = new URL( restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000")); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Authorization", ADMIN_CREDENTIALS); assertEquals(200, con.getResponseCode()); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), UTF_8)); String inputLine; StringBuilder content = new StringBuilder(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); con.disconnect(); String originalTaskComment = content.toString(); String modifiedTaskComment = originalTaskComment.replace("some text in textfield", "updated text in textfield"); this.mockMvc .perform( RestDocumentationRequestBuilders.put( restHelper.toUrl( Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000")) .header("Authorization", ADMIN_CREDENTIALS) .contentType(MediaTypes.HAL_JSON) .content(modifiedTaskComment)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "UpdateTaskCommentDocTest", requestFields(taskCommentFieldDescriptors), responseFields(taskCommentFieldDescriptors))); }
Example #15
Source File: TaskCommentControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void createAndDeleteTaskCommentDocTest() throws Exception { String createTaskCommentContent = "{ \"taskId\" : \"TKI:000000000000000000000000000000000000\",\n" + " \"textField\" : \"some text in textfield\"} "; MvcResult result = this.mockMvc .perform( RestDocumentationRequestBuilders.post( restHelper.toUrl( Mapping.URL_TASK_GET_POST_COMMENTS, "TKI:000000000000000000000000000000000000")) .contentType(MediaTypes.HAL_JSON) .content(createTaskCommentContent) .header("Authorization", ADMIN_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isCreated()) .andDo( MockMvcRestDocumentation.document( "CreateTaskCommentDocTest", requestFields(createTaskCommentFieldDescriptors), responseFields(taskCommentFieldDescriptors))) .andReturn(); String resultContent = result.getResponse().getContentAsString(); String newId = resultContent.substring(resultContent.indexOf("TCI:"), resultContent.indexOf("TCI:") + 40); this.mockMvc .perform( RestDocumentationRequestBuilders.delete( restHelper.toUrl(Mapping.URL_TASK_COMMENT, newId)) .header("Authorization", ADMIN_CREDENTIALS)) // admin .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(MockMvcRestDocumentation.document("DeleteTaskCommentDocTest")); }
Example #16
Source File: ClassificationControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void getAllClassificationsDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?domain=DOMAIN_B") .accept("application/hal+json") .header("Authorization", TEAMLEAD_1_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "GetAllClassificationsDocTest", responseFields(allClassificationsFieldDescriptors))); }
Example #17
Source File: ClassificationControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void getSpecificClassificationDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( restHelper.toUrl( Mapping.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009")) .header("Authorization", TEAMLEAD_1_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "GetSpecificClassificationDocTest", responseFields(classificationFieldDescriptors))); }
Example #18
Source File: ClassificationControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void classificationSubsetDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( restHelper.toUrl( Mapping.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009")) .header("Authorization", TEAMLEAD_1_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "ClassificationSubset", responseFields(classificationSubsetFieldDescriptors))); }
Example #19
Source File: GetGreetingDocTest.java From skeleton-ws-spring-boot with Apache License 2.0 | 5 votes |
/** * Generate API documentation for GET /api/greetings/{id}. * * @throws Exception Thrown if documentation generation failure occurs. */ @Test public void documentGetGreeting() throws Exception { // Generate API Documentation final MvcResult result = this.mockMvc .perform(RestDocumentationRequestBuilders .get("/api/greetings/{id}", "0").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcRestDocumentation.document("get-greeting", RequestDocumentation.pathParameters( RequestDocumentation.parameterWithName("id").description("The greeting identifier.")), PayloadDocumentation.relaxedResponseFields( PayloadDocumentation.fieldWithPath("id") .description( "The identifier. Used to reference specific greetings in API requests.") .type(JsonFieldType.NUMBER), PayloadDocumentation.fieldWithPath("referenceId") .description("The supplementary identifier.").type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("text").description("The text.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("version").description("The entity version.") .type(JsonFieldType.NUMBER), PayloadDocumentation.fieldWithPath("createdBy").description("The entity creator.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("createdAt").description("The creation timestamp.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("updatedBy").description("The last modifier.") .type(JsonFieldType.STRING).optional(), PayloadDocumentation.fieldWithPath("updatedAt") .description("The last modification timestamp.").type(JsonFieldType.STRING) .optional()))) .andReturn(); // Perform a simple, standard JUnit assertion to satisfy PMD rule Assert.assertEquals("failure - expected HTTP status 200", 200, result.getResponse().getStatus()); }
Example #20
Source File: TaskHistoryEventControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test public void getAllTaskHistoryEventDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( "http://127.0.0.1:" + port + "/api/v1/task-history-event?page=1&page-size=3") .accept("application/hal+json") .header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x")) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "GetAllTaskHistoryEventDocTest", responseFields(allTaskHistoryEventFieldDescriptors))); }
Example #21
Source File: DeleteGreetingDocTest.java From skeleton-ws-spring-boot with Apache License 2.0 | 5 votes |
/** * Generate API documentation for DELETE /api/greetings/{id}. * * @throws Exception Thrown if documentation generation failure occurs. */ @Test public void documentDeleteGreeting() throws Exception { // Generate API Documentation final MvcResult result = this.mockMvc.perform(RestDocumentationRequestBuilders.delete("/api/greetings/{id}", 1)) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(MockMvcRestDocumentation.document("delete-greeting")).andReturn(); // Perform a simple, standard JUnit assertion to satisfy PMD rule Assert.assertEquals("failure - expected HTTP status 204", 204, result.getResponse().getStatus()); }
Example #22
Source File: TaskHistoryEventControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test public void getSpecificTaskHistoryEventDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get( "http://127.0.0.1:" + port + "/api/v1/task-history-event/1") .accept("application/hal+json") .header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x")) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "GetSpecificTaskHistoryEventDocTest", responseFields(taskHistoryEventFieldDescriptors))); }
Example #23
Source File: TaskanaEngineControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void getCurrentUserInfo() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.get(restHelper.toUrl(Mapping.URL_CURRENT_USER)) .accept("application/json") .header("Authorization", TEAMLEAD_1_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo( MockMvcRestDocumentation.document( "GetCurrentUserInfoDocTest", responseFields(currentUserInfoFieldDescriptors))); }
Example #24
Source File: XmlStubGeneratorTests.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Test public void should_return_full_content() throws Exception { mockMvc.perform(post("/xmlfraud").contentType(MediaType.APPLICATION_XML) .content("<XmlRequestBody><name>foo</name></XmlRequestBody>")) .andExpect(status().is2xxSuccessful()) .andExpect(content().string( "<XmlResponseBody><status>FULL</status></XmlResponseBody>")) .andDo(MockMvcRestDocumentation.document("{methodName}")); }
Example #25
Source File: GetGreetingsDocTest.java From skeleton-ws-spring-boot with Apache License 2.0 | 5 votes |
/** * Generate API documentation for GET /api/greetings. * * @throws Exception Thrown if documentation generation failure occurs. */ @Test public void documentGetGreetings() throws Exception { // Generate API Documentation final MvcResult result = this.mockMvc .perform(RestDocumentationRequestBuilders.get("/api/greetings").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcRestDocumentation.document("get-greetings", PayloadDocumentation.relaxedResponseFields( PayloadDocumentation.fieldWithPath("[].id").description( "The identifier. Used to reference specific greetings in API requests."), PayloadDocumentation.fieldWithPath("[].referenceId") .description("The supplementary identifier."), PayloadDocumentation.fieldWithPath("[].text").description("The text."), PayloadDocumentation.fieldWithPath("[].version").description("The entity version."), PayloadDocumentation.fieldWithPath("[].createdBy").description("The entity creator."), PayloadDocumentation.fieldWithPath("[].createdAt") .description("The creation timestamp."), PayloadDocumentation.fieldWithPath("[].updatedBy").description("The last modifier."), PayloadDocumentation.fieldWithPath("[].updatedAt") .description("The last modification timestamp.")))) .andReturn(); // Perform a simple, standard JUnit assertion to satisfy PMD rule Assert.assertEquals("failure - expected HTTP status 200", 200, result.getResponse().getStatus()); }
Example #26
Source File: XmlStubGeneratorTests.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Test public void should_return_empty_content() throws Exception { mockMvc.perform(post("/xmlfraud").contentType(MediaType.APPLICATION_XML) .content("<XmlRequestBody><name></name></XmlRequestBody>")) .andExpect(status().is2xxSuccessful()) .andExpect(content().string( "<XmlResponseBody><status>EMPTY</status></XmlResponseBody>")) .andDo(MockMvcRestDocumentation.document("{methodName}")); }
Example #27
Source File: UpdateGreetingDocTest.java From skeleton-ws-spring-boot with Apache License 2.0 | 5 votes |
/** * Generate API documentation for PUT /api/greetings/{id}. * * @throws Exception Thrown if documentation generation failure occurs. */ @Test public void documentUpdateGreeting() throws Exception { // Generate API Documentation final MvcResult result = this.mockMvc.perform(RestDocumentationRequestBuilders.put("/api/greetings/{id}", 1) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).content(REQUEST_BODY)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcRestDocumentation.document("update-greeting", RequestDocumentation.pathParameters( RequestDocumentation.parameterWithName("id").description("The greeting identifier.")), PayloadDocumentation.relaxedRequestFields(PayloadDocumentation.fieldWithPath("text") .description("The text.").type(JsonFieldType.STRING)), PayloadDocumentation.relaxedResponseFields( PayloadDocumentation .fieldWithPath("id") .description( "The identifier. Used to reference specific greetings in API requests.") .type(JsonFieldType.NUMBER), PayloadDocumentation.fieldWithPath("referenceId") .description("The supplementary identifier.").type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("text").description("The text.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("version").description("The entity version.") .type(JsonFieldType.NUMBER), PayloadDocumentation.fieldWithPath("createdBy").description("The entity creator.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("createdAt").description("The creation timestamp.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("updatedBy").description("The last modifier.") .type(JsonFieldType.STRING).optional(), PayloadDocumentation.fieldWithPath("updatedAt") .description("The last modification timestamp.").type(JsonFieldType.STRING) .optional()))) .andReturn(); // Perform a simple, standard JUnit assertion to satisfy PMD rule Assert.assertEquals("failure - expected HTTP status 200", 200, result.getResponse().getStatus()); }
Example #28
Source File: CreateGreetingDocTest.java From skeleton-ws-spring-boot with Apache License 2.0 | 5 votes |
/** * Generate API documentation for POST /api/greetings. * * @throws Exception Thrown if documentation generation failure occurs. */ @Test public void documentCreateGreeting() throws Exception { // Generate API Documentation final MvcResult result = this.mockMvc .perform(RestDocumentationRequestBuilders.post("/api/greetings").contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON).content(REQUEST_BODY)) .andExpect(MockMvcResultMatchers.status().isCreated()) .andDo(MockMvcRestDocumentation.document("create-greeting", PayloadDocumentation.relaxedRequestFields(PayloadDocumentation.fieldWithPath("text") .description("The text.").type(JsonFieldType.STRING)), PayloadDocumentation.relaxedResponseFields( PayloadDocumentation .fieldWithPath("id") .description( "The identifier. Used to reference specific greetings in API requests.") .type(JsonFieldType.NUMBER), PayloadDocumentation.fieldWithPath("referenceId") .description("The supplementary identifier.").type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("text").description("The text.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("version").description("The entity version.") .type(JsonFieldType.NUMBER), PayloadDocumentation.fieldWithPath("createdBy").description("The entity creator.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("createdAt").description("The creation timestamp.") .type(JsonFieldType.STRING), PayloadDocumentation.fieldWithPath("updatedBy").description("The last modifier.") .type(JsonFieldType.STRING).optional(), PayloadDocumentation.fieldWithPath("updatedAt") .description("The last modification timestamp.").type(JsonFieldType.STRING) .optional()))) .andReturn(); // Perform a simple, standard JUnit assertion to satisfy PMD rule Assert.assertEquals("failure - expected HTTP status 201", 201, result.getResponse().getStatus()); }
Example #29
Source File: AbstractApiRestDocumentation.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
@Before protected void setUp() { this.document = document(resourceName + "/{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())); this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) .apply(MockMvcRestDocumentation.documentationConfiguration(this.restDocumentation).uris() .withScheme("https").withHost(host + ".com").withPort(443)) .alwaysDo(this.document).addFilter(filterHttpResponse).build(); arrayPrefix = "[]"; }
Example #30
Source File: WorkbasketControllerRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@Test void removeWorkbasketAsDistributionTargetDocTest() throws Exception { this.mockMvc .perform( RestDocumentationRequestBuilders.delete( restHelper.toUrl( Mapping.URL_WORKBASKET_ID_DISTRIBUTION, "WBI:100000000000000000000000000000000007")) .header("Authorization", TEAMLEAD_1_CREDENTIALS)) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(MockMvcRestDocumentation.document("RemoveWorkbasketAsDistributionTargetDocTest")); }