KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > wsrp > test > TestGetServiceDescriptionInterface


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  * Created on 6 janv. 2004
6  */

7 package org.exoplatform.services.wsrp.test;
8
9
10 import org.exoplatform.services.wsrp.type.*;
11
12 /**
13  * @author Mestrallet Benjamin
14  * benjmestrallet@users.sourceforge.net
15  */

16 public class TestGetServiceDescriptionInterface extends BaseTest{
17
18   public TestGetServiceDescriptionInterface(String JavaDoc s) {
19     super(s);
20   }
21   
22   public void testGetDescription() throws Exception JavaDoc {
23     PortletDescription ps = getHelloWorldPortlet("en");
24     assertEquals("Usual Hello World Portlet", ps.getDescription().getValue());
25     
26     ps = getHelloWorldPortlet("fr");
27     assertEquals("Salut le monde Portlet", ps.getDescription().getValue());
28   }
29   
30   public void testGetDisplayName() throws Exception JavaDoc {
31     PortletDescription ps = getHelloWorldPortlet("en");
32     assertEquals("HelloWorldPortlet", ps.getDisplayName().getValue());
33     
34     ps = getHelloWorldPortlet("fr");
35     assertEquals("SalutLeMondePortlet", ps.getDisplayName().getValue());
36   }
37   
38   public void testGetTitle() throws Exception JavaDoc {
39     PortletDescription ps = getHelloWorldPortlet("en");
40     assertEquals("HelloWorld title", ps.getTitle().getValue());
41     
42     ps = getHelloWorldPortlet("fr");
43     assertEquals("Bonjour le monde Portlet", ps.getTitle().getValue());
44   }
45
46   public void testGetShortTitle() throws Exception JavaDoc {
47     PortletDescription ps = getHelloWorldPortlet("en");
48     assertEquals("Hello World", ps.getShortTitle().getValue());
49     
50     ps = getHelloWorldPortlet("fr");
51     assertEquals("Bonjour", ps.getShortTitle().getValue());
52   }
53   
54   public void testGetKeyWords() throws Exception JavaDoc {
55     PortletDescription ps = getHelloWorldPortlet("en");
56     assertEquals("sample", ps.getKeywords(0).getValue());
57     assertEquals("hello", ps.getKeywords(1).getValue());
58     
59     ps = getHelloWorldPortlet("fr");
60     assertEquals("exemple", ps.getKeywords(0).getValue());
61     assertEquals("bonjour", ps.getKeywords(1).getValue());
62   }
63   
64   public void testGetPortletHandle() throws Exception JavaDoc{
65     PortletDescription ps = getHelloWorldPortlet("en");
66     assertEquals("hello/HelloWorld", ps.getPortletHandle());
67   }
68   
69   public void testGetGroupId() throws Exception JavaDoc{
70     PortletDescription ps = getHelloWorldPortlet("en");
71     assertEquals("hello", ps.getGroupID());
72   }
73   
74   public void testGetMarkup() throws Exception JavaDoc {
75     PortletDescription ps = getHelloWorldPortlet("en");
76     MarkupType mT = ps.getMarkupTypes(0);
77     
78     assertEquals("text/html", mT.getMimeType());
79     assertEquals("wsrp:config", mT.getModes(0));
80     assertEquals("wsrp:help", mT.getModes(2));
81     assertEquals("wsrp:minimized", mT.getWindowStates(0));
82     assertEquals("wsrp:normal", mT.getWindowStates(1));
83     assertEquals("wsrp:maximized", mT.getWindowStates(2));
84     assertEquals("wsrp:half-page", mT.getWindowStates(3));
85     assertEquals("en", mT.getLocales()[0]);
86   }
87   
88   public void testPortletNeedsSecureTransportation() throws Exception JavaDoc {
89     PortletDescription ps = getHelloWorldPortlet("en");
90     assertEquals(false, ps.getDefaultMarkupSecure().booleanValue());
91     assertEquals(false, ps.getOnlySecure().booleanValue());
92   }
93   
94   public void testRequiresRegistration() throws Exception JavaDoc{
95     ServiceDescriptionRequest getServiceDescription = new ServiceDescriptionRequest();
96     getServiceDescription.setDesiredLocales(new String JavaDoc[]{"en"});
97     ServiceDescription sd = serviceDescriptionInterface.getServiceDescription(getServiceDescription) ;
98     assertEquals(true, sd.isRequiresRegistration());
99   }
100   
101   public void testGetCustomModes() throws Exception JavaDoc{
102     ServiceDescriptionRequest getServiceDescription = new ServiceDescriptionRequest();
103     getServiceDescription.setDesiredLocales(new String JavaDoc[]{"en"});
104     ServiceDescription sd = serviceDescriptionInterface.getServiceDescription(getServiceDescription) ;
105     ItemDescription[] iDArray = sd.getCustomModeDescriptions();
106     
107     ItemDescription iD = iDArray[0];
108     assertEquals("config",iD.getItemName());
109     assertEquals("en",iD.getDescription().getLang());
110     assertEquals("to let admin config portlets",iD.getDescription().getValue());
111     
112     iD = iDArray[1];
113     assertEquals("config",iD.getItemName());
114     assertEquals("fr",iD.getDescription().getLang());
115   }
116   
117   public void testGetCustomWindowStates() throws Exception JavaDoc{
118     ServiceDescriptionRequest getServiceDescription = new ServiceDescriptionRequest();
119     getServiceDescription.setDesiredLocales(new String JavaDoc[]{"en"});
120     ServiceDescription sd = serviceDescriptionInterface.getServiceDescription(getServiceDescription) ;
121     ItemDescription[] iDArray = sd.getCustomWindowStateDescriptions();
122     
123     ItemDescription iD = iDArray[0];
124     assertEquals("half-page",iD.getItemName());
125     assertEquals("en",iD.getDescription().getLang());
126     assertEquals("portlet takes half of the page",iD.getDescription().getValue());
127     
128     iD = iDArray[1];
129     assertEquals("half-page",iD.getItemName());
130     assertEquals("fr",iD.getDescription().getLang());
131     assertEquals("portlet sure une demi page",iD.getDescription().getValue());
132     
133     iD = iDArray[2];
134     assertEquals("max-per-column",iD.getItemName());
135     assertEquals("en",iD.getDescription().getLang());
136     assertEquals("portlet the whole column",iD.getDescription().getValue());
137   }
138   
139   public void testGetSupportedLocales() throws Exception JavaDoc{
140     ServiceDescriptionRequest getServiceDescription = new ServiceDescriptionRequest();
141     getServiceDescription.setDesiredLocales(new String JavaDoc[]{"en"});
142     ServiceDescription sd = serviceDescriptionInterface.getServiceDescription(getServiceDescription) ;
143     String JavaDoc[] localesArray = sd.getLocales();
144     assertEquals("en", localesArray[0]);
145     assertEquals("fr", localesArray[1]);
146   }
147   
148   public void testGetUserAttributes() throws Exception JavaDoc{
149     PortletDescription ps = getHelloWorldPortlet("en");
150     assertEquals("workInfo/telephone", ps.getUserProfileItems(0));
151   }
152
153   private PortletDescription getHelloWorldPortlet(String JavaDoc locale) throws Exception JavaDoc{
154     ServiceDescriptionRequest getServiceDescription = new ServiceDescriptionRequest();
155     getServiceDescription.setDesiredLocales(new String JavaDoc[]{locale});
156     ServiceDescription sd = serviceDescriptionInterface.getServiceDescription(getServiceDescription) ;
157     PortletDescription[] psArray = sd.getOfferedPortlets();
158     for (int i = 0; i < psArray.length; i++) {
159       if("hello/HelloWorld".equals(psArray[i].getPortletHandle()))
160         return psArray[i];
161     }
162     return null;
163   }
164
165 }
166
Popular Tags