KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > tags > AbstractTagTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.tags;
18
19 import junit.framework.TestCase;
20
21 import org.springframework.mock.web.MockHttpServletRequest;
22 import org.springframework.mock.web.MockPageContext;
23 import org.springframework.mock.web.MockServletContext;
24 import org.springframework.web.context.WebApplicationContext;
25 import org.springframework.web.servlet.DispatcherServlet;
26 import org.springframework.web.servlet.LocaleResolver;
27 import org.springframework.web.servlet.SimpleWebApplicationContext;
28 import org.springframework.web.servlet.ThemeResolver;
29 import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
30 import org.springframework.web.servlet.theme.FixedThemeResolver;
31
32 /**
33  * Abstract base class for testing tags: provides createPageContext.
34  *
35  * @author Alef Arendsen
36  */

37 public abstract class AbstractTagTests extends TestCase {
38     
39     protected MockPageContext createPageContext() {
40         MockServletContext sc = new MockServletContext();
41         SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
42         wac.setServletContext(sc);
43         wac.setNamespace("test");
44         wac.refresh();
45
46         MockHttpServletRequest request = new MockHttpServletRequest(sc);
47         if (inDispatcherServlet()) {
48             request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
49             LocaleResolver lr = new AcceptHeaderLocaleResolver();
50             request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
51             ThemeResolver tr = new FixedThemeResolver();
52             request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
53         }
54         else {
55             sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
56         }
57
58         return new MockPageContext(sc, request);
59     }
60
61     protected boolean inDispatcherServlet() {
62         return true;
63     }
64
65 }
66
Popular Tags