1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.components.portletregistry.direct;
18
19 import java.util.Arrays;
20 import java.util.Locale;
21
22 import javax.portlet.PortletMode;
23
24 import org.apache.jetspeed.components.persistence.store.LockFailedException;
25 import org.apache.jetspeed.components.portletregistry.AbstractRegistryTest;
26 import org.apache.jetspeed.components.portletregistry.RegistryException;
27 import org.apache.jetspeed.om.common.DublinCore;
28 import org.apache.jetspeed.om.common.GenericMetadata;
29 import org.apache.jetspeed.om.common.JetspeedServiceReference;
30 import org.apache.jetspeed.om.common.UserAttribute;
31 import org.apache.jetspeed.om.common.UserAttributeRef;
32 import org.apache.jetspeed.om.common.portlet.ContentTypeComposite;
33 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
34 import org.apache.jetspeed.om.common.preference.PreferenceComposite;
35 import org.apache.jetspeed.om.impl.DublinCoreImpl;
36 import org.apache.jetspeed.om.impl.JetspeedServiceReferenceImpl;
37 import org.apache.jetspeed.om.impl.UserAttributeImpl;
38 import org.apache.jetspeed.om.impl.UserAttributeRefImpl;
39 import org.apache.jetspeed.om.portlet.impl.ContentTypeImpl;
40 import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
41 import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
42 import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
43 import org.apache.jetspeed.util.JetspeedLocale;
44 import org.apache.pluto.om.common.PreferenceSetCtrl;
45
46 /***
47 *
48 * TestRegistry runs a suite tests creating, updating, retreiving and deleting
49 * portlet information from the registry.
50 *
51 * Aggregation of Part1a, Part1b, and Part2a tests that do not
52 * get executed in a predictable order by maven/junit.
53 *
54 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
55 * @version $Id$
56 *
57 */
58 public class TestRegistryDirectAll extends AbstractRegistryTest
59 {
60
61
62
63
64
65
66 protected void setUp() throws Exception
67 {
68 super.setUp();
69 buildTestData();
70
71 }
72
73
74
75
76
77
78 protected void tearDown() throws Exception
79 {
80
81 }
82
83
84
85 /***
86 * <p>
87 * buildTestData
88 * </p>
89 *
90 * @throws RegistryException
91 * @throws LockFailedException
92 */
93 private void buildTestData() throws RegistryException, LockFailedException
94 {
95
96 PortletApplicationDefinitionImpl app = new PortletApplicationDefinitionImpl();
97 app.setName("App_1");
98 app.setApplicationIdentifier("App_1");
99
100 UserAttributeRef uaRef = new UserAttributeRefImpl("user-name-family", "user.name.family");
101 app.addUserAttributeRef(uaRef);
102
103 UserAttribute ua = new UserAttributeImpl("user.name.family", "User Last Name");
104 app.addUserAttribute(ua);
105
106 JetspeedServiceReference service1 = new JetspeedServiceReferenceImpl("PortletEntityAccessComponent");
107 app.addJetspeedService(service1);
108 JetspeedServiceReference service2 = new JetspeedServiceReferenceImpl("PortletRegistryComponent");
109 app.addJetspeedService(service2);
110
111 addDublinCore(app.getMetadata());
112
113 WebApplicationDefinitionImpl webApp = new WebApplicationDefinitionImpl();
114 webApp.setContextRoot("/app1");
115 webApp.addDescription(Locale.FRENCH, "Description: Le fromage est dans mon pantalon!");
116 webApp.addDisplayName(Locale.FRENCH, "Display Name: Le fromage est dans mon pantalon!");
117
118 PortletDefinitionComposite portlet = new PortletDefinitionImpl();
119 portlet.setClassName("org.apache.Portlet");
120 portlet.setName("Portlet 1");
121 portlet.addDescription(Locale.getDefault(), "Portlet description.");
122 portlet.addDisplayName(Locale.getDefault(), "Portlet display Name.");
123
124 portlet.addInitParameter("testparam", "test value", "This is a test portlet parameter", Locale.getDefault());
125
126 addDublinCore(portlet.getMetadata());
127
128
129 app.addPortletDefinition(portlet);
130 PreferenceSetCtrl prefSetCtrl = (PreferenceSetCtrl) portlet.getPreferenceSet();
131 PreferenceComposite pc = (PreferenceComposite) prefSetCtrl.add("preference 1", Arrays.asList(new String[]{
132 "value 1", "value 2"}));
133 pc.addDescription(JetspeedLocale.getDefaultLocale(), "Preference Description");
134
135 assertNotNull(pc.getValueAt(0));
136
137 portlet.addLanguage(registry.createLanguage(Locale.getDefault(), "Portlet 1", "Portlet 1", "This is Portlet 1",
138 null));
139
140 ContentTypeComposite html = new ContentTypeImpl();
141 html.setContentType("html/text");
142 ContentTypeComposite wml = new ContentTypeImpl();
143 html.addPortletMode(new PortletMode(MODE_EDIT));
144 html.addPortletMode(new PortletMode(MODE_VIEW));
145 html.addPortletMode(new PortletMode(MODE_HELP));
146 wml.setContentType("wml");
147 wml.addPortletMode(new PortletMode(MODE_HELP));
148 wml.addPortletMode(new PortletMode(MODE_VIEW));
149 portlet.addContentType(html);
150 portlet.addContentType(wml);
151
152 app.setWebApplicationDefinition(webApp);
153 registry.registerPortletApplication(app);
154 }
155
156 private void addDublinCore( GenericMetadata metadata )
157 {
158 DublinCore dc = new DublinCoreImpl(metadata);
159 dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 1");
160 dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 2");
161 dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 3");
162 dc.addContributor(JetspeedLocale.getDefaultLocale(), "Contrib 1");
163 dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 1");
164 dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 2");
165 dc.addCreator(JetspeedLocale.getDefaultLocale(), "Creator 1");
166 dc.addDescription(JetspeedLocale.getDefaultLocale(), "Description 1");
167 dc.addFormat(JetspeedLocale.getDefaultLocale(), "Format 1");
168 dc.addIdentifier(JetspeedLocale.getDefaultLocale(), "Identifier 1");
169 dc.addLanguage(JetspeedLocale.getDefaultLocale(), "Language 1");
170 dc.addPublisher(JetspeedLocale.getDefaultLocale(), "Publisher 1");
171 dc.addRelation(JetspeedLocale.getDefaultLocale(), "Relation 1");
172 dc.addRight(JetspeedLocale.getDefaultLocale(), "Right 1");
173 dc.addSource(JetspeedLocale.getDefaultLocale(), "Source 1");
174 dc.addSubject(JetspeedLocale.getDefaultLocale(), "Subject 1");
175 dc.addType(JetspeedLocale.getDefaultLocale(), "Type 1");
176 }
177
178 public void testAll() throws Exception
179 {
180
181 verifyData(false);
182
183
184 PortletApplicationDefinitionImpl app = (PortletApplicationDefinitionImpl) registry.getPortletApplication("App_1");
185 assertNotNull("PA App_1 is NULL", app);
186
187 app.addUserAttribute("user.pets.doggie", "Busby");
188
189 registry.updatePortletApplication(app);
190
191 System.out.println("PA update test complete");
192
193
194 verifyData(true);
195 }
196 }