KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > web > unit > NewMockSessionUnit


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.test.web.unit;
6
7 import org.exoplatform.test.web.ExoWebClient;
8 import com.meterware.httpunit.*;
9 import com.meterware.servletunit.ServletRunner;
10 import com.meterware.servletunit.ServletUnitClient;
11 /**
12  * May 21, 2004
13  * @author: Tuan Nguyen
14  * @email: tuan08@users.sourceforge.net
15  * @version: $Id: NewMockSessionUnit.java,v 1.1 2004/10/11 23:36:06 tuan08 Exp $
16  **/

17 public class NewMockSessionUnit extends WebUnit {
18   private static String JavaDoc SERVLET_NAME = "portal";
19     private String JavaDoc servletName_ ;
20   private String JavaDoc uicomponent_ ;
21   private ServletRunner srunner_ ;
22   
23   public NewMockSessionUnit(String JavaDoc name, String JavaDoc description) {
24     super(name, description) ;
25     srunner_ = new ServletRunner();
26   }
27   
28   public NewMockSessionUnit setServletName(String JavaDoc name) {
29     servletName_ = name ;
30     srunner_.registerServlet(SERVLET_NAME, servletName_);
31     return this ;
32   }
33   
34   public NewMockSessionUnit setUIComponent(String JavaDoc component) {
35     uicomponent_ = component ;
36     return this ;
37   }
38   
39   public WebResponse execute(WebResponse previousResponse, WebTable block,
40                                                          ExoWebClient client) throws Exception JavaDoc {
41     ServletUnitClient webClient = srunner_.newClient();
42     WebRequest request = new GetMethodWebRequest("http://localhost/" + SERVLET_NAME);
43     request.setParameter("component", uicomponent_) ;
44     client.setWebClient(webClient) ;
45     client.setHomePageURL("http://localhost/" + SERVLET_NAME) ;
46     WebResponse response = webClient.getResponse( request );
47     return response ;
48   }
49   
50   public String JavaDoc getActionDescription() {
51     return "This web unit create a new mock session environment for the servlet" + servletName_ ;
52   }
53 }
Popular Tags