001    package com.mockrunner.mock.web;
002    
003    import java.lang.reflect.Method;
004    
005    import org.apache.struts.action.ActionForward;
006    
007    /**
008     * Mock implementation of <code>ActionForward</code>.
009     */
010    public class MockActionForward extends MockForwardConfig
011    {
012        public MockActionForward()
013        {
014            this(null, false);
015        }
016        
017        public MockActionForward(String name)
018        {
019            this(name, false);
020        }
021        
022        public MockActionForward(String name, boolean redirect)
023        {
024            
025            super();
026            setName(name);
027            setPath(null);
028            setRedirect(redirect);
029            
030        }
031        
032        public MockActionForward(String name, String path, boolean redirect)
033        {
034            super();
035            setName(name);
036            setPath(path);
037            setRedirect(redirect);
038        }
039        
040        public MockActionForward(String name, String path, boolean redirect, boolean contextRelative)
041        {
042            super();
043            setName(name);
044            setPath(path);
045            setRedirect(redirect);
046            setContextRelative(contextRelative);
047        }
048    
049        public MockActionForward(String name, String path, boolean redirect, String module)
050        {
051            super();
052            setName(name);
053            setPath(path);
054            setRedirect(redirect);
055            setModule(module);
056        }
057        
058        public MockActionForward(ActionForward copyMe) 
059        {
060            setName(copyMe.getName());
061            setPath(copyMe.getPath());
062            setRedirect(copyMe.getRedirect());
063            try
064            {
065                Method getContextRelativeMethod = copyMe.getClass().getMethod("getContextRelative", null);
066                Boolean value = (Boolean)getContextRelativeMethod.invoke(copyMe, null);
067                if(null != value)
068                {
069                    setContextRelative(value.booleanValue());
070                }
071            } 
072            catch(Exception exc)
073            {
074                //Struts 1.3 does not define the method "getContextRelative"
075                //this hack is necessary to avoid different versions for Struts 1.2 and 1.3
076            }
077        }
078        
079        public boolean verifyName(String name)
080        {
081            if (null == getName()) return false;
082            if (getName().equals(name))
083            {
084                return true;
085            }
086            return false;
087        }
088        
089        public boolean verifyPath(String path)
090        {
091            if (null == getPath()) return false;
092            if (getPath().equals(path))
093            {
094                return true;
095            }
096            return false;
097        }
098        
099        public boolean verifyRedirect(boolean redirect)
100        {
101            return getRedirect() == redirect;
102        }
103    }