Commit 36f6ad2a62fecedabd6a8dc940cbd25cd1d52540
Merge branch 'develop/2.6-edge' of github.com:volodymyr-babak/thingsboard into develop/2.6-edge
Showing
2 changed files
with
36 additions
and
33 deletions
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | 7 | * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | 9 | * |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ... | ... |
... | ... | @@ -31,7 +31,6 @@ import org.junit.Assert; |
31 | 31 | import org.junit.Before; |
32 | 32 | import org.junit.Test; |
33 | 33 | import org.springframework.beans.factory.annotation.Autowired; |
34 | -import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest; | |
35 | 34 | import org.thingsboard.server.common.data.Customer; |
36 | 35 | import org.thingsboard.server.common.data.Dashboard; |
37 | 36 | import org.thingsboard.server.common.data.DataConstants; |
... | ... | @@ -180,7 +179,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
180 | 179 | |
181 | 180 | private Device findDeviceByName(String deviceName) throws Exception { |
182 | 181 | List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", |
183 | - new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); | |
182 | + new TypeReference<TimePageData<Device>>() { | |
183 | + }, new TextPageLink(100)).getData(); | |
184 | 184 | Optional<Device> foundDevice = edgeDevices.stream().filter(d -> d.getName().equals(deviceName)).findAny(); |
185 | 185 | Assert.assertTrue(foundDevice.isPresent()); |
186 | 186 | Device device = foundDevice.get(); |
... | ... | @@ -190,7 +190,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
190 | 190 | |
191 | 191 | private Asset findAssetByName(String assetName) throws Exception { |
192 | 192 | List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?", |
193 | - new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100)).getData(); | |
193 | + new TypeReference<TimePageData<Asset>>() { | |
194 | + }, new TextPageLink(100)).getData(); | |
194 | 195 | |
195 | 196 | Assert.assertEquals(1, edgeAssets.size()); |
196 | 197 | Asset asset = edgeAssets.get(0); |
... | ... | @@ -215,20 +216,14 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
215 | 216 | private void testRpcCall() throws Exception { |
216 | 217 | Device device = findDeviceByName("Edge Device 1"); |
217 | 218 | |
218 | - RuleEngineDeviceRpcRequest request = RuleEngineDeviceRpcRequest.builder() | |
219 | - .oneway(true) | |
220 | - .method("test_method") | |
221 | - .body("{\"param1\":\"value1\"}") | |
222 | - .tenantId(device.getTenantId()) | |
223 | - .deviceId(device.getId()) | |
224 | - .requestId(new Random().nextInt()) | |
225 | - .requestUUID(UUIDs.timeBased()) | |
226 | - .originServiceId("originServiceId") | |
227 | - .expirationTime(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10)) | |
228 | - .restApiCall(true) | |
229 | - .build(); | |
230 | - | |
231 | - JsonNode body = mapper.valueToTree(request); | |
219 | + ObjectNode body = mapper.createObjectNode(); | |
220 | + body.put("requestId", new Random().nextInt()); | |
221 | + body.put("requestUUID", UUIDs.timeBased().toString()); | |
222 | + body.put("oneway", false); | |
223 | + body.put("expirationTime", System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10)); | |
224 | + body.put("method", "test_method"); | |
225 | + body.put("params", "{\"param1\":\"value1\"}"); | |
226 | + | |
232 | 227 | EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.RPC_CALL, device.getId().getId(), EdgeEventType.DEVICE, body); |
233 | 228 | edgeImitator.expectMessageAmount(1); |
234 | 229 | edgeEventService.saveAsync(edgeEvent); |
... | ... | @@ -260,7 +255,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
260 | 255 | Device device = doGet("/api/device/" + deviceUUID.toString(), Device.class); |
261 | 256 | Assert.assertNotNull(device); |
262 | 257 | List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", |
263 | - new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); | |
258 | + new TypeReference<TimePageData<Device>>() { | |
259 | + }, new TextPageLink(100)).getData(); | |
264 | 260 | Assert.assertTrue(edgeDevices.contains(device)); |
265 | 261 | |
266 | 262 | Optional<AssetUpdateMsg> optionalMsg2 = edgeImitator.findMessageByType(AssetUpdateMsg.class); |
... | ... | @@ -271,7 +267,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
271 | 267 | Asset asset = doGet("/api/asset/" + assetUUID.toString(), Asset.class); |
272 | 268 | Assert.assertNotNull(asset); |
273 | 269 | List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?", |
274 | - new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100)).getData(); | |
270 | + new TypeReference<TimePageData<Asset>>() { | |
271 | + }, new TextPageLink(100)).getData(); | |
275 | 272 | Assert.assertTrue(edgeAssets.contains(asset)); |
276 | 273 | |
277 | 274 | testAutoGeneratedCodeByProtobuf(assetUpdateMsg); |
... | ... | @@ -284,7 +281,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
284 | 281 | RuleChain ruleChain = doGet("/api/ruleChain/" + ruleChainUUID.toString(), RuleChain.class); |
285 | 282 | Assert.assertNotNull(ruleChain); |
286 | 283 | List<RuleChain> edgeRuleChains = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/ruleChains?", |
287 | - new TypeReference<TimePageData<RuleChain>>() {}, new TextPageLink(100)).getData(); | |
284 | + new TypeReference<TimePageData<RuleChain>>() { | |
285 | + }, new TextPageLink(100)).getData(); | |
288 | 286 | Assert.assertTrue(edgeRuleChains.contains(ruleChain)); |
289 | 287 | |
290 | 288 | testAutoGeneratedCodeByProtobuf(ruleChainUpdateMsg); |
... | ... | @@ -292,7 +290,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
292 | 290 | log.info("Received data checked"); |
293 | 291 | } |
294 | 292 | |
295 | - private void testDevices() throws Exception { | |
293 | + private void testDevices() throws Exception { | |
296 | 294 | log.info("Testing devices"); |
297 | 295 | |
298 | 296 | Device savedDevice = saveDevice("Edge Device 2"); |
... | ... | @@ -490,9 +488,9 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
490 | 488 | ruleChainMetaData.setFirstNodeIndex(0); |
491 | 489 | ruleChainMetaData.setNodes(ruleNodes); |
492 | 490 | |
493 | - ruleChainMetaData.addConnectionInfo(0,1,"success"); | |
494 | - ruleChainMetaData.addConnectionInfo(0,2,"fail"); | |
495 | - ruleChainMetaData.addConnectionInfo(1,2,"success"); | |
491 | + ruleChainMetaData.addConnectionInfo(0, 1, "success"); | |
492 | + ruleChainMetaData.addConnectionInfo(0, 2, "fail"); | |
493 | + ruleChainMetaData.addConnectionInfo(1, 2, "success"); | |
496 | 494 | |
497 | 495 | ruleChainMetaData.addRuleChainConnectionInfo(2, edge.getRootRuleChainId(), "success", mapper.createObjectNode()); |
498 | 496 | |
... | ... | @@ -563,7 +561,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
563 | 561 | |
564 | 562 | Device device = findDeviceByName("Edge Device 1"); |
565 | 563 | Asset asset = findAssetByName("Edge Asset 1"); |
566 | - | |
564 | + | |
567 | 565 | EntityRelation relation = new EntityRelation(); |
568 | 566 | relation.setType("test"); |
569 | 567 | relation.setFrom(device.getId()); |
... | ... | @@ -605,7 +603,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
605 | 603 | Assert.assertEquals(relationUpdateMsg.getType(), relation.getType()); |
606 | 604 | Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits()); |
607 | 605 | Assert.assertEquals(relationUpdateMsg.getFromIdLSB(), relation.getFrom().getId().getLeastSignificantBits()); |
608 | - Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits()); | |
606 | + Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name()); | |
607 | + Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits()); | |
609 | 608 | Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits()); |
610 | 609 | Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name()); |
611 | 610 | Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name()); |
... | ... | @@ -664,7 +663,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
664 | 663 | Assert.assertEquals(alarmUpdateMsg.getStatus(), AlarmStatus.CLEARED_ACK.name()); |
665 | 664 | |
666 | 665 | doDelete("/api/alarm/" + savedAlarm.getId().getId().toString()) |
667 | - .andExpect(status().isOk()); | |
666 | + .andExpect(status().isOk()); | |
668 | 667 | log.info("Alarms tested successfully"); |
669 | 668 | } |
670 | 669 | |
... | ... | @@ -973,7 +972,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
973 | 972 | private void sendDevice() throws Exception { |
974 | 973 | UUID uuid = UUIDs.timeBased(); |
975 | 974 | |
976 | - UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder(); | |
975 | + UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder(); | |
977 | 976 | DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder(); |
978 | 977 | deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits()); |
979 | 978 | deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits()); |
... | ... | @@ -1063,7 +1062,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
1063 | 1062 | |
1064 | 1063 | |
1065 | 1064 | List<AlarmInfo> alarms = doGetTypedWithPageLink("/api/alarm/{entityType}/{entityId}?", |
1066 | - new TypeReference<TimePageData<AlarmInfo>>() {}, | |
1065 | + new TypeReference<TimePageData<AlarmInfo>>() { | |
1066 | + }, | |
1067 | 1067 | new TextPageLink(100), device.getId().getEntityType().name(), device.getId().getId().toString()) |
1068 | 1068 | .getData(); |
1069 | 1069 | Optional<AlarmInfo> foundAlarm = alarms.stream().filter(alarm -> alarm.getType().equals("alarm from edge")).findAny(); |
... | ... | @@ -1076,7 +1076,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
1076 | 1076 | |
1077 | 1077 | private void sendRelation() throws Exception { |
1078 | 1078 | List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", |
1079 | - new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); | |
1079 | + new TypeReference<TimePageData<Device>>() { | |
1080 | + }, new TextPageLink(100)).getData(); | |
1080 | 1081 | Optional<Device> foundDevice1 = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 1")).findAny(); |
1081 | 1082 | Assert.assertTrue(foundDevice1.isPresent()); |
1082 | 1083 | Device device1 = foundDevice1.get(); |
... | ... | @@ -1116,7 +1117,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
1116 | 1117 | |
1117 | 1118 | private void sendTelemetry() throws Exception { |
1118 | 1119 | List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", |
1119 | - new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); | |
1120 | + new TypeReference<TimePageData<Device>>() { | |
1121 | + }, new TextPageLink(100)).getData(); | |
1120 | 1122 | Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny(); |
1121 | 1123 | Assert.assertTrue(foundDevice.isPresent()); |
1122 | 1124 | Device device = foundDevice.get(); |
... | ... | @@ -1340,7 +1342,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
1340 | 1342 | |
1341 | 1343 | private void sendDeleteDeviceOnEdge() throws Exception { |
1342 | 1344 | List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?", |
1343 | - new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData(); | |
1345 | + new TypeReference<TimePageData<Device>>() { | |
1346 | + }, new TextPageLink(100)).getData(); | |
1344 | 1347 | Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny(); |
1345 | 1348 | Assert.assertTrue(foundDevice.isPresent()); |
1346 | 1349 | Device device = foundDevice.get(); | ... | ... |