Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions test/unit/ngsiv2/mqttBinding-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ describe('MQTT Transport binding: measures', function () {
}, 100);
});
});

it('should send a new update context request to the Context Broker with just that attribute (without leading slash)', function (done) {
mqttClient.publish('ul/1234/MQTT_2/attrs/temperature', '23', null, function (error) {
setTimeout(function () {
contextBrokerMock.done();
done();
}, 100);
});
});
});

describe('When new multiple different format types measures arrives for a Device', function () {
Expand Down Expand Up @@ -131,6 +140,23 @@ describe('MQTT Transport binding: measures', function () {
}
);
});

it('should send a new update context request to the Context Broker with just this attribute (without leading slash)', function (done) {
mqttClient.publish(
'ul/1234/MQTT_2/attrs',
'luminosity|10|humidity|32|pollution|43.4|' +
'temperature|10|enabled|true|alive|null|tags' +
'|["iot","device"]|configuration|{"firmware":' +
'{"version":"1.1.0","hash":"cf23df2207d99a74fbe169e3eba035e633b65d94" } }',
null,
function (error) {
setTimeout(function () {
contextBrokerMock.done();
done();
}, 100);
}
);
});
});

describe('When a new measure arrives for an unprovisioned Device', function () {
Expand Down Expand Up @@ -177,6 +203,15 @@ describe('MQTT Transport binding: measures', function () {
}, 100);
});
});

it('should send a new update context request to the Context Broker with just that attribute (without leading slash)', function (done) {
mqttClient.publish('ul/80K09H324HV8732/UL_UNPROVISIONED/attrs/temperature', '23', null, function (error) {
setTimeout(function () {
contextBrokerUnprovMock.done();
done();
}, 100);
});
});
});

describe('When a new multiple measure arrives to a Device topic with one measure', function () {
Expand All @@ -200,6 +235,15 @@ describe('MQTT Transport binding: measures', function () {
}, 100);
});
});

it('should send a single update context request with all the attributes (without leading slash)', function (done) {
mqttClient.publish('ul/1234/MQTT_2/attrs', 'temperature|23', null, function (error) {
setTimeout(function () {
contextBrokerMock.done();
done();
}, 100);
});
});
});

describe('When a new multiple measure arrives to a Device topic with a faulty payload', function () {
Expand All @@ -210,6 +254,14 @@ describe('MQTT Transport binding: measures', function () {
}, 100);
});
});

it('should silently ignore the error (without crashing) (without leading slash)', function (done) {
mqttClient.publish('ul/1234/MQTT_2/attrs', 'notAULPayload ', null, function (error) {
setTimeout(function () {
done();
}, 100);
});
});
});

describe('When single message with multiple measures arrive to a Device topic', function () {
Expand All @@ -233,6 +285,15 @@ describe('MQTT Transport binding: measures', function () {
}, 100);
});
});

it('should send one update context per measure group to the Contet Broker (without leading slash)', function (done) {
mqttClient.publish('ul/1234/MQTT_2/attrs', 'temperature|23|humidity|98', null, function (error) {
setTimeout(function () {
contextBrokerMock.done();
done();
}, 100);
});
});
});

describe('When a message with multiple measure groups arrives to a Device topic', function () {
Expand Down Expand Up @@ -266,6 +327,15 @@ describe('MQTT Transport binding: measures', function () {
}, 100);
});
});

it('should send a two update context requests to the Context Broker one with each attribute (without leading slash)', function (done) {
mqttClient.publish('ul/1234/MQTT_2/attrs', 'temperature|23#humidity|98', null, function (error) {
setTimeout(function () {
contextBrokerMock.done();
done();
}, 100);
});
});
});

describe('When multiple groups of measures arrive, with multiple attributes, to a Device topic', function () {
Expand Down Expand Up @@ -304,6 +374,20 @@ describe('MQTT Transport binding: measures', function () {
}
);
});

it('should send a two update context requests to the Context Broker one with each attribute (without leading slash)', function (done) {
mqttClient.publish(
'ul/1234/MQTT_2/attrs',
'temperature|23|humidity|98#temperature|16|humidity|34',
null,
function (error) {
setTimeout(function () {
contextBrokerMock.done();
done();
}, 100);
}
);
});
});

describe('When a measure with a timestamp arrives with an alias to TimeInstant', function () {
Expand Down Expand Up @@ -363,5 +447,19 @@ describe('MQTT Transport binding: measures', function () {
}
);
});

it('should use the provided TimeInstant as the general timestamp for the measures (without leading slash)', function (done) {
mqttClient.publish(
'ul/1234/timestampedDevice/attrs',
'tmp|24.4|tt|2016-09-26T12:19:26.476659Z',
null,
function (error) {
setTimeout(function () {
contextBrokerMock.done();
done();
}, 100);
}
);
});
});
});