Skip to content

Commit

Permalink
Don't restict options to just attach for attachSenderLink and attachR…
Browse files Browse the repository at this point in the history
…eceiverLink.
  • Loading branch information
anthonyvercolano committed Feb 25, 2017
1 parent 7645aef commit 893defa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions common/transport/amqp/devdoc/amqp_requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ Configures an AmqpReceiver object to use the endpoint passed as a parameter and
**SRS_NODE_COMMON_AMQP_16_012: [** The `attachSenderLink` method shall throw a ReferenceError if the `endpoint` argument is falsy. **]**
**SRS_NODE_COMMON_AMQP_16_032: [** The `attachSenderLink` method shall call the `done` callback with a `NotConnectedError` object if the amqp client is not connected when the method is called. **]**
**SRS_NODE_COMMON_AMQP_16_013: [** The `attachSenderLink` method shall call `createSender` on the `amqp10` client object. **]**
**SRS_NODE_COMMON_AMQP_16_014: [** The `attachSenderLink` method shall create a policy object that contain link properties to be merged is the properties argument is not falsy. **]**
**SRS_NODE_COMMON_AMQP_06_003: [** The `attachSenderLink` method shall create a policy object that contain link options to be merged if the linkOptions argument is not falsy. **]**
**SRS_NODE_COMMON_AMQP_16_015: [** The `attachSenderLink` method shall call the `done` callback with a `null` error and the link object that was created if the link was attached successfully. **]**
**SRS_NODE_COMMON_AMQP_16_016: [** The `attachSenderLink` method shall call the `done` callback with an `Error` object if the link object wasn't created successfully. **]**

### attachReceiverLink(endpoint, properties, done)
**SRS_NODE_COMMON_AMQP_16_017: [** The `attachReceiverLink` method shall throw a ReferenceError if the `endpoint` argument is falsy. **]**
**SRS_NODE_COMMON_AMQP_16_033: [** The `attachReceiverLink` method shall call the `done` callback with a `NotConnectedError` object if the amqp client is not connected when the method is called. **]**
**SRS_NODE_COMMON_AMQP_16_018: [** The `attachReceiverLink` method shall call `createReceiver` on the `amqp10` client object. **]**
**SRS_NODE_COMMON_AMQP_16_019: [** The `attachReceiverLink` method shall create a policy object that contain link properties to be merged is the properties argument is not falsy. **]**
**SRS_NODE_COMMON_AMQP_06_004: [** The `attachReceiverLink` method shall create a policy object that contain link options to be merged if the linkOptions argument is not falsy. **]**
**SRS_NODE_COMMON_AMQP_16_020: [** The `attachReceiverLink` method shall call the `done` callback with a `null` error and the link object that was created if the link was attached successfully. **]**
**SRS_NODE_COMMON_AMQP_16_021: [** The `attachReceiverLink` method shall call the `done` callback with an `Error` object if the link object wasn't created successfully. **]**

Expand Down
30 changes: 14 additions & 16 deletions common/transport/amqp/lib/amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function safeCallback(callback, error, result) {
* @method module:azure-iot-amqp-base.Amqp#connect
* @description Establishes a connection with the IoT Hub instance.
* @param uri The uri to connect with.
* @param {Function} done Called when the connection is established of if an error happened.
* @param {Function} done Called when the connection is established or if an error happened.
*/
Amqp.prototype.connect = function connect(uri, sslOptions, done) {
/*Codes_SRS_NODE_COMMON_AMQP_06_002: [The connect method shall throw a ReferenceError if the uri parameter has not been supplied.] */
Expand Down Expand Up @@ -228,11 +228,11 @@ Amqp.prototype.getReceiver = function getReceiver(endpoint, done) {
* @method module:azure-iot-amqp-base.Amqp#attachReceiverLink
* @description Creates and attaches an AMQP receiver link for the specified endpoint.
*
* @param {string} endpoint Endpoint used for the receiver link.
* @param {Object} linkProperties Dictionnary of key/value pairs that are going to be inserted as properties in the 'attach' AMQP frame.
* @param {Function} done Callback used to return the link object or an Error.
* @param {string} endpoint Endpoint used for the receiver link.
* @param {Object} linkOptions Configuration options to be merged with the AMQP10 policies for the link..
* @param {Function} done Callback used to return the link object or an Error.
*/
Amqp.prototype.attachReceiverLink = function attachReceiverLink(endpoint, linkProperties, done) {
Amqp.prototype.attachReceiverLink = function attachReceiverLink(endpoint, linkOptions, done) {
/*Codes_SRS_NODE_COMMON_AMQP_16_017: [The `attachReceiverLink` method shall throw a ReferenceError if the `endpoint` argument is falsy.]*/
if (!endpoint) {
throw new ReferenceError('endpoint cannot be \'' + endpoint + '\'');
Expand All @@ -250,10 +250,9 @@ Amqp.prototype.attachReceiverLink = function attachReceiverLink(endpoint, linkPr
/*Codes_SRS_NODE_COMMON_AMQP_16_007: [If send encounters an error before it can send the request, it shall invoke the done callback function and pass the standard JavaScript Error object with a text description of the error (err.message).]*/
this._amqp.on('client:errorReceived', clientErrorHandler);

/*Codes_SRS_NODE_COMMON_AMQP_16_019: [The `attachReceiverLink` method shall create a policy object that contain link properties to be merged is the properties argument is not falsy.]*/
var attachProps = linkProperties ? { attach: { properties: linkProperties } }: undefined;
/*Codes_SRS_NODE_COMMON_AMQP_06_004: [The `attachReceiverLink` method shall create a policy object that contain link options to be merged if the linkOptions argument is not falsy.]*/
/*Codes_SRS_NODE_COMMON_AMQP_16_018: [The `attachReceiverLink` method shall call `createReceiver` on the `amqp10` client object.]*/
self._amqp.createReceiver(endpoint, attachProps)
self._amqp.createReceiver(endpoint, linkOptions)
.then(function (receiver) {
self._amqp.removeListener('client:errorReceived', clientErrorHandler);
if (!connectionError) {
Expand Down Expand Up @@ -281,11 +280,11 @@ Amqp.prototype.attachReceiverLink = function attachReceiverLink(endpoint, linkPr
* @method module:azure-iot-amqp-base.Amqp#attachSenderLink
* @description Creates and attaches an AMQP sender link for the specified endpoint.
*
* @param {string} endpoint Endpoint used for the sender link.
* @param {Object} linkProperties Dictionnary of key/value pairs that are going to be inserted as properties in the 'attach' AMQP frame.
* @param {Function} done Callback used to return the link object or an Error.
* @param {string} endpoint Endpoint used for the sender link.
* @param {Object} linkOptions Configuration options to be merged with the AMQP10 policies for the link..
* @param {Function} done Callback used to return the link object or an Error.
*/
Amqp.prototype.attachSenderLink = function attachSenderLink(endpoint, linkProperties, done) {
Amqp.prototype.attachSenderLink = function attachSenderLink(endpoint, linkOptions, done) {
/*Codes_SRS_NODE_COMMON_AMQP_16_012: [The `attachSenderLink` method shall throw a ReferenceError if the `endpoint` argument is falsy.]*/
if (!endpoint) {
throw new ReferenceError('endpoint cannot be \'' + endpoint + '\'');
Expand All @@ -303,10 +302,9 @@ Amqp.prototype.attachSenderLink = function attachSenderLink(endpoint, linkProper
/*Codes_SRS_NODE_COMMON_AMQP_16_007: [If send encounters an error before it can send the request, it shall invoke the done callback function and pass the standard JavaScript Error object with a text description of the error (err.message).]*/
this._amqp.on('client:errorReceived', clientErrorHandler);

/*Codes_SRS_NODE_COMMON_AMQP_16_014: [The `attachSenderLink` method shall create a policy object that contain link properties to be merged is the properties argument is not falsy.]*/
var attachProps = linkProperties ? { attach: { properties: linkProperties } }: undefined;
/*Codes_SRS_NODE_COMMON_AMQP_06_003: [The `attachSenderLink` method shall create a policy object that contain link options to be merged if the linkOptions argument is not falsy.]*/
/*Codes_SRS_NODE_COMMON_AMQP_16_013: [The `attachSenderLink` method shall call `createSender` on the `amqp10` client object.]*/
self._amqp.createSender(endpoint, attachProps)
self._amqp.createSender(endpoint, linkOptions)
.then(function (sender) {
self._amqp.removeListener('client:errorReceived', clientErrorHandler);
if (!connectionError) {
Expand All @@ -318,7 +316,7 @@ Amqp.prototype.attachSenderLink = function attachSenderLink(endpoint, linkProper
/*Codes_SRS_NODE_COMMON_AMQP_16_016: [The `attachSenderLink` method shall call the `done` callback with an `Error` object if the link object wasn't created successfully.]*/
safeCallback(done, connectionError);
}

return null;
})
.catch(function (err) {
Expand Down
2 changes: 1 addition & 1 deletion common/transport/amqp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"alltest": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec test/_*_test*.js",
"ci": "npm -s run lint && npm -s run alltest-min && npm -s run check-cover",
"test": "npm -s run lint && npm -s run unittest",
"check-cover": "istanbul check-coverage --statements 95 --branches 83 --functions 92 --lines 94"
"check-cover": "istanbul check-coverage --statements 94 --branches 83 --functions 92 --lines 94"
},
"engines": {
"node": ">= 0.10"
Expand Down
22 changes: 11 additions & 11 deletions common/transport/amqp/test/_amqp_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('Amqp', function () {
var amqp = new Amqp();
var sender = new EventEmitter();
sender.send = sinon.stub().resolves('message enqueued');

sinon.stub(amqp._amqp, 'connect').resolves('connected');
sinon.stub(amqp._amqp, 'createSender').resolves(sender);

Expand All @@ -141,7 +141,7 @@ describe('Amqp', function () {
assert.instanceOf(result, results.MessageEnqueued);
}
testCallback(err);

});
});
});
Expand All @@ -151,7 +151,7 @@ describe('Amqp', function () {
var amqp = new Amqp();
var sender = new EventEmitter();
sender.send = sinon.stub().resolves('message enqueued');

sinon.stub(amqp._amqp, 'connect').resolves('connected');
sinon.stub(amqp._amqp, 'createSender').rejects('failed to create sender');

Expand All @@ -167,7 +167,7 @@ describe('Amqp', function () {
var amqp = new Amqp();
var sender = new EventEmitter();
sender.send = sinon.stub().rejects('could not send');

sinon.stub(amqp._amqp, 'connect').resolves('connected');
sinon.stub(amqp._amqp, 'createSender').resolves(sender);

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('Amqp', function () {
var amqp = new Amqp();
var sender = new EventEmitter();
sender.send = sinon.stub().resolves('message enqueued');

sinon.stub(amqp._amqp, 'connect').resolves('connected');
sinon.stub(amqp._amqp, 'createSender').resolves(sender);

Expand All @@ -222,7 +222,7 @@ describe('Amqp', function () {
var amqp = new Amqp();
var sender = new EventEmitter();
sender.send = sinon.stub().resolves('message enqueued');

sinon.stub(amqp._amqp, 'connect').resolves('connected');
sinon.stub(amqp._amqp, 'createSender').resolves(sender);

Expand All @@ -237,7 +237,7 @@ describe('Amqp', function () {
var amqp = new Amqp();
var sender = new EventEmitter();
sender.send = sinon.stub().rejects('failed to enqueue message');

sinon.stub(amqp._amqp, 'connect').resolves('connected');
sinon.stub(amqp._amqp, 'createSender').resolves(sender);

Expand Down Expand Up @@ -340,16 +340,16 @@ describe('Amqp', function () {
amqp.connect('uri', null, function() {
amqp[testConfig.amqpFunc](endpoint, null, function(err, result) {
assert.isNull(err);
assert.isUndefined(amqp._amqp[testConfig.amqp10Func].args[0][1]);
assert.isNotTrue(amqp._amqp[testConfig.amqp10Func].args[0][1]);
assert.isOk(result);
assert.strictEqual(result, amqp[testConfig.privateLinkArray][endpoint]);
testCallback();
});
});
});

/*Tests_SRS_NODE_COMMON_AMQP_16_014: [The `attachSenderLink` method shall create a policy object that contain link properties to be merged is the properties argument is not falsy.]*/
/*Tests_SRS_NODE_COMMON_AMQP_16_019: [The `attachReceiverLink` method shall create a policy object that contain link properties to be merged is the properties argument is not falsy.]*/
/*Tests_SRS_NODE_COMMON_AMQP_06_003: [The `attachSenderLink` method shall create a policy object that contain link options to be merged if the linkOptions argument is not falsy.]*/
/*Tests_SRS_NODE_COMMON_AMQP_06_004: [The `attachReceiverLink` method shall create a policy object that contain link options to be merged if the linkOptions argument is not falsy.]*/
it('sets up the attach properties object with the link properties passed as argument', function(testCallback) {
var amqp = new Amqp();
var endpoint = 'endpoint';
Expand All @@ -363,7 +363,7 @@ describe('Amqp', function () {
/*Tests_SRS_NODE_COMMON_AMQP_16_015: [The `attachSenderLink` method shall call the `done` callback with a `null` error and the link object that was created if the link was attached successfully.]*/
/*Tests_SRS_NODE_COMMON_AMQP_16_020: [The `attachReceiverLink` method shall call the `done` callback with a `null` error and the link object that was created if the link was attached successfully.]*/
amqp[testConfig.amqpFunc](endpoint, fakeLinkProps, function() {
assert.deepEqual(amqp._amqp[testConfig.amqp10Func].args[0][1], { attach: { properties: fakeLinkProps }});
assert.deepEqual(amqp._amqp[testConfig.amqp10Func].args[0][1], { fakeKey: 'fakeValue'});
testCallback();
});
});
Expand Down

0 comments on commit 893defa

Please sign in to comment.