KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > wsrp > testConsumer > BaseTest


1 /*
2 * Copyright 2001-2004 The eXo platform SARL All rights reserved.
3 * Please look at license.txt in info directory for more license detail.
4 */

5
6 package org.exoplatform.services.wsrp.testConsumer;
7
8
9
10 import java.io.InputStream JavaDoc;
11 import java.net.URL JavaDoc;
12 import java.util.ArrayList JavaDoc;
13 import java.util.Collection JavaDoc;
14 import java.util.GregorianCalendar JavaDoc;
15 import junit.framework.TestCase;
16 import org.exoplatform.Constants;
17 import org.exoplatform.container.PortalContainer;
18 import org.exoplatform.services.database.HibernateService;
19 import org.exoplatform.services.portletcontainer.PortletApplicationRegister;
20 import org.exoplatform.services.portletcontainer.impl.PortletApplicationsHolder;
21 import org.exoplatform.services.portletcontainer.pci.model.PortletApp;
22 import org.exoplatform.services.portletcontainer.pci.model.XMLParser;
23 import org.exoplatform.services.wsrp.consumer.*;
24 import org.exoplatform.services.wsrp.consumer.adapters.PortletKeyAdapter;
25 import org.exoplatform.services.wsrp.consumer.adapters.UserAdapter;
26 import org.exoplatform.services.wsrp.consumer.adapters.WSRPPortletAdapter;
27 import org.exoplatform.services.wsrp.consumer.impl.ProducerImpl;
28 import org.exoplatform.services.wsrp.type.*;
29 import org.exoplatform.test.mocks.servlet.MockServletContext;
30
31 /*
32  * @author Mestrallet Benjamin
33  * benjmestrallet@users.sourceforge.net
34  * Date: 2 févr. 2004
35  * Time: 17:39:19
36  */

