Fossil

Diff
Login

Differences From Artifact [454163a92c]:

To Artifact [5000b787cb]:


1
2
3

4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43






















44
45
46
47
48
49
50
1
2

3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23




















24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52


-
+


-
+

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







var TestApp = {
    serverUrl:
        //'http://localhost:8080'
        'http://localhost:8080'
        //'http://fjson/cgi-bin/fossil-json.cgi'
        //'http://192.168.1.62:8080'
        'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
        //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
        ,
    verbose:true,
    wiki:{}
};
(function bootstrap() {
    var srcdir = '../js/';
    var includes = [srcdir+'json2.js',
                    srcdir+'whajaj.js',
                    srcdir+'fossil-ajaj.js'
                    ];
    for( var i in includes ) {
        load(includes[i]);
    }
    WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
    TestApp.fossil = new FossilAjaj({
        asynchronous:false, /* rhino-based impl doesn't support async or timeout. */
        timeout:0,
        url:TestApp.serverUrl,
        beforeSend:function(req,opt){
            if(!TestApp.verbose) return;
            print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
            if(req) print("Request envelope="+WhAjaj.stringify(req));
        },
        afterSend:function(req,opt){
            //if(!TestApp.verbose) return;
            //print("REQUEST RETURNED: opt="+JSON.stringify(opt));
            //if(req) print("Request="+WhAjaj.stringify(req));
        },
        onError:function(req,opt){
            if(!TestApp.verbose) return;
            print("ERROR: "+WhAjaj.stringify(opt));
        },
        onResponse:function(resp,req){
            if(!TestApp.verbose) return;
            print("GOT RESPONSE: "+(('string'===typeof resp) ? resp : WhAjaj.stringify(resp)));
        }
    });
        url:TestApp.serverUrl
    });
    var cb = TestApp.fossil.ajaj.callbacks;
    cb.beforeSend = function(req,opt){
        if(!TestApp.verbose) return;
        print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
        if(req) print("Request envelope="+WhAjaj.stringify(req));
    };
    cb.afterSend = function(req,opt){
        //if(!TestApp.verbose) return;
        //print("REQUEST RETURNED: opt="+JSON.stringify(opt));
        //if(req) print("Request="+WhAjaj.stringify(req));
    };
    cb.onError = function(req,opt){
        if(!TestApp.verbose) return;
        print("ERROR: "+WhAjaj.stringify(opt));
    };
    cb.onResponse = function(resp,req){
        if(!TestApp.verbose) return;
        print("GOT RESPONSE: "+(('string'===typeof resp) ? resp : WhAjaj.stringify(resp)));
    };
    
})();

/**
    Throws an exception of cond is a falsy value.
*/
function assert(cond, descr){
    descr = descr || "Undescribed condition.";
113
114
115
116
117
118
119
120
121


122
123
124
125
126
127
128
129
130


131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
115
116
117
118
119
120
121


122
123
124
125
126
127
128
129
130


131
132
133
134

135
136
137
138
139
140
141

142
143
144
145
146
147
148







-
-
+
+







-
-
+
+


-
+






-







    });
    assert( 'string' === typeof TestApp.serverVersion, 'server version = '+TestApp.serverVersion);
}
testHAI.description = 'Get server version info.';

function testIAmNobody(){
    TestApp.fossil.whoami('/json/whoami');
    assert('nobody' === TestApp.fossil.userName, 'User == nobody.' );
    assert(!TestApp.fossil.authToken, 'authToken is not set.' );
    assert('nobody' === TestApp.fossil.auth.name, 'User == nobody.' );
    assert(!TestApp.fossil.auth.authToken, 'authToken is not set.' );
   
}
testIAmNobody.description = 'Ensure that current user is "nobody".';


function testAnonymousLogin(){
    TestApp.fossil.login();
    assert('string' === typeof TestApp.fossil.authToken, 'authToken = '+TestApp.fossil.authToken);
    assert( 'string' === typeof TestApp.fossil.userName, 'User name = '+TestApp.fossil.userName);
    assert('string' === typeof TestApp.fossil.auth.authToken, 'authToken = '+TestApp.fossil.auth.authToken);
    assert( 'string' === typeof TestApp.fossil.auth.name, 'User name = '+TestApp.fossil.auth.name);
    TestApp.fossil.userName = null;
    TestApp.fossil.whoami('/json/whoami');
    assert( 'string' === typeof TestApp.fossil.userName, 'User name = '+TestApp.fossil.userName);
    assert( 'string' === typeof TestApp.fossil.auth.name, 'User name = '+TestApp.fossil.auth.name);
}
testAnonymousLogin.description = 'Perform anonymous login.';

function testAnonWiki(){
    TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
        beforeSend:function(req,opt){
            TestApp.fossil.ajaj.options.beforeSend(req,opt);
            assert( req && (req.authToken==TestApp.fossil.authToken), 'Request envelope contains expected authToken.'  );
        },
        onResponse:function(resp,req){
            assertResponseOK(resp);
            assert( (typeof [] === typeof resp.payload) && resp.payload.length,
                "Wiki list seems to be okay.");
            TestApp.wiki.list = resp.payload;