001 package com.mockrunner.base;
002
003 import com.mockrunner.mock.web.WebMockObjectFactory;
004
005 /**
006 * This class provides some convenience methods for
007 * request and session attribute handling
008 */
009 public abstract class WebTestModule
010 {
011 private WebMockObjectFactory mockFactory;
012
013 public WebTestModule(WebMockObjectFactory mockFactory)
014 {
015 this.mockFactory = mockFactory;
016 }
017
018 /**
019 * Adds an empty request parameter. Same as
020 * <code>addRequestParameter(key, "")</code>.
021 * @param key the request key
022 */
023 public void addRequestParameter(String key)
024 {
025 addRequestParameter(key, "");
026 }
027
028 /**
029 * Adds a request parameter.
030 * @param key the request key
031 * @param value the request value
032 */
033 public void addRequestParameter(String key, String value)
034 {
035 mockFactory.getMockRequest().setupAddParameter(key, value);
036 }
037
038 /**
039 * Adds several request parameters.
040 * @param key the
041 * @param values the request values
042 */
043 public void addRequestParameter(String key, String[] values)
044 {
045 mockFactory.getMockRequest().setupAddParameter(key, values);
046 }
047
048 /**
049 * Returns the request parameter for the specified key
050 * @param key the request key
051 * @return the parameter
052 */
053 public String getRequestParameter(String key)
054 {
055 return mockFactory.getWrappedRequest().getParameter(key);
056 }
057
058 /**
059 * Returns the request attribute for the specified key
060 * @param key the request key
061 * @return the attribute
062 */
063 public Object getRequestAttribute(String key)
064 {
065 return mockFactory.getWrappedRequest().getAttribute(key);
066 }
067
068 /**
069 * Sets the request attribute for the specified key
070 * @param key the request key
071 * @param value the value
072 */
073 public void setRequestAttribute(String key, Object value)
074 {
075 mockFactory.getWrappedRequest().setAttribute(key, value);
076 }
077
078 /**
079 * Returns the session attribute for the specified key
080 * @param key the session key
081 * @return the attribute
082 */
083 public Object getSessionAttribute(String key)
084 {
085 return mockFactory.getMockSession().getAttribute(key);
086 }
087
088 /**
089 * Sets the session attribute for the specified key
090 * @param key the session key
091 * @param value the value
092 */
093 public void setSessionAttribute(String key, Object value)
094 {
095 mockFactory.getMockSession().setAttribute(key, value);
096 }
097 }