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.classextension.EasyMock.createMock;
18: import static org.easymock.classextension.EasyMock.replay;
19: import static org.easymock.classextension.EasyMock.verify;
20:
21: import java.util.Map;
22:
23: import javax.servlet.http.HttpServletRequest;
24:
25: import org.strecks.context.ActionContext;
26: import org.strecks.context.impl.TestContextImpl;
27: import org.strecks.injection.handler.impl.ActionWithRequest;
28: import org.strecks.injection.internal.InjectionAnnotationReader;
29: import org.strecks.injection.internal.InjectionWrapper;
30: import org.testng.annotations.Test;
31:
32: /**
33: * @author Phil Zoio
34: */
35: public class TestRequestInjectionHandler {
36:
37: @Test
38: public void test() {
39: InjectionAnnotationReader c = new InjectionAnnotationReader();
40: ActionWithRequest action = new ActionWithRequest();
41:
42: c.readAnnotations(action.getClass());
43: Map<String, InjectionWrapper> inputs = c.getInjectionMap();
44:
45: HttpServletRequest request = createMock(HttpServletRequest.class);
46:
47: replay(request);
48:
49: InjectionWrapper inputWrapper = inputs.get("request");
50:
51: ActionContext injectionContext = new TestContextImpl(request);
52: inputWrapper.inject(action, injectionContext);
53:
54: verify(request);
55:
56: assert action.getRequest() != null;
57: assert action.getRequest() == request;
58: }
59:
60: }
|