1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
52   * @version $Id: TestRegistryDirectPart1a.java 516448 2007-03-09 16:25:47Z ate $
53   *  
54   */
55  public class TestRegistryDirectPart1a extends AbstractRegistryTest
56  {
57  
58      /*
59       * (non-Javadoc)
60       * 
61       * @see junit.framework.TestCase#setUp()
62       */
63      protected void setUp() throws Exception
64      {
65          super.setUp();
66          buildTestData();
67  
68      }
69  
70      /*
71       * (non-Javadoc)
72       * 
73       * @see junit.framework.TestCase#tearDown()
74       */
75      protected void tearDown() throws Exception
76      {
77          //  super.tearDown();
78      }
79  
80   
81  
82      /***
83       * <p>
84       * buildTestData
85       * </p>
86       * 
87       * @throws RegistryException
88       * @throws LockFailedException
89       */
90      private void buildTestData() throws RegistryException, LockFailedException
91      {
92          // Create an Application and a Web app      
93          PortletApplicationDefinitionImpl app = new PortletApplicationDefinitionImpl();
94          app.setName("App_1");
95          app.setApplicationIdentifier("App_1");
96  
97          UserAttributeRef uaRef = new UserAttributeRefImpl("user-name-family", "user.name.family");
98          app.addUserAttributeRef(uaRef);
99  
100         UserAttribute ua = new UserAttributeImpl("user.name.family", "User Last Name");
101         app.addUserAttribute(ua);
102 
103         JetspeedServiceReference service1 = new JetspeedServiceReferenceImpl("PortletEntityAccessComponent");
104         app.addJetspeedService(service1);
105         JetspeedServiceReference service2 = new JetspeedServiceReferenceImpl("PortletRegistryComponent");
106         app.addJetspeedService(service2);
107 
108         addDublinCore(app.getMetadata());
109 
110         WebApplicationDefinitionImpl webApp = new WebApplicationDefinitionImpl();
111         webApp.setContextRoot("/app1");
112         webApp.addDescription(Locale.FRENCH, "Description: Le fromage est dans mon pantalon!");
113         webApp.addDisplayName(Locale.FRENCH, "Display Name: Le fromage est dans mon pantalon!");
114 
115         PortletDefinitionComposite portlet = new PortletDefinitionImpl();
116         portlet.setClassName("org.apache.Portlet");
117         portlet.setName("Portlet 1");
118         portlet.addDescription(Locale.getDefault(), "Portlet description.");
119         portlet.addDisplayName(Locale.getDefault(), "Portlet display Name.");
120 
121         portlet.addInitParameter("testparam", "test value", "This is a test portlet parameter", Locale.getDefault());
122 
123         addDublinCore(portlet.getMetadata());
124 
125         // PreferenceComposite pc = new PrefsPreference();
126         app.addPortletDefinition(portlet);
127         PreferenceSetCtrl prefSetCtrl = (PreferenceSetCtrl) portlet.getPreferenceSet();
128         PreferenceComposite pc = (PreferenceComposite) prefSetCtrl.add("preference 1", Arrays.asList(new String[]{
129                 "value 1", "value 2"}));
130         pc.addDescription(JetspeedLocale.getDefaultLocale(), "Preference Description");
131 
132         assertNotNull(pc.getValueAt(0));
133 
134         portlet.addLanguage(registry.createLanguage(Locale.getDefault(), "Portlet 1", "Portlet 1", "This is Portlet 1",
135                 null));
136 
137         ContentTypeComposite html = new ContentTypeImpl();
138         html.setContentType("html/text");
139         ContentTypeComposite wml = new ContentTypeImpl();
140         html.addPortletMode(new PortletMode(MODE_EDIT));
141         html.addPortletMode(new PortletMode(MODE_VIEW));
142         html.addPortletMode(new PortletMode(MODE_HELP));
143         wml.setContentType("wml");
144         wml.addPortletMode(new PortletMode(MODE_HELP));
145         wml.addPortletMode(new PortletMode(MODE_VIEW));
146         portlet.addContentType(html);
147         portlet.addContentType(wml);
148 
149         app.setWebApplicationDefinition(webApp);
150         registry.registerPortletApplication(app);
151     }
152 
153     private void addDublinCore( GenericMetadata metadata )
154     {
155         DublinCore dc = new DublinCoreImpl(metadata);
156         dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 1");
157         dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 2");
158         dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 3");
159         dc.addContributor(JetspeedLocale.getDefaultLocale(), "Contrib 1");
160         dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 1");
161         dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 2");
162         dc.addCreator(JetspeedLocale.getDefaultLocale(), "Creator 1");
163         dc.addDescription(JetspeedLocale.getDefaultLocale(), "Description 1");
164         dc.addFormat(JetspeedLocale.getDefaultLocale(), "Format 1");
165         dc.addIdentifier(JetspeedLocale.getDefaultLocale(), "Identifier 1");
166         dc.addLanguage(JetspeedLocale.getDefaultLocale(), "Language 1");
167         dc.addPublisher(JetspeedLocale.getDefaultLocale(), "Publisher 1");
168         dc.addRelation(JetspeedLocale.getDefaultLocale(), "Relation 1");
169         dc.addRight(JetspeedLocale.getDefaultLocale(), "Right 1");
170         dc.addSource(JetspeedLocale.getDefaultLocale(), "Source 1");
171         dc.addSubject(JetspeedLocale.getDefaultLocale(), "Subject 1");
172         dc.addType(JetspeedLocale.getDefaultLocale(), "Type 1");
173     }
174 
175     public void testData() throws Exception
176     {
177         verifyData(false);
178     }
179 }