iotagent-node-lib 3.1.0 → 3.2.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.
- package/CHANGES_NEXT_RELEASE +0 -2
- package/config.js +5 -5
- package/doc/api.md +1540 -298
- package/doc/deprecated.md +3 -1
- package/doc/development.md +120 -0
- package/doc/installationguide.md +3 -6
- package/lib/commonConfig.js +7 -10
- package/lib/fiware-iotagent-lib.js +0 -10
- package/lib/jexlTranformsMap.js +2 -1
- package/lib/plugins/bidirectionalData.js +8 -26
- package/lib/plugins/expressionPlugin.js +8 -40
- package/lib/plugins/jexlParser.js +28 -0
- package/lib/services/commands/commandService.js +1 -1
- package/lib/services/devices/deviceService.js +2 -1
- package/lib/services/ngsi/entities-NGSI-LD.js +13 -57
- package/lib/services/ngsi/entities-NGSI-v2.js +145 -108
- package/lib/services/northBound/deviceProvisioningServer.js +17 -14
- package/lib/templates/createDevice.json +5 -2
- package/lib/templates/createDeviceLax.json +7 -5
- package/lib/templates/updateDevice.json +5 -2
- package/lib/templates/updateDeviceLax.json +3 -5
- package/package.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +5 -5
- package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +1 -0
- package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +4 -4
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -2
- package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +8 -8
- package/test/unit/ngsi-ld/plugins/custom-plugin_test.js +152 -0
- package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +20 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +42 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +32 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +37 -0
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +228 -6
- package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +1 -2
- package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +6 -6
- package/test/unit/ngsiv2/plugins/custom-plugin_test.js +151 -0
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +85 -12
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +11 -3
- package/doc/advanced-topics.md +0 -626
- package/doc/expressionLanguage.md +0 -762
- package/lib/plugins/expressionParser.js +0 -205
- package/test/unit/expressions/expression-test.js +0 -197
- package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +0 -882
- package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +0 -951
- package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +0 -296
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2014 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, 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
|
-
* Developed by: Federico M. Facca - Martel Innovate
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/* jshint camelcase: false */
|
|
27
|
-
|
|
28
|
-
const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
|
|
29
|
-
const utils = require('../../../tools/utils');
|
|
30
|
-
const should = require('should');
|
|
31
|
-
const logger = require('logops');
|
|
32
|
-
const nock = require('nock');
|
|
33
|
-
let contextBrokerMock;
|
|
34
|
-
const iotAgentConfigJexl = {
|
|
35
|
-
contextBroker: {
|
|
36
|
-
host: '192.168.1.1',
|
|
37
|
-
port: '1026',
|
|
38
|
-
ngsiVersion: 'v2'
|
|
39
|
-
},
|
|
40
|
-
server: {
|
|
41
|
-
port: 4041,
|
|
42
|
-
host: 'localhost'
|
|
43
|
-
},
|
|
44
|
-
defaultExpressionLanguage: 'jexl',
|
|
45
|
-
types: {
|
|
46
|
-
WeatherStationLegacy: {
|
|
47
|
-
commands: [],
|
|
48
|
-
type: 'WeatherStation',
|
|
49
|
-
expressionLanguage: 'legacy',
|
|
50
|
-
lazy: [],
|
|
51
|
-
active: [
|
|
52
|
-
{
|
|
53
|
-
object_id: 'p',
|
|
54
|
-
name: 'pressure',
|
|
55
|
-
type: 'Number',
|
|
56
|
-
expression: '${@pressure * 20}'
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
},
|
|
60
|
-
WeatherStationJexl: {
|
|
61
|
-
commands: [],
|
|
62
|
-
type: 'WeatherStation',
|
|
63
|
-
lazy: [],
|
|
64
|
-
active: [
|
|
65
|
-
{
|
|
66
|
-
object_id: 'p',
|
|
67
|
-
name: 'pressure',
|
|
68
|
-
type: 'Number',
|
|
69
|
-
expression: 'pressure * 20'
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
service: 'smartgondor',
|
|
75
|
-
subservice: 'gardens',
|
|
76
|
-
providerUrl: 'http://smartgondor.com',
|
|
77
|
-
deviceRegistrationDuration: 'P1M',
|
|
78
|
-
throttling: 'PT5S'
|
|
79
|
-
};
|
|
80
|
-
const iotAgentConfigLegacy = {
|
|
81
|
-
contextBroker: {
|
|
82
|
-
host: '192.168.1.1',
|
|
83
|
-
port: '1026',
|
|
84
|
-
ngsiVersion: 'v2'
|
|
85
|
-
},
|
|
86
|
-
server: {
|
|
87
|
-
port: 4041,
|
|
88
|
-
host: 'localhost'
|
|
89
|
-
},
|
|
90
|
-
types: {
|
|
91
|
-
WeatherStationLegacy: {
|
|
92
|
-
commands: [],
|
|
93
|
-
type: 'WeatherStation',
|
|
94
|
-
lazy: [],
|
|
95
|
-
active: [
|
|
96
|
-
{
|
|
97
|
-
object_id: 'p',
|
|
98
|
-
name: 'pressure',
|
|
99
|
-
type: 'Number',
|
|
100
|
-
expression: '${@pressure * 20}'
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
},
|
|
104
|
-
WeatherStationJexl: {
|
|
105
|
-
commands: [],
|
|
106
|
-
type: 'WeatherStation',
|
|
107
|
-
expressionLanguage: 'jexl',
|
|
108
|
-
lazy: [],
|
|
109
|
-
active: [
|
|
110
|
-
{
|
|
111
|
-
object_id: 'p',
|
|
112
|
-
name: 'pressure',
|
|
113
|
-
type: 'Number',
|
|
114
|
-
expression: 'pressure * 20'
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
service: 'smartgondor',
|
|
120
|
-
subservice: 'gardens',
|
|
121
|
-
providerUrl: 'http://smartgondor.com',
|
|
122
|
-
deviceRegistrationDuration: 'P1M',
|
|
123
|
-
throttling: 'PT5S'
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
describe('Combine Jexl and legacy expressions (default JEXL) - NGSI v2', function () {
|
|
127
|
-
beforeEach(function (done) {
|
|
128
|
-
logger.setLevel('FATAL');
|
|
129
|
-
|
|
130
|
-
iotAgentLib.activate(iotAgentConfigJexl, function () {
|
|
131
|
-
iotAgentLib.clearAll(function () {
|
|
132
|
-
done();
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
afterEach(function (done) {
|
|
138
|
-
iotAgentLib.clearAll(function () {
|
|
139
|
-
iotAgentLib.deactivate(done);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe('When an update comes for type with expression "legacy"', function () {
|
|
144
|
-
const values = [
|
|
145
|
-
{
|
|
146
|
-
name: 'p',
|
|
147
|
-
type: 'Number',
|
|
148
|
-
value: 52
|
|
149
|
-
}
|
|
150
|
-
];
|
|
151
|
-
|
|
152
|
-
beforeEach(function () {
|
|
153
|
-
nock.cleanAll();
|
|
154
|
-
|
|
155
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
156
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
157
|
-
.matchHeader('fiware-servicepath', 'gardens')
|
|
158
|
-
.patch(
|
|
159
|
-
'/v2/entities/ws1/attrs',
|
|
160
|
-
utils.readExampleFile(
|
|
161
|
-
'./test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin15.json'
|
|
162
|
-
)
|
|
163
|
-
)
|
|
164
|
-
.query({ type: 'WeatherStation' })
|
|
165
|
-
.reply(204);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should apply the legacy expression before sending the values', function (done) {
|
|
169
|
-
iotAgentLib.update('ws1', 'WeatherStationLegacy', '', values, function (error) {
|
|
170
|
-
should.not.exist(error);
|
|
171
|
-
contextBrokerMock.done();
|
|
172
|
-
done();
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe('When an update comes for type with expression "JEXL" - default', function () {
|
|
178
|
-
const values = [
|
|
179
|
-
{
|
|
180
|
-
name: 'p',
|
|
181
|
-
type: 'Number',
|
|
182
|
-
value: 52
|
|
183
|
-
}
|
|
184
|
-
];
|
|
185
|
-
|
|
186
|
-
beforeEach(function () {
|
|
187
|
-
nock.cleanAll();
|
|
188
|
-
|
|
189
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
190
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
191
|
-
.matchHeader('fiware-servicepath', 'gardens')
|
|
192
|
-
.patch(
|
|
193
|
-
'/v2/entities/ws2/attrs',
|
|
194
|
-
utils.readExampleFile(
|
|
195
|
-
'./test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin15.json'
|
|
196
|
-
)
|
|
197
|
-
)
|
|
198
|
-
.query({ type: 'WeatherStation' })
|
|
199
|
-
.reply(204);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('should apply the default (JEXL) expression before sending the values', function (done) {
|
|
203
|
-
iotAgentLib.update('ws2', 'WeatherStationJexl', '', values, function (error) {
|
|
204
|
-
should.not.exist(error);
|
|
205
|
-
contextBrokerMock.done();
|
|
206
|
-
done();
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('Combine Jexl and legacy expressions (default Legacy) - NGSI v2', function () {
|
|
213
|
-
beforeEach(function (done) {
|
|
214
|
-
logger.setLevel('FATAL');
|
|
215
|
-
|
|
216
|
-
iotAgentLib.activate(iotAgentConfigLegacy, function () {
|
|
217
|
-
iotAgentLib.clearAll(function () {
|
|
218
|
-
done();
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
afterEach(function (done) {
|
|
224
|
-
iotAgentLib.clearAll(function () {
|
|
225
|
-
iotAgentLib.deactivate(done);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe('When an update comes for type with expression "legacy" - default', function () {
|
|
230
|
-
const values = [
|
|
231
|
-
{
|
|
232
|
-
name: 'p',
|
|
233
|
-
type: 'Number',
|
|
234
|
-
value: 52
|
|
235
|
-
}
|
|
236
|
-
];
|
|
237
|
-
|
|
238
|
-
beforeEach(function () {
|
|
239
|
-
nock.cleanAll();
|
|
240
|
-
|
|
241
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
242
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
243
|
-
.matchHeader('fiware-servicepath', 'gardens')
|
|
244
|
-
.patch(
|
|
245
|
-
'/v2/entities/ws3/attrs',
|
|
246
|
-
utils.readExampleFile(
|
|
247
|
-
'./test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin15.json'
|
|
248
|
-
)
|
|
249
|
-
)
|
|
250
|
-
.query({ type: 'WeatherStation' })
|
|
251
|
-
.reply(204);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('should apply the legacy expression before sending the values', function (done) {
|
|
255
|
-
iotAgentLib.update('ws3', 'WeatherStationLegacy', '', values, function (error) {
|
|
256
|
-
should.not.exist(error);
|
|
257
|
-
contextBrokerMock.done();
|
|
258
|
-
done();
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
describe('When an update comes for type with expression "JEXL"', function () {
|
|
264
|
-
const values = [
|
|
265
|
-
{
|
|
266
|
-
name: 'p',
|
|
267
|
-
type: 'Number',
|
|
268
|
-
value: 52
|
|
269
|
-
}
|
|
270
|
-
];
|
|
271
|
-
|
|
272
|
-
beforeEach(function () {
|
|
273
|
-
nock.cleanAll();
|
|
274
|
-
|
|
275
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
276
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
277
|
-
.matchHeader('fiware-servicepath', 'gardens')
|
|
278
|
-
.patch(
|
|
279
|
-
'/v2/entities/ws4/attrs',
|
|
280
|
-
utils.readExampleFile(
|
|
281
|
-
'./test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin15.json'
|
|
282
|
-
)
|
|
283
|
-
)
|
|
284
|
-
.query({ type: 'WeatherStation' })
|
|
285
|
-
.reply(204);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('should apply the default (JEXL) expression before sending the values', function (done) {
|
|
289
|
-
iotAgentLib.update('ws4', 'WeatherStationJexl', '', values, function (error) {
|
|
290
|
-
should.not.exist(error);
|
|
291
|
-
contextBrokerMock.done();
|
|
292
|
-
done();
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
});
|