iotagent-node-lib 2.26.0 → 3.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.
Files changed (60) hide show
  1. package/lib/fiware-iotagent-lib.js +0 -5
  2. package/lib/plugins/compressTimestamp.js +2 -7
  3. package/lib/plugins/expressionParser.js +0 -47
  4. package/lib/plugins/expressionPlugin.js +6 -78
  5. package/lib/plugins/jexlParser.js +0 -36
  6. package/lib/plugins/pluginUtils.js +0 -119
  7. package/lib/services/ngsi/entities-NGSI-LD.js +600 -199
  8. package/lib/services/ngsi/entities-NGSI-v2.js +620 -298
  9. package/lib/services/ngsi/ngsiUtils.js +15 -22
  10. package/package.json +1 -1
  11. package/test/unit/general/loglevel-api_test.js +0 -2
  12. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin1.json +0 -5
  13. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast10.json +1 -1
  14. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast8.json +1 -1
  15. package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast9.json +1 -1
  16. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +16 -15
  17. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4.json +8 -8
  18. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +34 -34
  19. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +8 -8
  20. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin6.json +0 -20
  21. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin7.json +0 -5
  22. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +10 -10
  23. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +8 -7
  24. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +5 -4
  25. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  26. package/test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json +4 -4
  27. package/test/unit/ngsi-ld/examples/contextRequests/updateContextTimestampOverride.json +4 -3
  28. package/test/unit/ngsi-ld/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +4 -3
  29. package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +2 -5
  30. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1 -7
  31. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +15 -3
  32. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +0 -2
  33. package/test/unit/ngsi-ld/plugins/compress-timestamp-plugin_test.js +0 -31
  34. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +18 -18
  35. package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +19 -6
  36. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -2
  37. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +5 -1
  38. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +4 -4
  39. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +0 -16
  40. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +0 -4
  41. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +8 -8
  42. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +42 -42
  43. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +7 -7
  44. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +0 -5
  45. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +1 -7
  46. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +0 -3
  47. package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +0 -6
  48. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +1 -7
  49. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +0 -2
  50. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +0 -4
  51. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +0 -32
  52. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +5 -15
  53. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +1 -1
  54. package/lib/plugins/addEvent.js +0 -32
  55. package/lib/plugins/attributeAlias.js +0 -107
  56. package/lib/plugins/multiEntity.js +0 -255
  57. package/lib/plugins/timestampProcessPlugin.js +0 -95
  58. package/test/unit/ngsi-ld/plugins/event-plugin_test.js +0 -116
  59. package/test/unit/ngsiv2/plugins/event-plugin_test.js +0 -118
  60. package/test/unit/ngsiv2/plugins/translation-inPlugins_test.js +0 -262
