Fixed RPC call edge test
This commit is contained in:
parent
075bc7a40c
commit
144891b393
@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ -31,7 +31,6 @@ import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.Dashboard;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
@ -180,7 +179,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
|
||||
private Device findDeviceByName(String deviceName) throws Exception {
|
||||
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();
|
||||
Assert.assertTrue(foundDevice.isPresent());
|
||||
Device device = foundDevice.get();
|
||||
@ -190,7 +190,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
|
||||
private Asset findAssetByName(String assetName) throws Exception {
|
||||
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());
|
||||
Asset asset = edgeAssets.get(0);
|
||||
@ -215,20 +216,14 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
private void testRpcCall() throws Exception {
|
||||
Device device = findDeviceByName("Edge Device 1");
|
||||
|
||||
RuleEngineDeviceRpcRequest request = RuleEngineDeviceRpcRequest.builder()
|
||||
.oneway(true)
|
||||
.method("test_method")
|
||||
.body("{\"param1\":\"value1\"}")
|
||||
.tenantId(device.getTenantId())
|
||||
.deviceId(device.getId())
|
||||
.requestId(new Random().nextInt())
|
||||
.requestUUID(UUIDs.timeBased())
|
||||
.originServiceId("originServiceId")
|
||||
.expirationTime(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10))
|
||||
.restApiCall(true)
|
||||
.build();
|
||||
ObjectNode body = mapper.createObjectNode();
|
||||
body.put("requestId", new Random().nextInt());
|
||||
body.put("requestUUID", UUIDs.timeBased().toString());
|
||||
body.put("oneway", false);
|
||||
body.put("expirationTime", System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10));
|
||||
body.put("method", "test_method");
|
||||
body.put("params", "{\"param1\":\"value1\"}");
|
||||
|
||||
JsonNode body = mapper.valueToTree(request);
|
||||
EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.RPC_CALL, device.getId().getId(), EdgeEventType.DEVICE, body);
|
||||
edgeImitator.expectMessageAmount(1);
|
||||
edgeEventService.saveAsync(edgeEvent);
|
||||
@ -260,7 +255,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
Device device = doGet("/api/device/" + deviceUUID.toString(), Device.class);
|
||||
Assert.assertNotNull(device);
|
||||
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));
|
||||
|
||||
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);
|
||||
Assert.assertNotNull(asset);
|
||||
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));
|
||||
|
||||
testAutoGeneratedCodeByProtobuf(assetUpdateMsg);
|
||||
@ -284,7 +281,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
RuleChain ruleChain = doGet("/api/ruleChain/" + ruleChainUUID.toString(), RuleChain.class);
|
||||
Assert.assertNotNull(ruleChain);
|
||||
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));
|
||||
|
||||
testAutoGeneratedCodeByProtobuf(ruleChainUpdateMsg);
|
||||
@ -292,7 +290,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
log.info("Received data checked");
|
||||
}
|
||||
|
||||
private void testDevices() throws Exception {
|
||||
private void testDevices() throws Exception {
|
||||
log.info("Testing devices");
|
||||
|
||||
Device savedDevice = saveDevice("Edge Device 2");
|
||||
@ -490,9 +488,9 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
ruleChainMetaData.setFirstNodeIndex(0);
|
||||
ruleChainMetaData.setNodes(ruleNodes);
|
||||
|
||||
ruleChainMetaData.addConnectionInfo(0,1,"success");
|
||||
ruleChainMetaData.addConnectionInfo(0,2,"fail");
|
||||
ruleChainMetaData.addConnectionInfo(1,2,"success");
|
||||
ruleChainMetaData.addConnectionInfo(0, 1, "success");
|
||||
ruleChainMetaData.addConnectionInfo(0, 2, "fail");
|
||||
ruleChainMetaData.addConnectionInfo(1, 2, "success");
|
||||
|
||||
ruleChainMetaData.addRuleChainConnectionInfo(2, edge.getRootRuleChainId(), "success", mapper.createObjectNode());
|
||||
|
||||
@ -563,7 +561,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
|
||||
Device device = findDeviceByName("Edge Device 1");
|
||||
Asset asset = findAssetByName("Edge Asset 1");
|
||||
|
||||
|
||||
EntityRelation relation = new EntityRelation();
|
||||
relation.setType("test");
|
||||
relation.setFrom(device.getId());
|
||||
@ -605,7 +603,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
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.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());
|
||||
@ -664,7 +663,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
Assert.assertEquals(alarmUpdateMsg.getStatus(), AlarmStatus.CLEARED_ACK.name());
|
||||
|
||||
doDelete("/api/alarm/" + savedAlarm.getId().getId().toString())
|
||||
.andExpect(status().isOk());
|
||||
.andExpect(status().isOk());
|
||||
log.info("Alarms tested successfully");
|
||||
}
|
||||
|
||||
@ -973,7 +972,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
private void sendDevice() throws Exception {
|
||||
UUID uuid = UUIDs.timeBased();
|
||||
|
||||
UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
||||
UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
||||
DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder();
|
||||
deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits());
|
||||
deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits());
|
||||
@ -1063,7 +1062,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
|
||||
|
||||
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())
|
||||
.getData();
|
||||
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 {
|
||||
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();
|
||||
Assert.assertTrue(foundDevice1.isPresent());
|
||||
Device device1 = foundDevice1.get();
|
||||
@ -1116,7 +1117,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
|
||||
private void sendTelemetry() throws Exception {
|
||||
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();
|
||||
Assert.assertTrue(foundDevice.isPresent());
|
||||
Device device = foundDevice.get();
|
||||
@ -1340,7 +1342,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
|
||||
|
||||
private void sendDeleteDeviceOnEdge() throws Exception {
|
||||
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();
|
||||
Assert.assertTrue(foundDevice.isPresent());
|
||||
Device device = foundDevice.get();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user