KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.exoplatform.services.portletcontainer.imp;
2
3
4 import javax.servlet.http.HttpServletRequest JavaDoc;
5 import javax.servlet.http.HttpServletResponse JavaDoc;
6 import org.exoplatform.services.portletcontainer.PortletContainerException;
7 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.pool.EmptyResponse;
8 import org.exoplatform.services.portletcontainer.pci.ExoWindowID;
9 import org.exoplatform.services.portletcontainer.pci.RenderOutput;
10 import org.exoplatform.test.mocks.servlet.MockHttpSession;
11 import org.exoplatform.test.mocks.servlet.MockServletRequest;
12 import org.exoplatform.test.mocks.servlet.MockServletResponse;
13 import java.util.HashMap JavaDoc;
14 import java.util.Locale JavaDoc;
15 import java.util.Map JavaDoc;
16
17 /**
18  * Copyright 2001-2003 The eXo Platform SARL All rights reserved.
19  * Please look at license.txt in info directory for more license detail.
20  **/

21
22 /**
23  * Created by The eXo Platform SARL
24  * Author : Mestrallet Benjamin
25  * benjmestrallet@users.sourceforge.net
26  * Date: 15 oct. 2003
27  * Time: 20:51:01
28  */

29 public class TestPortletURL extends BaseTest{
30
31     public TestPortletURL(String JavaDoc s) {
32         super(s);
33     }
34
35
36   /**
37      * test (xxviii) : A call to any of the setParameter methods must replace
38      * any parameter with the same name previously set.
39      *
40      * PLT.7.1
41      *
42      * This test uses the PortletToTestPortletURL portlet class to test
43      */

44   public void testSetParameterMethods() throws PortletContainerException {
45         HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
46         HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
47         ((ExoWindowID)input.getWindowID()).setPortletName("PortletToTestPortletURL");
48         RenderOutput o = portletContainer.render(request, response, input);
49         assertNull(o.getTitle());
50         assertTrue(new String JavaDoc(o.getContent()).startsWith("Everything is ok"));
51     }
52
53     /**
54      * test (xxix) : All the parameters a portlet adds to a PortletURL object must be made available to
55      * the portlet as request parameters.
56      *
57      * PLT.7.1
58      */

59     public void testAvailibilityOfRenderParameters() throws PortletContainerException {
60         HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
61         HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
62         Map JavaDoc renderMap = new HashMap JavaDoc();
63         renderMap.put("testParam", "testParamValue");
64     ((ExoWindowID)input.getWindowID()).setPortletName("PortletToTestPortletURL2");
65     input.setRenderParameters(renderMap);
66         RenderOutput o = portletContainer.render(request, response, input);
67         assertNull(o.getTitle());
68         assertTrue(new String JavaDoc(o.getContent()).startsWith("Everything is ok"));
69     }
70
71     /**
72      * test (xxx) : The portlet-container must ?x-www-form-urlencoded? encode parameter
73      * names and values added to a PortletURL object.
74      *
75      * PLT.7.1
76      */

77     public void testParameterEncoding() throws PortletContainerException {
78         HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US,false);
79         HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
80         ((ExoWindowID)input.getWindowID()).setPortletName("PortletToTestParameterEncoding");
81         RenderOutput o = portletContainer.render(request, response, input);
82         assertTrue(new String JavaDoc(o.getContent()).startsWith("Everything is ok"));
83     }
84
85     /**
86      * test (xxxii) : A portlet cannot create a portlet URL using a portlet mode that is not defined as
87      * supported by the portlet or that the user it is not allowed to use. The setPortletMode
88      * methods must throw a PortletModeException in that situation.
89      *
90      * PLT.7.1.1
91      */

92     public void testModeSupport() throws PortletContainerException {
93         HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
94         HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
95         ((ExoWindowID)input.getWindowID()).setPortletName("PortletToTestModeSupport");
96         RenderOutput o = portletContainer.render(request, response, input);
97         assertEquals("Exception occured", o.getTitle());
98         assertEquals("javax.portlet.PortletModeException: The mode edit is not supported by that portlet",
99                         new String JavaDoc(o.getContent()));
100     }
101
102     /**
103      * test (xxxiv) : A portlet cannot create a portlet URL using a window state that is not
104      * supported by the portlet container. The setWindowState method must throw
105      * a WindowStateException if that is the case.
106      *
107      * PLT.7.1.1
108      */

109     public void testWindowStateSupport() throws PortletContainerException {
110         HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
111         HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
112         ((ExoWindowID)input.getWindowID()).setPortletName("PortletToTestStateSupport");
113         RenderOutput o = portletContainer.render(request, response, input);
114         assertEquals("Exception occured", o.getTitle());
115         assertEquals("javax.portlet.WindowStateException: The window state detached is not supported by the portlet container",
116                         new String JavaDoc(o.getContent()));
117     }
118
119     /**
120      * test (xxxv) : If the setSecure method is not used, the portlet URL must be of the same security
121      * level of the current request.
122      *
123      * PLT.7.1.2
124      */

125     public void testPortletURLSecurity() throws PortletContainerException {
126         HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
127         HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
128         ((ExoWindowID)input.getWindowID()).setPortletName("PortletToTestPortletURLSecurity");
129         RenderOutput o = portletContainer.render(request, response, input);
130         assertTrue(new String JavaDoc(o.getContent()).startsWith("Everything is ok"));
131     }
132
133 }
134
Popular Tags