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.direct;
018:
019: import java.util.Arrays;
020: import java.util.Locale;
021:
022: import javax.portlet.PortletMode;
023:
024: import org.apache.jetspeed.components.persistence.store.LockFailedException;
025: import org.apache.jetspeed.components.portletregistry.AbstractRegistryTest;
026: import org.apache.jetspeed.components.portletregistry.RegistryException;
027: import org.apache.jetspeed.om.common.DublinCore;
028: import org.apache.jetspeed.om.common.GenericMetadata;
029: import org.apache.jetspeed.om.common.JetspeedServiceReference;
030: import org.apache.jetspeed.om.common.UserAttribute;
031: import org.apache.jetspeed.om.common.UserAttributeRef;
032: import org.apache.jetspeed.om.common.portlet.ContentTypeComposite;
033: import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
034: import org.apache.jetspeed.om.common.preference.PreferenceComposite;
035: import org.apache.jetspeed.om.impl.DublinCoreImpl;
036: import org.apache.jetspeed.om.impl.JetspeedServiceReferenceImpl;
037: import org.apache.jetspeed.om.impl.UserAttributeImpl;
038: import org.apache.jetspeed.om.impl.UserAttributeRefImpl;
039: import org.apache.jetspeed.om.portlet.impl.ContentTypeImpl;
040: import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
041: import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
042: import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
043: import org.apache.jetspeed.util.JetspeedLocale;
044: import org.apache.pluto.om.common.PreferenceSetCtrl;
045:
046: /**
047: *
048: * TestRegistry runs a suite tests creating, updating, retreiving and deleting
049: * portlet information from the registry.
050: *
051: * Aggregation of Part1a, Part1b, and Part2a tests that do not
052: * get executed in a predictable order by maven/junit.
053: *
054: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
055: * @version $Id$
056: *
057: */
058: public class TestRegistryDirectAll extends AbstractRegistryTest {
059:
060: /*
061: * (non-Javadoc)
062: *
063: * @see junit.framework.TestCase#setUp()
064: */
065: protected void setUp() throws Exception {
066: super .setUp();
067: buildTestData();
068:
069: }
070:
071: /*
072: * (non-Javadoc)
073: *
074: * @see junit.framework.TestCase#tearDown()
075: */
076: protected void tearDown() throws Exception {
077: // super.tearDown();
078: }
079:
080: /**
081: * <p>
082: * buildTestData
083: * </p>
084: *
085: * @throws RegistryException
086: * @throws LockFailedException
087: */
088: private void buildTestData() throws RegistryException,
089: LockFailedException {
090: // Create an Application and a Web app
091: PortletApplicationDefinitionImpl app = new PortletApplicationDefinitionImpl();
092: app.setName("App_1");
093: app.setApplicationIdentifier("App_1");
094:
095: UserAttributeRef uaRef = new UserAttributeRefImpl(
096: "user-name-family", "user.name.family");
097: app.addUserAttributeRef(uaRef);
098:
099: UserAttribute ua = new UserAttributeImpl("user.name.family",
100: "User Last Name");
101: app.addUserAttribute(ua);
102:
103: JetspeedServiceReference service1 = new JetspeedServiceReferenceImpl(
104: "PortletEntityAccessComponent");
105: app.addJetspeedService(service1);
106: JetspeedServiceReference service2 = new JetspeedServiceReferenceImpl(
107: "PortletRegistryComponent");
108: app.addJetspeedService(service2);
109:
110: addDublinCore(app.getMetadata());
111:
112: WebApplicationDefinitionImpl webApp = new WebApplicationDefinitionImpl();
113: webApp.setContextRoot("/app1");
114: webApp.addDescription(Locale.FRENCH,
115: "Description: Le fromage est dans mon pantalon!");
116: webApp.addDisplayName(Locale.FRENCH,
117: "Display Name: Le fromage est dans mon pantalon!");
118:
119: PortletDefinitionComposite portlet = new PortletDefinitionImpl();
120: portlet.setClassName("org.apache.Portlet");
121: portlet.setName("Portlet 1");
122: portlet.addDescription(Locale.getDefault(),
123: "Portlet description.");
124: portlet.addDisplayName(Locale.getDefault(),
125: "Portlet display Name.");
126:
127: portlet
128: .addInitParameter("testparam", "test value",
129: "This is a test portlet parameter", Locale
130: .getDefault());
131:
132: addDublinCore(portlet.getMetadata());
133:
134: // PreferenceComposite pc = new PrefsPreference();
135: app.addPortletDefinition(portlet);
136: PreferenceSetCtrl prefSetCtrl = (PreferenceSetCtrl) portlet
137: .getPreferenceSet();
138: PreferenceComposite pc = (PreferenceComposite) prefSetCtrl.add(
139: "preference 1", Arrays.asList(new String[] { "value 1",
140: "value 2" }));
141: pc.addDescription(JetspeedLocale.getDefaultLocale(),
142: "Preference Description");
143:
144: assertNotNull(pc.getValueAt(0));
145:
146: portlet.addLanguage(registry.createLanguage(
147: Locale.getDefault(), "Portlet 1", "Portlet 1",
148: "This is Portlet 1", null));
149:
150: ContentTypeComposite html = new ContentTypeImpl();
151: html.setContentType("html/text");
152: ContentTypeComposite wml = new ContentTypeImpl();
153: html.addPortletMode(new PortletMode(MODE_EDIT));
154: html.addPortletMode(new PortletMode(MODE_VIEW));
155: html.addPortletMode(new PortletMode(MODE_HELP));
156: wml.setContentType("wml");
157: wml.addPortletMode(new PortletMode(MODE_HELP));
158: wml.addPortletMode(new PortletMode(MODE_VIEW));
159: portlet.addContentType(html);
160: portlet.addContentType(wml);
161:
162: app.setWebApplicationDefinition(webApp);
163: registry.registerPortletApplication(app);
164: }
165:
166: private void addDublinCore(GenericMetadata metadata) {
167: DublinCore dc = new DublinCoreImpl(metadata);
168: dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 1");
169: dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 2");
170: dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 3");
171: dc.addContributor(JetspeedLocale.getDefaultLocale(),
172: "Contrib 1");
173: dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 1");
174: dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 2");
175: dc.addCreator(JetspeedLocale.getDefaultLocale(), "Creator 1");
176: dc.addDescription(JetspeedLocale.getDefaultLocale(),
177: "Description 1");
178: dc.addFormat(JetspeedLocale.getDefaultLocale(), "Format 1");
179: dc.addIdentifier(JetspeedLocale.getDefaultLocale(),
180: "Identifier 1");
181: dc.addLanguage(JetspeedLocale.getDefaultLocale(), "Language 1");
182: dc.addPublisher(JetspeedLocale.getDefaultLocale(),
183: "Publisher 1");
184: dc.addRelation(JetspeedLocale.getDefaultLocale(), "Relation 1");
185: dc.addRight(JetspeedLocale.getDefaultLocale(), "Right 1");
186: dc.addSource(JetspeedLocale.getDefaultLocale(), "Source 1");
187: dc.addSubject(JetspeedLocale.getDefaultLocale(), "Subject 1");
188: dc.addType(JetspeedLocale.getDefaultLocale(), "Type 1");
189: }
190:
191: public void testAll() throws Exception {
192: // Part1a: data
193: verifyData(false);
194:
195: // Part1b: updates
196: PortletApplicationDefinitionImpl app = (PortletApplicationDefinitionImpl) registry
197: .getPortletApplication("App_1");
198: assertNotNull("PA App_1 is NULL", app);
199:
200: app.addUserAttribute("user.pets.doggie", "Busby");
201:
202: registry.updatePortletApplication(app);
203:
204: System.out.println("PA update test complete");
205:
206: // Part2a: data
207: verifyData(true);
208: }
209: }
|