View Javadoc

1   /*
2    * $Id: ChainedTilesContextFactoryTest.java 531904 2007-04-24 12:33:18Z 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  package org.apache.tiles.context;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  import org.apache.shale.test.mock.MockHttpServletRequest;
30  import org.apache.shale.test.mock.MockHttpServletResponse;
31  import org.apache.shale.test.mock.MockHttpSession;
32  import org.apache.shale.test.mock.MockServletContext;
33  import org.apache.tiles.TilesApplicationContext;
34  import org.apache.tiles.servlet.context.ServletTilesApplicationContext;
35  
36  import junit.framework.TestCase;
37  
38  /***
39   * @version $Rev: 531904 $ $Date: 2007-04-24 14:33:18 +0200 (Tue, 24 Apr 2007) $
40   */
41  public class ChainedTilesContextFactoryTest extends TestCase {
42  
43      /***
44       * The request object.
45       */
46      private HttpServletRequest request;
47  
48      /***
49       * The request object.
50       */
51      private HttpServletResponse response;
52  
53      /***
54       * The Tiles application context.
55       */
56      private TilesApplicationContext appContext;
57  
58      /*** {@inheritDoc} */
59      @Override
60      protected void setUp() throws Exception {
61          super.setUp();
62          MockServletContext servletContext = new MockServletContext();
63          appContext = new ServletTilesApplicationContext(servletContext);
64          MockHttpSession session = new MockHttpSession(servletContext);
65          MockHttpServletRequest request = new MockHttpServletRequest(session);
66          MockHttpServletResponse response = new MockHttpServletResponse();
67          this.request = request;
68          this.response = response;
69      }
70  
71      /***
72       * Tests the initialization method.
73       *
74       * @throws Exception If something goes wrong during testing.
75       */
76      public void testInit() throws Exception {
77          Map<String, String> config = new HashMap<String, String>();
78          config.put(ChainedTilesContextFactory.FACTORY_CLASS_NAMES,
79                  "this.is.not.a.class.Name,"
80                  + "org.apache.tiles.servlet.context.ServletTilesContextFactory");
81          ChainedTilesContextFactory factory = new ChainedTilesContextFactory();
82          factory.init(config);
83          TilesRequestContext context = factory.createRequestContext(appContext,
84                  request, response);
85          assertNotNull("The request context cannot be null", context);
86      }
87  }