View Javadoc

1   /*
2    * $Id: PreparatorServletTest.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.portlet.context;
19  
20  import javax.servlet.ServletConfig;
21  import javax.servlet.ServletContext;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import org.apache.struts2.ServletActionContext;
26  import org.apache.struts2.StrutsTestCase;
27  import org.easymock.MockControl;
28  
29  /***
30   * 
31   * Test for the {@link PreparatorServletTest}
32   * 
33   */
34  public class PreparatorServletTest extends StrutsTestCase {
35  
36      /***
37       * Test that the service method stores the request, response and servlet context
38       * in the {@link com.opensymphony.xwork2.ActionContext}
39       */
40      public void testServiceHttpServletRequestHttpServletResponse() throws Exception {
41          MockControl mockRequest = MockControl.createNiceControl(HttpServletRequest.class);
42          MockControl mockResponse = MockControl.createNiceControl(HttpServletResponse.class);
43          MockControl mockContext = MockControl.createNiceControl(ServletContext.class);
44          MockControl mockConfig = MockControl.createNiceControl(ServletConfig.class);
45          
46          HttpServletRequest req = (HttpServletRequest)mockRequest.getMock();
47          HttpServletResponse res = (HttpServletResponse)mockResponse.getMock();
48          ServletContext context = (ServletContext)mockContext.getMock();
49          ServletConfig config = (ServletConfig)mockConfig.getMock();
50          
51          mockConfig.expectAndDefaultReturn(config.getServletContext(), 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  }