You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Thomas Kettenbach <ke...@prostep.de> on 2001/12/06 16:32:34 UTC

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?

Please help,
Thomas



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Initialization of Servlets with IBM WSAD 4.0?

Posted by Vincent Massol <vm...@octo.com>.
Hi Thomas,

----- Original Message -----
From: "Thomas Kettenbach" <ke...@prostep.de>
To: <ca...@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:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>