Skip to content

Commit 6d12d86

Browse files
committed
Test: WebRTC 시그널링 서버 테스트
1 parent 34aac99 commit 6d12d86

File tree

6 files changed

+877
-3
lines changed

6 files changed

+877
-3
lines changed

src/main/java/com/back/global/websocket/controller/WebSocketApiController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import java.util.Map;
1515

1616
@RestController
17-
@RequestMapping("api/ws")
1817
@RequiredArgsConstructor
18+
@RequestMapping("api/ws")
1919
@Tag(name = "WebSocket REST API", description = "WebSocket 서버 상태 확인 + 실시간 연결 정보 제공 API")
2020
public class WebSocketApiController {
2121

src/main/java/com/back/global/websocket/webrtc/controller/WebRTCApiController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
@Slf4j
1717
@RestController
18-
@RequestMapping("/api/webrtc")
1918
@RequiredArgsConstructor
19+
@RequestMapping("/api/webrtc")
2020
@Tag(name = "WebRTC API", description = "WebRTC 시그널링 및 ICE 서버 관련 REST API")
2121
public class WebRTCApiController {
2222

src/main/java/com/back/global/websocket/webrtc/controller/WebRTCSignalingController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import java.security.Principal;
2020

21+
@Slf4j
2122
@Controller
2223
@RequiredArgsConstructor
23-
@Slf4j
2424
public class WebRTCSignalingController {
2525

2626
private final SimpMessagingTemplate messagingTemplate;
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
package com.back.global.websocket.webrtc.controller;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import org.junit.jupiter.api.DisplayName;
5+
import org.junit.jupiter.api.Nested;
6+
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.http.MediaType;
11+
import org.springframework.security.test.context.support.WithMockUser;
12+
import org.springframework.test.web.servlet.MockMvc;
13+
import org.springframework.test.web.servlet.MvcResult;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
17+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
18+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
19+
20+
@SpringBootTest
21+
@AutoConfigureMockMvc
22+
@WithMockUser
23+
@DisplayName("WebRTC API 컨트롤러")
24+
class WebRTCApiControllerTest {
25+
26+
@Autowired
27+
private MockMvc mockMvc;
28+
29+
@Autowired
30+
private ObjectMapper objectMapper;
31+
32+
@Nested
33+
@DisplayName("ICE 서버 조회")
34+
class GetIceServersTest {
35+
36+
@Test
37+
@DisplayName("기본 조회")
38+
void t1() throws Exception {
39+
// when & then
40+
MvcResult result = mockMvc.perform(get("/api/webrtc/ice-servers")
41+
.contentType(MediaType.APPLICATION_JSON))
42+
.andDo(print())
43+
.andExpect(status().isOk())
44+
.andExpect(jsonPath("$.code").value("SUCCESS_200"))
45+
.andExpect(jsonPath("$.message").value("ICE 서버 설정 조회 성공"))
46+
.andExpect(jsonPath("$.success").value(true))
47+
.andExpect(jsonPath("$.data").exists())
48+
.andExpect(jsonPath("$.data.iceServers").isArray())
49+
.andExpect(jsonPath("$.data.iceServers").isNotEmpty())
50+
.andReturn();
51+
52+
// 응답 본문 검증
53+
String content = result.getResponse().getContentAsString();
54+
assertThat(content).contains("stun:");
55+
}
56+
57+
@Test
58+
@DisplayName("userId, roomId 파라미터")
59+
void t2() throws Exception {
60+
// given
61+
Long userId = 1L;
62+
Long roomId = 100L;
63+
64+
// when & then
65+
mockMvc.perform(get("/api/webrtc/ice-servers")
66+
.param("userId", userId.toString())
67+
.param("roomId", roomId.toString())
68+
.contentType(MediaType.APPLICATION_JSON))
69+
.andDo(print())
70+
.andExpect(status().isOk())
71+
.andExpect(jsonPath("$.code").value("SUCCESS_200"))
72+
.andExpect(jsonPath("$.message").value("ICE 서버 설정 조회 성공"))
73+
.andExpect(jsonPath("$.success").value(true))
74+
.andExpect(jsonPath("$.data").exists())
75+
.andExpect(jsonPath("$.data.iceServers").isArray())
76+
.andExpect(jsonPath("$.data.iceServers").isNotEmpty());
77+
}
78+
79+
@Test
80+
@DisplayName("userId만")
81+
void t3() throws Exception {
82+
// given
83+
Long userId = 1L;
84+
85+
// when & then
86+
mockMvc.perform(get("/api/webrtc/ice-servers")
87+
.param("userId", userId.toString())
88+
.contentType(MediaType.APPLICATION_JSON))
89+
.andDo(print())
90+
.andExpect(status().isOk())
91+
.andExpect(jsonPath("$.code").value("SUCCESS_200"))
92+
.andExpect(jsonPath("$.success").value(true))
93+
.andExpect(jsonPath("$.data.iceServers").isArray());
94+
}
95+
96+
@Test
97+
@DisplayName("roomId만")
98+
void t4() throws Exception {
99+
// given
100+
Long roomId = 100L;
101+
102+
// when & then
103+
mockMvc.perform(get("/api/webrtc/ice-servers")
104+
.param("roomId", roomId.toString())
105+
.contentType(MediaType.APPLICATION_JSON))
106+
.andDo(print())
107+
.andExpect(status().isOk())
108+
.andExpect(jsonPath("$.code").value("SUCCESS_200"))
109+
.andExpect(jsonPath("$.success").value(true))
110+
.andExpect(jsonPath("$.data.iceServers").isArray());
111+
}
112+
113+
@Test
114+
@DisplayName("Google STUN 서버 포함")
115+
void t5() throws Exception {
116+
// when & then
117+
MvcResult result = mockMvc.perform(get("/api/webrtc/ice-servers")
118+
.contentType(MediaType.APPLICATION_JSON))
119+
.andDo(print())
120+
.andExpect(status().isOk())
121+
.andReturn();
122+
123+
String content = result.getResponse().getContentAsString();
124+
125+
// Google STUN 서버 확인
126+
assertThat(content).contains("stun.l.google.com");
127+
}
128+
129+
@Test
130+
@DisplayName("응답 구조 검증")
131+
void t6() throws Exception {
132+
// when & then
133+
MvcResult result = mockMvc.perform(get("/api/webrtc/ice-servers")
134+
.contentType(MediaType.APPLICATION_JSON))
135+
.andDo(print())
136+
.andExpect(status().isOk())
137+
.andReturn();
138+
139+
String content = result.getResponse().getContentAsString();
140+
assertThat(content).isNotEmpty();
141+
142+
// JSON 구조 검증
143+
assertThat(content).contains("code");
144+
assertThat(content).contains("message");
145+
assertThat(content).contains("data");
146+
assertThat(content).contains("success");
147+
assertThat(content).contains("iceServers");
148+
}
149+
}
150+
151+
@Nested
152+
@DisplayName("Health Check")
153+
class HealthCheckTest {
154+
155+
@Test
156+
@DisplayName("정상 응답")
157+
void t7() throws Exception {
158+
// when & then
159+
mockMvc.perform(get("/api/webrtc/health")
160+
.contentType(MediaType.APPLICATION_JSON))
161+
.andDo(print())
162+
.andExpect(status().isOk())
163+
.andExpect(jsonPath("$.code").value("SUCCESS_200"))
164+
.andExpect(jsonPath("$.message").value("WebRTC 서비스 정상 작동 중"))
165+
.andExpect(jsonPath("$.success").value(true));
166+
}
167+
168+
@Test
169+
@DisplayName("반복 호출")
170+
void t8() throws Exception {
171+
// when & then
172+
for (int i = 0; i < 3; i++) {
173+
mockMvc.perform(get("/api/webrtc/health")
174+
.contentType(MediaType.APPLICATION_JSON))
175+
.andExpect(status().isOk())
176+
.andExpect(jsonPath("$.code").value("SUCCESS_200"))
177+
.andExpect(jsonPath("$.success").value(true));
178+
}
179+
}
180+
181+
@Test
182+
@DisplayName("응답 구조 검증")
183+
void t9() throws Exception {
184+
// when & then
185+
MvcResult result = mockMvc.perform(get("/api/webrtc/health")
186+
.contentType(MediaType.APPLICATION_JSON))
187+
.andDo(print())
188+
.andExpect(status().isOk())
189+
.andReturn();
190+
191+
String content = result.getResponse().getContentAsString();
192+
193+
// RsData 구조 검증
194+
assertThat(content).contains("code");
195+
assertThat(content).contains("message");
196+
assertThat(content).contains("success");
197+
}
198+
}
199+
200+
@Nested
201+
@DisplayName("엔드포인트")
202+
class EndpointTest {
203+
204+
@Test
205+
@DisplayName("Content-Type 생략 가능")
206+
void t10() throws Exception {
207+
// when & then
208+
mockMvc.perform(get("/api/webrtc/health"))
209+
.andExpect(status().isOk())
210+
.andExpect(jsonPath("$.success").value(true));
211+
}
212+
213+
@Test
214+
@DisplayName("JSON 응답")
215+
void t11() throws Exception {
216+
// ICE servers endpoint
217+
mockMvc.perform(get("/api/webrtc/ice-servers"))
218+
.andExpect(status().isOk())
219+
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON));
220+
221+
// Health endpoint
222+
mockMvc.perform(get("/api/webrtc/health"))
223+
.andExpect(status().isOk())
224+
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON));
225+
}
226+
}
227+
}

0 commit comments

Comments
 (0)