|
|
|
@ -17,6 +17,7 @@ package org.thingsboard.server.edge; |
|
|
|
|
|
|
|
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
|
import com.google.protobuf.AbstractMessage; |
|
|
|
import com.google.protobuf.InvalidProtocolBufferException; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
@ -98,30 +99,23 @@ public class ResourceEdgeTest extends AbstractEdgeTest { |
|
|
|
public void testSendResourceToCloud() throws Exception { |
|
|
|
TbResource tbResource = createTbResource(); |
|
|
|
UUID uuid = Uuids.timeBased(); |
|
|
|
UplinkMsg uplinkMsg = getUplinkMsg(uuid, tbResource, UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE); |
|
|
|
|
|
|
|
UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder(); |
|
|
|
ResourceUpdateMsg.Builder resourceUpdateMsgBuilder = ResourceUpdateMsg.newBuilder(); |
|
|
|
resourceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits()); |
|
|
|
resourceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits()); |
|
|
|
resourceUpdateMsgBuilder.setEntity(JacksonUtil.toString(tbResource)); |
|
|
|
resourceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE); |
|
|
|
testAutoGeneratedCodeByProtobuf(resourceUpdateMsgBuilder); |
|
|
|
uplinkMsgBuilder.addResourceUpdateMsg(resourceUpdateMsgBuilder.build()); |
|
|
|
checkResourceOnCloud(uplinkMsg, uuid, tbResource.getTitle()); |
|
|
|
} |
|
|
|
|
|
|
|
testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder); |
|
|
|
@Test |
|
|
|
public void testUpdateResourceTitleOnCloud() throws Exception { |
|
|
|
TbResource tbResource = createTbResource(); |
|
|
|
UUID uuid = Uuids.timeBased(); |
|
|
|
UplinkMsg uplinkMsg = getUplinkMsg(uuid, tbResource, UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE); |
|
|
|
|
|
|
|
edgeImitator.expectResponsesAmount(1); |
|
|
|
edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build()); |
|
|
|
checkResourceOnCloud(uplinkMsg, uuid, tbResource.getTitle()); |
|
|
|
|
|
|
|
Assert.assertTrue(edgeImitator.waitForResponses()); |
|
|
|
tbResource.setTitle("Updated Edge Test Resource"); |
|
|
|
UplinkMsg updatedUplinkMsg = getUplinkMsg(uuid, tbResource, UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE); |
|
|
|
|
|
|
|
UplinkResponseMsg latestResponseMsg = edgeImitator.getLatestResponseMsg(); |
|
|
|
Assert.assertTrue(latestResponseMsg.getSuccess()); |
|
|
|
|
|
|
|
TbResource tb = doGet("/api/resource/" + uuid, TbResource.class); |
|
|
|
Assert.assertNotNull(tb); |
|
|
|
Assert.assertEquals("Edge Test Resource", tb.getName()); |
|
|
|
Assert.assertEquals(TEST_DATA, tb.getEncodedData()); |
|
|
|
checkResourceOnCloud(updatedUplinkMsg, uuid, tbResource.getTitle()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -134,21 +128,12 @@ public class ResourceEdgeTest extends AbstractEdgeTest { |
|
|
|
|
|
|
|
UUID uuid = Uuids.timeBased(); |
|
|
|
|
|
|
|
UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder(); |
|
|
|
ResourceUpdateMsg.Builder resourceUpdateMsgBuilder = ResourceUpdateMsg.newBuilder(); |
|
|
|
resourceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits()); |
|
|
|
resourceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits()); |
|
|
|
resourceUpdateMsgBuilder.setEntity(JacksonUtil.toString(resource)); |
|
|
|
resourceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE); |
|
|
|
testAutoGeneratedCodeByProtobuf(resourceUpdateMsgBuilder); |
|
|
|
uplinkMsgBuilder.addResourceUpdateMsg(resourceUpdateMsgBuilder.build()); |
|
|
|
|
|
|
|
testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder); |
|
|
|
UplinkMsg uplinkMsg = getUplinkMsg(uuid, resource, UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE); |
|
|
|
|
|
|
|
edgeImitator.expectResponsesAmount(1); |
|
|
|
edgeImitator.expectMessageAmount(1); |
|
|
|
|
|
|
|
edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build()); |
|
|
|
edgeImitator.sendUplinkMsg(uplinkMsg); |
|
|
|
|
|
|
|
Assert.assertTrue(edgeImitator.waitForResponses()); |
|
|
|
Assert.assertTrue(edgeImitator.waitForMessages()); |
|
|
|
@ -177,4 +162,35 @@ public class ResourceEdgeTest extends AbstractEdgeTest { |
|
|
|
tbResource.setEncodedData(TEST_DATA); |
|
|
|
return tbResource; |
|
|
|
} |
|
|
|
|
|
|
|
private UplinkMsg getUplinkMsg(UUID uuid, TbResource tbResource, UpdateMsgType updateMsgType) throws InvalidProtocolBufferException { |
|
|
|
UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder(); |
|
|
|
ResourceUpdateMsg.Builder resourceUpdateMsgBuilder = ResourceUpdateMsg.newBuilder(); |
|
|
|
resourceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits()); |
|
|
|
resourceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits()); |
|
|
|
resourceUpdateMsgBuilder.setEntity(JacksonUtil.toString(tbResource)); |
|
|
|
resourceUpdateMsgBuilder.setMsgType(updateMsgType); |
|
|
|
testAutoGeneratedCodeByProtobuf(resourceUpdateMsgBuilder); |
|
|
|
uplinkMsgBuilder.addResourceUpdateMsg(resourceUpdateMsgBuilder.build()); |
|
|
|
|
|
|
|
testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder); |
|
|
|
|
|
|
|
return uplinkMsgBuilder.build(); |
|
|
|
} |
|
|
|
|
|
|
|
private void checkResourceOnCloud(UplinkMsg uplinkMsg, UUID uuid, String resourceTitle) throws Exception { |
|
|
|
edgeImitator.expectResponsesAmount(1); |
|
|
|
edgeImitator.sendUplinkMsg(uplinkMsg); |
|
|
|
|
|
|
|
Assert.assertTrue(edgeImitator.waitForResponses()); |
|
|
|
|
|
|
|
UplinkResponseMsg latestResponseMsg = edgeImitator.getLatestResponseMsg(); |
|
|
|
Assert.assertTrue(latestResponseMsg.getSuccess()); |
|
|
|
|
|
|
|
TbResource tb = doGet("/api/resource/" + uuid, TbResource.class); |
|
|
|
Assert.assertNotNull(tb); |
|
|
|
Assert.assertEquals(resourceTitle, tb.getName()); |
|
|
|
Assert.assertEquals(TEST_DATA, tb.getEncodedData()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|