iotagent-node-lib 3.4.4 → 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 (93) hide show
  1. package/README.md +4 -0
  2. package/doc/admin.md +1 -13
  3. package/doc/api.md +116 -18
  4. package/doc/devel/architecture.md +0 -12
  5. package/doc/index.md +1 -1
  6. package/doc/roadmap.md +22 -10
  7. package/lib/commonConfig.js +0 -11
  8. package/lib/model/Device.js +2 -1
  9. package/lib/model/Group.js +2 -1
  10. package/lib/model/dbConn.js +22 -11
  11. package/lib/plugins/expressionPlugin.js +0 -5
  12. package/lib/plugins/jexlParser.js +15 -31
  13. package/lib/services/common/genericMiddleware.js +14 -2
  14. package/lib/services/common/iotManagerService.js +2 -1
  15. package/lib/services/devices/deviceRegistryMongoDB.js +3 -1
  16. package/lib/services/devices/deviceService.js +16 -21
  17. package/lib/services/devices/devices-NGSI-LD.js +5 -98
  18. package/lib/services/devices/devices-NGSI-mixed.js +0 -14
  19. package/lib/services/devices/devices-NGSI-v2.js +3 -0
  20. package/lib/services/groups/groupRegistryMemory.js +0 -25
  21. package/lib/services/groups/groupRegistryMongoDB.js +20 -19
  22. package/lib/services/groups/groupService.js +3 -14
  23. package/lib/services/ngsi/entities-NGSI-LD.js +81 -6
  24. package/lib/services/ngsi/entities-NGSI-v2.js +303 -698
  25. package/lib/services/ngsi/ngsiUtils.js +0 -30
  26. package/lib/services/northBound/deviceProvisioningServer.js +6 -3
  27. package/lib/templates/createDevice.json +4 -0
  28. package/lib/templates/createDeviceLax.json +4 -0
  29. package/lib/templates/deviceGroup.json +4 -0
  30. package/lib/templates/updateDevice.json +4 -0
  31. package/lib/templates/updateDeviceLax.json +4 -0
  32. package/package.json +6 -2
  33. package/test/functional/README.md +378 -0
  34. package/test/functional/config-test.js +70 -0
  35. package/test/functional/functional-tests-runner.js +126 -0
  36. package/test/functional/functional-tests.js +241 -0
  37. package/test/functional/testCases.js +2944 -0
  38. package/test/functional/testUtils.js +251 -0
  39. package/test/tools/utils.js +25 -0
  40. package/test/unit/mongodb/mongodb-connectionoptions-test.js +35 -22
  41. package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +3 -34
  42. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +8 -1
  43. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin7.json +1 -4
  44. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin8.json +1 -6
  45. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +67 -87
  46. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +7 -13
  47. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +43 -43
  48. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +19 -29
  49. package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +0 -1
  50. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +35 -46
  51. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +8 -9
  52. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +96 -221
  53. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +18 -27
  54. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +8 -16
  55. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +0 -13
  56. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +4 -4
  57. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29b.json +8 -0
  58. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +1 -1
  59. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +0 -6
  60. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +8 -0
  61. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34b.json +14 -0
  62. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +1 -11
  63. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36b.json +13 -0
  64. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin37.json +8 -0
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +1 -11
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10b.json +37 -0
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +0 -4
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +0 -4
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +0 -4
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +4 -0
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +0 -3
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +10 -12
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +0 -4
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -5
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +8 -12
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +0 -4
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +0 -8
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +7 -1
  79. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +898 -28
  80. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +0 -4
  81. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +267 -0
  82. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +19 -21
  83. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +21 -24
  84. package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +1 -21
  85. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +4 -6
  86. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +0 -438
  87. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +0 -381
  88. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +0 -311
  89. package/test/unit/ngsiv2/ngsiService/autocast-test.js +0 -325
  90. package/test/unit/ngsiv2/ngsiService/geoproperties-test.js +0 -427
  91. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +0 -217
  92. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +0 -119
  93. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -309
