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.ServletContext;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: import org.apache.struts.action.Action;
24: import org.apache.struts.action.ActionForm;
25: import org.apache.struts.action.ActionForward;
26: import org.apache.struts.action.ActionMapping;
27: import org.apache.struts.chain.contexts.ServletActionContext;
28: import org.strecks.context.ActionContext;
29: import org.strecks.context.ActionContextFactory;
30: import org.strecks.controller.ControllerProcessorDelegate;
31: import org.testng.annotations.Test;
32:
33: /**
34: * @author Phil Zoio
35: */
36: public class TestExecuteAction extends AbstractTestChain {
37:
38: @Test
39: public void testCreateAction() throws Exception {
40: ServletActionContext sac = getActionContext();
41: ControllerProcessorDelegate delegate = newMock(ControllerProcessorDelegate.class);
42: ActionContextFactory factory = newMock(ActionContextFactory.class);
43: ExecuteAction executeAction = getExecuteAction(delegate,
44: factory);
45: Action action = newMock(Action.class);
46: ActionMapping actionConfig = newMock(ActionMapping.class);
47: ActionForm actionForm = newMock(ActionForm.class);
48: ActionContext actionContext = newMock(ActionContext.class);
49: ActionForward forwardConfig = newMock(ActionForward.class);
50: HttpServletRequest request = newMock(HttpServletRequest.class);
51: HttpServletResponse response = newMock(HttpServletResponse.class);
52: ServletContext servletContext = newMock(ServletContext.class);
53:
54: expect(sac.getRequest()).andReturn(request);
55: expect(sac.getResponse()).andReturn(response);
56: expect(sac.getContext()).andReturn(servletContext);
57: expect(
58: factory.createActionContext(request, response,
59: servletContext, actionForm, actionConfig))
60: .andReturn(actionContext);
61: expect(
62: action.execute(actionConfig, actionForm, request,
63: response)).andReturn(forwardConfig);
64:
65: replayMocks();
66: executeAction.execute(sac, action, actionConfig, actionForm);
67: verifyMocks();
68: }
69:
70: public ExecuteAction getExecuteAction(
71: final ControllerProcessorDelegate delegate,
72: final ActionContextFactory factory) {
73: return new ExecuteAction() {
74: @Override
75: protected ControllerProcessorDelegate newControllerProcessorDelegate() {
76: return delegate;
77: }
78:
79: @Override
80: protected ActionContextFactory newActionContextFactory() {
81: return factory;
82: }
83: };
84: }
85: }
|