Hi, all!

In the json branch, under ajax/i-test, i've started adding integration-style
tests which run against a fossil server or CGI. It uses the Rhino JS engine
to implement the connection logic, but uses the same client-side JavaScript
AJAX interface as the current browser-based test/demo code
(ajax/js/fossil-ajaj.js and friends).

For those who don't know: rhino is a JS engine implemented in Java, and is
built in to JDK6+. It ties in with the Java language, allowing JS code to
use Java classes and objects. That's how this ajax impl can communicate with
fossil: it uses java.net classes instantiated from JavaScript.

Here's a quick demo:


[stephan@cheyenne:~/cvs/fossil/fossil-json/ajax/i-test]$ which js
/usr/bin/js
[stephan@cheyenne:~/cvs/fossil/fossil-json/ajax/i-test]$ js rhino-test.js
Running #1: Get server version info.
SENDING REQUEST: AJAJ options={"method":"GET","url":"
http://localhost:8080/json/HAI","asynchronous":false,"timeout":10000}
ERROR: {
    "method": "GET",
    "url": "http://localhost:8080/json/HAI";,
    "asynchronous": false,
    "timeout": 10000,
    "errorMessage": "JavaException: java.net.ConnectException: Connection
refused"
}
Test failed: Error: Assertion failed: server version = undefined
js: "rhino-test.js", line 172: exception from uncaught JavaScript throw:
Error: Assertion failed: server version = undefined


That's what happens when the server/CGI isn't running. Once the server/CGI
is up:


[stephan@cheyenne:~/cvs/fossil/fossil-json/ajax/i-test]$ js rhino-test.js
Running test #1: Get server version info.
SENDING REQUEST: AJAJ options={"method":"GET","url":"
http://localhost:8080/json/HAI","asynchronous":false,"timeout":10000}
Assertion OK: Response is-a object.
Assertion OK: Response contains fossil property.
Assertion OK: resp.resultCode=undefined
Assertion OK: server version = 42a07be4c5460a1f461e42522aa07be217218be3
Running test #2: Ensure that current user is "nobody".
SENDING REQUEST: AJAJ options={"asynchronous":false,"url":"
http://localhost:8080/json/whoami","method":"GET","timeout":10000}
GOT RESPONSE: {
    "fossil": "42a07be4c5460a1f461e42522aa07be217218be3",
    "timestamp": 1317401247,
    "procTimeMs": 1,
    "payload": {
        "name": "nobody",
        "capabilities": "r"
    }
}
Assertion OK: User == nobody.
Assertion OK: authToken is not set.
Running test #3: Perform anonymous login.
SENDING REQUEST: AJAJ options={"method":"GET","url":"
http://localhost:8080/json/anonymousPassword
","asynchronous":false,"timeout":10000}
GOT RESPONSE: {
    "fossil": "42a07be4c5460a1f461e42522aa07be217218be3",
    "timestamp": 1317401247,
    "procTimeMs": 1,
    "payload": {
        "seed": 1409998474,
        "password": "9fb54989"
    }
}
SENDING REQUEST: AJAJ options={"asynchronous":false,"url":"
http://localhost:8080/json/login","method":"POST","timeout":10000}
Request envelope={
    "payload": {
        "name": "anonymous",
        "password": "9fb54989",
        "anonymousSeed": 1409998474
    },
    "requestId": "WhAjaj.Connector-1317401247513/88720268:1"
}
GOT RESPONSE: {
    "fossil": "42a07be4c5460a1f461e42522aa07be217218be3",
    "timestamp": 1317401247,
    "requestId": "WhAjaj.Connector-1317401247513/88720268:1",
    "procTimeMs": 1,
    "payload":
"a3351f00dcc9985fb9d78440abe5af622729c0fb/2455835.19962418/anonymous"
}
Assertion OK: authToken =
a3351f00dcc9985fb9d78440abe5af622729c0fb/2455835.19962418/anonymous
Assertion OK: User name = anonymous
Running test #4: Fetch wiki list as anonymous user.
SENDING REQUEST: AJAJ options={"method":"POST","url":"
http://localhost:8080/json/wiki/list","asynchronous":false,"timeout":10000}
Request envelope={
    "requestId": "WhAjaj.Connector-1317401247534/42079623:2",
    "authToken":
"a3351f00dcc9985fb9d78440abe5af622729c0fb/2455835.19962418/anonymous"
}
Assertion OK: Request envelope contains expected authToken.
Assertion OK: Response is-a object.
Assertion OK: Response contains fossil property.
Assertion OK: resp.resultCode=undefined
Assertion OK: Wiki list seems to be okay.
Running test #5: Log out anonymous user.
SENDING REQUEST: AJAJ options={"asynchronous":false,"url":"
http://localhost:8080/json/logout","method":"POST","timeout":10000}
Request envelope={
    "requestId": "WhAjaj.Connector-1317401247562/79297587:3",
    "authToken":
"a3351f00dcc9985fb9d78440abe5af622729c0fb/2455835.19962418/anonymous"
}
Assertion OK: Response is-a object.
Assertion OK: Response contains fossil property.
Assertion OK: resp.resultCode=undefined
SENDING REQUEST: AJAJ options={"asynchronous":false,"url":"
http://localhost:8080/json/logout","method":"GET","timeout":10000}
Assertion OK: Response is-a object.
Assertion OK: Response contains fossil property.
Assertion OK: resp.resultCode=FOSSIL-2001
Done!


-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to