1 15 package org.apache.tapestry.engine; 16 17 import java.util.Map ; 18 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpSession ; 21 22 import org.apache.hivemind.test.HiveMindTestCase; 23 import org.apache.tapestry.IPage; 24 import org.apache.tapestry.IRequestCycle; 25 import org.apache.tapestry.services.LinkFactory; 26 import org.apache.tapestry.services.ResponseRenderer; 27 import org.apache.tapestry.web.WebRequest; 28 import org.apache.tapestry.web.WebSession; 29 import org.easymock.MockControl; 30 31 37 public abstract class ServiceTestCase extends HiveMindTestCase 38 { 39 protected IRequestCycle newRequestCycle() 40 { 41 return (IRequestCycle) newMock(IRequestCycle.class); 42 } 43 44 protected IPage newPage(String name) 45 { 46 MockControl control = newControl(IPage.class); 47 IPage result = (IPage) control.getMock(); 48 49 result.getPageName(); 50 control.setReturnValue(name); 51 52 return result; 53 } 54 55 protected HttpServletRequest newRequest(HttpSession session) 56 { 57 MockControl control = newControl(HttpServletRequest .class); 58 HttpServletRequest result = (HttpServletRequest ) control.getMock(); 59 60 result.getSession(); 61 control.setReturnValue(session); 62 63 return result; 64 } 65 66 protected WebRequest newWebRequest(WebSession session) 67 { 68 MockControl control = newControl(WebRequest.class); 69 WebRequest result = (WebRequest) control.getMock(); 70 71 result.getSession(false); 72 control.setReturnValue(session); 73 74 return result; 75 } 76 77 protected HttpServletRequest newRequest(boolean create, HttpSession session) 78 { 79 MockControl control = newControl(HttpServletRequest .class); 80 HttpServletRequest result = (HttpServletRequest ) control.getMock(); 81 82 result.getSession(create); 83 control.setReturnValue(session); 84 85 return result; 86 } 87 88 protected WebRequest newWebRequest(boolean create, WebSession session) 89 { 90 MockControl control = newControl(WebRequest.class); 91 WebRequest result = (WebRequest) control.getMock(); 92 93 result.getSession(create); 94 control.setReturnValue(session); 95 96 return result; 97 } 98 99 protected HttpSession newSession(boolean isNew) 100 { 101 MockControl control = newControl(HttpSession .class); 102 HttpSession session = (HttpSession ) control.getMock(); 103 104 session.isNew(); 105 control.setReturnValue(isNew); 106 107 return session; 108 } 109 110 protected WebSession newWebSession(boolean isNew) 111 { 112 MockControl control = newControl(WebSession.class); 113 WebSession session = (WebSession) control.getMock(); 114 115 session.isNew(); 116 control.setReturnValue(isNew); 117 118 return session; 119 } 120 121 122 protected HttpSession newSession() 123 { 124 return (HttpSession ) newMock(HttpSession .class); 125 } 126 127 protected WebSession newWebSession() 128 { 129 return (WebSession) newMock(WebSession.class); 130 } 131 132 protected ILink newLink() 133 { 134 return (ILink) newMock(ILink.class); 135 } 136 137 protected LinkFactory newLinkFactory(IRequestCycle cycle, Map parameters, boolean stateful, 138 ILink link) 139 { 140 MockControl control = newControl(LinkFactory.class); 141 LinkFactory lf = (LinkFactory) control.getMock(); 142 143 lf.constructLink(cycle, parameters, stateful); 144 145 control.setReturnValue(link); 146 147 return lf; 148 } 149 150 protected ResponseRenderer newResponseRenderer() 151 { 152 return (ResponseRenderer) newMock(ResponseRenderer.class); 153 } 154 155 } | Popular Tags |