Skip to content

Commit

Permalink
Merge pull request #1484 from telefonicaid/task/add_test_entity_name_…
Browse files Browse the repository at this point in the history
…id_number

add tests with entityNameExp with id number
  • Loading branch information
fgalan authored Oct 6, 2023
2 parents 5562c90 + 76b701e commit 7899b00
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
14 changes: 7 additions & 7 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ information coming from the device (measures) is mapped to the Context Broker at
All of them have the same syntax, a list of objects with the following attributes:

- **object_id** (optional): name of the attribute as coming from the device.
- **name** (mandatory): ID of the attribute in the target entity in the Context Broker. Note that `id` and `type`
are not valid attribute names at Context Broker. Thus, although a measure named `id` or `type` will not break the IoT Agent, they
are silently ignored and never progress toward Context Broker entities.
- **name** (mandatory): ID of the attribute in the target entity in the Context Broker. Note that `id` and `type` are
not valid attribute names at Context Broker. Thus, although a measure named `id` or `type` will not break the IoT
Agent, they are silently ignored and never progress toward Context Broker entities.
- **type** (mandatory): name of the type of the attribute in the target entity.
- **metadata** (optional): additional static metadata for the attribute in the target entity. (e.g. `unitCode`)

Expand Down Expand Up @@ -211,10 +211,10 @@ Additionally for commands (which are attributes of type `command`) the following
particular IOTAs documentation for allowed values of this field in each case.
- **contentType**: `content-type` header used when send command by HTTP transport (ignored in other kinds of
transports)
Note that, when information coming from devices, this means measures, are not defined neither in the group, nor in the
device, the IoT agent will store that information into the destination entity using the same attribute name than the
measure name, unless `explicitAttrs` is defined. Measures `id` or `type` names are invalid, and will be ignored.

Note that, when information coming from devices, this means measures, are not defined neither in the group, nor in the
device, the IoT agent will store that information into the destination entity using the same attribute name than the
measure name, unless `explicitAttrs` is defined. Measures `id` or `type` names are invalid, and will be ignored.

## Multientity support

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "1234",
"type": "WeatherStation",
"pressure": {
"value": 1040,
"type": "Number"
}
}
55 changes: 55 additions & 0 deletions test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ const iotAgentConfig = {
}
]
},
WeatherStationWithIdNumber: {
commands: [],
type: 'WeatherStation',
entityNameExp: 'id',
lazy: [],
active: [
{
object_id: 'p',
name: 'pressure',
type: 'Number',
expression: 'pressure * 20'
}
]
},
WeatherStationUndef: {
commands: [],
type: 'WeatherStation',
Expand Down Expand Up @@ -1625,6 +1639,47 @@ describe('Java expression language (JEXL) based transformations plugin', functio
});
});

describe('When a measure arrives with id number', function () {
const values = [
{
name: 'p',
type: 'centigrades',
value: '52'
}
];
const typeInformation = {
service: 'smartgondor',
subservice: 'gardens',
name: '1234',
id: '1234',
type: 'WeatherStation',
active: [{ object_id: 'p', name: 'pressure', type: 'Number', expression: 'pressure * 20' }]
};

beforeEach(function () {
nock.cleanAll();

contextBrokerMock = nock('http://192.168.1.1:1026')
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', 'gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile(
'./test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29b.json'
)
)
.reply(204);
});

it('should calculate the expression', function (done) {
iotAgentLib.update(1234, 'WeatherStationWithIdNumber', '', values, typeInformation, function (error) {
should.not.exist(error);
contextBrokerMock.done();
done();
});
});
});

describe('When a measure arrives and there is not enough information to calculate an expression', function () {
const values = [
{
Expand Down
3 changes: 0 additions & 3 deletions test/unit/ngsiv2/ngsiService/active-devices-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,6 @@ describe('NGSI-v2 - Active attributes test', function () {
];

beforeEach(function (done) {

nock.cleanAll();

contextBrokerMock = nock('http://192.168.1.1:1026')
Expand Down Expand Up @@ -970,7 +969,6 @@ describe('NGSI-v2 - Active attributes test', function () {
];

beforeEach(function (done) {

nock.cleanAll();

contextBrokerMock = nock('http://192.168.1.1:1026')
Expand Down Expand Up @@ -1018,7 +1016,6 @@ describe('NGSI-v2 - Active attributes test', function () {
];

beforeEach(function (done) {

nock.cleanAll();

contextBrokerMock = nock('http://192.168.1.1:1026')
Expand Down

0 comments on commit 7899b00

Please sign in to comment.