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.internal;
16:
17: import java.util.Map;
18:
19: import org.strecks.converter.StandardBeanUtilsConverter;
20: import org.strecks.converter.StringConverter;
21: import org.strecks.injection.handler.RequestParameterInjectionHandler;
22: import org.strecks.injection.handler.impl.TestAction;
23: import org.testng.Assert;
24: import org.testng.annotations.Test;
25:
26: /**
27: * @author Phil Zoio
28: */
29: public class TestInjectionAnnotationReader {
30:
31: @Test
32: public void testInputReader() {
33: InjectionAnnotationReader c = new InjectionAnnotationReader();
34: TestAction action = new TestAction();
35: c.readAnnotations(action.getClass());
36: Map<String, InjectionWrapper> inputs = c.getInjectionMap();
37:
38: Assert.assertEquals(inputs.size(), 10);
39:
40: InjectionWrapper wrapper = inputs.get("integerInput");
41: RequestParameterInjectionHandler handler = (RequestParameterInjectionHandler) wrapper
42: .getInjectionHandlers().get(0);
43:
44: InjectionSetter info = wrapper.getInjectionSetter();
45: Assert.assertEquals("setIntegerInput", info.getMethodName());
46: Assert.assertEquals("integerInput", info.getPropertyName());
47: Assert.assertEquals(Integer.class, info.getType());
48: Assert.assertEquals("integerInput", handler.getParameterName());
49: Assert.assertEquals(StandardBeanUtilsConverter.class, handler
50: .getConverter().getClass());
51:
52: wrapper = inputs.get("longInput");
53: handler = (RequestParameterInjectionHandler) wrapper
54: .getInjectionHandlers().get(0);
55:
56: info = wrapper.getInjectionSetter();
57: Assert.assertEquals("setLongInput", info.getMethodName());
58: Assert.assertEquals("longInput", info.getPropertyName());
59: Assert.assertEquals(Long.class, info.getType());
60: Assert.assertEquals("longInput", handler.getParameterName());
61: Assert.assertEquals(StandardBeanUtilsConverter.class, handler
62: .getConverter().getClass());
63:
64: wrapper = inputs.get("convertedLongInput");
65: handler = (RequestParameterInjectionHandler) wrapper
66: .getInjectionHandlers().get(0);
67:
68: info = wrapper.getInjectionSetter();
69: Assert.assertEquals("setConvertedLongInput", info
70: .getMethodName());
71: Assert.assertEquals("convertedLongInput", info
72: .getPropertyName());
73: Assert.assertEquals(String.class, info.getType());
74: Assert.assertEquals("converted_long", handler
75: .getParameterName());
76: Assert.assertEquals(StringConverter.class, handler
77: .getConverter().getClass());
78:
79: }
80:
81: }
|