jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Massol" <vmas...@octo.com>
Subject Re: Initialization of Servlets with IBM WSAD 4.0?
Date Thu, 06 Dec 2001 15:45:17 GMT
Hi Thomas,

----- Original Message -----
From: "Thomas Kettenbach" <kettenbach@prostep.de>
To: <cactus-user@jakarta.apache.org>
Sent: Thursday, December 06, 2001 3:32 PM
Subject: Initialization of Servlets with IBM WSAD 4.0?


> The servlets i like to test need some init-params provided in the web.xml
> file for my web-app. If i create a servlet within a cactus test case, are
> these
> parameters automaticly provided by the ServletRedirector? Or do i need
> to configure something?

With the current version, you have 2 solutions :

* Solution 1 : put these init-parameter under the configuration of the
ServletRedirector, in web.xml. The config implicit object that is provided
will then contain the data.
* Solution 2 : use the config.setInitParameter(name, value) at the beginning
of your testXXX() method. Then any subsequent call to
config.getInitParameterNames() or config.getInitParameter(name) will return
the values you have set up.

Here is an example extracted from TestServletTestCase2.java (from the sample
application provided with cactus) :

    /**
     * Verify that we can add parameters to the config list of parameters
     * programatically, without having to define them in
<code>web.xml</code>.
     */
    public void testSetConfigParameter()
    {
        config.setInitParameter("testparam", "test value");

        assertEquals("test value", config.getInitParameter("testparam"));

        boolean found = false;
        Enumeration enum = config.getInitParameterNames();
        while(enum.hasMoreElements()) {
            String name = (String)enum.nextElement();
            if (name.equals("testparam")) {
                found = true;
                break;
            }
        }

        assert("[testparam] not found in parameter names", found);
    }

Hope it helps
-Vincent

>
> Please help,
> Thomas
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:cactus-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:cactus-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@jakarta.apache.org>


Mime
View raw message