iotagent-node-lib 3.4.3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/CHANGES_NEXT_RELEASE +0 -1
  2. package/README.md +4 -0
  3. package/doc/admin.md +1 -13
  4. package/doc/api.md +118 -14
  5. package/doc/devel/architecture.md +0 -12
  6. package/doc/index.md +1 -1
  7. package/doc/roadmap.md +22 -10
  8. package/lib/commonConfig.js +0 -11
  9. package/lib/model/Device.js +2 -1
  10. package/lib/model/Group.js +2 -1
  11. package/lib/model/dbConn.js +22 -11
  12. package/lib/plugins/expressionPlugin.js +0 -5
  13. package/lib/plugins/jexlParser.js +15 -31
  14. package/lib/services/common/genericMiddleware.js +14 -2
  15. package/lib/services/common/iotManagerService.js +2 -1
  16. package/lib/services/devices/deviceRegistryMongoDB.js +3 -1
  17. package/lib/services/devices/deviceService.js +16 -21
  18. package/lib/services/devices/devices-NGSI-LD.js +5 -98
  19. package/lib/services/devices/devices-NGSI-mixed.js +0 -14
  20. package/lib/services/devices/devices-NGSI-v2.js +3 -0
  21. package/lib/services/groups/groupRegistryMemory.js +0 -25
  22. package/lib/services/groups/groupRegistryMongoDB.js +20 -19
  23. package/lib/services/groups/groupService.js +3 -14
  24. package/lib/services/ngsi/entities-NGSI-LD.js +81 -6
  25. package/lib/services/ngsi/entities-NGSI-v2.js +304 -687
  26. package/lib/services/ngsi/ngsiUtils.js +0 -30
  27. package/lib/services/northBound/deviceProvisioningServer.js +6 -3
  28. package/lib/templates/createDevice.json +4 -0
  29. package/lib/templates/createDeviceLax.json +4 -0
  30. package/lib/templates/deviceGroup.json +4 -0
  31. package/lib/templates/updateDevice.json +4 -0
  32. package/lib/templates/updateDeviceLax.json +4 -0
  33. package/package.json +6 -2
  34. package/test/functional/README.md +378 -0
  35. package/test/functional/config-test.js +70 -0
  36. package/test/functional/functional-tests-runner.js +126 -0
  37. package/test/functional/functional-tests.js +241 -0
  38. package/test/functional/testCases.js +2944 -0
  39. package/test/functional/testUtils.js +251 -0
  40. package/test/tools/utils.js +25 -0
  41. package/test/unit/mongodb/mongodb-connectionoptions-test.js +35 -22
  42. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +3 -34
  43. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +8 -1
  44. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin7.json +1 -4
  45. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin8.json +1 -6
  46. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +67 -87
  47. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +7 -13
  48. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +43 -43
  49. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +19 -29
  50. package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +0 -1
  51. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +35 -46
  52. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +8 -9
  53. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +96 -221
  54. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +18 -27
  55. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +8 -16
  56. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +0 -13
  57. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +4 -4
  58. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29b.json +8 -0
  59. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +1 -1
  60. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +0 -6
  61. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +8 -0
  62. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34b.json +14 -0
  63. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +1 -11
  64. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36b.json +13 -0
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin37.json +8 -0
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +1 -11
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10b.json +37 -0
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +0 -4
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +0 -4
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +0 -4
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +4 -0
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +0 -3
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +10 -12
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +0 -4
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -5
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +8 -12
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +0 -4
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +0 -8
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +7 -1
  80. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +898 -28
  81. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +188 -1
  82. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +267 -0
  83. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +19 -21
  84. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +21 -24
  85. package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +1 -21
  86. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +4 -6
  87. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +0 -438
  88. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +0 -381
  89. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +0 -311
  90. package/test/unit/ngsiv2/ngsiService/autocast-test.js +0 -325
  91. package/test/unit/ngsiv2/ngsiService/geoproperties-test.js +0 -427
  92. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +0 -217
  93. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +0 -119
  94. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -309
