Search in sources :

Example 6 with EntityDataProto

use of org.thingsboard.server.gen.edge.v1.EntityDataProto in project thingsboard by thingsboard.

the class BaseEdgeTest method testAttributesDeleteMsg.

private void testAttributesDeleteMsg(Device device) throws JsonProcessingException, InterruptedException {
    String deleteAttributesData = "{\"scope\":\"SERVER_SCOPE\",\"keys\":[\"key1\",\"key2\"]}";
    JsonNode deleteAttributesEntityData = mapper.readTree(deleteAttributesData);
    EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_DELETED, device.getId().getId(), EdgeEventType.DEVICE, deleteAttributesEntityData);
    edgeImitator.expectMessageAmount(1);
    edgeEventService.save(edgeEvent);
    clusterService.onEdgeEventUpdate(tenantId, edge.getId());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof EntityDataProto);
    EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
    Assert.assertEquals(device.getUuidId().getMostSignificantBits(), latestEntityDataMsg.getEntityIdMSB());
    Assert.assertEquals(device.getUuidId().getLeastSignificantBits(), latestEntityDataMsg.getEntityIdLSB());
    Assert.assertEquals(device.getId().getEntityType().name(), latestEntityDataMsg.getEntityType());
    Assert.assertTrue(latestEntityDataMsg.hasAttributeDeleteMsg());
    AttributeDeleteMsg attributeDeleteMsg = latestEntityDataMsg.getAttributeDeleteMsg();
    Assert.assertEquals(attributeDeleteMsg.getScope(), deleteAttributesEntityData.get("scope").asText());
    Assert.assertEquals(2, attributeDeleteMsg.getAttributeNamesCount());
    Assert.assertEquals("key1", attributeDeleteMsg.getAttributeNames(0));
    Assert.assertEquals("key2", attributeDeleteMsg.getAttributeNames(1));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) EntityDataProto(org.thingsboard.server.gen.edge.v1.EntityDataProto) AttributeDeleteMsg(org.thingsboard.server.gen.edge.v1.AttributeDeleteMsg) JsonNode(com.fasterxml.jackson.databind.JsonNode) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 7 with EntityDataProto

use of org.thingsboard.server.gen.edge.v1.EntityDataProto in project thingsboard by thingsboard.

the class BaseEdgeTest method testAttributesUpdatedMsg.

private void testAttributesUpdatedMsg(Device device) throws JsonProcessingException, InterruptedException {
    String attributesData = "{\"scope\":\"SERVER_SCOPE\",\"kv\":{\"key1\":\"value1\"}}";
    JsonNode attributesEntityData = mapper.readTree(attributesData);
    EdgeEvent edgeEvent1 = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData);
    edgeImitator.expectMessageAmount(1);
    edgeEventService.save(edgeEvent1);
    clusterService.onEdgeEventUpdate(tenantId, edge.getId());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof EntityDataProto);
    EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
    Assert.assertEquals(device.getUuidId().getMostSignificantBits(), latestEntityDataMsg.getEntityIdMSB());
    Assert.assertEquals(device.getUuidId().getLeastSignificantBits(), latestEntityDataMsg.getEntityIdLSB());
    Assert.assertEquals(device.getId().getEntityType().name(), latestEntityDataMsg.getEntityType());
    Assert.assertEquals("SERVER_SCOPE", latestEntityDataMsg.getPostAttributeScope());
    Assert.assertTrue(latestEntityDataMsg.hasAttributesUpdatedMsg());
    TransportProtos.PostAttributeMsg attributesUpdatedMsg = latestEntityDataMsg.getAttributesUpdatedMsg();
    Assert.assertEquals(1, attributesUpdatedMsg.getKvCount());
    TransportProtos.KeyValueProto keyValueProto = attributesUpdatedMsg.getKv(0);
    Assert.assertEquals("key1", keyValueProto.getKey());
    Assert.assertEquals("value1", keyValueProto.getStringV());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) EntityDataProto(org.thingsboard.server.gen.edge.v1.EntityDataProto) JsonNode(com.fasterxml.jackson.databind.JsonNode) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 8 with EntityDataProto

use of org.thingsboard.server.gen.edge.v1.EntityDataProto in project thingsboard by thingsboard.

the class BaseEdgeTest method isIdxExistsInTheDownlinkList.

private boolean isIdxExistsInTheDownlinkList(int idx, List<EntityDataProto> allTelemetryMsgs) {
    for (EntityDataProto proto : allTelemetryMsgs) {
        TransportProtos.PostTelemetryMsg postTelemetryMsg = proto.getPostTelemetryMsg();
        Assert.assertEquals(1, postTelemetryMsg.getTsKvListCount());
        TransportProtos.TsKvListProto tsKvListProto = postTelemetryMsg.getTsKvList(0);
        Assert.assertEquals(1, tsKvListProto.getKvCount());
        TransportProtos.KeyValueProto keyValueProto = tsKvListProto.getKv(0);
        Assert.assertEquals("idx", keyValueProto.getKey());
        if (keyValueProto.getLongV() == idx) {
            return true;
        }
    }
    return false;
}
Also used : EntityDataProto(org.thingsboard.server.gen.edge.v1.EntityDataProto) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos)

Aggregations

EntityDataProto (org.thingsboard.server.gen.edge.v1.EntityDataProto)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)6 AbstractMessage (com.google.protobuf.AbstractMessage)5 EdgeEvent (org.thingsboard.server.common.data.edge.EdgeEvent)5 Test (org.junit.Test)2 Device (org.thingsboard.server.common.data.Device)2 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)2 AttributeDeleteMsg (org.thingsboard.server.gen.edge.v1.AttributeDeleteMsg)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 TypeToken (com.google.gson.reflect.TypeToken)1 AttributesRequestMsg (org.thingsboard.server.gen.edge.v1.AttributesRequestMsg)1 UplinkMsg (org.thingsboard.server.gen.edge.v1.UplinkMsg)1