Search in sources :

Example 1 with DeviceCredentialsRequestMsg

use of org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg 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 2 with DeviceCredentialsRequestMsg

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

the class EntityEdgeProcessor method processCredentialsRequestMessageToEdge.

public DownlinkMsg processCredentialsRequestMessageToEdge(EdgeEvent edgeEvent) {
    DownlinkMsg downlinkMsg = null;
    if (EdgeEventType.DEVICE.equals(edgeEvent.getType())) {
        DeviceId deviceId = new DeviceId(edgeEvent.getEntityId());
        DeviceCredentialsRequestMsg deviceCredentialsRequestMsg = DeviceCredentialsRequestMsg.newBuilder().setDeviceIdMSB(deviceId.getId().getMostSignificantBits()).setDeviceIdLSB(deviceId.getId().getLeastSignificantBits()).build();
        DownlinkMsg.Builder builder = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceCredentialsRequestMsg(deviceCredentialsRequestMsg);
        downlinkMsg = builder.build();
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) DeviceCredentialsRequestMsg(org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg) DeviceId(org.thingsboard.server.common.data.id.DeviceId)

Example 3 with DeviceCredentialsRequestMsg

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

the class BaseEdgeTest method testSendDeviceToCloud.

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

Aggregations

DeviceCredentialsRequestMsg (org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 Device (org.thingsboard.server.common.data.Device)2 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)2 DeviceUpdateMsg (org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg)2 UplinkMsg (org.thingsboard.server.gen.edge.v1.UplinkMsg)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)1