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 org.apache.struts.action.Action;
23: import org.apache.struts.action.ActionForward;
24: import org.apache.struts.action.ActionMapping;
25: import org.strecks.action.navigable.impl.NavigableReadOnlyBean;
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.BeanNavigationReader;
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 TestNavigableReadOnlyController {
38:
39: @Test
40: public void testCreationAction() throws Exception {
41: ActionCreator actionCreator = new ActionCreatorImpl();
42: Action action = actionCreator
43: .createAction(NavigableReadOnlyBean.class);
44: NavigableController controller = (NavigableController) action;
45: assert controller.getBeanSource() != null;
46: assert controller.getNavigationHolder() != null;
47: }
48:
49: @Test
50: public void test() {
51:
52: NavigableController action = new NavigableController();
53: BeanNavigationReader navigationReader = new BeanNavigationReader();
54: navigationReader.readAnnotations(NavigableReadOnlyBean.class);
55: action.setNavigationHolder(navigationReader
56: .getNavigationHolder());
57:
58: ActionForward actionForward = new ActionForward();
59:
60: NavigableReadOnlyBean actionBean = createMock(NavigableReadOnlyBean.class);
61: ActionMapping mapping = createMock(ActionMapping.class);
62:
63: actionBean.execute();
64: expect(actionBean.getSuccessResult()).andReturn("success");
65: expect(mapping.findForward("success")).andReturn(actionForward);
66:
67: replay(actionBean);
68: replay(mapping);
69:
70: ViewAdapter viewAdapter = action.executeAction(actionBean,
71: new TestContextImpl(null, mapping));
72: ActionForwardViewAdapter va = (ActionForwardViewAdapter) viewAdapter;
73: assert (va.getActionForward() == actionForward);
74:
75: verify(actionBean);
76: verify(mapping);
77:
78: }
79: }
|