The Artima Developer Community
Sponsored Link

Java Buzz Forum
Testing WebWork

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Carlos Villela

Posts: 116
Nickname: cvillela
Registered: Jun, 2003

Carlos Villela is a Java developer working mostly with web technologies and AOP.
Testing WebWork Posted: Jun 28, 2003 1:54 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Carlos Villela.
Original Post: Testing WebWork
Feed Title: That's sooo '82!
Feed URL: http://www.jroller.com/rss/cv?catname=Technical
Feed Description: Carlos Villela's weblog. Everyday life, everyday software development, everyday musings.
Latest Java Buzz Posts
Latest Java Buzz Posts by Carlos Villela
Latest Posts From That's sooo '82!

Advertisement
Testing WebWork stuff is just awesome! I've found a way to easily test any JavaScript action, and if you liked my little irresponsible lame HOWTO a few posts ago, you'll find this interesting. I'll post the source code directly, it's easier read than explained.

import java.util.HashMap;
import java.util.Map;
import webwork.action.standard.Script;

(...)

private static final String NAME = "John Smith";

public void testHelloWithNameParameter() throws Exception {
    Script script = new Script(); // Create a new Script Action object
    script.setScript("hello.js"); // Load a script

    // Parameters Map that'll hold the name to greet
    Map params = new HashMap();
    params.put("name", new String[] { NAME }); // every parameter needs to be a Sting[]
    script.setParameters(params);

    String result = script.execute();
    assertEquals(Script.SUCCESS, result);
       
    Map results = script.getResults();
    assertEquals(NAME, results.get("name"));
    assertNotNull(results.get("today"));
}


Could this get easier/nicer? I'm not really into TDD, so I'm probably making some mistakes here. If you think so, please drop a comment.

Read: Testing WebWork

Topic: Java and Scripting Languages Previous Topic   Next Topic Topic: Typed vs. Loosely Typed, the Debate Continues:

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use