01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. 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 distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.injection.handler;
16:
17: import static org.easymock.EasyMock.expect;
18: import static org.easymock.classextension.EasyMock.createMock;
19: import static org.easymock.classextension.EasyMock.replay;
20: import static org.easymock.classextension.EasyMock.verify;
21:
22: import java.util.Locale;
23: import java.util.Map;
24:
25: import javax.servlet.http.HttpServletRequest;
26:
27: import org.apache.struts.Globals;
28: import org.strecks.context.ActionContext;
29: import org.strecks.context.impl.TestContextImpl;
30: import org.strecks.injection.handler.impl.ActionWithLocale;
31: import org.strecks.injection.internal.InjectionAnnotationReader;
32: import org.strecks.injection.internal.InjectionWrapper;
33: import org.testng.annotations.Test;
34:
35: /**
36: * @author Phil Zoio
37: */
38: public class TestLocaleInjectionHandler {
39:
40: @Test
41: public void test() {
42: InjectionAnnotationReader c = new InjectionAnnotationReader();
43: ActionWithLocale action = new ActionWithLocale();
44:
45: c.readAnnotations(action.getClass());
46: Map<String, InjectionWrapper> inputs = c.getInjectionMap();
47:
48: Locale locale = Locale.getDefault();
49:
50: HttpServletRequest request = createMock(HttpServletRequest.class);
51: expect(request.getAttribute(Globals.LOCALE_KEY)).andReturn(
52: locale);
53:
54: replay(request);
55:
56: InjectionWrapper inputWrapper = inputs.get("locale");
57:
58: ActionContext injectionContext = new TestContextImpl(request);
59: inputWrapper.inject(action, injectionContext);
60:
61: verify(request);
62:
63: assert action.getLocale() != null;
64: assert action.getLocale() == locale;
65: }
66:
67: }
|