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 java.util.Map;
18:
19: import org.apache.struts.action.ActionForm;
20: import org.strecks.context.ActionContext;
21: import org.strecks.context.impl.TestContextImpl;
22: import org.strecks.form.controller.DelegatingForm;
23: import org.strecks.injection.handler.impl.ActionWithActionForm;
24: import org.strecks.injection.handler.impl.SimpleForm;
25: import org.strecks.injection.internal.InjectionAnnotationReader;
26: import org.strecks.injection.internal.InjectionWrapper;
27: import org.testng.annotations.Test;
28:
29: /**
30: * @author Phil Zoio
31: */
32: public class TestActionFormInjectionHandler {
33:
34: @Test
35: public void testSimple() {
36: InjectionAnnotationReader c = new InjectionAnnotationReader();
37: ActionWithActionForm action = new ActionWithActionForm();
38:
39: c.readAnnotations(action.getClass());
40: Map<String, InjectionWrapper> injectionHandlers = c
41: .getInjectionMap();
42: ActionForm actionForm = new SimpleForm();
43:
44: InjectionWrapper inputWrapper = injectionHandlers
45: .get("actionForm");
46:
47: ActionContext injectionContext = new TestContextImpl(
48: actionForm, null);
49: inputWrapper.inject(action, injectionContext);
50:
51: assert action.getActionForm() != null;
52: assert action.getActionForm() == actionForm;
53: }
54:
55: @Test
56: public void testDelegating() {
57: InjectionAnnotationReader c = new InjectionAnnotationReader();
58: ActionWithActionForm action = new ActionWithActionForm();
59:
60: c.readAnnotations(action.getClass());
61: Map<String, InjectionWrapper> injectionHandlers = c
62: .getInjectionMap();
63: ActionForm actionForm = new SimpleForm();
64: DelegatingForm delegator = new DelegatingForm(actionForm);
65:
66: InjectionWrapper inputWrapper = injectionHandlers
67: .get("actionForm");
68:
69: ActionContext injectionContext = new TestContextImpl(delegator,
70: null);
71: inputWrapper.inject(action, injectionContext);
72:
73: assert action.getActionForm() != null;
74: assert action.getActionForm() == actionForm;
75: }
76:
77: }
|