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 javax.servlet.http.HttpServletRequest;
22:
23: import org.easymock.classextension.EasyMock;
24: import org.strecks.context.impl.TestContextImpl;
25: import org.strecks.exceptions.ApplicationConfigurationException;
26: import org.strecks.exceptions.ApplicationRuntimeException;
27: import org.strecks.injection.factory.impl.IntToIntConverter;
28: import org.strecks.injection.handler.impl.ActionWithInvalidConverter;
29: import org.strecks.injection.internal.InjectionAnnotationReader;
30: import org.testng.Assert;
31: import org.testng.annotations.Test;
32:
33: /**
34: * @author Phil Zoio
35: */
36: public class TestInvalidRequestHandlerConverter {
37:
38: @Test
39: public void test() {
40:
41: HttpServletRequest request = EasyMock
42: .createStrictMock(HttpServletRequest.class);
43: RequestParameterInjectionHandler handler = new RequestParameterInjectionHandler(
44: "paramName", new IntToIntConverter(), true);
45:
46: expect(request.getParameter("paramName")).andReturn("1");
47:
48: replay(request);
49:
50: try {
51: handler.getValue(new TestContextImpl(request));
52: } catch (ApplicationRuntimeException e) {
53: Assert
54: .assertEquals(
55: e.getMessage(),
56: "Converter org.strecks.injection.factory.impl.IntToIntConverter "
57: + "is parameterized using type (class java.lang.Integer), "
58: + "does not support conversion from String properties");
59: }
60:
61: verify(request);
62: }
63:
64: @Test
65: public void testReadAnnotations() {
66:
67: try {
68: InjectionAnnotationReader c = new InjectionAnnotationReader();
69: c.readAnnotations(ActionWithInvalidConverter.class);
70: } catch (ApplicationConfigurationException e) {
71: Assert
72: .assertEquals(
73: e.getMessage(),
74: "@InjectRequestParameter in org.strecks.injection.handler.impl.ActionWithInvalidConverter "
75: + "uses converter org.strecks.injection.factory.impl.IntToIntConverter "
76: + "whose conversion source type is java.lang.Integer, and not java.lang.String");
77: }
78: }
79:
80: }
|