iotagent-node-lib 3.3.0 → 3.4.1
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 +1 -0
- package/README.md +10 -11
- package/doc/README.md +16 -0
- package/doc/admin.md +565 -0
- package/doc/api.md +9 -5
- package/doc/deprecated.md +16 -14
- package/doc/{architecture.md → devel/architecture.md} +3 -3
- package/doc/{Contribution.md → devel/contribution-guidelines.md} +43 -35
- package/doc/devel/development.md +1879 -0
- package/doc/{northboundinteractions.md → devel/northboundinteractions.md} +18 -33
- package/doc/index.md +3 -5
- package/docker/Mosquitto/README.md +1 -0
- package/lib/commonConfig.js +0 -5
- package/lib/fiware-iotagent-lib.js +1 -1
- package/lib/jexlTranformsMap.js +2 -1
- package/lib/request-shim.js +2 -2
- package/lib/services/commands/commandService.js +1 -1
- package/lib/services/common/genericMiddleware.js +1 -1
- package/lib/services/devices/deviceRegistryMemory.js +2 -2
- package/lib/services/devices/deviceRegistryMongoDB.js +22 -9
- package/lib/services/devices/deviceService.js +36 -30
- package/lib/services/devices/devices-NGSI-LD.js +14 -2
- package/lib/services/devices/devices-NGSI-mixed.js +0 -2
- package/lib/services/devices/devices-NGSI-v2.js +22 -100
- package/lib/services/groups/groupService.js +1 -1
- package/lib/services/ngsi/entities-NGSI-v2.js +14 -27
- package/lib/services/northBound/deviceProvisioningServer.js +14 -5
- package/mkdocs.yml +6 -11
- package/package.json +3 -3
- package/scripts/legacy_expression_tool/README.md +56 -38
- package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +2 -2
- package/test/unit/mongodb/mongodb-registry-test.js +1 -1
- package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +66 -65
- package/test/unit/ngsi-ld/general/https-support-test.js +1 -1
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +8 -7
- package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +12 -11
- package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +41 -39
- package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +122 -122
- package/test/unit/ngsi-ld/provisioning/device-registration_test.js +28 -28
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +18 -17
- package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +7 -7
- package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +8 -7
- package/test/unit/ngsiv2/examples/contextRequests/updateContext6.json +2 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +0 -12
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +1 -5
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +0 -12
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +0 -12
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +0 -10
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +0 -12
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +0 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +1 -5
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +13 -12
- package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +2 -2
- package/test/unit/ngsiv2/general/https-support-test.js +1 -1
- package/test/unit/ngsiv2/ngsiService/active-devices-test.js +3 -8
- package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +10 -10
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +8 -103
- package/test/unit/ngsiv2/provisioning/device-registration_test.js +8 -6
- package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +2 -1
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +0 -1
- package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
- package/.nyc_output/processinfo/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/doc/config-basic-example.js +0 -20
- package/doc/development.md +0 -285
- package/doc/howto.md +0 -641
- package/doc/installationguide.md +0 -365
- package/doc/operations.md +0 -127
- package/doc/usermanual.md +0 -900
- package/lib/plugins/bidirectionalData.js +0 -356
- package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +0 -697
- package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +0 -536
- /package/doc/{NorthboundInteractions.postman_collection → devel/NorthboundInteractions.postman_collection} +0 -0
- /package/doc/{echo.js → devel/echo.js} +0 -0
- /package/doc/{finalResult.js → devel/finalResult.js} +0 -0
|
@@ -5,20 +5,8 @@
|
|
|
5
5
|
"type": "Number",
|
|
6
6
|
"value": 8.8
|
|
7
7
|
},
|
|
8
|
-
"pressure":{
|
|
9
|
-
"type":"Number",
|
|
10
|
-
"value":null
|
|
11
|
-
},
|
|
12
8
|
"weather":{
|
|
13
9
|
"type":"Summary",
|
|
14
10
|
"value":"Humidity NaN and pressure NaN"
|
|
15
|
-
},
|
|
16
|
-
"alive":{
|
|
17
|
-
"type":"None",
|
|
18
|
-
"value":null
|
|
19
|
-
},
|
|
20
|
-
"updated":{
|
|
21
|
-
"type":"Boolean",
|
|
22
|
-
"value":null
|
|
23
11
|
}
|
|
24
12
|
}
|
|
@@ -440,6 +440,19 @@ const iotAgentConfig = {
|
|
|
440
440
|
object_id: 'condition',
|
|
441
441
|
name: 'condition',
|
|
442
442
|
type: 'Number'
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
object_id: 'nonProgressAtt1',
|
|
446
|
+
name: 'nonProgressatt1',
|
|
447
|
+
type: 'Number',
|
|
448
|
+
expression: 'nonexistent * 2'
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
object_id: 'nonProgressAtt2',
|
|
452
|
+
name: 'nonProgressatt2',
|
|
453
|
+
type: 'Number',
|
|
454
|
+
expression: 'nonexistent * 2',
|
|
455
|
+
skipValue: null
|
|
443
456
|
}
|
|
444
457
|
]
|
|
445
458
|
}
|
|
@@ -952,23 +965,11 @@ describe('Java expression language (JEXL) based transformations plugin', functio
|
|
|
952
965
|
|
|
953
966
|
beforeEach(function () {
|
|
954
967
|
nock.cleanAll();
|
|
955
|
-
|
|
956
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
957
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
958
|
-
.matchHeader('fiware-servicepath', 'gardens')
|
|
959
|
-
.post(
|
|
960
|
-
'/v2/entities?options=upsert',
|
|
961
|
-
utils.readExampleFile(
|
|
962
|
-
'./test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json'
|
|
963
|
-
)
|
|
964
|
-
)
|
|
965
|
-
.reply(204);
|
|
966
968
|
});
|
|
967
969
|
|
|
968
970
|
it('should apply the expression before sending the values', function (done) {
|
|
969
971
|
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
970
972
|
should.not.exist(error);
|
|
971
|
-
contextBrokerMock.done();
|
|
972
973
|
done();
|
|
973
974
|
});
|
|
974
975
|
});
|
|
@@ -310,7 +310,7 @@ describe('NGSI-v2 - Secured access to the Context Broker with OAuth2 provider',
|
|
|
310
310
|
});
|
|
311
311
|
|
|
312
312
|
it('subscribe requests use auth header', function (done) {
|
|
313
|
-
iotAgentLib.getDevice('Light1', 'smartgondor', 'electricity', function (error, device) {
|
|
313
|
+
iotAgentLib.getDevice('Light1', null, 'smartgondor', 'electricity', function (error, device) {
|
|
314
314
|
iotAgentLib.subscribe(device, ['dimming'], null, function (error) {
|
|
315
315
|
should.not.exist(error);
|
|
316
316
|
|
|
@@ -331,7 +331,7 @@ describe('NGSI-v2 - Secured access to the Context Broker with OAuth2 provider',
|
|
|
331
331
|
|
|
332
332
|
contextBrokerMock.delete('/v2/subscriptions/51c0ac9ed714fb3b37d7d5a8', '').reply(204);
|
|
333
333
|
|
|
334
|
-
iotAgentLib.getDevice('Light1', 'smartgondor', 'electricity', function (error, device) {
|
|
334
|
+
iotAgentLib.getDevice('Light1', null, 'smartgondor', 'electricity', function (error, device) {
|
|
335
335
|
iotAgentLib.subscribe(device, ['dimming'], null, function (error) {
|
|
336
336
|
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
337
337
|
contextBrokerMock.done();
|
|
@@ -210,7 +210,7 @@ describe('NGSI-v2 - HTTPS support tests', function () {
|
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
it('should send the appropriate request to the Context Broker', function (done) {
|
|
213
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
213
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
214
214
|
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
215
215
|
should.not.exist(error);
|
|
216
216
|
|
|
@@ -827,7 +827,7 @@ describe('NGSI-v2 - Active attributes test', function () {
|
|
|
827
827
|
});
|
|
828
828
|
});
|
|
829
829
|
|
|
830
|
-
describe('When the IoT Agent receives new information from a device
|
|
830
|
+
describe('When the IoT Agent receives new information from a device', function () {
|
|
831
831
|
beforeEach(function (done) {
|
|
832
832
|
nock.cleanAll();
|
|
833
833
|
|
|
@@ -840,13 +840,10 @@ describe('NGSI-v2 - Active attributes test', function () {
|
|
|
840
840
|
)
|
|
841
841
|
.reply(204);
|
|
842
842
|
|
|
843
|
-
iotAgentConfig.appendMode = true;
|
|
844
843
|
iotAgentLib.activate(iotAgentConfig, done);
|
|
845
844
|
});
|
|
846
845
|
|
|
847
846
|
afterEach(function (done) {
|
|
848
|
-
iotAgentConfig.appendMode = false;
|
|
849
|
-
|
|
850
847
|
done();
|
|
851
848
|
});
|
|
852
849
|
|
|
@@ -868,16 +865,14 @@ describe('NGSI-v2 - Active attributes test', function () {
|
|
|
868
865
|
contextBrokerMock = nock('http://cbhost:1026')
|
|
869
866
|
.matchHeader('fiware-service', 'smartgondor')
|
|
870
867
|
.matchHeader('fiware-servicepath', 'gardens')
|
|
871
|
-
.
|
|
872
|
-
'/v2/entities
|
|
868
|
+
.post(
|
|
869
|
+
'/v2/entities?options=upsert',
|
|
873
870
|
utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContext6.json')
|
|
874
871
|
)
|
|
875
|
-
.query({ type: 'Light' })
|
|
876
872
|
.reply(204);
|
|
877
873
|
|
|
878
874
|
iotAgentLib.activate(iotAgentConfig, done);
|
|
879
875
|
});
|
|
880
|
-
|
|
881
876
|
it('should change the value of the corresponding attribute in the context broker', function (done) {
|
|
882
877
|
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
883
878
|
should.not.exist(error);
|
|
@@ -95,7 +95,7 @@ describe('NGSI-v2 - Subscription tests', function () {
|
|
|
95
95
|
|
|
96
96
|
describe('When a client invokes the subscribe() function for device', function () {
|
|
97
97
|
it('should send the appropriate request to the Context Broker', function (done) {
|
|
98
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
98
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
99
99
|
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
100
100
|
should.not.exist(error);
|
|
101
101
|
|
|
@@ -106,9 +106,9 @@ describe('NGSI-v2 - Subscription tests', function () {
|
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
it('should store the subscription ID in the Device Registry', function (done) {
|
|
109
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
109
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
110
110
|
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
111
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
111
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
112
112
|
should.not.exist(error);
|
|
113
113
|
should.exist(device);
|
|
114
114
|
should.exist(device.subscriptions);
|
|
@@ -132,10 +132,10 @@ describe('NGSI-v2 - Subscription tests', function () {
|
|
|
132
132
|
done();
|
|
133
133
|
});
|
|
134
134
|
it('should delete the subscription from the CB', function (done) {
|
|
135
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
135
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
136
136
|
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
137
137
|
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
138
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
138
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
139
139
|
contextBrokerMock.done();
|
|
140
140
|
done();
|
|
141
141
|
});
|
|
@@ -144,10 +144,10 @@ describe('NGSI-v2 - Subscription tests', function () {
|
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
146
|
it('should remove the id from the subscriptions array', function (done) {
|
|
147
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
147
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
148
148
|
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
149
149
|
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
150
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
150
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
151
151
|
should.not.exist(error);
|
|
152
152
|
should.exist(device);
|
|
153
153
|
should.exist(device.subscriptions);
|
|
@@ -171,9 +171,9 @@ describe('NGSI-v2 - Subscription tests', function () {
|
|
|
171
171
|
});
|
|
172
172
|
|
|
173
173
|
it('should delete the subscription from the CB', function (done) {
|
|
174
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
174
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
175
175
|
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
176
|
-
iotAgentLib.unregister(device.id, 'smartgondor', '/gardens', function (error) {
|
|
176
|
+
iotAgentLib.unregister(device.id, null, 'smartgondor', '/gardens', function (error) {
|
|
177
177
|
contextBrokerMock.done();
|
|
178
178
|
done();
|
|
179
179
|
});
|
|
@@ -183,7 +183,7 @@ describe('NGSI-v2 - Subscription tests', function () {
|
|
|
183
183
|
});
|
|
184
184
|
describe('When a new notification comes to the IoTAgent', function () {
|
|
185
185
|
beforeEach(function (done) {
|
|
186
|
-
iotAgentLib.getDevice('MicroLight1', 'smartgondor', '/gardens', function (error, device) {
|
|
186
|
+
iotAgentLib.getDevice('MicroLight1', null, 'smartgondor', '/gardens', function (error, device) {
|
|
187
187
|
iotAgentLib.subscribe(device, ['attr_name'], null, function (error) {
|
|
188
188
|
done();
|
|
189
189
|
});
|
|
@@ -311,7 +311,6 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
|
|
|
311
311
|
nock.cleanAll();
|
|
312
312
|
done();
|
|
313
313
|
});
|
|
314
|
-
|
|
315
314
|
it('should send the appropriate requests to the Context Broker', function (done) {
|
|
316
315
|
request(options, function (error, response, body) {
|
|
317
316
|
contextBrokerMock.done();
|
|
@@ -813,31 +812,19 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
|
|
|
813
812
|
|
|
814
813
|
beforeEach(function (done) {
|
|
815
814
|
iotAgentLib.deactivate(function () {
|
|
816
|
-
iotAgentConfig.appendMode = false;
|
|
817
815
|
iotAgentLib.activate(iotAgentConfig, done);
|
|
818
816
|
});
|
|
819
817
|
});
|
|
820
818
|
|
|
821
|
-
afterEach(function () {
|
|
822
|
-
iotAgentConfig.appendMode = false;
|
|
823
|
-
});
|
|
819
|
+
afterEach(function () {});
|
|
824
820
|
|
|
825
821
|
beforeEach(function (done) {
|
|
826
822
|
nock.cleanAll();
|
|
827
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
828
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
829
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
830
|
-
.post(
|
|
831
|
-
'/v2/entities?options=upsert',
|
|
832
|
-
utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/createAutoprovisionDevice.json')
|
|
833
|
-
)
|
|
834
|
-
.reply(204);
|
|
835
823
|
done();
|
|
836
824
|
});
|
|
837
825
|
|
|
838
|
-
it('should
|
|
826
|
+
it('should should not appropriate requests to the Context Broker', function (done) {
|
|
839
827
|
request(options, function (error, response, body) {
|
|
840
|
-
contextBrokerMock.done();
|
|
841
828
|
done();
|
|
842
829
|
});
|
|
843
830
|
});
|
|
@@ -867,36 +854,11 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
|
|
|
867
854
|
|
|
868
855
|
beforeEach(function (done) {
|
|
869
856
|
nock.cleanAll();
|
|
870
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
871
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
872
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
873
|
-
.post('/v2/entities?options=upsert', function (body) {
|
|
874
|
-
const expectedBody = utils.readExampleFile(
|
|
875
|
-
'./test/unit/ngsiv2/examples/contextRequests/createTimeInstantMinimumDevice.json'
|
|
876
|
-
);
|
|
877
|
-
if (!body.TimeInstant.value) {
|
|
878
|
-
return false;
|
|
879
|
-
} else if (moment(body.TimeInstant.value, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isValid()) {
|
|
880
|
-
const timeInstantDiff = moment().diff(body.TimeInstant.value, 'milliseconds');
|
|
881
|
-
if (timeInstantDiff < 500) {
|
|
882
|
-
delete body.TimeInstant;
|
|
883
|
-
|
|
884
|
-
return JSON.stringify(body) === JSON.stringify(expectedBody);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
return false;
|
|
888
|
-
} else {
|
|
889
|
-
return false;
|
|
890
|
-
}
|
|
891
|
-
})
|
|
892
|
-
.reply(204);
|
|
893
|
-
|
|
894
857
|
done();
|
|
895
858
|
});
|
|
896
859
|
|
|
897
|
-
it('should send
|
|
860
|
+
it('should not send any requests to the Context Broker', function (done) {
|
|
898
861
|
request(options, function (error, response, body) {
|
|
899
|
-
contextBrokerMock.done();
|
|
900
862
|
done();
|
|
901
863
|
});
|
|
902
864
|
});
|
|
@@ -915,23 +877,11 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
|
|
|
915
877
|
|
|
916
878
|
beforeEach(function (done) {
|
|
917
879
|
nock.cleanAll();
|
|
918
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
919
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
920
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
921
|
-
.post(
|
|
922
|
-
'/v2/entities?options=upsert',
|
|
923
|
-
utils.readExampleFile(
|
|
924
|
-
'./test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice.json'
|
|
925
|
-
)
|
|
926
|
-
)
|
|
927
|
-
.reply(204);
|
|
928
|
-
|
|
929
880
|
done();
|
|
930
881
|
});
|
|
931
882
|
|
|
932
|
-
it('should send
|
|
883
|
+
it('should not send any requests to the Context Broker', function (done) {
|
|
933
884
|
request(options, function (error, response, body) {
|
|
934
|
-
contextBrokerMock.done();
|
|
935
885
|
done();
|
|
936
886
|
});
|
|
937
887
|
});
|
|
@@ -974,23 +924,10 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
|
|
|
974
924
|
|
|
975
925
|
beforeEach(function (done) {
|
|
976
926
|
nock.cleanAll();
|
|
977
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
978
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
979
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
980
|
-
.post(
|
|
981
|
-
'/v2/entities?options=upsert',
|
|
982
|
-
utils.readExampleFile(
|
|
983
|
-
'./test/unit/ngsiv2/examples/contextRequests/createGeopointProvisionedDevice.json'
|
|
984
|
-
)
|
|
985
|
-
)
|
|
986
|
-
.reply(204);
|
|
987
|
-
|
|
988
927
|
done();
|
|
989
928
|
});
|
|
990
|
-
|
|
991
|
-
it('should send the appropriate initial values to the Context Broker', function (done) {
|
|
929
|
+
it('should not send any initial values to the Context Broker', function (done) {
|
|
992
930
|
request(options, function (error, response, body) {
|
|
993
|
-
contextBrokerMock.done();
|
|
994
931
|
done();
|
|
995
932
|
});
|
|
996
933
|
});
|
|
@@ -1009,23 +946,10 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
|
|
|
1009
946
|
|
|
1010
947
|
beforeEach(function (done) {
|
|
1011
948
|
nock.cleanAll();
|
|
1012
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
1013
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
1014
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
1015
|
-
.post(
|
|
1016
|
-
'/v2/entities?options=upsert',
|
|
1017
|
-
utils.readExampleFile(
|
|
1018
|
-
'./test/unit/ngsiv2/examples/contextRequests/createDatetimeProvisionedDevice.json'
|
|
1019
|
-
)
|
|
1020
|
-
)
|
|
1021
|
-
.reply(204);
|
|
1022
|
-
|
|
1023
949
|
done();
|
|
1024
950
|
});
|
|
1025
|
-
|
|
1026
|
-
it('should send the appropriate initial values to the Context Broker', function (done) {
|
|
951
|
+
it('should not send any initial values to the Context Broker', function (done) {
|
|
1027
952
|
request(options, function (error, response, body) {
|
|
1028
|
-
contextBrokerMock.done();
|
|
1029
953
|
done();
|
|
1030
954
|
});
|
|
1031
955
|
});
|
|
@@ -1122,23 +1046,13 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
|
|
|
1122
1046
|
.matchHeader('fiware-servicepath', '/gardens')
|
|
1123
1047
|
.post('/v2/registrations')
|
|
1124
1048
|
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
1125
|
-
|
|
1126
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
1127
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
1128
|
-
// provisioning folder
|
|
1129
|
-
contextBrokerMock
|
|
1130
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
1131
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
1132
|
-
.post('/v2/entities?options=upsert')
|
|
1133
|
-
.replyWithError({ message: 'Description of the error', code: 'STRING_CODE' });
|
|
1134
|
-
|
|
1135
1049
|
done();
|
|
1136
1050
|
});
|
|
1137
1051
|
|
|
1138
1052
|
it('should return a valid return code', function (done) {
|
|
1139
1053
|
request(options, function (error, response, body) {
|
|
1140
1054
|
should.not.exist(error);
|
|
1141
|
-
response.statusCode.should.equal(
|
|
1055
|
+
response.statusCode.should.equal(201);
|
|
1142
1056
|
|
|
1143
1057
|
done();
|
|
1144
1058
|
});
|
|
@@ -1165,22 +1079,13 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
|
|
|
1165
1079
|
.post('/v2/registrations')
|
|
1166
1080
|
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
1167
1081
|
|
|
1168
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
1169
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
1170
|
-
// provisioning folder
|
|
1171
|
-
contextBrokerMock
|
|
1172
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
1173
|
-
.matchHeader('fiware-servicepath', '/gardens')
|
|
1174
|
-
.post('/v2/entities?options=upsert')
|
|
1175
|
-
.replyWithError({ message: 'Description of the error', code: 123456789 });
|
|
1176
|
-
|
|
1177
1082
|
done();
|
|
1178
1083
|
});
|
|
1179
1084
|
|
|
1180
1085
|
it('should return a valid return code (three character number)', function (done) {
|
|
1181
1086
|
request(options, function (error, response, body) {
|
|
1182
1087
|
should.not.exist(error);
|
|
1183
|
-
response.statusCode.should.equal(
|
|
1088
|
+
response.statusCode.should.equal(201);
|
|
1184
1089
|
|
|
1185
1090
|
done();
|
|
1186
1091
|
});
|
|
@@ -82,13 +82,15 @@ const device1 = {
|
|
|
82
82
|
id: 'light1',
|
|
83
83
|
type: 'Light',
|
|
84
84
|
service: 'smartgondor',
|
|
85
|
-
subservice: 'gardens'
|
|
85
|
+
subservice: 'gardens',
|
|
86
|
+
apikey: null
|
|
86
87
|
};
|
|
87
88
|
const device2 = {
|
|
88
89
|
id: 'term2',
|
|
89
90
|
type: 'Termometer',
|
|
90
91
|
service: 'smartgondor',
|
|
91
|
-
subservice: 'gardens'
|
|
92
|
+
subservice: 'gardens',
|
|
93
|
+
apikey: null
|
|
92
94
|
};
|
|
93
95
|
|
|
94
96
|
describe('NGSI-v2 - IoT Agent Device Registration', function () {
|
|
@@ -223,7 +225,7 @@ describe('NGSI-v2 - IoT Agent Device Registration', function () {
|
|
|
223
225
|
|
|
224
226
|
it("should return all the device's information", function (done) {
|
|
225
227
|
iotAgentLib.register(device1, function (error) {
|
|
226
|
-
iotAgentLib.getDevice('light1', 'smartgondor', 'gardens', function (error, data) {
|
|
228
|
+
iotAgentLib.getDevice('light1', null, 'smartgondor', 'gardens', function (error, data) {
|
|
227
229
|
should.not.exist(error);
|
|
228
230
|
should.exist(data);
|
|
229
231
|
data.type.should.equal('Light');
|
|
@@ -254,7 +256,7 @@ describe('NGSI-v2 - IoT Agent Device Registration', function () {
|
|
|
254
256
|
|
|
255
257
|
it('should return a ENTITY_NOT_FOUND error', function (done) {
|
|
256
258
|
iotAgentLib.register(device1, function (error) {
|
|
257
|
-
iotAgentLib.getDevice('lightUnexistent', 'smartgondor', 'gardens', function (error, data) {
|
|
259
|
+
iotAgentLib.getDevice('lightUnexistent', null, 'smartgondor', 'gardens', function (error, data) {
|
|
258
260
|
should.exist(error);
|
|
259
261
|
should.not.exist(data);
|
|
260
262
|
error.code.should.equal(404);
|
|
@@ -301,7 +303,7 @@ describe('NGSI-v2 - IoT Agent Device Registration', function () {
|
|
|
301
303
|
});
|
|
302
304
|
|
|
303
305
|
it('should update the devices information in Context Broker', function (done) {
|
|
304
|
-
iotAgentLib.unregister(device1.id, 'smartgondor', 'gardens', function (error) {
|
|
306
|
+
iotAgentLib.unregister(device1.id, null, 'smartgondor', 'gardens', function (error) {
|
|
305
307
|
should.not.exist(error);
|
|
306
308
|
contextBrokerMock.done();
|
|
307
309
|
done();
|
|
@@ -346,7 +348,7 @@ describe('NGSI-v2 - IoT Agent Device Registration', function () {
|
|
|
346
348
|
|
|
347
349
|
it('should not remove the device from the internal registry');
|
|
348
350
|
it('should return a UNREGISTRATION_ERROR error to the caller', function (done) {
|
|
349
|
-
iotAgentLib.unregister(device1.id, 'smartgondor', 'gardens', function (error) {
|
|
351
|
+
iotAgentLib.unregister(device1.id, null, 'smartgondor', 'gardens', function (error) {
|
|
350
352
|
should.exist(error);
|
|
351
353
|
should.exist(error.name);
|
|
352
354
|
error.name.should.equal('UNREGISTRATION_ERROR');
|
|
@@ -206,7 +206,7 @@ describe('NGSI-v2 - IoT Agent Device Update Registration', function () {
|
|
|
206
206
|
|
|
207
207
|
it('should store the new values in the registry', function (done) {
|
|
208
208
|
iotAgentLib.updateRegister(deviceUpdated, false, function (error, data) {
|
|
209
|
-
iotAgentLib.getDevice(deviceUpdated.id, 'smartgondor', 'gardens', function (error, deviceResult) {
|
|
209
|
+
iotAgentLib.getDevice(deviceUpdated.id, null, 'smartgondor', 'gardens', function (error, deviceResult) {
|
|
210
210
|
should.not.exist(error);
|
|
211
211
|
should.exist(deviceResult);
|
|
212
212
|
deviceResult.internalId.should.equal(deviceUpdated.internalId);
|
|
@@ -264,6 +264,7 @@ describe('NGSI-v2 - IoT Agent Device Update Registration', function () {
|
|
|
264
264
|
iotAgentLib.updateRegister(deviceCommandUpdated, false, function (error, data) {
|
|
265
265
|
iotAgentLib.getDevice(
|
|
266
266
|
deviceCommandUpdated.id,
|
|
267
|
+
null,
|
|
267
268
|
'smartgondor',
|
|
268
269
|
'gardens',
|
|
269
270
|
function (error, deviceResult) {
|
|
@@ -240,7 +240,6 @@ describe('NGSI-v2 - Device provisioning API: Update provisioned devices', functi
|
|
|
240
240
|
|
|
241
241
|
request(options, function (error, response, body) {
|
|
242
242
|
/* jshint camelcase:false */
|
|
243
|
-
|
|
244
243
|
body.entity_name.should.equal('ANewLightName');
|
|
245
244
|
body.timezone.should.equal('Europe/Madrid');
|
|
246
245
|
done();
|