Thanks Jari !
I'll commit this ASAP. And don't worry about the format (the preferred
method is to do a diff but what you have provided is fine with me) !
Vincent.
----- Original Message -----
From: "Jari Worsley" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 21, 2001 4:18 PM
Subject: [cactus][patch]Query String to request parameters
> [code] Automatically add the query string parameters defined when using
> the ServletTestRequest.setURL() API to the list of parameters passed to
> the server redirector, so that it won't be necessary to call
> ServletTestRequest.addParameter() for each of these parameters.
>
> I have changed ServletTestRequest and TestServletTestCase4 to put this
> in for myself. The changes are shown below. Not sure how to submit a
> patch or change as I've not done it before (tried to contribute to an
> open source project that is).
>
> Is this enough? Sorry I've tried to do the cvs diff, but don't seem to
> get anything useful from it - it seems to complain about the whole damn
> file, not just the few method changes.
>
> Jari
>
> In ServletTestRequest:
> > public void setURL(String theServerName, String theContextPath,
> > String theServletPath, String thePathInfo, String
theQueryString)
> > {
> > m_URL = new ServletURL(theServerName, theContextPath,
> > theServletPath, thePathInfo, theQueryString);
> > addQueryStringParameters( theQueryString);
> > }
> >
> > private void addQueryStringParameters(String theQueryString)
> > {
> > if (theQueryString == null)
> > return;
> >
> > // now addParameters for querystring
> > // actually - might need to remove old if m_URL != null;
> > String nameValue = null;
> > StringTokenizer tokenizer =
> > new StringTokenizer(theQueryString, "&");
> > int breakParam = -1;
> > try {
> > while (tokenizer.hasMoreTokens() )
> > {
> > nameValue =tokenizer.nextToken();
> > breakParam = nameValue.indexOf("=");
> > if (breakParam != -1)
> > {
> > addParameter(nameValue.substring(0, breakParam),
> >
nameValue.substring(breakParam+1));
> >
> > }
> > else
> > {
> > throw new junit.framework.AssertionFailedError("Bad
QueryString [" + theQueryString + "] NameValue pair: [" + nameValue + "]");
> > }
> > }
> > } catch (NoSuchElementException s) {
> > throw new junit.framework.AssertionFailedError("Bad
QueryString [" + theQueryString + "]");
> > }
> > }
>
> and in
> TestServletTestCase4.java
> > /**
> > * Verify that we can simulate different parts of the URL.
> > * Set 5 of test values (taken from Sun's Servlet API spec)
> > */
> > public void testSimulatedURL5()
> > {
> > assertEquals("jakarta.apache.org", request.getServerName());
> > assertEquals("/catalog/help/feedback.jsp",
request.getRequestURI());
> > assertEquals(80, request.getServerPort());
> > assertEquals("/catalog", request.getContextPath());
> > assertEquals("/help/feedback.jsp", request.getServletPath());
> > assert(request.getPathInfo() == null);
> > assertEquals("PARAM1=param1&PARAM2=param2",
request.getQueryString());
> > assertEquals(request.getParameter("PARAM1"), "param1");
> > assertEquals(request.getParameter("PARAM2"), "param2");
> > }
> >
> >
//-------------------------------------------------------------------------
> >
> > /**
> > * Verify that we can simulate different parts of the URL.
> > * can't find the sun servlet spec tests, so this is made up.
> > *
> > * @param theRequest the request object that serves to initialize
the
> > * HTTP connection to the server redirector.
> > */
> > public void beginSimulatedURL6(ServletTestRequest theRequest)
> > {
> > theRequest.setURL("jakarta.apache.org", "/catalog",
"/help/feedback.jsp", null, "PARAM1=&PARAM2=param2");
> > }
> >
> > /**
> > * Verify that we can simulate different parts of the URL.
> > * made up test for empty value.
> > */
> > public void testSimulatedURL6()
> > {
> > assertEquals("jakarta.apache.org", request.getServerName());
> > assertEquals("/catalog/help/feedback.jsp",
request.getRequestURI());
> > assertEquals(80, request.getServerPort());
> > assertEquals("/catalog", request.getContextPath());
> > assertEquals("/help/feedback.jsp", request.getServletPath());
> > assert(request.getPathInfo() == null);
> > assertEquals("PARAM1=&PARAM2=param2", request.getQueryString());
> > assertEquals(request.getParameter("PARAM1"), "");
> > assertEquals(request.getParameter("PARAM2"), "param2");
> > }
> >
>
>
>
> --
> Jari Worsley
> Senior Programmer
> Hyperlink Interactive Ltd
>