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.Collection;
020: import java.util.Iterator;
021: import java.util.Locale;
022:
023: import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
024: import org.apache.jetspeed.om.common.DublinCore;
025: import org.apache.jetspeed.om.common.GenericMetadata;
026: import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
027: import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
028: import org.apache.jetspeed.om.impl.DublinCoreImpl;
029: import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
030: import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
031:
032: /**
033: * @author scott
034: */
035: public abstract class AbstractRegistryTest extends
036: DatasourceEnabledSpringTestCase {
037:
038: protected static final String PORTLET_0_CLASS = "com.portlet.MyClass0";
039:
040: protected static final String PORTLET_0_NAME = "Portlet 0";
041:
042: protected static final String PORTLET_1_CLASS = "com.portlet.MyClass";
043:
044: protected static final String PORTLET_1_NAME = "Portlet 1";
045:
046: protected static final String PORTLET_1_UID = "com.portlet.MyClass.Portlet 1";
047:
048: protected static final String PORTLET_0_UID = "com.portlet.MyClass0.Portlet 0";
049:
050: protected static final String MODE_HELP = "HELP";
051:
052: protected static final String MODE_VIEW = "VIEW";
053:
054: protected static final String MODE_EDIT = "EDIT";
055:
056: public static final String APP_1_NAME = "RegistryTestPortlet";
057:
058: protected PortletRegistry registry;
059:
060: private static int testPasses = 0;
061:
062: /**
063: * <p>
064: * setUp
065: * </p>
066: *
067: * @see junit.framework.TestCase#setUp()
068: * @throws Exception
069: */
070: protected void setUp() throws Exception {
071: super .setUp();
072: this .registry = (PortletRegistry) ctx
073: .getBean("portletRegistry");
074:
075: testPasses++;
076: }
077:
078: /**
079: * <p>
080: * tearDown
081: * </p>
082: *
083: * @see junit.framework.TestCase#tearDown()
084: * @throws Exception
085: */
086: protected void tearDown() throws Exception {
087: //super.tearDown();
088: }
089:
090: protected void validateDublinCore(GenericMetadata metadata) {
091: DublinCore dc = new DublinCoreImpl(metadata);
092: assertEquals(dc.getTitles().size(), 3);
093: assertEquals(dc.getContributors().size(), 1);
094: assertEquals(dc.getCoverages().size(), 2);
095: assertEquals(dc.getCreators().size(), 1);
096: assertEquals(dc.getDescriptions().size(), 1);
097: assertEquals(dc.getFormats().size(), 1);
098: assertEquals(dc.getIdentifiers().size(), 1);
099: assertEquals(dc.getLanguages().size(), 1);
100: assertEquals(dc.getPublishers().size(), 1);
101: assertEquals(dc.getRelations().size(), 1);
102: assertEquals(dc.getRights().size(), 1);
103: assertEquals(dc.getSources().size(), 1);
104: assertEquals(dc.getSubjects().size(), 1);
105: assertEquals(dc.getTypes().size(), 1);
106: }
107:
108: // protected void invalidate( Object[] objs ) throws LockFailedException
109: // {
110: // persistenceStore.getTransaction().begin();
111: // for (int i = 0; i < objs.length; i++)
112: // {
113: // persistenceStore.invalidate(objs[i]);
114: // }
115: // persistenceStore.getTransaction().commit();
116: // }
117:
118: protected void verifyData(boolean afterUpdates) throws Exception {
119: MutablePortletApplication app;
120: WebApplicationDefinitionImpl webApp;
121: PortletDefinitionComposite portlet;
122:
123: app = null;
124:
125: app = registry.getPortletApplication("App_1");
126:
127: webApp = (WebApplicationDefinitionImpl) app
128: .getWebApplicationDefinition();
129: portlet = (PortletDefinitionImpl) app
130: .getPortletDefinitionByName("Portlet 1");
131:
132: assertNotNull("Failed to reteive portlet application", app);
133:
134: validateDublinCore(app.getMetadata());
135:
136: Collection services = app.getJetspeedServices();
137: assertNotNull("jetspeed services is null", services);
138: System.out.println("services is " + services);
139:
140: assertNotNull(
141: "Failed to reteive portlet application via registry",
142: registry.getPortletApplication("App_1"));
143: assertNotNull(
144: "Web app was not saved along with the portlet app.",
145: webApp);
146: assertNotNull(
147: "Portlet was not saved along with the portlet app.",
148: app.getPortletDefinitionByName("Portlet 1"));
149: if (!afterUpdates) {
150: assertTrue(
151: "\"user.name.family\" user attribute was not found.",
152: app.getUserAttributes().size() == 1);
153: } else {
154: assertTrue(
155: "\"user.name.family\" and user.pets user attributes were not found.",
156: app.getUserAttributes().size() == 2);
157:
158: }
159:
160: portlet = registry
161: .getPortletDefinitionByUniqueName("App_1::Portlet 1");
162:
163: assertNotNull("Portlet could not be retreived by unique name.",
164: portlet);
165:
166: validateDublinCore(portlet.getMetadata());
167:
168: assertNotNull(
169: "Portlet Application was not set in the portlet defintion.",
170: portlet.getPortletApplicationDefinition());
171: assertNotNull(
172: "French description was not materialized for the web app.",
173: webApp.getDescription(Locale.FRENCH));
174: assertNotNull(
175: "French display name was not materialized for the web app.",
176: webApp.getDisplayName(Locale.FRENCH));
177: assertNotNull(
178: "description was not materialized for the portlet.",
179: portlet.getDescription(Locale.getDefault()));
180: assertNotNull(
181: "display name was not materialized for the portlet.",
182: portlet.getDisplayName(Locale.getDefault()));
183: assertNotNull("\"testparam\" portlet parameter was not saved",
184: portlet.getInitParameterSet().get("testparam"));
185: assertNotNull("\"preference 1\" was not found.", portlet
186: .getPreferenceSet().get("preference 1"));
187: assertNotNull("Language information not found for Portlet 1",
188: portlet.getLanguageSet().get(Locale.getDefault()));
189: assertNotNull("Content Type html not found.", portlet
190: .getContentTypeSet().get("html/text"));
191: assertNotNull("Content Type wml not found.", portlet
192: .getContentTypeSet().get("wml"));
193: Iterator itr = portlet.getPreferenceSet().get("preference 1")
194: .getValues();
195: int valueCount = 0;
196:
197: while (itr.hasNext()) {
198: itr.next();
199: valueCount++;
200: }
201: assertEquals("\"preference 1\" did not have 2 values.", 2,
202: valueCount);
203:
204: // Pull out our Web app and add a Description to it
205:
206: webApp = null;
207:
208: app = registry.getPortletApplication("App_1");
209:
210: webApp = (WebApplicationDefinitionImpl) app
211: .getWebApplicationDefinition();
212: assertNotNull("Web app was not located by query.", webApp);
213: webApp.addDescription(Locale.getDefault(),
214: "Web app description");
215:
216: webApp = null;
217:
218: app = registry.getPortletApplication("App_1");
219: webApp = (WebApplicationDefinitionImpl) app
220: .getWebApplicationDefinition();
221:
222: assertNotNull("Web app was not located by query.", webApp);
223: assertNotNull("Web app did NOT persist its description", webApp
224: .getDescription(Locale.FRENCH));
225:
226: }
227:
228: protected String[] getConfigurations() {
229: return new String[] { "transaction.xml", "prefs.xml",
230: "registry-test.xml", "cache.xml" };
231: }
232:
233: }
|