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.expect;
18:
19: import javax.servlet.ServletException;
20: import javax.servlet.http.HttpServletRequest;
21:
22: import org.apache.struts.action.ActionForm;
23: import org.apache.struts.action.ActionMapping;
24: import org.apache.struts.chain.contexts.ServletActionContext;
25: import org.apache.struts.config.ActionConfig;
26: import org.strecks.form.handler.FormPopulateSource;
27: import org.testng.annotations.Test;
28:
29: /**
30: * @author Phil Zoio
31: */
32: public class TestPopulateActionForm extends AbstractTestChain {
33:
34: @Test
35: public void testPopulateActionForm() throws Exception {
36: ServletActionContext sac = getActionContext();
37: FormPopulateSource formPopulateSource = newMock(FormPopulateSource.class);
38: PopulateActionForm populateActionForm = getPopulateActionForm(formPopulateSource);
39: ActionMapping actionConfig = newMock(ActionMapping.class);
40: ActionForm actionForm = newMock(ActionForm.class);
41: HttpServletRequest request = newMock(HttpServletRequest.class);
42:
43: expect(sac.getActionForm()).andReturn(actionForm);
44: expect(sac.getRequest()).andReturn(request);
45: expect(formPopulateSource.prePopulate(actionForm, request))
46: .andReturn(actionForm);
47:
48: replayMocks();
49: populateActionForm.populate(sac, actionConfig, actionForm);
50: verifyMocks();
51: }
52:
53: public PopulateActionForm getPopulateActionForm(
54: final FormPopulateSource formPopulateSource) {
55: return new PopulateActionForm() {
56: protected FormPopulateSource newFormPopulateSource() {
57: return formPopulateSource;
58: }
59:
60: protected void populateForm(ActionConfig actionConfig,
61: final HttpServletRequest request,
62: ActionForm wrappedForm) throws ServletException {
63: }
64: };
65: }
66: }
|