1 15 package org.apache.tapestry.portlet; 16 17 import javax.portlet.ActionRequest; 18 import javax.portlet.ActionResponse; 19 import javax.portlet.PortletConfig; 20 import javax.portlet.PortletContext; 21 import javax.portlet.RenderRequest; 22 import javax.portlet.RenderResponse; 23 24 import org.apache.hivemind.Registry; 25 import org.apache.hivemind.test.HiveMindTestCase; 26 import org.easymock.MockControl; 27 28 34 public class TestApplicationPortlet extends HiveMindTestCase 35 { 36 public static class ApplicationPortletFixture extends ApplicationPortlet 37 { 38 private final Registry _constructRegistry; 39 40 public ApplicationPortletFixture(Registry registry) 41 { 42 _constructRegistry = registry; 43 } 44 45 protected Registry constructRegistry(PortletConfig config) 46 { 47 return _constructRegistry; 48 } 49 } 50 51 private PortletApplicationInitializer newInitializer() 52 { 53 return (PortletApplicationInitializer) newMock(PortletApplicationInitializer.class); 54 } 55 56 private ActionRequestServicer newActionRequestServicer() 57 { 58 return (ActionRequestServicer) newMock(ActionRequestServicer.class); 59 } 60 61 private RenderRequestServicer newRenderRequestServicer() 62 { 63 return (RenderRequestServicer) newMock(RenderRequestServicer.class); 64 } 65 66 private Registry newRegistry(PortletApplicationInitializer initializer, 67 ActionRequestServicer actionRequestServicer, RenderRequestServicer renderRequestServicer) 68 { 69 MockControl control = newControl(Registry.class); 70 Registry registry = (Registry) control.getMock(); 71 72 registry.getService( 73 "tapestry.portlet.PortletApplicationInitializer", 74 PortletApplicationInitializer.class); 75 control.setReturnValue(initializer); 76 77 registry.getService("tapestry.portlet.ActionRequestServicer", ActionRequestServicer.class); 78 control.setReturnValue(actionRequestServicer); 79 80 registry.getService("tapestry.portlet.RenderRequestServicer", RenderRequestServicer.class); 81 control.setReturnValue(renderRequestServicer); 82 83 return registry; 84 } 85 86 private PortletConfig newConfig() 87 { 88 return (PortletConfig) newMock(PortletConfig.class); 89 } 90 91 private ActionRequest newActionRequest() 92 { 93 return (ActionRequest) newMock(ActionRequest.class); 94 } 95 96 private ActionResponse newActionResponse() 97 { 98 return (ActionResponse) newMock(ActionResponse.class); 99 } 100 101 private RenderRequest newRenderRequest() 102 { 103 return (RenderRequest) newMock(RenderRequest.class); 104 } 105 106 private RenderResponse newRenderResponse() 107 { 108 return (RenderResponse) newMock(RenderResponse.class); 109 } 110 111 public void testParseOptionalDescriptors() throws Exception 112 { 113 MockControl configc = MockControl.createControl(PortletConfig.class); 114 addControl(configc); 115 PortletConfig config = (PortletConfig) configc.getMock(); 116 117 MockControl contextc = MockControl.createControl(PortletContext.class); 118 addControl(contextc); 119 PortletContext context = (PortletContext) contextc.getMock(); 120 121 config.getPortletName(); 122 configc.setReturnValue("myportlet", 3); 123 124 127 config.getPortletContext(); 128 configc.setReturnValue(context, 2); 129 130 context.getResource("/WEB-INF/myportlet/hivemodule.xml"); 131 contextc.setReturnValue(getClass().getResource("hivemodule-portlet.xml"), 2); 132 133 context.getResource("/WEB-INF/hivemodule.xml"); 134 contextc.setReturnValue(getClass().getResource("hivemodule.xml"), 2); 135 136 context.getResource("/WEB-INF/myportlet/myportlet.application"); 137 contextc.setReturnValue(null); 138 139 context.getResource("/WEB-INF/myportlet.application"); 140 contextc.setReturnValue(null); 141 142 replayControls(); 143 144 ApplicationPortlet ap = new ApplicationPortlet(); 145 146 ap.init(config); 147 148 assertNotNull(ap._registry); 149 assertNotNull(ap._actionRequestServicer); 150 assertNotNull(ap._renderRequestServicer); 151 152 assertEquals("parsed", ap._registry.expandSymbols("${module-portlet}", null)); 153 assertEquals("parsed", ap._registry.expandSymbols("${module-plain}", null)); 154 } 155 156 public void testInitAndDestroy() throws Exception 157 { 158 PortletApplicationInitializer initializer = newInitializer(); 159 ActionRequestServicer actionRequestServicer = newActionRequestServicer(); 160 RenderRequestServicer renderRequestServicer = newRenderRequestServicer(); 161 162 Registry registry = newRegistry(initializer, actionRequestServicer, renderRequestServicer); 163 PortletConfig config = newConfig(); 164 165 initializer.initialize(config); 166 167 replayControls(); 168 169 ApplicationPortletFixture portlet = new ApplicationPortletFixture(registry); 170 171 portlet.init(config); 172 173 verifyControls(); 174 175 registry.shutdown(); 176 177 replayControls(); 178 179 portlet.destroy(); 180 181 verifyControls(); 182 } 183 184 public void testProcessAction() throws Exception 185 { 186 PortletApplicationInitializer initializer = newInitializer(); 187 ActionRequestServicer actionRequestServicer = newActionRequestServicer(); 188 RenderRequestServicer renderRequestServicer = newRenderRequestServicer(); 189 190 Registry registry = newRegistry(initializer, actionRequestServicer, renderRequestServicer); 191 192 PortletConfig config = newConfig(); 193 194 initializer.initialize(config); 195 196 replayControls(); 197 198 ApplicationPortletFixture portlet = new ApplicationPortletFixture(registry); 199 200 portlet.init(config); 201 202 verifyControls(); 203 204 ActionRequest request = newActionRequest(); 205 ActionResponse response = newActionResponse(); 206 207 registry.setupThread(); 208 209 actionRequestServicer.service(request, response); 210 211 registry.cleanupThread(); 212 213 replayControls(); 214 215 portlet.processAction(request, response); 216 217 verifyControls(); 218 } 219 220 public void testProcessRender() throws Exception 221 { 222 PortletApplicationInitializer initializer = newInitializer(); 223 ActionRequestServicer actionRequestServicer = newActionRequestServicer(); 224 RenderRequestServicer renderRequestServicer = newRenderRequestServicer(); 225 226 Registry registry = newRegistry(initializer, actionRequestServicer, renderRequestServicer); 227 228 PortletConfig config = newConfig(); 229 230 initializer.initialize(config); 231 232 replayControls(); 233 234 ApplicationPortletFixture portlet = new ApplicationPortletFixture(registry); 235 236 portlet.init(config); 237 238 verifyControls(); 239 240 RenderRequest request = newRenderRequest(); 241 RenderResponse response = newRenderResponse(); 242 243 registry.setupThread(); 244 245 renderRequestServicer.service(request, response); 246 247 registry.cleanupThread(); 248 249 replayControls(); 250 251 portlet.render(request, response); 252 253 verifyControls(); 254 } 255 } | Popular Tags |