Search in sources :

Example 16 with AbstractMessage

use of com.google.protobuf.AbstractMessage in project thingsboard by thingsboard.

the class BaseEdgeTest method testRuleChainMetadataRequestMsg.

private void testRuleChainMetadataRequestMsg(RuleChainId ruleChainId) throws Exception {
    RuleChainMetadataRequestMsg.Builder ruleChainMetadataRequestMsgBuilder = RuleChainMetadataRequestMsg.newBuilder().setRuleChainIdMSB(ruleChainId.getId().getMostSignificantBits()).setRuleChainIdLSB(ruleChainId.getId().getLeastSignificantBits());
    testAutoGeneratedCodeByProtobuf(ruleChainMetadataRequestMsgBuilder);
    UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder().addRuleChainMetadataRequestMsg(ruleChainMetadataRequestMsgBuilder.build());
    testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
    edgeImitator.expectResponsesAmount(1);
    edgeImitator.expectMessageAmount(1);
    edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
    Assert.assertTrue(edgeImitator.waitForResponses());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof RuleChainMetadataUpdateMsg);
    RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = (RuleChainMetadataUpdateMsg) latestMessage;
    RuleChainId receivedRuleChainId = new RuleChainId(new UUID(ruleChainMetadataUpdateMsg.getRuleChainIdMSB(), ruleChainMetadataUpdateMsg.getRuleChainIdLSB()));
    Assert.assertEquals(ruleChainId, receivedRuleChainId);
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) RuleChainMetadataUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg) UplinkMsg(org.thingsboard.server.gen.edge.v1.UplinkMsg) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) UUID(java.util.UUID) RuleChainMetadataRequestMsg(org.thingsboard.server.gen.edge.v1.RuleChainMetadataRequestMsg)

Example 17 with AbstractMessage

use of com.google.protobuf.AbstractMessage 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 18 with AbstractMessage

use of com.google.protobuf.AbstractMessage in project thingsboard by thingsboard.

the class BaseEdgeTest method testDashboards.

