Fixed RPC call edge test

This commit is contained in:
Volodymyr Babak 2020-12-03 11:11:11 +02:00
parent 075bc7a40c
commit 144891b393

View File

@ -31,7 +31,6 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Dashboard; import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.DataConstants; import org.thingsboard.server.common.data.DataConstants;
@ -180,7 +179,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
private Device findDeviceByName(String deviceName) throws Exception { private Device findDeviceByName(String deviceName) throws Exception {
List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); new TypeReference<TimePageData<Device>>() {
}, new TextPageLink(100)).getData();
Optional<Device> foundDevice = edgeDevices.stream().filter(d -> d.getName().equals(deviceName)).findAny(); Optional<Device> foundDevice = edgeDevices.stream().filter(d -> d.getName().equals(deviceName)).findAny();
Assert.assertTrue(foundDevice.isPresent()); Assert.assertTrue(foundDevice.isPresent());
Device device = foundDevice.get(); Device device = foundDevice.get();
@ -190,7 +190,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
private Asset findAssetByName(String assetName) throws Exception { private Asset findAssetByName(String assetName) throws Exception {
List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?", List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?",
new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100)).getData(); new TypeReference<TimePageData<Asset>>() {
}, new TextPageLink(100)).getData();
Assert.assertEquals(1, edgeAssets.size()); Assert.assertEquals(1, edgeAssets.size());
Asset asset = edgeAssets.get(0); Asset asset = edgeAssets.get(0);
@ -215,20 +216,14 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
private void testRpcCall() throws Exception { private void testRpcCall() throws Exception {
Device device = findDeviceByName("Edge Device 1"); Device device = findDeviceByName("Edge Device 1");
RuleEngineDeviceRpcRequest request = RuleEngineDeviceRpcRequest.builder() ObjectNode body = mapper.createObjectNode();
.oneway(true) body.put("requestId", new Random().nextInt());
.method("test_method") body.put("requestUUID", UUIDs.timeBased().toString());
.body("{\"param1\":\"value1\"}") body.put("oneway", false);
.tenantId(device.getTenantId()) body.put("expirationTime", System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10));
.deviceId(device.getId()) body.put("method", "test_method");
.requestId(new Random().nextInt()) body.put("params", "{\"param1\":\"value1\"}");
.requestUUID(UUIDs.timeBased())
.originServiceId("originServiceId")
.expirationTime(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10))
.restApiCall(true)
.build();
JsonNode body = mapper.valueToTree(request);
EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.RPC_CALL, device.getId().getId(), EdgeEventType.DEVICE, body); EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.RPC_CALL, device.getId().getId(), EdgeEventType.DEVICE, body);
edgeImitator.expectMessageAmount(1); edgeImitator.expectMessageAmount(1);
edgeEventService.saveAsync(edgeEvent); edgeEventService.saveAsync(edgeEvent);
@ -260,7 +255,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
Device device = doGet("/api/device/" + deviceUUID.toString(), Device.class); Device device = doGet("/api/device/" + deviceUUID.toString(), Device.class);
Assert.assertNotNull(device); Assert.assertNotNull(device);
List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); new TypeReference<TimePageData<Device>>() {
}, new TextPageLink(100)).getData();
Assert.assertTrue(edgeDevices.contains(device)); Assert.assertTrue(edgeDevices.contains(device));
Optional<AssetUpdateMsg> optionalMsg2 = edgeImitator.findMessageByType(AssetUpdateMsg.class); Optional<AssetUpdateMsg> optionalMsg2 = edgeImitator.findMessageByType(AssetUpdateMsg.class);
@ -271,7 +267,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
Asset asset = doGet("/api/asset/" + assetUUID.toString(), Asset.class); Asset asset = doGet("/api/asset/" + assetUUID.toString(), Asset.class);
Assert.assertNotNull(asset); Assert.assertNotNull(asset);
List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?", List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?",
new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100)).getData(); new TypeReference<TimePageData<Asset>>() {
}, new TextPageLink(100)).getData();
Assert.assertTrue(edgeAssets.contains(asset)); Assert.assertTrue(edgeAssets.contains(asset));
testAutoGeneratedCodeByProtobuf(assetUpdateMsg); testAutoGeneratedCodeByProtobuf(assetUpdateMsg);
@ -284,7 +281,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
RuleChain ruleChain = doGet("/api/ruleChain/" + ruleChainUUID.toString(), RuleChain.class); RuleChain ruleChain = doGet("/api/ruleChain/" + ruleChainUUID.toString(), RuleChain.class);
Assert.assertNotNull(ruleChain); Assert.assertNotNull(ruleChain);
List<RuleChain> edgeRuleChains = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/ruleChains?", List<RuleChain> edgeRuleChains = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/ruleChains?",
new TypeReference<TimePageData<RuleChain>>() {}, new TextPageLink(100)).getData(); new TypeReference<TimePageData<RuleChain>>() {
}, new TextPageLink(100)).getData();
Assert.assertTrue(edgeRuleChains.contains(ruleChain)); Assert.assertTrue(edgeRuleChains.contains(ruleChain));
testAutoGeneratedCodeByProtobuf(ruleChainUpdateMsg); testAutoGeneratedCodeByProtobuf(ruleChainUpdateMsg);
@ -605,7 +603,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
Assert.assertEquals(relationUpdateMsg.getType(), relation.getType()); Assert.assertEquals(relationUpdateMsg.getType(), relation.getType());
Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits()); Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
Assert.assertEquals(relationUpdateMsg.getFromIdLSB(), relation.getFrom().getId().getLeastSignificantBits()); 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.getToEntityType(), relation.getTo().getEntityType().name());
Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits()); Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name()); Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name()); Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name());
@ -1063,7 +1062,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
List<AlarmInfo> alarms = doGetTypedWithPageLink("/api/alarm/{entityType}/{entityId}?", List<AlarmInfo> alarms = doGetTypedWithPageLink("/api/alarm/{entityType}/{entityId}?",
new TypeReference<TimePageData<AlarmInfo>>() {}, new TypeReference<TimePageData<AlarmInfo>>() {
},
new TextPageLink(100), device.getId().getEntityType().name(), device.getId().getId().toString()) new TextPageLink(100), device.getId().getEntityType().name(), device.getId().getId().toString())
.getData(); .getData();
Optional<AlarmInfo> foundAlarm = alarms.stream().filter(alarm -> alarm.getType().equals("alarm from edge")).findAny(); Optional<AlarmInfo> foundAlarm = alarms.stream().filter(alarm -> alarm.getType().equals("alarm from edge")).findAny();
@ -1076,7 +1076,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
private void sendRelation() throws Exception { private void sendRelation() throws Exception {
List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); new TypeReference<TimePageData<Device>>() {
}, new TextPageLink(100)).getData();
Optional<Device> foundDevice1 = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 1")).findAny(); Optional<Device> foundDevice1 = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 1")).findAny();
Assert.assertTrue(foundDevice1.isPresent()); Assert.assertTrue(foundDevice1.isPresent());
Device device1 = foundDevice1.get(); Device device1 = foundDevice1.get();
@ -1116,7 +1117,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
private void sendTelemetry() throws Exception { private void sendTelemetry() throws Exception {
List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); new TypeReference<TimePageData<Device>>() {
}, new TextPageLink(100)).getData();
Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny(); Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny();
Assert.assertTrue(foundDevice.isPresent()); Assert.assertTrue(foundDevice.isPresent());
Device device = foundDevice.get(); Device device = foundDevice.get();
@ -1340,7 +1342,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
private void sendDeleteDeviceOnEdge() throws Exception { private void sendDeleteDeviceOnEdge() throws Exception {
List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); new TypeReference<TimePageData<Device>>() {
}, new TextPageLink(100)).getData();
Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny(); Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny();
Assert.assertTrue(foundDevice.isPresent()); Assert.assertTrue(foundDevice.isPresent());
Device device = foundDevice.get(); Device device = foundDevice.get();