@@ -272,7 +272,7 @@ const iotAgentConfig = {
272
272
  commands: [],
273
273
  type: 'WeatherStation',
274
274
  lazy: [],
275
- static: [
275
+ staticAttributes: [
276
276
  {
277
277
  name: 'st1',
278
278
  type: 'Number',
@@ -522,7 +522,13 @@ const iotAgentConfig = {
522
522
  expression: 'z+1'
523
523
  },
524
524
  {
525
- name: 'nonexpectedAtt',
525
+ name: 'alsoexpectedAtt',
526
+ type: 'number',
527
+ expression: 'w+1',
528
+ skipValue: 'loquesea'
529
+ },
530
+ {
531
+ name: 'nonexpectedAttByDefaultSkipValue',
526
532
  type: 'number',
527
533
  expression: 'w+1'
528
534
  },
@@ -564,7 +570,7 @@ const iotAgentConfig = {
564
570
  object_id: 'y'
565
571
  }
566
572
  ],
567
- static: [
573
+ staticAttributes: [
568
574
  {
569
575
  name: 'bar',
570
576
  type: 'text',
@@ -600,7 +606,7 @@ const iotAgentConfig = {
600
606
 
601
607
  describe('NGSI-v2 - Multi-entity plugin', function () {
602
608
  beforeEach(function (done) {
603
- logger.setLevel('DEBUG');
609
+ logger.setLevel('FATAL');
604
610
 
605
611
  iotAgentLib.activate(iotAgentConfig, function () {
606
612
  iotAgentLib.clearAll(function () {
@@ -702,7 +708,6 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
702
708
 
703
709
  beforeEach(function () {
704
710
  nock.cleanAll();
705
-
706
711
  contextBrokerMock = nock('http://192.168.1.1:1026')
707
712
  .matchHeader('fiware-service', 'smartgondor')
708
713
  .matchHeader('fiware-servicepath', 'gardens')
@@ -740,7 +745,6 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
740
745
 
741
746
  beforeEach(function () {
742
747
  nock.cleanAll();
743
-
744
748
  contextBrokerMock = nock('http://192.168.1.1:1026')
745
749
  .matchHeader('fiware-service', 'smartgondor')
746
750
  .matchHeader('fiware-servicepath', 'gardens')
@@ -779,7 +783,6 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
779
783
 
780
784
  beforeEach(function () {
781
785
  nock.cleanAll();
782
-
783
786
  contextBrokerMock = nock('http://192.168.1.1:1026')
784
787
  .matchHeader('fiware-service', 'smartgondor')
785
788
  .matchHeader('fiware-servicepath', 'gardens')
@@ -1120,7 +1123,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1120
1123
  .post(
1121
1124
  '/v2/op/update',
1122
1125
  utils.readExampleFile(
1123
- './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json'
1126
+ './test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10b.json'
1124
1127
  )
1125
1128
  )
1126
1129
  .reply(204);
@@ -1151,7 +1154,7 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1151
1154
  .reply(204);
1152
1155
  });
1153
1156
 
1154
- describe('When an update comes for a multientity whith a wrong mapping)', function () {
1157
+ describe('When an update comes for a multientity whith a wrong mapping', function () {
1155
1158
  const values = [
1156
1159
  {
1157
1160
  name: 'v',
@@ -1172,7 +1175,6 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1172
1175
 
1173
1176
  beforeEach(function () {
1174
1177
  nock.cleanAll();
1175
-
1176
1178
  contextBrokerMock = nock('http://192.168.1.1:1026')
1177
1179
  .matchHeader('fiware-service', 'smartgondor')
1178
1180
  .matchHeader('fiware-servicepath', 'gardens')
@@ -1372,7 +1374,6 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1372
1374
 
1373
1375
  beforeEach(function () {
1374
1376
  nock.cleanAll();
1375
-
1376
1377
  contextBrokerMock = nock('http://192.168.1.1:1026')
1377
1378
  .matchHeader('fiware-service', 'smartgondor')
1378
1379
  .matchHeader('fiware-servicepath', 'gardens')
@@ -1424,7 +1425,6 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1424
1425
 
1425
1426
  beforeEach(function () {
1426
1427
  nock.cleanAll();
1427
-
1428
1428
  contextBrokerMock = nock('http://192.168.1.1:1026')
1429
1429
  .matchHeader('fiware-service', 'smartgondor')
1430
1430
  .matchHeader('fiware-servicepath', 'gardens')
@@ -1489,7 +1489,6 @@ describe('NGSI-v2 - Multi-entity plugin', function () {
1489
1489
  describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plugin', function () {
1490
1490
  beforeEach(function (done) {
1491
1491
  logger.setLevel('FATAL');
1492
-
1493
1492
  iotAgentConfig.timestamp = true;
1494
1493
  iotAgentLib.activate(iotAgentConfig, function () {
1495
1494
  iotAgentLib.clearAll(function () {
@@ -1560,7 +1559,7 @@ describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plu
1560
1559
 
1561
1560
  delete expectedBody.entities[1].TimeInstant;
1562
1561
  delete expectedBody.entities[1].humidity.metadata.TimeInstant;
1563
- return JSON.stringify(body) === JSON.stringify(expectedBody);
1562
+ return utils.deepEqual(body, expectedBody);
1564
1563
  }
1565
1564
  return false;
1566
1565
  })
@@ -1583,22 +1582,22 @@ describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plu
1583
1582
  );
1584
1583
  // Note that TimeInstant fields are not included in the json used by this mock as they are dynamic
1585
1584
  // fields. The following code just checks that TimeInstant fields are present.
1586
- if (!body.entities[1].TimeInstant || !body.entities[1].humidity.metadata.TimeInstant) {
1585
+ if (!body.entities[0].TimeInstant || !body.entities[0].humidity.metadata.TimeInstant) {
1587
1586
  return false;
1588
1587
  }
1589
1588
 
1590
- const timeInstantEntity2 = body.entities[1].TimeInstant;
1591
- const timeInstantAtt = body.entities[1].humidity.metadata.TimeInstant;
1589
+ const timeInstantEntity2 = body.entities[0].TimeInstant;
1590
+ const timeInstantAtt = body.entities[0].humidity.metadata.TimeInstant;
1592
1591
  if (
1593
1592
  moment(timeInstantEntity2, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid &&
1594
1593
  moment(timeInstantAtt, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid
1595
1594
  ) {
1596
- delete body.entities[1].TimeInstant;
1597
- delete body.entities[1].humidity.metadata.TimeInstant;
1595
+ delete body.entities[0].TimeInstant;
1596
+ delete body.entities[0].humidity.metadata.TimeInstant;
1598
1597
 
1599
- delete expectedBody.entities[1].TimeInstant;
1600
- delete expectedBody.entities[1].humidity.metadata.TimeInstant;
1601
- return JSON.stringify(body) === JSON.stringify(expectedBody);
1598
+ delete expectedBody.entities[0].TimeInstant;
1599
+ delete expectedBody.entities[0].humidity.metadata.TimeInstant;
1600
+ return utils.deepEqual(body, expectedBody);
1602
1601
  }
1603
1602
  return false;
1604
1603
  })
@@ -1636,7 +1635,6 @@ describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plu
1636
1635
  value: '2018-06-13T13:28:34.611Z'
1637
1636
  }
1638
1637
  ];
1639
-
1640
1638
  iotAgentLib.update('ws5', 'WeatherStation', '', tsValue, function (error) {
1641
1639
  should.not.exist(error);
1642
1640
  contextBrokerMock.done();
@@ -1649,7 +1647,6 @@ describe('NGSI-v2 - Multi-entity plugin is executed before timestamp process plu
1649
1647
  describe('NGSI-v2 - Multi-entity plugin is executed for a command update for a regular entity ', function () {
1650
1648
  beforeEach(function (done) {
1651
1649
  logger.setLevel('FATAL');
1652
-
1653
1650
  iotAgentConfig.timestamp = true;
1654
1651
  const time = new Date(1438760101468); // 2015-08-05T07:35:01.468+00:00
1655
1652
  timekeeper.freeze(time);
@@ -88,7 +88,7 @@ describe('Device Group utils', function () {
88
88
  });
89
89
  });
90
90
 
91
- describe('When an API Key is requested for a device in a group without the SingleConfiguration mode', function () {
91
+ describe('When an API Key is requested for a device in a group', function () {
92
92
  beforeEach(function (done) {
93
93
  async.series(
94
94
  [
@@ -107,26 +107,6 @@ describe('Device Group utils', function () {
107
107
  });
108
108
  });
109
109
  });
110
- describe('When an API Key is requested for a device in a subservice with the SingleConfiguration mode', function () {
111
- beforeEach(function (done) {
112
- iotAgentConfig.singleConfigurationMode = true;
113
- iotAgentLib.activate(iotAgentConfig, function () {
114
- request(groupCreation, function (error, response, body) {
115
- done();
116
- });
117
- });
118
- });
119
- afterEach(function () {
120
- iotAgentConfig.singleConfigurationMode = false;
121
- });
122
- it('should return the API Key of the related subservice', function (done) {
123
- iotAgentLib.getEffectiveApiKey('testservice', '/testingPath', null, function (error, apiKey) {
124
- should.not.exist(error);
125
- apiKey.should.equal('801230BJKL23Y9090DSFL123HJK09H324HV8732');
126
- done();
127
- });
128
- });
129
- });
130
110
  describe('When an API Key is requested without a provisioned group but with a configured type', function () {
131
111
  beforeEach(function (done) {
132
112
  iotAgentLib.activate(iotAgentConfig, done);
@@ -366,11 +366,10 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
366
366
  done();
367
367
  });
368
368
  });
369
- it('should store the device with explicitAttrs value provided in configuration', function (done) {
369
+ it('should store the device without explicitAttrs', function (done) {
370
370
  request(options, function (error, response, body) {
371
371
  iotAgentLib.listDevices('smartgondor', '/gardens', function (error, results) {
372
- should.exist(results.devices[0].explicitAttrs);
373
- results.devices[0].explicitAttrs.should.equal(false);
372
+ should.not.exist(results.devices[0].explicitAttrs);
374
373
  done();
375
374
  });
376
375
  });
@@ -430,12 +429,11 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
430
429
  done();
431
430
  });
432
431
 
433
- it('should store the device with explicitAttrs value provided in configuration', function (done) {
432
+ it('should store the device without explicitAttrs value', function (done) {
434
433
  request(groupCreation, function (error, response, body) {
435
434
  request(options, function (error, response, body) {
436
435
  iotAgentLib.listDevices('smartgondor', '/gardens', function (error, results) {
437
- should.exist(results.devices[0].explicitAttrs);
438
- results.devices[0].explicitAttrs.should.equal(true);
436
+ should.not.exist(results.devices[0].explicitAttrs);
439
437
  done();
440
438
  });
441
439
  });
@@ -1,438 +0,0 @@
1
- /*
2
- * Copyright 2020 Telefonica Investigación y Desarrollo, S.A.U
3
- *
4
- * This file is part of fiware-iotagent-lib
5
- *
6
- * fiware-iotagent-lib is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU Affero General Public License as
8
- * published by the Free Software Foundation, either version 3 of the License,
9
- * or (at your option) any later version.
10
- *
11
- * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
- * See the GNU Affero General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Affero General Public
17
- * License along with fiware-iotagent-lib.
18
- * If not, see http://www.gnu.org/licenses/.
19
- *
20
- * For those usages not covered by the GNU Affero General Public License
21
- * please contact with::[contacto@tid.es]
22
- *
23
- * Modified by: Jason Fox - FIWARE Foundation
24
- */
25
-
26
- /* eslint-disable no-unused-vars */
27
-
28
- const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
29
- const utils = require('../../../tools/utils');
30
- const request = utils.request;
31
- const should = require('should');
32
- const logger = require('logops');
33
- const nock = require('nock');
34
- let contextBrokerMock;
35
- const iotAgentConfig = {
36
- autocast: true,
37
- contextBroker: {
38
- host: '192.168.1.1',
39
- port: '1026',
40
- ngsiVersion: 'ld',
41
- jsonLdContext: 'http://context.json-ld'
42
- },
43
- server: {
44
- port: 4041,
45
- host: 'localhost'
46
- },
47
- types: {
48
- Light: {
49
- commands: [],
50
- type: 'Light',
51
- active: [
52
- {
53
- name: 'pressure',
54
- type: 'Number'
55
- },
56
- {
57
- name: 'temperature',
58
- type: 'Number'
59
- },
60
- {
61
- name: 'id',
62
- type: 'String'
63
- },
64
- {
65
- name: 'status',
66
- type: 'Boolean'
67
- },
68
- {
69
- name: 'keep_alive',
70
- type: 'None'
71
- },
72
- {
73
- name: 'tags',
74
- type: 'Array'
75
- },
76
- {
77
- name: 'configuration',
78
- type: 'Object'
79
- },
80
- {
81
- name: 'date',
82
- type: 'Date'
83
- },
84
- {
85
- name: 'time',
86
- type: 'Time'
87
- },
88
- {
89
- name: 'dateTime',
90
- type: 'DateTime'
91
- }
92
- ]
93
- }
94
- },
95
- service: 'smartgondor',
96
- subservice: 'gardens',
97
- providerUrl: 'http://smartgondor.com'
98
- };
99
-
100
- describe('NGSI-LD - JSON native types autocast test', function () {
101
- beforeEach(function () {
102
- logger.setLevel('FATAL');
103
- });
104
-
105
- afterEach(function (done) {
106
- iotAgentLib.deactivate(done);
107
- });
108
-
109
- describe('When the IoT Agent receives new information from a device. Observation with Number type and Integer value', function () {
110
- const values = [
111
- {
112
- name: 'pressure',
113
- type: 'Number',
114
- value: '23'
115
- }
116
- ];
117
-
118
- beforeEach(function (done) {
119
- nock.cleanAll();
120
-
121
- contextBrokerMock = nock('http://192.168.1.1:1026')
122
- .matchHeader('fiware-service', 'smartgondor')
123
- .post(
124
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
125
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast1.json')
126
- )
127
-
128
- .reply(204);
129
-
130
- iotAgentLib.activate(iotAgentConfig, done);
131
- });
132
-
133
- it('should change the value of the corresponding attribute in the context broker', function (done) {
134
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
135
- should.not.exist(error);
136
- contextBrokerMock.done();
137
- done();
138
- });
139
- });
140
- });
141
-
142
- describe('When the IoT Agent receives new information from a device. Observation with Number type and Float value', function () {
143
- const values = [
144
- {
145
- name: 'temperature',
146
- type: 'Number',
147
- value: '14.4'
148
- }
149
- ];
150
-
151
- beforeEach(function (done) {
152
- nock.cleanAll();
153
-
154
- contextBrokerMock = nock('http://192.168.1.1:1026')
155
- .matchHeader('fiware-service', 'smartgondor')
156
- .post(
157
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
158
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast2.json')
159
- )
160
-
161
- .reply(204);
162
-
163
- iotAgentLib.activate(iotAgentConfig, done);
164
- });
165
-
166
- it('should change the value of the corresponding attribute in the context broker', function (done) {
167
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
168
- should.not.exist(error);
169
- contextBrokerMock.done();
170
- done();
171
- });
172
- });
173
- });
174
-
175
- describe('When the IoT Agent receives new information from a device. Observation with Boolean type and True value', function () {
176
- const values = [
177
- {
178
- name: 'status',
179
- type: 'Boolean',
180
- value: 'true'
181
- }
182
- ];
183
-
184
- beforeEach(function (done) {
185
- nock.cleanAll();
186
-
187
- contextBrokerMock = nock('http://192.168.1.1:1026')
188
- .matchHeader('fiware-service', 'smartgondor')
189
- .post(
190
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
191
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast3.json')
192
- )
193
-
194
- .reply(204);
195
-
196
- iotAgentLib.activate(iotAgentConfig, done);
197
- });
198
-
199
- it('should change the value of the corresponding attribute in the context broker', function (done) {
200
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
201
- should.not.exist(error);
202
- contextBrokerMock.done();
203
- done();
204
- });
205
- });
206
- });
207
-
208
- describe('When the IoT Agent receives new information from a device. Observation with Boolean type and False value', function () {
209
- const values = [
210
- {
211
- name: 'status',
212
- type: 'Boolean',
213
- value: 'false'
214
- }
215
- ];
216
-
217
- beforeEach(function (done) {
218
- nock.cleanAll();
219
-
220
- contextBrokerMock = nock('http://192.168.1.1:1026')
221
- .matchHeader('fiware-service', 'smartgondor')
222
- .post(
223
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
224
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast4.json')
225
- )
226
-
227
- .reply(204);
228
-
229
- iotAgentLib.activate(iotAgentConfig, done);
230
- });
231
-
232
- it('should change the value of the corresponding attribute in the context broker', function (done) {
233
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
234
- should.not.exist(error);
235
- contextBrokerMock.done();
236
- done();
237
- });
238
- });
239
- });
240
-
241
- describe('When the IoT Agent receives new information from a device. Observation with None type', function () {
242
- const values = [
243
- {
244
- name: 'keep_alive',
245
- type: 'None',
246
- value: 'null'
247
- }
248
- ];
249
-
250
- beforeEach(function (done) {
251
- nock.cleanAll();
252
-
253
- contextBrokerMock = nock('http://192.168.1.1:1026')
254
- .matchHeader('fiware-service', 'smartgondor')
255
- .post(
256
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
257
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json')
258
- )
259
-
260
- .reply(204);
261
-
262
- iotAgentLib.activate(iotAgentConfig, done);
263
- });
264
-
265
- it('should change the value of the corresponding attribute in the context broker', function (done) {
266
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
267
- should.not.exist(error);
268
- contextBrokerMock.done();
269
- done();
270
- });
271
- });
272
- });
273
-
274
- describe('When the IoT Agent receives new information from a device. Observation with Array type', function () {
275
- const values = [
276
- {
277
- name: 'tags',
278
- type: 'Array',
279
- value: '["iot","device"]'
280
- }
281
- ];
282
-
283
- beforeEach(function (done) {
284
- nock.cleanAll();
285
-
286
- contextBrokerMock = nock('http://192.168.1.1:1026')
287
- .matchHeader('fiware-service', 'smartgondor')
288
- .post(
289
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
290
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast6.json')
291
- )
292
-
293
- .reply(204);
294
-
295
- iotAgentLib.activate(iotAgentConfig, done);
296
- });
297
-
298
- it('should change the value of the corresponding attribute in the context broker', function (done) {
299
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
300
- should.not.exist(error);
301
- contextBrokerMock.done();
302
- done();
303
- });
304
- });
305
- });
306
-
307
- describe('When the IoT Agent receives new information from a device. Observation with Object type', function () {
308
- const values = [
309
- {
310
- name: 'configuration',
311
- type: 'Object',
312
- value: '{"firmware": {"version": "1.1.0","hash": "cf23df2207d99a74fbe169e3eba035e633b65d94"}}'
313
- }
314
- ];
315
-
316
- beforeEach(function (done) {
317
- nock.cleanAll();
318
-
319
- contextBrokerMock = nock('http://192.168.1.1:1026')
320
- .matchHeader('fiware-service', 'smartgondor')
321
- .post(
322
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
323
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast7.json')
324
- )
325
-
326
- .reply(204);
327
-
328
- iotAgentLib.activate(iotAgentConfig, done);
329
- });
330
-
331
- it('should change the value of the corresponding attribute in the context broker', function (done) {
332
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
333
- should.not.exist(error);
334
- contextBrokerMock.done();
335
- done();
336
- });
337
- });
338
- });
339
-
340
- describe('When the IoT Agent receives new information from a device. Observation with Time type', function () {
341
- const values = [
342
- {
343
- name: 'time',
344
- type: 'Time',
345
- value: '2016-04-30T14:59:46.000Z'
346
- }
347
- ];
348
-
349
- beforeEach(function (done) {
350
- nock.cleanAll();
351
-
352
- contextBrokerMock = nock('http://192.168.1.1:1026')
353
- .matchHeader('fiware-service', 'smartgondor')
354
- .post(
355
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
356
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast8.json')
357
- )
358
-
359
- .reply(204);
360
-
361
- iotAgentLib.activate(iotAgentConfig, done);
362
- });
363
-
364
- it('should change the value of the corresponding attribute in the context broker', function (done) {
365
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
366
- should.not.exist(error);
367
- contextBrokerMock.done();
368
- done();
369
- });
370
- });
371
- });
372
-
373
- describe('When the IoT Agent receives new information from a device. Observation with DateTime type', function () {
374
- const values = [
375
- {
376
- name: 'dateTime',
377
- type: 'DateTime',
378
- value: '2016-04-30Z'
379
- }
380
- ];
381
-
382
- beforeEach(function (done) {
383
- nock.cleanAll();
384
-
385
- contextBrokerMock = nock('http://192.168.1.1:1026')
386
- .matchHeader('fiware-service', 'smartgondor')
387
- .post(
388
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
389
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast9.json')
390
- )
391
-
392
- .reply(204);
393
-
394
- iotAgentLib.activate(iotAgentConfig, done);
395
- });
396
-
397
- it('should change the value of the corresponding attribute in the context broker', function (done) {
398
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
399
- should.not.exist(error);
400
- contextBrokerMock.done();
401
- done();
402
- });
403
- });
404
- });
405
-
406
- describe('When the IoT Agent receives new information from a device. Observation with Date type', function () {
407
- const values = [
408
- {
409
- name: 'date',
410
- type: 'Date',
411
- value: '2016-04-30T14:59:46.000Z'
412
- }
413
- ];
414
-
415
- beforeEach(function (done) {
416
- nock.cleanAll();
417
-
418
- contextBrokerMock = nock('http://192.168.1.1:1026')
419
- .matchHeader('fiware-service', 'smartgondor')
420
- .post(
421
- '/ngsi-ld/v1/entityOperations/upsert/?options=update',
422
- utils.readExampleFile('./test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast10.json')
423
- )
424
-
425
- .reply(204);
426
-
427
- iotAgentLib.activate(iotAgentConfig, done);
428
- });
429
-
430
- it('should change the value of the corresponding attribute in the context broker', function (done) {
431
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
432
- should.not.exist(error);
433
- contextBrokerMock.done();
434
- done();
435
- });
436
- });
437
- });
438
- });