`

mock UrlPreparerTest

阅读更多
1   /*
2    * $Id: UrlPreparerTest.java 709151 2008-10-30 12:36:29Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.tiles.compat.preparer;
23  
24  import java.io.IOException;
25  
26  import javax.servlet.RequestDispatcher;
27  import javax.servlet.ServletContext;
28  import javax.servlet.ServletException;
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  
32  import org.apache.tiles.AttributeContext;
33  import org.apache.tiles.TilesApplicationContext;
34  import org.apache.tiles.context.TilesRequestContext;
35  import org.apache.tiles.servlet.context.ServletTilesApplicationContext;
36  import org.apache.tiles.servlet.context.ServletTilesRequestContext;
37  import org.apache.tiles.servlet.context.ServletUtil;
38  import org.easymock.EasyMock;
39  
40  import junit.framework.TestCase;
41  
42  /***
43   * Tests {@link UrlPreparer}.
44   *
45   * @version $Rev: 709151 $ $Date: 2008-10-30 13:36:29 +0100 (gio, 30 ott 2008) $
46   */
47  public class UrlPreparerTest extends TestCase {
48  
49      /***
50       * The preparer to test.
51       */
52      private UrlPreparer preparer;
53  
54      /*** {@inheritDoc} */
55      @Override
56      protected void setUp() throws Exception {
57          preparer = new UrlPreparer("/my/url.do");
58      }
59  
60      /***
61       * Test method for
62       * {@link org.apache.tiles.compat.preparer.UrlPreparer#execute(
63       * org.apache.tiles.context.TilesRequestContext, org.apache.tiles.AttributeContext)}.
64       * @throws IOException If something goes wrong.
65       * @throws ServletException If something goes wrong.
66       */
67      public void testExecute() throws ServletException, IOException {
68          HttpServletRequest request = EasyMock
69                  .createMock(HttpServletRequest.class);
70          request.setAttribute(ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
71          HttpServletResponse response = EasyMock
72                  .createMock(HttpServletResponse.class);
73          ServletContext servletContext = EasyMock
74                  .createMock(ServletContext.class);
75          RequestDispatcher rd = EasyMock.createMock(RequestDispatcher.class);
76          TilesApplicationContext applicationContext = new ServletTilesApplicationContext(
77                  servletContext);
78          TilesRequestContext requestContext = new ServletTilesRequestContext(
79                  applicationContext, request, response);
80          AttributeContext attributeContext = EasyMock
81                  .createMock(AttributeContext.class);
82  
83          EasyMock.expect(request.getRequestDispatcher("/my/url.do"))
84                  .andReturn(rd);
85          rd.include(request, response);
86          EasyMock
87                  .replay(request, response, servletContext, attributeContext, rd);
88          preparer.execute(requestContext, attributeContext);
89          EasyMock.verify(rd);
90      }
91  }

This page was automatically generated by Maven
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics