01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.portlet.context;
06:
07: import javax.servlet.ServletConfig;
08: import javax.servlet.ServletContext;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11:
12: import org.easymock.MockControl;
13:
14: import com.opensymphony.webwork.ServletActionContext;
15: import com.opensymphony.xwork.ActionContext;
16:
17: import junit.framework.TestCase;
18:
19: /**
20: *
21: * Test for the {@link PreparatorServletTest}
22: *
23: * @author Nils-Helge Garli
24: *
25: */
26: public class PreparatorServletTest extends TestCase {
27:
28: /**
29: * Test that the service method stores the request, response and servlet context
30: * in the {@link com.opensymphony.xwork.ActionContext}
31: */
32: public void testServiceHttpServletRequestHttpServletResponse()
33: throws Exception {
34: MockControl mockRequest = MockControl
35: .createNiceControl(HttpServletRequest.class);
36: MockControl mockResponse = MockControl
37: .createNiceControl(HttpServletResponse.class);
38: MockControl mockContext = MockControl
39: .createNiceControl(ServletContext.class);
40: MockControl mockConfig = MockControl
41: .createNiceControl(ServletConfig.class);
42:
43: HttpServletRequest req = (HttpServletRequest) mockRequest
44: .getMock();
45: HttpServletResponse res = (HttpServletResponse) mockResponse
46: .getMock();
47: ServletContext context = (ServletContext) mockContext.getMock();
48: ServletConfig config = (ServletConfig) mockConfig.getMock();
49:
50: mockConfig.expectAndDefaultReturn(config.getServletContext(),
51: context);
52: mockConfig.replay();
53:
54: PreparatorServlet servlet = new PreparatorServlet();
55: servlet.init(config);
56: servlet.service(req, res);
57: assertSame(req, ServletActionContext.getRequest());
58: assertSame(res, ServletActionContext.getResponse());
59: assertSame(context, ServletActionContext.getServletContext());
60:
61: mockConfig.verify();
62: }
63:
64: }
|