iotagent-node-lib 4.2.0 → 4.4.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 (31) hide show
  1. package/doc/api.md +178 -69
  2. package/docker/Mosquitto/Dockerfile +1 -1
  3. package/lib/commonConfig.js +18 -0
  4. package/lib/errors.js +48 -20
  5. package/lib/services/commands/commandRegistryMemory.js +12 -2
  6. package/lib/services/commands/commandRegistryMongoDB.js +26 -15
  7. package/lib/services/devices/deviceRegistryMemory.js +1 -1
  8. package/lib/services/devices/deviceRegistryMongoDB.js +7 -12
  9. package/lib/services/devices/deviceService.js +4 -3
  10. package/lib/services/devices/devices-NGSI-LD.js +3 -3
  11. package/lib/services/devices/devices-NGSI-v2.js +10 -4
  12. package/lib/services/groups/groupRegistryMemory.js +1 -1
  13. package/lib/services/groups/groupRegistryMongoDB.js +1 -1
  14. package/lib/services/groups/groupService.js +9 -3
  15. package/lib/services/ngsi/entities-NGSI-LD.js +15 -7
  16. package/lib/services/ngsi/entities-NGSI-v2.js +86 -54
  17. package/lib/services/ngsi/ngsiService.js +3 -3
  18. package/lib/services/ngsi/subscription-NGSI-LD.js +2 -0
  19. package/lib/services/ngsi/subscription-NGSI-v2.js +2 -0
  20. package/lib/services/northBound/contextServer-NGSI-LD.js +50 -55
  21. package/lib/services/northBound/contextServer-NGSI-v2.js +1 -1
  22. package/lib/services/northBound/deviceProvisioningServer.js +100 -26
  23. package/lib/services/northBound/restUtils.js +1 -1
  24. package/package.json +2 -2
  25. package/scripts/legacy_expression_tool/requirements.txt +1 -1
  26. package/test/functional/testCases.js +797 -66
  27. package/test/functional/testUtils.js +3 -1
  28. package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +0 -1
  29. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +8 -5
  30. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +34 -2
  31. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +37 -2
