1 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 17 public class NewMockSessionUnit extends WebUnit { 18 private static String SERVLET_NAME = "portal"; 19 private String servletName_ ; 20 private String uicomponent_ ; 21 private ServletRunner srunner_ ; 22 23 public NewMockSessionUnit(String name, String description) { 24 super(name, description) ; 25 srunner_ = new ServletRunner(); 26 } 27 28 public NewMockSessionUnit setServletName(String name) { 29 servletName_ = name ; 30 srunner_.registerServlet(SERVLET_NAME, servletName_); 31 return this ; 32 } 33 34 public NewMockSessionUnit setUIComponent(String component) { 35 uicomponent_ = component ; 36 return this ; 37 } 38 39 public WebResponse execute(WebResponse previousResponse, WebTable block, 40 ExoWebClient client) throws Exception { 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 getActionDescription() { 51 return "This web unit create a new mock session environment for the servlet" + servletName_ ; 52 } 53 } | Popular Tags |