| | @@ -1,7 +1,12 @@ |
| 1 | 1 | var TestApp = { |
| 2 | | - serverUrl:'http://localhost:8080' |
| 2 | + serverUrl: |
| 3 | + 'http://localhost:8080' |
| 4 | + //'http://fjson/cgi-bin/fossil-json.cgi' |
| 5 | + //'http://192.168.1.62:8080' |
| 6 | + , |
| 7 | + verbose:true |
| 3 | 8 | }; |
| 4 | 9 | (function bootstrap() { |
| 5 | 10 | var srcdir = '../js/'; |
| 6 | 11 | var includes = [srcdir+'json2.js', |
| 7 | 12 | srcdir+'whajaj.js', |
| | @@ -13,19 +18,25 @@ |
| 13 | 18 | WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino; |
| 14 | 19 | TestApp.fossil = new FossilAjaj({ |
| 15 | 20 | asynchronous:false, /* rhino-based impl doesn't support asynch. */ |
| 16 | 21 | url:TestApp.serverUrl, |
| 17 | 22 | beforeSend:function(req,opt){ |
| 18 | | - print("SENDING REQUEST: "+WhAjaj.stringify(opt)); |
| 23 | + if(!TestApp.verbose) return; |
| 24 | + print("SENDING REQUEST: opt="+JSON.stringify(opt)); |
| 25 | + if(req) print("Request="+WhAjaj.stringify(req)); |
| 19 | 26 | }, |
| 20 | 27 | afterSend:function(req,opt){ |
| 21 | | - print("SENT REQUEST: "+WhAjaj.stringify(opt)); |
| 28 | + if(!TestApp.verbose) return; |
| 29 | + print("SENT REQUEST: opt="+JSON.stringify(opt)); |
| 30 | + if(req) print("Request="+WhAjaj.stringify(req)); |
| 22 | 31 | }, |
| 23 | 32 | onError:function(req,opt){ |
| 33 | + if(!TestApp.verbose) return; |
| 24 | 34 | print("ERROR: "+WhAjaj.stringify(opt)); |
| 25 | 35 | }, |
| 26 | 36 | onResponse:function(resp,req){ |
| 37 | + if(!TestApp.verbose) return; |
| 27 | 38 | print("GOT RESPONSE: "+(('string'===typeof resp) ? resp : WhAjaj.stringify(resp))); |
| 28 | 39 | } |
| 29 | 40 | }); |
| 30 | 41 | })(); |
| 31 | 42 | |
| | @@ -33,12 +44,11 @@ |
| 33 | 44 | Throws an exception of cond is a falsy value. |
| 34 | 45 | */ |
| 35 | 46 | function assert(cond, descr){ |
| 36 | 47 | descr = descr || "Undescribed condition failed."; |
| 37 | 48 | if(!cond){ |
| 38 | | - print("Assertion failed: "+descr); |
| 39 | | - throw new Error(descr); |
| 49 | + throw new Error("Assertion failed: "+descr); |
| 40 | 50 | }else{ |
| 41 | 51 | print("Assertion OK: "+descr); |
| 42 | 52 | } |
| 43 | 53 | } |
| 44 | 54 | |
| | @@ -73,13 +83,20 @@ |
| 73 | 83 | !resp.resultCode. |
| 74 | 84 | */ |
| 75 | 85 | function assertResponseOK(resp){ |
| 76 | 86 | assert('object' === typeof resp,'Response is-a object.'); |
| 77 | 87 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 78 | | - assert( !resp.resultCode, 'Response contains no error state.'); |
| 88 | + assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode); |
| 79 | 89 | } |
| 80 | | - |
| 90 | +function assertResponseError(resp,expectCode){ |
| 91 | + assert('object' === typeof resp,'Response is-a object.'); |
| 92 | + assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 93 | + assert( resp.resultCode, 'resp.resultCode='+resp.resultCode); |
| 94 | + if(expectCode){ |
| 95 | + assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode ); |
| 96 | + } |
| 97 | +} |
| 81 | 98 | function testHAI(){ |
| 82 | 99 | TestApp.fossil.HAI({ |
| 83 | 100 | onResponse:function(resp,req){ |
| 84 | 101 | assertResponseOK(resp); |
| 85 | 102 | TestApp.serverVersion = resp.fossil; |
| | @@ -87,24 +104,33 @@ |
| 87 | 104 | }); |
| 88 | 105 | assert( 'string' === typeof TestApp.serverVersion, 'server version = '+TestApp.serverVersion); |
| 89 | 106 | } |
| 90 | 107 | testHAI.description = 'Get server version info.'; |
| 91 | 108 | |
| 92 | | -function testWhoAmI_1(){ |
| 109 | +function testIAmNobody(){ |
| 93 | 110 | TestApp.fossil.whoami('/json/whoami'); |
| 94 | 111 | assert('nobody' === TestApp.fossil.userName, 'User == nobody.' ); |
| 95 | | - assert('anonymous' !== TestApp.fossil.userName, 'User != anonymous.' ); |
| 96 | | - |
| 112 | + assert(!TestApp.fossil.authToken, 'authToken is not set.' ); |
| 113 | + |
| 114 | +} |
| 115 | +testIAmNobody.description = 'Ensure that current user is "nobody".'; |
| 116 | + |
| 117 | + |
| 118 | +function testAnonymousLogin(){ |
| 119 | + TestApp.fossil.login(); |
| 120 | + assert('string' === typeof TestApp.fossil.authToken, 'authToken = '+TestApp.fossil.authToken); |
| 121 | + assert( 'string' === typeof TestApp.fossil.userName, 'User name = '+TestApp.fossil.userName); |
| 97 | 122 | } |
| 98 | | -testWhoAmI_1.description = 'First ever fossil-over-rhino test.'; |
| 123 | +testAnonymousLogin.description = 'Perform anonymous login.'; |
| 99 | 124 | |
| 100 | 125 | |
| 101 | 126 | |
| 102 | 127 | (function runAllTests(){ |
| 103 | 128 | var testList = [ |
| 104 | 129 | testHAI, |
| 105 | | - testWhoAmI_1 |
| 130 | + testIAmNobody, |
| 131 | + testAnonymousLogin |
| 106 | 132 | ]; |
| 107 | 133 | var i, f; |
| 108 | 134 | for( i = 0; i < testList.length; ++i ){ |
| 109 | 135 | f = testList[i]; |
| 110 | 136 | try{ |
| 111 | 137 | |