Permalink
Browse files

Updated node and rhino test servers to use new testing protocol that …

…relies on passing around URL to test SCXML file, rather than the document encoded directly as a string in JSON. Also, fixed two small bugs in the rhino platform adapter.
  • Loading branch information...
1 parent ca319d6 commit 317fb4d2ef520db7144af45b514dcd38bbd1ad43 @jbeard4 committed Jul 16, 2012
Showing with 25 additions and 27 deletions.
  1. +1 −1 lib/core/util/docToModel.js
  2. +2 −2 lib/rhino/platform.js
  3. +1 −1 test/node-test-server.js
  4. +21 −23 test/rhino-test-server.js
View
2 lib/core/util/docToModel.js
@@ -15,7 +15,7 @@ function documentToModel(url,doc,cb){
inlineSrcs(url,scxmlJson,function(errors){
if(errors){
//I think we should probably just log any of these errors
- console.error("Errors downloading src attributes");
+ platform.log("Errors downloading src attributes",errors);
}
scxmlJsonToModel(scxmlJson,cb);
});
View
4 lib/rhino/platform.js
@@ -9,7 +9,7 @@ function getDb(){
module.exports = {
- pathSeparator : Packages.java.lang.System.getProperty('path.separator'),
+ pathSeparator : Packages.java.lang.System.getProperty('file.separator'),
//used in parsing
getDocumentFromUrl : function(url,cb){
@@ -46,7 +46,7 @@ module.exports = {
log : function(){
for(var i=0; i < arguments.length; i++){
- Packages.java.lang.System.out.println(arguments[i]);
+ Packages.java.lang.System.out.println(String(arguments[i]));
}
}
};
View
2 test/node-test-server.js
@@ -28,7 +28,7 @@ http.createServer(function (req, res) {
if(reqJson.load){
console.log("Loading new statechart");
- scion.documentStringToModel(reqJson.load,function(err,model){
+ scion.urlToModel(reqJson.load,function(err,model){
if(err){
console.error(err);
res.writeHead(500, {'Content-Type': 'text/plain'});
View
44 test/rhino-test-server.js
@@ -14,21 +14,6 @@ var server = HttpServer.create(addr, 0);
var sessionCounter = 0, sessions = {}, timeouts = {}, timeoutMs = 5000;
-function loadScxml(scxmlStr,cb){
- scion.documentStringToModel(scxmlStr,function(err,model){
- if(err){
- throw err;
- }
-
- var interpreter = new scion.SCXML(model);
-
- var sessionToken = sessionCounter;
- sessionCounter++;
- sessions[sessionToken] = interpreter;
-
- cb(sessionToken,interpreter);
- });
-}
function cleanUp(sessionToken){
delete sessions[sessionToken];
@@ -57,16 +42,29 @@ var handler = new HttpHandler({handle : function(exchange){
var reqJson = JSON.parse(s);
if(reqJson.load){
print("Loading new statechart");
- loadScxml(reqJson.load,function(sessionToken,interpreter){
- var conf = interpreter.start();
- responseHeaders.set("Content-Type", "application/json");
- exchange.sendResponseHeaders(200, 0);
- responseBody.write(toBytes({
- sessionToken : sessionToken,
- nextConfiguration : conf
- }));
+ scion.urlToModel(reqJson.load,function(err,model){
+
+ if(err){
+ exchange.sendResponseHeaders(500, 0);
+ responseBody.write(toBytes(err.message));
+ }else{
+ var interpreter = new scion.SCXML(model);
+
+ var sessionToken = sessionCounter;
+ sessionCounter++;
+ sessions[sessionToken] = interpreter;
+
+ var conf = interpreter.start();
+
+ responseHeaders.set("Content-Type", "application/json");
+ exchange.sendResponseHeaders(200, 0);
+ responseBody.write(toBytes({
+ sessionToken : sessionToken,
+ nextConfiguration : conf
+ }));
+ }
responseBody.close();
//timeouts[sessionToken] = setTimeout(function(){cleanUp(sessionToken);},timeoutMs);

0 comments on commit 317fb4d

Please sign in to comment.