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.navigable;
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.navigable.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.navigate.internal.BeanNavigationReader;
32: import org.strecks.view.ActionForwardViewAdapter;
33: import org.strecks.view.ViewAdapter;
34: import org.testng.annotations.Test;
35:
36: /**
37: * @author Phil Zoio
38: */
39: public class TestNavigableMappingDispatchController {
40:
41: @Test
42: public void testCreationAction() throws Exception {
43: ActionCreator actionCreator = new ActionCreatorImpl();
44: Action action = actionCreator
45: .createAction(SimpleDispatchAction.class);
46: NavigableMappingDispatchController controller = (NavigableMappingDispatchController) action;
47: assert controller.getNavigationHolder() != null;
48: assert controller.getBeanSource() != null;
49: }
50:
51: @Test
52: public void testInsertMethod() {
53:
54: NavigableMappingDispatchController action = new NavigableMappingDispatchController();
55:
56: BeanNavigationReader navigationReader = new BeanNavigationReader();
57: navigationReader.readAnnotations(SimpleDispatchAction.class);
58: action.setNavigationHolder(navigationReader
59: .getNavigationHolder());
60:
61: ActionForward actionForward = new ActionForward();
62:
63: SimpleDispatchAction actionBean = createMock(SimpleDispatchAction.class);
64: ActionMapping mapping = createMock(ActionMapping.class);
65: HttpServletRequest request = createMock(HttpServletRequest.class);
66:
67: expect(mapping.getParameter()).andReturn("insert");
68: actionBean.insert();
69: expect(actionBean.getSuccessResult()).andReturn("insertResult");
70: expect(mapping.findForward("insertResult")).andReturn(
71: actionForward);
72:
73: replay(actionBean);
74: replay(mapping);
75: replay(request);
76:
77: ViewAdapter viewAdapter = action
78: .executeAction(actionBean, new TestContextImpl(request,
79: null, null, null, mapping));
80: ActionForwardViewAdapter va = (ActionForwardViewAdapter) viewAdapter;
81: assert (va.getActionForward() == actionForward);
82:
83: verify(actionBean);
84: verify(mapping);
85: verify(request);
86:
87: }
88:
89: }
|