package com.zy.integration.iot;
|
|
import com.zy.iot.config.IotProperties;
|
import com.zy.iot.util.IotInstructionIdGenerator;
|
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Test;
|
|
public class IotSupportTest {
|
|
@Test
|
public void shouldResolveServerUriAndClientId() {
|
IotProperties properties = new IotProperties();
|
properties.setEndpoint("example-ats.iot.cn-north-1.amazonaws.com.cn");
|
properties.setPort(8883);
|
properties.setThingName("thing-a");
|
|
Assertions.assertEquals("mqtts://example-ats.iot.cn-north-1.amazonaws.com.cn:8883", properties.getServerUri());
|
String thingId = properties.getResolvedClientId();
|
Assertions.assertNotNull(thingId);
|
Assertions.assertTrue(thingId.startsWith("thing-a-"));
|
Assertions.assertEquals(thingId, properties.getResolvedClientId());
|
|
IotProperties withClient = new IotProperties();
|
withClient.setClientId("client-b");
|
String cid = withClient.getResolvedClientId();
|
Assertions.assertNotNull(cid);
|
Assertions.assertTrue(cid.startsWith("client-b-"));
|
Assertions.assertEquals(cid, withClient.getResolvedClientId());
|
}
|
|
@Test
|
public void shouldGenerateStableLengthInstructionId() {
|
String instructionId = IotInstructionIdGenerator.generate("wrk-1001");
|
|
Assertions.assertEquals(20, instructionId.length());
|
Assertions.assertEquals(instructionId, instructionId.toUpperCase());
|
}
|
}
|