KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.exoplatform.services.portletcontainer.imp;
2
3
4 import javax.portlet.PortletConfig;
5 import org.exoplatform.Constants;
6 import org.exoplatform.services.portletcontainer.impl.PortletDataImp;
7 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.PortletConfigImp;
8 import java.util.Enumeration JavaDoc;
9 import java.util.Locale JavaDoc;
10 import java.util.ResourceBundle JavaDoc;
11
12 /**
13  * Copyright 2001-2003 The eXo Platform SARL All rights reserved.
14  * Please look at license.txt in info directory for more license detail.
15  **/

16
17 /**
18  * Created by The eXo Platform SARL .
19  * Author : Mestrallet Benjamin
20  * benjmestrallet@users.sourceforge.net
21  * Date: 15 oct. 2003
22  * Time: 16:25:42
23  */

24 public class TestPortletConfig extends BaseTest{
25
26     PortletConfig config;
27
28     public TestPortletConfig(String JavaDoc s) {
29         super(s);
30     }
31
32     public void setUp() throws Exception JavaDoc {
33         super.setUp();
34         PortletDataImp portletDatas = (PortletDataImp) portletContainer.
35                  getAllPortletMetaData().get("hello" + Constants.PORTLET_META_DATA_ENCODER
36                  + "HelloWorld");
37
38         config = new PortletConfigImp(portletDatas.getWrappedPortletTyped(), portletContext,
39                         portletApp_.getSecurityConstraint(),
40                         portletApp_.getUserAttribute(),
41                         portletApp_.getCustomPortletMode(),
42                         portletApp_.getCustomWindowState());
43     }
44
45     /**
46      * test : The getInitParameterNames and getInitParameter methods of the PortletConfig
47      * interface return the initialization parameter names and values found in the
48      * portlet definition in the deployment descriptor.
49      *
50      * PLT.6.1
51      */

52     public void testInitializationParam(){
53         Enumeration JavaDoc e = config.getInitParameterNames();
54         assertEquals("initName", e.nextElement());
55         assertFalse(e.hasMoreElements());
56
57         assertEquals("initValue", config.getInitParameter("initName"));
58     }
59
60     /**
61      * test (xxiv) : If the portlet definition defines a resource bundle, the portlet-container
62      * must look up these values in the ResourceBundle. If the root resource bundle
63      * does not contain the resources for these values and the values are defined
64      * inline, the portlet container must add the inline values as resources of the
65      * root resource bundle.
66      *
67      * PLT.6.2
68      */

69   public void testResourceBundleCreation(){
70         Locale JavaDoc l = Locale.ENGLISH ;
71         ResourceBundle JavaDoc rB = config.getResourceBundle(l);
72     
73     assertEquals("HelloWorld title",rB.getString("javax.portlet.title"));
74     assertEquals("Hello World",rB.getString("javax.portlet.short-title"));
75         assertEquals("sample, hello",rB.getString("javax.portlet.keywords"));
76     //assertTrue(rB.getStringArray("key") instanceof String[]);
77
assertEquals(l, rB.getLocale());
78         
79         l = Locale.FRENCH ;
80         rB = config.getResourceBundle(l);
81     assertEquals("Bonjour le monde Portlet",rB.getString("javax.portlet.title"));
82     assertEquals("Bonjour",rB.getString("javax.portlet.short-title"));
83         assertEquals("exemple, bonjour",rB.getString("javax.portlet.keywords"));
84         assertEquals(l, rB.getLocale());
85     }
86
87     /**
88      * test (xxv) : If the portlet definition does not define a resource bundle
89      * and the information is defined inline in the deployment descriptor,
90      * the portlet container must create a ResourceBundle and populate it,
91      * with the inline values, using the keys defined in the PLT.21.10
92      * Resource Bundles Section.
93      *
94      * PLT.6.2
95      */

96     public void testInlineResourceBundleCreation(){
97     PortletDataImp portletDatas = (PortletDataImp) portletContainer.
98                  getAllPortletMetaData().get("hello" + Constants.PORTLET_META_DATA_ENCODER
99                  + "HelloWorld2");
100
101         config = new PortletConfigImp(portletDatas.getWrappedPortletTyped(), portletContext,
102                         portletApp_.getSecurityConstraint(),
103                         portletApp_.getUserAttribute(),
104                         portletApp_.getCustomPortletMode(),
105                         portletApp_.getCustomWindowState());
106
107         Locale JavaDoc l = Locale.US;
108         ResourceBundle JavaDoc rB = config.getResourceBundle(l);
109
110     assertEquals("HelloWorld2",rB.getString("javax.portlet.title"));
111     assertEquals("HelloWorld2s",rB.getString("javax.portlet.short-title"));
112         assertEquals("Time, Zone, World, Clock",rB.getString("javax.portlet.keywords"));
113         assertEquals(l, rB.getLocale());
114     }
115
116
117 }
118
Popular Tags