KickJava   Java API By Example, From Geeks To Geeks.

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


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

22
23 /**
24  * Created by The eXo Platform SARL .
25  * Author : Mestrallet Benjamin
26  * benjmestrallet@users.sourceforge.net
27  * Date: 16 oct. 2003
28  * Time: 18:49:32
29  */

30 public class TestPortletMode extends BaseTest{
31
32     public TestPortletMode(String JavaDoc s) {
33         super(s);
34     }
35
36     /**
37      * test (xxxvii) : As all portlets must support the VIEW portlet mode, VIEW does not
38      * have to be indicated.
39      *
40      * PLT.8.6
41      */

42     public void testImplicitViewMode(){
43         Collection JavaDoc c = portletContainer.getPortletModes("hello", "HelloWorld", "text/html");
44
45         assertTrue(contains(c, PortletMode.VIEW));
46     }
47
48     public void testOtherModes(){
49         Collection JavaDoc c = portletContainer.getPortletModes("hello", "HelloWorld", "text/html");
50
51         assertTrue(contains(c, PortletMode.EDIT));
52         assertTrue(contains(c, PortletMode.HELP));
53         assertTrue(contains(c, new PortletMode("config")));
54         assertFalse(contains(c, new PortletMode("about")));
55         assertFalse(contains(c, new PortletMode("not_exist")));
56
57         assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", PortletMode.VIEW));
58         assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", PortletMode.EDIT));
59         assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", new PortletMode("config")));
60         assertFalse(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", new PortletMode("about")));
61         assertFalse(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", new PortletMode("not_exist")));
62     }
63
64     public void testOtherMarkup(){
65     Collection JavaDoc c = portletContainer.getPortletModes("hello", "HelloWorld", "text/wml");
66
67       assertTrue(contains(c, PortletMode.EDIT));
68         assertTrue(contains(c, PortletMode.HELP));
69         assertFalse(contains(c, new PortletMode("config")));
70         assertFalse(contains(c, new PortletMode("not_exist")));
71
72         assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", PortletMode.VIEW));
73         assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", PortletMode.EDIT));
74         assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", PortletMode.HELP));
75         assertFalse(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", new PortletMode("config")));
76         assertFalse(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", new PortletMode("not_exist")));
77     }
78
79     /**
80      * test (xxxviii) : The portlet must not be invoked in a portlet mode that has not been declared as supported
81      * for a given markup type.
82      *
83      * PLT.8.6
84      */

85     public void testNonPortletAccessWhenModeIsNotDefined() {
86         ((ExoWindowID)actionInput.getWindowID()).setPortletName("HelloWorld");
87     actionInput.setPortletMode(new PortletMode("config"));
88         actionInput.setMarkup("text/wml");
89
90       ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld2");
91         input.setPortletMode(PortletMode.HELP);
92         HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
93         HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
94         try {
95             portletContainer.processAction(request, response, actionInput);
96         } catch (PortletContainerException e) {
97             assertEquals( "The portlet mode config is not supported for the text/wml markup language.", e.getMessage());
98         }
99         try {
100             portletContainer.render(request, response, input);
101         } catch (PortletContainerException e) {
102             assertEquals( "The portlet mode help is not supported for the text/html markup language.", e.getMessage());
103         }
104     }
105
106     /**
107      * test (xxxix) : The portlet container must ignore all references to custom portlet modes that are not
108      * supported by the portal implementation, or that have no mapping to portlet modes supported
109      * by the portal.
110      *
111      * PLT.8.6
112      */

113     public void testIgnoreCustomModesNotSupportedByPortal(){
114         Collection JavaDoc c = portletContainer.getPortletModes("hello", "HelloWorld2", "text/html");
115
116         assertFalse(contains(c, new PortletMode("not_supported")));
117     }
118
119
120     private boolean contains(Collection JavaDoc modes, PortletMode mode){
121         for (Iterator JavaDoc iterator = modes.iterator(); iterator.hasNext();) {
122             PortletMode portletMode = (PortletMode) iterator.next();
123             if(portletMode.toString().equals(mode.toString()))
124                 return true;
125         }
126         return false;
127     }
128
129 }
130
Popular Tags