完善测试用例
This commit is contained in:
parent
c7e636345f
commit
f961c6eb4b
|
|
@ -182,6 +182,88 @@ public class BasicScenarioTest {
|
||||||
log.info(">>> 测试通过:状态回调超时,错误消息: {}", result.getErrorMessage());
|
log.info(">>> 测试通过:状态回调超时,错误消息: {}", result.getErrorMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试1: 简单成功场景
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Order(5)
|
||||||
|
@DisplayName("测试1: 简单成功场景 状态第一次错误 第二次成功")
|
||||||
|
public void testSimpleSuccessTwo() throws ExecutionException, InterruptedException {
|
||||||
|
log.info(">>> 场景:指令被通过,远程命令成功,方法回调和状态回调都成功");
|
||||||
|
|
||||||
|
CompletableFuture<CommandResult> future =
|
||||||
|
machineCommandManager.executeCommand(TEST_SN, CommandType.TAKE_OFF, new HashMap<>());
|
||||||
|
|
||||||
|
scheduler.schedule(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
String response = "{\"result\":\"success\"}";
|
||||||
|
mqttCallbackRegistry.handleMessage("test/" + TEST_SN + "/response", response);
|
||||||
|
log.info(">>> 模拟发送方法回调: {}", response);
|
||||||
|
|
||||||
|
Thread.sleep(100);
|
||||||
|
response = "{\"status\":\"error\"}";
|
||||||
|
mqttCallbackRegistry.handleMessage("test/" + TEST_SN + "/state", response);
|
||||||
|
log.info(">>> 模拟发送状态回调: {}", response);
|
||||||
|
|
||||||
|
Thread.sleep(100);
|
||||||
|
response = "{\"status\":\"completed\"}";
|
||||||
|
mqttCallbackRegistry.handleMessage("test/" + TEST_SN + "/state", response);
|
||||||
|
log.info(">>> 模拟发送状态回调: {}", response);
|
||||||
|
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}, 200, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
CommandResult result = future.get();
|
||||||
|
assertTrue(result.isSuccess(), "指令应该执行成功");
|
||||||
|
log.info(">>> 测试通过:指令执行成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试1: 简单成功场景
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Order(6)
|
||||||
|
@DisplayName("测试6: 简单失败场景 方法第一次失败 第二次成功")
|
||||||
|
public void testSimpleSuccessThree() throws ExecutionException, InterruptedException {
|
||||||
|
log.info(">>> 场景:指令被通过,远程命令成功,方法回调和状态回调都成功");
|
||||||
|
|
||||||
|
CompletableFuture<CommandResult> future =
|
||||||
|
machineCommandManager.executeCommand(TEST_SN, CommandType.TAKE_OFF, new HashMap<>());
|
||||||
|
|
||||||
|
scheduler.schedule(() -> {
|
||||||
|
try {
|
||||||
|
|
||||||
|
Thread.sleep(100);
|
||||||
|
String response = "{\"result\":\"error\"}";
|
||||||
|
mqttCallbackRegistry.handleMessage("test/" + TEST_SN + "/response", response);
|
||||||
|
log.info(">>> 模拟发送方法回调: {}", response);
|
||||||
|
|
||||||
|
Thread.sleep(100);
|
||||||
|
response = "{\"result\":\"success\"}";
|
||||||
|
mqttCallbackRegistry.handleMessage("test/" + TEST_SN + "/response", response);
|
||||||
|
log.info(">>> 模拟发送方法回调: {}", response);
|
||||||
|
|
||||||
|
Thread.sleep(100);
|
||||||
|
response = "{\"status\":\"completed\"}";
|
||||||
|
mqttCallbackRegistry.handleMessage("test/" + TEST_SN + "/state", response);
|
||||||
|
log.info(">>> 模拟发送状态回调: {}", response);
|
||||||
|
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}, 200, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
CommandResult result = future.get();
|
||||||
|
assertFalse(result.isSuccess(), "指令应该失败");
|
||||||
|
log.info(">>> 测试通过:指令执行失败");
|
||||||
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void cleanupAll() {
|
public static void cleanupAll() {
|
||||||
log.info("=== 基础场景测试完成 ===");
|
log.info("=== 基础场景测试完成 ===");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue