Dear Wiki user, You have subscribed to a wiki page or wiki category on "Jakarta-velocity Wiki" for change notification.
The following page has been changed by ShinobuKawaiYoshida: http://wiki.apache.org/jakarta-velocity/TestingVelocity The comment on the change is: Cactus integeration. ------------------------------------------------------------------------------ } }}} + '''''Approach 4:''''' Cactus integeration. + + You can test Velocity templates in your web application by integerating [http://jakarta.apache.org/cactus/ Cactus] with !VelocityViewServlet. + + If your template at {{{/test/test.vm}}} looks like this: + {{{ + <html> + <body> + Hello $user ! + </body> + </html> + }}} + Then your !TestCase might look like this: + {{{ + import org.apache.cactus.ServletTestCase; + import org.apache.cactus.WebRequest; + import org.apache.cactus.WebResponse; + import org.apache.velocity.tools.view.servlet.VelocityViewServlet; + + public class VelocityTest extends ServletTestCase + { + + public void beginTestVelocity(WebRequest theRequest) + { + theRequest.setURL("localhost:8080", "/CactusDemo", "/test/test.vm", null, null); + } + + public void testTestVelocity() throws Exception + { + VelocityViewServlet servlet = new VelocityViewServlet(); + servlet.init(this.config); + + this.request.setAttribute("user", "Servlet User from Cactus"); + + servlet.doGet(this.request, this.response); + } + + public void endTestVelocity(WebResponse theResponse) + { + String expected = "" + + "<html>\n" + + " <body>\n" + + " Hello Servlet User from Cactus !\n" + + " </body>\n" + + "</html>\n" + + ""; + + assertEquals(expected, theResponse.getText()); + } + } + }}} + This assumes that you are running your web application at {{{http://localhost:8080/CactusDemo/}}}. + --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
