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.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.easymock.classextension.EasyMock;
26: import org.strecks.context.impl.TestContextImpl;
27: import org.strecks.injection.handler.impl.TestAction;
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 TestRequestHandler {
36:
37: @Test
38: public void testInputReader() {
39:
40: InjectionAnnotationReader c = new InjectionAnnotationReader();
41: TestAction action = new TestAction();
42:
43: c.readAnnotations(action.getClass());
44: Map<String, InjectionWrapper> inputs = c.getInjectionMap();
45:
46: HttpServletRequest request = EasyMock
47: .createMock(HttpServletRequest.class);
48:
49: expect(request.getParameter("integerInput")).andReturn("1");
50: expect(request.getParameter("converted_long")).andReturn("2");
51:
52: replay(request);
53:
54: InjectionWrapper inputWrapper = inputs.get("integerInput");
55:
56: inputWrapper.inject(action, new TestContextImpl(request));
57:
58: inputWrapper = inputs.get("convertedLongInput");
59:
60: inputWrapper.inject(action, new TestContextImpl(request));
61:
62: verify(request);
63:
64: assert action.getConvertedLongInput() != null;
65: assert action.getIntegerInput() != null;
66: assert action.getLongInput() == null;
67:
68: }
69:
70: }
|