iotagent-node-lib 4.6.0 → 4.8.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/.github/workflows/ci.yml +2 -3
- package/CHANGES_NEXT_RELEASE +1 -0
- package/Changelog +20 -0
- package/config.js +3 -1
- package/doc/README.md +1 -0
- package/doc/admin.md +39 -5
- package/doc/api.md +74 -9
- package/doc/devel/northboundinteractions.md +122 -15
- package/doc/models/models.md +260 -0
- package/doc/requirements.txt +1 -1
- package/docker/Mosquitto/Dockerfile +1 -1
- package/lib/commonConfig.js +21 -2
- package/lib/fiware-iotagent-lib.js +15 -11
- package/lib/jexlTranformsMap.js +182 -35
- package/lib/model/Command.js +11 -2
- package/lib/model/Device.js +8 -3
- package/lib/model/Group.js +5 -3
- package/lib/model/dbConn.js +53 -112
- package/lib/services/commands/commandRegistryMongoDB.js +130 -76
- package/lib/services/commands/commandService.js +3 -3
- package/lib/services/common/iotManagerService.js +3 -1
- package/lib/services/devices/deviceRegistryMemory.js +36 -0
- package/lib/services/devices/deviceRegistryMongoDB.js +161 -88
- package/lib/services/devices/deviceService.js +44 -5
- package/lib/services/devices/devices-NGSI-v2.js +6 -1
- package/lib/services/groups/groupRegistryMongoDB.js +120 -83
- package/lib/services/ngsi/entities-NGSI-v2.js +14 -1
- package/lib/services/ngsi/ngsiService.js +32 -1
- package/lib/services/northBound/contextServer-NGSI-v2.js +12 -3
- package/lib/services/northBound/contextServer.js +2 -1
- package/lib/services/northBound/deviceProvisioningServer.js +12 -3
- package/lib/services/northBound/northboundServer.js +1 -0
- package/lib/templates/createDevice.json +4 -0
- package/lib/templates/updateDevice.json +16 -0
- package/lib/templates/updateDeviceLax.json +12 -0
- package/package.json +4 -4
- package/test/functional/config-test.js +3 -2
- package/test/functional/testUtils.js +15 -4
- package/test/unit/examples/groupProvisioningRequests/provisionFullGroup.json +1 -0
- package/test/unit/expressions/jexlExpression-test.js +165 -1
- package/test/unit/general/config-multi-core-test.js +1 -2
- package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +5 -4
- package/test/unit/general/deviceService-test.js +6 -5
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +6 -5
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +7 -39
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1 -2
- package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +1 -2
- package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +8 -5
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +42 -41
- package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +11 -10
- package/test/unit/ngsiv2/general/deviceService-test.js +6 -5
- package/test/unit/ngsiv2/general/https-support-test.js +1 -1
- package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +4 -3
- package/test/unit/ngsiv2/lazyAndCommands/command-test.js +6 -5
- package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +17 -16
- package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +10 -18
- package/test/unit/ngsiv2/ngsiService/active-devices-test.js +21 -20
- package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +8 -7
- package/test/unit/ngsiv2/plugins/alias-plugin_test.js +12 -11
- package/test/unit/ngsiv2/plugins/custom-plugin_test.js +3 -2
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +28 -27
- package/test/unit/ngsiv2/provisioning/device-group-api-test.js +6 -4
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +12 -11
- package/test/unit/ngsiv2/provisioning/device-provisioning-configGroup-api_test.js +11 -10
- package/test/unit/ngsiv2/provisioning/device-registration_test.js +5 -4
- package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +6 -5
- package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +1 -1
- package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +5 -4
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +8 -7
- package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +0 -326
|
@@ -48,7 +48,8 @@ const iotAgentConfig = {
|
|
|
48
48
|
types: {},
|
|
49
49
|
service: 'smartgondor',
|
|
50
50
|
subservice: 'gardens',
|
|
51
|
-
providerUrl: 'http://smartgondor.com'
|
|
51
|
+
providerUrl: 'http://smartgondor.com',
|
|
52
|
+
useCBflowControl: true
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
describe('NGSI-v2 - Device provisioning API: Update provisioned devices', function () {
|
|
@@ -107,7 +108,7 @@ describe('NGSI-v2 - Device provisioning API: Update provisioned devices', functi
|
|
|
107
108
|
contextBrokerMock
|
|
108
109
|
.matchHeader('fiware-service', 'smartgondor')
|
|
109
110
|
.matchHeader('fiware-servicepath', '/gardens')
|
|
110
|
-
.post('/v2/entities?options=upsert')
|
|
111
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
111
112
|
.reply(204);
|
|
112
113
|
|
|
113
114
|
const nockBody2 = utils.readExampleFile(
|
|
@@ -126,7 +127,7 @@ describe('NGSI-v2 - Device provisioning API: Update provisioned devices', functi
|
|
|
126
127
|
contextBrokerMock
|
|
127
128
|
.matchHeader('fiware-service', 'smartgondor')
|
|
128
129
|
.matchHeader('fiware-servicepath', '/gardens')
|
|
129
|
-
.post('/v2/entities?options=upsert')
|
|
130
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
130
131
|
.reply(204);
|
|
131
132
|
|
|
132
133
|
// FIXME: When https://github.com/telefonicaid/fiware-orion/issues/3007 is merged into master branch,
|
|
@@ -181,7 +182,7 @@ describe('NGSI-v2 - Device provisioning API: Update provisioned devices', functi
|
|
|
181
182
|
.matchHeader('fiware-service', 'smartgondor')
|
|
182
183
|
.matchHeader('fiware-servicepath', '/gardens')
|
|
183
184
|
.post(
|
|
184
|
-
'/v2/entities?options=upsert',
|
|
185
|
+
'/v2/entities?options=upsert,flowControl',
|
|
185
186
|
utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateProvisionDevice.json')
|
|
186
187
|
)
|
|
187
188
|
.reply(204);
|
|
@@ -374,7 +375,7 @@ describe('NGSI-v2 - Device provisioning API: Update provisioned devices', functi
|
|
|
374
375
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
375
376
|
.matchHeader('fiware-service', 'smartgondor')
|
|
376
377
|
.matchHeader('fiware-servicepath', '/gardens')
|
|
377
|
-
.post('/v2/entities?options=upsert')
|
|
378
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
378
379
|
.reply(204);
|
|
379
380
|
|
|
380
381
|
contextBrokerMock
|
|
@@ -442,7 +443,7 @@ describe('NGSI-v2 - Device provisioning API: Update provisioned devices', functi
|
|
|
442
443
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
443
444
|
.matchHeader('fiware-service', 'smartgondor')
|
|
444
445
|
.matchHeader('fiware-servicepath', '/gardens')
|
|
445
|
-
.post('/v2/entities?options=upsert')
|
|
446
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
446
447
|
.reply(204);
|
|
447
448
|
|
|
448
449
|
contextBrokerMock
|
|
@@ -504,7 +505,7 @@ describe('NGSI-v2 - Device provisioning API: Update provisioned devices', functi
|
|
|
504
505
|
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
505
506
|
.matchHeader('fiware-service', 'smartgondor')
|
|
506
507
|
.matchHeader('fiware-servicepath', '/gardens')
|
|
507
|
-
.post('/v2/entities?options=upsert')
|
|
508
|
+
.post('/v2/entities?options=upsert,flowControl')
|
|
508
509
|
.reply(204);
|
|
509
510
|
|
|
510
511
|
async.series([iotAgentLib.clearAll, async.apply(request, provisioning4Options)], done);
|
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2016 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
|
-
|
|
33
|
-
const nock = require('nock');
|
|
34
|
-
let contextBrokerMock;
|
|
35
|
-
const iotAgentConfig = {
|
|
36
|
-
logLevel: 'FATAL',
|
|
37
|
-
contextBroker: {
|
|
38
|
-
host: '192.168.1.1',
|
|
39
|
-
port: '1026',
|
|
40
|
-
ngsiVersion: 'v2'
|
|
41
|
-
},
|
|
42
|
-
server: {
|
|
43
|
-
port: 4041,
|
|
44
|
-
host: 'localhost'
|
|
45
|
-
},
|
|
46
|
-
types: {},
|
|
47
|
-
service: 'smartgondor',
|
|
48
|
-
subservice: 'gardens',
|
|
49
|
-
providerUrl: 'http://smartgondor.com'
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe('NGSI-v2 - Subscription tests', function () {
|
|
53
|
-
beforeEach(function (done) {
|
|
54
|
-
const optionsProvision = {
|
|
55
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
56
|
-
method: 'POST',
|
|
57
|
-
json: utils.readExampleFile('./test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice.json'),
|
|
58
|
-
headers: {
|
|
59
|
-
'fiware-service': 'smartgondor',
|
|
60
|
-
'fiware-servicepath': '/gardens'
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
nock.cleanAll();
|
|
65
|
-
|
|
66
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
67
|
-
contextBrokerMock = nock('http://192.168.1.1:1026');
|
|
68
|
-
|
|
69
|
-
contextBrokerMock
|
|
70
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
71
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
72
|
-
.post(
|
|
73
|
-
'/v2/subscriptions',
|
|
74
|
-
utils.readExampleFile(
|
|
75
|
-
'./test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest.json'
|
|
76
|
-
)
|
|
77
|
-
)
|
|
78
|
-
.reply(201, null, { Location: '/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8' });
|
|
79
|
-
|
|
80
|
-
iotAgentLib.clearAll(function () {
|
|
81
|
-
request(optionsProvision, function (error, result, body) {
|
|
82
|
-
done();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
afterEach(function (done) {
|
|
89
|
-
nock.cleanAll();
|
|
90
|
-
iotAgentLib.setNotificationHandler();
|
|
91
|
-
iotAgentLib.clearAll(function () {
|
|
92
|
-
iotAgentLib.deactivate(done);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('When a client invokes the subscribe() function for device', function () {
|
|
97
|
-
it('should send the appropriate request to the Context Broker', function (done) {
|
|
98
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
99
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
100
|
-
should.not.exist(error);
|
|
101
|
-
|
|
102
|
-
contextBrokerMock.done();
|
|
103
|
-
|
|
104
|
-
done();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
it('should store the subscription ID in the Device Registry', function (done) {
|
|
109
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
110
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
111
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
112
|
-
should.not.exist(error);
|
|
113
|
-
should.exist(device);
|
|
114
|
-
should.exist(device.subscriptions);
|
|
115
|
-
device.subscriptions.length.should.equal(1);
|
|
116
|
-
device.subscriptions[0].id.should.equal('51c0ac9ed714fb3b37d7d5a8');
|
|
117
|
-
device.subscriptions[0].triggers[0].should.equal('attr_name');
|
|
118
|
-
done();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
describe('When a client invokes the unsubscribe() function for an entity', function () {
|
|
125
|
-
beforeEach(function (done) {
|
|
126
|
-
contextBrokerMock
|
|
127
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
128
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
129
|
-
.delete('/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8', '')
|
|
130
|
-
.reply(204);
|
|
131
|
-
|
|
132
|
-
done();
|
|
133
|
-
});
|
|
134
|
-
it('should delete the subscription from the CB', function (done) {
|
|
135
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
136
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
137
|
-
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
138
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
139
|
-
contextBrokerMock.done();
|
|
140
|
-
done();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
it('should remove the id from the subscriptions array', function (done) {
|
|
147
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
148
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
149
|
-
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
150
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
151
|
-
should.not.exist(error);
|
|
152
|
-
should.exist(device);
|
|
153
|
-
should.exist(device.subscriptions);
|
|
154
|
-
device.subscriptions.length.should.equal(0);
|
|
155
|
-
done();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
describe('When a client removes a device from the registry', function () {
|
|
163
|
-
beforeEach(function (done) {
|
|
164
|
-
contextBrokerMock
|
|
165
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
166
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
167
|
-
.delete('/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8', '')
|
|
168
|
-
.reply(204);
|
|
169
|
-
|
|
170
|
-
done();
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should delete the subscription from the CB', function (done) {
|
|
174
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
175
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
176
|
-
iotAgentLib.unregister(device.id, null, 'smartgondor', '/gardens', function (error) {
|
|
177
|
-
contextBrokerMock.done();
|
|
178
|
-
done();
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
describe('When a new notification comes to the IoTAgent', function () {
|
|
185
|
-
beforeEach(function (done) {
|
|
186
|
-
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
187
|
-
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
188
|
-
done();
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should invoke the user defined callback', function (done) {
|
|
194
|
-
const notificationOptions = {
|
|
195
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
|
|
196
|
-
method: 'POST',
|
|
197
|
-
json: utils.readExampleFile('./test/unit/ngsiv2/examples/subscriptionRequests/simpleNotification.json'),
|
|
198
|
-
headers: {
|
|
199
|
-
'fiware-service': 'smartgondor',
|
|
200
|
-
'fiware-servicepath': '/gardens'
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
let executedHandler = false;
|
|
204
|
-
|
|
205
|
-
function mockedHandler(device, notification, callback) {
|
|
206
|
-
executedHandler = true;
|
|
207
|
-
callback();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
iotAgentLib.setNotificationHandler(mockedHandler);
|
|
211
|
-
|
|
212
|
-
request(notificationOptions, function (error, response, body) {
|
|
213
|
-
should.not.exist(error);
|
|
214
|
-
executedHandler.should.equal(true);
|
|
215
|
-
|
|
216
|
-
done();
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
it('should invoke all the notification middlewares before the user defined callback', function (done) {
|
|
220
|
-
const notificationOptions = {
|
|
221
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
|
|
222
|
-
method: 'POST',
|
|
223
|
-
json: utils.readExampleFile('./test/unit/ngsiv2/examples/subscriptionRequests/simpleNotification.json'),
|
|
224
|
-
headers: {
|
|
225
|
-
'fiware-service': 'smartgondor',
|
|
226
|
-
'fiware-servicepath': '/gardens'
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
let executedMiddlewares = false;
|
|
230
|
-
let executedHandler = false;
|
|
231
|
-
let modifiedData = false;
|
|
232
|
-
|
|
233
|
-
function mockedHandler(device, notification, callback) {
|
|
234
|
-
executedHandler = true;
|
|
235
|
-
modifiedData = notification.length === 2;
|
|
236
|
-
callback();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function mockedMiddleware(device, notification, callback) {
|
|
240
|
-
executedMiddlewares = true;
|
|
241
|
-
notification.push({
|
|
242
|
-
name: 'middlewareAttribute',
|
|
243
|
-
type: 'middlewareType',
|
|
244
|
-
value: 'middlewareValue'
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
callback(null, device, notification);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
iotAgentLib.addNotificationMiddleware(mockedMiddleware);
|
|
251
|
-
iotAgentLib.setNotificationHandler(mockedHandler);
|
|
252
|
-
|
|
253
|
-
request(notificationOptions, function (error, response, body) {
|
|
254
|
-
should.not.exist(error);
|
|
255
|
-
executedHandler.should.equal(true);
|
|
256
|
-
executedMiddlewares.should.equal(true);
|
|
257
|
-
modifiedData.should.equal(true);
|
|
258
|
-
done();
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
it('should get the correspondent device information', function (done) {
|
|
262
|
-
const notificationOptions = {
|
|
263
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
|
|
264
|
-
method: 'POST',
|
|
265
|
-
json: utils.readExampleFile('./test/unit/ngsiv2/examples/subscriptionRequests/simpleNotification.json'),
|
|
266
|
-
headers: {
|
|
267
|
-
'fiware-service': 'smartgondor',
|
|
268
|
-
'fiware-servicepath': '/gardens'
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
let rightFields = false;
|
|
272
|
-
|
|
273
|
-
function mockedHandler(device, data, callback) {
|
|
274
|
-
if (
|
|
275
|
-
device &&
|
|
276
|
-
device.id === 'MicroLight1' &&
|
|
277
|
-
device.name === 'FirstMicroLight' &&
|
|
278
|
-
data &&
|
|
279
|
-
data.length === 1 &&
|
|
280
|
-
data[0].name === 'attr_name'
|
|
281
|
-
) {
|
|
282
|
-
rightFields = true;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
callback();
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
iotAgentLib.setNotificationHandler(mockedHandler);
|
|
289
|
-
|
|
290
|
-
request(notificationOptions, function (error, response, body) {
|
|
291
|
-
should.not.exist(error);
|
|
292
|
-
rightFields.should.equal(true);
|
|
293
|
-
|
|
294
|
-
done();
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
describe('When a wrong notification arrives at the IOTA', function () {
|
|
299
|
-
it('should not call the handler', function (done) {
|
|
300
|
-
const notificationOptions = {
|
|
301
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/notify',
|
|
302
|
-
method: 'POST',
|
|
303
|
-
json: utils.readExampleFile('./test/unit/ngsiv2/examples/subscriptionRequests/errorNotification.json'),
|
|
304
|
-
headers: {
|
|
305
|
-
'fiware-service': 'smartgondor',
|
|
306
|
-
'fiware-servicepath': '/gardens'
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
let executedHandler = false;
|
|
310
|
-
|
|
311
|
-
function mockedHandler(device, notification, callback) {
|
|
312
|
-
executedHandler = true;
|
|
313
|
-
callback();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
iotAgentLib.setNotificationHandler(mockedHandler);
|
|
317
|
-
|
|
318
|
-
request(notificationOptions, function (error, response, body) {
|
|
319
|
-
should.not.exist(error);
|
|
320
|
-
executedHandler.should.equal(false);
|
|
321
|
-
|
|
322
|
-
done();
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
});
|