test(接口测试): 添加Socket消息推送测试用例

This commit is contained in:
fit2-zhao 2024-01-03 16:51:08 +08:00 committed by Craftsman
parent ee4d3a7d49
commit 27921050a4
2 changed files with 16 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import io.metersphere.sdk.util.JSON;
import jakarta.websocket.RemoteEndpoint; import jakarta.websocket.RemoteEndpoint;
import jakarta.websocket.Session; import jakarta.websocket.Session;
import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
@ -32,6 +33,7 @@ public class WebSocketHandlerTest {
private WebSocketHandler webSocketHandler; private WebSocketHandler webSocketHandler;
@Test @Test
@Order(1)
void testOpenSession() throws IOException { void testOpenSession() throws IOException {
// 模拟参数 // 模拟参数
String reportId = "123"; String reportId = "123";
@ -46,6 +48,7 @@ public class WebSocketHandlerTest {
} }
@Test @Test
@Order(2)
void testOnMessage() { void testOnMessage() {
// 模拟参数 // 模拟参数
String reportId = "123"; String reportId = "123";
@ -60,6 +63,17 @@ public class WebSocketHandlerTest {
} }
@Test @Test
@Order(3)
void testOnHeartbeatCheck() throws IOException {
// 模拟参数
when(session.getAsyncRemote()).thenReturn(async);
// 调用被测试方法
webSocketHandler.heartbeatCheck();
}
@Test
@Order(4)
void testOnClose() throws IOException { void testOnClose() throws IOException {
// 模拟参数 // 模拟参数
String reportId = "123"; String reportId = "123";
@ -73,6 +87,7 @@ public class WebSocketHandlerTest {
} }
@Test @Test
@Order(5)
void testOnError() throws IOException { void testOnError() throws IOException {
// 模拟参数 // 模拟参数
when(session.getAsyncRemote()).thenReturn(async); when(session.getAsyncRemote()).thenReturn(async);

View File

@ -28,7 +28,7 @@
<guava.version>32.0.1-jre</guava.version> <guava.version>32.0.1-jre</guava.version>
<pagehelper.version>6.0.0</pagehelper.version> <pagehelper.version>6.0.0</pagehelper.version>
<metersphere-jmeter-functions.version>3.0</metersphere-jmeter-functions.version> <metersphere-jmeter-functions.version>3.0</metersphere-jmeter-functions.version>
<metersphere-jmeter-assertions.version>1.0.0</metersphere-jmeter-assertions.version> <metersphere-jmeter-assertions.version>1.0.1</metersphere-jmeter-assertions.version>
<quartz-starter.version>1.0.7</quartz-starter.version> <quartz-starter.version>1.0.7</quartz-starter.version>
<redisson-starter.version>3.25.2</redisson-starter.version> <redisson-starter.version>3.25.2</redisson-starter.version>
<guice.version>5.1.0</guice.version> <guice.version>5.1.0</guice.version>