@@ -0,0 +1,126 @@
1
+ /*
2
+ * Copyright 2023 Telefonica Investigación y Desarrollo, S.A.U
3
+ *
4
+ * This file is part of iotagent-json
5
+ *
6
+ * iotagent-json 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
+ * iotagent-json 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 iotagent-json.
18
+ * If not, seehttp://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: Miguel Angel Pedraza
24
+ */
25
+
26
+ /* eslint-disable no-unused-vars*/
27
+ /* eslint-disable no-unused-expressions*/
28
+
29
+ const config = require('./config-test.js');
30
+ const nock = require('nock');
31
+ const chai = require('chai');
32
+ const expect = chai.expect;
33
+ const iotAgentLib = require('../../lib/fiware-iotagent-lib');
34
+ const testUtils = require('./testUtils');
35
+ const logger = require('logops');
36
+ chai.config.truncateThreshold = 0;
37
+
38
+ const baseTestCases = require('./testCases.js').testCases;
39
+
40
+ const env = {
41
+ service: 'smartgondor',
42
+ servicePath: '/gardens'
43
+ };
44
+
45
+ // You can add here your own test cases to be executed in addition to the base ones
46
+ // It is useful to test new features or to test specific scenarios. If you are going
47
+ // to add a new test case, please, add it to the testCases.js file instead of adding
48
+ // it here.
49
+ let testCases = [];
50
+
51
+ // If you want to execute only the test cases defined above, you can comment
52
+ // the following line. Otherwise, the tests defined in testCases.js will be
53
+ // executed as well.
54
+ testCases = testCases.concat(baseTestCases);
55
+
56
+ describe('FUNCTIONAL TESTS AUTO', function () {
57
+ testCases.forEach((testCase) => {
58
+ describe(testCase.describeName, function () {
59
+ beforeEach(function (done) {
60
+ if (testCase.skip && testUtils.checkSkip(testCase.skip, 'lib')) {
61
+ this.skip();
62
+ }
63
+ if (testCase.loglevel) {
64
+ logger.setLevel(testCase.loglevel);
65
+ }
66
+ let type = testUtils.groupToIoTAConfigType(
67
+ testCase.provision.json.services[0],
68
+ testCase.provision.headers.fiwareService,
69
+ testCase.provision.headers.fiwareServicepath
70
+ );
71
+ config.iota.types[type.name] = type.type;
72
+ iotAgentLib.activate(config.iota, function (error) {
73
+ done(error);
74
+ });
75
+ });
76
+
77
+ afterEach(function (done) {
78
+ logger.setLevel('FATAL');
79
+ nock.cleanAll();
80
+ iotAgentLib.clearAll(function () {
81
+ iotAgentLib.deactivate(function () {
82
+ iotAgentLib.setDataUpdateHandler();
83
+ iotAgentLib.setCommandHandler();
84
+ done();
85
+ });
86
+ });
87
+ });
88
+
89
+ testCase.should.forEach((should) => {
90
+ it(should.shouldName, async function () {
91
+ if (testCase.skip && testUtils.checkSkip(testCase.skip, 'lib')) {
92
+ this.skip();
93
+ }
94
+ // Skip the test if the transport is specified (IoTA Lib does not support any transport)
95
+ if (
96
+ should.transport &&
97
+ (should.transport === 'MQTT' || should.transport === 'AMQP' || should.transport === 'HTTP')
98
+ ) {
99
+ this.skip();
100
+ }
101
+
102
+ this.retries(2); // Retry if the test fails
103
+
104
+ if (should.loglevel) {
105
+ // You can use this line to set a breakpoint in the test in order to debug it
106
+ // You just need to add a loglevel element to the test case with the desired log level
107
+ // and then set a breakpoint in the next line. By default, the log level is FATAL and
108
+ // the following line will never be executed
109
+ logger.setLevel(should.loglevel);
110
+ } else {
111
+ await testUtils.testCase(
112
+ should.measure,
113
+ should.expectation,
114
+ testCase.provision,
115
+ env,
116
+ config,
117
+ should.type ? should.type : 'single',
118
+ should.transport,
119
+ should.isRegex ? should.isRegex : false
120
+ );
121
+ }
122
+ });
123
+ });
124
+ });
125
+ });
126
+ });
@@ -0,0 +1,241 @@
1
+ /*
2
+ * Copyright 2023 Telefonica Investigación y Desarrollo, S.A.U
3
+ *
4
+ * This file is part of iotagent-json
5
+ *
6
+ * iotagent-json 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
+ * iotagent-json 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 iotagent-json.
18
+ * If not, seehttp://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: Miguel Angel Pedraza
24
+ */
25
+
26
+ /* eslint-disable no-unused-vars*/
27
+ /* eslint-disable no-unused-expressions*/
28
+
29
+ const config = require('./config-test.js');
30
+ const nock = require('nock');
31
+ const chai = require('chai');
32
+ const expect = chai.expect;
33
+ const iotAgentLib = require('../../lib/fiware-iotagent-lib');
34
+ const async = require('async');
35
+ const utils = require('../tools/utils');
36
+ const testUtils = require('./testUtils');
37
+ const request = utils.request;
38
+ const logger = require('logops');
39
+ var chaiMatchPattern = require('chai-match-pattern');
40
+
41
+ chai.use(chaiMatchPattern);
42
+ var _ = chaiMatchPattern.getLodashModule();
43
+ let contextBrokerMock;
44
+
45
+ const globalEnv = {
46
+ service: 'smartgondor',
47
+ servicePath: '/gardens',
48
+ apikey: '123456',
49
+ entity_type: 'TestType',
50
+ entity_name: 'TestType:TestDevice',
51
+ deviceId: 'TestDevice'
52
+ };
53
+
54
+ describe('FUNCTIONAL TESTS', function () {
55
+ describe('Basic group provision with attributes', function () {
56
+ const provision = {
57
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
58
+ method: 'POST',
59
+ json: {
60
+ services: [
61
+ {
62
+ resource: '/iot/json',
63
+ apikey: globalEnv.apikey,
64
+ entity_type: globalEnv.entity_type,
65
+ commands: [],
66
+ lazy: [],
67
+ attributes: [
68
+ {
69
+ object_id: 's',
70
+ name: 'status',
71
+ type: 'Boolean'
72
+ },
73
+ {
74
+ object_id: 't',
75
+ name: 'temperature',
76
+ type: 'Number'
77
+ }
78
+ ],
79
+ static_attributes: []
80
+ }
81
+ ]
82
+ },
83
+ headers: {
84
+ 'fiware-service': globalEnv.service,
85
+ 'fiware-servicepath': globalEnv.servicePath
86
+ }
87
+ };
88
+
89
+ const measure = {
90
+ url: 'http://localhost:' + config.http.port + '/iot/json',
91
+ method: 'POST',
92
+ qs: {
93
+ i: globalEnv.deviceId,
94
+ k: globalEnv.apikey
95
+ },
96
+ json: {
97
+ s: false,
98
+ t: 10
99
+ }
100
+ };
101
+
102
+ const expectation = {
103
+ id: globalEnv.entity_name,
104
+ type: globalEnv.entity_type,
105
+ temperature: {
106
+ value: 10,
107
+ type: 'Number'
108
+ },
109
+ status: {
110
+ value: false,
111
+ type: 'Boolean'
112
+ }
113
+ };
114
+
115
+ beforeEach(function (done) {
116
+ let type = testUtils.groupToIoTAConfigType(
117
+ provision.json.services[0],
118
+ provision.headers.fiwareService,
119
+ provision.headers.fiwareServicepath
120
+ );
121
+ config.iota.types[type.name] = type.type;
122
+ iotAgentLib.activate(config.iota, function (error) {
123
+ done(error);
124
+ });
125
+ });
126
+
127
+ afterEach(function (done) {
128
+ nock.cleanAll();
129
+ iotAgentLib.clearAll(function () {
130
+ iotAgentLib.deactivate(function () {
131
+ iotAgentLib.setDataUpdateHandler();
132
+ iotAgentLib.setCommandHandler();
133
+ done();
134
+ });
135
+ });
136
+ });
137
+
138
+ it('should send its value to the Context Broker', async function () {
139
+ await testUtils.testCase(measure, expectation, provision, globalEnv, config, 'single', '');
140
+ });
141
+ });
142
+
143
+ describe('Basic group provision with attributes and multientity', function () {
144
+ const provision = {
145
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
146
+ method: 'POST',
147
+ json: {
148
+ services: [
149
+ {
150
+ resource: '/iot/json',
151
+ apikey: globalEnv.apikey,
152
+ entity_type: globalEnv.entity_type,
153
+ commands: [],
154
+ lazy: [],
155
+ attributes: [
156
+ {
157
+ object_id: 's',
158
+ name: 'status',
159
+ type: 'Boolean'
160
+ },
161
+ {
162
+ object_id: 't',
163
+ name: 'temperature',
164
+ type: 'Number',
165
+ entity_name: 'TheLightType2:MQTT_3',
166
+ entity_type: 'TheLightType2'
167
+ }
168
+ ],
169
+ static_attributes: []
170
+ }
171
+ ]
172
+ },
173
+ headers: {
174
+ 'fiware-service': globalEnv.service,
175
+ 'fiware-servicepath': globalEnv.servicePath
176
+ }
177
+ };
178
+
179
+ const measure = {
180
+ url: 'http://localhost:' + config.http.port + '/iot/json',
181
+ method: 'POST',
182
+ qs: {
183
+ i: globalEnv.deviceId,
184
+ k: globalEnv.apikey
185
+ },
186
+ json: {
187
+ s: false,
188
+ t: 10
189
+ }
190
+ };
191
+
192
+ const expectation = {
193
+ entities: [
194
+ {
195
+ id: globalEnv.entity_name,
196
+ type: globalEnv.entity_type,
197
+ status: {
198
+ value: false,
199
+ type: 'Boolean'
200
+ }
201
+ },
202
+ {
203
+ id: 'TheLightType2:MQTT_3',
204
+ type: 'TheLightType2',
205
+ temperature: {
206
+ value: 10,
207
+ type: 'Number'
208
+ }
209
+ }
210
+ ],
211
+ actionType: 'append'
212
+ };
213
+
214
+ beforeEach(function (done) {
215
+ let type = testUtils.groupToIoTAConfigType(
216
+ provision.json.services[0],
217
+ provision.headers.fiwareService,
218
+ provision.headers.fiwareServicepath
219
+ );
220
+ config.iota.types[type.name] = type.type;
221
+ iotAgentLib.activate(config.iota, function (error) {
222
+ done(error);
223
+ });
224
+ });
225
+
226
+ afterEach(function (done) {
227
+ nock.cleanAll();
228
+ iotAgentLib.clearAll(function () {
229
+ iotAgentLib.deactivate(function () {
230
+ iotAgentLib.setDataUpdateHandler();
231
+ iotAgentLib.setCommandHandler();
232
+ done();
233
+ });
234
+ });
235
+ });
236
+
237
+ it('should send its value to the Context Broker', async function () {
238
+ await testUtils.testCase(measure, expectation, provision, globalEnv, config, 'multientity', '');
239
+ });
240
+ });
241
+ });