1 5 6 package org.exoplatform.services.portletcontainer.imp; 7 8 import javax.portlet.PortletMode; 9 import javax.servlet.http.HttpServletResponse ; 10 import org.exoplatform.Constants; 11 import org.exoplatform.services.portletcontainer.PortletContainerException; 12 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.pool.EmptyResponse; 13 import org.exoplatform.services.portletcontainer.pci.*; 14 import org.exoplatform.test.mocks.servlet.MockHttpSession; 15 import org.exoplatform.test.mocks.servlet.MockServletRequest; 16 import org.exoplatform.test.mocks.servlet.MockServletResponse; 17 import java.util.HashMap ; 18 import java.util.Locale ; 19 import java.util.Map ; 20 21 25 public class TestPortletRequests extends BaseTest { 26 27 public TestPortletRequests(String s) { 28 super(s); 29 } 30 31 40 public void testIncomingRequestParameter() throws PortletContainerException { 41 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 42 Locale.US, true); 43 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 44 request.setParameter("param1", "param-value1"); 45 request.setParameter("param2", "param-value2"); 46 request.setParameter("param3", "param-value3"); 47 ((ExoWindowID) actionInput.getWindowID()) 48 .setPortletName("PortletToTestIncomingRequestParam"); 49 actionInput.setPortletMode(new PortletMode("config")); 50 ActionOutput aO = portletContainer.processAction(request, response, 51 actionInput); 52 assertEquals("Everything is ok", ((String []) aO.getRenderParameters().get( 53 "status"))[0]); 54 Map renderMap = new HashMap (); 55 renderMap.put("renderParam1", "param-value1"); 56 renderMap.put("renderParam2", "param-value2"); 57 renderMap.put("renderParam3", "param-value3"); 58 ((ExoWindowID) input.getWindowID()) 59 .setPortletName("PortletToTestIncomingRequestParam"); 60 input.setPortletMode(PortletMode.HELP); 61 input.setRenderParameters(renderMap); 62 RenderOutput o = portletContainer.render(request, response, input); 63 assertTrue(new String (o.getContent()).startsWith("Everything is ok")); 64 } 65 66 72 public void testParameterDecoding() throws PortletContainerException { 73 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 74 Locale.US, true); 75 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 76 Map renderMap = new HashMap (); 77 renderMap.put("renderParam", "param value non url encoded"); 78 ((ExoWindowID) input.getWindowID()) 79 .setPortletName("PortletToTestParameterNonEncoding"); 80 input.setPortletMode(PortletMode.HELP); 81 input.setRenderParameters(renderMap); 82 RenderOutput o = portletContainer.render(request, response, input); 83 assertTrue(new String (o.getContent()).startsWith("Everything is ok")); 84 } 85 86 92 public void testNonPropagationToRenderOfParametersReceivedInAction() 93 throws PortletContainerException { 94 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 95 Locale.US, true); 96 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 97 request.setParameter("param", "param-value"); 98 ((ExoWindowID) actionInput.getWindowID()) 99 .setPortletName("PortletToTestNonPropagationOfActionParamToRender"); 100 actionInput.setPortletMode(new PortletMode("config")); 101 ActionOutput aO = portletContainer.processAction(request, response, 102 actionInput); 103 assertEquals("Everything is ok", ((String []) aO.getRenderParameters().get( 104 "status"))[0]); 105 ((ExoWindowID) input.getWindowID()) 106 .setPortletName("PortletToTestNonPropagationOfActionParamToRender"); 107 input.setPortletMode(PortletMode.HELP); 108 RenderOutput o = portletContainer.render(request, response, input); 109 assertTrue(new String (o.getContent()).startsWith("Everything is ok")); 110 } 111 112 118 public void testGetParameterXXMethods() throws PortletContainerException { 119 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 120 Locale.US, true); 121 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 122 ((ExoWindowID) actionInput.getWindowID()) 123 .setPortletName("PortletToTestGetParameterXXXMethods"); 124 actionInput.setPortletMode(new PortletMode("config")); 125 ActionOutput aO = portletContainer.processAction(request, response, 126 actionInput); 127 assertEquals("Everything is ok", ((String []) aO.getRenderParameters().get( 128 "status"))[0]); 129 Map renderMap = new HashMap (); 130 renderMap.put("renderParam1", new String [] { "param-value1", 131 "param-value1bis" }); 132 renderMap.put("renderParam2", new String [] { "param-value2" }); 133 ((ExoWindowID) input.getWindowID()) 134 .setPortletName("PortletToTestGetParameterXXXMethods"); 135 input.setPortletMode(PortletMode.HELP); 136 input.setRenderParameters(renderMap); 137 RenderOutput o = portletContainer.render(request, response, input); 138 assertTrue(new String (o.getContent()).startsWith("Everything is ok")); 139 } 140 141 147 public void testInvisibilityOfExtraParameters() 148 throws PortletContainerException { 149 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 150 Locale.US, true); 151 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 152 Map renderMap = new HashMap (); 153 renderMap.put(Constants.PARAMETER_ENCODER + "renderParam1", "param-value1"); 154 ((ExoWindowID) input.getWindowID()) 155 .setPortletName("PortletToTestInvisibilityOfExtraParameters"); 156 input.setPortletMode(PortletMode.HELP); 157 input.setRenderParameters(renderMap); 158 RenderOutput o = portletContainer.render(request, response, input); 159 assertTrue(new String (o.getContent()).startsWith("Everything is ok")); 160 } 161 162 170 public void testHeadersFromProperty() throws PortletContainerException { 171 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 172 Locale.US, true); 173 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 174 ((ExoWindowID) actionInput.getWindowID()) 175 .setPortletName("PortletToTestAccessToHeaders"); 176 actionInput.setPortletMode(new PortletMode("config")); 177 ActionOutput aO = portletContainer.processAction(request, response, 178 actionInput); 179 assertEquals("Everything is ok", ((String []) aO.getRenderParameters().get( 180 "status"))[0]); 181 } 182 183 204 public void testSecurityMethods() throws PortletContainerException { 205 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 206 Locale.US, true); 207 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 208 ((ExoWindowID) actionInput.getWindowID()) 209 .setPortletName("PortletToTestSecurityInfoFromRequest"); 210 actionInput.setPortletMode(new PortletMode("config")); 211 ActionOutput aO = portletContainer.processAction(request, response, 212 actionInput); 213 assertEquals("Everything is ok", ((String []) aO.getRenderParameters().get( 214 "status"))[0]); 215 } 216 217 233 public void testResponseContentTypesMethods() 234 throws PortletContainerException { 235 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 236 Locale.US, true); 237 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 238 ((ExoWindowID) actionInput.getWindowID()) 239 .setPortletName("PortletToTestResponseContentTypeMethods"); 240 actionInput.setPortletMode(new PortletMode("config")); 241 actionInput.setMarkup("text/wml"); 242 ActionOutput aO = portletContainer.processAction(request, response, 243 actionInput); 244 assertEquals("Everything is ok", ((String []) aO.getRenderParameters().get( 245 "status"))[0]); 246 Map renderMap = new HashMap (); 247 ((ExoWindowID) input.getWindowID()) 248 .setPortletName("PortletToTestResponseContentTypeMethods"); 249 input.setPortletMode(PortletMode.HELP); 250 input.setRenderParameters(renderMap); 251 RenderOutput o = portletContainer.render(request, response, input); 252 assertTrue(new String (o.getContent()).startsWith("Everything is ok")); 253 } 254 255 public void testGetTitle() throws PortletContainerException { 256 MockServletRequest request = new MockServletRequest(new MockHttpSession(), 257 Locale.US, true); 258 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 259 ((ExoWindowID) input.getWindowID()) 260 .setPortletName("PortletToTestGetTitle"); 261 RenderOutput o = portletContainer.render(request, response, input); 262 assertTrue(new String (o.getContent()).startsWith("Everything is ok")); 263 } 264 265 } | Popular Tags |