1
1
/*
2
- * Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
2
+ * Copyright 2020 Telefonica Investigación y Desarrollo, S.A.U
3
3
*
4
4
* This file is part of fiware-iotagent-lib
5
5
*
20
20
* For those usages not covered by the GNU Affero General Public License
21
21
* please contact with::[[email protected] ]
22
22
*
23
- * Modified by: Daniel Calvo - ATOS Research & Innovation
23
+ * Modified by: Jason Fox - FIWARE Foundation
24
24
*/
25
- 'use strict' ;
26
25
27
26
/* jshint camelcase: false */
28
27
29
- var iotAgentLib = require ( '../../../../lib/fiware-iotagent-lib' ) ,
30
- utils = require ( '../../../tools/utils' ) ,
31
- should = require ( 'should' ) ,
32
- nock = require ( 'nock' ) ,
33
- request = require ( 'request' ) ,
34
- logger = require ( 'logops' ) ,
35
- async = require ( 'async' ) ,
36
- iotAgentConfig = {
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
28
+ const iotAgentLib = require ( '../../../../lib/fiware-iotagent-lib' ) ;
29
+ const utils = require ( '../../../tools/utils' ) ;
30
+ const should = require ( 'should' ) ;
31
+ const nock = require ( 'nock' ) ;
32
+ const request = require ( 'request' ) ;
33
+ const logger = require ( 'logops' ) ;
34
+ const async = require ( 'async' ) ;
35
+ const iotAgentConfig = {
36
+ contextBroker : {
37
+ host : '192.168.1.1' ,
38
+ port : '1026' ,
39
+ ngsiVersion : 'ld' ,
40
+ jsonLdContext : 'http://context.json-ld'
41
+ } ,
42
+ server : {
43
+ port : 4041
44
+ } ,
45
+ types : {
46
+ Light : {
47
+ commands : [ ] ,
48
+ type : 'Light' ,
49
+ lazy : [
50
+ {
51
+ name : 'temperature' ,
52
+ type : 'centigrades'
53
+ }
54
+ ] ,
55
+ active : [
56
+ {
57
+ name : 'pressure' ,
58
+ type : 'Hgmm'
59
+ }
60
+ ]
45
61
} ,
46
- types : {
47
- 'Light' : {
48
- commands : [ ] ,
49
- type : 'Light' ,
50
- lazy : [
51
- {
52
- name : 'temperature' ,
53
- type : 'centigrades'
54
- }
55
- ] ,
56
- active : [
57
- {
58
- name : 'pressure' ,
59
- type : 'Hgmm'
60
- }
61
- ]
62
- } ,
63
- 'BrokenLight' : {
64
- commands : [ ] ,
65
- lazy : [
66
- {
67
- name : 'temperature' ,
68
- type : 'centigrades'
69
- }
70
- ] ,
71
- active : [
72
- {
73
- name : 'pressure' ,
74
- type : 'Hgmm'
75
- }
76
- ]
77
- } ,
78
- 'Termometer' : {
79
- type : 'Termometer' ,
80
- commands : [ ] ,
81
- lazy : [
82
- {
83
- name : 'temp' ,
84
- type : 'kelvin'
85
- }
86
- ] ,
87
- active : [
88
- ]
89
- } ,
90
- 'Humidity' : {
91
- type : 'Humidity' ,
92
- cbHost : 'http://192.168.1.1:3024' ,
93
- commands : [ ] ,
94
- lazy : [ ] ,
95
- active : [
96
- {
97
- name : 'humidity' ,
98
- type : 'percentage'
99
- }
100
- ]
101
- } ,
102
- 'Motion' : {
103
- type : 'Motion' ,
104
- commands : [ ] ,
105
- lazy : [ ] ,
106
- staticAttributes : [
107
- {
108
- 'name' : 'location' ,
109
- 'type' : 'Vector' ,
110
- 'value' : '(123,523)'
111
- }
112
- ] ,
113
- active : [
114
- {
115
- name : 'humidity' ,
116
- type : 'percentage'
117
- }
118
- ]
119
- }
62
+ BrokenLight : {
63
+ commands : [ ] ,
64
+ lazy : [
65
+ {
66
+ name : 'temperature' ,
67
+ type : 'centigrades'
68
+ }
69
+ ] ,
70
+ active : [
71
+ {
72
+ name : 'pressure' ,
73
+ type : 'Hgmm'
74
+ }
75
+ ]
120
76
} ,
121
- iotManager : {
122
- host : 'localhost' ,
123
- port : 8082 ,
124
- path : '/protocols' ,
125
- protocol : 'MQTT_UL' ,
126
- description : 'MQTT Ultralight 2.0 IoT Agent (Node.js version)'
77
+ Termometer : {
78
+ type : 'Termometer' ,
79
+ commands : [ ] ,
80
+ lazy : [
81
+ {
82
+ name : 'temp' ,
83
+ type : 'kelvin'
84
+ }
85
+ ] ,
86
+ active : [ ]
127
87
} ,
128
- service : 'smartGondor' ,
129
- subservice : 'gardens' ,
130
- providerUrl : 'http://smartGondor.com'
131
- } ,
132
- groupCreation = {
133
- url : 'http://localhost:' + iotAgentConfig . server . port + '/iot/services' ,
134
- method : 'POST' ,
135
- json : {
136
- services : [
88
+ Humidity : {
89
+ type : 'Humidity' ,
90
+ cbHost : 'http://192.168.1.1:3024' ,
91
+ commands : [ ] ,
92
+ lazy : [ ] ,
93
+ active : [
137
94
{
138
- resource : '' ,
139
- apikey : '801230BJKL23Y9090DSFL123HJK09H324HV8732' ,
140
- entity_type : 'TheLightType' ,
141
- trust : '8970A9078A803H3BL98PINEQRW8342HBAMS' ,
142
- cbHost : 'http://unexistentHost:1026' ,
143
- commands : [ ] ,
144
- lazy : [ ] ,
145
- attributes : [
146
- {
147
- name : 'status' ,
148
- type : 'Boolean'
149
- }
150
- ] ,
151
- static_attributes : [ ]
95
+ name : 'humidity' ,
96
+ type : 'percentage'
152
97
}
153
98
]
154
99
} ,
155
- headers : {
156
- 'fiware-service' : 'TestService' ,
157
- 'fiware-servicepath' : '/testingPath'
100
+ Motion : {
101
+ type : 'Motion' ,
102
+ commands : [ ] ,
103
+ lazy : [ ] ,
104
+ staticAttributes : [
105
+ {
106
+ name : 'location' ,
107
+ type : 'Vector' ,
108
+ value : '(123,523)'
109
+ }
110
+ ] ,
111
+ active : [
112
+ {
113
+ name : 'humidity' ,
114
+ type : 'percentage'
115
+ }
116
+ ]
158
117
}
159
118
} ,
160
- deviceCreation = {
161
- url : 'http://localhost:' + iotAgentConfig . server . port + '/iot/devices' ,
162
- method : 'POST' ,
163
- json : utils . readExampleFile ( './test/unit/examples/deviceProvisioningRequests/provisionNewDevice.json' ) ,
164
- headers : {
165
- 'fiware-service' : 'TestService' ,
166
- 'fiware-servicepath' : '/testingPath'
167
- }
119
+ iotManager : {
120
+ host : 'localhost' ,
121
+ port : 8082 ,
122
+ path : '/protocols' ,
123
+ protocol : 'MQTT_UL' ,
124
+ description : 'MQTT Ultralight 2.0 IoT Agent (Node.js version)'
168
125
} ,
169
- contextBrokerMock ,
170
- iotamMock ;
171
-
126
+ service : 'smartGondor' ,
127
+ subservice : 'gardens' ,
128
+ providerUrl : 'http://smartGondor.com'
129
+ } ;
130
+ const groupCreation = {
131
+ url : 'http://localhost:' + iotAgentConfig . server . port + '/iot/services' ,
132
+ method : 'POST' ,
133
+ json : {
134
+ services : [
135
+ {
136
+ resource : '' ,
137
+ apikey : '801230BJKL23Y9090DSFL123HJK09H324HV8732' ,
138
+ entity_type : 'TheLightType' ,
139
+ trust : '8970A9078A803H3BL98PINEQRW8342HBAMS' ,
140
+ cbHost : 'http://unexistentHost:1026' ,
141
+ commands : [ ] ,
142
+ lazy : [ ] ,
143
+ attributes : [
144
+ {
145
+ name : 'status' ,
146
+ type : 'Boolean'
147
+ }
148
+ ] ,
149
+ static_attributes : [ ]
150
+ }
151
+ ]
152
+ } ,
153
+ headers : {
154
+ 'fiware-service' : 'TestService' ,
155
+ 'fiware-servicepath' : '/testingPath'
156
+ }
157
+ } ;
158
+ const deviceCreation = {
159
+ url : 'http://localhost:' + iotAgentConfig . server . port + '/iot/devices' ,
160
+ method : 'POST' ,
161
+ json : utils . readExampleFile ( './test/unit/examples/deviceProvisioningRequests/provisionNewDevice.json' ) ,
162
+ headers : {
163
+ 'fiware-service' : 'TestService' ,
164
+ 'fiware-servicepath' : '/testingPath'
165
+ }
166
+ } ;
167
+ let contextBrokerMock ;
168
+ let iotamMock ;
172
169
173
170
/* jshint camelcase: false */
174
171
describe ( 'NGSI-LD - Device Service: utils' , function ( ) {
@@ -184,15 +181,11 @@ describe('NGSI-LD - Device Service: utils', function() {
184
181
185
182
afterEach ( function ( done ) {
186
183
nock . cleanAll ( ) ;
187
- async . series ( [
188
- iotAgentLib . clearAll ,
189
- iotAgentLib . deactivate
190
- ] , done ) ;
184
+ async . series ( [ iotAgentLib . clearAll , iotAgentLib . deactivate ] , done ) ;
191
185
} ) ;
192
186
193
187
describe ( 'When an existing device tries to be retrieved with retrieveOrCreate()' , function ( ) {
194
188
beforeEach ( function ( done ) {
195
-
196
189
// This mock does not check the payload since the aim of the test is not to verify
197
190
// device provisioning functionality. Appropriate verification is done in tests under
198
191
// provisioning folder
@@ -201,10 +194,10 @@ describe('NGSI-LD - Device Service: utils', function() {
201
194
. post ( '/ngsi-ld/v1/entityOperations/upsert/' )
202
195
. reply ( 200 ) ;
203
196
204
- async . series ( [
205
- request . bind ( request , groupCreation ) ,
206
- request . bind ( request , deviceCreation )
207
- ] , function ( error , results ) {
197
+ async . series ( [ request . bind ( request , groupCreation ) , request . bind ( request , deviceCreation ) ] , function (
198
+ error ,
199
+ results
200
+ ) {
208
201
done ( ) ;
209
202
} ) ;
210
203
} ) ;
@@ -222,7 +215,6 @@ describe('NGSI-LD - Device Service: utils', function() {
222
215
223
216
describe ( 'When an unexisting device tries to be retrieved for an existing APIKey' , function ( ) {
224
217
beforeEach ( function ( done ) {
225
-
226
218
// This mock does not check the payload since the aim of the test is not to verify
227
219
// device provisioning functionality. Appropriate verification is done in tests under
228
220
// provisioning folder
@@ -231,36 +223,38 @@ describe('NGSI-LD - Device Service: utils', function() {
231
223
. post ( '/ngsi-ld/v1/entityOperations/upsert/' )
232
224
. reply ( 200 ) ;
233
225
234
- async . series ( [
235
- request . bind ( request , groupCreation )
236
- ] , function ( error , results ) {
226
+ async . series ( [ request . bind ( request , groupCreation ) ] , function ( error , results ) {
237
227
done ( ) ;
238
228
} ) ;
239
229
} ) ;
240
230
241
231
it ( 'should register the device and return it' , function ( done ) {
242
- iotAgentLib . retrieveDevice ( 'UNEXISTENT_DEV' , '801230BJKL23Y9090DSFL123HJK09H324HV8732' ,
243
- function ( error , device ) {
244
- should . not . exist ( error ) ;
245
- should . exist ( device ) ;
232
+ iotAgentLib . retrieveDevice ( 'UNEXISTENT_DEV' , '801230BJKL23Y9090DSFL123HJK09H324HV8732' , function (
233
+ error ,
234
+ device
235
+ ) {
236
+ should . not . exist ( error ) ;
237
+ should . exist ( device ) ;
246
238
247
- device . id . should . equal ( 'UNEXISTENT_DEV' ) ;
248
- should . exist ( device . protocol ) ;
249
- device . protocol . should . equal ( 'MQTT_UL' ) ;
250
- done ( ) ;
251
- } ) ;
239
+ device . id . should . equal ( 'UNEXISTENT_DEV' ) ;
240
+ should . exist ( device . protocol ) ;
241
+ device . protocol . should . equal ( 'MQTT_UL' ) ;
242
+ done ( ) ;
243
+ } ) ;
252
244
} ) ;
253
245
} ) ;
254
246
255
247
describe ( 'When an unexisting device tries to be retrieved for an unexisting APIKey' , function ( ) {
256
248
it ( 'should raise an error' , function ( done ) {
257
- iotAgentLib . retrieveDevice ( 'UNEXISTENT_DEV_AND_GROUP' , 'H2332Y909DSF3H346yh20JK092' ,
258
- function ( error , device ) {
259
- should . exist ( error ) ;
260
- error . name . should . equal ( 'DEVICE_GROUP_NOT_FOUND' ) ;
261
- should . not . exist ( device ) ;
262
- done ( ) ;
263
- } ) ;
249
+ iotAgentLib . retrieveDevice ( 'UNEXISTENT_DEV_AND_GROUP' , 'H2332Y909DSF3H346yh20JK092' , function (
250
+ error ,
251
+ device
252
+ ) {
253
+ should . exist ( error ) ;
254
+ error . name . should . equal ( 'DEVICE_GROUP_NOT_FOUND' ) ;
255
+ should . not . exist ( device ) ;
256
+ done ( ) ;
257
+ } ) ;
264
258
} ) ;
265
259
} ) ;
266
260
} ) ;
0 commit comments