jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Franz Roth" <franzr...@gmx.de>
Subject Re: Can I pass parameters to ServletTestCase ?
Date Fri, 24 Nov 2006 10:17:26 GMT
Hi,

I think all should be fine documented at the cactus project-page, somtimes  
somone says: read the f* manual, well here's a simple sample:


import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;
import org.apache.log4j.Logger;

import **.**.FRLoggerFactory;

public class TestSimple extends ServletTestCase {
	
	private Logger _log;
	public void beginTest(WebRequest theRequest) {
		_log= FRLoggerFactory.getLog();
		_log.info("beginTest");
		theRequest.addParameter("test", "value");
	}
	public void testTest() {
		try {
			TestServlet writer= new TestServlet();
			writer.init(config);
			writer.doPost(request, response);
		}
		catch (Exception e) {
			_log.error("", e);
		}
	}
	public void endTest(WebResponse theResponse) {
		String[] result= theResponse.getTextAsArray();
		_log.debug("and here's the result:");
		for (int i = 0; i < result.length; i++) {
			_log.debug(result[i]);
		}
		
	}
	class TestServlet extends HttpServlet {
		private static final long serialVersionUID = 1L;

		protected void doPost(HttpServletRequest req,
				HttpServletResponse resp) {
			Logger log= FRLoggerFactory.getLog();
			log.debug("got a param: " + req.getParameter("test"));
			try {
				PrintWriter out= resp.getWriter();
				out.println("<html>\n" +
						"<head><title>TestSimle</title>\n" +
						"</head>\n" +
						"<body><h3>All is fine done ...</h3>\n" +
						"</body></html>");
			}
			catch(Exception e) {
				log.error("", e);
			}
		}
	}
}



Am 22.11.2006, 16:26 Uhr, schrieb Jean-Charles Giardina  
<jc.giardina@gmail.com>:

> Hi,
>
> Can I pass URL parameters to a ServletTestCase ?
> I want to test more and more value with the same test method.
> I don't want to recompile to change value.
>
> I want to use an URL like :
>   http://localhost/ServletTestRunner?suite=my.tests.MyTest&foo=bar
> where "foo" is the parameter name and "bar" is the parameter value.
>
> Thks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org



-- 
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/

Mime
View raw message