testing appenginejs in ringojs console - 23 Dec 2010



For my ringopress project, i am doing a plugin system, and to test it, i am taking some wordpress plugins - the most popular ones - and implement them in javascript.

They say the most popular is akismet, so it seems that I have a job for tonight. I found a java akismet library - thank you ringojs and rhino for being on JVM - so it seemed like in 30 minutes i could go to bed.

I tested it a little in the ringo console, all fine, started google appengine local server and it said socket class use forbidden.

I forgot about that. Akismet java lib was using the apache httpclient and it boiled down finally to socket. Didn't mind that, i have been warned by google about this, happened as it should. good.

Well, let's make the akismet plugin with appenginejs lib based on urlfetch. I should use this lib in more places, though i still cannot drop the model and storage ringojs has built in, the abstraction is too nice.

First, let's play a little with it and do some exploratory programming. Before starting ringo console , we should place appenginejs package into ${RINGOJS_FOLDER}/packages/. next, place: ${JAVA_APPENGINE_GOOGLE_SDK_FOLDER}/lib/impl/appengine-api.jar,${JAVA_APPENGINE_GOOGLE_SDK_FOLDER}/lib/impl/appengine-api-labs.jar,${JAVA_APPENGINE_GOOGLE_SDK_FOLDER}/lib/impl/appengine-api-stubs.jar,${JAVA_APPENGINE_GOOGLE_SDK_FOLDER}/lib/impl/appengine-api.jar,${JAVA_APPENGINE_GOOGLE_SDK_FOLDER}/lib/testing/appengine-testing.jar into ${RINGOJS_FOLDER}/lib/ folder.

now we are ready to rock:

ringo >>

First, we have to setup a google appengine environment in order for appengine API calls work, and we do it as they do when they prepare unit testing environment.

>> var localServiceTestHelper = com.google.appengine.tools.development.testing.LocalServiceTestHelper; >> var localURLFetchServiceTestConfig = com.google.appengine.tools.development.testing.LocalURLFetchServiceTestConfig; >> var helper = new localServiceTestHelper(new localURLFetchServiceTestConfig());

If we would have wanted to play with storage, we would have used LocalDatastoreServiceTestConfig in addition to LocalURLFetchServiceTestConfig. you can see them all if you look inside appengine-testing.jar. next we do:

>> helper.setUp();

and we have our environment ready to serve us. You can place all above statements into a js file and execute it automatically at startup:

ringo -b gae-env.js

so you can be more productive.

i grabbed the example from here: http://www.appenginejs.org/docs#urlfetch

var fetch = require("google/appengine/api/urlfetch").fetch; var response = fetch("http://www.appenginejs.org"), html = response.content.decodeToString("UTF-8");

and there you go. GAE on your ringojs command line.

No comments yet.
Leave a comment:

author
email
website
Comment