-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Chore: Spring REST Docs 환경 세팅
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
= Snappy REST Docs 문서 | ||
|
||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlightjs | ||
:toc: left | ||
:toclevels: 2 |
34 changes: 34 additions & 0 deletions
34
src/test/java/com/dnd/dndphoto/config/ApiDocumentUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.dnd.dndphoto.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.restdocs.RestDocumentationContextProvider; | ||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
import org.springframework.web.filter.CharacterEncodingFilter; | ||
|
||
@Component | ||
public class ApiDocumentUtils { | ||
|
||
@Autowired | ||
private RestDocumentationResultHandler restDocs; | ||
|
||
// TODO: 컨트롤러 단위 or 통합 테스트 | ||
public MockMvc mockMvcSetup(final WebApplicationContext context, | ||
final RestDocumentationContextProvider provider) { | ||
return MockMvcBuilders.webAppContextSetup(context) | ||
.apply(MockMvcRestDocumentation.documentationConfiguration(provider)) | ||
.alwaysDo(MockMvcResultHandlers.print()) | ||
.alwaysDo(restDocs) | ||
.addFilters(new CharacterEncodingFilter("UTF-8", true)) | ||
.build(); | ||
} | ||
|
||
public RestDocumentationResultHandler restDocs() { | ||
return restDocs; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/com/dnd/dndphoto/config/RestDocsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.dnd.dndphoto.config; | ||
|
||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; | ||
import org.springframework.restdocs.operation.preprocess.Preprocessors; | ||
import static org.springframework.restdocs.snippet.Attributes.Attribute; | ||
|
||
@TestConfiguration | ||
public class RestDocsConfiguration { | ||
|
||
@Bean | ||
public RestDocumentationResultHandler write() { | ||
return MockMvcRestDocumentation.document( | ||
"{class-name}/{method-name}", | ||
Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), | ||
Preprocessors.preprocessResponse(Preprocessors.prettyPrint()) | ||
); | ||
} | ||
|
||
public static Attribute field(final String key, final String value) { | ||
return new Attribute(key, value); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/resources/org.springframework.restdocs.templates/request-fields.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
==== Request Fields | ||
|=== | ||
|Path|Type|Optional|Description | ||
|
||
{{#fields}} | ||
|
||
|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}{{#optional}}O{{/optional}}{{/tableCellContent}} | ||
|{{#tableCellContent}}{{description}}{{/tableCellContent}} | ||
|
||
{{/fields}} | ||
|
||
|=== |
14 changes: 14 additions & 0 deletions
14
src/test/resources/org.springframework.restdocs.templates/response-fields.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
==== Request Fields | ||
|=== | ||
|Path|Type|Optional|Description | ||
|
||
{{#fields}} | ||
|
||
|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}} | ||
|{{#tableCellContent}}{{#optional}}O{{/optional}}{{/tableCellContent}} | ||
|{{#tableCellContent}}{{description}}{{/tableCellContent}} | ||
|
||
{{/fields}} | ||
|
||
|=== |