01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal;
16:
17: import java.util.Arrays;
18: import java.util.Collections;
19: import java.util.Enumeration;
20:
21: import javax.servlet.ServletContext;
22:
23: import org.apache.tapestry.ioc.services.SymbolProvider;
24: import org.apache.tapestry.ioc.test.TestBase;
25: import org.testng.annotations.Test;
26:
27: public class ServletContextSymbolProviderTest extends TestBase {
28: @Test
29: public void access_of_keys_is_case_insensitive() {
30: ServletContext context = newMock(ServletContext.class);
31:
32: String key1 = "fred";
33: String value1 = "Fred Flintstone";
34: String key2 = "barney";
35: String value2 = "Barney Rubble";
36:
37: expect(context.getInitParameterNames()).andReturn(
38: toEnumeration(key1, key2));
39:
40: expect(context.getInitParameter(key1)).andReturn(value1);
41: expect(context.getInitParameter(key2)).andReturn(value2);
42:
43: replay();
44:
45: SymbolProvider p = new ServletContextSymbolProvider(context);
46:
47: assertEquals(p.valueForSymbol(key1), value1);
48: assertEquals(p.valueForSymbol(key2), value2);
49:
50: // Not in config is null
51: assertNull(p.valueForSymbol("wilma"));
52:
53: // Check for case insensitivity
54: assertEquals(p.valueForSymbol("FRED"), value1);
55:
56: verify();
57: }
58:
59: protected final <T> Enumeration<T> toEnumeration(T... values) {
60: return Collections.enumeration(Arrays.asList(values));
61: }
62:
63: }
|