@@ -96,26 +96,26 @@ const testCases = [
96
96
  type: globalEnv.entity_type,
97
97
  a: {
98
98
  value: false,
99
- type: 'string'
99
+ type: 'Text'
100
100
  },
101
101
  b: {
102
102
  value: 10,
103
- type: 'string'
103
+ type: 'Text'
104
104
  },
105
105
  c: {
106
- type: 'string',
106
+ type: 'Text',
107
107
  value: 'text'
108
108
  },
109
109
  d: {
110
- type: 'string',
110
+ type: 'Text',
111
111
  value: 10.5
112
112
  },
113
113
  e: {
114
- type: 'string',
114
+ type: 'Text',
115
115
  value: [1, 2]
116
116
  },
117
117
  f: {
118
- type: 'string',
118
+ type: 'Text',
119
119
  value: {
120
120
  a: 1,
121
121
  b: 2
@@ -149,26 +149,26 @@ const testCases = [
149
149
  type: globalEnv.entity_type,
150
150
  a: {
151
151
  value: false,
152
- type: 'string'
152
+ type: 'Text'
153
153
  },
154
154
  b: {
155
155
  value: 10,
156
- type: 'string'
156
+ type: 'Text'
157
157
  },
158
158
  c: {
159
- type: 'string',
159
+ type: 'Text',
160
160
  value: 'text'
161
161
  },
162
162
  d: {
163
- type: 'string',
163
+ type: 'Text',
164
164
  value: 10.5
165
165
  },
166
166
  e: {
167
- type: 'string',
167
+ type: 'Text',
168
168
  value: [1, 2]
169
169
  },
170
170
  f: {
171
- type: 'string',
171
+ type: 'Text',
172
172
  value: {
173
173
  a: 1,
174
174
  b: 2
@@ -363,26 +363,26 @@ const testCases = [
363
363
  type: globalEnv.entity_type,
364
364
  u: {
365
365
  value: false,
366
- type: 'string'
366
+ type: 'Text'
367
367
  },
368
368
  v: {
369
369
  value: 10,
370
- type: 'string'
370
+ type: 'Text'
371
371
  },
372
372
  w: {
373
- type: 'string',
373
+ type: 'Text',
374
374
  value: 'text'
375
375
  },
376
376
  y: {
377
- type: 'string',
377
+ type: 'Text',
378
378
  value: 10.5
379
379
  },
380
380
  x: {
381
- type: 'string',
381
+ type: 'Text',
382
382
  value: [1, 2]
383
383
  },
384
384
  z: {
385
- type: 'string',
385
+ type: 'Text',
386
386
  value: {
387
387
  a: 1,
388
388
  b: 2
@@ -416,26 +416,26 @@ const testCases = [
416
416
  type: globalEnv.entity_type,
417
417
  u: {
418
418
  value: false,
419
- type: 'string'
419
+ type: 'Text'
420
420
  },
421
421
  v: {
422
422
  value: 10,
423
- type: 'string'
423
+ type: 'Text'
424
424
  },
425
425
  w: {
426
- type: 'string',
426
+ type: 'Text',
427
427
  value: 'text'
428
428
  },
429
429
  y: {
430
- type: 'string',
430
+ type: 'Text',
431
431
  value: 10.5
432
432
  },
433
433
  x: {
434
- type: 'string',
434
+ type: 'Text',
435
435
  value: [1, 2]
436
436
  },
437
437
  z: {
438
- type: 'string',
438
+ type: 'Text',
439
439
  value: {
440
440
  a: 1,
441
441
  b: 2
@@ -445,6 +445,74 @@ const testCases = [
445
445
  }
446
446
  ]
447
447
  },
448
+ {
449
+ describeName: '0021 Simple group with active attributes with metadata',
450
+ provision: {
451
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
452
+ method: 'POST',
453
+ json: {
454
+ services: [
455
+ {
456
+ resource: '/iot/json',
457
+ apikey: globalEnv.apikey,
458
+ entity_type: globalEnv.entity_type,
459
+ commands: [],
460
+ lazy: [],
461
+ attributes: [
462
+ {
463
+ object_id: 'a',
464
+ name: 'attr_a',
465
+ type: 'Boolean',
466
+ metadata: {
467
+ accuracy: {
468
+ value: 0.8,
469
+ type: 'Float'
470
+ }
471
+ }
472
+ }
473
+ ],
474
+ static_attributes: []
475
+ }
476
+ ]
477
+ },
478
+ headers: {
479
+ 'fiware-service': globalEnv.service,
480
+ 'fiware-servicepath': globalEnv.servicePath
481
+ }
482
+ },
483
+ should: [
484
+ {
485
+ shouldName:
486
+ 'A - WHEN sending defined object_ids (measures) through http IT should send measures to Context Broker preserving value types, name mappings and metadatas',
487
+ type: 'single',
488
+ measure: {
489
+ url: 'http://localhost:' + config.http.port + '/iot/json',
490
+ method: 'POST',
491
+ qs: {
492
+ i: globalEnv.deviceId,
493
+ k: globalEnv.apikey
494
+ },
495
+ json: {
496
+ a: false
497
+ }
498
+ },
499
+ expectation: {
500
+ id: globalEnv.entity_name,
501
+ type: globalEnv.entity_type,
502
+ attr_a: {
503
+ value: false,
504
+ type: 'Boolean',
505
+ metadata: {
506
+ accuracy: {
507
+ value: 0.8,
508
+ type: 'Float'
509
+ }
510
+ }
511
+ }
512
+ }
513
+ }
514
+ ]
515
+ },
448
516
  // 0100 - JEXL TESTS
449
517
  {
450
518
  describeName: '0100 - Simple group with active attribute + JEXL expression boolean (!)',
@@ -573,7 +641,7 @@ const testCases = [
573
641
  },
574
642
  b: {
575
643
  value: 1,
576
- type: 'string'
644
+ type: 'Text'
577
645
  }
578
646
  }
579
647
  }
@@ -726,7 +794,7 @@ const testCases = [
726
794
  type: globalEnv.entity_type,
727
795
  b: {
728
796
  value: 1,
729
- type: 'string'
797
+ type: 'Text'
730
798
  }
731
799
  }
732
800
  }
@@ -872,7 +940,7 @@ const testCases = [
872
940
  type: globalEnv.entity_type,
873
941
  b: {
874
942
  value: 1,
875
- type: 'string'
943
+ type: 'Text'
876
944
  }
877
945
  }
878
946
  }
@@ -1029,14 +1097,15 @@ const testCases = [
1029
1097
  },
1030
1098
  b: {
1031
1099
  value: 1,
1032
- type: 'string'
1100
+ type: 'Text'
1033
1101
  }
1034
1102
  }
1035
1103
  }
1036
1104
  ]
1037
1105
  },
1038
1106
  {
1039
- describeName: '0140 - Simple group with active attribute + chained JEXL expression text (a|substr(0,2))',
1107
+ describeName:
1108
+ '0140 - Simple group with active attribute + chained JEXL expression text (a | trim | replacestr("hello","hi"))',
1040
1109
  provision: {
1041
1110
  url: 'http://localhost:' + config.iota.server.port + '/iot/services',
1042
1111
  method: 'POST',
@@ -1476,6 +1545,75 @@ const testCases = [
1476
1545
  }
1477
1546
  ]
1478
1547
  },
1548
+ {
1549
+ describeName: '0191 - Simple group with JEXL expression in metadata',
1550
+ provision: {
1551
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
1552
+ method: 'POST',
1553
+ json: {
1554
+ services: [
1555
+ {
1556
+ resource: '/iot/json',
1557
+ apikey: globalEnv.apikey,
1558
+ entity_type: globalEnv.entity_type,
1559
+ commands: [],
1560
+ lazy: [],
1561
+ attributes: [
1562
+ {
1563
+ object_id: 'a',
1564
+ name: 'attr_a',
1565
+ type: 'Boolean',
1566
+ expression: 'a?threshold[90|tostring].max:true',
1567
+ metadata: {
1568
+ unit: {
1569
+ type: 'Text',
1570
+ expression: '"hola" + "adios"'
1571
+ }
1572
+ }
1573
+ }
1574
+ ]
1575
+ }
1576
+ ]
1577
+ },
1578
+ headers: {
1579
+ 'fiware-service': globalEnv.service,
1580
+ 'fiware-servicepath': globalEnv.servicePath
1581
+ }
1582
+ },
1583
+ should: [
1584
+ {
1585
+ shouldName:
1586
+ 'A - WHEN sending a measure through http IT should send to Context Broker expanded metadata value ',
1587
+ type: 'single',
1588
+ isRegex: true,
1589
+ measure: {
1590
+ url: 'http://localhost:' + config.http.port + '/iot/json',
1591
+ method: 'POST',
1592
+ qs: {
1593
+ i: globalEnv.deviceId,
1594
+ k: globalEnv.apikey
1595
+ },
1596
+ json: {
1597
+ a: false
1598
+ }
1599
+ },
1600
+ expectation: {
1601
+ id: globalEnv.entity_name,
1602
+ type: globalEnv.entity_type,
1603
+ attr_a: {
1604
+ value: true,
1605
+ type: 'Boolean',
1606
+ metadata: {
1607
+ unit: {
1608
+ type: 'Text',
1609
+ value: 'holaadios'
1610
+ }
1611
+ }
1612
+ }
1613
+ }
1614
+ }
1615
+ ]
1616
+ },
1479
1617
  // 0200 - COMMANDS TESTS
1480
1618
  {
1481
1619
  describeName: '0200 - Simple group with commands',
@@ -1529,7 +1667,7 @@ const testCases = [
1529
1667
  type: globalEnv.entity_type,
1530
1668
  b: {
1531
1669
  value: 10,
1532
- type: 'string'
1670
+ type: 'Text'
1533
1671
  }
1534
1672
  }
1535
1673
  }
@@ -1594,7 +1732,7 @@ const testCases = [
1594
1732
  type: globalEnv.entity_type,
1595
1733
  b: {
1596
1734
  value: 10,
1597
- type: 'string'
1735
+ type: 'Text'
1598
1736
  },
1599
1737
  static_a: {
1600
1738
  value: 3,
@@ -1688,7 +1826,7 @@ const testCases = [
1688
1826
  type: globalEnv.entity_type,
1689
1827
  a: {
1690
1828
  value: 10,
1691
- type: 'string'
1829
+ type: 'Text'
1692
1830
  },
1693
1831
  static_a: {
1694
1832
  value: {
@@ -1704,6 +1842,78 @@ const testCases = [
1704
1842
  }
1705
1843
  ]
1706
1844
  },
1845
+ {
1846
+ describeName: '0320 - Simple group with active attributes + metadata in Static attributes ',
1847
+ provision: {
1848
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
1849
+ method: 'POST',
1850
+ json: {
1851
+ services: [
1852
+ {
1853
+ resource: '/iot/json',
1854
+ apikey: globalEnv.apikey,
1855
+ entity_type: globalEnv.entity_type,
1856
+ commands: [],
1857
+ lazy: [],
1858
+ attributes: [],
1859
+ static_attributes: [
1860
+ {
1861
+ name: 'static_a',
1862
+ type: 'Number',
1863
+ value: 4,
1864
+ metadata: {
1865
+ accuracy: {
1866
+ value: 0.8,
1867
+ type: 'Float'
1868
+ }
1869
+ }
1870
+ }
1871
+ ]
1872
+ }
1873
+ ]
1874
+ },
1875
+ headers: {
1876
+ 'fiware-service': globalEnv.service,
1877
+ 'fiware-servicepath': globalEnv.servicePath
1878
+ }
1879
+ },
1880
+ should: [
1881
+ {
1882
+ shouldName:
1883
+ 'A - WHEN sending measures through http IT should store metatada static attributes into Context Broker',
1884
+ type: 'single',
1885
+ measure: {
1886
+ url: 'http://localhost:' + config.http.port + '/iot/json',
1887
+ method: 'POST',
1888
+ qs: {
1889
+ i: globalEnv.deviceId,
1890
+ k: globalEnv.apikey
1891
+ },
1892
+ json: {
1893
+ a: 10
1894
+ }
1895
+ },
1896
+ expectation: {
1897
+ id: globalEnv.entity_name,
1898
+ type: globalEnv.entity_type,
1899
+ a: {
1900
+ value: 10,
1901
+ type: 'Text'
1902
+ },
1903
+ static_a: {
1904
+ value: 4,
1905
+ type: 'Number',
1906
+ metadata: {
1907
+ accuracy: {
1908
+ value: 0.8,
1909
+ type: 'Float'
1910
+ }
1911
+ }
1912
+ }
1913
+ }
1914
+ }
1915
+ ]
1916
+ },
1707
1917
  // 0400 - TIMESTAMP TESTS
1708
1918
  {
1709
1919
  describeName: '0400 - Simple group with active attribute + timestamp:false',
@@ -1976,9 +2186,8 @@ const testCases = [
1976
2186
  }
1977
2187
  ]
1978
2188
  },
1979
- // 0500 - EXPLICIT ATTRIBUTES TESTS
1980
2189
  {
1981
- describeName: '0500 - Group with explicit attrs:false (boolean) + active atributes',
2190
+ describeName: '0430 - Simple group with active attribute + timestamp mapping defined',
1982
2191
  provision: {
1983
2192
  url: 'http://localhost:' + config.iota.server.port + '/iot/services',
1984
2193
  method: 'POST',
@@ -1987,18 +2196,17 @@ const testCases = [
1987
2196
  {
1988
2197
  resource: '/iot/json',
1989
2198
  apikey: globalEnv.apikey,
2199
+ timestamp: true,
1990
2200
  entity_type: globalEnv.entity_type,
1991
- explicitAttrs: false,
1992
2201
  commands: [],
1993
2202
  lazy: [],
1994
2203
  attributes: [
1995
2204
  {
1996
- object_id: 'a',
1997
- name: 'attr_a',
1998
- type: 'Number'
2205
+ object_id: 'mydatetime',
2206
+ name: 'TimeInstant',
2207
+ type: 'DateTime'
1999
2208
  }
2000
- ],
2001
- static_attributes: []
2209
+ ]
2002
2210
  }
2003
2211
  ]
2004
2212
  },
@@ -2010,7 +2218,7 @@ const testCases = [
2010
2218
  should: [
2011
2219
  {
2012
2220
  shouldName:
2013
- 'A - WHEN sending both provisioned and not object_ids (measures) through http IT should store all attributes into Context Broker',
2221
+ 'A - WHEN sending a measure through http IT should map the measure to timestamp attribute and use it for timestmap and other metadata attributes sent to Context Broker',
2014
2222
  type: 'single',
2015
2223
  measure: {
2016
2224
  url: 'http://localhost:' + config.http.port + '/iot/json',
@@ -2020,37 +2228,499 @@ const testCases = [
2020
2228
  k: globalEnv.apikey
2021
2229
  },
2022
2230
  json: {
2023
- a: 3,
2024
- b: 10
2231
+ mydatetime: '2022-02-02T02:22:22.222Z',
2232
+ a: 23
2025
2233
  }
2026
2234
  },
2027
2235
  expectation: {
2028
2236
  id: globalEnv.entity_name,
2029
2237
  type: globalEnv.entity_type,
2030
- b: {
2031
- value: 10,
2032
- type: 'string'
2238
+ a: {
2239
+ value: 23,
2240
+ type: 'Text',
2241
+ metadata: {
2242
+ TimeInstant: {
2243
+ value: '2022-02-02T02:22:22.222Z',
2244
+ type: 'DateTime'
2245
+ }
2246
+ }
2033
2247
  },
2034
- attr_a: {
2035
- value: 3,
2036
- type: 'Number'
2248
+ TimeInstant: {
2249
+ value: '2022-02-02T02:22:22.222Z',
2250
+ type: 'DateTime'
2037
2251
  }
2038
2252
  }
2039
- }
2040
- ]
2041
- },
2042
- {
2043
- describeName: '0510 - Group without explicit (not defined) + active atributes',
2044
- provision: {
2045
- url: 'http://localhost:' + config.iota.server.port + '/iot/services',
2046
- method: 'POST',
2047
- json: {
2048
- services: [
2049
- {
2050
- resource: '/iot/json',
2051
- apikey: globalEnv.apikey,
2052
- entity_type: globalEnv.entity_type,
2053
- commands: [],
2253
+ },
2254
+ {
2255
+ shouldName:
2256
+ 'A - WHEN sending a measure without timestamp through http IT should use system timestamp for mapped attribute and use it for timestmap and other metadata attributes sent to Context Broker',
2257
+ type: 'single',
2258
+ isRegex: true,
2259
+ measure: {
2260
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2261
+ method: 'POST',
2262
+ qs: {
2263
+ i: globalEnv.deviceId,
2264
+ k: globalEnv.apikey
2265
+ },
2266
+ json: {
2267
+ a: 23
2268
+ }
2269
+ },
2270
+ expectation: {
2271
+ id: globalEnv.entity_name,
2272
+ type: globalEnv.entity_type,
2273
+ a: {
2274
+ value: 23,
2275
+ type: 'Text',
2276
+ metadata: {
2277
+ TimeInstant: {
2278
+ value: _.isDateString,
2279
+ type: 'DateTime'
2280
+ }
2281
+ }
2282
+ },
2283
+ TimeInstant: {
2284
+ value: _.isDateString,
2285
+ type: 'DateTime'
2286
+ }
2287
+ }
2288
+ },
2289
+ {
2290
+ shouldName:
2291
+ 'A - WHEN sending a measure with timestamp through http IT should map the measure to timestamp attribute and use it for timestmap and other metadata attributes sent to Context Broker',
2292
+ type: 'single',
2293
+ measure: {
2294
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2295
+ method: 'POST',
2296
+ qs: {
2297
+ i: globalEnv.deviceId,
2298
+ k: globalEnv.apikey
2299
+ },
2300
+ json: {
2301
+ mydatetime: '2022-02-02T02:22:22.222Z',
2302
+ TimeInstant: '2033-03-03T03:33:33.333Z',
2303
+ a: 23
2304
+ }
2305
+ },
2306
+ expectation: {
2307
+ id: globalEnv.entity_name,
2308
+ type: globalEnv.entity_type,
2309
+ a: {
2310
+ value: 23,
2311
+ type: 'Text',
2312
+ metadata: {
2313
+ TimeInstant: {
2314
+ value: '2022-02-02T02:22:22.222Z',
2315
+ type: 'DateTime'
2316
+ }
2317
+ }
2318
+ },
2319
+ TimeInstant: {
2320
+ value: '2022-02-02T02:22:22.222Z',
2321
+ type: 'DateTime'
2322
+ }
2323
+ }
2324
+ }
2325
+ ]
2326
+ },
2327
+ {
2328
+ describeName: '0431 - Simple group with active attribute + timestamp mapping defined + explicitAttrs',
2329
+ provision: {
2330
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
2331
+ method: 'POST',
2332
+ json: {
2333
+ services: [
2334
+ {
2335
+ resource: '/iot/json',
2336
+ apikey: globalEnv.apikey,
2337
+ timestamp: true,
2338
+ explicitAttrs: true,
2339
+ entity_type: globalEnv.entity_type,
2340
+ commands: [],
2341
+ lazy: [],
2342
+ attributes: [
2343
+ {
2344
+ object_id: 'mydatetime',
2345
+ name: 'TimeInstant',
2346
+ type: 'DateTime'
2347
+ },
2348
+ {
2349
+ object_id: 'a',
2350
+ name: 'a',
2351
+ type: 'Text'
2352
+ }
2353
+ ]
2354
+ }
2355
+ ]
2356
+ },
2357
+ headers: {
2358
+ 'fiware-service': globalEnv.service,
2359
+ 'fiware-servicepath': globalEnv.servicePath
2360
+ }
2361
+ },
2362
+ should: [
2363
+ {
2364
+ shouldName:
2365
+ 'A - WHEN sending a measure through http IT should map the measure to timestamp attribute and use it for timestmap and other metadata attributes sent to Context Broker',
2366
+ type: 'single',
2367
+ measure: {
2368
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2369
+ method: 'POST',
2370
+ qs: {
2371
+ i: globalEnv.deviceId,
2372
+ k: globalEnv.apikey
2373
+ },
2374
+ json: {
2375
+ mydatetime: '2022-02-02T02:22:22.222Z',
2376
+ a: 23
2377
+ }
2378
+ },
2379
+ expectation: {
2380
+ id: globalEnv.entity_name,
2381
+ type: globalEnv.entity_type,
2382
+ a: {
2383
+ value: 23,
2384
+ type: 'Text',
2385
+ metadata: {
2386
+ TimeInstant: {
2387
+ value: '2022-02-02T02:22:22.222Z',
2388
+ type: 'DateTime'
2389
+ }
2390
+ }
2391
+ },
2392
+ TimeInstant: {
2393
+ value: '2022-02-02T02:22:22.222Z',
2394
+ type: 'DateTime'
2395
+ }
2396
+ }
2397
+ },
2398
+ {
2399
+ shouldName:
2400
+ 'A - WHEN sending a measure without timestamp through http IT should use system timestamp for mapped attribute and use it for timestmap and other metadata attributes sent to Context Broker',
2401
+ type: 'single',
2402
+ isRegex: true,
2403
+ measure: {
2404
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2405
+ method: 'POST',
2406
+ qs: {
2407
+ i: globalEnv.deviceId,
2408
+ k: globalEnv.apikey
2409
+ },
2410
+ json: {
2411
+ a: 23
2412
+ }
2413
+ },
2414
+ expectation: {
2415
+ id: globalEnv.entity_name,
2416
+ type: globalEnv.entity_type,
2417
+ a: {
2418
+ value: 23,
2419
+ type: 'Text',
2420
+ metadata: {
2421
+ TimeInstant: {
2422
+ value: _.isDateString,
2423
+ type: 'DateTime'
2424
+ }
2425
+ }
2426
+ },
2427
+ TimeInstant: {
2428
+ value: _.isDateString,
2429
+ type: 'DateTime'
2430
+ }
2431
+ }
2432
+ },
2433
+ {
2434
+ shouldName:
2435
+ 'A - WHEN sending a measure with timestamp through http IT should map the measure to timestamp attribute and use it for timestmap and other metadata attributes sent to Context Broker',
2436
+ type: 'single',
2437
+ measure: {
2438
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2439
+ method: 'POST',
2440
+ qs: {
2441
+ i: globalEnv.deviceId,
2442
+ k: globalEnv.apikey
2443
+ },
2444
+ json: {
2445
+ mydatetime: '2022-02-02T02:22:22.222Z',
2446
+ TimeInstant: '2033-03-03T03:33:33.333Z',
2447
+ a: 23
2448
+ }
2449
+ },
2450
+ expectation: {
2451
+ id: globalEnv.entity_name,
2452
+ type: globalEnv.entity_type,
2453
+ a: {
2454
+ value: 23,
2455
+ type: 'Text',
2456
+ metadata: {
2457
+ TimeInstant: {
2458
+ value: '2022-02-02T02:22:22.222Z',
2459
+ type: 'DateTime'
2460
+ }
2461
+ }
2462
+ },
2463
+ TimeInstant: {
2464
+ value: '2022-02-02T02:22:22.222Z',
2465
+ type: 'DateTime'
2466
+ }
2467
+ }
2468
+ }
2469
+ ]
2470
+ },
2471
+ {
2472
+ describeName: '0432 - Simple group with active attribute + bad timestamp mapping defined',
2473
+ provision: {
2474
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
2475
+ method: 'POST',
2476
+ json: {
2477
+ services: [
2478
+ {
2479
+ resource: '/iot/json',
2480
+ apikey: globalEnv.apikey,
2481
+ timestamp: true,
2482
+ entity_type: globalEnv.entity_type,
2483
+ commands: [],
2484
+ lazy: [],
2485
+ attributes: [
2486
+ {
2487
+ object_id: 'mydatetime',
2488
+ name: 'TimeInstant',
2489
+ type: 'DateTime',
2490
+ expression: '"2033-03-03T" + "03:33:33.333Z"'
2491
+ }
2492
+ ]
2493
+ }
2494
+ ]
2495
+ },
2496
+ headers: {
2497
+ 'fiware-service': globalEnv.service,
2498
+ 'fiware-servicepath': globalEnv.servicePath
2499
+ }
2500
+ },
2501
+ should: [
2502
+ {
2503
+ shouldName:
2504
+ 'A - WHEN sending a measure through http IT should map the measure to fixed timestamp attribute and use it for timestmap sent to Context Broker',
2505
+ type: 'single',
2506
+ measure: {
2507
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2508
+ method: 'POST',
2509
+ qs: {
2510
+ i: globalEnv.deviceId,
2511
+ k: globalEnv.apikey
2512
+ },
2513
+ json: {
2514
+ mydatetime: '2022-02-02T02:22:22.222Z',
2515
+ a: 23
2516
+ }
2517
+ },
2518
+ expectation: {
2519
+ id: globalEnv.entity_name,
2520
+ type: globalEnv.entity_type,
2521
+ a: {
2522
+ value: 23,
2523
+ type: 'Text',
2524
+ metadata: {
2525
+ TimeInstant: {
2526
+ value: '2033-03-03T03:33:33.333Z',
2527
+ type: 'DateTime'
2528
+ }
2529
+ }
2530
+ },
2531
+ TimeInstant: {
2532
+ value: '2033-03-03T03:33:33.333Z',
2533
+ type: 'DateTime'
2534
+ }
2535
+ }
2536
+ }
2537
+ ]
2538
+ },
2539
+ {
2540
+ describeName: '0433 - Simple group with active attribute + several timestamp mappings defined in multientity',
2541
+ provision: {
2542
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
2543
+ method: 'POST',
2544
+ json: {
2545
+ services: [
2546
+ {
2547
+ resource: '/iot/json',
2548
+ apikey: globalEnv.apikey,
2549
+ timestamp: true,
2550
+ entity_type: globalEnv.entity_type,
2551
+ commands: [],
2552
+ lazy: [],
2553
+ attributes: [
2554
+ {
2555
+ object_id: 'a',
2556
+ name: 'a',
2557
+ type: 'Text'
2558
+ },
2559
+ {
2560
+ object_id: 'mydatetime1',
2561
+ name: 'TimeInstant',
2562
+ type: 'DateTime',
2563
+ entity_name: 'TestType:TestDevice1',
2564
+ entity_type: 'TestType'
2565
+ },
2566
+ {
2567
+ object_id: 'mydatetime2',
2568
+ name: 'TimeInstant',
2569
+ type: 'DateTime',
2570
+ entity_name: 'TestType:TestDevice2',
2571
+ entity_type: 'TestType'
2572
+ },
2573
+ {
2574
+ object_id: 'a1',
2575
+ name: 'a1',
2576
+ type: 'Text',
2577
+ expression: 'a',
2578
+ entity_name: 'TestType:TestDevice1',
2579
+ entity_type: 'TestType'
2580
+ },
2581
+ {
2582
+ object_id: 'a2',
2583
+ name: 'a2',
2584
+ type: 'Text',
2585
+ expression: 'a',
2586
+ entity_name: 'TestType:TestDevice2',
2587
+ entity_type: 'TestType'
2588
+ }
2589
+ ]
2590
+ }
2591
+ ]
2592
+ },
2593
+ headers: {
2594
+ 'fiware-service': globalEnv.service,
2595
+ 'fiware-servicepath': globalEnv.servicePath
2596
+ }
2597
+ },
2598
+ should: [
2599
+ {
2600
+ shouldName:
2601
+ 'A - WHEN sending a measure through http IT should map the measure to timestamp attributes and use it for timestmap and other metadata attributes sent to Context Broker',
2602
+ type: 'multientity',
2603
+ isRegex: true,
2604
+ measure: {
2605
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2606
+ method: 'POST',
2607
+ qs: {
2608
+ i: globalEnv.deviceId,
2609
+ k: globalEnv.apikey
2610
+ },
2611
+ json: {
2612
+ a: 23,
2613
+ mydatetime1: '2011-01-01T01:11:11.111Z',
2614
+ mydatetime2: '2022-02-02T02:22:22.222Z'
2615
+ }
2616
+ },
2617
+ expectation: {
2618
+ actionType: 'append',
2619
+ entities: [
2620
+ {
2621
+ id: globalEnv.entity_name,
2622
+ type: globalEnv.entity_type,
2623
+ a: {
2624
+ value: 23,
2625
+ type: 'Text',
2626
+ metadata: {
2627
+ TimeInstant: {
2628
+ value: _.isDateString,
2629
+ type: 'DateTime'
2630
+ }
2631
+ }
2632
+ },
2633
+ TimeInstant: {
2634
+ value: _.isDateString,
2635
+ type: 'DateTime'
2636
+ }
2637
+ },
2638
+ {
2639
+ id: 'TestType:TestDevice1',
2640
+ type: globalEnv.entity_type,
2641
+ a1: {
2642
+ value: 23,
2643
+ type: 'Text',
2644
+ metadata: {
2645
+ TimeInstant: {
2646
+ value: '2011-01-01T01:11:11.111Z',
2647
+ type: 'DateTime'
2648
+ }
2649
+ }
2650
+ },
2651
+ TimeInstant: {
2652
+ value: '2011-01-01T01:11:11.111Z',
2653
+ type: 'DateTime'
2654
+ }
2655
+ },
2656
+ {
2657
+ id: 'TestType:TestDevice2',
2658
+ type: globalEnv.entity_type,
2659
+ a2: {
2660
+ value: 23,
2661
+ type: 'Text',
2662
+ metadata: {
2663
+ TimeInstant: {
2664
+ value: '2022-02-02T02:22:22.222Z',
2665
+ type: 'DateTime'
2666
+ }
2667
+ }
2668
+ },
2669
+ TimeInstant: {
2670
+ value: '2022-02-02T02:22:22.222Z',
2671
+ type: 'DateTime'
2672
+ }
2673
+ }
2674
+ ]
2675
+ }
2676
+ },
2677
+ {
2678
+ shouldName:
2679
+ 'A - WHEN sending a measure through http IT should map the measure to timestamp attributes for just mapped entity and sent to Context Broker',
2680
+ type: 'multientity',
2681
+ isRegex: true,
2682
+ measure: {
2683
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2684
+ method: 'POST',
2685
+ qs: {
2686
+ i: globalEnv.deviceId,
2687
+ k: globalEnv.apikey
2688
+ },
2689
+ json: {
2690
+ mydatetime1: '2011-01-01T01:11:11.111Z'
2691
+ }
2692
+ },
2693
+ expectation: {
2694
+ actionType: 'append',
2695
+ entities: [
2696
+ {
2697
+ id: 'TestType:TestDevice1',
2698
+ type: globalEnv.entity_type,
2699
+ TimeInstant: {
2700
+ value: '2011-01-01T01:11:11.111Z',
2701
+ type: 'DateTime'
2702
+ }
2703
+ }
2704
+ ]
2705
+ }
2706
+ }
2707
+ ]
2708
+ },
2709
+
2710
+ // 0500 - EXPLICIT ATTRIBUTES TESTS
2711
+ {
2712
+ describeName: '0500 - Group with explicit attrs:false (boolean) + active atributes',
2713
+ provision: {
2714
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
2715
+ method: 'POST',
2716
+ json: {
2717
+ services: [
2718
+ {
2719
+ resource: '/iot/json',
2720
+ apikey: globalEnv.apikey,
2721
+ entity_type: globalEnv.entity_type,
2722
+ explicitAttrs: false,
2723
+ commands: [],
2054
2724
  lazy: [],
2055
2725
  attributes: [
2056
2726
  {
@@ -2090,7 +2760,68 @@ const testCases = [
2090
2760
  type: globalEnv.entity_type,
2091
2761
  b: {
2092
2762
  value: 10,
2093
- type: 'string'
2763
+ type: 'Text'
2764
+ },
2765
+ attr_a: {
2766
+ value: 3,
2767
+ type: 'Number'
2768
+ }
2769
+ }
2770
+ }
2771
+ ]
2772
+ },
2773
+ {
2774
+ describeName: '0510 - Group without explicit (not defined) + active atributes',
2775
+ provision: {
2776
+ url: 'http://localhost:' + config.iota.server.port + '/iot/services',
2777
+ method: 'POST',
2778
+ json: {
2779
+ services: [
2780
+ {
2781
+ resource: '/iot/json',
2782
+ apikey: globalEnv.apikey,
2783
+ entity_type: globalEnv.entity_type,
2784
+ commands: [],
2785
+ lazy: [],
2786
+ attributes: [
2787
+ {
2788
+ object_id: 'a',
2789
+ name: 'attr_a',
2790
+ type: 'Number'
2791
+ }
2792
+ ],
2793
+ static_attributes: []
2794
+ }
2795
+ ]
2796
+ },
2797
+ headers: {
2798
+ 'fiware-service': globalEnv.service,
2799
+ 'fiware-servicepath': globalEnv.servicePath
2800
+ }
2801
+ },
2802
+ should: [
2803
+ {
2804
+ shouldName:
2805
+ 'A - WHEN sending both provisioned and not object_ids (measures) through http IT should store all attributes into Context Broker',
2806
+ type: 'single',
2807
+ measure: {
2808
+ url: 'http://localhost:' + config.http.port + '/iot/json',
2809
+ method: 'POST',
2810
+ qs: {
2811
+ i: globalEnv.deviceId,
2812
+ k: globalEnv.apikey
2813
+ },
2814
+ json: {
2815
+ a: 3,
2816
+ b: 10
2817
+ }
2818
+ },
2819
+ expectation: {
2820
+ id: globalEnv.entity_name,
2821
+ type: globalEnv.entity_type,
2822
+ b: {
2823
+ value: 10,
2824
+ type: 'Text'
2094
2825
  },
2095
2826
  attr_a: {
2096
2827
  value: 3,
@@ -2354,7 +3085,7 @@ const testCases = [
2354
3085
  },
2355
3086
  d: {
2356
3087
  value: 12,
2357
- type: 'string'
3088
+ type: 'Text'
2358
3089
  },
2359
3090
  static_a: {
2360
3091
  value: 3,