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.
- package/README.md +4 -0
- package/doc/admin.md +1 -13
- package/doc/api.md +116 -18
- package/doc/devel/architecture.md +0 -12
- package/doc/index.md +1 -1
- package/doc/roadmap.md +22 -10
- package/lib/commonConfig.js +0 -11
- package/lib/model/Device.js +2 -1
- package/lib/model/Group.js +2 -1
- package/lib/model/dbConn.js +22 -11
- package/lib/plugins/expressionPlugin.js +0 -5
- package/lib/plugins/jexlParser.js +15 -31
- package/lib/services/common/genericMiddleware.js +14 -2
- package/lib/services/common/iotManagerService.js +2 -1
- package/lib/services/devices/deviceRegistryMongoDB.js +3 -1
- package/lib/services/devices/deviceService.js +16 -21
- package/lib/services/devices/devices-NGSI-LD.js +5 -98
- package/lib/services/devices/devices-NGSI-mixed.js +0 -14
- package/lib/services/devices/devices-NGSI-v2.js +3 -0
- package/lib/services/groups/groupRegistryMemory.js +0 -25
- package/lib/services/groups/groupRegistryMongoDB.js +20 -19
- package/lib/services/groups/groupService.js +3 -14
- package/lib/services/ngsi/entities-NGSI-LD.js +81 -6
- package/lib/services/ngsi/entities-NGSI-v2.js +303 -698
- package/lib/services/ngsi/ngsiUtils.js +0 -30
- package/lib/services/northBound/deviceProvisioningServer.js +6 -3
- package/lib/templates/createDevice.json +4 -0
- package/lib/templates/createDeviceLax.json +4 -0
- package/lib/templates/deviceGroup.json +4 -0
- package/lib/templates/updateDevice.json +4 -0
- package/lib/templates/updateDeviceLax.json +4 -0
- package/package.json +6 -2
- package/test/functional/README.md +378 -0
- package/test/functional/config-test.js +70 -0
- package/test/functional/functional-tests-runner.js +126 -0
- package/test/functional/functional-tests.js +241 -0
- package/test/functional/testCases.js +2944 -0
- package/test/functional/testUtils.js +251 -0
- package/test/tools/utils.js +25 -0
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +35 -22
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +3 -34
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +8 -1
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin7.json +1 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin8.json +1 -6
- package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +67 -87
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +7 -13
- package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +43 -43
- package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +19 -29
- package/test/unit/ngsi-ld/ngsiService/languageProperties-test.js +0 -1
- package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +35 -46
- package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +8 -9
- package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +96 -221
- package/test/unit/ngsi-ld/provisioning/device-registration_test.js +18 -27
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +8 -16
- package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +0 -13
- package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +4 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29b.json +8 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +0 -6
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +8 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34b.json +14 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +1 -11
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36b.json +13 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin37.json +8 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +1 -11
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10b.json +37 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +4 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +0 -3
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +10 -12
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -5
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +8 -12
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +0 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +7 -1
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +898 -28
- package/test/unit/ngsiv2/ngsiService/active-devices-test.js +0 -4
- package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +267 -0
- package/test/unit/ngsiv2/plugins/alias-plugin_test.js +19 -21
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +21 -24
- package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +1 -21
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +4 -6
- package/test/unit/ngsi-ld/ngsiService/autocast-test.js +0 -438
- package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +0 -381
- package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +0 -311
- package/test/unit/ngsiv2/ngsiService/autocast-test.js +0 -325
- package/test/unit/ngsiv2/ngsiService/geoproperties-test.js +0 -427
- package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +0 -217
- package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +0 -119
- package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -309
|
@@ -1,381 +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, 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: Daniel Calvo - ATOS Research & Innovation
|
|
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: 'location',
|
|
54
|
-
type: 'GeoProperty'
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
service: 'smartgondor',
|
|
60
|
-
subservice: 'gardens',
|
|
61
|
-
providerUrl: 'http://smartgondor.com'
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
describe('NGSI-LD - Geo-JSON types autocast test', function () {
|
|
65
|
-
beforeEach(function () {
|
|
66
|
-
logger.setLevel('FATAL');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
afterEach(function (done) {
|
|
70
|
-
iotAgentLib.deactivate(done);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe(
|
|
74
|
-
'When the IoT Agent receives new geo-information from a device.' +
|
|
75
|
-
'Location with GeoProperty type and String value',
|
|
76
|
-
function () {
|
|
77
|
-
const values = [
|
|
78
|
-
{
|
|
79
|
-
name: 'location',
|
|
80
|
-
type: 'GeoProperty',
|
|
81
|
-
value: '23,12.5'
|
|
82
|
-
}
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
beforeEach(function (done) {
|
|
86
|
-
nock.cleanAll();
|
|
87
|
-
|
|
88
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
89
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
90
|
-
.post(
|
|
91
|
-
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
92
|
-
utils.readExampleFile(
|
|
93
|
-
'./test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties1.json'
|
|
94
|
-
)
|
|
95
|
-
)
|
|
96
|
-
.reply(204);
|
|
97
|
-
|
|
98
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
102
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
103
|
-
should.not.exist(error);
|
|
104
|
-
contextBrokerMock.done();
|
|
105
|
-
done();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
describe('When the IoT Agent receives new geo-information from a device. Location with Point type and Array value', function () {
|
|
112
|
-
const values = [
|
|
113
|
-
{
|
|
114
|
-
name: 'location',
|
|
115
|
-
type: 'Point',
|
|
116
|
-
value: [23, 12.5]
|
|
117
|
-
}
|
|
118
|
-
];
|
|
119
|
-
|
|
120
|
-
beforeEach(function (done) {
|
|
121
|
-
nock.cleanAll();
|
|
122
|
-
|
|
123
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
124
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
125
|
-
.post(
|
|
126
|
-
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
127
|
-
utils.readExampleFile(
|
|
128
|
-
'./test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties1.json'
|
|
129
|
-
)
|
|
130
|
-
)
|
|
131
|
-
.reply(204);
|
|
132
|
-
|
|
133
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
137
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
138
|
-
should.not.exist(error);
|
|
139
|
-
contextBrokerMock.done();
|
|
140
|
-
done();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe(
|
|
146
|
-
'When the IoT Agent receives new geo-information from a device.' +
|
|
147
|
-
'Location with LineString type and Array value',
|
|
148
|
-
function () {
|
|
149
|
-
const values = [
|
|
150
|
-
{
|
|
151
|
-
name: 'location',
|
|
152
|
-
type: 'LineString',
|
|
153
|
-
value: [
|
|
154
|
-
[23, 12.5],
|
|
155
|
-
[22, 12.5]
|
|
156
|
-
]
|
|
157
|
-
}
|
|
158
|
-
];
|
|
159
|
-
|
|
160
|
-
beforeEach(function (done) {
|
|
161
|
-
nock.cleanAll();
|
|
162
|
-
|
|
163
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
164
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
165
|
-
.post(
|
|
166
|
-
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
167
|
-
utils.readExampleFile(
|
|
168
|
-
'./test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties2.json'
|
|
169
|
-
)
|
|
170
|
-
)
|
|
171
|
-
.reply(204);
|
|
172
|
-
|
|
173
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
177
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
178
|
-
should.not.exist(error);
|
|
179
|
-
contextBrokerMock.done();
|
|
180
|
-
done();
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
describe(
|
|
187
|
-
'When the IoT Agent receives new geo-information from a device.' +
|
|
188
|
-
'Location with LineString type and Array of Strings',
|
|
189
|
-
function () {
|
|
190
|
-
const values = [
|
|
191
|
-
{
|
|
192
|
-
name: 'location',
|
|
193
|
-
type: 'LineString',
|
|
194
|
-
value: ['23,12.5', '22,12.5']
|
|
195
|
-
}
|
|
196
|
-
];
|
|
197
|
-
|
|
198
|
-
beforeEach(function (done) {
|
|
199
|
-
nock.cleanAll();
|
|
200
|
-
|
|
201
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
202
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
203
|
-
.post(
|
|
204
|
-
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
205
|
-
utils.readExampleFile(
|
|
206
|
-
'./test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties2.json'
|
|
207
|
-
)
|
|
208
|
-
)
|
|
209
|
-
.reply(204);
|
|
210
|
-
|
|
211
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
215
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
216
|
-
should.not.exist(error);
|
|
217
|
-
contextBrokerMock.done();
|
|
218
|
-
done();
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
describe('When the IoT Agent receives new geo-information from a device. Location with None type', function () {
|
|
225
|
-
const values = [
|
|
226
|
-
{
|
|
227
|
-
name: 'location',
|
|
228
|
-
type: 'None',
|
|
229
|
-
value: 'null'
|
|
230
|
-
}
|
|
231
|
-
];
|
|
232
|
-
|
|
233
|
-
beforeEach(function (done) {
|
|
234
|
-
nock.cleanAll();
|
|
235
|
-
|
|
236
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
237
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
238
|
-
.post(
|
|
239
|
-
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
240
|
-
utils.readExampleFile(
|
|
241
|
-
'./test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties3.json'
|
|
242
|
-
)
|
|
243
|
-
)
|
|
244
|
-
.reply(204);
|
|
245
|
-
|
|
246
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
250
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
251
|
-
should.not.exist(error);
|
|
252
|
-
contextBrokerMock.done();
|
|
253
|
-
done();
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
describe(
|
|
259
|
-
'When the IoT Agent receives new geo-information from a device.' +
|
|
260
|
-
'Location with Polygon type - Array of coordinates',
|
|
261
|
-
function () {
|
|
262
|
-
const values = [
|
|
263
|
-
{
|
|
264
|
-
name: 'location',
|
|
265
|
-
type: 'Polygon',
|
|
266
|
-
value: [
|
|
267
|
-
[23, 12.5],
|
|
268
|
-
[22, 13.5],
|
|
269
|
-
[22, 13.5]
|
|
270
|
-
]
|
|
271
|
-
}
|
|
272
|
-
];
|
|
273
|
-
|
|
274
|
-
beforeEach(function (done) {
|
|
275
|
-
nock.cleanAll();
|
|
276
|
-
|
|
277
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
278
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
279
|
-
.post(
|
|
280
|
-
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
281
|
-
utils.readExampleFile(
|
|
282
|
-
'./test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties4.json'
|
|
283
|
-
)
|
|
284
|
-
)
|
|
285
|
-
.reply(204);
|
|
286
|
-
|
|
287
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
291
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
292
|
-
should.not.exist(error);
|
|
293
|
-
contextBrokerMock.done();
|
|
294
|
-
done();
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
describe(
|
|
301
|
-
'When the IoT Agent receives new geo-information from a device.' +
|
|
302
|
-
'Location with Polygon type - list of coordinates',
|
|
303
|
-
function () {
|
|
304
|
-
const values = [
|
|
305
|
-
{
|
|
306
|
-
name: 'location',
|
|
307
|
-
type: 'Polygon',
|
|
308
|
-
value: '23,12.5,22,13.5,22,13.5'
|
|
309
|
-
}
|
|
310
|
-
];
|
|
311
|
-
|
|
312
|
-
beforeEach(function (done) {
|
|
313
|
-
nock.cleanAll();
|
|
314
|
-
|
|
315
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
316
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
317
|
-
.post(
|
|
318
|
-
'/ngsi-ld/v1/entityOperations/upsert/?options=update',
|
|
319
|
-
utils.readExampleFile(
|
|
320
|
-
'./test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties4.json'
|
|
321
|
-
)
|
|
322
|
-
)
|
|
323
|
-
.reply(204);
|
|
324
|
-
|
|
325
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
329
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
330
|
-
should.not.exist(error);
|
|
331
|
-
contextBrokerMock.done();
|
|
332
|
-
done();
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
);
|
|
337
|
-
|
|
338
|
-
describe('When the IoT Agent receives new geo-information from a device. Location with a missing latitude', function () {
|
|
339
|
-
const values = [
|
|
340
|
-
{
|
|
341
|
-
name: 'location',
|
|
342
|
-
type: 'Point',
|
|
343
|
-
value: '23,12.5,22,13.5,22'
|
|
344
|
-
}
|
|
345
|
-
];
|
|
346
|
-
|
|
347
|
-
beforeEach(function (done) {
|
|
348
|
-
nock.cleanAll();
|
|
349
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
it('should throw a BadGeocoordinates Error', function (done) {
|
|
353
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
354
|
-
should.exist(error);
|
|
355
|
-
done();
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
describe('When the IoT Agent receives new geo-information from a device. Location invalid coordinates', function () {
|
|
361
|
-
const values = [
|
|
362
|
-
{
|
|
363
|
-
name: 'location',
|
|
364
|
-
type: 'Point',
|
|
365
|
-
value: '2016-04-30Z'
|
|
366
|
-
}
|
|
367
|
-
];
|
|
368
|
-
|
|
369
|
-
beforeEach(function (done) {
|
|
370
|
-
nock.cleanAll();
|
|
371
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
it('should throw a BadGeocoordinates Error', function (done) {
|
|
375
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
376
|
-
should.exist(error);
|
|
377
|
-
done();
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
});
|
|
@@ -1,311 +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
|
-
|
|
32
|
-
const should = require('should');
|
|
33
|
-
const nock = require('nock');
|
|
34
|
-
let contextBrokerMock;
|
|
35
|
-
|
|
36
|
-
const iotAgentConfig = {
|
|
37
|
-
logLevel: 'FATAL',
|
|
38
|
-
contextBroker: {
|
|
39
|
-
host: '192.168.1.1',
|
|
40
|
-
port: '1026',
|
|
41
|
-
ngsiVersion: 'ld',
|
|
42
|
-
jsonLdContext: 'http://context.json-ld'
|
|
43
|
-
},
|
|
44
|
-
server: {
|
|
45
|
-
port: 4041,
|
|
46
|
-
host: 'localhost',
|
|
47
|
-
baseRoot: '/'
|
|
48
|
-
},
|
|
49
|
-
types: {},
|
|
50
|
-
service: 'smartgondor',
|
|
51
|
-
singleConfigurationMode: true,
|
|
52
|
-
subservice: 'gardens',
|
|
53
|
-
providerUrl: 'http://smartgondor.com'
|
|
54
|
-
};
|
|
55
|
-
const groupCreation = {
|
|
56
|
-
url: 'http://localhost:4041/iot/services',
|
|
57
|
-
method: 'POST',
|
|
58
|
-
json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/provisionFullGroup.json'),
|
|
59
|
-
headers: {
|
|
60
|
-
'fiware-service': 'testservice',
|
|
61
|
-
'fiware-servicepath': '/testingPath'
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const deviceCreation = {
|
|
65
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
66
|
-
method: 'POST',
|
|
67
|
-
json: utils.readExampleFile('./test/unit/examples/deviceProvisioningRequests/provisionNewDevice.json'),
|
|
68
|
-
headers: {
|
|
69
|
-
'fiware-service': 'testservice',
|
|
70
|
-
'fiware-servicepath': '/testingPath'
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
describe('NGSI-LD - Provisioning API: Single service mode', function () {
|
|
75
|
-
beforeEach(function (done) {
|
|
76
|
-
nock.cleanAll();
|
|
77
|
-
|
|
78
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
79
|
-
iotAgentLib.clearAll(done);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
afterEach(function (done) {
|
|
84
|
-
nock.cleanAll();
|
|
85
|
-
iotAgentLib.setProvisioningHandler();
|
|
86
|
-
iotAgentLib.deactivate(done);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('When a new configuration arrives to an already configured subservice', function () {
|
|
90
|
-
const groupCreationDuplicated = {
|
|
91
|
-
url: 'http://localhost:4041/iot/services',
|
|
92
|
-
method: 'POST',
|
|
93
|
-
json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/provisionDuplicateGroup.json'),
|
|
94
|
-
headers: {
|
|
95
|
-
'fiware-service': 'testservice',
|
|
96
|
-
'fiware-servicepath': '/testingPath'
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
beforeEach(function (done) {
|
|
101
|
-
request(groupCreation, done);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should raise a DUPLICATE_GROUP error', function (done) {
|
|
105
|
-
request(groupCreationDuplicated, function (error, response, body) {
|
|
106
|
-
should.not.exist(error);
|
|
107
|
-
response.statusCode.should.equal(409);
|
|
108
|
-
should.exist(body.name);
|
|
109
|
-
body.name.should.equal('DUPLICATE_GROUP');
|
|
110
|
-
done();
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
describe('When a device is provisioned with an ID that already exists in the configuration', function () {
|
|
115
|
-
const deviceCreationDuplicated = {
|
|
116
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
117
|
-
method: 'POST',
|
|
118
|
-
json: utils.readExampleFile('./test/unit/examples/deviceProvisioningRequests/provisionDuplicatedDev.json'),
|
|
119
|
-
headers: {
|
|
120
|
-
'fiware-service': 'testservice',
|
|
121
|
-
'fiware-servicepath': '/testingPath'
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
beforeEach(function (done) {
|
|
126
|
-
nock.cleanAll();
|
|
127
|
-
|
|
128
|
-
contextBrokerMock = nock('http://unexistentHost:1026')
|
|
129
|
-
.matchHeader('fiware-service', 'testservice')
|
|
130
|
-
.post('/ngsi-ld/v1/csourceRegistrations/')
|
|
131
|
-
.reply(201, null, { Location: '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' });
|
|
132
|
-
|
|
133
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
134
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
135
|
-
// provisioning folder
|
|
136
|
-
contextBrokerMock
|
|
137
|
-
.matchHeader('fiware-service', 'testservice')
|
|
138
|
-
.post('/ngsi-ld/v1/entityOperations/upsert/')
|
|
139
|
-
.reply(204);
|
|
140
|
-
|
|
141
|
-
request(groupCreation, function (error) {
|
|
142
|
-
request(deviceCreation, function (error, response, body) {
|
|
143
|
-
done();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should raise a DUPLICATE_DEVICE_ID error', function (done) {
|
|
149
|
-
request(deviceCreationDuplicated, function (error, response, body) {
|
|
150
|
-
should.not.exist(error);
|
|
151
|
-
response.statusCode.should.equal(409);
|
|
152
|
-
should.exist(body.name);
|
|
153
|
-
body.name.should.equal('DUPLICATE_DEVICE_ID');
|
|
154
|
-
done();
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe('When a device is provisioned with an ID that exists globally but not in the configuration', function () {
|
|
159
|
-
const alternativeDeviceCreation = {
|
|
160
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
161
|
-
method: 'POST',
|
|
162
|
-
json: utils.readExampleFile('./test/unit/examples/deviceProvisioningRequests/provisionNewDevice.json'),
|
|
163
|
-
headers: {
|
|
164
|
-
'fiware-service': 'AlternateService',
|
|
165
|
-
'fiware-servicepath': '/testingPath'
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const alternativeGroupCreation = {
|
|
169
|
-
url: 'http://localhost:4041/iot/services',
|
|
170
|
-
method: 'POST',
|
|
171
|
-
json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/provisionFullGroup.json'),
|
|
172
|
-
headers: {
|
|
173
|
-
'fiware-service': 'AlternateService',
|
|
174
|
-
'fiware-servicepath': '/testingPath'
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
beforeEach(function (done) {
|
|
179
|
-
nock.cleanAll();
|
|
180
|
-
|
|
181
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
182
|
-
.matchHeader('fiware-service', 'testservice')
|
|
183
|
-
.post('/ngsi-ld/v1/csourceRegistrations/')
|
|
184
|
-
.reply(201, null, { Location: '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' });
|
|
185
|
-
|
|
186
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
187
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
188
|
-
// provisioning folder
|
|
189
|
-
contextBrokerMock
|
|
190
|
-
.matchHeader('fiware-service', 'testservice')
|
|
191
|
-
.post('/ngsi-ld/v1/entityOperations/upsert/')
|
|
192
|
-
.reply(204);
|
|
193
|
-
|
|
194
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
195
|
-
.matchHeader('fiware-service', 'AlternateService')
|
|
196
|
-
.post('/ngsi-ld/v1/csourceRegistrations/')
|
|
197
|
-
.reply(201, null, { Location: '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' });
|
|
198
|
-
|
|
199
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
200
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
201
|
-
// provisioning folder
|
|
202
|
-
contextBrokerMock
|
|
203
|
-
.matchHeader('fiware-service', 'AlternateService')
|
|
204
|
-
.post('/ngsi-ld/v1/entityOperations/upsert/')
|
|
205
|
-
.reply(204);
|
|
206
|
-
|
|
207
|
-
request(groupCreation, function (error) {
|
|
208
|
-
request(deviceCreation, function (error, response, body) {
|
|
209
|
-
request(alternativeGroupCreation, function (error, response, body) {
|
|
210
|
-
done();
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('should return a 201 OK', function (done) {
|
|
217
|
-
request(alternativeDeviceCreation, function (error, response, body) {
|
|
218
|
-
should.not.exist(error);
|
|
219
|
-
response.statusCode.should.equal(201);
|
|
220
|
-
done();
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
describe('When a device is provisioned without a type and with a default configuration type', function () {
|
|
225
|
-
const getDevice = {
|
|
226
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices/Light1',
|
|
227
|
-
method: 'GET',
|
|
228
|
-
headers: {
|
|
229
|
-
'fiware-service': 'testservice',
|
|
230
|
-
'fiware-servicepath': '/testingPath'
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
let oldType;
|
|
234
|
-
|
|
235
|
-
beforeEach(function (done) {
|
|
236
|
-
nock.cleanAll();
|
|
237
|
-
|
|
238
|
-
contextBrokerMock = nock('http://unexistentHost:1026')
|
|
239
|
-
.matchHeader('fiware-service', 'testservice')
|
|
240
|
-
.post('/ngsi-ld/v1/csourceRegistrations/')
|
|
241
|
-
.reply(201, null, { Location: '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' });
|
|
242
|
-
|
|
243
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
244
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
245
|
-
// provisioning folder
|
|
246
|
-
contextBrokerMock
|
|
247
|
-
.matchHeader('fiware-service', 'testservice')
|
|
248
|
-
.post('/ngsi-ld/v1/entityOperations/upsert/')
|
|
249
|
-
.reply(204);
|
|
250
|
-
|
|
251
|
-
oldType = deviceCreation.json.devices[0].entity_type;
|
|
252
|
-
delete deviceCreation.json.devices[0].entity_type;
|
|
253
|
-
request(groupCreation, done);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
afterEach(function () {
|
|
257
|
-
deviceCreation.json.devices[0].entity_type = oldType;
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it('should be provisioned with the default type', function (done) {
|
|
261
|
-
request(deviceCreation, function (error, response, body) {
|
|
262
|
-
request(getDevice, function (error, response, body) {
|
|
263
|
-
body.entity_type.should.equal('SensorMachine');
|
|
264
|
-
done();
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
describe('When a device is provisioned for a configuration', function () {
|
|
270
|
-
beforeEach(function (done) {
|
|
271
|
-
nock.cleanAll();
|
|
272
|
-
contextBrokerMock = nock('http://unexistentHost:1026')
|
|
273
|
-
.matchHeader('fiware-service', 'testservice')
|
|
274
|
-
.post(
|
|
275
|
-
'/ngsi-ld/v1/csourceRegistrations/',
|
|
276
|
-
utils.readExampleFile(
|
|
277
|
-
'./test/unit/ngsi-ld/examples' +
|
|
278
|
-
'/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json'
|
|
279
|
-
)
|
|
280
|
-
)
|
|
281
|
-
.reply(201, null, { Location: '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' });
|
|
282
|
-
|
|
283
|
-
contextBrokerMock
|
|
284
|
-
.matchHeader('fiware-service', 'testservice')
|
|
285
|
-
.post(
|
|
286
|
-
'/ngsi-ld/v1/entityOperations/upsert/',
|
|
287
|
-
utils.readExampleFile(
|
|
288
|
-
'./test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json'
|
|
289
|
-
)
|
|
290
|
-
)
|
|
291
|
-
.reply(204);
|
|
292
|
-
|
|
293
|
-
request(groupCreation, done);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it('should not raise any error', function (done) {
|
|
297
|
-
request(deviceCreation, function (error, response, body) {
|
|
298
|
-
should.not.exist(error);
|
|
299
|
-
response.statusCode.should.equal(201);
|
|
300
|
-
done();
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
// FIXME: disabled test by #1421
|
|
304
|
-
// it('should send the mixed data to the Context Broker', function (done) {
|
|
305
|
-
// request(deviceCreation, function (error, response, body) {
|
|
306
|
-
// contextBrokerMock.done();
|
|
307
|
-
// done();
|
|
308
|
-
// });
|
|
309
|
-
// });
|
|
310
|
-
});
|
|
311
|
-
});
|