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
|
var TestApp = {
serverUrl:
'http://localhost:8080'
//'http://fjson/cgi-bin/fossil-json.cgi'
//'http://192.168.1.62:8080'
,
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. */
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){
|
|
>
>
|
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
|
var TestApp = {
serverUrl:
//'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'
,
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){
|
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
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);
}
testAnonymousLogin.description = 'Perform anonymous login.';
function testAnonWikiList(){
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;
}
});
}
testAnonWikiList.description = 'Fetch wiki list as anonymous user.';
function testAnonLogout(){
TestApp.fossil.logout({
onResponse:function(resp,req){
assertResponseOK(resp);
}
});
TestApp.fossil.logout({
onResponse:function(resp,req){
assertResponseError(resp);
}
});
}
testAnonLogout.description = 'Log out anonymous user.';
(function runAllTests(){
var testList = [
testHAI,
testIAmNobody,
testAnonymousLogin,
testAnonWikiList,
testAnonLogout
];
var i, f;
for( i = 0; i < testList.length; ++i ){
f = testList[i];
try{
print("Running test #"+(i+1)+": "+(f.description || "no description."));
|
>
>
>
|
>
>
>
>
>
>
>
|
>
>
|
|
|
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
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);
TestApp.fossil.userName = null;
TestApp.fossil.whoami('/json/whoami');
assert( 'string' === typeof TestApp.fossil.userName, 'User name = '+TestApp.fossil.userName);
}
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;
}
});
TestApp.fossil.sendCommand('/json/wiki/get',{
page:TestApp.wiki.list[0]
},{
onResponse:function(resp,req){
assertResponseOK(resp);
assert(resp.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations.");
print("Got first wiki page: "+WhAjaj.stringify(resp.payload));
}
});
}
testAnonWiki.description = 'Fetch wiki list as anonymous user.';
function testAnonLogout(){
TestApp.fossil.logout({
onResponse:function(resp,req){
assertResponseOK(resp);
}
});
TestApp.fossil.logout({
onResponse:function(resp,req){
assertResponseError(resp);
}
});
}
testAnonLogout.description = 'Log out anonymous user.';
(function runAllTests(){
var testList = [
testHAI,
testIAmNobody,
testAnonymousLogin,
testAnonWiki,
testAnonLogout
];
var i, f;
for( i = 0; i < testList.length; ++i ){
f = testList[i];
try{
print("Running test #"+(i+1)+": "+(f.description || "no description."));
|