jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pedro Nevado" <pnev...@javato.com>
Subject RE: Sample Cactus project-specifically JSP example
Date Wed, 16 Nov 2005 21:00:47 GMT
Nagaraj,
I enclose some code of a Cactus test for a login page. As I said before, I
do not think you will find it useful.
Cactus can be used in several ways; for example, here it is used to test a
Struts Action. I do not code any logic in the JSP's, because I prefer a MVC
architecture, so the only thing to test in JSP's is the state of same
request or session attributes.
Regards,
Pedro



/**
 * @author Pedro Nevado
 * @version $ Date: 14-jun-2005 18:27:14 $
 */
public class LoginActionTest extends ServletTestCase {

    private RequestDispatcher dispatcher;
    private static final String LISTA_CAMPAGNAS_TEXTO_IDENTIFICADOR
            = "Plataforma: campa&ntilde;as realizadas";
    private static final String LOGIN_TEXTO_IDENTIFICADOR = "Plataforma:
login";

    // ................................... MÉTODOS COMUNES
....................................

    public void begin(WebRequest request) {
    }

    protected void setUp() {
        dispatcher = request.getRequestDispatcher("/login_Submit.do");
        assert dispatcher != null : "dispatcher not null";
    }

    protected void tearDown() {}

    public void end(WebResponse response) {
    }

    //................................. TEST CASO_1
..........................................

    /**
     * Usuario bien identificado.
     * @param request
     */
    public void beginCaso_1(WebRequest request) {
        request.addParameter("usuario", "123456L", WebRequest.POST_METHOD);
        request.addParameter("password", "leben", WebRequest.POST_METHOD);
    }

    public void testCaso_1() throws IOException, ServletException {
        dispatcher.forward(request, response);
        session = request.getSession(true);
        String usuario = (String)
session.getAttribute(Constants.USUARIO_EN_SESSION);
        assertNotNull("usario not null en la sesión", usuario);
        assertEquals("usuario ok", "123456L", usuario);
    }

    public void endCaso_1(WebResponse response) {
        String jspText = response.getText();
        // Como el password era correcto, se le da acceso.
        assertTrue("jsp listado campañas",
jspText.indexOf(LISTA_CAMPAGNAS_TEXTO_IDENTIFICADOR) >= 0);
    }

    //................................. TEST CASO_2
..........................................

    /**
     * Usuario mal identificado: no existe su combinación de password y
usuario.
     *
     * @param request
     */
    public void beginCaso_2(WebRequest request) {
        request.addParameter("usuario", "123456L", WebRequest.POST_METHOD);
        // password incorrecto.
        request.addParameter("password", "lebenn", WebRequest.POST_METHOD);
    }

    public void testCaso_2() throws IOException, ServletException {
        dispatcher.forward(request, response);
        session = request.getSession(true);
        String usuario = (String)
session.getAttribute(Constants.USUARIO_EN_SESSION);
        assertNull("usario null en la sesión", usuario);
    }

    public void endCaso_2(WebResponse response) {
        String jspText = response.getText();
        // Se le devuelve a la página de login con mensaje de error.
        assertTrue("jsp listado campañas",
jspText.indexOf(LOGIN_TEXTO_IDENTIFICADOR) >= 0);
    }
}

-----Mensaje original-----
De: Nagaraj Palanichamy [mailto:nagaraj.palanichamy@gmail.com]
Enviado el: miércoles, 16 de noviembre de 2005 14:10
Para: Cactus Users List
Asunto: Re: Sample Cactus project-specifically JSP example


Pedro,
 Thanks a lot for your timely reply. I really apperciate you for this
one.Ihave gone through that cactus site. But i feel i need some more
assitance.
Like, i just need a test page which should test a simple JSP page which
contains some Java statements and HTML Statments. Not even testing the tag
library. So that from there onwards i can kick-off my process. I hope you
understand my problem. If you have it , please send it to me.
  Thank you
Nagaraj P

 On 11/16/05, Pedro Nevado <pnevado@javato.com> wrote:
>
> Nagaraj, let me to refer you to the Cactus Home page.
> If you want to see a sample of a class to test a Jsp, you will find there
> one. If you want to know how to configure you client and server runtimes,
> you also will find there valuable assistance.
> I do not think you would find more useful just seeing a couple of classes
> of
> a project or a real execution script. Besides, take into account that the
> everyday life of Cactus tests depends on very particular factors: the
> integration of JUnit with your favourite IDE, for example, or your
> preferences for Ant or Maven, etc..
> Regards,
> Pedro
>
> -----Mensaje original-----
> De: Nagaraj Palanichamy [mailto:nagaraj.palanichamy@gmail.com]
> Enviado el: miércoles, 16 de noviembre de 2005 12:39
> Para: cactus-user@jakarta.apache.org
> Asunto: Sample Cactus project-specifically JSP example
>
>
> Dear Sir/Madam,
> I am New to this cactus world. I need some help. If you any one of you
> have
> catcus project, Please send it me. My requirement is , i just wants to
> some
> JSP Pages. So If you have any such kind of example project, please send it
> to me.
> Thank you
> Nagaraj P
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>



Mime
View raw message