Skip to content

Commit

Permalink
Merge pull request #1618 from telefonicaid/task/add-533-func_avg2
Browse files Browse the repository at this point in the history
Add TimeInstant + explicitAttr tests (func test 533)
  • Loading branch information
mrutid authored Jun 6, 2024
2 parents 3e3842a + ea2979d commit 52a524f
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix: do not propage TimeInstant when explicitAttrs is empty array (#1606)
- Fix: update device using previous device apikey to avoid error when apikey is updated (iota-json#833)
- Fix: allow send multiple measures to CB in a batch (POST /v2/op/update) and sorted by TimeInstant when possible, instead of using multiples single request (iotagent-json#825, #1612)
- Fix: default express limit to 1Mb instead default 100Kb and allow change it throught a conf env var 'IOTA_EXPRESS_LIMIT' (iotagent-json#827)
Expand Down
2 changes: 2 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ mappings of the provision. If `explicitAttrs` is provided both at device and con
precedence. Additionally `explicitAttrs` can be used to define which measures (identified by their attribute names, not
by their object_id) defined in JSON/JEXL array will be propagated to NGSI interface.

Note that when `explicitAttrs` is an array or a JEXL expression resulting in to Array, if this array is empty then `TimeInstant` is not propaged to CB.

The different possibilities are summarized below:

Case 1 (default):
Expand Down
2 changes: 1 addition & 1 deletion lib/services/ngsi/entities-NGSI-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation,
if (typeof typeInformation.explicitAttrs === 'string') {
try {
explicit = jexlParser.applyExpression(typeInformation.explicitAttrs, jexlctxt, typeInformation);
if (explicit instanceof Array && mustInsertTimeInstant) {
if (explicit instanceof Array && explicit.length > 0 && mustInsertTimeInstant) {
explicit.push(constants.TIMESTAMP_ATTRIBUTE);
}
logger.debug(
Expand Down
202 changes: 202 additions & 0 deletions test/functional/testCases.js
Original file line number Diff line number Diff line change
Expand Up @@ -3519,6 +3519,208 @@ const testCases = [
}
]
},
{
describeName:
'0533 - Group with explicit attrs:[ ] (empty array) + active attributes + TimeInstant attribute + static attributes + timestamp:true',
provision: {
url: 'http://localhost:' + config.iota.server.port + '/iot/services',
method: 'POST',
json: {
services: [
{
resource: '/iot/json',
apikey: globalEnv.apikey,
entity_type: globalEnv.entity_type,
explicitAttrs: '[ ]',
timestamp: true,
commands: [],
lazy: [],
attributes: [
{
name: 'attr_a',
object_id: 'a',
type: 'Number'
},
{
name: 'attr_b',
object_id: 'b',
type: 'Number'
},
{
name: 'DateIssued',
object_id: 'TimeInstant',
type: 'DateTime'
},
{
name: 'TimeInstant',
object_id: 't',
type: 'DateTime'
}
],
static_attributes: [
{
name: 'static_a',
type: 'Number',
value: 3
},
{
name: 'static_b',
type: 'Number',
value: 4
}
]
}
]
},
headers: {
'fiware-service': globalEnv.service,
'fiware-servicepath': globalEnv.servicePath
}
},
should: [
{
shouldName:
'A - WHEN sending data and a measure called "t" (defined as TimeInstant attribte) through http IT should NOT store anything into the Context Broker (No request to CB)',
type: 'single',
measure: {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
qs: {
i: globalEnv.deviceId,
k: globalEnv.apikey
},
json: {
a: 3,
b: 10,
c: 11,
t: '2015-12-14T08:06:01.468Z'
}
},
expectation: []
},
{
shouldName:
'B - WHEN sending data and a measure called TimeInstant through http IT should NOT store anything into the Context Broker (No request to CB)',
type: 'single',
measure: {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
qs: {
i: globalEnv.deviceId,
k: globalEnv.apikey
},
json: {
a: 3,
b: 10,
c: 11,
TimeInstant: '2015-12-14T08:06:01.468Z'
}
},
expectation: [] // No payload expected
}
]
},
{
describeName:
'0534 - Group with explicit attrs:[ ] (empty array) + active attributes + TimeInstant attribute + static attributes + timestamp:false',
provision: {
url: 'http://localhost:' + config.iota.server.port + '/iot/services',
method: 'POST',
json: {
services: [
{
resource: '/iot/json',
apikey: globalEnv.apikey,
entity_type: globalEnv.entity_type,
explicitAttrs: '[ ]',
timestamp: false,
commands: [],
lazy: [],
attributes: [
{
name: 'attr_a',
object_id: 'a',
type: 'Number'
},
{
name: 'attr_b',
object_id: 'b',
type: 'Number'
},
{
name: 'DateIssued',
object_id: 'TimeInstant',
type: 'DateTime'
},
{
name: 'TimeInstant',
object_id: 't',
type: 'DateTime'
}
],
static_attributes: [
{
name: 'static_a',
type: 'Number',
value: 3
},
{
name: 'static_b',
type: 'Number',
value: 4
}
]
}
]
},
headers: {
'fiware-service': globalEnv.service,
'fiware-servicepath': globalEnv.servicePath
}
},
should: [
{
shouldName:
'A - WHEN sending data and a measure called "t" (defined as TimeInstant attribte) through http IT should NOT store anything into the Context Broker (No request to CB)',
type: 'single',
measure: {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
qs: {
i: globalEnv.deviceId,
k: globalEnv.apikey
},
json: {
a: 3,
b: 10,
c: 11,
t: '2015-12-14T08:06:01.468Z'
}
},
expectation: []
},
{
shouldName:
'B - WHEN sending data and a measure called TimeInstant through http IT should NOT store anything into the Context Broker (No request to CB)',
type: 'single',
measure: {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
qs: {
i: globalEnv.deviceId,
k: globalEnv.apikey
},
json: {
a: 3,
b: 10,
c: 11,
TimeInstant: '2015-12-14T08:06:01.468Z'
}
},
expectation: [] // No payload expected
}
]
},
{
describeName:
'0540 - Group with explicit attrs: JEXL expression based on measure resulting boolean + active attributes + static attributes',
Expand Down

0 comments on commit 52a524f

Please sign in to comment.