8. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/4/2017 9:15:14 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

8.1 Files compared

# Location File Last Modified
1 vista-js.zip\vista-js\tests\unit RpcClient-spec.js Mon Aug 28 19:30:23 2017 UTC
2 vista-js.zip\vista-js\tests\unit RpcClient-spec.js Wed Oct 4 13:40:45 2017 UTC

8.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 7 1646
Changed 6 24
Inserted 0 0
Removed 0 0

8.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

8.4 Active regular expressions

No regular expressions were active.

8.5 Comparison detail

  1   'use stric t';
  2  
  3   var _ = re quire('und erscore');
  4  
  5   var RpcCli ent = requ ire('../.. /src/RpcCl ient').Rpc Client;
  6  
  7   var parseM essage = r equire('.. /../src/Rp cSender'). RpcSender. parseMessa ge;
  8  
  9   var logger  = {
  10       trace:  _.noop,
  11       debug:  _.noop,
  12       info:  _.noop,
  13       warn:  _.noop,
  14       error:  _.noop,
  15       fatal:  _.noop
  16   };
  17  
  18   var config  = {
  19         host: ' IP          ',
  20         port:  PORT ,
  21         accessCode : ' PL      ',
  22         verifyCode : ' PW        ',
  23       contex t: 'HMP UI  CONTEXT',
  24       localI P: '127.0. 0.1',
  25       localA ddress: 'l ocalhost',
  26       connec tTimeout:  3000,
  27       sendTi meout: 100 00
  28   };
  29  
  30   function d efaultFunc tion(callb ack) {
  31       setTim eout(callb ack);
  32   }
  33  
  34   function c reateSende r() {
  35       return  {
  36           cl ose: _.noo p,
  37           co nnect: def aultFuncti on
  38       };
  39   }
  40  
  41   function t estCommand (command,  sentError,  sentResul t, expecte dError, ex pectedResu lt) {
  42       var te stError;
  43       var te stResult;
  44       var ca lled = fal se;
  45  
  46       functi on callbac k(error, r esult) {
  47           ca lled = tru e;
  48           te stError =  error;
  49           te stResult =  result;
  50       }
  51  
  52       var in stance = {
  53           lo gger: logg er,
  54           co nfig: conf ig,
  55           se nder: {
  56                send: fu nction sen d(string,  callback)  {
  57                    call back(sentE rror, sent Result);
  58                },
  59                close: _ .noop
  60           }
  61       };
  62  
  63       comman d.call(ins tance, cal lback);
  64  
  65       waitsF or(functio n() {
  66           re turn calle d;
  67       }, 'sh ould be ca lled', 100 0);
  68  
  69       runs(f unction()  {
  70           ex pect(testE rror).toEq ual(expect edError);
  71           ex pect(testR esult).toE qual(expec tedResult) ;
  72       });
  73   }
  74  
  75   function t estCommand MultiRpc(c ommand, se ntErrors,  sentResult s, expecte dError, ex pectedResu lt, overri deConfig)  {
  76       var te stError;
  77       var te stResult;
  78       var ca lled = fal se;
  79  
  80       functi on callbac k(error, r esult) {
  81           ca lled = tru e;
  82           te stError =  error;
  83           te stResult =  result;
  84       }
  85  
  86       var in stance = {
  87           lo gger: logg er,
  88           co nfig: over rideConfig  || config ,
  89           se nder: {
  90                send: fu nction sen d(string,  callback)  {
  91                    call back(sentE rrors.shif t(), sentR esults.shi ft());
  92                },
  93                close: _ .noop
  94           }
  95       };
  96  
  97       comman d.call(ins tance, cal lback);
  98  
  99       waitsF or(functio n() {
  100           re turn calle d && sentE rrors.leng th === 0 & & sentResu lts.length  === 0;
  101       }, 'sh ould be ca lled', 100 0);
  102  
  103       runs(f unction()  {
  104           ex pect(testE rror).toEq ual(expect edError);
  105           ex pect(testR esult).toE qual(expec tedResult) ;
  106       });
  107   }
  108  
  109   var greeti ng = {
  110       patter n: new Reg Exp('^\\[X WB\\]10304 \u000ATCPC onnect5001 40009127\\ .0\\.0\\.1 ff00010f00 140009loca lhostff\u0 004$'),
  111       respon se: '\u000 0\u0000acc ept\u0004'
  112   };
  113  
  114   var signon  = {
  115       patter n: new Reg Exp('^\\[X WB\\]11302 \u00051\\. 108\u0010X US SIGNON  SETUP54f\u 0004$'),
  116       respon se: '\u000 0\u0000loc alhost.loc aldomain\u 000D\u000A ROU\u000D\ u000AVISTA \u000D\u00 0A/dev/nul l:16898\u0 00D\u000A5 \u000D\u00 0A0\u000D\ u000AVISTA .LOCAL.US\ u000D\u000 A0\u000D\u 000A\u0004 '
  117   };
  118  
  119   var verify  = {
  120       patter n: new Reg Exp('^\\[X WB\\]11302 \u00051\\. 108\u000BX US AV CODE 50017.{17} f\u0004$') ,
  121       respon se: '\u000 0\u0000100 00000226\u 000D\u000A 0\u000D\u0 00A0\u000D \u000A\u00 0D\u000A0\ u000D\u000 A0\u000D\u 000A\u000D \u000AGood  evening U SER,PANORA MA\u000D\u 000A     Y ou last si gned on ye sterday at  15:59\u00 0D\u000A\u 0004'
  122   };
  123  
  124   var contex t = {
  125       patter n: new Reg Exp('^\\[X WB\\]11302 \u00051\\. 108\u0012X WB CREATE  CONTEXT500 16.{16}f\u 0004$'),
  126       respon se: '\u000 0\u00001\u 0004'
  127   };
  128  
  129   /* jshint  ignore:sta rt */
  130   var execut e = {
  131       patter n: new Reg Exp('^\\[X WB\\]11302 \u00051\\. 108\u000DO RWU USERIN FO54f\u000 4$'),
  132       respon se: '\u000 0\u0000100 00000226^U SER,PANORA MA^3^1^1^3 ^0^4000^20 ^1^1^20^KO DAK.VISTAC ORE.US^0^1 80^^^^0^0^ ^1^0^500^^ 0\u0004'
  133   };
  134  
  135   var signof f = {
  136       patter n: new Reg Exp('^\\[X WB\\]10304 \u0005#BYE #\u0004$') ,
  137       respon se: '\u000 0\u0000#BY E#\u0004'
  138   };
  139   /* jshint  ignore:end  */
  140  
  141   var dummyS ender = {
  142       count:  0,
  143       reqRes : [],
  144       connec t: functio n(callback ) {
  145           ca llback(nul l, 'connec ted');
  146       },
  147       send:  function s end(string , callback ) {
  148           va r curr = t his.reqRes [this.coun t];
  149           if  (!curr) {
  150                this.cou nt = 0;
  151                return c allback('e rror');
  152           }
  153  
  154           if  (!curr.pa ttern.test (string))  {
  155                this.cou nt = 0;
  156                return c allback(nu ll, '\u000 0\u0001App lication E rror\u0004 ');
  157           }
  158  
  159           th is.count++ ;
  160           va r response  = parseMe ssage(curr .response) ;
  161           ca llback(res ponse.erro r, respons e.response );
  162       },
  163       close:  _.noop
  164   };
  165  
  166   describe(' RpcClient. js', funct ion() {
  167       descri be('greeti ngCommand( )', functi on() {
  168           it ('verify e rror trigg ers callba ck error',  function( ) {
  169                testComm and(RpcCli ent.protot ype.greeti ngCommand,  'error',  'result',  'error', ' result');
  170           }) ;
  171  
  172           it ('verify i nvalid res ponse stri ng trigger s callback  error', f unction()  {
  173                testComm and(RpcCli ent.protot ype.greeti ngCommand,  null, 'xa ccept', 'R esponse to  greeting  was invali d', 'xacce pt');
  174           }) ;
  175  
  176           it ('verify n o error tr iggers cal lback resu lt', funct ion() {
  177                testComm and(RpcCli ent.protot ype.greeti ngCommand,  null, 'ac cept', nul l, 'HANDSH AKE SUCCES SFUL');
  178           }) ;
  179       });
  180  
  181       descri be('buildS ignonCallb ack()', fu nction() {
  182           it ('verify e rror trigg ers callba ck error',  function( ) {
  183                testComm and(RpcCli ent.protot ype.signon Command, ' error', 'r esult', 'e rror', 're sult');
  184           }) ;
  185  
  186           it ('verify i nvalid res ponse stri ng trigger s callback  error', f unction()  {
  187                testComm and(RpcCli ent.protot ype.signon Command, n ull, '', ' No respons e to signo n callback ', null);
  188           }) ;
  189  
  190           xi t('verify  no error t riggers ca llback res ult', func tion() {
  191                testComm and(RpcCli ent.protot ype.signon Command, n ull, 'anyt hing', nul l, 'SIGNON  SETUP SUC CESSFUL');
  192           }) ;
  193       });
  194  
  195       descri be('buildV erifyCallb ack()', fu nction() {
  196           it ('verify e rror trigg ers callba ck error',  function( ) {
  197                testComm and(RpcCli ent.protot ype.verify Command, ' error', 'r esult', 'e rror', 're sult');
  198           }) ;
  199  
  200           it ('verify i nvalid res ponse stri ng trigger s callback  error', f unction()  {
  201                testComm and(RpcCli ent.protot ype.verify Command, n ull, '', ' No respons e to login  request',  null);
  202           }) ;
  203  
  204           it ('verify n o DUZ trig gers callb ack error' , function () {
  205                testComm and(RpcCli ent.protot ype.verify Command, n ull, '0\r\ n0', 'No D UZ returne d from log in request ', '0\r\n0 ');
  206           }) ;
  207  
  208           it ('verify n o DUZ trig gers callb ack error  from rpc',  function( ) {
  209                testComm and(RpcCli ent.protot ype.verify Command, n ull, '0\r\ n0\r\n0\r\ nNot a val id access/ verify cod e\r\n0', ' Not a vali d access/v erify code ', '0\r\n0 \r\n0\r\nN ot a valid  access/ve rify code\ r\n0');
  210           }) ;
  211  
  212           it ('verify n o error tr iggers cal lback resu lt', funct ion() {
  213                testComm and(RpcCli ent.protot ype.verify Command, n ull, '1000 0217\r\n0' , null, {
  214                    acce ssCode: co nfig.acces sCode,
  215                    veri fyCode: co nfig.verif yCode,
  216                    duz:  '10000217 ',
  217                    gree ting: 'OK'
  218                });
  219           }) ;
  220       });
  221  
  222       descri be('divisi onCommand( )', functi on() {
  223           it ('verify d oesnt call  divisionC ommand whe n no divis ion presen t', functi on() {
  224                testComm and(RpcCli ent.protot ype.divisi onCommand,  null, nul l, null, 0 );
  225           }) ;
  226  
  227           it ('verify i t returns  the error  when DIVIS ION GET fa ils', func tion() {
  228                var test Config = _ .clone(con fig);
  229                testConf ig.divisio n = '500';
  230                testComm andMultiRp c(RpcClien t.prototyp e.division Command, [ 'explode'] , [null],  'explode',  null, tes tConfig);
  231           }) ;
  232  
  233           it ('verify i t returns  the error  when GET U SER INFO f ails', fun ction() {
  234                var test Config = _ .clone(con fig);
  235                testConf ig.divisio n = '500';
  236                testComm andMultiRp c(RpcClien t.prototyp e.division Command, [ null, 'exp lode'], [' 0\r\n', nu ll], 'expl ode', null , testConf ig);
  237           }) ;
  238  
  239           it ('verify r eturns the  correct d ivision wh en user is  assigned  to the div ision in s ingle divi sion site' , function () {
  240                var test Config = _ .clone(con fig);
  241                testConf ig.divisio n = '500';
  242                testComm andMultiRp c(RpcClien t.prototyp e.division Command, [ null, null ], ['0\r\n ', '100000 00270\r\nU SER,PANORA MA\r\nPano rama User\ r\n500^CAM P MASTER^5 00\r\n\r\n MEDICINE\r \n\r\n4000 \r\n\r\n'] , null, '5 00', testC onfig);
  243           }) ;
  244  
  245           it ('verify r eturns the  correct d ivision wh en given v alid non-s tring divi sion', fun ction() {
  246                var test Config = _ .clone(con fig);
  247                testConf ig.divisio n = 500;
  248                testComm andMultiRp c(RpcClien t.prototyp e.division Command, [ null, null ], ['0\r\n ', '100000 00270\r\nU SER,PANORA MA\r\nPano rama User\ r\n500^CAM P MASTER^5 00\r\n\r\n MEDICINE\r \n\r\n4000 \r\n\r\n'] , null, '5 00', testC onfig);
  249           }) ;
  250  
  251           it ('verify r eturns the  correct d ivision wh en user is  assigned  to the div ision in m ultidivisi on site',  function()  {
  252                var test Config = _ .clone(con fig);
  253                testConf ig.divisio n = '613';
  254                testComm andMultiRp c(RpcClien t.prototyp e.division Command, [ null, null ], ['3\r\n 507^CAMP B EE^507^1\r \n613^MART INSBURG VA MC^613\r\n 17102^WASH INGTON^688 \r\n', '1' ], null, ' 613', test Config);
  255           }) ;
  256  
  257           it ('verify r eturns the  parent di vision whe n the user  account d efaults to  a non-fac ility divi sion and a  parent di vision is  passed', f unction()  {
  258                var test Config = _ .clone(con fig);
  259                testConf ig.divisio n = '500';
  260                var user Info = '10 000000270\ r\nUSER,PA NORAMA\r\n Panorama U ser\r\n300 0^REGION 3 ^\r\n\r\nM EDICINE\r\ n\r\n4000\ r\n\r\n';
  261                testComm andMultiRp c(RpcClien t.prototyp e.division Command, [ null, null ], ['0\r\n ', userInf o], null,  '500', tes tConfig);
  262           }) ;
  263  
  264           it ('verify r eturns the  error whe n user acc ount defau lts to a n on-facilit y division  and a chi ld divisio n is passe d', functi on() {
  265                var test Config = _ .clone(con fig);
  266                testConf ig.divisio n = '500AA ';
  267                var user Info = '10 000000270\ r\nUSER,PA NORAMA\r\n Panorama U ser\r\n300 0^REGION 3 ^\r\n\r\nM EDICINE\r\ n\r\n4000\ r\n\r\n';
  268                testComm andMultiRp c(RpcClien t.prototyp e.division Command, [ null, null ], ['0\r\n ', userInf o], 'Selec ted divisi on not fou nd for thi s user', u serInfo, t estConfig) ;
  269           }) ;
  270       });
  271  
  272       descri be('buildC ontextCall back()', f unction()  {
  273           it ('verify e rror trigg ers callba ck error',  function( ) {
  274                testComm and(RpcCli ent.protot ype.contex tCommand,  'error', ' result', ' error', 'r esult');
  275           }) ;
  276  
  277           it ('verify i nvalid res ponse stri ng trigger s callback  error', f unction()  {
  278                testComm and(RpcCli ent.protot ype.contex tCommand,  null, '0',  'Authoriz ation erro r', '0');
  279           }) ;
  280  
  281           it ('verify v alid respo nse string  triggers  callback r esult', fu nction() {
  282                testComm and(RpcCli ent.protot ype.contex tCommand,  null, '1',  null, con fig.contex t);
  283           }) ;
  284       });
  285  
  286       descri be('buildS ignOffCall back()', f unction()  {
  287           it ('verify e rror trigg ers callba ck error',  function( ) {
  288                testComm and(RpcCli ent.protot ype.signof fCommand,  'error', ' result', ' error', 'r esult');
  289           }) ;
  290  
  291           it ('verify n o error tr iggers cal lback resu lt', funct ion() {
  292                testComm and(RpcCli ent.protot ype.signof fCommand,  null, 'res ult', null , 'SIGNOFF  SUCCESSFU L');
  293           }) ;
  294       });
  295  
  296       descri be('isClie nt()', fun ction() {
  297           it ('verify R pcClient p asses', fu nction() {
  298                var clie nt = new R pcClient(l ogger, con fig);
  299                expect(R pcClient.i sClient(cl ient)).toB e(true);
  300           }) ;
  301  
  302           it ('verify c orrect sig nature pas ses', func tion() {
  303                expect(R pcClient.i sClient({
  304                    conn ect: _.noo p,
  305                    exec ute: _.noo p,
  306                    clos e: _.noop
  307                })).toBe (true);
  308  
  309                expect(R pcClient.i sClient({
  310                    conn ect: _.noo p,
  311                    exec ute: _.noo p,
  312                    clos e: _.noop,
  313                    foo:  _.noop,
  314                    bar:  'bar'
  315                })).toBe (true);
  316           }) ;
  317  
  318           it ('verify u ndefined,  null, and  incorrect  signatures /types fai l', functi on() {
  319                expect(R pcClient.i sClient()) .toBe(fals e);
  320                expect(R pcClient.i sClient(nu ll)).toBe( false);
  321                expect(R pcClient.i sClient({} )).toBe(fa lse);
  322                expect(R pcClient.i sClient('' )).toBe(fa lse);
  323                expect(R pcClient.i sClient({
  324                    conn ect: _.noo p,
  325                    exec ute: _.noo p,
  326                    clos e: 'foo'
  327                }));
  328                expect(R pcClient.i sClient({
  329                    conn ect: _.noo p,
  330                    exec ute: _.noo p
  331                }));
  332           }) ;
  333       });
  334  
  335       descri be('RpcCli ent.create ()', funct ion() {
  336           it ('verify i nstance cr eated', fu nction() {
  337                var clie nt = RpcCl ient.creat e(logger,  config);
  338                expect(c lient inst anceof Rpc Client).to Be(true);
  339                expect(c lient.logg er).toBe(l ogger);
  340                expect(c lient.conf ig).toBe(c onfig);
  341                expect(c lient.queu e).not.toB eUndefined ();
  342           }) ;
  343       });
  344  
  345       descri be('RpcCli ent.execut e()', func tion() {
  346           va r testErro r;
  347           va r testResu lt;
  348           va r called;
  349           va r client;
  350           va r execute;
  351  
  352           be foreEach(f unction()  {
  353                testErro r = undefi ned;
  354                testResu lt = undef ined;
  355                called =  false;
  356  
  357                client =  RpcClient .create(lo gger, conf ig);
  358                client._ execute =  function(s tartTime,  rpcCall, c allback) {
  359                    setT imeout(cal lback, 0,  null, 'res ponse');
  360                };
  361  
  362                execute  = client.e xecute.bin d(client);
  363           }) ;
  364  
  365           it ('test ins ufficient  arguments' , function () {
  366                execute( function(e rror, resu lt) {
  367                    call ed = true;
  368                    test Error = er ror;
  369                    test Result = r esult;
  370                });
  371  
  372                waitsFor (function( ) {
  373                    retu rn called;
  374                }, 'shou ld be call ed', 1000) ;
  375  
  376                runs(fun ction() {
  377                    expe ct(testErr or).toEqua l('Insuffi cient numb er of argu ments');
  378                    expe ct(testRes ult).toBeU ndefined() ;
  379                });
  380           }) ;
  381  
  382           it ('test inv alid argum ents', fun ction() {
  383                execute( '', functi on(error,  result) {
  384                    call ed = true;
  385                    test Error = er ror;
  386                    test Result = r esult;
  387                });
  388  
  389                waitsFor (function( ) {
  390                    retu rn called;
  391                }, 'shou ld be call ed', 1000) ;
  392  
  393                runs(fun ction() {
  394                    expe ct(testErr or).toEqua l('Invalid  arguments  for rpcCa ll');
  395                    expe ct(testRes ult).toBeU ndefined() ;
  396                });
  397           }) ;
  398  
  399           it ('test val id argumen ts', funct ion() {
  400                var rpcC md = 'XUS  SIGNON SET UP';
  401  
  402                execute( rpcCmd, fu nction(err or, result ) {
  403                    call ed = true;
  404                    test Error = er ror;
  405                    test Result = r esult;
  406                });
  407  
  408                waitsFor (function( ) {
  409                    retu rn called;
  410                }, 'shou ld be call ed', 1000) ;
  411  
  412                runs(fun ction() {
  413                    expe ct(testErr or).toBeNu ll();
  414                    expe ct(testRes ult).not.t oBeUndefin ed();
  415                });
  416           }) ;
  417       });
  418  
  419       descri be('RpcCli ent.close( )', functi on() {
  420           va r testErro r;
  421           va r testResu lt;
  422           va r called;
  423           va r client;
  424           va r close;
  425  
  426           be foreEach(f unction()  {
  427                testErro r = undefi ned;
  428                testResu lt = undef ined;
  429                called =  false;
  430  
  431                client =  RpcClient .create(lo gger, conf ig);
  432                client._ close = fu nction(cal lback) {
  433                    setT imeout(cal lback);
  434                };
  435  
  436                close =  RpcClient. prototype. close.bind (client);
  437           }) ;
  438  
  439           it ('test not  connected ', functio n() {
  440                close(fu nction(err or, result ) {
  441                    call ed = true;
  442                    test Error = er ror;
  443                    test Result = r esult;
  444                });
  445  
  446                waitsFor (function( ) {
  447                    retu rn called;
  448                }, 'shou ld be call ed', 1000) ;
  449  
  450                runs(fun ction() {
  451                    expe ct(testErr or).toBeUn defined();
  452                    expe ct(testRes ult).toBeU ndefined() ;
  453                });
  454           }) ;
  455  
  456           it ('test val id signoff ', functio n() {
  457                client._ close = fu nction(cal lback) {
  458                    setT imeout(cal lback, 0,  null, 'SIG NOFF SUCCE SSFUL');
  459                };
  460  
  461                close(fu nction(err or, result ) {
  462                    call ed = true;
  463                    test Error = er ror;
  464                    test Result = r esult;
  465                });
  466  
  467                waitsFor (function( ) {
  468                    retu rn called;
  469                }, 'shou ld be call ed', 1000) ;
  470  
  471                runs(fun ction() {
  472                    expe ct(testErr or).toBeNu ll();
  473                    expe ct(testRes ult).toEqu al('SIGNOF F SUCCESSF UL');
  474                });
  475           }) ;
  476       });
  477  
  478       descri be('RpcCli ent.connec t()', func tion() {
  479           it ('verify c onnection' , function () {
  480                var user  = {
  481                      accessCode : ' PL      ',
  482                      verifyCode : ' PW        ',
  483                    duz:  '10000000 226',
  484                    gree ting: 'OK'
  485                };
  486  
  487                var reqR es = [gree ting, sign on, verify , context] ;
  488                dummySen der.reqRes  = reqRes;
  489                dummySen der.count  = 0;
  490  
  491                var clie nt = new R pcClient(l ogger, con fig);
  492                client._ connect =  function(c allback) {
  493                    setT imeout(cal lback, 0,  null, user );
  494                };
  495  
  496                var test Error;
  497                var test Result;
  498                var call ed = false ;
  499  
  500                var test Callback =  function( error, res ult) {
  501                    call ed = true;
  502                    test Error = er ror;
  503                    test Result = r esult;
  504                };
  505  
  506                client.c onnect(tes tCallback) ;
  507  
  508                waitsFor (function( ) {
  509                    retu rn called;
  510                }, 'shou ld be call ed', 1000) ;
  511  
  512                runs(fun ction() {
  513                    expe ct(testErr or).toBeNu ll();
  514                    expe ct(testRes ult).toEqu al(user);
  515                });
  516           }) ;
  517       });
  518  
  519       descri be('_enque ue', funct ion() {
  520           va r instance  = {
  521                config:  {
  522                    host : '0.0.0.0 ',
  523                    port : 0
  524                },
  525                logger:  logger,
  526                queue: {
  527                    q: [ ],
  528                    _hig hWaterMark : 0,
  529                    _max Length: 0,
  530                    leng th: functi on() {
  531                         return thi s.q.length ;
  532                    },
  533                    push : function (item) {
  534                         this.q.pus h(item);
  535                    },
  536                    pop:  function( ) {
  537                         return thi s.q.pop();
  538                    }
  539                },
  540                _enqueue : RpcClien t.prototyp e._enqueue
  541           };
  542  
  543           it ('test pus h onto que ue', funct ion() {
  544                instance ._enqueue( 'task1');
  545                expect(_ .contains( instance.q ueue.q, 't ask1')).to Be(true);
  546           }) ;
  547  
  548           it ('test hig hWater', f unction()  {
  549                instance ._enqueue( 'task2');
  550                instance ._enqueue( 'task3');
  551                instance .queue.pop ();
  552                instance .queue.pop ();
  553                expect(i nstance.qu eue._highW aterMark). toEqual(3) ;
  554           }) ;
  555       });
  556  
  557       descri be('_conne ct', funct ion() {
  558           va r instance ;
  559           va r testErro r;
  560           va r testResu lt;
  561           va r called;
  562  
  563           fu nction tes tCallback( error, res ult) {
  564                called =  true;
  565                testErro r = error;
  566                testResu lt = resul t;
  567           }
  568  
  569           be foreEach(f unction()  {
  570                testErro r = undefi ned;
  571                testResu lt = undef ined;
  572                called =  false;
  573  
  574                instance  = {
  575                    logg er: logger ,
  576                    conf ig: {
  577                         host: '0.0 .0.0',
  578                          port:  PORT
  579                    },
  580                    send er: null,
  581                    _cre ateSender:  function( ) {
  582                         this.sende r = create Sender();
  583                    },
  584                    conn ect: funct ion(callba ck) {
  585                         if (this.s ender) {
  586                             this.s ender(call back);
  587                         }
  588                    },
  589                    gree tingComman d: default Function,
  590                    sign onCommand:  defaultFu nction,
  591                    veri fyCommand:  defaultFu nction,
  592                    divi sionComman d: default Function,
  593                    cont extCommand : defaultF unction
  594                };
  595  
  596                spyOn(in stance, '_ createSend er').andCa llThrough( );
  597                spyOn(in stance, 'g reetingCom mand').and CallThroug h();
  598                spyOn(in stance, 's ignonComma nd').andCa llThrough( );
  599                spyOn(in stance, 'v erifyComma nd').andCa llThrough( );
  600                spyOn(in stance, 'd ivisionCom mand').and CallThroug h();
  601                spyOn(in stance, 'c ontextComm and').andC allThrough ();
  602           }) ;
  603  
  604           it ('sender',  function( ) {
  605                var send er = creat eSender();
  606                instance .sender =  sender;
  607                spyOn(se nder, 'clo se').andCa llThrough( );
  608  
  609                RpcClien t.prototyp e._connect .call(inst ance, test Callback);
  610  
  611                waitsFor (function( ) {
  612                    retu rn called;
  613                }, 'shou ld be call ed', 500);
  614  
  615                runs(fun ction() {
  616                    expe ct(called) .toBe(true );
  617                    expe ct(sender. close).toH aveBeenCal led();
  618                    expe ct(instanc e._createS ender).toH aveBeenCal led();
  619                    expe ct(instanc e.greeting Command).t oHaveBeenC alled();
  620                    expe ct(instanc e.signonCo mmand).toH aveBeenCal led();
  621                    expe ct(instanc e.verifyCo mmand).toH aveBeenCal led();
  622                    expe ct(instanc e.division Command).t oHaveBeenC alled();
  623                    expe ct(instanc e.contextC ommand).to HaveBeenCa lled();
  624                });
  625           }) ;
  626  
  627           it ('no sende r', functi on() {
  628                var send er = creat eSender();
  629                instance .sender =  sender;
  630                spyOn(se nder, 'clo se').andCa llThrough( );
  631  
  632                RpcClien t.prototyp e._connect .call(inst ance, test Callback);
  633  
  634                waitsFor (function( ) {
  635                    retu rn called;
  636                }, 'shou ld be call ed', 500);
  637  
  638                runs(fun ction() {
  639                    expe ct(called) .toBe(true );
  640                    expe ct(instanc e._createS ender).toH aveBeenCal led();
  641                    expe ct(instanc e.greeting Command).t oHaveBeenC alled();
  642                    expe ct(instanc e.signonCo mmand).toH aveBeenCal led();
  643                    expe ct(instanc e.verifyCo mmand).toH aveBeenCal led();
  644                    expe ct(instanc e.contextC ommand).to HaveBeenCa lled();
  645                });
  646           }) ;
  647       });
  648  
  649       descri be('_close ', functio n() {
  650           va r instance ;
  651           va r testErro r;
  652           va r testResu lt;
  653           va r called;
  654  
  655           fu nction tes tCallback( error, res ult) {
  656                called =  true;
  657                testErro r = error;
  658                testResu lt = resul t;
  659           }
  660  
  661           be foreEach(f unction()  {
  662                testErro r = undefi ned;
  663                testResu lt = undef ined;
  664                called =  false;
  665  
  666                instance  = {
  667                    logg er: logger ,
  668                    conf ig: {
  669                         host: '0.0 .0.0',
  670                          port:  PORT
  671                    },
  672                    send er: null,
  673                    _cre ateSender:  function( ) {
  674                         this.sende r = create Sender();
  675                    },
  676  
  677                    sign offCommand : defaultF unction
  678                };
  679           }) ;
  680  
  681           it ('no sende r instance ', functio n() {
  682                // callb ack
  683                RpcClien t.prototyp e._close.c all(instan ce, testCa llback);
  684  
  685                waitsFor (function( ) {
  686                    retu rn called;
  687                }, 'shou ld be call ed', 500);
  688  
  689                runs(fun ction() {
  690                    expe ct(called) .toBe(true );
  691                });
  692           }) ;
  693  
  694           it ('sender i nstance',  function()  {
  695                // signo ffCommand  called
  696                // sende r.close
  697  
  698                var send er = creat eSender();
  699                instance .sender =  sender;
  700                spyOn(se nder, 'clo se').andCa llThrough( );
  701  
  702                RpcClien t.prototyp e._close.c all(instan ce, testCa llback);
  703  
  704                waitsFor (function( ) {
  705                    retu rn called;
  706                }, 'shou ld be call ed', 500);
  707  
  708                runs(fun ction() {
  709                    expe ct(called) .toBe(true );
  710                    expe ct(sender. close).toH aveBeenCal led();
  711                });
  712           }) ;
  713       });
  714  
  715       descri be('_creat eSender',  function()  {
  716           it ('verify s ender inst antiated',  function( ) {
  717                var inst ance = {
  718                    logg er: logger ,
  719                    conf ig: config
  720                };
  721  
  722  
  723                RpcClien t.prototyp e._createS ender.call (instance) ;
  724                expect(i nstance.se nder).not. toBeUndefi ned();
  725                expect(i nstance.lo gger).toBe (logger);
  726                expect(i nstance.co nfig).toBe (config);
  727           }) ;
  728       });
  729  
  730       descri be('authen ticate()',  function( ) {
  731           it ('verify a uthenticat e() calls  connect()  and close( )', functi on() {
  732                var user  = {
  733                      accessCode : ' PL      ',
  734                      verifyCode : ' PW        ',
  735                    duz:  '10000000 226',
  736                    gree ting: 'OK'
  737                };
  738  
  739                var conn ectCalled  = false;
  740                var clos eCalled =  false;
  741  
  742                var mock Client = {
  743                    logg er: logger ,
  744                    conf ig: config ,
  745                    conn ect: funct ion(callba ck) {
  746                         connectCal led = true ;
  747                         callback(n ull, user) ;
  748                    },
  749                    exec ute: _.noo p,
  750                    clos e: functio n(callback ) {
  751                         callback =  callback  || functio n() {};
  752                         closeCalle d = true;
  753                         callback() ;
  754                    }
  755                };
  756  
  757                var test Error;
  758                var test Result;
  759                var call ed = false ;
  760  
  761                var test Callback =  function( error, res ult) {
  762                    call ed = true;
  763                    test Error = er ror;
  764                    test Result = r esult;
  765                };
  766  
  767                RpcClien t.authenti cate(mockC lient, tes tCallback) ;
  768  
  769                waitsFor (function( ) {
  770                    retu rn called;
  771                }, 'shou ld be call ed', 1000) ;
  772  
  773  
  774                runs(fun ction() {
  775                    expe ct(testErr or).toBeNu ll();
  776                    expe ct(testRes ult).toEqu al(user);
  777                });
  778           }) ;
  779       });
  780  
  781       descri be('callRp c()', func tion() {
  782           it ('verify c allRpc() c alls conne ct(), exec ute(), and  close()',  function( ) {
  783                var user  = {
  784                      accessCode : ' PL      ',
  785                      verifyCode : ' PW        ',
  786                    duz:  '10000000 226',
  787                    gree ting: 'OK'
  788                };
  789                var resp onse = '10 000000226^ USER,PANOR AMA^3^1^1^ 3^0^4000^2 0^1^1^20^K ODAK.VISTA CORE.US^0^ 180^^^^0^0 ^^1^0^500^ ^0';
  790                var conn ectCalled  = false;
  791                var clos eCalled =  false;
  792  
  793                var mock Client = {
  794                    logg er: logger ,
  795                    conf ig: config ,
  796                    conn ect: funct ion(callba ck) {
  797                         connectCal led = true ;
  798                         callback(n ull, user) ;
  799                    },
  800                    _con nect: func tion() {},
  801                    exec ute: funct ion(startT ime, rpcCa ll, parame ters, call back) {
  802                         callback(n ull, respo nse);
  803                    },
  804                    _exe cute: func tion() {},
  805                    clos e: functio n(callback ) {
  806                         callback =  callback  || functio n() {};
  807                         closeCalle d = true;
  808                         callback() ;
  809                    },
  810                    _clo se: functi on() {}
  811                };
  812  
  813                var test Error;
  814                var test Result;
  815                var call ed = false ;
  816  
  817                var test Callback =  function( error, res ult) {
  818                    call ed = true;
  819                    test Error = er ror;
  820                    test Result = r esult;
  821                };
  822  
  823                RpcClien t.callRpc( mockClient , 'ORWU US ERINFO', t estCallbac k);
  824  
  825                waitsFor (function( ) {
  826                    retu rn called;
  827                }, 'shou ld be call ed', 1000) ;
  828  
  829                runs(fun ction() {
  830                    expe ct(testErr or).toBeNu ll();
  831                    expe ct(testRes ult).toEqu al(respons e);
  832                });
  833           }) ;
  834       });
  835   });