修改测试用例

This commit is contained in:
孙小云 2025-12-18 19:26:03 +08:00
parent af7800bdbe
commit 6fdfe482b2
2 changed files with 37 additions and 3 deletions

View File

@ -89,6 +89,40 @@ public class SubCommandTest {
Map<String, Object> params = new HashMap<>();
params.put("shouldFail", false);
CompletableFuture<CommandResult> future =
machineCommandManager.executeCommand(TEST_SN, CommandType.OPEN_COVER, params);
scheduler.schedule(() -> {
try {
Thread.sleep(100);
String response = "{\"result\":\"success\"}";
mqttCallbackRegistry.handleMessage("test/" + TEST_SN + "/response", response);
log.info(">>> 模拟发送主指令方法回调(成功): {}", response);
Thread.sleep(100);
response = "{\"result\":\"subSuccess\"}";
mqttCallbackRegistry.handleMessage("test/" + TEST_SN + "/response123", response);
log.info(">>> 模拟发送成功子指令方法回调: {}", response);
} catch (InterruptedException e) {
e.printStackTrace();
}
}, 200, TimeUnit.MILLISECONDS);
CommandResult result = future.get();
assertTrue(result.isSuccess(), "指令应该执行成功(包括子指令)");
log.info(">>> 测试通过:主指令和成功子指令都执行成功");
}
@Test
@Order(6)
@DisplayName("测试6: 失败子命令场景")
public void testSuccessSubCommand2() throws ExecutionException, InterruptedException {
log.info(">>> 场景:主指令成功后执行成功分支的子指令");
Map<String, Object> params = new HashMap<>();
params.put("shouldFail", false);
CompletableFuture<CommandResult> future =
machineCommandManager.executeCommand(TEST_SN, CommandType.OPEN_COVER, params);
@ -118,8 +152,8 @@ public class SubCommandTest {
* 测试6: 失败子命令场景
*/
@Test
@Order(6)
@DisplayName("测试6: 失败子命令场景")
@Order(7)
@DisplayName("测试7: 主指令失败走子指令,子指令又有子指令")
public void testFailureSubCommand() throws ExecutionException, InterruptedException {
log.info(">>> 场景:主指令失败后执行失败分支的补救子指令");

View File

@ -34,7 +34,7 @@ public class TestSuccessSubInstruction extends AbstractInstruction {
String sn = context.getSn();
return CallbackConfig.builder()
.topic("test/" + sn + "/response")
.topic("test/" + sn + "/response123")
.fieldPath("result")
.expectedValue("subSuccess")
.timeoutMs(5000)