KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.exoplatform.services.portletcontainer.imp;
2
3
4 import javax.portlet.WindowState;
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpServletResponse JavaDoc;
7 import org.exoplatform.services.portletcontainer.PortletContainerException;
8 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.pool.EmptyResponse;
9 import org.exoplatform.services.portletcontainer.pci.ExoWindowID;
10 import org.exoplatform.services.portletcontainer.pci.RenderOutput;
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: 23:42:13
29  */

30 public class TestWindowState extends BaseTest{
31     public TestWindowState(String JavaDoc s) {
32         super(s);
33     }
34
35   public void testWindowStateSupport(){
36     Collection JavaDoc states = portletContainer.getWindowStates("hello");
37
38         assertTrue(contains(states,WindowState.NORMAL));
39         assertTrue(contains(states,WindowState.MINIMIZED));
40         assertTrue(contains(states,WindowState.MAXIMIZED));
41         assertTrue(contains(states,new WindowState("half-page")));
42         assertFalse(contains(states,new WindowState("max-per-column")));
43         assertFalse(contains(states, new WindowState("not_exist")));
44     }
45
46     /**
47      * test (xi) : If a custom window state defined in the deployment descriptor is not mapped to a custom
48      * window state provided by the portal, portlets must not be invoked in that window state.
49      *
50      * PLT.P.4
51      */

52     public void testPortletNotCalledWithAnUnsupportedMode() throws PortletContainerException {
53         HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
54         HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
55         ((ExoWindowID)input.getWindowID()).setPortletName("PortletToTestNonUsageOfUndefinedState");
56     input.setWindowState(new WindowState("max-per-column"));
57         RenderOutput o = portletContainer.render(request, response, input);
58         assertNull(o.getTitle());
59         assertTrue(new String JavaDoc(o.getContent()).startsWith("Everything is ok"));
60     }
61
62     private boolean contains(Collection JavaDoc modes, WindowState state){
63         for (Iterator JavaDoc iterator = modes.iterator(); iterator.hasNext();) {
64             WindowState windowState = (WindowState) iterator.next();
65             if(windowState.toString().equals(state.toString()))
66                 return true;
67         }
68         return false;
69     }
70
71 }
72
Popular Tags