001: package com.mockrunner.test.web;
002:
003: import junit.framework.TestCase;
004:
005: import org.apache.struts.action.ActionForward;
006: import org.apache.struts.action.ActionMapping;
007:
008: import com.mockrunner.mock.web.MockActionForward;
009: import com.mockrunner.mock.web.MockActionMapping;
010: import com.mockrunner.struts.ActionMappingProxyGenerator;
011:
012: public class ActionMappingProxyGeneratorTest extends TestCase {
013: private MockActionMapping delegate;
014: private ActionMappingProxyGenerator generator;
015:
016: protected void setUp() throws Exception {
017: delegate = new MockActionMapping();
018: delegate.addForward("success", "testpath");
019: delegate.setInput("willBeReplaced");
020: generator = new ActionMappingProxyGenerator(delegate);
021: }
022:
023: public void testCreateActionMappingProxy() {
024: TestMapping proxy = (TestMapping) generator
025: .createActionMappingProxy(TestMapping.class);
026: MockActionForward forward = (MockActionForward) proxy
027: .findForward("success");
028: proxy.setInput("testinput");
029: assertEquals("testpath", forward.getPath());
030: String[] forwards = proxy.findForwards();
031: assertEquals(1, forwards.length);
032: assertEquals("success", forwards[0]);
033: MockActionForward inputForward = (MockActionForward) proxy
034: .getInputForward();
035: assertEquals("testinput", inputForward.getPath());
036: proxy.freeze();
037: assertFalse(proxy.wasFindForwardCalled());
038: assertFalse(proxy.wasFindForwardsCalled());
039: assertFalse(proxy.wasGetInputForwardCalled());
040: assertTrue(proxy.wasFreezeCalled());
041: }
042:
043: public void testDuplicateMethods() {
044: TestMapping proxy = (TestMapping) generator
045: .createActionMappingProxy(TestMapping.class);
046: proxy.setInput("testinput");
047: assertTrue(proxy.wasSetInputCalled());
048: assertEquals("testinput", proxy.getSetInputParam());
049: assertEquals("testinput", delegate.getInput());
050: assertEquals("testinput", proxy.getInput());
051: proxy.setScope("request");
052: proxy.setForward("testforward");
053: assertEquals("request", proxy.getScope());
054: assertEquals("testforward", proxy.getForward());
055: assertEquals("request", delegate.getScope());
056: assertEquals("testforward", delegate.getForward());
057: proxy.setValidate(false);
058: proxy.setParameter("parameter");
059: proxy.setType("mytype");
060: assertEquals(false, proxy.getValidate());
061: assertEquals("parameter", proxy.getParameter());
062: assertEquals("mytype", proxy.getType());
063: assertEquals(false, delegate.getValidate());
064: assertEquals("parameter", delegate.getParameter());
065: assertEquals("mytype", delegate.getType());
066: }
067:
068: public static class TestMapping extends ActionMapping {
069: private boolean findForwardCalled = false;
070: private boolean findForwardsCalled = false;
071: private boolean getInputForwardCalled = false;
072: private boolean setInputCalled = false;
073: private boolean freezeCalled = false;
074: private String setInputParam = null;
075:
076: public boolean wasFindForwardCalled() {
077: return findForwardCalled;
078: }
079:
080: public boolean wasFindForwardsCalled() {
081: return findForwardsCalled;
082: }
083:
084: public boolean wasFreezeCalled() {
085: return freezeCalled;
086: }
087:
088: public boolean wasSetInputCalled() {
089: return setInputCalled;
090: }
091:
092: public boolean wasGetInputForwardCalled() {
093: return getInputForwardCalled;
094: }
095:
096: public String getSetInputParam() {
097: return setInputParam;
098: }
099:
100: public ActionForward findForward(String name) {
101: findForwardCalled = true;
102: return null;
103: }
104:
105: public String[] findForwards() {
106: findForwardsCalled = true;
107: return null;
108: }
109:
110: public void setInput(String input) {
111: setInputCalled = true;
112: setInputParam = input;
113: super .setInput(input);
114: }
115:
116: public ActionForward getInputForward() {
117: getInputForwardCalled = true;
118: return null;
119: }
120:
121: public void freeze() {
122: freezeCalled = true;
123: }
124: }
125: }
|