KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > imp > TestPortletRequests


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5
6 package org.exoplatform.services.portletcontainer.imp;
7
8 import javax.portlet.PortletMode;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc;
18 import java.util.Locale JavaDoc;
19 import java.util.Map JavaDoc;
20
21 /**
22  * Created by the Exo Development team. Author : Mestrallet Benjamin
23  * benjmestrallet@users.sourceforge.net Date: 16 nov. 2003 Time: 16:39:59
24  */

25 public class TestPortletRequests extends BaseTest {
26
27   public TestPortletRequests(String JavaDoc s) {
28     super(s);
29   }
30
31   /**
32    * test (xlviii) : If a portlet receives a request from a client request
33    * targeted to the portlet itself, the parameters must be the string
34    * parameters encoded in the URL (added when creating the PortletURL) and the
35    * string parameters sent by the client to the portlet as part of the client
36    * request
37    *
38    * PLT.11.1.1
39    */

40   public void testIncomingRequestParameter() throws PortletContainerException {
41     MockServletRequest request = new MockServletRequest(new MockHttpSession(),
42         Locale.US, true);
43     HttpServletResponse JavaDoc 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 JavaDoc[]) aO.getRenderParameters().get(
53         "status"))[0]);
54     Map JavaDoc renderMap = new HashMap JavaDoc();
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 JavaDoc(o.getContent()).startsWith("Everything is ok"));
64   }
65
66   /**
67    * test (xlix) : The parameters the request object returns must be
68    * "x-www-formurlencoded" decoded.
69    *
70    * PLT.11.1.1
71    */

72   public void testParameterDecoding() throws PortletContainerException {
73     MockServletRequest request = new MockServletRequest(new MockHttpSession(),
74         Locale.US, true);
75     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
76     Map JavaDoc renderMap = new HashMap JavaDoc();
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 JavaDoc(o.getContent()).startsWith("Everything is ok"));
84   }
85
86   /**
87    * test (l) : The portlet-container must not propagate parameters received in
88    * an action request to subsequent render requests of the portlet.
89    *
90    * PLT.11.1.1
91    */

92   public void testNonPropagationToRenderOfParametersReceivedInAction()
93       throws PortletContainerException {
94     MockServletRequest request = new MockServletRequest(new MockHttpSession(),
95         Locale.US, true);
96     HttpServletResponse JavaDoc 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 JavaDoc[]) 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 JavaDoc(o.getContent()).startsWith("Everything is ok"));
110   }
111
112   /**
113    * test (lv) : The value returned from the getParameter method must be the
114    * first value in the array of String objects returned by getParameterValues
115    *
116    * PLT.11.1.1
117    */

118   public void testGetParameterXXMethods() throws PortletContainerException {
119     MockServletRequest request = new MockServletRequest(new MockHttpSession(),
120         Locale.US, true);
121     HttpServletResponse JavaDoc 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 JavaDoc[]) aO.getRenderParameters().get(
128         "status"))[0]);
129     Map JavaDoc renderMap = new HashMap JavaDoc();
130     renderMap.put("renderParam1", new String JavaDoc[] { "param-value1",
131         "param-value1bis" });
132     renderMap.put("renderParam2", new String JavaDoc[] { "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 JavaDoc(o.getContent()).startsWith("Everything is ok"));
139   }
140
141   /**
142    * test (lvii) : Extra parameters used by the portal/portlet-container must be
143    * invisible to the portlets receiving the request.
144    *
145    * PLT.11.1.2
146    */

147   public void testInvisibilityOfExtraParameters()
148       throws PortletContainerException {
149     MockServletRequest request = new MockServletRequest(new MockHttpSession(),
150         Locale.US, true);
151     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
152     Map JavaDoc renderMap = new HashMap JavaDoc();
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 JavaDoc(o.getContent()).startsWith("Everything is ok"));
160   }
161
162   /**
163    * test : A portlet can access portal/portlet-container specific properties
164    * and, if available, the headers of the HTTP client request through the
165    * following methods of the methods of the PortletRequest interface: �
166    * getProperty � getProperties � getPropertyNames
167    *
168    * PLT.11.1.4
169    */

170   public void testHeadersFromProperty() throws PortletContainerException {
171     MockServletRequest request = new MockServletRequest(new MockHttpSession(),
172         Locale.US, true);
173     HttpServletResponse JavaDoc 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 JavaDoc[]) aO.getRenderParameters().get(
180         "status"))[0]);
181   }
182
183   /**
184    * test : The getAuthType indicates the authentication scheme being used
185    * between the user and the portal. It may return one of the defined constants
186    * (BASIC_AUTH, DIGEST_AUTH, CERT_AUTH and FORM_AUTH) or another String value
187    * that represents a vendor provided authentication type. If the user is not
188    * authenticated the getAuthType method must return null. (lx)
189    *
190    * The getRemoteUser method returns the login name of the user making this
191    * request.
192    *
193    * The getUserPrincipal method returns a java.security.Principal object
194    * containing the name of the authenticated user.
195    *
196    * The isUserInRole method indicates if an authenticated user is included in
197    * the specified logical role.
198    *
199    * The isSecure method indicates if the request has been transmitted over a
200    * secure protocol such as HTTPS.
201    *
202    * PLT.11.1.6
203    */

204   public void testSecurityMethods() throws PortletContainerException {
205     MockServletRequest request = new MockServletRequest(new MockHttpSession(),
206         Locale.US, true);
207     HttpServletResponse JavaDoc 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 JavaDoc[]) aO.getRenderParameters().get(
214         "status"))[0]);
215   }
216
217   /**
218    * test : Portlet developers may code portlets to support multiple content
219    * types. A portlet can obtain, using the getResponseContentType method of the
220    * request object, a string representing the default content type the portlet
221    * container assumes for the output.
222    *
223    * The returned Enumeration of strings should contain the content types the
224    * portlet container supports in order of preference.
225    *
226    * test (lxi) : The first element of the enumeration must be the same content
227    * type returned by the getResponseContentType method.
228    *
229    * test (lxii) : The getResponseContentTypes method must return only the
230    * content types supported by the current portlet mode of the portlet.
231    *
232    */

233   public void testResponseContentTypesMethods()
234       throws PortletContainerException {
235     MockServletRequest request = new MockServletRequest(new MockHttpSession(),
236         Locale.US, true);
237     HttpServletResponse JavaDoc 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 JavaDoc[]) aO.getRenderParameters().get(
245         "status"))[0]);
246     Map JavaDoc renderMap = new HashMap JavaDoc();
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 JavaDoc(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 JavaDoc response = new MockServletResponse(new EmptyResponse());
259     ((ExoWindowID) input.getWindowID())
260         .setPortletName("PortletToTestGetTitle");
261     RenderOutput o = portletContainer.render(request, response, input);
262     assertTrue(new String JavaDoc(o.getContent()).startsWith("Everything is ok"));
263   }
264
265 }
Popular Tags