001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.dispatcher;
006:
007: import com.opensymphony.webwork.dispatcher.WebWorkResultSupport;
008: import org.easymock.MockControl;
009:
010: import com.opensymphony.webwork.WebWorkTestCase;
011: import com.opensymphony.xwork.ActionInvocation;
012: import com.opensymphony.xwork.ActionSupport;
013: import com.opensymphony.xwork.util.OgnlValueStack;
014:
015: /**
016: * Test case for WebWorkResultSupport.
017: *
018: * @author tm_jee
019: * @version $Date: 2006-07-01 19:26:05 +0200 (Sat, 01 Jul 2006) $ $Id: WebWorkResultSupportTest.java 2625 2006-07-01 17:26:05Z tmjee $
020: */
021: public class WebWorkResultSupportTest extends WebWorkTestCase {
022:
023: public void testParse() throws Exception {
024: OgnlValueStack stack = new OgnlValueStack();
025: stack.push(new ActionSupport() {
026: private static final long serialVersionUID = 2482793811882036901L;
027:
028: public String getMyLocation() {
029: return "ThisIsMyLocation";
030: }
031: });
032: MockControl mockControlActionInvocation = MockControl
033: .createNiceControl(ActionInvocation.class);
034: ActionInvocation mockActionInvocation = (ActionInvocation) mockControlActionInvocation
035: .getMock();
036: mockActionInvocation.getStack();
037: mockControlActionInvocation.setDefaultReturnValue(stack);
038: mockControlActionInvocation.replay();
039:
040: /*ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class);
041: mockActionInvocation.getStack();
042: EasyMock.expectLastCall().andReturn(stack);
043: EasyMock.replay(mockActionInvocation);*/
044:
045: InternalWebWorkResultSupport result = new InternalWebWorkResultSupport();
046: result.setParse(true);
047: result.setEncode(false);
048: result.setLocation("/pages/myJsp.jsp?location=${myLocation}");
049:
050: result.execute(mockActionInvocation);
051:
052: assertNotNull(result.getInternalLocation());
053: assertEquals("/pages/myJsp.jsp?location=ThisIsMyLocation",
054: result.getInternalLocation());
055:
056: mockControlActionInvocation.verify();
057: //EasyMock.verify(mockActionInvocation);
058: }
059:
060: public void testParseAndEncode() throws Exception {
061: OgnlValueStack stack = new OgnlValueStack();
062: stack.push(new ActionSupport() {
063: public String getMyLocation() {
064: return "/myPage?param=value¶m1=value1";
065: }
066: });
067:
068: MockControl mockControlActionInvocation = MockControl
069: .createNiceControl(ActionInvocation.class);
070: ActionInvocation mockActionInvocation = (ActionInvocation) mockControlActionInvocation
071: .getMock();
072: mockActionInvocation.getStack();
073: mockControlActionInvocation.setDefaultReturnValue(stack);
074: mockControlActionInvocation.replay();
075:
076: /*ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class);
077: mockActionInvocation.getStack();
078: EasyMock.expectLastCall().andReturn(stack);
079: EasyMock.replay(mockActionInvocation);*/
080:
081: InternalWebWorkResultSupport result = new InternalWebWorkResultSupport();
082: result.setParse(true);
083: result.setEncode(true);
084: result.setLocation("/pages/myJsp.jsp?location=${myLocation}");
085:
086: result.execute(mockActionInvocation);
087:
088: assertNotNull(result.getInternalLocation());
089: assertEquals(
090: "/pages/myJsp.jsp?location=%2FmyPage%3Fparam%3Dvalue%26param1%3Dvalue1",
091: result.getInternalLocation());
092:
093: mockControlActionInvocation.verify();
094: //EasyMock.verify(mockActionInvocation);
095: }
096:
097: public void testNoParseAndEncode() throws Exception {
098: OgnlValueStack stack = new OgnlValueStack();
099: stack.push(new ActionSupport() {
100: public String getMyLocation() {
101: return "myLocation.jsp";
102: }
103: });
104:
105: MockControl mockControlActionInvocaton = MockControl
106: .createNiceControl(ActionInvocation.class);
107: ActionInvocation mockActionInvocation = (ActionInvocation) mockControlActionInvocaton
108: .getMock();
109: mockControlActionInvocaton.replay();
110:
111: /*ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class);
112: EasyMock.replay(mockActionInvocation);*/
113:
114: InternalWebWorkResultSupport result = new InternalWebWorkResultSupport();
115: result.setParse(false);
116: result.setEncode(false); // don't really need this, as encode is only valid when parse is true.
117: result.setLocation("/pages/myJsp.jsp?location=${myLocation}");
118:
119: result.execute(mockActionInvocation);
120:
121: assertNotNull(result.getInternalLocation());
122: assertEquals("/pages/myJsp.jsp?location=${myLocation}", result
123: .getInternalLocation());
124:
125: mockControlActionInvocaton.verify();
126: //EasyMock.verify(mockActionInvocation);
127: }
128:
129: public static class InternalWebWorkResultSupport extends
130: WebWorkResultSupport {
131:
132: private static final long serialVersionUID = 7910355535690184631L;
133:
134: private String _internalLocation = null;
135:
136: protected void doExecute(String finalLocation,
137: ActionInvocation invocation) throws Exception {
138: _internalLocation = finalLocation;
139: }
140:
141: public String getInternalLocation() {
142: return _internalLocation;
143: }
144: }
145: }
|