001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.components.portletregistry;
018:
019: import java.util.Arrays;
020: import java.util.Iterator;
021: import java.util.Locale;
022:
023: import javax.portlet.PortletMode;
024:
025: import org.apache.jetspeed.components.persistence.store.LockFailedException;
026: import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
027: import org.apache.jetspeed.om.common.JetspeedServiceReference;
028: import org.apache.jetspeed.om.common.UserAttribute;
029: import org.apache.jetspeed.om.common.UserAttributeRef;
030: import org.apache.jetspeed.om.common.portlet.ContentTypeComposite;
031: import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
032: import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
033: import org.apache.jetspeed.om.common.preference.PreferenceComposite;
034: import org.apache.jetspeed.om.impl.JetspeedServiceReferenceImpl;
035: import org.apache.jetspeed.om.impl.UserAttributeImpl;
036: import org.apache.jetspeed.om.impl.UserAttributeRefImpl;
037: import org.apache.jetspeed.om.portlet.impl.ContentTypeImpl;
038: import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
039: import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
040: import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
041: import org.apache.jetspeed.util.JetspeedLocale;
042: import org.apache.pluto.om.common.PreferenceSetCtrl;
043: import org.apache.pluto.om.portlet.PortletApplicationDefinition;
044:
045: /**
046: * <p>
047: * TestPortletRegistryDAO
048: * </p>
049: *
050: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
051: * @version $Id: TestPortletRegistryDAO.java 506825 2007-02-13 02:47:07Z taylor $
052: */
053: public class TestRegistryCache extends DatasourceEnabledSpringTestCase {
054: protected PortletRegistry portletRegistry;
055:
056: /*
057: * @see TestCase#setUp()
058: */
059: protected void setUp() throws Exception {
060: super .setUp();
061: this .portletRegistry = (PortletRegistry) ctx
062: .getBean("portletRegistry");
063:
064: buildTestData();
065:
066: }
067:
068: // impl not complete
069: public void xtestProxy() throws Exception {
070: MutablePortletApplication app = portletRegistry
071: .getPortletApplication("PA-001");
072: MutablePortletApplication cached = MutablePortletApplicationProxy
073: .createProxy(app);
074: if (cached instanceof MutablePortletApplication)
075: System.out.println("ISA Mutable");
076: if (cached instanceof PortletApplicationProxy)
077: System.out.println("ISA Mutable Proxy");
078: PortletApplicationProxy proxy = (PortletApplicationProxy) cached;
079: MutablePortletApplication two = proxy.getRealApplication();
080: proxy.setRealApplication(two);
081: System.out.println("Two is " + two);
082: assertEquals(app, two);
083: }
084:
085: public void testCache() throws Exception {
086: assertNotNull(portletRegistry);
087: MutablePortletApplication one = portletRegistry
088: .getPortletApplication("PA-001");
089: MutablePortletApplication two = portletRegistry
090: .getPortletApplication("PA-001");
091: assertEquals(one, two);
092: PortletDefinitionComposite def = portletRegistry
093: .getPortletDefinitionByUniqueName("PA-001::Portlet-1");
094: assertNotNull(def);
095: assertEquals(def.getPortletApplicationDefinition(), one);
096: assertEquals(def, two.getPortletDefinitions().iterator().next());
097: MutablePortletApplication o = (MutablePortletApplication) portletRegistry
098: .getPortletApplications().iterator().next();
099: assertEquals(one, o);
100: assertEquals(portletRegistry.getAllPortletDefinitions()
101: .iterator().next(), def);
102: }
103:
104: private void buildTestData() throws RegistryException,
105: LockFailedException {
106: // start clean
107: Iterator itr = portletRegistry.getPortletApplications()
108: .iterator();
109: while (itr.hasNext()) {
110: portletRegistry
111: .removeApplication((PortletApplicationDefinition) itr
112: .next());
113: }
114:
115: // Create an Application and a Web app
116:
117: PortletApplicationDefinitionImpl app = new PortletApplicationDefinitionImpl();
118: app.setName("PA-001");
119: UserAttributeRef uaRef = new UserAttributeRefImpl(
120: "user-name-family", "user.name.family");
121: app.addUserAttributeRef(uaRef);
122:
123: UserAttribute ua = new UserAttributeImpl("user.name.family",
124: "User Last Name");
125: app.addUserAttribute(ua);
126:
127: JetspeedServiceReference service1 = new JetspeedServiceReferenceImpl(
128: "PortletEntityAccessComponent");
129: app.addJetspeedService(service1);
130: JetspeedServiceReference service2 = new JetspeedServiceReferenceImpl(
131: "PortletRegistryComponent");
132: app.addJetspeedService(service2);
133:
134: WebApplicationDefinitionImpl webApp = new WebApplicationDefinitionImpl();
135: webApp.setContextRoot("/pa-001");
136: webApp.addDescription(Locale.FRENCH,
137: "Description: Le fromage est dans mon pantalon!");
138: webApp.addDisplayName(Locale.FRENCH,
139: "Display Name: Le fromage est dans mon pantalon!");
140:
141: PortletDefinitionComposite portlet = new PortletDefinitionImpl();
142: portlet.setClassName("org.apache.Portlet");
143: portlet.setName("Portlet-1");
144: portlet.addDescription(Locale.getDefault(),
145: "POrtlet description.");
146: portlet.addDisplayName(Locale.getDefault(),
147: "Portlet display Name.");
148:
149: portlet
150: .addInitParameter("testparam", "test value",
151: "This is a test portlet parameter", Locale
152: .getDefault());
153:
154: // PreferenceComposite pc = new PrefsPreference();
155: app.addPortletDefinition(portlet);
156:
157: PreferenceSetCtrl prefSetCtrl = (PreferenceSetCtrl) portlet
158: .getPreferenceSet();
159: PreferenceComposite pc = (PreferenceComposite) prefSetCtrl.add(
160: "preference 1", Arrays.asList(new String[] { "value 1",
161: "value 2" }));
162: pc.addDescription(JetspeedLocale.getDefaultLocale(),
163: "Preference Description");
164:
165: assertNotNull(pc.getValueAt(0));
166:
167: portlet.addLanguage(portletRegistry.createLanguage(Locale
168: .getDefault(), "Portlet 1", "Portlet 1",
169: "This is Portlet 1", null));
170:
171: ContentTypeComposite html = new ContentTypeImpl();
172: html.setContentType("html/text");
173: ContentTypeComposite wml = new ContentTypeImpl();
174: html.addPortletMode(new PortletMode("EDIT"));
175: html.addPortletMode(new PortletMode("VIEW"));
176: html.addPortletMode(new PortletMode("HELP"));
177: wml.setContentType("wml");
178: wml.addPortletMode(new PortletMode("HELP"));
179: wml.addPortletMode(new PortletMode("VIEW"));
180: portlet.addContentType(html);
181: portlet.addContentType(wml);
182:
183: app.setWebApplicationDefinition(webApp);
184: portletRegistry.updatePortletApplication(app);
185: }
186:
187: /*
188: * @see TestCase#tearDown()
189: */
190: protected void tearDown() throws Exception {
191: Iterator itr = portletRegistry.getPortletApplications()
192: .iterator();
193: while (itr.hasNext()) {
194: portletRegistry
195: .removeApplication((PortletApplicationDefinition) itr
196: .next());
197: }
198: }
199:
200: protected String[] getConfigurations() {
201: return new String[] { "transaction.xml", "registry-test.xml",
202: "prefs.xml", "cache.xml" };
203: }
204:
205: }
|