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 org.apache.struts.action.Action;
23: import org.apache.struts.action.ActionForward;
24: import org.apache.struts.action.ActionMapping;
25: import org.strecks.action.BasicAction;
26: import org.strecks.context.impl.TestContextImpl;
27: import org.strecks.controller.ActionCreator;
28: import org.strecks.controller.ActionCreatorImpl;
29: import org.strecks.navigate.internal.impl.ActionWithNoNavigate;
30: import org.strecks.view.ActionForwardViewAdapter;
31: import org.strecks.view.ViewAdapter;
32: import org.testng.annotations.Test;
33:
34: /**
35: * @author Phil Zoio
36: */
37: public class TestBasicController {
38:
39: @Test
40: public void testCreationAction() throws Exception {
41: ActionCreator actionCreator = new ActionCreatorImpl();
42: Action action = actionCreator
43: .createAction(ActionWithNoNavigate.class);
44: BasicController controller = (BasicController) action;
45: assert controller.getBeanSource() != null;
46: }
47:
48: @Test
49: public void test() {
50:
51: BasicController action = new BasicController();
52: ActionForward actionForward = new ActionForward();
53:
54: BasicAction actionBean = createMock(BasicAction.class);
55: ActionMapping mapping = createMock(ActionMapping.class);
56:
57: expect(actionBean.execute()).andReturn("success");
58: expect(mapping.findForward("success")).andReturn(actionForward);
59:
60: replay(actionBean);
61: replay(mapping);
62:
63: ViewAdapter viewAdapter = action.executeAction(actionBean,
64: new TestContextImpl(null, mapping));
65: ActionForwardViewAdapter va = (ActionForwardViewAdapter) viewAdapter;
66: assert (va.getActionForward() == actionForward);
67:
68: verify(actionBean);
69: verify(mapping);
70:
71: }
72: }
|