-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tht chat server 18 openapi3 환경 구축 (#19)
* log : add disconnect case log * feat : openapi3
- Loading branch information
Showing
7 changed files
with
285 additions
and
3 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
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 |
---|---|---|
@@ -1,3 +1,17 @@ | ||
spring: | ||
config: | ||
import: security/Server-Security/application-security.yaml | ||
import: security/Server-Security/application-security.yaml | ||
|
||
thymeleaf: | ||
prefix: classpath:static/ | ||
suffix: .html | ||
cache: false | ||
|
||
springdoc: | ||
swagger-ui: | ||
url: /docs/open-api-3.0.1.json | ||
path: /docs/swagger | ||
groups-order: DESC # path, query, body, response 순으로 출력 | ||
tags-sorter: alpha # 태그를 알파벳 순으로 정렬 | ||
default-consumes-media-type: application/json;charset=UTF-8 | ||
default-produces-media-type: application/json;charset=UTF-8 |
55 changes: 55 additions & 0 deletions
55
src/test/java/com/example/chatserver/config/ControllerTestConfig.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,55 @@ | ||
package com.example.chatserver.config; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplicationExtensionsKt; | ||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext; | ||
import org.springframework.restdocs.RestDocumentationContextProvider; | ||
import org.springframework.restdocs.RestDocumentationExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
import org.springframework.web.filter.CharacterEncodingFilter; | ||
import org.springframework.web.socket.messaging.WebSocketStompClient; | ||
|
||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
@AutoConfigureMockMvc | ||
@AutoConfigureRestDocs | ||
@MockBean(JpaMetamodelMappingContext.class) | ||
@Import({WebSocketConfig.class, StompHandler.class, JwtUtils.class, StompExceptionHandler.class}) | ||
@ExtendWith({RestDocumentationExtension.class}) | ||
public abstract class ControllerTestConfig { | ||
|
||
@Autowired | ||
protected WebApplicationContext ctx; | ||
|
||
@Autowired | ||
protected ObjectMapper mapper; | ||
|
||
protected static ObjectMapper objectMapper; | ||
|
||
|
||
protected static MockMvc mockMvc; | ||
|
||
|
||
@BeforeEach | ||
void setUp(final RestDocumentationContextProvider restDocumentation) { | ||
|
||
objectMapper = mapper; | ||
|
||
mockMvc = MockMvcBuilders.webAppContextSetup(ctx) | ||
.apply(documentationConfiguration(restDocumentation)) | ||
.addFilters(new CharacterEncodingFilter("UTF-8", true)) | ||
.alwaysDo(print()) | ||
.build(); | ||
} | ||
|
||
} |
117 changes: 117 additions & 0 deletions
117
src/test/java/com/example/chatserver/documentation/ChatControllerDocumentation.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,117 @@ | ||
package com.example.chatserver.documentation; | ||
|
||
import com.epages.restdocs.apispec.ResourceSnippetParameters; | ||
import com.epages.restdocs.apispec.Schema; | ||
import com.example.chatserver.config.ControllerTestConfig; | ||
import com.example.chatserver.controller.ChatController; | ||
import com.example.chatserver.facade.ChatFacade; | ||
import com.example.chatserver.fixture.ChatRequestFixture; | ||
import com.google.api.client.json.Json; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; | ||
import org.springframework.restdocs.payload.JsonFieldType; | ||
|
||
import static com.epages.restdocs.apispec.ResourceDocumentation.parameterWithName; | ||
import static com.epages.restdocs.apispec.ResourceDocumentation.resource; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest(ChatController.class) | ||
class ChatControllerDocumentation extends ControllerTestConfig { | ||
|
||
@MockBean | ||
ChatFacade chatFacade; | ||
|
||
@Test | ||
void documentStompEndpoint() throws Exception { | ||
|
||
mockMvc.perform( | ||
get("/websocket-endpoint") | ||
.header("Authorization", testToken()) | ||
|
||
) | ||
.andDo(document("stomp connect endpoint", | ||
preprocessRequest(prettyPrint()), | ||
preprocessResponse(prettyPrint()), | ||
resource( | ||
ResourceSnippetParameters.builder() | ||
.tag("소켓 연결 정보") | ||
.description("stomp connect endpoint url 주소") | ||
.build() | ||
) | ||
)); | ||
|
||
} | ||
|
||
private static String testToken() { | ||
return "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhdXRob3JpemF0aW9uIiwidXNlclV1aWQiOiI0NmQ5NjBmNTY1LTJhZTItNDE5My05NmZkLTMxYjZhODc1NzYxMSIsInJvbGUiOiJOT1JNQUwiLCJleHAiOjQ4NjQwMDQxODZ9.VGC6EJmCBdevtfSQspqsdu42FFl25dSBSHvHue6mAhE"; | ||
} | ||
|
||
// @Test | ||
// void documentStompPub() throws Exception { | ||
// | ||
// String requestBody = objectMapper.writeValueAsString(ChatRequestFixture.make()); | ||
// | ||
// mockMvc.perform(post("/pub/chat/{chat-room-no}",1) | ||
// .content(requestBody) | ||
// .header("Authorization", testToken())) | ||
// .andDo(document("stomp publish(전송 - send) url", | ||
// preprocessRequest(prettyPrint()), | ||
// preprocessResponse(prettyPrint()), | ||
// resource( | ||
// ResourceSnippetParameters.builder() | ||
// .tag("소켓 연결 정보") | ||
// .description("stomp publish (send) url 주소") | ||
// .pathParameters( | ||
// parameterWithName("chat-room-no").description("채팅방 idx") | ||
// ) | ||
// .requestFields( | ||
// fieldWithPath("sender").type(JsonFieldType.STRING).description(""), | ||
// fieldWithPath("senderUuid").type(JsonFieldType.STRING).description("보내는 사람 user uuid"), | ||
// fieldWithPath("imgUrl").type(JsonFieldType.STRING).description("보내는 사람 프로필 img url"), | ||
// fieldWithPath("msg").type(JsonFieldType.STRING).description("전송 메세지 내용") | ||
// ) | ||
// .requestFields() | ||
// .responseFields() | ||
// .requestSchema(Schema.schema("ChatRequest")) | ||
// .build() | ||
// ) | ||
// )); | ||
// } | ||
// | ||
// @Test | ||
// void documentStompSub() throws Exception { | ||
// | ||
// mockMvc.perform(post("/sub/chat/{chat-room-no}",1) | ||
// .content("stomp 구독(subscribe) url") | ||
// .header("Authorization", testToken())) | ||
// .andDo(document("stomp subscribe(구독) url", | ||
// preprocessRequest(prettyPrint()), | ||
// preprocessResponse(prettyPrint()), | ||
// resource( | ||
// ResourceSnippetParameters.builder() | ||
// .tag("소켓 연결 정보") | ||
// .description("stomp subscribe url 주소") | ||
// .pathParameters( | ||
// parameterWithName("chat-room-no").description("채팅방 idx") | ||
// ) | ||
// .requestFields() | ||
// .responseFields( | ||
// fieldWithPath("chatIdx").type(JsonFieldType.STRING).description(""), | ||
// fieldWithPath("sender").type(JsonFieldType.STRING).description(""), | ||
// fieldWithPath("senderUuid").type(JsonFieldType.STRING).description("보내는 사람 user uuid"), | ||
// fieldWithPath("msg").type(JsonFieldType.STRING).description("보내는 사람 프로필 img url"), | ||
// fieldWithPath("imgUrl").type(JsonFieldType.STRING).description("전송 메세지 내용"), | ||
// fieldWithPath("dateTime").type(JsonFieldType.STRING).description("전송 메세지 내용") | ||
// ) | ||
// .build() | ||
// ) | ||
// )); | ||
// } | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/java/com/example/chatserver/fixture/ChatRequestFixture.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,14 @@ | ||
package com.example.chatserver.fixture; | ||
|
||
import com.example.chatserver.stomp.ChatRequest; | ||
|
||
public class ChatRequestFixture{ | ||
private static final String sender = "보내는 사람 이름"; | ||
private static final String senderUuid = "보내는 사람 user uuid"; | ||
private static final String imgUrl = "보내는 사람 프로필 img url"; | ||
private static final String msg = "전송 메세지 내용"; | ||
|
||
public static ChatRequest make() { | ||
return new ChatRequest(sender, senderUuid, imgUrl, msg); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/java/com/example/chatserver/fixture/ChatResponseFixture.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,19 @@ | ||
package com.example.chatserver.fixture; | ||
|
||
import com.example.chatserver.stomp.ChatResponse; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class ChatResponseFixture { | ||
|
||
private static final String chatIdx = "채팅 메세지 고유 id"; | ||
private static final String sender = "메세지를 보낸 사람 이름"; | ||
private static final String senderUuid = "메세지를 보낸 사람 user uuid"; | ||
private static final String msg = "받은 메세지 내용"; | ||
private static final String imgUrl = "받은 이미지 url"; | ||
private static final LocalDateTime dateTime = LocalDateTime.now(); | ||
|
||
public static ChatResponse make() { | ||
return new ChatResponse(chatIdx, sender, senderUuid, msg, imgUrl, dateTime); | ||
} | ||
} |