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,119 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2015 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::daniel.moranjimenez@telefonica.com
|
|
22
|
-
*
|
|
23
|
-
* Modified by: Daniel Calvo - ATOS Research & Innovation
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
|
|
27
|
-
const utils = require('../../../tools/utils');
|
|
28
|
-
const should = require('should');
|
|
29
|
-
const logger = require('logops');
|
|
30
|
-
const nock = require('nock');
|
|
31
|
-
let contextBrokerMock;
|
|
32
|
-
const iotAgentConfig = {
|
|
33
|
-
contextBroker: {
|
|
34
|
-
host: '192.168.1.1',
|
|
35
|
-
port: '1026',
|
|
36
|
-
ngsiVersion: 'v2'
|
|
37
|
-
},
|
|
38
|
-
server: {
|
|
39
|
-
port: 4041,
|
|
40
|
-
host: 'localhost'
|
|
41
|
-
},
|
|
42
|
-
types: {
|
|
43
|
-
Light: {
|
|
44
|
-
commands: [],
|
|
45
|
-
type: 'Light',
|
|
46
|
-
lazy: [
|
|
47
|
-
{
|
|
48
|
-
name: 'temperature',
|
|
49
|
-
type: 'centigrades'
|
|
50
|
-
}
|
|
51
|
-
],
|
|
52
|
-
active: [
|
|
53
|
-
{
|
|
54
|
-
name: 'pressure',
|
|
55
|
-
type: 'Hgmm'
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
service: 'smartgondor',
|
|
61
|
-
subservice: 'gardens',
|
|
62
|
-
providerUrl: 'http://smartgondor.com'
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
describe('NGSI-v2 - Timestamp processing plugin', function () {
|
|
66
|
-
beforeEach(function (done) {
|
|
67
|
-
logger.setLevel('FATAL');
|
|
68
|
-
|
|
69
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
70
|
-
iotAgentLib.clearAll(function () {
|
|
71
|
-
done();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
afterEach(function (done) {
|
|
77
|
-
iotAgentLib.clearAll(function () {
|
|
78
|
-
iotAgentLib.deactivate(done);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe('When an update comes with a timestamp through the plugin', function () {
|
|
82
|
-
const values = [
|
|
83
|
-
{
|
|
84
|
-
name: 'state',
|
|
85
|
-
type: 'Boolean',
|
|
86
|
-
value: true
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
name: 'TimeInstant',
|
|
90
|
-
type: 'DateTime',
|
|
91
|
-
value: '2016-05-30T16:25:22.304Z'
|
|
92
|
-
}
|
|
93
|
-
];
|
|
94
|
-
|
|
95
|
-
beforeEach(function () {
|
|
96
|
-
nock.cleanAll();
|
|
97
|
-
|
|
98
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
99
|
-
.matchHeader('fiware-service', 'smartgondor')
|
|
100
|
-
.matchHeader('fiware-servicepath', 'gardens')
|
|
101
|
-
.post(
|
|
102
|
-
'/v2/entities?options=upsert',
|
|
103
|
-
// this tests breaks jexlBasedTransformation-test with uses updateContextExpressionPlugin32 which do not includes Timestamp in metadata attributes
|
|
104
|
-
utils.readExampleFile(
|
|
105
|
-
'./test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json'
|
|
106
|
-
)
|
|
107
|
-
)
|
|
108
|
-
.reply(204);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should return an entity with all its timestamps expanded to have separators', function (done) {
|
|
112
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
113
|
-
should.not.exist(error);
|
|
114
|
-
contextBrokerMock.done();
|
|
115
|
-
done();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
@@ -1,309 +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
|
-
const nock = require('nock');
|
|
33
|
-
let contextBrokerMock;
|
|
34
|
-
|
|
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
|
-
baseRoot: '/'
|
|
46
|
-
},
|
|
47
|
-
types: {},
|
|
48
|
-
service: 'smartgondor',
|
|
49
|
-
singleConfigurationMode: true,
|
|
50
|
-
subservice: 'gardens',
|
|
51
|
-
providerUrl: 'http://smartgondor.com'
|
|
52
|
-
};
|
|
53
|
-
const groupCreation = {
|
|
54
|
-
url: 'http://localhost:4041/iot/services',
|
|
55
|
-
method: 'POST',
|
|
56
|
-
json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/provisionFullGroup.json'),
|
|
57
|
-
headers: {
|
|
58
|
-
'fiware-service': 'testservice',
|
|
59
|
-
'fiware-servicepath': '/testingPath'
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const deviceCreation = {
|
|
63
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
64
|
-
method: 'POST',
|
|
65
|
-
json: utils.readExampleFile('./test/unit/examples/deviceProvisioningRequests/provisionNewDevice.json'),
|
|
66
|
-
headers: {
|
|
67
|
-
'fiware-service': 'testservice',
|
|
68
|
-
'fiware-servicepath': '/testingPath'
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
describe('NGSI-v2 - Provisioning API: Single service mode', function () {
|
|
73
|
-
beforeEach(function (done) {
|
|
74
|
-
nock.cleanAll();
|
|
75
|
-
|
|
76
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
77
|
-
iotAgentLib.clearAll(done);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
afterEach(function (done) {
|
|
82
|
-
nock.cleanAll();
|
|
83
|
-
iotAgentLib.setProvisioningHandler();
|
|
84
|
-
iotAgentLib.deactivate(done);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('When a new configuration arrives to an already configured subservice', function () {
|
|
88
|
-
const groupCreationDuplicated = {
|
|
89
|
-
url: 'http://localhost:4041/iot/services',
|
|
90
|
-
method: 'POST',
|
|
91
|
-
json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/provisionDuplicateGroup.json'),
|
|
92
|
-
headers: {
|
|
93
|
-
'fiware-service': 'testservice',
|
|
94
|
-
'fiware-servicepath': '/testingPath'
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
beforeEach(function (done) {
|
|
99
|
-
request(groupCreation, done);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should raise a DUPLICATE_GROUP error', function (done) {
|
|
103
|
-
request(groupCreationDuplicated, function (error, response, body) {
|
|
104
|
-
should.not.exist(error);
|
|
105
|
-
response.statusCode.should.equal(409);
|
|
106
|
-
should.exist(body.name);
|
|
107
|
-
body.name.should.equal('DUPLICATE_GROUP');
|
|
108
|
-
done();
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
describe('When a device is provisioned with an ID that already exists in the configuration', function () {
|
|
113
|
-
const deviceCreationDuplicated = {
|
|
114
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
115
|
-
method: 'POST',
|
|
116
|
-
json: utils.readExampleFile('./test/unit/examples/deviceProvisioningRequests/provisionDuplicatedDev.json'),
|
|
117
|
-
headers: {
|
|
118
|
-
'fiware-service': 'testservice',
|
|
119
|
-
'fiware-servicepath': '/testingPath'
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
beforeEach(function (done) {
|
|
124
|
-
nock.cleanAll();
|
|
125
|
-
|
|
126
|
-
contextBrokerMock = nock('http://unexistentHost:1026')
|
|
127
|
-
.matchHeader('fiware-service', 'testservice')
|
|
128
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
129
|
-
.post('/v2/registrations')
|
|
130
|
-
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
131
|
-
|
|
132
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
133
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
134
|
-
// provisioning folder
|
|
135
|
-
contextBrokerMock
|
|
136
|
-
.matchHeader('fiware-service', 'testservice')
|
|
137
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
138
|
-
.post('/v2/entities?options=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
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
184
|
-
.post('/v2/registrations')
|
|
185
|
-
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
186
|
-
|
|
187
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
188
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
189
|
-
// provisioning folder
|
|
190
|
-
contextBrokerMock
|
|
191
|
-
.matchHeader('fiware-service', 'testservice')
|
|
192
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
193
|
-
.post('/v2/entities?options=upsert')
|
|
194
|
-
.reply(204);
|
|
195
|
-
|
|
196
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
197
|
-
.matchHeader('fiware-service', 'AlternateService')
|
|
198
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
199
|
-
.post('/v2/registrations')
|
|
200
|
-
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
201
|
-
|
|
202
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
203
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
204
|
-
// provisioning folder
|
|
205
|
-
contextBrokerMock
|
|
206
|
-
.matchHeader('fiware-service', 'AlternateService')
|
|
207
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
208
|
-
.post('/v2/entities?options=upsert')
|
|
209
|
-
.reply(204);
|
|
210
|
-
|
|
211
|
-
request(groupCreation, function (error) {
|
|
212
|
-
request(deviceCreation, function (error, response, body) {
|
|
213
|
-
request(alternativeGroupCreation, function (error, response, body) {
|
|
214
|
-
done();
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('should return a 201 OK', function (done) {
|
|
221
|
-
request(alternativeDeviceCreation, function (error, response, body) {
|
|
222
|
-
should.not.exist(error);
|
|
223
|
-
response.statusCode.should.equal(201);
|
|
224
|
-
done();
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe('When a device is provisioned without a type and with a default configuration type', function () {
|
|
229
|
-
const getDevice = {
|
|
230
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices/Light1',
|
|
231
|
-
method: 'GET',
|
|
232
|
-
headers: {
|
|
233
|
-
'fiware-service': 'testservice',
|
|
234
|
-
'fiware-servicepath': '/testingPath'
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
let oldType;
|
|
238
|
-
|
|
239
|
-
beforeEach(function (done) {
|
|
240
|
-
nock.cleanAll();
|
|
241
|
-
|
|
242
|
-
contextBrokerMock = nock('http://unexistentHost:1026')
|
|
243
|
-
.matchHeader('fiware-service', 'testservice')
|
|
244
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
245
|
-
.post('/v2/registrations')
|
|
246
|
-
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
247
|
-
|
|
248
|
-
// This mock does not check the payload since the aim of the test is not to verify
|
|
249
|
-
// device provisioning functionality. Appropriate verification is done in tests under
|
|
250
|
-
// provisioning folder
|
|
251
|
-
contextBrokerMock
|
|
252
|
-
.matchHeader('fiware-service', 'testservice')
|
|
253
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
254
|
-
.post('/v2/entities?options=upsert')
|
|
255
|
-
.reply(204);
|
|
256
|
-
|
|
257
|
-
oldType = deviceCreation.json.devices[0].entity_type;
|
|
258
|
-
delete deviceCreation.json.devices[0].entity_type;
|
|
259
|
-
request(groupCreation, done);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
afterEach(function () {
|
|
263
|
-
deviceCreation.json.devices[0].entity_type = oldType;
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('should be provisioned with the default type', function (done) {
|
|
267
|
-
request(deviceCreation, function (error, response, body) {
|
|
268
|
-
request(getDevice, function (error, response, body) {
|
|
269
|
-
body.entity_type.should.equal('SensorMachine');
|
|
270
|
-
|
|
271
|
-
done();
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
describe('When a device is provisioned for a configuration', function () {
|
|
277
|
-
beforeEach(function (done) {
|
|
278
|
-
nock.cleanAll();
|
|
279
|
-
contextBrokerMock = nock('http://unexistentHost:1026')
|
|
280
|
-
.matchHeader('fiware-service', 'testservice')
|
|
281
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
282
|
-
.post(
|
|
283
|
-
'/v2/registrations',
|
|
284
|
-
utils.readExampleFile(
|
|
285
|
-
'./test/unit/ngsiv2/examples' +
|
|
286
|
-
'/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json'
|
|
287
|
-
)
|
|
288
|
-
)
|
|
289
|
-
.reply(201, null, { Location: '/v2/registrations/6319a7f5254b05844116584d' });
|
|
290
|
-
|
|
291
|
-
request(groupCreation, done);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('should not raise any error', function (done) {
|
|
295
|
-
request(deviceCreation, function (error, response, body) {
|
|
296
|
-
should.not.exist(error);
|
|
297
|
-
response.statusCode.should.equal(201);
|
|
298
|
-
done();
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it('should send the mixed data to the Context Broker', function (done) {
|
|
303
|
-
request(deviceCreation, function (error, response, body) {
|
|
304
|
-
contextBrokerMock.done();
|
|
305
|
-
done();
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
});
|