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.action.basic;
16:
17: import static org.easymock.EasyMock.expect;
18: import static org.easymock.classextension.EasyMock.createMock;
19: import static org.easymock.classextension.EasyMock.replay;
20: import static org.easymock.classextension.EasyMock.verify;
21:
22: import javax.servlet.http.HttpServletRequest;
23:
24: import org.apache.struts.action.Action;
25: import org.apache.struts.action.ActionForward;
26: import org.apache.struts.action.ActionMapping;
27: import org.strecks.action.basic.impl.SimpleDispatchAction;
28: import org.strecks.context.impl.TestContextImpl;
29: import org.strecks.controller.ActionCreator;
30: import org.strecks.controller.ActionCreatorImpl;
31: import org.strecks.view.ActionForwardViewAdapter;
32: import org.strecks.view.ViewAdapter;
33: import org.testng.annotations.Test;
34:
35: /**
36: * @author Phil Zoio
37: */
38: public class TestBasicMappingDispatchController {
39:
40: @Test
41: public void testCreationAction() throws Exception {
42: ActionCreator actionCreator = new ActionCreatorImpl();
43: Action action = actionCreator
44: .createAction(SimpleDispatchAction.class);
45: BasicMappingDispatchController controller = (BasicMappingDispatchController) action;
46: assert controller.getBeanSource() != null;
47: }
48:
49: @Test
50: public void testInsertMethod() {
51:
52: BasicMappingDispatchController action = new BasicMappingDispatchController();
53: ActionForward actionForward = new ActionForward();
54:
55: SimpleDispatchAction actionBean = createMock(SimpleDispatchAction.class);
56: ActionMapping mapping = createMock(ActionMapping.class);
57: HttpServletRequest request = createMock(HttpServletRequest.class);
58:
59: expect(mapping.getParameter()).andReturn("insert");
60: expect(actionBean.insert()).andReturn("insertResult");
61: expect(mapping.findForward("insertResult")).andReturn(
62: actionForward);
63:
64: replay(actionBean);
65: replay(mapping);
66: replay(request);
67:
68: ViewAdapter viewAdapter = action
69: .executeAction(actionBean, new TestContextImpl(request,
70: null, null, null, mapping));
71: ActionForwardViewAdapter va = (ActionForwardViewAdapter) viewAdapter;
72: assert (va.getActionForward() == actionForward);
73:
74: verify(actionBean);
75: verify(mapping);
76: verify(request);
77:
78: }
79:
80: }
|