1 15 package org.apache.tapestry.portlet; 16 17 import java.io.IOException ; 18 19 import javax.portlet.ActionRequest; 20 import javax.portlet.ActionResponse; 21 import javax.portlet.PortletException; 22 import javax.portlet.RenderRequest; 23 import javax.portlet.RenderResponse; 24 25 import org.apache.hivemind.test.AggregateArgumentsMatcher; 26 import org.apache.hivemind.test.ArgumentMatcher; 27 import org.apache.hivemind.test.HiveMindTestCase; 28 import org.apache.hivemind.test.TypeMatcher; 29 import org.apache.tapestry.services.WebRequestServicer; 30 import org.apache.tapestry.web.WebRequest; 31 import org.apache.tapestry.web.WebResponse; 32 import org.easymock.MockControl; 33 34 41 public class TestPortletServicerBridges extends HiveMindTestCase 42 { 43 private class WebRequestServicerFixture implements WebRequestServicer 44 { 45 WebRequest _request; 46 47 WebResponse _response; 48 49 public void service(WebRequest request, WebResponse response) throws IOException 50 { 51 _request = request; 52 _response = response; 53 } 54 55 } 56 57 public void testActionBridgeSuccess() throws Exception 58 { 59 ActionRequest request = (ActionRequest) newMock(ActionRequest.class); 60 61 MockControl responsec = newControl(ActionResponse.class); 62 ActionResponse response = (ActionResponse) responsec.getMock(); 63 64 PortletRequestGlobals prg = (PortletRequestGlobals) newMock(PortletRequestGlobals.class); 65 WebRequestServicerFixture wrs = new WebRequestServicerFixture(); 66 67 prg.store(request, response); 68 69 request.removeAttribute("FOO"); 70 response.encodeURL("FOO"); 71 responsec.setReturnValue(null); 72 73 replayControls(); 74 75 ActionRequestServicerToWebRequestServicerBridge bridge = new ActionRequestServicerToWebRequestServicerBridge(); 76 bridge.setPortletRequestGlobals(prg); 77 bridge.setWebRequestServicer(wrs); 78 79 bridge.service(request, response); 80 81 84 wrs._request.setAttribute("FOO", null); 85 wrs._response.encodeURL("FOO"); 86 87 verifyControls(); 88 } 89 90 public void testRenderBridgeSuccess() throws Exception 91 { 92 RenderRequest request = (RenderRequest) newMock(RenderRequest.class); 93 94 MockControl responsec = newControl(RenderResponse.class); 95 RenderResponse response = (RenderResponse) responsec.getMock(); 96 97 PortletRequestGlobals prg = (PortletRequestGlobals) newMock(PortletRequestGlobals.class); 98 WebRequestServicerFixture wrs = new WebRequestServicerFixture(); 99 100 prg.store(request, response); 101 102 request.removeAttribute("FOO"); 103 response.reset(); 104 105 replayControls(); 106 107 RenderRequestServicerToWebRequestServicerBridge bridge = new RenderRequestServicerToWebRequestServicerBridge(); 108 bridge.setPortletRequestGlobals(prg); 109 bridge.setWebRequestServicer(wrs); 110 111 bridge.service(request, response); 112 113 116 wrs._request.setAttribute("FOO", null); 117 118 120 wrs._response.reset(); 121 122 verifyControls(); 123 } 124 125 public void testActionBridgeFailure() throws Exception 126 { 127 ActionRequest request = (ActionRequest) newMock(ActionRequest.class); 128 ActionResponse response = (ActionResponse) newMock(ActionResponse.class); 129 PortletRequestGlobals prg = (PortletRequestGlobals) newMock(PortletRequestGlobals.class); 130 131 MockControl control = newControl(WebRequestServicer.class); 132 WebRequestServicer servicer = (WebRequestServicer) control.getMock(); 133 134 Throwable t = new RuntimeException ("Failure."); 135 136 prg.store(request, response); 137 servicer.service(new PortletWebRequest(request), new PortletWebResponse(response)); 138 control.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[] 139 { new TypeMatcher(), new TypeMatcher() })); 140 control.setThrowable(t); 141 142 replayControls(); 143 144 ActionRequestServicerToWebRequestServicerBridge bridge = new ActionRequestServicerToWebRequestServicerBridge(); 145 bridge.setPortletRequestGlobals(prg); 146 bridge.setWebRequestServicer(servicer); 147 148 try 149 { 150 151 bridge.service(request, response); 152 unreachable(); 153 } 154 catch (PortletException ex) 155 { 156 assertSame(t, ex.getCause()); 162 } 163 164 verifyControls(); 165 } 166 167 public void testRenderBridgeFailure() throws Exception 168 { 169 RenderRequest request = (RenderRequest) newMock(RenderRequest.class); 170 RenderResponse response = (RenderResponse) newMock(RenderResponse.class); 171 PortletRequestGlobals prg = (PortletRequestGlobals) newMock(PortletRequestGlobals.class); 172 173 MockControl control = newControl(WebRequestServicer.class); 174 WebRequestServicer servicer = (WebRequestServicer) control.getMock(); 175 176 Throwable t = new RuntimeException ("Failure."); 177 178 prg.store(request, response); 179 servicer.service(new PortletWebRequest(request), new RenderWebResponse(response)); 180 control.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[] 181 { new TypeMatcher(), new TypeMatcher() })); 182 control.setThrowable(t); 183 184 replayControls(); 185 186 RenderRequestServicerToWebRequestServicerBridge bridge = new RenderRequestServicerToWebRequestServicerBridge(); 187 bridge.setPortletRequestGlobals(prg); 188 bridge.setWebRequestServicer(servicer); 189 190 try 191 { 192 193 bridge.service(request, response); 194 unreachable(); 195 } 196 catch (PortletException ex) 197 { 198 assertSame(t, ex.getCause()); 204 } 205 206 verifyControls(); 207 } 208 } | Popular Tags |