重构设备数据存储

This commit is contained in:
zhouhao 2022-08-24 17:59:10 +08:00
parent 3cbbaa6643
commit 1227a8e6ce
1 changed files with 16 additions and 7 deletions

View File

@ -309,17 +309,26 @@ public class JetLinksMqttDeviceMessageCodecTest {
@Test @Test
public void testPropertiesReport() { public void testPropertiesReport() {
Message message = codec.decode(createMessageContext(SimpleMqttMessage.builder() Message message = codec.decode(createMessageContext(
.topic("/product1/device1/properties/report") SimpleMqttMessage
.payload(Unpooled.wrappedBuffer("{\"messageId\":\"test\",\"properties\":{\"sn\":\"test\"}}" .builder()
.getBytes())) .topic("/product1/device1/properties/report")
.build())).blockFirst(); .payload(Unpooled.wrappedBuffer(("{\"messageId\":\"test\"," +
"\"properties\":{\"sn\":\"test\"}," +
"\"propertySourceTimes\":{\"sn\":10086}" +
"}").getBytes()))
.build()))
.blockFirst();
Assert.assertTrue(message instanceof ReportPropertyMessage); Assert.assertTrue(message instanceof ReportPropertyMessage);
ReportPropertyMessage reply = ((ReportPropertyMessage) message); ReportPropertyMessage reply = ((ReportPropertyMessage) message);
Assert.assertNotNull(reply.getPropertySourceTimes());
Assert.assertEquals(reply.getPropertySourceTimes().get("sn"), Long.valueOf(10086L));
Assert.assertEquals(reply.getDeviceId(), "device1"); Assert.assertEquals(reply.getDeviceId(), "device1");
Assert.assertEquals(reply.getMessageId(), "test"); Assert.assertEquals(reply.getMessageId(), "test");
Assert.assertEquals(reply.getProperties(), Collections.singletonMap("sn", "test")); Assert.assertEquals(reply.getProperties(), Collections.singletonMap("sn", "test"));
System.out.println(reply); System.out.println(reply);
} }
@ -390,12 +399,12 @@ public class JetLinksMqttDeviceMessageCodecTest {
Assert.assertNotNull(currentReply); Assert.assertNotNull(currentReply);
Assert.assertEquals(((MqttMessage) currentReply).getTopic(),"/product1/device1/time-sync/reply"); Assert.assertEquals(((MqttMessage) currentReply).getTopic(), "/product1/device1/time-sync/reply");
Assert.assertTrue(currentReply.payloadAsString().contains("timestamp")); Assert.assertTrue(currentReply.payloadAsString().contains("timestamp"));
} }
public void testTopic(){ public void testTopic() {
} }