|
|
|
@ -146,7 +146,7 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
installation(); |
|
|
|
|
|
|
|
edgeImitator = new EdgeImitator("localhost", 7070, edge.getRoutingKey(), edge.getSecret()); |
|
|
|
edgeImitator.expectMessageAmount(16); |
|
|
|
edgeImitator.expectMessageAmount(21); |
|
|
|
edgeImitator.connect(); |
|
|
|
|
|
|
|
requestEdgeRuleChainMetadata(); |
|
|
|
@ -240,10 +240,14 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
validateEdgeConfiguration(); |
|
|
|
|
|
|
|
// 3 messages - 2 from device profile fetcher (default and thermostat), 1 from device profile controller (thermostat)
|
|
|
|
// 5 messages
|
|
|
|
// - 2 from device profile fetcher (default and thermostat)
|
|
|
|
// - 1 from device fetcher
|
|
|
|
// - 1 from device profile controller (thermostat)
|
|
|
|
// - 1 from device controller (thermostat)
|
|
|
|
validateDeviceProfiles(); |
|
|
|
|
|
|
|
// 1 message from device controller
|
|
|
|
// 2 messages - 1 from device fetcher and 1 from device controller
|
|
|
|
validateDevices(); |
|
|
|
|
|
|
|
// 2 messages - 1 from asset fetcher and 1 from asset controller
|
|
|
|
@ -258,7 +262,10 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
// 4 messages - 4 messages from fetcher - 2 from system level ('mail', 'mailTemplates') and 2 from admin level ('mail', 'mailTemplates')
|
|
|
|
validateAdminSettings(); |
|
|
|
|
|
|
|
// 1 message from asset profile fetcher
|
|
|
|
// 3 messages
|
|
|
|
// - 1 message from asset profile fetcher
|
|
|
|
// - 1 message from asset fetcher
|
|
|
|
// - 1 message from asset controller
|
|
|
|
validateAssetProfiles(); |
|
|
|
|
|
|
|
// 1 message from queue fetcher
|
|
|
|
@ -278,8 +285,10 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
List<DeviceProfileUpdateMsg> deviceProfileUpdateMsgList = edgeImitator.findAllMessagesByType(DeviceProfileUpdateMsg.class); |
|
|
|
// default msg
|
|
|
|
// thermostat msg from fetcher
|
|
|
|
// thermostat msg from contoller
|
|
|
|
Assert.assertEquals(3, deviceProfileUpdateMsgList.size()); |
|
|
|
// thermostat msg from device fetcher
|
|
|
|
// thermostat msg from controller
|
|
|
|
// thermostat msg from creation of device
|
|
|
|
Assert.assertEquals(5, deviceProfileUpdateMsgList.size()); |
|
|
|
Optional<DeviceProfileUpdateMsg> thermostatProfileUpdateMsgOpt = |
|
|
|
deviceProfileUpdateMsgList.stream().filter(dfum -> THERMOSTAT_DEVICE_PROFILE_NAME.equals(dfum.getName())).findAny(); |
|
|
|
Assert.assertTrue(thermostatProfileUpdateMsgOpt.isPresent()); |
|
|
|
@ -296,9 +305,13 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
|
|
|
|
private void validateDevices() throws Exception { |
|
|
|
Optional<DeviceUpdateMsg> deviceUpdateMsgOpt = edgeImitator.findMessageByType(DeviceUpdateMsg.class); |
|
|
|
Assert.assertTrue(deviceUpdateMsgOpt.isPresent()); |
|
|
|
DeviceUpdateMsg deviceUpdateMsg = deviceUpdateMsgOpt.get(); |
|
|
|
List<DeviceUpdateMsg> deviceUpdateMsgs = edgeImitator.findAllMessagesByType(DeviceUpdateMsg.class); |
|
|
|
Assert.assertEquals(2, deviceUpdateMsgs.size()); |
|
|
|
validateDevice(deviceUpdateMsgs.get(0)); |
|
|
|
validateDevice(deviceUpdateMsgs.get(1)); |
|
|
|
} |
|
|
|
|
|
|
|
private void validateDevice(DeviceUpdateMsg deviceUpdateMsg) throws Exception { |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceUpdateMsg.getMsgType()); |
|
|
|
UUID deviceUUID = new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()); |
|
|
|
Device device = doGet("/api/device/" + deviceUUID, Device.class); |
|
|
|
@ -306,6 +319,8 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getUuidId() + "/devices?", |
|
|
|
new TypeReference<PageData<Device>>() {}, new PageLink(100)).getData(); |
|
|
|
Assert.assertTrue(edgeDevices.contains(device)); |
|
|
|
|
|
|
|
testAutoGeneratedCodeByProtobuf(deviceUpdateMsg); |
|
|
|
} |
|
|
|
|
|
|
|
private void validateAssets() throws Exception { |
|
|
|
@ -392,9 +407,9 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
|
|
|
|
private void validateAssetProfiles() throws Exception { |
|
|
|
Optional<AssetProfileUpdateMsg> assetProfileUpdateMsgOpt = edgeImitator.findMessageByType(AssetProfileUpdateMsg.class); |
|
|
|
Assert.assertTrue(assetProfileUpdateMsgOpt.isPresent()); |
|
|
|
AssetProfileUpdateMsg assetProfileUpdateMsg = assetProfileUpdateMsgOpt.get(); |
|
|
|
List<AssetProfileUpdateMsg> assetProfileUpdateMsgs = edgeImitator.findAllMessagesByType(AssetProfileUpdateMsg.class); |
|
|
|
Assert.assertEquals(3, assetProfileUpdateMsgs.size()); |
|
|
|
AssetProfileUpdateMsg assetProfileUpdateMsg = assetProfileUpdateMsgs.get(0); |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, assetProfileUpdateMsg.getMsgType()); |
|
|
|
UUID assetProfileUUID = new UUID(assetProfileUpdateMsg.getIdMSB(), assetProfileUpdateMsg.getIdLSB()); |
|
|
|
AssetProfile assetProfile = doGet("/api/assetProfile/" + assetProfileUUID, AssetProfile.class); |
|
|
|
@ -439,17 +454,24 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
// create device and assign to edge
|
|
|
|
Device savedDevice = saveDevice(StringUtils.randomAlphanumeric(15), thermostatDeviceProfile.getName()); |
|
|
|
edgeImitator.expectMessageAmount(1); |
|
|
|
edgeImitator.expectMessageAmount(2); // device and device profile messages
|
|
|
|
doPost("/api/edge/" + edge.getUuidId() |
|
|
|
+ "/device/" + savedDevice.getUuidId(), Device.class); |
|
|
|
Assert.assertTrue(edgeImitator.waitForMessages()); |
|
|
|
AbstractMessage latestMessage = edgeImitator.getLatestMessage(); |
|
|
|
Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg); |
|
|
|
DeviceUpdateMsg deviceUpdateMsg = (DeviceUpdateMsg) latestMessage; |
|
|
|
Optional<DeviceUpdateMsg> deviceUpdateMsgOpt = edgeImitator.findMessageByType(DeviceUpdateMsg.class); |
|
|
|
Assert.assertTrue(deviceUpdateMsgOpt.isPresent()); |
|
|
|
DeviceUpdateMsg deviceUpdateMsg = deviceUpdateMsgOpt.get(); |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceUpdateMsg.getMsgType()); |
|
|
|
Assert.assertEquals(savedDevice.getUuidId().getMostSignificantBits(), deviceUpdateMsg.getIdMSB()); |
|
|
|
Assert.assertEquals(savedDevice.getUuidId().getLeastSignificantBits(), deviceUpdateMsg.getIdLSB()); |
|
|
|
|
|
|
|
Optional<DeviceProfileUpdateMsg> deviceProfileUpdateMsgOpt = edgeImitator.findMessageByType(DeviceProfileUpdateMsg.class); |
|
|
|
Assert.assertTrue(deviceProfileUpdateMsgOpt.isPresent()); |
|
|
|
DeviceProfileUpdateMsg deviceProfileUpdateMsg = deviceProfileUpdateMsgOpt.get(); |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceProfileUpdateMsg.getMsgType()); |
|
|
|
Assert.assertEquals(thermostatDeviceProfile.getUuidId().getMostSignificantBits(), deviceProfileUpdateMsg.getIdMSB()); |
|
|
|
Assert.assertEquals(thermostatDeviceProfile.getUuidId().getLeastSignificantBits(), deviceProfileUpdateMsg.getIdLSB()); |
|
|
|
|
|
|
|
// update device
|
|
|
|
edgeImitator.expectMessageAmount(1); |
|
|
|
savedDevice.setFirmwareId(firmwareOtaPackageInfo.getId()); |
|
|
|
@ -463,7 +485,7 @@ abstract public class AbstractEdgeTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
savedDevice = doPost("/api/device", savedDevice, Device.class); |
|
|
|
Assert.assertTrue(edgeImitator.waitForMessages()); |
|
|
|
latestMessage = edgeImitator.getLatestMessage(); |
|
|
|
AbstractMessage latestMessage = edgeImitator.getLatestMessage(); |
|
|
|
Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg); |
|
|
|
deviceUpdateMsg = (DeviceUpdateMsg) latestMessage; |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE, deviceUpdateMsg.getMsgType()); |
|
|
|
|