I've been using this as well in my unit testing, just to execute the
Task Queue (unless I'm doing something totally wrong and queue
execution is supposed to actually work as part of
LocalTaskQueueTestConfig).

Code below, if it helps anyone.  I'm executing all queues against a
single servlet ("/data") and using parameters to differentiate
behaviors from there.

/**
     * GAE test harness doesn't include the servlet side of Task
Queues.  This article:
     *          
http://turbomanage.wordpress.com/2010/03/03/a-recipe-for-unit-testing-appengine-task-queues/
     * had some getting started tips, but it did not full work as-is,
so I tweaked it myself using
     * the ServletUnit examples.
     * @throws SAXException
     * @throws IOException
     */
    public static void ManuallyExecuteQueue() throws IOException,
SAXException
    {
        ServletRunner sr = new ServletRunner();
        sr.registerServlet("data",
HttpRequestServlet.class.getName());

        String queueName = "default";
        LocalTaskQueue taskQueue =
LocalTaskQueueTestConfig.getLocalTaskQueue();
        for(TaskStateInfo info :
taskQueue.getQueueStateInfo().get(queueName).getTaskInfo() )
        {
                // This causes an exception because no server is listening!
                // taskQueue.runTask(queueName, info.getTaskName());
                ServletUnitClient sc = sr.newClient();
            WebRequest request  = new PostMethodWebRequest( "http://
localhost:8080/data?" + info.getBody() );
            WebResponse response = sc.getResponse( request );

            // Check for success same as GAE Task runner will.
            assertTrue(response.getResponseCode() >= 200 &&
response.getResponseCode() <= 299);
        }

        // Flush task queue (removes all tasks)
        taskQueue.flushQueue(queueName);

        sr.shutDown();
    }















On Mar 9, 2:22 pm, "Ikai L (Google)" <[email protected]> wrote:
> Great news! I'll incorporate this into the article.
>
>
>
>
>
> On Tue, Mar 9, 2010 at 4:12 AM, legendlink <[email protected]> wrote:
> > Hi Ikai L,
>
> > I have tried simple HttpUnit test and it works. I just followed the
> > HttpUnit (ServletUnit) example in the link below.
>
> >http://httpunit.sourceforge.net/doc/servletunit-intro.html
>
> > I included the JUnit library + HttpUnit library in eclipse. and run
> > without errors. But I implemented it just like the sample.
>
> > Hope this helps!
>
> > On Mar 6, 4:02 am, "Ikai L (Google)" <[email protected]> wrote:
> >> I'm researching this right now for an article I plan on writing, but
> >> it's not one of my highest priorities. I've heard HTTPUnit works (I
> >> have also heard it doesn't work). Lastly, and I know this works for
> >> sure but it is ugly, you could use raw JUnit with the test in the same
> >> package (parallel directory structure), but there are many limitations
> >> of this approach.
>
> >> HTTPUnit:http://httpunit.sourceforge.net/
>
> >> Can you let the group know what you find?
>
> >> On Thu, Mar 4, 2010 at 8:24 PM, legendlink <[email protected]> wrote:
> >> > by the way, the error is ExceptionInInitializerError
> >> > at
> >> > org.apache.cactus.server.runner.ServletTestRunner.run(ServletTestRunner.jav
> >> >  a:
> >> > 297)
> >> > ...
> >> > caused by: java.security.accesscontrolexception: access denied
> >> > (java.io.filepermission dir\junit.properties read)
>
> >> > i guess it is impossible to use cactus since it can only access web-
> >> > inf files?
> >> > if cactus is not possible, is there any other alternatives to test
> >> > servlets?
>
> >> > On Mar 5, 12:08 pm, legendlink <[email protected]> wrote:
> >> >> hi,
> >> >> its really nice that there is local unit testing of datastore and
> >> >> other google implemented apis. i've been able to test it without
> >> >> problems.
>
> >> >> but i also wanted to test my servlets. i tried using cactus and
> >> >> included libraries of cactus in my project. and added the required
> >> >> web.xml servlet mappings for cactus to work in my project's web.xml
> >> >> i run the google dev server without problem but when i access the
> >> >> cactus test url it throws error..
>
> >> >> has anyone tried cactus on google app engine?
>
> >> > --
> >> > You received this message because you are subscribed to the Google 
> >> > Groups "Google App Engine for Java" group.
> >> > To post to this group, send email to 
> >> > [email protected].
> >> > To unsubscribe from this group, send email to 
> >> > [email protected].
> >> > For more options, visit this group 
> >> > athttp://groups.google.com/group/google-appengine-java?hl=en.
>
> >> --
> >> Ikai Lan
> >> Developer Programs Engineer, Google App 
> >> Enginehttp://googleappengine.blogspot.com|http://twitter.com/app_engine
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Google App Engine for Java" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/google-appengine-java?hl=en.
>
> --
> Ikai Lan
> Developer Programs Engineer, Google App 
> Enginehttp://googleappengine.blogspot.com|http://twitter.com/app_engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to