37
38 public class BaseTest extends TestCase {
39   protected static final String JavaDoc PORTLET_APP_PATH = "file:./war_template";
40
41   protected ProducerRegistry producerRegistry;
42   protected Producer producer;
43   protected RegistrationData registrationData;
44
45   protected static final String JavaDoc[] USER_CATEGORIES_ARRAY = {
46     "full", "standard", "minimal"
47   };
48
49   public static final String JavaDoc[] CONSUMER_MODES = {"wsrp:view", "wsrp:edit"};
50   public static final String JavaDoc[] CONSUMER_STATES = {"wsrp:normal", "wsrp:maximized"};
51   public static final String JavaDoc[] CONSUMER_SCOPES = {"chunk_data"};
52   public static final String JavaDoc[] CONSUMER_CUSTOM_PROFILES = {"what_more"};
53
54   public static final String JavaDoc PRODUCER_ID = "producerID";
55   public static final String JavaDoc PRODUCER_DESCRIPTION = "producerDescription";
56   public static final String JavaDoc PRODUCER_NAME = "producerName";
57   public static final String JavaDoc PRODUCER_MARKUP_INTERFACE_ENDPOINT = "markupInterfaceEndpoint";
58   public static final String JavaDoc PRODUCER_PORTLET_MANAGEMENT_INTERFACE_ENDPOINT = "PortletManagementInterfaceEndpoint";
59   public static final String JavaDoc PRODUCER_REGISTRATION_INTERFACE_ENDPOINT = "RegistrationInterfaceEndpoint";
60   public static final String JavaDoc PRODUCER_SERVICE_DESCRIPTION_INTERFACE_ENDPOINT = "ServiceDescriptionInterfaceEndpoint";
61
62   public static final String JavaDoc[] desiredLocales = {"en"};
63   protected PortletRegistry portletRegistry;
64   protected UserRegistry userRegistry;
65   protected UserContext userContext;
66   protected PersonName personName;
67   protected UserProfile userProfile;
68
69   public static final String JavaDoc BASE_URL = "/portal/faces/portal/portal.jsp?portal:ctx=" + Constants.DEFAUL_PORTAL_OWNER;
70   protected URLGenerator urlGenerator;
71   protected URLRewriter urlRewriter;
72   private MockServletContext mockServletContext;
73   private PortletApp portletApp_;
74   private PortletApplicationsHolder holder;
75
76   private PortletApplicationRegister portletApplicationRegister;
77
78   protected void setUp() throws Exception JavaDoc {
79     try {
80
81       URL JavaDoc url = new URL JavaDoc(PORTLET_APP_PATH + "/WEB-INF/portlet.xml");
82       InputStream JavaDoc is = url.openStream();
83       portletApp_ = XMLParser.parse(is);
84
85       Collection JavaDoc roles = new ArrayList JavaDoc();
86       roles.add("auth-user");
87
88       PortalContainer manager = PortalContainer.getInstance();
89
90       mockServletContext = new MockServletContext("hello", "./war_template");
91       mockServletContext.setInitParameter("test-param", "test-parame-value");
92
93       portletApplicationRegister = (PortletApplicationRegister) manager.
94         getComponentInstanceOfType(PortletApplicationRegister.class);
95     
96       portletApplicationRegister.registerPortletApplication(mockServletContext, portletApp_, roles);
97
98     } catch (Exception JavaDoc ex) {
99       ex.printStackTrace();
100     }
101
102     PortalContainer manager = PortalContainer.getInstance();
103     producerRegistry = (ProducerRegistry) manager.getComponentInstanceOfType(ProducerRegistry.class);
104     portletRegistry = (PortletRegistry) manager.getComponentInstanceOfType(PortletRegistry.class);
105     userRegistry = (UserRegistry) manager.getComponentInstanceOfType(UserRegistry.class);
106
107     registrationData = new RegistrationData();
108     registrationData.setConsumerName("www.exoplatform.com");
109     registrationData.setConsumerAgent("exoplatform.1.0");
110     registrationData.setMethodGetSupported(false);
111     registrationData.setConsumerModes(CONSUMER_MODES);
112     registrationData.setConsumerWindowStates(CONSUMER_STATES);
113     registrationData.setConsumerUserScopes(CONSUMER_SCOPES);
114     registrationData.setCustomUserProfileData(CONSUMER_CUSTOM_PROFILES);
115
116     producer = new ProducerImpl();
117     producer.setID(PRODUCER_ID);
118     producer.setDescription(PRODUCER_DESCRIPTION);
119     producer.setName(PRODUCER_NAME);
120     //producer.setMarkupInterfaceEndpoint(PRODUCER_MARKUP_INTERFACE_ENDPOINT);
121
producer.setPortletManagementInterfaceEndpoint(PRODUCER_PORTLET_MANAGEMENT_INTERFACE_ENDPOINT);
122     producer.setRegistrationInterfaceEndpoint(PRODUCER_REGISTRATION_INTERFACE_ENDPOINT);
123     producer.setServiceDescriptionInterfaceEndpoint(PRODUCER_SERVICE_DESCRIPTION_INTERFACE_ENDPOINT);
124
125     personName = new PersonName();
126     personName.setNickname("exotest");
127
128     userProfile = new UserProfile();
129     userProfile.setBdate(new GregorianCalendar JavaDoc());
130     userProfile.setGender("male");
131     userProfile.setName(personName);
132
133     userContext = new UserContext();
134     userContext.setUserCategories(USER_CATEGORIES_ARRAY);
135     userContext.setProfile(userProfile);
136     userContext.setUserContextKey("exotest");
137
138     urlRewriter = (URLRewriter) manager.getComponentInstanceOfType(URLRewriter.class);
139   }
140
141   public void tearDown() throws Exception JavaDoc {
142     try {
143       PortalContainer manager = PortalContainer.getInstance();
144       
145       portletApplicationRegister.removePortletApplication(mockServletContext);
146       HibernateService hservice =
147           (HibernateService) manager.getComponentInstanceOfType(HibernateService.class) ;
148       hservice.closeSession();
149     } catch (Exception JavaDoc e) {
150       e.printStackTrace();
151     }
152   }
153
154   protected WSRPPortlet createPortlet(String JavaDoc portletHandle,
155                                       String JavaDoc parent,
156                                       PortletContext portletContext) {
157     PortletKey portletKey = new PortletKeyAdapter();
158     portletKey.setProducerId(PRODUCER_ID);
159     portletKey.setPortletHandle(portletHandle);
160
161     WSRPPortlet portlet = new WSRPPortletAdapter(portletKey);
162     portlet.setPortletKey(portletKey);
163     return portlet;
164   }
165
166   protected User createUser(String JavaDoc userID) {
167     User user = new UserAdapter();
168     user.setUserID(userID);
169     user.setUserContext(userContext);
170     return user;
171   }
172 }
Popular Tags