@ -25,11 +25,13 @@ import io.netty.handler.codec.mqtt.MqttQoS;
import org.awaitility.Awaitility ;
import org.junit.Assert ;
import org.junit.Test ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.test.context.TestPropertySource ;
import org.thingsboard.common.util.JacksonUtil ;
import org.thingsboard.server.common.data.Customer ;
import org.thingsboard.server.common.data.DataConstants ;
import org.thingsboard.server.common.data.Device ;
import org.thingsboard.server.common.data.DeviceInfo ;
import org.thingsboard.server.common.data.EntityType ;
import org.thingsboard.server.common.data.OtaPackageInfo ;
import org.thingsboard.server.common.data.StringUtils ;
@ -46,11 +48,14 @@ import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.ota.OtaPackageType ;
import org.thingsboard.server.common.data.page.PageData ;
import org.thingsboard.server.common.data.page.PageLink ;
import org.thingsboard.server.common.data.relation.EntityRelation ;
import org.thingsboard.server.common.data.relation.RelationTypeGroup ;
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.msg.session.FeatureType ;
import org.thingsboard.server.common.transport.adaptor.JsonConverter ;
import org.thingsboard.server.dao.relation.RelationService ;
import org.thingsboard.server.gen.edge.v1.AttributesRequestMsg ;
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg ;
import org.thingsboard.server.gen.edge.v1.DeviceCredentialsUpdateMsg ;
@ -378,18 +383,18 @@ abstract public class BaseDeviceEdgeTest extends AbstractEdgeTest {
sendAttributesRequestAndVerify ( device , DataConstants . SHARED_SCOPE , "{\"key2\":\"value2\"}" ,
"key2" , "value2" ) ;
doDelete ( "/api/plugins/telemetry/DEVICE/" + device . getUuidId ( ) + "/" + DataConstants . SERVER_SCOPE , "keys" , "key1, inactivityTimeout" ) ;
doDelete ( "/api/plugins/telemetry/DEVICE/" + device . getUuidId ( ) + "/" + DataConstants . SERVER_SCOPE , "keys" , "key1, inactivityTimeout" ) ;
doDelete ( "/api/plugins/telemetry/DEVICE/" + device . getUuidId ( ) + "/" + DataConstants . SHARED_SCOPE , "keys" , "key2" ) ;
}
@Test
public void testSendDeleteDeviceOnEdgeToCloud ( ) throws Exception {
Device device = saveDeviceOnCloudAndVerifyDeliveryToEdge ( ) ;
Device save dD evice = saveDeviceOnCloudAndVerifyDeliveryToEdge ( ) ;
UplinkMsg . Builder upLinkMsgBuilder = UplinkMsg . newBuilder ( ) ;
DeviceUpdateMsg . Builder deviceDeleteMsgBuilder = DeviceUpdateMsg . newBuilder ( ) ;
deviceDeleteMsgBuilder . setMsgType ( UpdateMsgType . ENTITY_DELETED_RPC_MESSAGE ) ;
deviceDeleteMsgBuilder . setIdMSB ( device . getId ( ) . getId ( ) . getMostSignificantBits ( ) ) ;
deviceDeleteMsgBuilder . setIdLSB ( device . getId ( ) . getId ( ) . getLeastSignificantBits ( ) ) ;
deviceDeleteMsgBuilder . setIdMSB ( save dD evice. getId ( ) . getId ( ) . getMostSignificantBits ( ) ) ;
deviceDeleteMsgBuilder . setIdLSB ( save dD evice. getId ( ) . getId ( ) . getLeastSignificantBits ( ) ) ;
testAutoGeneratedCodeByProtobuf ( deviceDeleteMsgBuilder ) ;
upLinkMsgBuilder . addDeviceUpdateMsg ( deviceDeleteMsgBuilder . build ( ) ) ;
@ -398,12 +403,12 @@ abstract public class BaseDeviceEdgeTest extends AbstractEdgeTest {
edgeImitator . expectResponsesAmount ( 1 ) ;
edgeImitator . sendUplinkMsg ( upLinkMsgBuilder . build ( ) ) ;
Assert . assertTrue ( edgeImitator . waitForResponses ( ) ) ;
device = doGet ( "/api/device/" + device . getUuidId ( ) , Device . class ) ;
Assert . assertNotNull ( device ) ;
List < Device > edgeDevices = doGetTypedWithPageLink ( "/api/edge/" + edge . getUuidId ( ) + "/devices?" ,
new TypeReference < PageData < Device > > ( ) {
DeviceInfo deviceInfo = doGet ( "/api/device/info/ " + save dD evice. getUuidId ( ) , DeviceInfo . class ) ;
Assert . assertNotNull ( deviceInfo ) ;
List < DeviceInfo > edgeDevices = doGetTypedWithPageLink ( "/api/edge/" + edge . getUuidId ( ) + "/devices?" ,
new TypeReference < PageData < DeviceInfo > > ( ) {
} , new PageLink ( 100 ) ) . getData ( ) ;
Assert . assertFalse ( edgeDevices . contains ( device ) ) ;
Assert . assertFalse ( edgeDevices . contains ( deviceInfo ) ) ;
}
@Test
@ -455,7 +460,8 @@ abstract public class BaseDeviceEdgeTest extends AbstractEdgeTest {
Assert . assertEquals ( timeseriesValue , timeseries . get ( timeseriesKey ) . get ( 0 ) . get ( "value" ) ) ;
String attributeValuesUrl = "/api/plugins/telemetry/DEVICE/" + device . getId ( ) + "/values/attributes/" + DataConstants . SERVER_SCOPE ;
List < Map < String , String > > attributes = doGetAsyncTyped ( attributeValuesUrl , new TypeReference < > ( ) { } ) ;
List < Map < String , String > > attributes = doGetAsyncTyped ( attributeValuesUrl , new TypeReference < > ( ) {
} ) ;
Assert . assertEquals ( 3 , attributes . size ( ) ) ;
@ -599,7 +605,8 @@ abstract public class BaseDeviceEdgeTest extends AbstractEdgeTest {
. atMost ( 10 , TimeUnit . SECONDS )
. until ( ( ) - > {
String urlTemplate = "/api/plugins/telemetry/DEVICE/" + device . getId ( ) + "/keys/attributes/" + scope ;
List < String > actualKeys = doGetAsyncTyped ( urlTemplate , new TypeReference < > ( ) { } ) ;
List < String > actualKeys = doGetAsyncTyped ( urlTemplate , new TypeReference < > ( ) {
} ) ;
return actualKeys ! = null & & ! actualKeys . isEmpty ( ) & & actualKeys . contains ( expectedKey ) ;
} ) ;
@ -656,7 +663,8 @@ abstract public class BaseDeviceEdgeTest extends AbstractEdgeTest {
private Map < String , List < Map < String , String > > > loadDeviceTimeseries ( Device device , String timeseriesKey ) throws Exception {
return doGetAsyncTyped ( "/api/plugins/telemetry/DEVICE/" + device . getUuidId ( ) + "/values/timeseries?keys=" + timeseriesKey ,
new TypeReference < > ( ) { } ) ;
new TypeReference < > ( ) {
} ) ;
}
@Test
@ -713,7 +721,8 @@ abstract public class BaseDeviceEdgeTest extends AbstractEdgeTest {
. atMost ( 10 , TimeUnit . SECONDS )
. until ( ( ) - > {
String urlTemplate = "/api/plugins/telemetry/DEVICE/" + device . getId ( ) + "/keys/timeseries" ;
List < String > actualKeys = doGetAsyncTyped ( urlTemplate , new TypeReference < > ( ) { } ) ;
List < String > actualKeys = doGetAsyncTyped ( urlTemplate , new TypeReference < > ( ) {
} ) ;
return actualKeys ! = null & & ! actualKeys . isEmpty ( ) & & actualKeys . contains ( "temperature" ) ;
} ) ;