Search in sources :

Example 1 with AbstractMessage

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

the class CompatibilityTest method testGetAllFields.

public void testGetAllFields() throws Exception {
    AbstractMessage data = TypicalData.newBuilder().setMyInt(1).addRepeatedInt32(2).setExtension(Typical.myExtension, TypicalDataMessage.getDefaultInstance()).setExtension(Typical.myPrimitiveExtension, 3).build();
    Map<FieldDescriptor, Object> allFields = data.getAllFields();
    assertEquals(4, allFields.size());
    assertNotNull(allFields.get(Typical.myExtension.getDescriptor()));
    assertEquals(4, data.toBuilder().getAllFields().size());
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    FieldDescriptor intField = descriptor.findFieldByNumber(1);
    assertEquals(1, allFields.get(intField));
    assertEquals(3, allFields.get(Typical.myPrimitiveExtension.getDescriptor()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 2 with AbstractMessage

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

the class BaseEdgeTest method testRelations.

@Test
public void testRelations() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    Device device = findDeviceByName("Edge Device 1");
    Asset asset = findAssetByName("Edge Asset 1");
    EntityRelation relation = new EntityRelation();
    relation.setType("test");
    relation.setFrom(device.getId());
    relation.setTo(asset.getId());
    relation.setTypeGroup(RelationTypeGroup.COMMON);
    doPost("/api/relation", relation);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof RelationUpdateMsg);
    RelationUpdateMsg relationUpdateMsg = (RelationUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, relationUpdateMsg.getMsgType());
    Assert.assertEquals(relationUpdateMsg.getType(), relation.getType());
    Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getFromIdLSB(), relation.getFrom().getId().getLeastSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
    Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
    Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name());
    // 2
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/relation?" + "fromId=" + relation.getFrom().getId().toString() + "&fromType=" + relation.getFrom().getEntityType().name() + "&relationType=" + relation.getType() + "&relationTypeGroup=" + relation.getTypeGroup().name() + "&toId=" + relation.getTo().getId().toString() + "&toType=" + relation.getTo().getEntityType().name()).andExpect(status().isOk());
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof RelationUpdateMsg);
    relationUpdateMsg = (RelationUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, relationUpdateMsg.getMsgType());
    Assert.assertEquals(relationUpdateMsg.getType(), relation.getType());
    Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getFromIdLSB(), relation.getFrom().getId().getLeastSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
    Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
    Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
    Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name());
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) AbstractMessage(com.google.protobuf.AbstractMessage) Device(org.thingsboard.server.common.data.Device) Asset(org.thingsboard.server.common.data.asset.Asset) RelationUpdateMsg(org.thingsboard.server.gen.edge.v1.RelationUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Example 3 with AbstractMessage

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

the class BaseEdgeTest method testTimeseries.

@Test
public void testTimeseries() throws Exception {
    edgeImitator.expectMessageAmount(1);
    Device device = findDeviceByName("Edge Device 1");
    String timeseriesData = "{\"data\":{\"temperature\":25},\"ts\":" + System.currentTimeMillis() + "}";
    JsonNode timeseriesEntityData = mapper.readTree(timeseriesData);
    EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.TIMESERIES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, timeseriesEntityData);
    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(latestEntityDataMsg.getEntityIdMSB(), device.getUuidId().getMostSignificantBits());
    Assert.assertEquals(latestEntityDataMsg.getEntityIdLSB(), device.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(latestEntityDataMsg.getEntityType(), device.getId().getEntityType().name());
    Assert.assertTrue(latestEntityDataMsg.hasPostTelemetryMsg());
    TransportProtos.PostTelemetryMsg postTelemetryMsg = latestEntityDataMsg.getPostTelemetryMsg();
    Assert.assertEquals(1, postTelemetryMsg.getTsKvListCount());
    TransportProtos.TsKvListProto tsKvListProto = postTelemetryMsg.getTsKvList(0);
    Assert.assertEquals(timeseriesEntityData.get("ts").asLong(), tsKvListProto.getTs());
    Assert.assertEquals(1, tsKvListProto.getKvCount());
    TransportProtos.KeyValueProto keyValueProto = tsKvListProto.getKv(0);
    Assert.assertEquals("temperature", keyValueProto.getKey());
    Assert.assertEquals(25, keyValueProto.getLongV());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) EntityDataProto(org.thingsboard.server.gen.edge.v1.EntityDataProto) Device(org.thingsboard.server.common.data.Device) JsonNode(com.fasterxml.jackson.databind.JsonNode) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Example 4 with AbstractMessage

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

the class BaseEdgeTest method testSendDeviceToCloudWithNameThatAlreadyExistsOnCloud.

@Test
public void testSendDeviceToCloudWithNameThatAlreadyExistsOnCloud() throws Exception {
    String deviceOnCloudName = RandomStringUtils.randomAlphanumeric(15);
    Device deviceOnCloud = saveDevice(deviceOnCloudName, "Default");
    UUID uuid = Uuids.timeBased();
    UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
    DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder();
    deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits());
    deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits());
    deviceUpdateMsgBuilder.setName(deviceOnCloudName);
    deviceUpdateMsgBuilder.setType("test");
    deviceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE);
    testAutoGeneratedCodeByProtobuf(deviceUpdateMsgBuilder);
    uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build());
    edgeImitator.expectResponsesAmount(1);
    edgeImitator.expectMessageAmount(2);
    testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
    edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
    Assert.assertTrue(edgeImitator.waitForResponses());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getMessageFromTail(2);
    Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg);
    DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage;
    Assert.assertNotEquals(deviceOnCloudName, latestDeviceUpdateMsg.getName());
    Assert.assertEquals(deviceOnCloudName, latestDeviceUpdateMsg.getConflictName());
    UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB());
    Assert.assertNotEquals(deviceOnCloud.getId().getId(), newDeviceId);
    Device device = doGet("/api/device/" + newDeviceId, Device.class);
    Assert.assertNotNull(device);
    Assert.assertNotEquals(deviceOnCloudName, device.getName());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DeviceCredentialsRequestMsg);
    DeviceCredentialsRequestMsg latestDeviceCredentialsRequestMsg = (DeviceCredentialsRequestMsg) latestMessage;
    Assert.assertEquals(uuid.getMostSignificantBits(), latestDeviceCredentialsRequestMsg.getDeviceIdMSB());
    Assert.assertEquals(uuid.getLeastSignificantBits(), latestDeviceCredentialsRequestMsg.getDeviceIdLSB());
    newDeviceId = new UUID(latestDeviceCredentialsRequestMsg.getDeviceIdMSB(), latestDeviceCredentialsRequestMsg.getDeviceIdLSB());
    device = doGet("/api/device/" + newDeviceId, Device.class);
    Assert.assertNotNull(device);
    Assert.assertNotEquals(deviceOnCloudName, device.getName());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) DeviceCredentialsRequestMsg(org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg) Device(org.thingsboard.server.common.data.Device) UplinkMsg(org.thingsboard.server.gen.edge.v1.UplinkMsg) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) UUID(java.util.UUID) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Example 5 with AbstractMessage

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

the class BaseEdgeTest method saveDeviceOnCloudAndVerifyDeliveryToEdge.

// Utility methods
private Device saveDeviceOnCloudAndVerifyDeliveryToEdge() throws Exception {
    edgeImitator.expectMessageAmount(1);
    Device savedDevice = saveDevice(RandomStringUtils.randomAlphanumeric(15), "Default");
    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;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, deviceUpdateMsg.getMsgType());
    Assert.assertEquals(deviceUpdateMsg.getIdMSB(), savedDevice.getUuidId().getMostSignificantBits());
    Assert.assertEquals(deviceUpdateMsg.getIdLSB(), savedDevice.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(deviceUpdateMsg.getName(), savedDevice.getName());
    Assert.assertEquals(deviceUpdateMsg.getType(), savedDevice.getType());
    return savedDevice;
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Device(org.thingsboard.server.common.data.Device) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg)

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