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.controller.chain.command;
16:
17: import static org.easymock.EasyMock.eq;
18: import static org.easymock.EasyMock.expect;
19: import static org.easymock.EasyMock.isA;
20:
21: import javax.servlet.http.HttpServletRequest;
22:
23: import org.apache.struts.action.ActionForm;
24: import org.apache.struts.chain.contexts.ServletActionContext;
25: import org.strecks.form.controller.BindingForm;
26: import org.strecks.form.controller.DelegatingForm;
27: import org.strecks.form.controller.ValidForm;
28: import org.strecks.form.handler.FormWrapper;
29: import org.testng.annotations.Test;
30:
31: /**
32: * @author Phil Zoio
33: */
34: public class TestDelegatingProcessActionForm extends AbstractTestChain {
35:
36: @Test
37: public void testDelegatingActionForm() throws Exception {
38: ServletActionContext sac = getActionContext();
39: FormWrapper wrapper = newMock(FormWrapper.class);
40: ProcessActionForm processActionForm = getProcessActionForm(wrapper);
41: HttpServletRequest request = newMock(HttpServletRequest.class);
42: ActionForm actionForm = newMock(ActionForm.class);
43: DelegatingForm delegatingForm = new DelegatingForm(actionForm);
44:
45: expect(sac.getActionForm()).andReturn(actionForm);
46: expect(sac.getRequest()).andReturn(request);
47:
48: expect(wrapper.wrapForm(actionForm, request)).andReturn(
49: delegatingForm);
50:
51: wrapper.handleBindingForm(isA(BindingForm.class), eq(request));
52: wrapper.handleValidForm(isA(ValidForm.class), eq(request));
53: sac.setActionForm(isA(ActionForm.class));
54:
55: replayMocks();
56: processActionForm.execute(sac);
57: verifyMocks();
58: }
59:
60: public ProcessActionForm getProcessActionForm(
61: final FormWrapper wrapper) {
62: return new ProcessActionForm() {
63: protected FormWrapper newFormHandler() {
64: return wrapper;
65: }
66: };
67: }
68: }
|