|
@@ -16,17 +16,22 @@ |
|
@@ -16,17 +16,22 @@ |
16
|
package org.thingsboard.server.edge;
|
16
|
package org.thingsboard.server.edge;
|
17
|
|
17
|
|
18
|
import com.datastax.driver.core.utils.UUIDs;
|
18
|
import com.datastax.driver.core.utils.UUIDs;
|
|
|
19
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
19
|
import com.fasterxml.jackson.core.type.TypeReference;
|
20
|
import com.fasterxml.jackson.core.type.TypeReference;
|
20
|
import com.fasterxml.jackson.databind.JsonNode;
|
21
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
22
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
21
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
23
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
22
|
import com.google.gson.JsonObject;
|
24
|
import com.google.gson.JsonObject;
|
23
|
import com.google.protobuf.AbstractMessage;
|
25
|
import com.google.protobuf.AbstractMessage;
|
|
|
26
|
+import com.google.protobuf.InvalidProtocolBufferException;
|
|
|
27
|
+import com.google.protobuf.MessageLite;
|
24
|
import lombok.extern.slf4j.Slf4j;
|
28
|
import lombok.extern.slf4j.Slf4j;
|
25
|
import org.junit.After;
|
29
|
import org.junit.After;
|
26
|
import org.junit.Assert;
|
30
|
import org.junit.Assert;
|
27
|
import org.junit.Before;
|
31
|
import org.junit.Before;
|
28
|
import org.junit.Test;
|
32
|
import org.junit.Test;
|
29
|
import org.springframework.beans.factory.annotation.Autowired;
|
33
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
34
|
+import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest;
|
30
|
import org.thingsboard.server.common.data.Customer;
|
35
|
import org.thingsboard.server.common.data.Customer;
|
31
|
import org.thingsboard.server.common.data.Dashboard;
|
36
|
import org.thingsboard.server.common.data.Dashboard;
|
32
|
import org.thingsboard.server.common.data.DataConstants;
|
37
|
import org.thingsboard.server.common.data.DataConstants;
|
|
@@ -45,6 +50,8 @@ import org.thingsboard.server.common.data.edge.EdgeEvent; |
|
@@ -45,6 +50,8 @@ import org.thingsboard.server.common.data.edge.EdgeEvent; |
45
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
50
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
46
|
import org.thingsboard.server.common.data.edge.EdgeEventType;
|
51
|
import org.thingsboard.server.common.data.edge.EdgeEventType;
|
47
|
import org.thingsboard.server.common.data.id.EdgeId;
|
52
|
import org.thingsboard.server.common.data.id.EdgeId;
|
|
|
53
|
+import org.thingsboard.server.common.data.id.EntityId;
|
|
|
54
|
+import org.thingsboard.server.common.data.id.EntityIdFactory;
|
48
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
55
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
49
|
import org.thingsboard.server.common.data.id.TenantId;
|
56
|
import org.thingsboard.server.common.data.id.TenantId;
|
50
|
import org.thingsboard.server.common.data.id.UserId;
|
57
|
import org.thingsboard.server.common.data.id.UserId;
|
|
@@ -53,9 +60,12 @@ import org.thingsboard.server.common.data.page.TimePageData; |
|
@@ -53,9 +60,12 @@ import org.thingsboard.server.common.data.page.TimePageData; |
53
|
import org.thingsboard.server.common.data.relation.EntityRelation;
|
60
|
import org.thingsboard.server.common.data.relation.EntityRelation;
|
54
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
61
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
55
|
import org.thingsboard.server.common.data.rule.RuleChain;
|
62
|
import org.thingsboard.server.common.data.rule.RuleChain;
|
|
|
63
|
+import org.thingsboard.server.common.data.rule.RuleChainMetaData;
|
56
|
import org.thingsboard.server.common.data.rule.RuleChainType;
|
64
|
import org.thingsboard.server.common.data.rule.RuleChainType;
|
|
|
65
|
+import org.thingsboard.server.common.data.rule.RuleNode;
|
57
|
import org.thingsboard.server.common.data.security.Authority;
|
66
|
import org.thingsboard.server.common.data.security.Authority;
|
58
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
67
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
|
|
68
|
+import org.thingsboard.server.common.data.security.DeviceCredentialsType;
|
59
|
import org.thingsboard.server.common.data.widget.WidgetType;
|
69
|
import org.thingsboard.server.common.data.widget.WidgetType;
|
60
|
import org.thingsboard.server.common.data.widget.WidgetsBundle;
|
70
|
import org.thingsboard.server.common.data.widget.WidgetsBundle;
|
61
|
import org.thingsboard.server.common.transport.adaptor.JsonConverter;
|
71
|
import org.thingsboard.server.common.transport.adaptor.JsonConverter;
|
|
@@ -65,15 +75,20 @@ import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
|
@@ -65,15 +75,20 @@ import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
65
|
import org.thingsboard.server.edge.imitator.EdgeImitator;
|
75
|
import org.thingsboard.server.edge.imitator.EdgeImitator;
|
66
|
import org.thingsboard.server.gen.edge.AlarmUpdateMsg;
|
76
|
import org.thingsboard.server.gen.edge.AlarmUpdateMsg;
|
67
|
import org.thingsboard.server.gen.edge.AssetUpdateMsg;
|
77
|
import org.thingsboard.server.gen.edge.AssetUpdateMsg;
|
|
|
78
|
+import org.thingsboard.server.gen.edge.AttributeDeleteMsg;
|
|
|
79
|
+import org.thingsboard.server.gen.edge.AttributesRequestMsg;
|
68
|
import org.thingsboard.server.gen.edge.CustomerUpdateMsg;
|
80
|
import org.thingsboard.server.gen.edge.CustomerUpdateMsg;
|
69
|
import org.thingsboard.server.gen.edge.DashboardUpdateMsg;
|
81
|
import org.thingsboard.server.gen.edge.DashboardUpdateMsg;
|
70
|
import org.thingsboard.server.gen.edge.DeviceCredentialsRequestMsg;
|
82
|
import org.thingsboard.server.gen.edge.DeviceCredentialsRequestMsg;
|
71
|
import org.thingsboard.server.gen.edge.DeviceCredentialsUpdateMsg;
|
83
|
import org.thingsboard.server.gen.edge.DeviceCredentialsUpdateMsg;
|
|
|
84
|
+import org.thingsboard.server.gen.edge.DeviceRpcCallMsg;
|
72
|
import org.thingsboard.server.gen.edge.DeviceUpdateMsg;
|
85
|
import org.thingsboard.server.gen.edge.DeviceUpdateMsg;
|
73
|
import org.thingsboard.server.gen.edge.EdgeConfiguration;
|
86
|
import org.thingsboard.server.gen.edge.EdgeConfiguration;
|
74
|
import org.thingsboard.server.gen.edge.EntityDataProto;
|
87
|
import org.thingsboard.server.gen.edge.EntityDataProto;
|
75
|
import org.thingsboard.server.gen.edge.EntityViewUpdateMsg;
|
88
|
import org.thingsboard.server.gen.edge.EntityViewUpdateMsg;
|
|
|
89
|
+import org.thingsboard.server.gen.edge.RelationRequestMsg;
|
76
|
import org.thingsboard.server.gen.edge.RelationUpdateMsg;
|
90
|
import org.thingsboard.server.gen.edge.RelationUpdateMsg;
|
|
|
91
|
+import org.thingsboard.server.gen.edge.RpcResponseMsg;
|
77
|
import org.thingsboard.server.gen.edge.RuleChainMetadataRequestMsg;
|
92
|
import org.thingsboard.server.gen.edge.RuleChainMetadataRequestMsg;
|
78
|
import org.thingsboard.server.gen.edge.RuleChainMetadataUpdateMsg;
|
93
|
import org.thingsboard.server.gen.edge.RuleChainMetadataUpdateMsg;
|
79
|
import org.thingsboard.server.gen.edge.RuleChainUpdateMsg;
|
94
|
import org.thingsboard.server.gen.edge.RuleChainUpdateMsg;
|
|
@@ -85,16 +100,16 @@ import org.thingsboard.server.gen.edge.WidgetTypeUpdateMsg; |
|
@@ -85,16 +100,16 @@ import org.thingsboard.server.gen.edge.WidgetTypeUpdateMsg; |
85
|
import org.thingsboard.server.gen.edge.WidgetsBundleUpdateMsg;
|
100
|
import org.thingsboard.server.gen.edge.WidgetsBundleUpdateMsg;
|
86
|
import org.thingsboard.server.gen.transport.TransportProtos;
|
101
|
import org.thingsboard.server.gen.transport.TransportProtos;
|
87
|
|
102
|
|
|
|
103
|
+import java.util.ArrayList;
|
88
|
import java.util.List;
|
104
|
import java.util.List;
|
89
|
import java.util.Map;
|
105
|
import java.util.Map;
|
90
|
import java.util.Optional;
|
106
|
import java.util.Optional;
|
|
|
107
|
+import java.util.Random;
|
91
|
import java.util.UUID;
|
108
|
import java.util.UUID;
|
|
|
109
|
+import java.util.concurrent.TimeUnit;
|
92
|
|
110
|
|
93
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
111
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
94
|
|
112
|
|
95
|
-;
|
|
|
96
|
-
|
|
|
97
|
-
|
|
|
98
|
@Slf4j
|
113
|
@Slf4j
|
99
|
abstract public class BaseEdgeTest extends AbstractControllerTest {
|
114
|
abstract public class BaseEdgeTest extends AbstractControllerTest {
|
100
|
|
115
|
|
|
@@ -137,7 +152,6 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -137,7 +152,6 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
137
|
@After
|
152
|
@After
|
138
|
public void afterTest() throws Exception {
|
153
|
public void afterTest() throws Exception {
|
139
|
edgeImitator.disconnect();
|
154
|
edgeImitator.disconnect();
|
140
|
- uninstallation();
|
|
|
141
|
|
155
|
|
142
|
loginSysAdmin();
|
156
|
loginSysAdmin();
|
143
|
|
157
|
|
|
@@ -161,6 +175,69 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -161,6 +175,69 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
161
|
testTimeseries();
|
175
|
testTimeseries();
|
162
|
testAttributes();
|
176
|
testAttributes();
|
163
|
testSendMessagesToCloud();
|
177
|
testSendMessagesToCloud();
|
|
|
178
|
+ testRpcCall();
|
|
|
179
|
+ }
|
|
|
180
|
+
|
|
|
181
|
+ private Device findDeviceByName(String deviceName) throws Exception {
|
|
|
182
|
+ List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
183
|
+ new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
|
|
184
|
+ Optional<Device> foundDevice = edgeDevices.stream().filter(d -> d.getName().equals(deviceName)).findAny();
|
|
|
185
|
+ Assert.assertTrue(foundDevice.isPresent());
|
|
|
186
|
+ Device device = foundDevice.get();
|
|
|
187
|
+ Assert.assertEquals(deviceName, device.getName());
|
|
|
188
|
+ return device;
|
|
|
189
|
+ }
|
|
|
190
|
+
|
|
|
191
|
+ private Asset findAssetByName(String assetName) throws Exception {
|
|
|
192
|
+ List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?",
|
|
|
193
|
+ new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100)).getData();
|
|
|
194
|
+
|
|
|
195
|
+ Assert.assertEquals(1, edgeAssets.size());
|
|
|
196
|
+ Asset asset = edgeAssets.get(0);
|
|
|
197
|
+ Assert.assertEquals(assetName, asset.getName());
|
|
|
198
|
+ return asset;
|
|
|
199
|
+ }
|
|
|
200
|
+
|
|
|
201
|
+ private Device saveDevice(String deviceName) throws Exception {
|
|
|
202
|
+ Device device = new Device();
|
|
|
203
|
+ device.setName(deviceName);
|
|
|
204
|
+ device.setType("test");
|
|
|
205
|
+ return doPost("/api/device", device, Device.class);
|
|
|
206
|
+ }
|
|
|
207
|
+
|
|
|
208
|
+ private Asset saveAsset(String assetName) throws Exception {
|
|
|
209
|
+ Asset asset = new Asset();
|
|
|
210
|
+ asset.setName(assetName);
|
|
|
211
|
+ asset.setType("test");
|
|
|
212
|
+ return doPost("/api/asset", asset, Asset.class);
|
|
|
213
|
+ }
|
|
|
214
|
+
|
|
|
215
|
+ private void testRpcCall() throws Exception {
|
|
|
216
|
+ Device device = findDeviceByName("Edge Device 1");
|
|
|
217
|
+
|
|
|
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);
|
|
|
232
|
+ EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.RPC_CALL, device.getId().getId(), EdgeEventType.DEVICE, body);
|
|
|
233
|
+ edgeImitator.expectMessageAmount(1);
|
|
|
234
|
+ edgeEventService.saveAsync(edgeEvent);
|
|
|
235
|
+ edgeImitator.waitForMessages();
|
|
|
236
|
+
|
|
|
237
|
+ AbstractMessage latestMessage = edgeImitator.getLatestMessage();
|
|
|
238
|
+ Assert.assertTrue(latestMessage instanceof DeviceRpcCallMsg);
|
|
|
239
|
+ DeviceRpcCallMsg latestDeviceRpcCallMsg = (DeviceRpcCallMsg) latestMessage;
|
|
|
240
|
+ Assert.assertEquals("test_method", latestDeviceRpcCallMsg.getRequestMsg().getMethod());
|
164
|
}
|
241
|
}
|
165
|
|
242
|
|
166
|
private void testReceivedInitialData() throws Exception {
|
243
|
private void testReceivedInitialData() throws Exception {
|
|
@@ -170,6 +247,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -170,6 +247,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
170
|
EdgeConfiguration configuration = edgeImitator.getConfiguration();
|
247
|
EdgeConfiguration configuration = edgeImitator.getConfiguration();
|
171
|
Assert.assertNotNull(configuration);
|
248
|
Assert.assertNotNull(configuration);
|
172
|
|
249
|
|
|
|
250
|
+ testAutoGeneratedCodeByProtobuf(configuration);
|
|
|
251
|
+
|
173
|
UserId userId = edgeImitator.getUserId();
|
252
|
UserId userId = edgeImitator.getUserId();
|
174
|
Assert.assertNotNull(userId);
|
253
|
Assert.assertNotNull(userId);
|
175
|
|
254
|
|
|
@@ -195,6 +274,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -195,6 +274,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
195
|
new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100)).getData();
|
274
|
new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100)).getData();
|
196
|
Assert.assertTrue(edgeAssets.contains(asset));
|
275
|
Assert.assertTrue(edgeAssets.contains(asset));
|
197
|
|
276
|
|
|
|
277
|
+ testAutoGeneratedCodeByProtobuf(assetUpdateMsg);
|
|
|
278
|
+
|
198
|
Optional<RuleChainUpdateMsg> optionalMsg3 = edgeImitator.findMessageByType(RuleChainUpdateMsg.class);
|
279
|
Optional<RuleChainUpdateMsg> optionalMsg3 = edgeImitator.findMessageByType(RuleChainUpdateMsg.class);
|
199
|
Assert.assertTrue(optionalMsg3.isPresent());
|
280
|
Assert.assertTrue(optionalMsg3.isPresent());
|
200
|
RuleChainUpdateMsg ruleChainUpdateMsg = optionalMsg3.get();
|
281
|
RuleChainUpdateMsg ruleChainUpdateMsg = optionalMsg3.get();
|
|
@@ -206,16 +287,15 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -206,16 +287,15 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
206
|
new TypeReference<TimePageData<RuleChain>>() {}, new TextPageLink(100)).getData();
|
287
|
new TypeReference<TimePageData<RuleChain>>() {}, new TextPageLink(100)).getData();
|
207
|
Assert.assertTrue(edgeRuleChains.contains(ruleChain));
|
288
|
Assert.assertTrue(edgeRuleChains.contains(ruleChain));
|
208
|
|
289
|
|
|
|
290
|
+ testAutoGeneratedCodeByProtobuf(ruleChainUpdateMsg);
|
|
|
291
|
+
|
209
|
log.info("Received data checked");
|
292
|
log.info("Received data checked");
|
210
|
}
|
293
|
}
|
211
|
|
294
|
|
212
|
private void testDevices() throws Exception {
|
295
|
private void testDevices() throws Exception {
|
213
|
log.info("Testing devices");
|
296
|
log.info("Testing devices");
|
214
|
|
297
|
|
215
|
- Device device = new Device();
|
|
|
216
|
- device.setName("Edge Device 2");
|
|
|
217
|
- device.setType("test");
|
|
|
218
|
- Device savedDevice = doPost("/api/device", device, Device.class);
|
298
|
+ Device savedDevice = saveDevice("Edge Device 2");
|
219
|
|
299
|
|
220
|
edgeImitator.expectMessageAmount(1);
|
300
|
edgeImitator.expectMessageAmount(1);
|
221
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
301
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
|
@@ -261,10 +341,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -261,10 +341,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
261
|
|
341
|
|
262
|
private void testAssets() throws Exception {
|
342
|
private void testAssets() throws Exception {
|
263
|
log.info("Testing assets");
|
343
|
log.info("Testing assets");
|
264
|
- Asset asset = new Asset();
|
|
|
265
|
- asset.setName("Edge Asset 2");
|
|
|
266
|
- asset.setType("test");
|
|
|
267
|
- Asset savedAsset = doPost("/api/asset", asset, Asset.class);
|
344
|
+ Asset savedAsset = saveAsset("Edge Asset 2");
|
268
|
|
345
|
|
269
|
edgeImitator.expectMessageAmount(1);
|
346
|
edgeImitator.expectMessageAmount(1);
|
270
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
347
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
|
@@ -314,6 +391,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -314,6 +391,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
314
|
ruleChain.setType(RuleChainType.EDGE);
|
391
|
ruleChain.setType(RuleChainType.EDGE);
|
315
|
RuleChain savedRuleChain = doPost("/api/ruleChain", ruleChain, RuleChain.class);
|
392
|
RuleChain savedRuleChain = doPost("/api/ruleChain", ruleChain, RuleChain.class);
|
316
|
|
393
|
|
|
|
394
|
+ createRuleChainMetadata(savedRuleChain);
|
|
|
395
|
+
|
|
|
396
|
+ // Wait before rule chain metadata saved to database before rule chain is assigned to edge
|
|
|
397
|
+ Thread.sleep(1000);
|
|
|
398
|
+
|
317
|
edgeImitator.expectMessageAmount(1);
|
399
|
edgeImitator.expectMessageAmount(1);
|
318
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
400
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
319
|
+ "/ruleChain/" + savedRuleChain.getId().getId().toString(), RuleChain.class);
|
401
|
+ "/ruleChain/" + savedRuleChain.getId().getId().toString(), RuleChain.class);
|
|
@@ -327,6 +409,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -327,6 +409,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
327
|
Assert.assertEquals(ruleChainUpdateMsg.getIdLSB(), savedRuleChain.getUuidId().getLeastSignificantBits());
|
409
|
Assert.assertEquals(ruleChainUpdateMsg.getIdLSB(), savedRuleChain.getUuidId().getLeastSignificantBits());
|
328
|
Assert.assertEquals(ruleChainUpdateMsg.getName(), savedRuleChain.getName());
|
410
|
Assert.assertEquals(ruleChainUpdateMsg.getName(), savedRuleChain.getName());
|
329
|
|
411
|
|
|
|
412
|
+ testRuleChainMetadataRequestMsg(savedRuleChain.getId());
|
|
|
413
|
+
|
330
|
edgeImitator.expectMessageAmount(1);
|
414
|
edgeImitator.expectMessageAmount(1);
|
331
|
doDelete("/api/edge/" + edge.getId().getId().toString()
|
415
|
doDelete("/api/edge/" + edge.getId().getId().toString()
|
332
|
+ "/ruleChain/" + savedRuleChain.getId().getId().toString(), RuleChain.class);
|
416
|
+ "/ruleChain/" + savedRuleChain.getId().getId().toString(), RuleChain.class);
|
|
@@ -354,6 +438,67 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -354,6 +438,67 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
354
|
log.info("RuleChains tested successfully");
|
438
|
log.info("RuleChains tested successfully");
|
355
|
}
|
439
|
}
|
356
|
|
440
|
|
|
|
441
|
+ private void testRuleChainMetadataRequestMsg(RuleChainId ruleChainId) throws Exception {
|
|
|
442
|
+ RuleChainMetadataRequestMsg.Builder ruleChainMetadataRequestMsgBuilder = RuleChainMetadataRequestMsg.newBuilder()
|
|
|
443
|
+ .setRuleChainIdMSB(ruleChainId.getId().getMostSignificantBits())
|
|
|
444
|
+ .setRuleChainIdLSB(ruleChainId.getId().getLeastSignificantBits());
|
|
|
445
|
+ testAutoGeneratedCodeByProtobuf(ruleChainMetadataRequestMsgBuilder);
|
|
|
446
|
+
|
|
|
447
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder()
|
|
|
448
|
+ .addRuleChainMetadataRequestMsg(ruleChainMetadataRequestMsgBuilder.build());
|
|
|
449
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
450
|
+
|
|
|
451
|
+ edgeImitator.expectResponsesAmount(1);
|
|
|
452
|
+ edgeImitator.expectMessageAmount(1);
|
|
|
453
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
|
|
454
|
+ edgeImitator.waitForResponses();
|
|
|
455
|
+ edgeImitator.waitForMessages();
|
|
|
456
|
+
|
|
|
457
|
+ AbstractMessage latestMessage = edgeImitator.getLatestMessage();
|
|
|
458
|
+ Assert.assertTrue(latestMessage instanceof RuleChainMetadataUpdateMsg);
|
|
|
459
|
+ RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = (RuleChainMetadataUpdateMsg) latestMessage;
|
|
|
460
|
+ RuleChainId receivedRuleChainId =
|
|
|
461
|
+ new RuleChainId(new UUID(ruleChainMetadataUpdateMsg.getRuleChainIdMSB(), ruleChainMetadataUpdateMsg.getRuleChainIdLSB()));
|
|
|
462
|
+ Assert.assertEquals(ruleChainId, receivedRuleChainId);
|
|
|
463
|
+ }
|
|
|
464
|
+
|
|
|
465
|
+ private void createRuleChainMetadata(RuleChain ruleChain) throws Exception {
|
|
|
466
|
+ RuleChainMetaData ruleChainMetaData = new RuleChainMetaData();
|
|
|
467
|
+ ruleChainMetaData.setRuleChainId(ruleChain.getId());
|
|
|
468
|
+
|
|
|
469
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
470
|
+
|
|
|
471
|
+ RuleNode ruleNode1 = new RuleNode();
|
|
|
472
|
+ ruleNode1.setName("name1");
|
|
|
473
|
+ ruleNode1.setType("type1");
|
|
|
474
|
+ ruleNode1.setConfiguration(mapper.readTree("\"key1\": \"val1\""));
|
|
|
475
|
+
|
|
|
476
|
+ RuleNode ruleNode2 = new RuleNode();
|
|
|
477
|
+ ruleNode2.setName("name2");
|
|
|
478
|
+ ruleNode2.setType("type2");
|
|
|
479
|
+ ruleNode2.setConfiguration(mapper.readTree("\"key2\": \"val2\""));
|
|
|
480
|
+
|
|
|
481
|
+ RuleNode ruleNode3 = new RuleNode();
|
|
|
482
|
+ ruleNode3.setName("name3");
|
|
|
483
|
+ ruleNode3.setType("type3");
|
|
|
484
|
+ ruleNode3.setConfiguration(mapper.readTree("\"key3\": \"val3\""));
|
|
|
485
|
+
|
|
|
486
|
+ List<RuleNode> ruleNodes = new ArrayList<>();
|
|
|
487
|
+ ruleNodes.add(ruleNode1);
|
|
|
488
|
+ ruleNodes.add(ruleNode2);
|
|
|
489
|
+ ruleNodes.add(ruleNode3);
|
|
|
490
|
+ ruleChainMetaData.setFirstNodeIndex(0);
|
|
|
491
|
+ ruleChainMetaData.setNodes(ruleNodes);
|
|
|
492
|
+
|
|
|
493
|
+ ruleChainMetaData.addConnectionInfo(0,1,"success");
|
|
|
494
|
+ ruleChainMetaData.addConnectionInfo(0,2,"fail");
|
|
|
495
|
+ ruleChainMetaData.addConnectionInfo(1,2,"success");
|
|
|
496
|
+
|
|
|
497
|
+ ruleChainMetaData.addRuleChainConnectionInfo(2, edge.getRootRuleChainId(), "success", mapper.createObjectNode());
|
|
|
498
|
+
|
|
|
499
|
+ doPost("/api/ruleChain/metadata", ruleChainMetaData, RuleChainMetaData.class);
|
|
|
500
|
+ }
|
|
|
501
|
+
|
357
|
private void testDashboards() throws Exception {
|
502
|
private void testDashboards() throws Exception {
|
358
|
log.info("Testing Dashboards");
|
503
|
log.info("Testing Dashboards");
|
359
|
Dashboard dashboard = new Dashboard();
|
504
|
Dashboard dashboard = new Dashboard();
|
|
@@ -373,6 +518,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -373,6 +518,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
373
|
Assert.assertEquals(dashboardUpdateMsg.getIdLSB(), savedDashboard.getUuidId().getLeastSignificantBits());
|
518
|
Assert.assertEquals(dashboardUpdateMsg.getIdLSB(), savedDashboard.getUuidId().getLeastSignificantBits());
|
374
|
Assert.assertEquals(dashboardUpdateMsg.getTitle(), savedDashboard.getName());
|
519
|
Assert.assertEquals(dashboardUpdateMsg.getTitle(), savedDashboard.getName());
|
375
|
|
520
|
|
|
|
521
|
+ testAutoGeneratedCodeByProtobuf(dashboardUpdateMsg);
|
|
|
522
|
+
|
376
|
edgeImitator.expectMessageAmount(1);
|
523
|
edgeImitator.expectMessageAmount(1);
|
377
|
savedDashboard.setTitle("Updated Edge Test Dashboard");
|
524
|
savedDashboard.setTitle("Updated Edge Test Dashboard");
|
378
|
doPost("/api/dashboard", savedDashboard, Dashboard.class);
|
525
|
doPost("/api/dashboard", savedDashboard, Dashboard.class);
|
|
@@ -413,18 +560,10 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -413,18 +560,10 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
413
|
|
560
|
|
414
|
private void testRelations() throws Exception {
|
561
|
private void testRelations() throws Exception {
|
415
|
log.info("Testing Relations");
|
562
|
log.info("Testing Relations");
|
416
|
- List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
417
|
- new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
|
|
418
|
- List<Asset> edgeAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?",
|
|
|
419
|
- new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100)).getData();
|
|
|
420
|
-
|
|
|
421
|
- Assert.assertEquals(1, edgeDevices.size());
|
|
|
422
|
- Assert.assertEquals(1, edgeAssets.size());
|
|
|
423
|
- Device device = edgeDevices.get(0);
|
|
|
424
|
- Asset asset = edgeAssets.get(0);
|
|
|
425
|
- Assert.assertEquals("Edge Device 1", device.getName());
|
|
|
426
|
- Assert.assertEquals("Edge Asset 1", asset.getName());
|
|
|
427
|
|
563
|
|
|
|
564
|
+ Device device = findDeviceByName("Edge Device 1");
|
|
|
565
|
+ Asset asset = findAssetByName("Edge Asset 1");
|
|
|
566
|
+
|
428
|
EntityRelation relation = new EntityRelation();
|
567
|
EntityRelation relation = new EntityRelation();
|
429
|
relation.setType("test");
|
568
|
relation.setType("test");
|
430
|
relation.setFrom(device.getId());
|
569
|
relation.setFrom(device.getId());
|
|
@@ -476,11 +615,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -476,11 +615,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
476
|
|
615
|
|
477
|
private void testAlarms() throws Exception {
|
616
|
private void testAlarms() throws Exception {
|
478
|
log.info("Testing Alarms");
|
617
|
log.info("Testing Alarms");
|
479
|
- List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
480
|
- new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
|
|
481
|
- Assert.assertEquals(1, edgeDevices.size());
|
|
|
482
|
- Device device = edgeDevices.get(0);
|
|
|
483
|
- Assert.assertEquals("Edge Device 1", device.getName());
|
618
|
+ Device device = findDeviceByName("Edge Device 1");
|
484
|
|
619
|
|
485
|
Alarm alarm = new Alarm();
|
620
|
Alarm alarm = new Alarm();
|
486
|
alarm.setOriginator(device.getId());
|
621
|
alarm.setOriginator(device.getId());
|
|
@@ -535,11 +670,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -535,11 +670,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
535
|
|
670
|
|
536
|
private void testEntityView() throws Exception {
|
671
|
private void testEntityView() throws Exception {
|
537
|
log.info("Testing EntityView");
|
672
|
log.info("Testing EntityView");
|
538
|
- List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
539
|
- new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
|
|
540
|
- Assert.assertEquals(1, edgeDevices.size());
|
|
|
541
|
- Device device = edgeDevices.get(0);
|
|
|
542
|
- Assert.assertEquals("Edge Device 1", device.getName());
|
673
|
+ Device device = findDeviceByName("Edge Device 1");
|
543
|
|
674
|
|
544
|
EntityView entityView = new EntityView();
|
675
|
EntityView entityView = new EntityView();
|
545
|
entityView.setName("Edge EntityView 1");
|
676
|
entityView.setName("Edge EntityView 1");
|
|
@@ -611,6 +742,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -611,6 +742,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
611
|
Assert.assertEquals(customerUpdateMsg.getIdLSB(), savedCustomer.getUuidId().getLeastSignificantBits());
|
742
|
Assert.assertEquals(customerUpdateMsg.getIdLSB(), savedCustomer.getUuidId().getLeastSignificantBits());
|
612
|
Assert.assertEquals(customerUpdateMsg.getTitle(), savedCustomer.getTitle());
|
743
|
Assert.assertEquals(customerUpdateMsg.getTitle(), savedCustomer.getTitle());
|
613
|
|
744
|
|
|
|
745
|
+ testAutoGeneratedCodeByProtobuf(customerUpdateMsg);
|
|
|
746
|
+
|
614
|
edgeImitator.expectMessageAmount(1);
|
747
|
edgeImitator.expectMessageAmount(1);
|
615
|
doDelete("/api/customer/edge/" + edge.getId().getId().toString(), Edge.class);
|
748
|
doDelete("/api/customer/edge/" + edge.getId().getId().toString(), Edge.class);
|
616
|
edgeImitator.waitForMessages();
|
749
|
edgeImitator.waitForMessages();
|
|
@@ -656,6 +789,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -656,6 +789,8 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
656
|
Assert.assertEquals(widgetsBundleUpdateMsg.getAlias(), savedWidgetsBundle.getAlias());
|
789
|
Assert.assertEquals(widgetsBundleUpdateMsg.getAlias(), savedWidgetsBundle.getAlias());
|
657
|
Assert.assertEquals(widgetsBundleUpdateMsg.getTitle(), savedWidgetsBundle.getTitle());
|
790
|
Assert.assertEquals(widgetsBundleUpdateMsg.getTitle(), savedWidgetsBundle.getTitle());
|
658
|
|
791
|
|
|
|
792
|
+ testAutoGeneratedCodeByProtobuf(widgetsBundleUpdateMsg);
|
|
|
793
|
+
|
659
|
WidgetType widgetType = new WidgetType();
|
794
|
WidgetType widgetType = new WidgetType();
|
660
|
widgetType.setName("Test Widget Type");
|
795
|
widgetType.setName("Test Widget Type");
|
661
|
widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
|
796
|
widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
|
|
@@ -706,11 +841,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -706,11 +841,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
706
|
|
841
|
|
707
|
private void testTimeseries() throws Exception {
|
842
|
private void testTimeseries() throws Exception {
|
708
|
log.info("Testing timeseries");
|
843
|
log.info("Testing timeseries");
|
709
|
- List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
710
|
- new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
|
|
711
|
- Assert.assertEquals(1, edgeDevices.size());
|
|
|
712
|
- Device device = edgeDevices.get(0);
|
|
|
713
|
- Assert.assertEquals("Edge Device 1", device.getName());
|
844
|
+ Device device = findDeviceByName("Edge Device 1");
|
714
|
|
845
|
|
715
|
String timeseriesData = "{\"data\":{\"temperature\":25},\"ts\":" + System.currentTimeMillis() + "}";
|
846
|
String timeseriesData = "{\"data\":{\"temperature\":25},\"ts\":" + System.currentTimeMillis() + "}";
|
716
|
JsonNode timeseriesEntityData = mapper.readTree(timeseriesData);
|
847
|
JsonNode timeseriesEntityData = mapper.readTree(timeseriesData);
|
|
@@ -740,61 +871,92 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -740,61 +871,92 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
740
|
|
871
|
|
741
|
private void testAttributes() throws Exception {
|
872
|
private void testAttributes() throws Exception {
|
742
|
log.info("Testing attributes");
|
873
|
log.info("Testing attributes");
|
743
|
- List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
744
|
- new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
|
|
745
|
- Assert.assertEquals(1, edgeDevices.size());
|
|
|
746
|
- Device device = edgeDevices.get(0);
|
|
|
747
|
- Assert.assertEquals("Edge Device 1", device.getName());
|
874
|
+ Device device = findDeviceByName("Edge Device 1");
|
748
|
|
875
|
|
749
|
- String attributesData = "{\"scope\":\"SERVER_SCOPE\",\"kv\":{\"key\":\"value\"}}";
|
|
|
750
|
- JsonNode attributesEntityData = mapper.readTree(attributesData);
|
|
|
751
|
- EdgeEvent edgeEvent1 = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData);
|
876
|
+ testAttributesUpdatedMsg(device);
|
|
|
877
|
+ testPostAttributesMsg(device);
|
|
|
878
|
+ testAttributesDeleteMsg(device);
|
|
|
879
|
+
|
|
|
880
|
+ log.info("Attributes tested successfully");
|
|
|
881
|
+ }
|
|
|
882
|
+
|
|
|
883
|
+ private void testAttributesDeleteMsg(Device device) throws JsonProcessingException, InterruptedException {
|
|
|
884
|
+ String deleteAttributesData = "{\"scope\":\"SERVER_SCOPE\",\"keys\":[\"key1\",\"key2\"]}";
|
|
|
885
|
+ JsonNode deleteAttributesEntityData = mapper.readTree(deleteAttributesData);
|
|
|
886
|
+ EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_DELETED, device.getId().getId(), EdgeEventType.DEVICE, deleteAttributesEntityData);
|
752
|
edgeImitator.expectMessageAmount(1);
|
887
|
edgeImitator.expectMessageAmount(1);
|
753
|
- edgeEventService.saveAsync(edgeEvent1);
|
888
|
+ edgeEventService.saveAsync(edgeEvent);
|
754
|
edgeImitator.waitForMessages();
|
889
|
edgeImitator.waitForMessages();
|
755
|
|
890
|
|
756
|
AbstractMessage latestMessage = edgeImitator.getLatestMessage();
|
891
|
AbstractMessage latestMessage = edgeImitator.getLatestMessage();
|
757
|
Assert.assertTrue(latestMessage instanceof EntityDataProto);
|
892
|
Assert.assertTrue(latestMessage instanceof EntityDataProto);
|
758
|
EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
|
893
|
EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
|
759
|
- Assert.assertEquals(latestEntityDataMsg.getEntityIdMSB(), device.getUuidId().getMostSignificantBits());
|
|
|
760
|
- Assert.assertEquals(latestEntityDataMsg.getEntityIdLSB(), device.getUuidId().getLeastSignificantBits());
|
|
|
761
|
- Assert.assertEquals(latestEntityDataMsg.getEntityType(), device.getId().getEntityType().name());
|
|
|
762
|
- Assert.assertEquals(latestEntityDataMsg.getPostAttributeScope(), attributesEntityData.get("scope").asText());
|
|
|
763
|
- Assert.assertTrue(latestEntityDataMsg.hasAttributesUpdatedMsg());
|
894
|
+ Assert.assertEquals(device.getUuidId().getMostSignificantBits(), latestEntityDataMsg.getEntityIdMSB());
|
|
|
895
|
+ Assert.assertEquals(device.getUuidId().getLeastSignificantBits(), latestEntityDataMsg.getEntityIdLSB());
|
|
|
896
|
+ Assert.assertEquals(device.getId().getEntityType().name(), latestEntityDataMsg.getEntityType());
|
764
|
|
897
|
|
765
|
- TransportProtos.PostAttributeMsg attributesUpdatedMsg = latestEntityDataMsg.getAttributesUpdatedMsg();
|
|
|
766
|
- Assert.assertEquals(1, attributesUpdatedMsg.getKvCount());
|
|
|
767
|
- TransportProtos.KeyValueProto keyValueProto = attributesUpdatedMsg.getKv(0);
|
|
|
768
|
- Assert.assertEquals("key", keyValueProto.getKey());
|
|
|
769
|
- Assert.assertEquals("value", keyValueProto.getStringV());
|
898
|
+ Assert.assertTrue(latestEntityDataMsg.hasAttributeDeleteMsg());
|
770
|
|
899
|
|
771
|
- ((ObjectNode) attributesEntityData).put("isPostAttributes", true);
|
|
|
772
|
- EdgeEvent edgeEvent2 = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData);
|
900
|
+ AttributeDeleteMsg attributeDeleteMsg = latestEntityDataMsg.getAttributeDeleteMsg();
|
|
|
901
|
+ Assert.assertEquals(attributeDeleteMsg.getScope(), deleteAttributesEntityData.get("scope").asText());
|
|
|
902
|
+
|
|
|
903
|
+ Assert.assertEquals(2, attributeDeleteMsg.getAttributeNamesCount());
|
|
|
904
|
+ Assert.assertEquals("key1", attributeDeleteMsg.getAttributeNames(0));
|
|
|
905
|
+ Assert.assertEquals("key2", attributeDeleteMsg.getAttributeNames(1));
|
|
|
906
|
+ }
|
|
|
907
|
+
|
|
|
908
|
+ private void testPostAttributesMsg(Device device) throws JsonProcessingException, InterruptedException {
|
|
|
909
|
+ String postAttributesData = "{\"scope\":\"SERVER_SCOPE\",\"kv\":{\"key2\":\"value2\"}}";
|
|
|
910
|
+ JsonNode postAttributesEntityData = mapper.readTree(postAttributesData);
|
|
|
911
|
+ EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.POST_ATTRIBUTES, device.getId().getId(), EdgeEventType.DEVICE, postAttributesEntityData);
|
773
|
edgeImitator.expectMessageAmount(1);
|
912
|
edgeImitator.expectMessageAmount(1);
|
774
|
- edgeEventService.saveAsync(edgeEvent2);
|
913
|
+ edgeEventService.saveAsync(edgeEvent);
|
775
|
edgeImitator.waitForMessages();
|
914
|
edgeImitator.waitForMessages();
|
776
|
|
915
|
|
777
|
- latestMessage = edgeImitator.getLatestMessage();
|
916
|
+ AbstractMessage latestMessage = edgeImitator.getLatestMessage();
|
778
|
Assert.assertTrue(latestMessage instanceof EntityDataProto);
|
917
|
Assert.assertTrue(latestMessage instanceof EntityDataProto);
|
779
|
- latestEntityDataMsg = (EntityDataProto) latestMessage;
|
|
|
780
|
- Assert.assertEquals(latestEntityDataMsg.getEntityIdMSB(), device.getUuidId().getMostSignificantBits());
|
|
|
781
|
- Assert.assertEquals(latestEntityDataMsg.getEntityIdLSB(), device.getUuidId().getLeastSignificantBits());
|
|
|
782
|
- Assert.assertEquals(latestEntityDataMsg.getEntityType(), device.getId().getEntityType().name());
|
|
|
783
|
- Assert.assertEquals(latestEntityDataMsg.getPostAttributeScope(), attributesEntityData.get("scope").asText());
|
918
|
+ EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
|
|
|
919
|
+ Assert.assertEquals(device.getUuidId().getMostSignificantBits(), latestEntityDataMsg.getEntityIdMSB());
|
|
|
920
|
+ Assert.assertEquals(device.getUuidId().getLeastSignificantBits(), latestEntityDataMsg.getEntityIdLSB());
|
|
|
921
|
+ Assert.assertEquals(device.getId().getEntityType().name(), latestEntityDataMsg.getEntityType());
|
|
|
922
|
+ Assert.assertEquals("SERVER_SCOPE", latestEntityDataMsg.getPostAttributeScope());
|
784
|
Assert.assertTrue(latestEntityDataMsg.hasPostAttributesMsg());
|
923
|
Assert.assertTrue(latestEntityDataMsg.hasPostAttributesMsg());
|
785
|
|
924
|
|
786
|
- attributesUpdatedMsg = latestEntityDataMsg.getPostAttributesMsg();
|
|
|
787
|
- Assert.assertEquals(1, attributesUpdatedMsg.getKvCount());
|
|
|
788
|
- keyValueProto = attributesUpdatedMsg.getKv(0);
|
|
|
789
|
- Assert.assertEquals("key", keyValueProto.getKey());
|
|
|
790
|
- Assert.assertEquals("value", keyValueProto.getStringV());
|
925
|
+ TransportProtos.PostAttributeMsg postAttributesMsg = latestEntityDataMsg.getPostAttributesMsg();
|
|
|
926
|
+ Assert.assertEquals(1, postAttributesMsg.getKvCount());
|
|
|
927
|
+ TransportProtos.KeyValueProto keyValueProto = postAttributesMsg.getKv(0);
|
|
|
928
|
+ Assert.assertEquals("key2", keyValueProto.getKey());
|
|
|
929
|
+ Assert.assertEquals("value2", keyValueProto.getStringV());
|
|
|
930
|
+ }
|
791
|
|
931
|
|
792
|
- log.info("Attributes tested successfully");
|
932
|
+ private void testAttributesUpdatedMsg(Device device) throws JsonProcessingException, InterruptedException {
|
|
|
933
|
+ String attributesData = "{\"scope\":\"SERVER_SCOPE\",\"kv\":{\"key1\":\"value1\"}}";
|
|
|
934
|
+ JsonNode attributesEntityData = mapper.readTree(attributesData);
|
|
|
935
|
+ EdgeEvent edgeEvent1 = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData);
|
|
|
936
|
+ edgeImitator.expectMessageAmount(1);
|
|
|
937
|
+ edgeEventService.saveAsync(edgeEvent1);
|
|
|
938
|
+ edgeImitator.waitForMessages();
|
|
|
939
|
+
|
|
|
940
|
+ AbstractMessage latestMessage = edgeImitator.getLatestMessage();
|
|
|
941
|
+ Assert.assertTrue(latestMessage instanceof EntityDataProto);
|
|
|
942
|
+ EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
|
|
|
943
|
+ Assert.assertEquals(device.getUuidId().getMostSignificantBits(), latestEntityDataMsg.getEntityIdMSB());
|
|
|
944
|
+ Assert.assertEquals(device.getUuidId().getLeastSignificantBits(), latestEntityDataMsg.getEntityIdLSB());
|
|
|
945
|
+ Assert.assertEquals(device.getId().getEntityType().name(), latestEntityDataMsg.getEntityType());
|
|
|
946
|
+ Assert.assertEquals("SERVER_SCOPE", latestEntityDataMsg.getPostAttributeScope());
|
|
|
947
|
+ Assert.assertTrue(latestEntityDataMsg.hasAttributesUpdatedMsg());
|
|
|
948
|
+
|
|
|
949
|
+ TransportProtos.PostAttributeMsg attributesUpdatedMsg = latestEntityDataMsg.getAttributesUpdatedMsg();
|
|
|
950
|
+ Assert.assertEquals(1, attributesUpdatedMsg.getKvCount());
|
|
|
951
|
+ TransportProtos.KeyValueProto keyValueProto = attributesUpdatedMsg.getKv(0);
|
|
|
952
|
+ Assert.assertEquals("key1", keyValueProto.getKey());
|
|
|
953
|
+ Assert.assertEquals("value1", keyValueProto.getStringV());
|
793
|
}
|
954
|
}
|
794
|
|
955
|
|
795
|
private void testSendMessagesToCloud() throws Exception {
|
956
|
private void testSendMessagesToCloud() throws Exception {
|
796
|
log.info("Sending messages to cloud");
|
957
|
log.info("Sending messages to cloud");
|
797
|
sendDevice();
|
958
|
sendDevice();
|
|
|
959
|
+ sendRelationRequest();
|
798
|
sendAlarm();
|
960
|
sendAlarm();
|
799
|
sendTelemetry();
|
961
|
sendTelemetry();
|
800
|
sendRelation();
|
962
|
sendRelation();
|
|
@@ -802,22 +964,30 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -802,22 +964,30 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
802
|
sendRuleChainMetadataRequest();
|
964
|
sendRuleChainMetadataRequest();
|
803
|
sendUserCredentialsRequest();
|
965
|
sendUserCredentialsRequest();
|
804
|
sendDeviceCredentialsRequest();
|
966
|
sendDeviceCredentialsRequest();
|
|
|
967
|
+ sendDeviceRpcResponse();
|
|
|
968
|
+ sendDeviceCredentialsUpdate();
|
|
|
969
|
+ sendAttributesRequest();
|
805
|
log.info("Messages were sent successfully");
|
970
|
log.info("Messages were sent successfully");
|
806
|
}
|
971
|
}
|
807
|
|
972
|
|
808
|
private void sendDevice() throws Exception {
|
973
|
private void sendDevice() throws Exception {
|
809
|
UUID uuid = UUIDs.timeBased();
|
974
|
UUID uuid = UUIDs.timeBased();
|
810
|
|
975
|
|
811
|
- UplinkMsg.Builder builder = UplinkMsg.newBuilder();
|
976
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
812
|
DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder();
|
977
|
DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder();
|
813
|
deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits());
|
978
|
deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits());
|
814
|
deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits());
|
979
|
deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits());
|
815
|
deviceUpdateMsgBuilder.setName("Edge Device 2");
|
980
|
deviceUpdateMsgBuilder.setName("Edge Device 2");
|
816
|
deviceUpdateMsgBuilder.setType("test");
|
981
|
deviceUpdateMsgBuilder.setType("test");
|
817
|
deviceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE);
|
982
|
deviceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE);
|
818
|
- builder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build());
|
983
|
+ testAutoGeneratedCodeByProtobuf(deviceUpdateMsgBuilder);
|
|
|
984
|
+ uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build());
|
|
|
985
|
+
|
819
|
edgeImitator.expectResponsesAmount(1);
|
986
|
edgeImitator.expectResponsesAmount(1);
|
820
|
- edgeImitator.sendUplinkMsg(builder.build());
|
987
|
+
|
|
|
988
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
989
|
+
|
|
|
990
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
821
|
edgeImitator.waitForResponses();
|
991
|
edgeImitator.waitForResponses();
|
822
|
|
992
|
|
823
|
Device device = doGet("/api/device/" + uuid.toString(), Device.class);
|
993
|
Device device = doGet("/api/device/" + uuid.toString(), Device.class);
|
|
@@ -825,23 +995,70 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -825,23 +995,70 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
825
|
Assert.assertEquals("Edge Device 2", device.getName());
|
995
|
Assert.assertEquals("Edge Device 2", device.getName());
|
826
|
}
|
996
|
}
|
827
|
|
997
|
|
|
|
998
|
+ private void sendRelationRequest() throws Exception {
|
|
|
999
|
+ Device device = findDeviceByName("Edge Device 1");
|
|
|
1000
|
+ Asset asset = findAssetByName("Edge Asset 1");
|
|
|
1001
|
+
|
|
|
1002
|
+ EntityRelation relation = new EntityRelation();
|
|
|
1003
|
+ relation.setType("test");
|
|
|
1004
|
+ relation.setFrom(device.getId());
|
|
|
1005
|
+ relation.setTo(asset.getId());
|
|
|
1006
|
+ relation.setTypeGroup(RelationTypeGroup.COMMON);
|
|
|
1007
|
+
|
|
|
1008
|
+ edgeImitator.expectMessageAmount(1);
|
|
|
1009
|
+ doPost("/api/relation", relation);
|
|
|
1010
|
+ edgeImitator.waitForMessages();
|
|
|
1011
|
+
|
|
|
1012
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
|
|
1013
|
+ RelationRequestMsg.Builder relationRequestMsgBuilder = RelationRequestMsg.newBuilder();
|
|
|
1014
|
+ relationRequestMsgBuilder.setEntityIdMSB(device.getId().getId().getMostSignificantBits());
|
|
|
1015
|
+ relationRequestMsgBuilder.setEntityIdLSB(device.getId().getId().getLeastSignificantBits());
|
|
|
1016
|
+ relationRequestMsgBuilder.setEntityType(device.getId().getEntityType().name());
|
|
|
1017
|
+ testAutoGeneratedCodeByProtobuf(relationRequestMsgBuilder);
|
|
|
1018
|
+
|
|
|
1019
|
+ uplinkMsgBuilder.addRelationRequestMsg(relationRequestMsgBuilder.build());
|
|
|
1020
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
1021
|
+
|
|
|
1022
|
+ edgeImitator.expectResponsesAmount(1);
|
|
|
1023
|
+ edgeImitator.expectMessageAmount(1);
|
|
|
1024
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
|
|
1025
|
+ edgeImitator.waitForResponses();
|
|
|
1026
|
+ edgeImitator.waitForMessages();
|
|
|
1027
|
+
|
|
|
1028
|
+ AbstractMessage latestMessage = edgeImitator.getLatestMessage();
|
|
|
1029
|
+ Assert.assertTrue(latestMessage instanceof RelationUpdateMsg);
|
|
|
1030
|
+ RelationUpdateMsg relationUpdateMsg = (RelationUpdateMsg) latestMessage;
|
|
|
1031
|
+ Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, relationUpdateMsg.getMsgType());
|
|
|
1032
|
+ Assert.assertEquals(relation.getType(), relationUpdateMsg.getType());
|
|
|
1033
|
+
|
|
|
1034
|
+ UUID fromUUID = new UUID(relationUpdateMsg.getFromIdMSB(), relationUpdateMsg.getFromIdLSB());
|
|
|
1035
|
+ EntityId fromEntityId = EntityIdFactory.getByTypeAndUuid(relationUpdateMsg.getFromEntityType(), fromUUID);
|
|
|
1036
|
+ Assert.assertEquals(relation.getFrom(), fromEntityId);
|
|
|
1037
|
+
|
|
|
1038
|
+ UUID toUUID = new UUID(relationUpdateMsg.getToIdMSB(), relationUpdateMsg.getToIdLSB());
|
|
|
1039
|
+ EntityId toEntityId = EntityIdFactory.getByTypeAndUuid(relationUpdateMsg.getToEntityType(), toUUID);
|
|
|
1040
|
+ Assert.assertEquals(relation.getTo(), toEntityId);
|
|
|
1041
|
+
|
|
|
1042
|
+ Assert.assertEquals(relation.getTypeGroup().name(), relationUpdateMsg.getTypeGroup());
|
|
|
1043
|
+ }
|
|
|
1044
|
+
|
828
|
private void sendAlarm() throws Exception {
|
1045
|
private void sendAlarm() throws Exception {
|
829
|
- List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
830
|
- new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
|
|
831
|
- Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny();
|
|
|
832
|
- Assert.assertTrue(foundDevice.isPresent());
|
|
|
833
|
- Device device = foundDevice.get();
|
1046
|
+ Device device = findDeviceByName("Edge Device 2");
|
834
|
|
1047
|
|
835
|
- UplinkMsg.Builder builder = UplinkMsg.newBuilder();
|
1048
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
836
|
AlarmUpdateMsg.Builder alarmUpdateMgBuilder = AlarmUpdateMsg.newBuilder();
|
1049
|
AlarmUpdateMsg.Builder alarmUpdateMgBuilder = AlarmUpdateMsg.newBuilder();
|
837
|
alarmUpdateMgBuilder.setName("alarm from edge");
|
1050
|
alarmUpdateMgBuilder.setName("alarm from edge");
|
838
|
alarmUpdateMgBuilder.setStatus(AlarmStatus.ACTIVE_UNACK.name());
|
1051
|
alarmUpdateMgBuilder.setStatus(AlarmStatus.ACTIVE_UNACK.name());
|
839
|
alarmUpdateMgBuilder.setSeverity(AlarmSeverity.CRITICAL.name());
|
1052
|
alarmUpdateMgBuilder.setSeverity(AlarmSeverity.CRITICAL.name());
|
840
|
alarmUpdateMgBuilder.setOriginatorName(device.getName());
|
1053
|
alarmUpdateMgBuilder.setOriginatorName(device.getName());
|
841
|
alarmUpdateMgBuilder.setOriginatorType(EntityType.DEVICE.name());
|
1054
|
alarmUpdateMgBuilder.setOriginatorType(EntityType.DEVICE.name());
|
842
|
- builder.addAlarmUpdateMsg(alarmUpdateMgBuilder.build());
|
1055
|
+ testAutoGeneratedCodeByProtobuf(alarmUpdateMgBuilder);
|
|
|
1056
|
+ uplinkMsgBuilder.addAlarmUpdateMsg(alarmUpdateMgBuilder.build());
|
|
|
1057
|
+
|
|
|
1058
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
1059
|
+
|
843
|
edgeImitator.expectResponsesAmount(1);
|
1060
|
edgeImitator.expectResponsesAmount(1);
|
844
|
- edgeImitator.sendUplinkMsg(builder.build());
|
1061
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
845
|
edgeImitator.waitForResponses();
|
1062
|
edgeImitator.waitForResponses();
|
846
|
|
1063
|
|
847
|
|
1064
|
|
|
@@ -867,7 +1084,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -867,7 +1084,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
867
|
Assert.assertTrue(foundDevice2.isPresent());
|
1084
|
Assert.assertTrue(foundDevice2.isPresent());
|
868
|
Device device2 = foundDevice2.get();
|
1085
|
Device device2 = foundDevice2.get();
|
869
|
|
1086
|
|
870
|
- UplinkMsg.Builder builder = UplinkMsg.newBuilder();
|
1087
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
871
|
RelationUpdateMsg.Builder relationUpdateMsgBuilder = RelationUpdateMsg.newBuilder();
|
1088
|
RelationUpdateMsg.Builder relationUpdateMsgBuilder = RelationUpdateMsg.newBuilder();
|
872
|
relationUpdateMsgBuilder.setType("test");
|
1089
|
relationUpdateMsgBuilder.setType("test");
|
873
|
relationUpdateMsgBuilder.setTypeGroup(RelationTypeGroup.COMMON.name());
|
1090
|
relationUpdateMsgBuilder.setTypeGroup(RelationTypeGroup.COMMON.name());
|
|
@@ -878,10 +1095,13 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -878,10 +1095,13 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
878
|
relationUpdateMsgBuilder.setFromIdLSB(device2.getId().getId().getLeastSignificantBits());
|
1095
|
relationUpdateMsgBuilder.setFromIdLSB(device2.getId().getId().getLeastSignificantBits());
|
879
|
relationUpdateMsgBuilder.setFromEntityType(device2.getId().getEntityType().name());
|
1096
|
relationUpdateMsgBuilder.setFromEntityType(device2.getId().getEntityType().name());
|
880
|
relationUpdateMsgBuilder.setAdditionalInfo("{}");
|
1097
|
relationUpdateMsgBuilder.setAdditionalInfo("{}");
|
881
|
- builder.addRelationUpdateMsg(relationUpdateMsgBuilder.build());
|
|
|
882
|
- UplinkMsg msg = builder.build();
|
1098
|
+ testAutoGeneratedCodeByProtobuf(relationUpdateMsgBuilder);
|
|
|
1099
|
+ uplinkMsgBuilder.addRelationUpdateMsg(relationUpdateMsgBuilder.build());
|
|
|
1100
|
+
|
|
|
1101
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
1102
|
+
|
883
|
edgeImitator.expectResponsesAmount(1);
|
1103
|
edgeImitator.expectResponsesAmount(1);
|
884
|
- edgeImitator.sendUplinkMsg(msg);
|
1104
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
885
|
edgeImitator.waitForResponses();
|
1105
|
edgeImitator.waitForResponses();
|
886
|
|
1106
|
|
887
|
EntityRelation relation = doGet("/api/relation?" +
|
1107
|
EntityRelation relation = doGet("/api/relation?" +
|
|
@@ -907,28 +1127,35 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -907,28 +1127,35 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
907
|
String timeseriesKey = "key";
|
1127
|
String timeseriesKey = "key";
|
908
|
String timeseriesValue = "25";
|
1128
|
String timeseriesValue = "25";
|
909
|
data.addProperty(timeseriesKey, timeseriesValue);
|
1129
|
data.addProperty(timeseriesKey, timeseriesValue);
|
910
|
- UplinkMsg.Builder builder1 = UplinkMsg.newBuilder();
|
1130
|
+ UplinkMsg.Builder uplinkMsgBuilder1 = UplinkMsg.newBuilder();
|
911
|
EntityDataProto.Builder entityDataBuilder = EntityDataProto.newBuilder();
|
1131
|
EntityDataProto.Builder entityDataBuilder = EntityDataProto.newBuilder();
|
912
|
entityDataBuilder.setPostTelemetryMsg(JsonConverter.convertToTelemetryProto(data, System.currentTimeMillis()));
|
1132
|
entityDataBuilder.setPostTelemetryMsg(JsonConverter.convertToTelemetryProto(data, System.currentTimeMillis()));
|
913
|
entityDataBuilder.setEntityType(device.getId().getEntityType().name());
|
1133
|
entityDataBuilder.setEntityType(device.getId().getEntityType().name());
|
914
|
entityDataBuilder.setEntityIdMSB(device.getUuidId().getMostSignificantBits());
|
1134
|
entityDataBuilder.setEntityIdMSB(device.getUuidId().getMostSignificantBits());
|
915
|
entityDataBuilder.setEntityIdLSB(device.getUuidId().getLeastSignificantBits());
|
1135
|
entityDataBuilder.setEntityIdLSB(device.getUuidId().getLeastSignificantBits());
|
916
|
- builder1.addEntityData(entityDataBuilder.build());
|
|
|
917
|
- edgeImitator.sendUplinkMsg(builder1.build());
|
1136
|
+ testAutoGeneratedCodeByProtobuf(entityDataBuilder);
|
|
|
1137
|
+ uplinkMsgBuilder1.addEntityData(entityDataBuilder.build());
|
|
|
1138
|
+
|
|
|
1139
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder1);
|
|
|
1140
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder1.build());
|
918
|
|
1141
|
|
919
|
JsonObject attributesData = new JsonObject();
|
1142
|
JsonObject attributesData = new JsonObject();
|
920
|
String attributesKey = "test_attr";
|
1143
|
String attributesKey = "test_attr";
|
921
|
String attributesValue = "test_value";
|
1144
|
String attributesValue = "test_value";
|
922
|
attributesData.addProperty(attributesKey, attributesValue);
|
1145
|
attributesData.addProperty(attributesKey, attributesValue);
|
923
|
- UplinkMsg.Builder builder2 = UplinkMsg.newBuilder();
|
1146
|
+ UplinkMsg.Builder uplinkMsgBuilder2 = UplinkMsg.newBuilder();
|
924
|
EntityDataProto.Builder entityDataBuilder2 = EntityDataProto.newBuilder();
|
1147
|
EntityDataProto.Builder entityDataBuilder2 = EntityDataProto.newBuilder();
|
925
|
entityDataBuilder2.setEntityType(device.getId().getEntityType().name());
|
1148
|
entityDataBuilder2.setEntityType(device.getId().getEntityType().name());
|
926
|
entityDataBuilder2.setEntityIdMSB(device.getId().getId().getMostSignificantBits());
|
1149
|
entityDataBuilder2.setEntityIdMSB(device.getId().getId().getMostSignificantBits());
|
927
|
entityDataBuilder2.setEntityIdLSB(device.getId().getId().getLeastSignificantBits());
|
1150
|
entityDataBuilder2.setEntityIdLSB(device.getId().getId().getLeastSignificantBits());
|
928
|
entityDataBuilder2.setAttributesUpdatedMsg(JsonConverter.convertToAttributesProto(attributesData));
|
1151
|
entityDataBuilder2.setAttributesUpdatedMsg(JsonConverter.convertToAttributesProto(attributesData));
|
929
|
entityDataBuilder2.setPostAttributeScope(DataConstants.SERVER_SCOPE);
|
1152
|
entityDataBuilder2.setPostAttributeScope(DataConstants.SERVER_SCOPE);
|
930
|
- builder2.addEntityData(entityDataBuilder2.build());
|
|
|
931
|
- edgeImitator.sendUplinkMsg(builder2.build());
|
1153
|
+ testAutoGeneratedCodeByProtobuf(entityDataBuilder2);
|
|
|
1154
|
+
|
|
|
1155
|
+ uplinkMsgBuilder2.addEntityData(entityDataBuilder2.build());
|
|
|
1156
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder2);
|
|
|
1157
|
+
|
|
|
1158
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder2.build());
|
932
|
edgeImitator.waitForResponses();
|
1159
|
edgeImitator.waitForResponses();
|
933
|
|
1160
|
|
934
|
Thread.sleep(1000);
|
1161
|
Thread.sleep(1000);
|
|
@@ -947,14 +1174,18 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -947,14 +1174,18 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
947
|
private void sendRuleChainMetadataRequest() throws Exception {
|
1174
|
private void sendRuleChainMetadataRequest() throws Exception {
|
948
|
RuleChainId edgeRootRuleChainId = edge.getRootRuleChainId();
|
1175
|
RuleChainId edgeRootRuleChainId = edge.getRootRuleChainId();
|
949
|
|
1176
|
|
950
|
- UplinkMsg.Builder builder = UplinkMsg.newBuilder();
|
1177
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
951
|
RuleChainMetadataRequestMsg.Builder ruleChainMetadataRequestMsgBuilder = RuleChainMetadataRequestMsg.newBuilder();
|
1178
|
RuleChainMetadataRequestMsg.Builder ruleChainMetadataRequestMsgBuilder = RuleChainMetadataRequestMsg.newBuilder();
|
952
|
ruleChainMetadataRequestMsgBuilder.setRuleChainIdMSB(edgeRootRuleChainId.getId().getMostSignificantBits());
|
1179
|
ruleChainMetadataRequestMsgBuilder.setRuleChainIdMSB(edgeRootRuleChainId.getId().getMostSignificantBits());
|
953
|
ruleChainMetadataRequestMsgBuilder.setRuleChainIdLSB(edgeRootRuleChainId.getId().getLeastSignificantBits());
|
1180
|
ruleChainMetadataRequestMsgBuilder.setRuleChainIdLSB(edgeRootRuleChainId.getId().getLeastSignificantBits());
|
954
|
- builder.addRuleChainMetadataRequestMsg(ruleChainMetadataRequestMsgBuilder.build());
|
1181
|
+ testAutoGeneratedCodeByProtobuf(ruleChainMetadataRequestMsgBuilder);
|
|
|
1182
|
+ uplinkMsgBuilder.addRuleChainMetadataRequestMsg(ruleChainMetadataRequestMsgBuilder.build());
|
|
|
1183
|
+
|
|
|
1184
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
1185
|
+
|
955
|
edgeImitator.expectResponsesAmount(1);
|
1186
|
edgeImitator.expectResponsesAmount(1);
|
956
|
edgeImitator.expectMessageAmount(1);
|
1187
|
edgeImitator.expectMessageAmount(1);
|
957
|
- edgeImitator.sendUplinkMsg(builder.build());
|
1188
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
958
|
edgeImitator.waitForResponses();
|
1189
|
edgeImitator.waitForResponses();
|
959
|
edgeImitator.waitForMessages();
|
1190
|
edgeImitator.waitForMessages();
|
960
|
|
1191
|
|
|
@@ -963,19 +1194,25 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -963,19 +1194,25 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
963
|
RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = (RuleChainMetadataUpdateMsg) latestMessage;
|
1194
|
RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = (RuleChainMetadataUpdateMsg) latestMessage;
|
964
|
Assert.assertEquals(ruleChainMetadataUpdateMsg.getRuleChainIdMSB(), edgeRootRuleChainId.getId().getMostSignificantBits());
|
1195
|
Assert.assertEquals(ruleChainMetadataUpdateMsg.getRuleChainIdMSB(), edgeRootRuleChainId.getId().getMostSignificantBits());
|
965
|
Assert.assertEquals(ruleChainMetadataUpdateMsg.getRuleChainIdLSB(), edgeRootRuleChainId.getId().getLeastSignificantBits());
|
1196
|
Assert.assertEquals(ruleChainMetadataUpdateMsg.getRuleChainIdLSB(), edgeRootRuleChainId.getId().getLeastSignificantBits());
|
|
|
1197
|
+
|
|
|
1198
|
+ testAutoGeneratedCodeByProtobuf(ruleChainMetadataUpdateMsg);
|
966
|
}
|
1199
|
}
|
967
|
|
1200
|
|
968
|
private void sendUserCredentialsRequest() throws Exception {
|
1201
|
private void sendUserCredentialsRequest() throws Exception {
|
969
|
UserId userId = edgeImitator.getUserId();
|
1202
|
UserId userId = edgeImitator.getUserId();
|
970
|
|
1203
|
|
971
|
- UplinkMsg.Builder builder = UplinkMsg.newBuilder();
|
1204
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
972
|
UserCredentialsRequestMsg.Builder userCredentialsRequestMsgBuilder = UserCredentialsRequestMsg.newBuilder();
|
1205
|
UserCredentialsRequestMsg.Builder userCredentialsRequestMsgBuilder = UserCredentialsRequestMsg.newBuilder();
|
973
|
userCredentialsRequestMsgBuilder.setUserIdMSB(userId.getId().getMostSignificantBits());
|
1206
|
userCredentialsRequestMsgBuilder.setUserIdMSB(userId.getId().getMostSignificantBits());
|
974
|
userCredentialsRequestMsgBuilder.setUserIdLSB(userId.getId().getLeastSignificantBits());
|
1207
|
userCredentialsRequestMsgBuilder.setUserIdLSB(userId.getId().getLeastSignificantBits());
|
975
|
- builder.addUserCredentialsRequestMsg(userCredentialsRequestMsgBuilder.build());
|
1208
|
+ testAutoGeneratedCodeByProtobuf(userCredentialsRequestMsgBuilder);
|
|
|
1209
|
+ uplinkMsgBuilder.addUserCredentialsRequestMsg(userCredentialsRequestMsgBuilder.build());
|
|
|
1210
|
+
|
|
|
1211
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
1212
|
+
|
976
|
edgeImitator.expectResponsesAmount(1);
|
1213
|
edgeImitator.expectResponsesAmount(1);
|
977
|
edgeImitator.expectMessageAmount(1);
|
1214
|
edgeImitator.expectMessageAmount(1);
|
978
|
- edgeImitator.sendUplinkMsg(builder.build());
|
1215
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
979
|
edgeImitator.waitForResponses();
|
1216
|
edgeImitator.waitForResponses();
|
980
|
edgeImitator.waitForMessages();
|
1217
|
edgeImitator.waitForMessages();
|
981
|
|
1218
|
|
|
@@ -984,26 +1221,27 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -984,26 +1221,27 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
984
|
UserCredentialsUpdateMsg userCredentialsUpdateMsg = (UserCredentialsUpdateMsg) latestMessage;
|
1221
|
UserCredentialsUpdateMsg userCredentialsUpdateMsg = (UserCredentialsUpdateMsg) latestMessage;
|
985
|
Assert.assertEquals(userCredentialsUpdateMsg.getUserIdMSB(), userId.getId().getMostSignificantBits());
|
1222
|
Assert.assertEquals(userCredentialsUpdateMsg.getUserIdMSB(), userId.getId().getMostSignificantBits());
|
986
|
Assert.assertEquals(userCredentialsUpdateMsg.getUserIdLSB(), userId.getId().getLeastSignificantBits());
|
1223
|
Assert.assertEquals(userCredentialsUpdateMsg.getUserIdLSB(), userId.getId().getLeastSignificantBits());
|
|
|
1224
|
+
|
|
|
1225
|
+ testAutoGeneratedCodeByProtobuf(userCredentialsUpdateMsg);
|
987
|
}
|
1226
|
}
|
988
|
|
1227
|
|
989
|
private void sendDeviceCredentialsRequest() throws Exception {
|
1228
|
private void sendDeviceCredentialsRequest() throws Exception {
|
990
|
- List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
991
|
- new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
|
|
992
|
- Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 1")).findAny();
|
|
|
993
|
- Assert.assertTrue(foundDevice.isPresent());
|
|
|
994
|
- Device device = foundDevice.get();
|
1229
|
+ Device device = findDeviceByName("Edge Device 1");
|
995
|
|
1230
|
|
996
|
DeviceCredentials deviceCredentials = doGet("/api/device/" + device.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
1231
|
DeviceCredentials deviceCredentials = doGet("/api/device/" + device.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
997
|
|
1232
|
|
998
|
- UplinkMsg.Builder builder = UplinkMsg.newBuilder();
|
1233
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
999
|
DeviceCredentialsRequestMsg.Builder deviceCredentialsRequestMsgBuilder = DeviceCredentialsRequestMsg.newBuilder();
|
1234
|
DeviceCredentialsRequestMsg.Builder deviceCredentialsRequestMsgBuilder = DeviceCredentialsRequestMsg.newBuilder();
|
1000
|
deviceCredentialsRequestMsgBuilder.setDeviceIdMSB(device.getUuidId().getMostSignificantBits());
|
1235
|
deviceCredentialsRequestMsgBuilder.setDeviceIdMSB(device.getUuidId().getMostSignificantBits());
|
1001
|
deviceCredentialsRequestMsgBuilder.setDeviceIdLSB(device.getUuidId().getLeastSignificantBits());
|
1236
|
deviceCredentialsRequestMsgBuilder.setDeviceIdLSB(device.getUuidId().getLeastSignificantBits());
|
1002
|
- builder.addDeviceCredentialsRequestMsg(deviceCredentialsRequestMsgBuilder.build());
|
1237
|
+ testAutoGeneratedCodeByProtobuf(deviceCredentialsRequestMsgBuilder);
|
|
|
1238
|
+ uplinkMsgBuilder.addDeviceCredentialsRequestMsg(deviceCredentialsRequestMsgBuilder.build());
|
|
|
1239
|
+
|
|
|
1240
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
1003
|
|
1241
|
|
1004
|
edgeImitator.expectResponsesAmount(1);
|
1242
|
edgeImitator.expectResponsesAmount(1);
|
1005
|
edgeImitator.expectMessageAmount(1);
|
1243
|
edgeImitator.expectMessageAmount(1);
|
1006
|
- edgeImitator.sendUplinkMsg(builder.build());
|
1244
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
1007
|
edgeImitator.waitForResponses();
|
1245
|
edgeImitator.waitForResponses();
|
1008
|
edgeImitator.waitForMessages();
|
1246
|
edgeImitator.waitForMessages();
|
1009
|
|
1247
|
|
|
@@ -1016,20 +1254,108 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -1016,20 +1254,108 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
1016
|
Assert.assertEquals(deviceCredentialsUpdateMsg.getCredentialsId(), deviceCredentials.getCredentialsId());
|
1254
|
Assert.assertEquals(deviceCredentialsUpdateMsg.getCredentialsId(), deviceCredentials.getCredentialsId());
|
1017
|
}
|
1255
|
}
|
1018
|
|
1256
|
|
|
|
1257
|
+ private void sendDeviceCredentialsUpdate() throws Exception {
|
|
|
1258
|
+ Device device = findDeviceByName("Edge Device 1");
|
|
|
1259
|
+
|
|
|
1260
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
|
|
1261
|
+ DeviceCredentialsUpdateMsg.Builder deviceCredentialsUpdateMsgBuilder = DeviceCredentialsUpdateMsg.newBuilder();
|
|
|
1262
|
+ deviceCredentialsUpdateMsgBuilder.setDeviceIdMSB(device.getUuidId().getMostSignificantBits());
|
|
|
1263
|
+ deviceCredentialsUpdateMsgBuilder.setDeviceIdLSB(device.getUuidId().getLeastSignificantBits());
|
|
|
1264
|
+ deviceCredentialsUpdateMsgBuilder.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN.name());
|
|
|
1265
|
+ deviceCredentialsUpdateMsgBuilder.setCredentialsId("NEW_TOKEN");
|
|
|
1266
|
+ testAutoGeneratedCodeByProtobuf(deviceCredentialsUpdateMsgBuilder);
|
|
|
1267
|
+ uplinkMsgBuilder.addDeviceCredentialsUpdateMsg(deviceCredentialsUpdateMsgBuilder.build());
|
|
|
1268
|
+
|
|
|
1269
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
1270
|
+
|
|
|
1271
|
+ edgeImitator.expectResponsesAmount(1);
|
|
|
1272
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
|
|
1273
|
+ edgeImitator.waitForResponses();
|
|
|
1274
|
+ }
|
|
|
1275
|
+
|
|
|
1276
|
+ private void sendDeviceRpcResponse() throws Exception {
|
|
|
1277
|
+ Device device = findDeviceByName("Edge Device 1");
|
|
|
1278
|
+
|
|
|
1279
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
|
|
1280
|
+ DeviceRpcCallMsg.Builder deviceRpcCallResponseBuilder = DeviceRpcCallMsg.newBuilder();
|
|
|
1281
|
+ deviceRpcCallResponseBuilder.setDeviceIdMSB(device.getUuidId().getMostSignificantBits());
|
|
|
1282
|
+ deviceRpcCallResponseBuilder.setDeviceIdLSB(device.getUuidId().getLeastSignificantBits());
|
|
|
1283
|
+ deviceRpcCallResponseBuilder.setOneway(true);
|
|
|
1284
|
+ deviceRpcCallResponseBuilder.setOriginServiceId("originServiceId");
|
|
|
1285
|
+ deviceRpcCallResponseBuilder.setExpirationTime(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10));
|
|
|
1286
|
+ RpcResponseMsg.Builder responseBuilder =
|
|
|
1287
|
+ RpcResponseMsg.newBuilder().setResponse("{}");
|
|
|
1288
|
+ testAutoGeneratedCodeByProtobuf(responseBuilder);
|
|
|
1289
|
+
|
|
|
1290
|
+ deviceRpcCallResponseBuilder.setResponseMsg(responseBuilder.build());
|
|
|
1291
|
+ testAutoGeneratedCodeByProtobuf(deviceRpcCallResponseBuilder);
|
|
|
1292
|
+
|
|
|
1293
|
+ uplinkMsgBuilder.addDeviceRpcCallMsg(deviceRpcCallResponseBuilder.build());
|
|
|
1294
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
1295
|
+
|
|
|
1296
|
+ edgeImitator.expectResponsesAmount(1);
|
|
|
1297
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
|
|
1298
|
+ edgeImitator.waitForResponses();
|
|
|
1299
|
+ }
|
|
|
1300
|
+
|
|
|
1301
|
+ private void sendAttributesRequest() throws Exception {
|
|
|
1302
|
+ Device device = findDeviceByName("Edge Device 1");
|
|
|
1303
|
+
|
|
|
1304
|
+ String attributesDataStr = "{\"key1\":\"value1\"}";
|
|
|
1305
|
+ JsonNode attributesData = mapper.readTree(attributesDataStr);
|
|
|
1306
|
+
|
|
|
1307
|
+ doPost("/api/plugins/telemetry/DEVICE/" + device.getId().getId().toString() + "/attributes/" + DataConstants.SERVER_SCOPE,
|
|
|
1308
|
+ attributesData);
|
|
|
1309
|
+
|
|
|
1310
|
+ UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
|
|
|
1311
|
+ AttributesRequestMsg.Builder attributesRequestMsgBuilder = AttributesRequestMsg.newBuilder();
|
|
|
1312
|
+ attributesRequestMsgBuilder.setEntityIdMSB(device.getUuidId().getMostSignificantBits());
|
|
|
1313
|
+ attributesRequestMsgBuilder.setEntityIdLSB(device.getUuidId().getLeastSignificantBits());
|
|
|
1314
|
+ attributesRequestMsgBuilder.setEntityType(EntityType.DEVICE.name());
|
|
|
1315
|
+ testAutoGeneratedCodeByProtobuf(attributesRequestMsgBuilder);
|
|
|
1316
|
+ uplinkMsgBuilder.addAttributesRequestMsg(attributesRequestMsgBuilder.build());
|
|
|
1317
|
+ testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder);
|
|
|
1318
|
+
|
|
|
1319
|
+ edgeImitator.expectResponsesAmount(1);
|
|
|
1320
|
+ edgeImitator.expectMessageAmount(1);
|
|
|
1321
|
+ edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
|
|
|
1322
|
+ edgeImitator.waitForResponses();
|
|
|
1323
|
+ edgeImitator.waitForMessages();
|
|
|
1324
|
+
|
|
|
1325
|
+ AbstractMessage latestMessage = edgeImitator.getLatestMessage();
|
|
|
1326
|
+ Assert.assertTrue(latestMessage instanceof EntityDataProto);
|
|
|
1327
|
+ EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
|
|
|
1328
|
+ Assert.assertEquals(device.getUuidId().getMostSignificantBits(), latestEntityDataMsg.getEntityIdMSB());
|
|
|
1329
|
+ Assert.assertEquals(device.getUuidId().getLeastSignificantBits(), latestEntityDataMsg.getEntityIdLSB());
|
|
|
1330
|
+ Assert.assertEquals(device.getId().getEntityType().name(), latestEntityDataMsg.getEntityType());
|
|
|
1331
|
+ Assert.assertEquals("SERVER_SCOPE", latestEntityDataMsg.getPostAttributeScope());
|
|
|
1332
|
+ Assert.assertTrue(latestEntityDataMsg.hasAttributesUpdatedMsg());
|
|
|
1333
|
+
|
|
|
1334
|
+ TransportProtos.PostAttributeMsg attributesUpdatedMsg = latestEntityDataMsg.getAttributesUpdatedMsg();
|
|
|
1335
|
+ Assert.assertEquals(1, attributesUpdatedMsg.getKvCount());
|
|
|
1336
|
+ TransportProtos.KeyValueProto keyValueProto = attributesUpdatedMsg.getKv(0);
|
|
|
1337
|
+ Assert.assertEquals("key1", keyValueProto.getKey());
|
|
|
1338
|
+ Assert.assertEquals("value1", keyValueProto.getStringV());
|
|
|
1339
|
+ }
|
|
|
1340
|
+
|
1019
|
private void sendDeleteDeviceOnEdge() throws Exception {
|
1341
|
private void sendDeleteDeviceOnEdge() throws Exception {
|
1020
|
List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
1342
|
List<Device> edgeDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
1021
|
new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
1343
|
new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100)).getData();
|
1022
|
Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny();
|
1344
|
Optional<Device> foundDevice = edgeDevices.stream().filter(device1 -> device1.getName().equals("Edge Device 2")).findAny();
|
1023
|
Assert.assertTrue(foundDevice.isPresent());
|
1345
|
Assert.assertTrue(foundDevice.isPresent());
|
1024
|
Device device = foundDevice.get();
|
1346
|
Device device = foundDevice.get();
|
1025
|
- UplinkMsg.Builder builder = UplinkMsg.newBuilder();
|
1347
|
+ UplinkMsg.Builder upLinkMsgBuilder = UplinkMsg.newBuilder();
|
1026
|
DeviceUpdateMsg.Builder deviceDeleteMsgBuilder = DeviceUpdateMsg.newBuilder();
|
1348
|
DeviceUpdateMsg.Builder deviceDeleteMsgBuilder = DeviceUpdateMsg.newBuilder();
|
1027
|
deviceDeleteMsgBuilder.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE);
|
1349
|
deviceDeleteMsgBuilder.setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE);
|
1028
|
deviceDeleteMsgBuilder.setIdMSB(device.getId().getId().getMostSignificantBits());
|
1350
|
deviceDeleteMsgBuilder.setIdMSB(device.getId().getId().getMostSignificantBits());
|
1029
|
deviceDeleteMsgBuilder.setIdLSB(device.getId().getId().getLeastSignificantBits());
|
1351
|
deviceDeleteMsgBuilder.setIdLSB(device.getId().getId().getLeastSignificantBits());
|
1030
|
- builder.addDeviceUpdateMsg(deviceDeleteMsgBuilder.build());
|
1352
|
+ testAutoGeneratedCodeByProtobuf(deviceDeleteMsgBuilder);
|
|
|
1353
|
+
|
|
|
1354
|
+ upLinkMsgBuilder.addDeviceUpdateMsg(deviceDeleteMsgBuilder.build());
|
|
|
1355
|
+ testAutoGeneratedCodeByProtobuf(upLinkMsgBuilder);
|
|
|
1356
|
+
|
1031
|
edgeImitator.expectResponsesAmount(1);
|
1357
|
edgeImitator.expectResponsesAmount(1);
|
1032
|
- edgeImitator.sendUplinkMsg(builder.build());
|
1358
|
+ edgeImitator.sendUplinkMsg(upLinkMsgBuilder.build());
|
1033
|
edgeImitator.waitForResponses();
|
1359
|
edgeImitator.waitForResponses();
|
1034
|
device = doGet("/api/device/" + device.getId().getId().toString(), Device.class);
|
1360
|
device = doGet("/api/device/" + device.getId().getId().toString(), Device.class);
|
1035
|
Assert.assertNotNull(device);
|
1361
|
Assert.assertNotNull(device);
|
|
@@ -1042,41 +1368,15 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -1042,41 +1368,15 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
1042
|
private void installation() throws Exception {
|
1368
|
private void installation() throws Exception {
|
1043
|
edge = doPost("/api/edge", constructEdge("Test Edge", "test"), Edge.class);
|
1369
|
edge = doPost("/api/edge", constructEdge("Test Edge", "test"), Edge.class);
|
1044
|
|
1370
|
|
1045
|
- Device device = new Device();
|
|
|
1046
|
- device.setName("Edge Device 1");
|
|
|
1047
|
- device.setType("test");
|
|
|
1048
|
- Device savedDevice = doPost("/api/device", device, Device.class);
|
1371
|
+ Device savedDevice = saveDevice("Edge Device 1");
|
1049
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
1372
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
1050
|
+ "/device/" + savedDevice.getId().getId().toString(), Device.class);
|
1373
|
+ "/device/" + savedDevice.getId().getId().toString(), Device.class);
|
1051
|
|
1374
|
|
1052
|
- Asset asset = new Asset();
|
|
|
1053
|
- asset.setName("Edge Asset 1");
|
|
|
1054
|
- asset.setType("test");
|
|
|
1055
|
- Asset savedAsset = doPost("/api/asset", asset, Asset.class);
|
1375
|
+ Asset savedAsset = saveAsset("Edge Asset 1");
|
1056
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
1376
|
doPost("/api/edge/" + edge.getId().getId().toString()
|
1057
|
+ "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
|
1377
|
+ "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
|
1058
|
}
|
1378
|
}
|
1059
|
|
1379
|
|
1060
|
- private void uninstallation() throws Exception {
|
|
|
1061
|
-
|
|
|
1062
|
- TimePageData<Device> pageDataDevices = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/devices?",
|
|
|
1063
|
- new TypeReference<TimePageData<Device>>() {}, new TextPageLink(100));
|
|
|
1064
|
- for (Device device: pageDataDevices.getData()) {
|
|
|
1065
|
- doDelete("/api/device/" + device.getId().getId().toString())
|
|
|
1066
|
- .andExpect(status().isOk());
|
|
|
1067
|
- }
|
|
|
1068
|
-
|
|
|
1069
|
- TimePageData<Asset> pageDataAssets = doGetTypedWithPageLink("/api/edge/" + edge.getId().getId().toString() + "/assets?",
|
|
|
1070
|
- new TypeReference<TimePageData<Asset>>() {}, new TextPageLink(100));
|
|
|
1071
|
- for (Asset asset: pageDataAssets.getData()) {
|
|
|
1072
|
- doDelete("/api/asset/" + asset.getId().getId().toString())
|
|
|
1073
|
- .andExpect(status().isOk());
|
|
|
1074
|
- }
|
|
|
1075
|
-
|
|
|
1076
|
- doDelete("/api/edge/" + edge.getId().getId().toString())
|
|
|
1077
|
- .andExpect(status().isOk());
|
|
|
1078
|
- }
|
|
|
1079
|
-
|
|
|
1080
|
private EdgeEvent constructEdgeEvent(TenantId tenantId, EdgeId edgeId, EdgeEventActionType edgeEventAction, UUID entityId, EdgeEventType edgeEventType, JsonNode entityBody) {
|
1380
|
private EdgeEvent constructEdgeEvent(TenantId tenantId, EdgeId edgeId, EdgeEventActionType edgeEventAction, UUID entityId, EdgeEventType edgeEventType, JsonNode entityBody) {
|
1081
|
EdgeEvent edgeEvent = new EdgeEvent();
|
1381
|
EdgeEvent edgeEvent = new EdgeEvent();
|
1082
|
edgeEvent.setEdgeId(edgeId);
|
1382
|
edgeEvent.setEdgeId(edgeId);
|
|
@@ -1087,4 +1387,19 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
|
@@ -1087,4 +1387,19 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { |
1087
|
edgeEvent.setBody(entityBody);
|
1387
|
edgeEvent.setBody(entityBody);
|
1088
|
return edgeEvent;
|
1388
|
return edgeEvent;
|
1089
|
}
|
1389
|
}
|
|
|
1390
|
+
|
|
|
1391
|
+ private void testAutoGeneratedCodeByProtobuf(MessageLite.Builder builder) throws InvalidProtocolBufferException {
|
|
|
1392
|
+ MessageLite source = builder.build();
|
|
|
1393
|
+
|
|
|
1394
|
+ testAutoGeneratedCodeByProtobuf(source);
|
|
|
1395
|
+
|
|
|
1396
|
+ MessageLite target = source.getParserForType().parseFrom(source.toByteArray());
|
|
|
1397
|
+ builder.clear().mergeFrom(target);
|
|
|
1398
|
+ }
|
|
|
1399
|
+
|
|
|
1400
|
+ private void testAutoGeneratedCodeByProtobuf(MessageLite source) throws InvalidProtocolBufferException {
|
|
|
1401
|
+ MessageLite target = source.getParserForType().parseFrom(source.toByteArray());
|
|
|
1402
|
+ Assert.assertEquals(source, target);
|
|
|
1403
|
+ Assert.assertEquals(source.hashCode(), target.hashCode());
|
|
|
1404
|
+ }
|
1090
|
} |
1405
|
} |