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: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
052: * @version $Id: TestRegistryDirectPart1a.java 516448 2007-03-09 16:25:47Z ate $
053: *
054: */
055: public class TestRegistryDirectPart1a extends AbstractRegistryTest {
056:
057: /*
058: * (non-Javadoc)
059: *
060: * @see junit.framework.TestCase#setUp()
061: */
062: protected void setUp() throws Exception {
063: super .setUp();
064: buildTestData();
065:
066: }
067:
068: /*
069: * (non-Javadoc)
070: *
071: * @see junit.framework.TestCase#tearDown()
072: */
073: protected void tearDown() throws Exception {
074: // super.tearDown();
075: }
076:
077: /**
078: * <p>
079: * buildTestData
080: * </p>
081: *
082: * @throws RegistryException
083: * @throws LockFailedException
084: */
085: private void buildTestData() throws RegistryException,
086: LockFailedException {
087: // Create an Application and a Web app
088: PortletApplicationDefinitionImpl app = new PortletApplicationDefinitionImpl();
089: app.setName("App_1");
090: app.setApplicationIdentifier("App_1");
091:
092: UserAttributeRef uaRef = new UserAttributeRefImpl(
093: "user-name-family", "user.name.family");
094: app.addUserAttributeRef(uaRef);
095:
096: UserAttribute ua = new UserAttributeImpl("user.name.family",
097: "User Last Name");
098: app.addUserAttribute(ua);
099:
100: JetspeedServiceReference service1 = new JetspeedServiceReferenceImpl(
101: "PortletEntityAccessComponent");
102: app.addJetspeedService(service1);
103: JetspeedServiceReference service2 = new JetspeedServiceReferenceImpl(
104: "PortletRegistryComponent");
105: app.addJetspeedService(service2);
106:
107: addDublinCore(app.getMetadata());
108:
109: WebApplicationDefinitionImpl webApp = new WebApplicationDefinitionImpl();
110: webApp.setContextRoot("/app1");
111: webApp.addDescription(Locale.FRENCH,
112: "Description: Le fromage est dans mon pantalon!");
113: webApp.addDisplayName(Locale.FRENCH,
114: "Display Name: Le fromage est dans mon pantalon!");
115:
116: PortletDefinitionComposite portlet = new PortletDefinitionImpl();
117: portlet.setClassName("org.apache.Portlet");
118: portlet.setName("Portlet 1");
119: portlet.addDescription(Locale.getDefault(),
120: "Portlet description.");
121: portlet.addDisplayName(Locale.getDefault(),
122: "Portlet display Name.");
123:
124: portlet
125: .addInitParameter("testparam", "test value",
126: "This is a test portlet parameter", Locale
127: .getDefault());
128:
129: addDublinCore(portlet.getMetadata());
130:
131: // PreferenceComposite pc = new PrefsPreference();
132: app.addPortletDefinition(portlet);
133: PreferenceSetCtrl prefSetCtrl = (PreferenceSetCtrl) portlet
134: .getPreferenceSet();
135: PreferenceComposite pc = (PreferenceComposite) prefSetCtrl.add(
136: "preference 1", Arrays.asList(new String[] { "value 1",
137: "value 2" }));
138: pc.addDescription(JetspeedLocale.getDefaultLocale(),
139: "Preference Description");
140:
141: assertNotNull(pc.getValueAt(0));
142:
143: portlet.addLanguage(registry.createLanguage(
144: Locale.getDefault(), "Portlet 1", "Portlet 1",
145: "This is Portlet 1", null));
146:
147: ContentTypeComposite html = new ContentTypeImpl();
148: html.setContentType("html/text");
149: ContentTypeComposite wml = new ContentTypeImpl();
150: html.addPortletMode(new PortletMode(MODE_EDIT));
151: html.addPortletMode(new PortletMode(MODE_VIEW));
152: html.addPortletMode(new PortletMode(MODE_HELP));
153: wml.setContentType("wml");
154: wml.addPortletMode(new PortletMode(MODE_HELP));
155: wml.addPortletMode(new PortletMode(MODE_VIEW));
156: portlet.addContentType(html);
157: portlet.addContentType(wml);
158:
159: app.setWebApplicationDefinition(webApp);
160: registry.registerPortletApplication(app);
161: }
162:
163: private void addDublinCore(GenericMetadata metadata) {
164: DublinCore dc = new DublinCoreImpl(metadata);
165: dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 1");
166: dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 2");
167: dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 3");
168: dc.addContributor(JetspeedLocale.getDefaultLocale(),
169: "Contrib 1");
170: dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 1");
171: dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 2");
172: dc.addCreator(JetspeedLocale.getDefaultLocale(), "Creator 1");
173: dc.addDescription(JetspeedLocale.getDefaultLocale(),
174: "Description 1");
175: dc.addFormat(JetspeedLocale.getDefaultLocale(), "Format 1");
176: dc.addIdentifier(JetspeedLocale.getDefaultLocale(),
177: "Identifier 1");
178: dc.addLanguage(JetspeedLocale.getDefaultLocale(), "Language 1");
179: dc.addPublisher(JetspeedLocale.getDefaultLocale(),
180: "Publisher 1");
181: dc.addRelation(JetspeedLocale.getDefaultLocale(), "Relation 1");
182: dc.addRight(JetspeedLocale.getDefaultLocale(), "Right 1");
183: dc.addSource(JetspeedLocale.getDefaultLocale(), "Source 1");
184: dc.addSubject(JetspeedLocale.getDefaultLocale(), "Subject 1");
185: dc.addType(JetspeedLocale.getDefaultLocale(), "Type 1");
186: }
187:
188: public void testData() throws Exception {
189: verifyData(false);
190: }
191: }
|