Re: Can I pass parameters to ServletTestCase ?

"Franz Roth" <[email protected]>
Newsgroups gmane.comp.jakarta.cactus.user
Message-ID <[email protected]>
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  
<[email protected]>:

> 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: [email protected]
> For additional commands, e-mail: [email protected]



-- 
Erstellt mit Operas revolutionÀrem E-Mail-Modul: http://www.opera.com/mail/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.