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.navigate.handler;
16:
17: import static org.easymock.EasyMock.expect;
18: import static org.easymock.classextension.EasyMock.createStrictMock;
19: import static org.easymock.classextension.EasyMock.replay;
20: import static org.easymock.classextension.EasyMock.verify;
21: import static org.testng.Assert.assertEquals;
22:
23: import javax.servlet.http.HttpServletRequest;
24:
25: import org.apache.struts.action.ActionForward;
26: import org.strecks.constants.InfrastructureKeys;
27: import org.strecks.context.ActionContext;
28: import org.strecks.context.impl.TestContextImpl;
29: import org.strecks.page.Page;
30: import org.strecks.page.PageForward;
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 TestPageNavigationHandler {
39:
40: @Test
41: public void testNavigationHandler() {
42:
43: Page pageClass = createStrictMock(Page.class);
44: ActionContext actionContext = createStrictMock(TestContextImpl.class);
45: HttpServletRequest request = createStrictMock(HttpServletRequest.class);
46:
47: expect(pageClass.getPagePath()).andReturn("page_path");
48: expect(actionContext.getResponse()).andReturn(null);
49: pageClass.setHttpServletResponse(null);
50: expect(actionContext.getRequest()).andReturn(request);
51: request.setAttribute(InfrastructureKeys.PAGE_BEAN, pageClass);
52:
53: replay(pageClass);
54: replay(actionContext);
55: replay(request);
56:
57: PageNavigationHandler handler = new PageNavigationHandler();
58: ViewAdapter viewAdapter = handler.getActionForward(
59: actionContext, pageClass);
60:
61: ActionForwardViewAdapter va = (ActionForwardViewAdapter) viewAdapter;
62: ActionForward forward = va.getActionForward();
63:
64: assert forward instanceof PageForward;
65: assertEquals(forward.getPath(), "page_path");
66:
67: verify(pageClass);
68: verify(actionContext);
69: verify(request);
70:
71: }
72: }
|