@@ -1,262 +0,0 @@
1
- /*
2
- * Copyright 2014 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
-
24
- /* eslint-disable no-unused-vars */
25
-
26
- const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
27
- const utils = require('../../../tools/utils');
28
- const request = utils.request;
29
- const should = require('should');
30
- const logger = require('logops');
31
- const nock = require('nock');
32
- let contextBrokerMock;
33
- const iotAgentConfig = {
34
- contextBroker: {
35
- host: '192.168.1.1',
36
- port: '1026',
37
- nsgiVersion: 'v2'
38
- },
39
- server: {
40
- port: 4041
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
- BrokenLight: {
60
- commands: [],
61
- lazy: [
62
- {
63
- name: 'temperature',
64
- type: 'centigrades'
65
- }
66
- ],
67
- active: [
68
- {
69
- name: 'pressure',
70
- type: 'Hgmm'
71
- }
72
- ]
73
- },
74
- Termometer: {
75
- type: 'Termometer',
76
- commands: [],
77
- lazy: [
78
- {
79
- name: 'temp',
80
- type: 'kelvin'
81
- }
82
- ],
83
- active: []
84
- },
85
- Humidity: {
86
- type: 'Humidity',
87
- cbHost: 'http://192.168.1.1:3024',
88
- commands: [],
89
- lazy: [],
90
- active: [
91
- {
92
- name: 'humidity',
93
- type: 'percentage'
94
- }
95
- ]
96
- },
97
- Motion: {
98
- type: 'Motion',
99
- commands: [],
100
- lazy: [],
101
- staticAttributes: [
102
- {
103
- name: 'location',
104
- type: 'Vector',
105
- value: '(123,523)'
106
- }
107
- ],
108
- active: [
109
- {
110
- name: 'humidity',
111
- type: 'percentage'
112
- }
113
- ]
114
- }
115
- },
116
- service: 'smartgondor',
117
- subservice: 'gardens',
118
- providerUrl: 'http://smartgondor.com',
119
- deviceRegistrationDuration: 'P1M'
120
- };
121
-
122
- describe('NGSI-v2 - Data Mapping Plugins: translation', function () {
123
- beforeEach(function (done) {
124
- logger.setLevel('FATAL');
125
-
126
- iotAgentLib.activate(iotAgentConfig, function () {
127
- iotAgentLib.clearAll(done);
128
- });
129
- });
130
-
131
- afterEach(function (done) {
132
- iotAgentLib.clearAll(function () {
133
- iotAgentLib.deactivate(done);
134
- });
135
- });
136
-
137
- describe('When a new update translation middleware is added to the IoT Agent', function () {
138
- beforeEach(function () {
139
- nock.cleanAll();
140
-
141
- contextBrokerMock = nock('http://192.168.1.1:1026')
142
- .matchHeader('fiware-service', 'smartgondor')
143
- .matchHeader('fiware-servicepath', 'gardens')
144
- .patch(
145
- '/v2/entities/light1/attrs?type=Light',
146
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware1.json')
147
- )
148
- .reply(204);
149
- });
150
-
151
- it('should execute the translation middlewares', function (done) {
152
- const values = [
153
- {
154
- name: 'state',
155
- type: 'Boolean',
156
- value: 'true'
157
- },
158
- {
159
- name: 'dimming',
160
- type: 'Percentage',
161
- value: '87'
162
- }
163
- ];
164
-
165
- let executed = false;
166
-
167
- function testMiddleware(entity, typeInformation, callback) {
168
- entity.dimming.value = entity.dimming.value + '%';
169
- executed = true;
170
- callback(null, entity, typeInformation);
171
- }
172
-
173
- iotAgentLib.addUpdateMiddleware(testMiddleware);
174
-
175
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
176
- should.not.exist(error);
177
- executed.should.equal(true);
178
- done();
179
- });
180
- });
181
-
182
- it('should translate the appropriate attributes', function (done) {
183
- const values = [
184
- {
185
- name: 'state',
186
- type: 'Boolean',
187
- value: 'true'
188
- },
189
- {
190
- name: 'dimming',
191
- type: 'Percentage',
192
- value: '87'
193
- }
194
- ];
195
-
196
- function testMiddleware(entity, typeInformation, callback) {
197
- entity.dimming.value = entity.dimming.value + '%';
198
- callback(null, entity, typeInformation);
199
- }
200
-
201
- iotAgentLib.addUpdateMiddleware(testMiddleware);
202
-
203
- iotAgentLib.update('light1', 'Light', '', values, function (error) {
204
- should.not.exist(error);
205
- contextBrokerMock.done();
206
- done();
207
- });
208
- });
209
- });
210
-
211
- describe('When a new query translation middleware is added to the IoT Agent', function () {
212
- const attributes = ['state', 'dimming'];
213
-
214
- beforeEach(function () {
215
- nock.cleanAll();
216
-
217
- contextBrokerMock = nock('http://192.168.1.1:1026')
218
- .matchHeader('fiware-service', 'smartgondor')
219
- .matchHeader('fiware-servicepath', 'gardens')
220
- .get('/v2/entities/light1/attrs?attrs=state,dimming&type=Light')
221
-
222
- .reply(
223
- 200,
224
- utils.readExampleFile('./test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware2.json')
225
- );
226
- });
227
-
228
- it('should call the middleware', function (done) {
229
- let called = false;
230
-
231
- function testMiddleware(entity, typeInformation, callback) {
232
- entity.dimming.value = entity.dimming.value + '%';
233
-
234
- called = true;
235
-
236
- callback(null, entity, typeInformation);
237
- }
238
-
239
- iotAgentLib.addQueryMiddleware(testMiddleware);
240
-
241
- iotAgentLib.query('light1', 'Light', '', attributes, function (error, result) {
242
- should.not.exist(error);
243
- called.should.equal(true);
244
- done();
245
- });
246
- });
247
- it('should call the middleware', function (done) {
248
- function testMiddleware(entity, typeInformation, callback) {
249
- entity.dimming.value = entity.dimming.value + '%';
250
- callback(null, entity, typeInformation);
251
- }
252
-
253
- iotAgentLib.addQueryMiddleware(testMiddleware);
254
-
255
- iotAgentLib.query('light1', 'Light', '', attributes, function (error, result) {
256
- should.not.exist(error);
257
- result.dimming.value.should.equal('23%');
258
- done();
259
- });
260
- });
261
- });
262
- });