Search in sources :

Example 6 with DeviceUpdateMsg

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

the class BaseEdgeTest method testDevices.

@Test
public void testDevices() throws Exception {
    // 1
    Device savedDevice = saveDeviceOnCloudAndVerifyDeliveryToEdge();
    // 2
    edgeImitator.expectMessageAmount(1);
    doDelete("/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_DELETED_RPC_MESSAGE, deviceUpdateMsg.getMsgType());
    Assert.assertEquals(deviceUpdateMsg.getIdMSB(), savedDevice.getUuidId().getMostSignificantBits());
    Assert.assertEquals(deviceUpdateMsg.getIdLSB(), savedDevice.getUuidId().getLeastSignificantBits());
    // 3
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/device/" + savedDevice.getUuidId()).andExpect(status().isOk());
    // we should not get any message because device is not assigned to edge any more
    Assert.assertFalse(edgeImitator.waitForMessages(1));
    // 4
    edgeImitator.expectMessageAmount(1);
    savedDevice = saveDevice("Edge Device 3", "Default");
    doPost("/api/edge/" + edge.getUuidId() + "/device/" + savedDevice.getUuidId(), Device.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof 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());
    // 5
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/device/" + savedDevice.getUuidId()).andExpect(status().isOk());
    // in this case we should get messages because device was assigned to edge
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg);
    deviceUpdateMsg = (DeviceUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, deviceUpdateMsg.getMsgType());
    Assert.assertEquals(deviceUpdateMsg.getIdMSB(), savedDevice.getUuidId().getMostSignificantBits());
    Assert.assertEquals(deviceUpdateMsg.getIdLSB(), savedDevice.getUuidId().getLeastSignificantBits());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Device(org.thingsboard.server.common.data.Device) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

Device (org.thingsboard.server.common.data.Device)6 DeviceUpdateMsg (org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg)6 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)3 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)3 UUID (java.util.UUID)2 CustomerId (org.thingsboard.server.common.data.id.CustomerId)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)2 DeviceCredentialsRequestMsg (org.thingsboard.server.gen.edge.v1.DeviceCredentialsRequestMsg)2 DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)2 UplinkMsg (org.thingsboard.server.gen.edge.v1.UplinkMsg)2 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 JsonObject (com.google.gson.JsonObject)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 MessageLite (com.google.protobuf.MessageLite)1