@Test
public void testDashboards() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    Dashboard dashboard = new Dashboard();
    dashboard.setTitle("Edge Test Dashboard");
    Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
    doPost("/api/edge/" + edge.getUuidId() + "/dashboard/" + savedDashboard.getUuidId(), Dashboard.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DashboardUpdateMsg);
    DashboardUpdateMsg dashboardUpdateMsg = (DashboardUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, dashboardUpdateMsg.getMsgType());
    Assert.assertEquals(dashboardUpdateMsg.getIdMSB(), savedDashboard.getUuidId().getMostSignificantBits());
    Assert.assertEquals(dashboardUpdateMsg.getIdLSB(), savedDashboard.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(dashboardUpdateMsg.getTitle(), savedDashboard.getName());
    testAutoGeneratedCodeByProtobuf(dashboardUpdateMsg);
    // 2
    edgeImitator.expectMessageAmount(1);
    savedDashboard.setTitle("Updated Edge Test Dashboard");
    doPost("/api/dashboard", savedDashboard, Dashboard.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DashboardUpdateMsg);
    dashboardUpdateMsg = (DashboardUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE, dashboardUpdateMsg.getMsgType());
    Assert.assertEquals(dashboardUpdateMsg.getTitle(), savedDashboard.getName());
    // 3
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/edge/" + edge.getUuidId() + "/dashboard/" + savedDashboard.getUuidId(), Dashboard.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DashboardUpdateMsg);
    dashboardUpdateMsg = (DashboardUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, dashboardUpdateMsg.getMsgType());
    Assert.assertEquals(dashboardUpdateMsg.getIdMSB(), savedDashboard.getUuidId().getMostSignificantBits());
    Assert.assertEquals(dashboardUpdateMsg.getIdLSB(), savedDashboard.getUuidId().getLeastSignificantBits());
    // 4
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/dashboard/" + savedDashboard.getUuidId()).andExpect(status().isOk());
    Assert.assertFalse(edgeImitator.waitForMessages(1));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Dashboard(org.thingsboard.server.common.data.Dashboard) DashboardUpdateMsg(org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Example 19 with AbstractMessage

use of com.google.protobuf.AbstractMessage 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 20 with AbstractMessage

use of com.google.protobuf.AbstractMessage in project thingsboard by thingsboard.

the class BaseEdgeTest method testWidgetsBundleAndWidgetType.

@Test
public void testWidgetsBundleAndWidgetType() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTitle("Test Widget Bundle");
    WidgetsBundle savedWidgetsBundle = doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof WidgetsBundleUpdateMsg);
    WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = (WidgetsBundleUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, widgetsBundleUpdateMsg.getMsgType());
    Assert.assertEquals(widgetsBundleUpdateMsg.getIdMSB(), savedWidgetsBundle.getUuidId().getMostSignificantBits());
    Assert.assertEquals(widgetsBundleUpdateMsg.getIdLSB(), savedWidgetsBundle.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(widgetsBundleUpdateMsg.getAlias(), savedWidgetsBundle.getAlias());
    Assert.assertEquals(widgetsBundleUpdateMsg.getTitle(), savedWidgetsBundle.getTitle());
    testAutoGeneratedCodeByProtobuf(widgetsBundleUpdateMsg);
    // 2
    edgeImitator.expectMessageAmount(1);
    WidgetType widgetType = new WidgetType();
    widgetType.setName("Test Widget Type");
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    ObjectNode descriptor = mapper.createObjectNode();
    descriptor.put("key", "value");
    widgetType.setDescriptor(descriptor);
    WidgetType savedWidgetType = doPost("/api/widgetType", widgetType, WidgetType.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof WidgetTypeUpdateMsg);
    WidgetTypeUpdateMsg widgetTypeUpdateMsg = (WidgetTypeUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, widgetTypeUpdateMsg.getMsgType());
    Assert.assertEquals(widgetTypeUpdateMsg.getIdMSB(), savedWidgetType.getUuidId().getMostSignificantBits());
    Assert.assertEquals(widgetTypeUpdateMsg.getIdLSB(), savedWidgetType.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(widgetTypeUpdateMsg.getAlias(), savedWidgetType.getAlias());
    Assert.assertEquals(widgetTypeUpdateMsg.getName(), savedWidgetType.getName());
    Assert.assertEquals(JacksonUtil.toJsonNode(widgetTypeUpdateMsg.getDescriptorJson()), savedWidgetType.getDescriptor());
    // 3
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/widgetType/" + savedWidgetType.getUuidId()).andExpect(status().isOk());
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof WidgetTypeUpdateMsg);
    widgetTypeUpdateMsg = (WidgetTypeUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, widgetTypeUpdateMsg.getMsgType());
    Assert.assertEquals(widgetTypeUpdateMsg.getIdMSB(), savedWidgetType.getUuidId().getMostSignificantBits());
    Assert.assertEquals(widgetTypeUpdateMsg.getIdLSB(), savedWidgetType.getUuidId().getLeastSignificantBits());
    // 4
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/widgetsBundle/" + savedWidgetsBundle.getUuidId()).andExpect(status().isOk());
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof WidgetsBundleUpdateMsg);
    widgetsBundleUpdateMsg = (WidgetsBundleUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, widgetsBundleUpdateMsg.getMsgType());
    Assert.assertEquals(widgetsBundleUpdateMsg.getIdMSB(), savedWidgetsBundle.getUuidId().getMostSignificantBits());
    Assert.assertEquals(widgetsBundleUpdateMsg.getIdLSB(), savedWidgetsBundle.getUuidId().getLeastSignificantBits());
}
Also used : WidgetTypeUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg) AbstractMessage(com.google.protobuf.AbstractMessage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundleUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)27 Test (org.junit.Test)17 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)17 Device (org.thingsboard.server.common.data.Device)11 UplinkMsg (org.thingsboard.server.gen.edge.v1.UplinkMsg)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 EdgeEvent (org.thingsboard.server.common.data.edge.EdgeEvent)5 EntityDataProto (org.thingsboard.server.gen.edge.v1.EntityDataProto)5 UUID (java.util.UUID)4 DeviceUpdateMsg (org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg)4 Asset (org.thingsboard.server.common.data.asset.Asset)3 DeviceCredentialsRequestMsg (org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg)3 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 RuleChainId (org.thingsboard.server.common.data.id.RuleChainId)2 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)2 EntityViewUpdateMsg (org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg)2 CodedOutputStream (com.google.protobuf.CodedOutputStream)1 Descriptor (com.google.protobuf.Descriptors.Descriptor)1 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)1