|
|
|
@ -43,6 +43,7 @@ import org.thingsboard.server.common.data.Dashboard; |
|
|
|
import org.thingsboard.server.common.data.DataConstants; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
|
import org.thingsboard.server.common.data.DeviceTransportType; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.EntityView; |
|
|
|
import org.thingsboard.server.common.data.OtaPackageInfo; |
|
|
|
@ -56,17 +57,24 @@ import org.thingsboard.server.common.data.alarm.AlarmInfo; |
|
|
|
import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
|
|
|
import org.thingsboard.server.common.data.alarm.AlarmStatus; |
|
|
|
import org.thingsboard.server.common.data.asset.Asset; |
|
|
|
import org.thingsboard.server.common.data.device.data.PowerMode; |
|
|
|
import org.thingsboard.server.common.data.device.data.PowerSavingConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.AlarmCondition; |
|
|
|
import org.thingsboard.server.common.data.device.profile.AlarmConditionFilter; |
|
|
|
import org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey; |
|
|
|
import org.thingsboard.server.common.data.device.profile.AlarmConditionKeyType; |
|
|
|
import org.thingsboard.server.common.data.device.profile.AlarmRule; |
|
|
|
import org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm; |
|
|
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
|
|
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.SimpleAlarmConditionSpec; |
|
|
|
import org.thingsboard.server.common.data.device.profile.SnmpDeviceProfileTransportConfiguration; |
|
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
|
import org.thingsboard.server.common.data.edge.EdgeEvent; |
|
|
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
|
|
|
@ -77,6 +85,7 @@ import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|
|
|
import org.thingsboard.server.common.data.id.RuleChainId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.kv.DataType; |
|
|
|
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; |
|
|
|
import org.thingsboard.server.common.data.ota.OtaPackageType; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
@ -99,6 +108,9 @@ import org.thingsboard.server.common.data.security.Authority; |
|
|
|
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|
|
|
import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
|
|
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|
|
|
import org.thingsboard.server.common.data.transport.snmp.SnmpMapping; |
|
|
|
import org.thingsboard.server.common.data.transport.snmp.config.SnmpCommunicationConfig; |
|
|
|
import org.thingsboard.server.common.data.transport.snmp.config.impl.TelemetryQueryingSnmpCommunicationConfig; |
|
|
|
import org.thingsboard.server.common.data.widget.WidgetType; |
|
|
|
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
|
|
|
import org.thingsboard.server.common.msg.queue.ServiceType; |
|
|
|
@ -139,6 +151,7 @@ import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; |
|
|
|
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; |
|
|
|
import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos; |
|
|
|
import org.thingsboard.server.transport.AbstractTransportIntegrationTest; |
|
|
|
|
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.util.ArrayList; |
|
|
|
@ -246,10 +259,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
|
|
private void installation() throws Exception { |
|
|
|
edge = doPost("/api/edge", constructEdge("Test Edge", "test"), Edge.class); |
|
|
|
|
|
|
|
MqttDeviceProfileTransportConfiguration transportConfiguration = new MqttDeviceProfileTransportConfiguration(); |
|
|
|
transportConfiguration.setTransportPayloadTypeConfiguration(new JsonTransportPayloadConfiguration()); |
|
|
|
|
|
|
|
thermostatDeviceProfile = this.createDeviceProfile(THERMOSTAT_DEVICE_PROFILE_NAME, transportConfiguration); |
|
|
|
thermostatDeviceProfile = this.createDeviceProfile(THERMOSTAT_DEVICE_PROFILE_NAME, |
|
|
|
createMqttDeviceProfileTransportConfiguration(new JsonTransportPayloadConfiguration(), false)); |
|
|
|
|
|
|
|
extendDeviceProfileData(thermostatDeviceProfile); |
|
|
|
thermostatDeviceProfile = doPost("/api/deviceProfile", thermostatDeviceProfile, DeviceProfile.class); |
|
|
|
@ -439,6 +450,119 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdLSB(), deviceProfile.getUuidId().getLeastSignificantBits()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeviceProfiles_snmp() throws Exception { |
|
|
|
DeviceProfile deviceProfile = createDeviceProfileAndDoBasicAssert("SNMP", createSnmpDeviceProfileTransportConfiguration()); |
|
|
|
|
|
|
|
AbstractMessage latestMessage = edgeImitator.getLatestMessage(); |
|
|
|
Assert.assertTrue(latestMessage instanceof DeviceProfileUpdateMsg); |
|
|
|
DeviceProfileUpdateMsg deviceProfileUpdateMsg = (DeviceProfileUpdateMsg) latestMessage; |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceProfileUpdateMsg.getMsgType()); |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdMSB(), deviceProfile.getUuidId().getMostSignificantBits()); |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdLSB(), deviceProfile.getUuidId().getLeastSignificantBits()); |
|
|
|
Assert.assertEquals(DeviceTransportType.SNMP.name(), deviceProfileUpdateMsg.getTransportType()); |
|
|
|
|
|
|
|
// TODO: add custom validation
|
|
|
|
|
|
|
|
removeDeviceProfileAndDoBasicAssert(deviceProfile); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeviceProfiles_lwm2m() throws Exception { |
|
|
|
DeviceProfile deviceProfile = createDeviceProfileAndDoBasicAssert("LWM2M", createLwm2mDeviceProfileTransportConfiguration()); |
|
|
|
|
|
|
|
AbstractMessage latestMessage = edgeImitator.getLatestMessage(); |
|
|
|
Assert.assertTrue(latestMessage instanceof DeviceProfileUpdateMsg); |
|
|
|
DeviceProfileUpdateMsg deviceProfileUpdateMsg = (DeviceProfileUpdateMsg) latestMessage; |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceProfileUpdateMsg.getMsgType()); |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdMSB(), deviceProfile.getUuidId().getMostSignificantBits()); |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdLSB(), deviceProfile.getUuidId().getLeastSignificantBits()); |
|
|
|
Assert.assertEquals(DeviceTransportType.LWM2M.name(), deviceProfileUpdateMsg.getTransportType()); |
|
|
|
|
|
|
|
// TODO: add custom validation
|
|
|
|
|
|
|
|
removeDeviceProfileAndDoBasicAssert(deviceProfile); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDeviceProfiles_coap() throws Exception { |
|
|
|
DeviceProfile deviceProfile = createDeviceProfileAndDoBasicAssert("COAP", createCoapDeviceProfileTransportConfiguration()); |
|
|
|
|
|
|
|
AbstractMessage latestMessage = edgeImitator.getLatestMessage(); |
|
|
|
Assert.assertTrue(latestMessage instanceof DeviceProfileUpdateMsg); |
|
|
|
DeviceProfileUpdateMsg deviceProfileUpdateMsg = (DeviceProfileUpdateMsg) latestMessage; |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceProfileUpdateMsg.getMsgType()); |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdMSB(), deviceProfile.getUuidId().getMostSignificantBits()); |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdLSB(), deviceProfile.getUuidId().getLeastSignificantBits()); |
|
|
|
Assert.assertEquals(DeviceTransportType.COAP.name(), deviceProfileUpdateMsg.getTransportType()); |
|
|
|
|
|
|
|
// TODO: add custom validation
|
|
|
|
|
|
|
|
removeDeviceProfileAndDoBasicAssert(deviceProfile); |
|
|
|
} |
|
|
|
|
|
|
|
private DeviceProfile createDeviceProfileAndDoBasicAssert(String deviceProfileName, DeviceProfileTransportConfiguration deviceProfileTransportConfiguration) throws Exception { |
|
|
|
DeviceProfile deviceProfile = this.createDeviceProfile(deviceProfileName, deviceProfileTransportConfiguration); |
|
|
|
extendDeviceProfileData(deviceProfile); |
|
|
|
edgeImitator.expectMessageAmount(1); |
|
|
|
deviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); |
|
|
|
Assert.assertTrue(edgeImitator.waitForMessages()); |
|
|
|
return deviceProfile; |
|
|
|
} |
|
|
|
|
|
|
|
private void removeDeviceProfileAndDoBasicAssert(DeviceProfile deviceProfile) throws Exception { |
|
|
|
edgeImitator.expectMessageAmount(1); |
|
|
|
doDelete("/api/deviceProfile/" + deviceProfile.getUuidId()) |
|
|
|
.andExpect(status().isOk()); |
|
|
|
Assert.assertTrue(edgeImitator.waitForMessages()); |
|
|
|
AbstractMessage latestMessage = edgeImitator.getLatestMessage(); |
|
|
|
Assert.assertTrue(latestMessage instanceof DeviceProfileUpdateMsg); |
|
|
|
DeviceProfileUpdateMsg deviceProfileUpdateMsg = (DeviceProfileUpdateMsg) latestMessage; |
|
|
|
Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, deviceProfileUpdateMsg.getMsgType()); |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdMSB(), deviceProfile.getUuidId().getMostSignificantBits()); |
|
|
|
Assert.assertEquals(deviceProfileUpdateMsg.getIdLSB(), deviceProfile.getUuidId().getLeastSignificantBits()); |
|
|
|
} |
|
|
|
|
|
|
|
private SnmpDeviceProfileTransportConfiguration createSnmpDeviceProfileTransportConfiguration() { |
|
|
|
SnmpDeviceProfileTransportConfiguration transportConfiguration = new SnmpDeviceProfileTransportConfiguration(); |
|
|
|
List<SnmpCommunicationConfig> communicationConfigs = new ArrayList<>(); |
|
|
|
TelemetryQueryingSnmpCommunicationConfig communicationConfig = new TelemetryQueryingSnmpCommunicationConfig(); |
|
|
|
communicationConfig.setQueryingFrequencyMs(500L); |
|
|
|
List<SnmpMapping> mappings = new ArrayList<>(); |
|
|
|
mappings.add(new SnmpMapping("1.3.3.5.6.7.8.9.1", "temperature", DataType.DOUBLE)); |
|
|
|
communicationConfig.setMappings(mappings); |
|
|
|
communicationConfigs.add(communicationConfig); |
|
|
|
transportConfiguration.setCommunicationConfigs(communicationConfigs); |
|
|
|
transportConfiguration.setTimeoutMs(1000); |
|
|
|
transportConfiguration.setRetries(3); |
|
|
|
return transportConfiguration; |
|
|
|
} |
|
|
|
|
|
|
|
private Lwm2mDeviceProfileTransportConfiguration createLwm2mDeviceProfileTransportConfiguration() { |
|
|
|
// TODO: add custom configuration
|
|
|
|
Lwm2mDeviceProfileTransportConfiguration transportConfiguration = new Lwm2mDeviceProfileTransportConfiguration(); |
|
|
|
return transportConfiguration; |
|
|
|
} |
|
|
|
|
|
|
|
private CoapDeviceProfileTransportConfiguration createCoapDeviceProfileTransportConfiguration() { |
|
|
|
CoapDeviceProfileTransportConfiguration transportConfiguration = new CoapDeviceProfileTransportConfiguration(); |
|
|
|
PowerSavingConfiguration clientSettings = new PowerSavingConfiguration(); |
|
|
|
clientSettings.setPowerMode(PowerMode.DRX); |
|
|
|
clientSettings.setEdrxCycle(1L); |
|
|
|
clientSettings.setPsmActivityTimer(1L); |
|
|
|
clientSettings.setPagingTransmissionWindow(1L); |
|
|
|
transportConfiguration.setClientSettings(clientSettings); |
|
|
|
DefaultCoapDeviceTypeConfiguration coapDeviceTypeConfiguration = new DefaultCoapDeviceTypeConfiguration(); |
|
|
|
ProtoTransportPayloadConfiguration transportPayloadTypeConfiguration = new ProtoTransportPayloadConfiguration(); |
|
|
|
transportPayloadTypeConfiguration.setDeviceTelemetryProtoSchema(AbstractTransportIntegrationTest.DEVICE_TELEMETRY_PROTO_SCHEMA); |
|
|
|
transportPayloadTypeConfiguration.setDeviceAttributesProtoSchema(AbstractTransportIntegrationTest.DEVICE_ATTRIBUTES_PROTO_SCHEMA); |
|
|
|
transportPayloadTypeConfiguration.setDeviceRpcResponseProtoSchema(AbstractTransportIntegrationTest.DEVICE_RPC_RESPONSE_PROTO_SCHEMA); |
|
|
|
transportPayloadTypeConfiguration.setDeviceRpcRequestProtoSchema(AbstractTransportIntegrationTest.DEVICE_RPC_REQUEST_PROTO_SCHEMA); |
|
|
|
coapDeviceTypeConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration); |
|
|
|
transportConfiguration.setCoapDeviceTypeConfiguration(coapDeviceTypeConfiguration); |
|
|
|
return transportConfiguration; |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDevices() throws Exception { |
|
|
|
// 1
|
|
|
|
|