"should parse correctly" : function(test) { var parsedUri = ringutil.parseUri('p2p:myapp/documents/xyz'); test.strictEqual('p2p', parsedUri.scheme); test.strictEqual('myapp', parsedUri.app_name); test.strictEqual('/documents/xyz', parsedUri.resource); test.strictEqual('A097B13EA2C82D0C2C09DE186E048D1EFF2537D2', parsedUri.hash); test.done(); }
"be able to send a message to a uri mapping to the current node" : function(test) { var destId = ringutil.parseUri(this.uri).hash; this.nextHop.id = this.transport.nodeId; this.transport.send(this.uri, this.content, {method : 'POST'}); test.ok(!this.sendMessage.called); test.ok(!this.appForwarding.called); test.strictEqual(this.appReceived.args[0][0].uri, this.uri); test.strictEqual(this.appReceived.args[0][0].dest_id, destId); test.strictEqual(this.appReceived.args[0][0].method, 'POST'); test.strictEqual(this.appReceived.args[0][0].source_id, 'ABCD'); test.deepEqual(this.appReceived.args[0][0].content, this.content); test.deepEqual(this.appReceived.args[0][1], { app_name : 'myapp' }); test.done(); },
"be able to send a message to a uri mapping to a remote node" : function(test) { var destId = ringutil.parseUri(this.uri).hash; this.transport.send(this.uri, this.content, {method : 'POST'}); test.strictEqual(this.sendMessage.args[0][0], 5555); test.strictEqual(this.sendMessage.args[0][1], '5.5.5.5'); test.strictEqual(this.sendMessage.args[0][2].uri, this.uri); test.strictEqual(this.sendMessage.args[0][2].dest_id, destId); test.strictEqual(this.sendMessage.args[0][2].method, 'POST'); test.deepEqual(this.sendMessage.args[0][2].content, this.content); test.deepEqual(this.appForwarding.args[0][0], this.sendMessage.args[0][2]); test.deepEqual(this.appForwarding.args[0][1], this.msginfo); test.ok(!this.appReceived.called); test.done(); },
assert.throws(function() {ringutil.parseUri('p2p:/myresource');}, /id/);
assert.throws(function() {ringutil.parseUri('p2p:abcdef-noresource');}, /resource/);
assert.throws(function() { ringutil.parseUri('bogus:abcdef/myresource'); }, /uri scheme/);