From f9e7ed27f6ae71f6b2d89c40b422284a7e5411d2 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期三, 26 八月 2026 13:29:53 +0800
Subject: [PATCH] fix(device): 完善 BTS 状态与模拟器契约
---
ruoyi-device/src/test/java/com/ruoyi/device/bts/BtsXmlCodecTest.java | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/ruoyi-device/src/test/java/com/ruoyi/device/bts/BtsXmlCodecTest.java b/ruoyi-device/src/test/java/com/ruoyi/device/bts/BtsXmlCodecTest.java
index 2699acd..d6d2862 100644
--- a/ruoyi-device/src/test/java/com/ruoyi/device/bts/BtsXmlCodecTest.java
+++ b/ruoyi-device/src/test/java/com/ruoyi/device/bts/BtsXmlCodecTest.java
@@ -77,6 +77,17 @@
}
@Test
+ void mapsFinishAsNormalCompletion()
+ {
+ String xml = "<bts><cmd>inquire_resp</cmd><list count=\"1\">"
+ + "<inquire dev=\"22-1-1-1-0\" workstatus=\"finish\"/></list></bts>";
+
+ RealtimeSnapshot snapshot = codec.parseSnapshots(xml, Instant.EPOCH).values().iterator().next();
+
+ assertEquals(DeviceWorkStatus.FINISHED, snapshot.workStatus());
+ }
+
+ @Test
void parsesHistoryPageAndHongKongDeviceTime()
{
ChannelIdentity channel = new ChannelIdentity("lab-bts", 24, 1, 1, 1);
@@ -164,6 +175,27 @@
}
@Test
+ void rejectsResponsesMissingRequiredContainers()
+ {
+ BtsProtocolException discovery = assertThrows(BtsProtocolException.class,
+ () -> codec.parseDeviceInfo("<bts><cmd>getdevinfo_resp</cmd></bts>"));
+ BtsProtocolException realtime = assertThrows(BtsProtocolException.class,
+ () -> codec.parseSnapshots("<bts><cmd>inquire_resp</cmd></bts>", Instant.EPOCH));
+ BtsProtocolException availability = assertThrows(BtsProtocolException.class,
+ () -> codec.parseHistoryAvailability("<bts><cmd>inquiredf_resp</cmd></bts>"));
+ ChannelIdentity channel = new ChannelIdentity("lab-bts", 24, 1, 1, 1);
+ BtsProtocolException history = assertThrows(BtsProtocolException.class,
+ () -> codec.parseHistory("<bts><cmd>download_resp</cmd>"
+ + "<download devtype=\"24\" devid=\"1\" subdevid=\"1\" chlid=\"1\" testid=\"42\"/>"
+ + "</bts>", channel, "42", 1));
+
+ assertEquals(BtsProtocolException.Reason.MISSING_FIELD, discovery.reason());
+ assertEquals(BtsProtocolException.Reason.MISSING_FIELD, realtime.reason());
+ assertEquals(BtsProtocolException.Reason.MISSING_FIELD, availability.reason());
+ assertEquals(BtsProtocolException.Reason.MISSING_FIELD, history.reason());
+ }
+
+ @Test
void rejectsDoctypeAndExternalEntities()
{
String xml = "<!DOCTYPE bts [<!ENTITY xxe SYSTEM \"file:///etc/passwd\">]><bts><cmd>inquire_resp</cmd>&xxe;</bts>";
--
Gitblit v1.7.1