iotagent-node-lib 2.25.0 → 2.26.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 -1
- package/config.js +6 -1
- package/doc/deprecated.md +4 -1
- package/doc/howto.md +8 -0
- package/doc/installationguide.md +18 -0
- package/doc/usermanual.md +77 -0
- package/lib/commonConfig.js +15 -1
- package/lib/constants.js +1 -0
- package/lib/fiware-iotagent-lib.js +1 -0
- package/lib/services/devices/deviceService.js +1 -0
- package/lib/services/devices/registrationUtils.js +21 -1
- package/lib/services/northBound/contextServer-NGSI-LD.js +221 -38
- package/lib/services/northBound/contextServer.js +14 -1
- package/lib/services/northBound/northboundServer.js +1 -0
- package/package.json +1 -1
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent1.json +24 -14
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent2.json +25 -15
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent4.json +15 -5
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +9 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommandsAndLazy.json +32 -0
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDevice.json +12 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +9 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +12 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +12 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup3.json +9 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateCommands1.json +10 -2
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent1.json +11 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent2.json +12 -1
- package/test/unit/ngsi-ld/general/startup-test.js +17 -2
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +1 -12
- package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +249 -0
- package/test/unit/ngsi-ld/ngsiService/unsupported-endpoints-test.js +171 -0
|
@@ -0,0 +1,249 @@
|
|
|
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, 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: 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
|
+
const mongoUtils = require('../../mongodb/mongoDBUtils');
|
|
35
|
+
|
|
36
|
+
const timekeeper = require('timekeeper');
|
|
37
|
+
let contextBrokerMock;
|
|
38
|
+
let statusAttributeMock;
|
|
39
|
+
const iotAgentConfig = {
|
|
40
|
+
contextBroker: {
|
|
41
|
+
host: '192.168.1.1',
|
|
42
|
+
port: '1026',
|
|
43
|
+
ngsiVersion: 'ld',
|
|
44
|
+
jsonLdContext: 'http://context.json-ld'
|
|
45
|
+
},
|
|
46
|
+
server: {
|
|
47
|
+
port: 4041,
|
|
48
|
+
ldSupport: {
|
|
49
|
+
null: true,
|
|
50
|
+
datasetId: false,
|
|
51
|
+
merge: true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
types: {
|
|
55
|
+
Robot: {
|
|
56
|
+
internalAttributes:[],
|
|
57
|
+
commands:[
|
|
58
|
+
{
|
|
59
|
+
name: 'position',
|
|
60
|
+
object_id: 'pos',
|
|
61
|
+
type: 'Object'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'orientation',
|
|
65
|
+
type: 'Object'
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
lazy: [
|
|
69
|
+
{
|
|
70
|
+
name: 'batteryLevel',
|
|
71
|
+
type: 'Object'
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
staticAttributes: [],
|
|
75
|
+
active: []
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
service: 'smartgondor',
|
|
79
|
+
providerUrl: 'http://smartgondor.com'
|
|
80
|
+
};
|
|
81
|
+
const device3 = {
|
|
82
|
+
id: 'r2d2',
|
|
83
|
+
type: 'Robot',
|
|
84
|
+
service: 'smartgondor'
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
describe('NGSI-LD - Merge-Patch functionalities', function () {
|
|
88
|
+
beforeEach(function (done) {
|
|
89
|
+
const time = new Date(1438760101468); // 2015-08-05T07:35:01.468+00:00
|
|
90
|
+
timekeeper.freeze(time);
|
|
91
|
+
nock.cleanAll();
|
|
92
|
+
|
|
93
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
94
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
95
|
+
.post(
|
|
96
|
+
'/ngsi-ld/v1/csourceRegistrations/',
|
|
97
|
+
utils.readExampleFile(
|
|
98
|
+
'./test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommandsAndLazy.json'
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
.reply(201, null, { Location: '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' });
|
|
102
|
+
|
|
103
|
+
contextBrokerMock
|
|
104
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
105
|
+
.post('/ngsi-ld/v1/entityOperations/upsert/')
|
|
106
|
+
.reply(204);
|
|
107
|
+
|
|
108
|
+
iotAgentLib.activate(iotAgentConfig, done);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
afterEach(function (done) {
|
|
112
|
+
timekeeper.reset();
|
|
113
|
+
delete device3.registrationId;
|
|
114
|
+
iotAgentLib.clearAll(function () {
|
|
115
|
+
iotAgentLib.deactivate(function () {
|
|
116
|
+
mongoUtils.cleanDbs(function () {
|
|
117
|
+
nock.cleanAll();
|
|
118
|
+
iotAgentLib.setDataUpdateHandler();
|
|
119
|
+
iotAgentLib.setCommandHandler();
|
|
120
|
+
done();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('When a merge-patch PATCH arrives to the IoT Agent as Context Provider', function () {
|
|
127
|
+
const options = {
|
|
128
|
+
url:
|
|
129
|
+
'http://localhost:' +
|
|
130
|
+
iotAgentConfig.server.port +
|
|
131
|
+
'/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2',
|
|
132
|
+
method: 'PATCH',
|
|
133
|
+
json: {
|
|
134
|
+
"position": {
|
|
135
|
+
"type": "Property",
|
|
136
|
+
"value": {
|
|
137
|
+
"moveTo" : [12,34],
|
|
138
|
+
"observedAt": "urn:ngsi-ld:null",
|
|
139
|
+
"precision": {
|
|
140
|
+
"value": 0.95,
|
|
141
|
+
"unitCode": "C62"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
"orientation" : "urn:ngsi-ld:null"
|
|
146
|
+
},
|
|
147
|
+
headers: {
|
|
148
|
+
'fiware-service': 'smartgondor',
|
|
149
|
+
'content-type': 'application/ld+json'
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
beforeEach(function (done) {
|
|
154
|
+
iotAgentLib.register(device3, function (error) {
|
|
155
|
+
done();
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should call the client handler once', function (done) {
|
|
160
|
+
let handlerCalled = 0;
|
|
161
|
+
|
|
162
|
+
iotAgentLib.setMergePatchHandler(function (id, type, service, subservice, attributes, callback) {
|
|
163
|
+
id.should.equal('urn:ngsi-ld:' + device3.type + ':' + device3.id);
|
|
164
|
+
type.should.equal(device3.type);
|
|
165
|
+
attributes[0].name.should.equal('position');
|
|
166
|
+
attributes[1].name.should.equal('orientation');
|
|
167
|
+
should.equal(attributes[1].value, null);
|
|
168
|
+
handlerCalled++;
|
|
169
|
+
callback(null, {
|
|
170
|
+
id,
|
|
171
|
+
type,
|
|
172
|
+
attributes: [
|
|
173
|
+
{
|
|
174
|
+
name: 'position',
|
|
175
|
+
type: 'Array',
|
|
176
|
+
value: '[28, -104, 23]'
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
request(options, function (error, response, body) {
|
|
183
|
+
should.not.exist(error);
|
|
184
|
+
response.statusCode.should.equal(200);
|
|
185
|
+
handlerCalled.should.equal(1);
|
|
186
|
+
done();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
xdescribe('When a partial update PATCH with an NGSI-LD Null arrives to the IoT Agent as Context Provider', function () {
|
|
193
|
+
const options = {
|
|
194
|
+
url:
|
|
195
|
+
'http://localhost:' +
|
|
196
|
+
iotAgentConfig.server.port +
|
|
197
|
+
'/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs/position',
|
|
198
|
+
method: 'PATCH',
|
|
199
|
+
json: {
|
|
200
|
+
"type": "Property",
|
|
201
|
+
"value": "urn:ngsi-ld:null"
|
|
202
|
+
},
|
|
203
|
+
headers: {
|
|
204
|
+
'fiware-service': 'smartgondor',
|
|
205
|
+
'content-type': 'application/ld+json'
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
beforeEach(function (done) {
|
|
210
|
+
logger.setLevel('FATAL');
|
|
211
|
+
iotAgentLib.register(device3, function (error) {
|
|
212
|
+
done();
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should call the client handler once', function (done) {
|
|
217
|
+
let handlerCalled = 0;
|
|
218
|
+
|
|
219
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
220
|
+
id.should.equal('urn:ngsi-ld:' + device3.type + ':' + device3.id);
|
|
221
|
+
type.should.equal(device3.type);
|
|
222
|
+
attributes[0].name.should.equal('position');
|
|
223
|
+
should.equal(attributes[0].value, null);
|
|
224
|
+
handlerCalled++;
|
|
225
|
+
callback(null, {
|
|
226
|
+
id,
|
|
227
|
+
type,
|
|
228
|
+
attributes: [
|
|
229
|
+
{
|
|
230
|
+
name: 'position',
|
|
231
|
+
type: 'Array',
|
|
232
|
+
value: null
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
request(options, function (error, response, body) {
|
|
239
|
+
console.error(error)
|
|
240
|
+
should.not.exist(error);
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
response.statusCode.should.equal(204);
|
|
244
|
+
handlerCalled.should.equal(1);
|
|
245
|
+
done();
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
@@ -29,6 +29,7 @@ const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
|
|
|
29
29
|
const utils = require('../../../tools/utils');
|
|
30
30
|
const request = utils.request;
|
|
31
31
|
const should = require('should');
|
|
32
|
+
const nock = require('nock');
|
|
32
33
|
|
|
33
34
|
let contextBrokerMock;
|
|
34
35
|
const iotAgentConfig = {
|
|
@@ -47,6 +48,50 @@ const iotAgentConfig = {
|
|
|
47
48
|
providerUrl: 'http://smartgondor.com'
|
|
48
49
|
};
|
|
49
50
|
|
|
51
|
+
|
|
52
|
+
const iotAgentConfigWithLimitedSupport = {
|
|
53
|
+
contextBroker: {
|
|
54
|
+
host: '192.168.1.1',
|
|
55
|
+
port: '1026',
|
|
56
|
+
ngsiVersion: 'ld',
|
|
57
|
+
jsonLdContext: 'http://context.json-ld'
|
|
58
|
+
},
|
|
59
|
+
server: {
|
|
60
|
+
port: 4041,
|
|
61
|
+
ldSupport : {
|
|
62
|
+
null: false,
|
|
63
|
+
datasetId: false
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
types: {
|
|
67
|
+
Robot: {
|
|
68
|
+
commands: [
|
|
69
|
+
{
|
|
70
|
+
name: 'position',
|
|
71
|
+
type: 'Array'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'orientation',
|
|
75
|
+
type: 'Array'
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
lazy: [],
|
|
79
|
+
staticAttributes: [],
|
|
80
|
+
active: []
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
service: 'smartgondor',
|
|
84
|
+
subservice: 'gardens',
|
|
85
|
+
providerUrl: 'http://smartgondor.com'
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const device = {
|
|
89
|
+
id: 'r2d2',
|
|
90
|
+
type: 'Robot',
|
|
91
|
+
service: 'smartgondor'
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
|
|
50
95
|
describe('NGSI-LD - Unsupported Endpoints', function () {
|
|
51
96
|
beforeEach(function (done) {
|
|
52
97
|
iotAgentLib.activate(iotAgentConfig, function () {
|
|
@@ -107,5 +152,131 @@ describe('NGSI-LD - Unsupported Endpoints', function () {
|
|
|
107
152
|
done();
|
|
108
153
|
});
|
|
109
154
|
});
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
it('PUT /entities/<entity-id> includes an NGSI-LD Null should return a valid NSGI-LD error message', function (done) {
|
|
158
|
+
const options = {
|
|
159
|
+
url:
|
|
160
|
+
'http://localhost:' +
|
|
161
|
+
iotAgentConfig.server.port +
|
|
162
|
+
'/ngsi-ld/v1/entities/urn:ngsi-ld:entity/attrs/att',
|
|
163
|
+
method: 'PUT',
|
|
164
|
+
json: {
|
|
165
|
+
"value": "urn:ngsi-ld:null"
|
|
166
|
+
},
|
|
167
|
+
headers: {
|
|
168
|
+
'fiware-service': 'smartgondor',
|
|
169
|
+
'content-type': 'application/ld+json'
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
request(options, function (error, response, body) {
|
|
173
|
+
response.statusCode.should.equal(400);
|
|
174
|
+
done();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('NGSI-LD - Limiting Support', function () {
|
|
181
|
+
beforeEach(function (done) {
|
|
182
|
+
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
183
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
184
|
+
.post(
|
|
185
|
+
'/ngsi-ld/v1/csourceRegistrations/',
|
|
186
|
+
utils.readExampleFile(
|
|
187
|
+
'./test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommands.json'
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
.reply(201, null, { Location: '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' });
|
|
191
|
+
|
|
192
|
+
contextBrokerMock
|
|
193
|
+
.matchHeader('fiware-service', 'smartgondor')
|
|
194
|
+
.post('/ngsi-ld/v1/entityOperations/upsert/')
|
|
195
|
+
.reply(204);
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
iotAgentLib.activate(iotAgentConfigWithLimitedSupport, function () {
|
|
199
|
+
iotAgentLib.clearAll(function () {
|
|
200
|
+
done();
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
afterEach(function (done) {
|
|
206
|
+
iotAgentLib.clearAll(function () {
|
|
207
|
+
iotAgentLib.deactivate(done);
|
|
208
|
+
});
|
|
110
209
|
});
|
|
210
|
+
|
|
211
|
+
describe('When sending sending an NGSI-LD Null when nulls are unsupported', function () {
|
|
212
|
+
it('should return a valid NSGI-LD error message', function (done) {
|
|
213
|
+
const options = {
|
|
214
|
+
url:
|
|
215
|
+
'http://localhost:' +
|
|
216
|
+
iotAgentConfig.server.port +
|
|
217
|
+
'/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs/position',
|
|
218
|
+
method: 'PATCH',
|
|
219
|
+
json: {
|
|
220
|
+
"value": "urn:ngsi-ld:null"
|
|
221
|
+
},
|
|
222
|
+
headers: {
|
|
223
|
+
'fiware-service': 'smartgondor',
|
|
224
|
+
'content-type': 'application/ld+json'
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
229
|
+
callback(null, {});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
iotAgentLib.register(device, function (error) {
|
|
233
|
+
request(options, function (error, response, body) {
|
|
234
|
+
response.statusCode.should.equal(400);
|
|
235
|
+
done();
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
describe('When sending a payload including a datasetId when datasetIds are unsupported ', function () {
|
|
242
|
+
it('should return a valid NSGI-LD error message', function (done) {
|
|
243
|
+
const options = {
|
|
244
|
+
url:
|
|
245
|
+
'http://localhost:' +
|
|
246
|
+
iotAgentConfig.server.port +
|
|
247
|
+
'/ngsi-ld/v1/entities/urn:ngsi-ld:Robot:r2d2/attrs/',
|
|
248
|
+
method: 'PATCH',
|
|
249
|
+
json: {
|
|
250
|
+
position: [
|
|
251
|
+
{
|
|
252
|
+
type: 'Property',
|
|
253
|
+
value: [1, 2, 3],
|
|
254
|
+
datasetId: 'urn:ngsi-ld:this'
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
type: 'Property',
|
|
258
|
+
value: [28, -104, 23],
|
|
259
|
+
datasetId: 'urn:ngsi-ld:that'
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
},
|
|
263
|
+
headers: {
|
|
264
|
+
'fiware-service': 'smartgondor',
|
|
265
|
+
'content-type': 'application/ld+json'
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
iotAgentLib.setCommandHandler(function (id, type, service, subservice, attributes, callback) {
|
|
270
|
+
callback(null, {});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
iotAgentLib.register(device, function (error) {
|
|
274
|
+
request(options, function (error, response, body) {
|
|
275
|
+
response.statusCode.should.equal(400);
|
|
276
|
+
done();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
});
|
|
281
|
+
});
|
|
111
282
|
});
|