KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > theme > ThemeResolverTests


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.theme;
18
19 import junit.framework.TestCase;
20
21 import org.springframework.mock.web.MockHttpServletRequest;
22 import org.springframework.mock.web.MockHttpServletResponse;
23 import org.springframework.mock.web.MockServletContext;
24 import org.springframework.web.servlet.ThemeResolver;
25
26 /**
27  * @author Jean-Pierre Pawlak
28  * @author Juergen Hoeller
29  * @since 19.06.2003
30  */

31 public class ThemeResolverTests extends TestCase {
32
33     private static final String JavaDoc TEST_THEME_NAME = "test.theme";
34     private static final String JavaDoc DEFAULT_TEST_THEME_NAME = "default.theme";
35
36     private void internalTest(ThemeResolver themeResolver, boolean shouldSet, String JavaDoc defaultName) {
37         // create mocks
38
MockServletContext context = new MockServletContext();
39         MockHttpServletRequest request = new MockHttpServletRequest(context);
40         MockHttpServletResponse response = new MockHttpServletResponse();
41         // check original theme
42
String JavaDoc themeName = themeResolver.resolveThemeName(request);
43         assertEquals(themeName, defaultName);
44         // set new theme name
45
try {
46             themeResolver.setThemeName(request, response, TEST_THEME_NAME);
47             if (!shouldSet)
48                 fail("should not be able to set Theme name");
49             // check new theme namelocale
50
themeName = themeResolver.resolveThemeName(request);
51             assertEquals(themeName, TEST_THEME_NAME);
52             themeResolver.setThemeName(request, response, null);
53             themeName = themeResolver.resolveThemeName(request);
54             assertEquals(themeName, defaultName);
55         } catch (IllegalArgumentException JavaDoc ex) {
56             if (shouldSet)
57                 fail("should be able to set Theme name");
58         }
59     }
60
61     public void testFixedThemeResolver() {
62         internalTest(new FixedThemeResolver(), false, AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME);
63     }
64
65     public void testCookieThemeResolver() {
66         internalTest(new CookieThemeResolver(), true, AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME);
67     }
68
69     public void testSessionThemeResolver() {
70         internalTest(new SessionThemeResolver(), true,AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME);
71     }
72
73     public void testSessionThemeResolverWithDefault() {
74         SessionThemeResolver tr = new SessionThemeResolver();
75         tr.setDefaultThemeName(DEFAULT_TEST_THEME_NAME);
76         internalTest(tr, true, DEFAULT_TEST_THEME_NAME);
77     }
78
79 }
80
Popular Tags