Repository: qpid-dispatch Updated Branches: refs/heads/master f6a0ecf02 -> db6ed6b15
DISPATCH-1204 Added console tests for edge routers Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/db6ed6b1 Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/db6ed6b1 Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/db6ed6b1 Branch: refs/heads/master Commit: db6ed6b15cc3c2a658cb37ab8f2122a8cb806db5 Parents: f6a0ecf Author: Ernest Allen <[email protected]> Authored: Mon Dec 3 13:41:54 2018 -0500 Committer: Ernest Allen <[email protected]> Committed: Mon Dec 3 13:41:54 2018 -0500 ---------------------------------------------------------------------- .../plugin/js/topology/qdrTopology.js | 1 + console/stand-alone/test/links.js | 33 +- console/stand-alone/test/nodes-edge.json | 1156 ++++++++++++++++++ console/stand-alone/test/utilities.js | 108 +- 4 files changed, 1237 insertions(+), 61 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/db6ed6b1/console/stand-alone/plugin/js/topology/qdrTopology.js ---------------------------------------------------------------------- diff --git a/console/stand-alone/plugin/js/topology/qdrTopology.js b/console/stand-alone/plugin/js/topology/qdrTopology.js index b20e69e..68b3797 100644 --- a/console/stand-alone/plugin/js/topology/qdrTopology.js +++ b/console/stand-alone/plugin/js/topology/qdrTopology.js @@ -406,6 +406,7 @@ export class TopologyController { force: true}], function () { let nodeInfo = QDRService.management.topology.nodeInfo(); + console.log(nodeInfo); forceData.nodes = nodes = new Nodes(QDRLog); nodes.initialize(nodeInfo, localStorage, width, height); forceData.links = links = new Links(QDRLog); http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/db6ed6b1/console/stand-alone/test/links.js ---------------------------------------------------------------------- diff --git a/console/stand-alone/test/links.js b/console/stand-alone/test/links.js index c3aad88..ef8ea44 100644 --- a/console/stand-alone/test/links.js +++ b/console/stand-alone/test/links.js @@ -22,24 +22,25 @@ var fs = require('fs'); var expect = require('chai').expect; import { Links } from '../plugin/js/topology/links.js'; import { Nodes } from '../plugin/js/topology/nodes.js'; -import { QDRService } from '../plugin/js/qdrService.js'; class Log { constructor() { } log (msg) {console.log(msg);} - debug (msg) {console.log(msg);} - error (msg) {console.log(msg);} - info (msg) {console.log(msg);} - warn (msg) {console.log(msg);} + debug (msg) {console.log(`Debug: ${msg}`);} + error (msg) {console.log(`Error: ${msg}`);} + info (msg) {console.log(`Info: ${msg}`);} + warn (msg) {console.log(`Warning: ${msg}`);} } var log = new Log(); var loc = {protocol: function () { return 'http://';}}; var timeout = {}; -var qdrService = new QDRService(log, timeout, loc); -var links = new Links(qdrService, log); -var nodes = new Nodes(qdrService, log); +var links = new Links(log); +var edgeLinks = new Links(log); +var nodes = new Nodes(log); +var edgeNodes = new Nodes(log); var nodeInfo; +var edgeInfo; var unknowns = []; const width = 1024; const height = 768; @@ -55,10 +56,13 @@ before(function(done){ src = PARAM_VALUE; } - console.log('src: ', src); fs.readFile(src + './test/nodes.json', 'utf8', function(err, fileContents) { if (err) throw err; nodeInfo = JSON.parse(fileContents); + }); + fs.readFile(src + './test/nodes-edge.json', 'utf8', function(err, fileContents) { + if (err) throw err; + edgeInfo = JSON.parse(fileContents); done(); }); }); @@ -74,6 +78,10 @@ describe('Nodes', function() { nodes.initialize(nodeInfo, {}, width, height); assert.equal(nodes.nodes.length, 6); }); + it('should initialize edge nodes', function() { + edgeNodes.initialize(edgeInfo, {}, width, height); + assert.equal(edgeNodes.nodes.length, 2); + }); }); }); @@ -88,6 +96,13 @@ describe('Links', function() { links.initialize(nodeInfo, nodes, unknowns, {}, width); assert.equal(links.links.length, 10); }); + it('should initialize edge links', function() { + edgeLinks.initialize(edgeInfo, edgeNodes, unknowns, {}, width); + assert.equal(edgeLinks.links.length, 6); + }); + it('should add nodes for edge router groups', function() { + assert.equal(edgeNodes.nodes.length, 6); + }); }); }); http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/db6ed6b1/console/stand-alone/test/nodes-edge.json ---------------------------------------------------------------------- diff --git a/console/stand-alone/test/nodes-edge.json b/console/stand-alone/test/nodes-edge.json new file mode 100644 index 0000000..6fb6d31 --- /dev/null +++ b/console/stand-alone/test/nodes-edge.json @@ -0,0 +1,1156 @@ +{ + "amqp:/_topo/0/INT.A/$management": { + "connection": { + "attributeNames": [ + "name", + "identity", + "host", + "role", + "dir", + "container", + "sasl", + "isAuthenticated", + "user", + "isEncrypted", + "sslProto", + "sslCipher", + "properties", + "sslSsf", + "tenant", + "type", + "ssl", + "opened", + "active" + ], + "results": [ + [ + "connection/127.0.0.1:52392", + "4", + "127.0.0.1:52392", + "edge", + "in", + "EDGE-3.0", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:45762", + "134", + "127.0.0.1:45762", + "edge", + "in", + "EDGE-4.0", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:38384", + "187", + "127.0.0.1:38384", + "edge", + "in", + "EDGE-13.2", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:38404", + "192", + "127.0.0.1:38404", + "edge", + "in", + "EDGE-13.7", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:38420", + "194", + "127.0.0.1:38420", + "edge", + "in", + "EDGE-13.9", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:52104", + "506", + "127.0.0.1:52104", + "inter-router", + "in", + "Interior Router B", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:52138", + "533", + "127.0.0.1:52138", + "edge", + "in", + "EDGE-8.0", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:52140", + "534", + "127.0.0.1:52140", + "edge", + "in", + "EDGE-8.1", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1", + "538", + "127.0.0.1", + "normal", + "in", + "111ea22b-e14b-db47-bcf9-5a747beb4d26", + null, + false, + "anonymous", + false, + null, + null, + { + "console_identifier": "Dispatch console" + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ] + ], + "timestamp": "2018-12-03T17:54:29.989Z" + }, + "router.node": { + "results": [ + [ + "INT.A", + "(self)" + ], + [ + "Interior Router B", + null + ] + ], + "attributeNames": [ + "id", + "nextHop" + ], + "timestamp": "2018-12-03T17:54:29.987Z" + }, + "router.link": { + "attributeNames": [ + "linkType", + "connectionId", + "linkDir", + "owningAddr" + ], + "results": [ + [ + "endpoint", + "4", + "in", + null + ], + [ + "edge-downlink", + "4", + "out", + "HEDGE-3.0" + ], + [ + "endpoint", + "4", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "4", + "in", + "M0$management" + ], + [ + "endpoint", + "4", + "out", + "Ltemp.7acuL0visoOXABp" + ], + [ + "endpoint", + "134", + "in", + null + ], + [ + "edge-downlink", + "134", + "out", + "HEDGE-4.0" + ], + [ + "endpoint", + "134", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "134", + "in", + "M0$management" + ], + [ + "endpoint", + "134", + "out", + "Ltemp.Hnh+MyiiosvTRBK" + ], + [ + "endpoint", + "4", + "in", + "M0to60" + ], + [ + "endpoint", + "187", + "in", + null + ], + [ + "edge-downlink", + "187", + "out", + "HEDGE-13.2" + ], + [ + "endpoint", + "187", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "187", + "in", + "M0$management" + ], + [ + "endpoint", + "187", + "out", + "Ltemp.luHTmRfBYvfmhcR" + ], + [ + "endpoint", + "192", + "in", + null + ], + [ + "edge-downlink", + "192", + "out", + "HEDGE-13.7" + ], + [ + "endpoint", + "192", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "192", + "in", + "M0$management" + ], + [ + "endpoint", + "192", + "out", + "Ltemp.c3j7PMiCRFT_T3P" + ], + [ + "endpoint", + "194", + "in", + null + ], + [ + "edge-downlink", + "194", + "out", + "HEDGE-13.9" + ], + [ + "endpoint", + "194", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "194", + "in", + "M0$management" + ], + [ + "endpoint", + "194", + "out", + "Ltemp.xxbXf7d+Bd5xfvs" + ], + [ + "router-control", + "506", + "out", + "Lqdhello" + ], + [ + "router-control", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "inter-router", + "506", + "out", + null + ], + [ + "inter-router", + "506", + "in", + null + ], + [ + "endpoint", + "533", + "in", + null + ], + [ + "edge-downlink", + "533", + "out", + "HEDGE-8.0" + ], + [ + "endpoint", + "533", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "533", + "in", + "M0$management" + ], + [ + "endpoint", + "533", + "out", + "Ltemp.5lr4JT4g7J2PxEy" + ], + [ + "endpoint", + "534", + "in", + null + ], + [ + "edge-downlink", + "534", + "out", + "HEDGE-8.1" + ], + [ + "endpoint", + "534", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "534", + "in", + "M0$management" + ], + [ + "endpoint", + "534", + "out", + "Ltemp.9bbwgPssAa8rg6U" + ], + [ + "endpoint", + "538", + "out", + "Ltemp.b73RFCgwEmMwxuu" + ], + [ + "endpoint", + "538", + "in", + null + ] + ], + "timestamp": "2018-12-03T17:54:29.993Z" + } + }, + "amqp:/_topo/0/Interior Router B/$management": { + "connection": { + "attributeNames": [ + "name", + "identity", + "host", + "role", + "dir", + "container", + "sasl", + "isAuthenticated", + "user", + "isEncrypted", + "sslProto", + "sslCipher", + "properties", + "sslSsf", + "tenant", + "type", + "ssl", + "opened", + "active" + ], + "results": [ + [ + "connection/127.0.0.1:22004", + "1", + "127.0.0.1:22004", + "inter-router", + "out", + "INT.A", + "ANONYMOUS", + true, + null, + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 506 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:48078", + "2", + "127.0.0.1:48078", + "edge", + "in", + "EDGE-4.0", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 37 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:48080", + "3", + "127.0.0.1:48080", + "edge", + "in", + "EDGE-13.9", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 7 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:48090", + "7", + "127.0.0.1:48090", + "edge", + "in", + "EDGE-13.2", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 7 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:48084", + "6", + "127.0.0.1:48084", + "edge", + "in", + "EDGE-13.7", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 7 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:48086", + "5", + "127.0.0.1:48086", + "edge", + "in", + "EDGE-3.0", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 764 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:48092", + "8", + "127.0.0.1:48092", + "edge", + "in", + "EDGE-6.0", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 35 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:41250", + "9", + "127.0.0.1:41250", + "edge", + "in", + "EDGE-10.0", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ], + [ + "connection/127.0.0.1:41252", + "10", + "127.0.0.1:41252", + "edge", + "in", + "EDGE-10.1", + "ANONYMOUS", + true, + "anonymous", + false, + null, + null, + { + "product": "qpid-dispatch-router", + "version": "1.5.0-SNAPSHOT", + "qd.conn-id": 1 + }, + 0, + null, + "org.apache.qpid.dispatch.connection", + false, + true, + true + ] + ], + "timestamp": "2018-12-03T17:54:29.993Z" + }, + "router.node": { + "results": [ + [ + "Interior Router B", + "(self)" + ], + [ + "INT.A", + null + ] + ], + "attributeNames": [ + "id", + "nextHop" + ], + "timestamp": "2018-12-03T17:54:29.990Z" + }, + "router.link": { + "attributeNames": [ + "linkType", + "connectionId", + "linkDir", + "owningAddr" + ], + "results": [ + [ + "router-control", + "1", + "in", + null + ], + [ + "router-control", + "1", + "out", + "Lqdhello" + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "inter-router", + "1", + "in", + null + ], + [ + "inter-router", + "1", + "out", + null + ], + [ + "endpoint", + "8", + "in", + null + ], + [ + "edge-downlink", + "8", + "out", + "HEDGE-6.0" + ], + [ + "endpoint", + "8", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "8", + "out", + "M0to60" + ], + [ + "endpoint", + "8", + "in", + "M0to61" + ], + [ + "endpoint", + "8", + "in", + "M0$management" + ], + [ + "endpoint", + "8", + "out", + "Ltemp.h1XzTsSzGVWKnCq" + ], + [ + "endpoint", + "9", + "in", + null + ], + [ + "edge-downlink", + "9", + "out", + "HEDGE-10.0" + ], + [ + "endpoint", + "9", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "9", + "in", + "M0$management" + ], + [ + "endpoint", + "9", + "out", + "Ltemp.kKv6kw5BDhsC3yo" + ], + [ + "endpoint", + "10", + "in", + null + ], + [ + "edge-downlink", + "10", + "out", + "HEDGE-10.1" + ], + [ + "endpoint", + "10", + "out", + "M0$qd.edge_addr_tracking" + ], + [ + "endpoint", + "10", + "in", + "M0$management" + ], + [ + "endpoint", + "10", + "out", + "Ltemp.4vyZk5C_Qo11yyw" + ] + ], + "timestamp": "2018-12-03T17:54:29.994Z" + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/db6ed6b1/console/stand-alone/test/utilities.js ---------------------------------------------------------------------- diff --git a/console/stand-alone/test/utilities.js b/console/stand-alone/test/utilities.js index 7882ccc..e3ae360 100644 --- a/console/stand-alone/test/utilities.js +++ b/console/stand-alone/test/utilities.js @@ -18,47 +18,32 @@ under the License. */ /* global describe it */ var assert = require('assert'); -var expect = require('chai').expect; -import { QDRService } from '../plugin/js/qdrService.js'; - -class Log { - constructor() { - } - log (msg) {} - debug (msg) {} - error (msg) {} - info (msg) {} - warn (msg) {} -} -var log = new Log(); -var loc = {protocol: function () { return 'http://';}}; -var timeout = function (f) {f();}; -var qdrService = new QDRService(log, timeout, loc); +import { utils } from '../plugin/js/amqp/utilities'; describe('Management utilities', function() { describe('#nameFromId', function() { it('should extract name from id', function() { - let name = qdrService.utilities.nameFromId('amqp:/topo/0/routerName/$management'); + let name = utils.nameFromId('amqp:/topo/0/routerName/$management'); assert.equal(name, 'routerName'); }); it('should extract name with / from id', function() { - let name = qdrService.utilities.nameFromId('amqp:/topo/0/router/Name/$management'); + let name = utils.nameFromId('amqp:/topo/0/router/Name/$management'); assert.equal(name, 'router/Name'); }); it('should extract from edge router id', function() { - let name = qdrService.utilities.nameFromId('amqp:/_edge/edgeName/$management'); + let name = utils.nameFromId('amqp:/_edge/edgeName/$management'); assert.equal(name, 'edgeName'); }); it('should extract name with / from edge router id', function() { - let name = qdrService.utilities.nameFromId('amqp:/_edge/edge/Name/$management'); + let name = utils.nameFromId('amqp:/_edge/edge/Name/$management'); assert.equal(name, 'edge/Name'); }); it('should extract name with multiple /s from router id', function() { - let name = qdrService.utilities.nameFromId('amqp:/_topo/0/router/Name/here/$management'); + let name = utils.nameFromId('amqp:/_topo/0/router/Name/here/$management'); assert.equal(name, 'router/Name/here'); }); it('should extract name with multiple /s from edge router id', function() { - let name = qdrService.utilities.nameFromId('amqp:/_edge/edge/Name/here/$management'); + let name = utils.nameFromId('amqp:/_edge/edge/Name/here/$management'); assert.equal(name, 'edge/Name/here'); }); }); @@ -66,143 +51,162 @@ describe('Management utilities', function() { let aAr = ['name', 'value']; let vAr = [['mary', 'lamb']]; it('should return correct value for key', function() { - let name = qdrService.utilities.valFor(aAr, vAr[0], 'name'); + let name = utils.valFor(aAr, vAr[0], 'name'); assert.equal(name, 'mary'); }); it('should return null if key is not found', function() { - let name = qdrService.utilities.valFor(aAr, vAr, 'address'); + let name = utils.valFor(aAr, vAr, 'address'); assert.equal(name, null); }); }); describe('#pretty', function() { it('should return unchanged if not a number', function() { - let val = qdrService.utilities.pretty('foo'); + let val = utils.pretty('foo'); assert.equal(val, 'foo'); }); it('should add commas to numbers', function() { - let val = qdrService.utilities.pretty('1234'); + let val = utils.pretty('1234'); assert.equal(val, '1,234'); }); }); describe('#humanify', function() { it('should handle empty strings', function() { - let val = qdrService.utilities.humanify(''); + let val = utils.humanify(''); assert.equal(val, ''); }); it('should handle undefined input', function() { - let val = qdrService.utilities.humanify(); + let val = utils.humanify(); assert.equal(val, undefined); }); it('should capitalize the first letter', function() { - let val = qdrService.utilities.humanify('foo'); + let val = utils.humanify('foo'); assert.equal(val, 'Foo'); }); it('should split on all capital letters', function() { - let val = qdrService.utilities.humanify('fooBarBaz'); + let val = utils.humanify('fooBarBaz'); assert.equal(val, 'Foo Bar Baz'); }); }); describe('#addr_class', function() { it('should handle unknown address types', function() { - let val = qdrService.utilities.addr_class(' '); + let val = utils.addr_class(' '); assert.equal(val, 'unknown: '); }); it('should handle undefined input', function() { - let val = qdrService.utilities.addr_class(); + let val = utils.addr_class(); assert.equal(val, '-'); }); it('should identify mobile addresses', function() { - let val = qdrService.utilities.addr_class('Mfoo'); + let val = utils.addr_class('Mfoo'); assert.equal(val, 'mobile'); }); it('should identify router addresses', function() { - let val = qdrService.utilities.addr_class('Rfoo'); + let val = utils.addr_class('Rfoo'); assert.equal(val, 'router'); }); it('should identify area addresses', function() { - let val = qdrService.utilities.addr_class('Afoo'); + let val = utils.addr_class('Afoo'); assert.equal(val, 'area'); }); it('should identify local addresses', function() { - let val = qdrService.utilities.addr_class('Lfoo'); + let val = utils.addr_class('Lfoo'); assert.equal(val, 'local'); }); it('should identify link-incoming C addresses', function() { - let val = qdrService.utilities.addr_class('Cfoo'); + let val = utils.addr_class('Cfoo'); assert.equal(val, 'link-incoming'); }); it('should identify link-incoming E addresses', function() { - let val = qdrService.utilities.addr_class('Efoo'); + let val = utils.addr_class('Efoo'); assert.equal(val, 'link-incoming'); }); it('should identify link-outgoing D addresses', function() { - let val = qdrService.utilities.addr_class('Dfoo'); + let val = utils.addr_class('Dfoo'); assert.equal(val, 'link-outgoing'); }); it('should identify link-outgoing F addresses', function() { - let val = qdrService.utilities.addr_class('Dfoo'); + let val = utils.addr_class('Dfoo'); assert.equal(val, 'link-outgoing'); }); it('should identify topo addresses', function() { - let val = qdrService.utilities.addr_class('Tfoo'); + let val = utils.addr_class('Tfoo'); assert.equal(val, 'topo'); }); }); describe('#addr_text', function() { it('should handle undefined input', function() { - let val = qdrService.utilities.addr_text(); + let val = utils.addr_text(); assert.equal(val, '-'); }); it('should identify mobile addresses', function() { - let val = qdrService.utilities.addr_text('M0foo'); + let val = utils.addr_text('M0foo'); assert.equal(val, 'foo'); }); it('should identify non-mobile addresses', function() { - let val = qdrService.utilities.addr_text('Rfoo'); + let val = utils.addr_text('Rfoo'); assert.equal(val, 'foo'); }); }); describe('#identity_clean', function() { it('should handle undefined input', function() { - let val = qdrService.utilities.identity_clean(); + let val = utils.identity_clean(); assert.equal(val, '-'); }); it('should handle identities with no /', function() { - let val = qdrService.utilities.identity_clean('foo'); + let val = utils.identity_clean('foo'); assert.equal(val, 'foo'); }); it('should return everything after the 1st /', function() { - let val = qdrService.utilities.identity_clean('foo/bar'); + let val = utils.identity_clean('foo/bar'); assert.equal(val, 'bar'); }); }); describe('#copy', function() { it('should handle undefined input', function() { - let val = qdrService.utilities.copy(); + let val = utils.copy(); assert.equal(val, undefined); }); it('should copy all object values instead making references', function() { let input = {a: 'original value'}; - let output = qdrService.utilities.copy(input); + let output = utils.copy(input); input.a = 'changed value'; assert.equal(output.a, 'original value'); }); }); describe('#flatten', function() { it('should return an object when passed undefined input', function() { - let val = qdrService.utilities.flatten(); + let val = utils.flatten(); assert.equal(typeof val, 'object'); }); it('and the returned object should be empty', function() { - let val = qdrService.utilities.flatten(); + let val = utils.flatten(); assert.equal(Object.keys(val).length, 0); }); it('should flatten the arrays into an object', function() { let attributes = ['first', 'second']; let value = ['1st', '2nd']; - let val = qdrService.utilities.flatten(attributes, value); + let val = utils.flatten(attributes, value); assert.equal(val.second, '2nd'); }); }); + describe('#flattenAll', function() { + let vals = []; + let attributes = ['first', 'second']; + let values = [['1st', '2nd'], ['3rd', '4th']]; + it('should flatten the router entity into an array of objects', function() { + vals = utils.flattenAll({attributeNames: attributes, results: values}); + assert.equal(vals.length, 2); + }); + it('should correctly create the objects', function() { + assert.equal(vals[1].second, '4th'); + }); + it('should filter out objects', function() { + vals = utils.flattenAll({attributeNames: attributes, results: values}, function (f) { + return f.first === '1st' ? {first: 'first', second: 'second'} : null; + }); + assert.equal(vals.length, 1); + assert.equal(vals[0].second, 'second'); + }); + }); }); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
