portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/components/registry/src/test/org/apache/jetspeed/containers test-entity.groovy
Date Mon, 15 Mar 2004 19:34:29 GMT
taylor      2004/03/15 11:34:29

  Modified:    components/registry maven.xml
               components/registry/src/java repository_registry.xml
               components/registry/src/java/org/apache/jetspeed/components/portletentity
                        PortletEntityAccessComponent.java
                        PortletEntityAccessComponentImpl.java
                        PortletEntityImpl.java
               components/registry/src/java/org/apache/jetspeed/components/portletregistry
                        PortletRegistryComponentImpl.java
               components/registry/src/java/org/apache/jetspeed/om/window/impl
                        PortletWindowImpl.java
  Added:       components/registry/src/test/org/apache/jetspeed/components/portletentity
                        TestPortletEntityAccessComponent.java
               components/registry/src/test/org/apache/jetspeed/containers
                        test-entity.groovy
  Log:
  Refactored PortletEntity access
  Added PortletEntity test
  
  Revision  Changes    Path
  1.12      +3 -0      jakarta-jetspeed-2/components/registry/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/maven.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- maven.xml	4 Mar 2004 21:22:43 -0000	1.11
  +++ maven.xml	15 Mar 2004 19:34:28 -0000	1.12
  @@ -7,7 +7,10 @@
     <preGoal name="test:test">
     	<attainGoal name="db.recreate"/>
     </preGoal>
  +<property name='testcase' value='org.apache.jetspeed.components.portletregistry.TestRegistryDirect'/>

  +
   -->  
  +<property name='testcase' value='org.apache.jetspeed.components.portletentity.TestPortletEntityAccessComponent'/>

     
      <goal name="deployJar">
     	<attainGoal name="jar:install"/>
  
  
  
  1.8       +5 -5      jakarta-jetspeed-2/components/registry/src/java/repository_registry.xml
  
  Index: repository_registry.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/repository_registry.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- repository_registry.xml	11 Mar 2004 19:16:14 -0000	1.7
  +++ repository_registry.xml	15 Mar 2004 19:34:28 -0000	1.8
  @@ -1214,8 +1214,8 @@
      >
         
           <field-descriptor
  -         name="id"
  -         column="ID"
  +         name="oid"
  +         column="OID"
            jdbc-type="INTEGER"
            primarykey="true"
            autoincrement="true"
  @@ -1230,10 +1230,10 @@
         />
         
         <field-descriptor
  -         name="oid"
  -         column="GUID"
  +         name="id"
  +         column="ID"
            jdbc-type="VARCHAR"
  -         conversion="org.apache.jetspeed.util.ojb.ObjectIDtoStringFieldConversion"
  +         conversion="org.apache.jetspeed.util.ojb.ObjectIDtoStringFieldConversion" 
         />
         
        <reference-descriptor 
  
  
  
  1.4       +2 -3      jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityAccessComponent.java
  
  Index: PortletEntityAccessComponent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityAccessComponent.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PortletEntityAccessComponent.java	8 Mar 2004 00:48:24 -0000	1.3
  +++ PortletEntityAccessComponent.java	15 Mar 2004 19:34:28 -0000	1.4
  @@ -33,7 +33,7 @@
   	StoreablePortletEntityDelegate getPortletEntity(ObjectID id);
   
   
  -	StoreablePortletEntityDelegate getPortletEntity(PortletDefinition portletDefinition, String
portletName);
  +//	StoreablePortletEntityDelegate getPortletEntity(PortletDefinition portletDefinition,
String portletName);
          
   
   	StoreablePortletEntityDelegate newPortletEntityInstance(PortletDefinition portletDefinition);
  @@ -43,6 +43,5 @@
   
   
   	void storePortletEntity(PortletEntity portletEntity) throws PortletEntityNotStoredException;
  -
   
   }
  
  
  
  1.10      +5 -4      jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityAccessComponentImpl.java
  
  Index: PortletEntityAccessComponentImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityAccessComponentImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PortletEntityAccessComponentImpl.java	8 Mar 2004 00:48:24 -0000	1.9
  +++ PortletEntityAccessComponentImpl.java	15 Mar 2004 19:34:28 -0000	1.10
  @@ -77,7 +77,7 @@
               prepareTransaction(store);
               
               Filter filter = store.newFilter();
  -            filter.addEqualTo("oid", entityId.toString());
  +            filter.addEqualTo("id", entityId.toString());
               Object q = store.newQuery(PortletEntityImpl.class, filter);
               PortletEntity portletEntity = (PortletEntity) store.getObjectByQuery(q);
               if(portletEntity == null)
  @@ -94,7 +94,7 @@
   
       /**
        * @see org.apache.jetspeed.entity.PortletEntityAccessComponent#getPortletEntity(org.apache.pluto.om.portlet.PortletDefinition,
java.lang.String)
  -     */
  +     *
       public StoreablePortletEntityDelegate getPortletEntity(PortletDefinition portletDefinition,
String entityName)
       {
           ObjectID entityId = JetspeedObjectID.createPortletEntityId(portletDefinition, entityName);
  @@ -106,7 +106,8 @@
           }
           return (StoreablePortletEntityDelegate)portletEntity; //wrapEntity(portletEntity);
       }
  -
  +    */
  +    
       /**
        * @see org.apache.jetspeed.entity.PortletEntityAccessComponent#newPortletEntityInstance(org.apache.pluto.om.portlet.PortletDefinition)
        */
  
  
  
  1.4       +5 -5      jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
  
  Index: PortletEntityImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PortletEntityImpl.java	8 Mar 2004 00:48:24 -0000	1.3
  +++ PortletEntityImpl.java	15 Mar 2004 19:34:28 -0000	1.4
  @@ -44,19 +44,19 @@
   public class PortletEntityImpl implements PortletEntity, PortletEntityCtrl
   {
   
  -    private long id;
  +    private long oid;
       private long portletId;
   
  -    private JetspeedObjectID oid;
  +    private JetspeedObjectID id;
   
       public ObjectID getId()
       {
  -        return oid;
  +        return id;
       }
   
       public void setId(String id)
       {
  -        this.oid = JetspeedObjectID.createFromString(id);
  +        this.id = JetspeedObjectID.createFromString(id);
       }
   
       private static final Log log = LogFactory.getLog(PortletEntityImpl.class);
  
  
  
  1.2       +2 -2      jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregistry/PortletRegistryComponentImpl.java
  
  Index: PortletRegistryComponentImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregistry/PortletRegistryComponentImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PortletRegistryComponentImpl.java	9 Mar 2004 19:35:27 -0000	1.1
  +++ PortletRegistryComponentImpl.java	15 Mar 2004 19:34:29 -0000	1.2
  @@ -391,8 +391,8 @@
                   // content type and langs asocciated are not
                   store.deletePersistent(portlets.next());
               }
  -            store.deletePersistent(app);
  -            store.getTransaction().checkpoint();
  +            store.deletePersistent(app);            
  +            store.getTransaction().checkpoint();            
           }
           catch (LockFailedException e)
           {
  
  
  
  1.3       +3 -10     jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/window/impl/PortletWindowImpl.java
  
  Index: PortletWindowImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/window/impl/PortletWindowImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PortletWindowImpl.java	8 Mar 2004 00:49:39 -0000	1.2
  +++ PortletWindowImpl.java	15 Mar 2004 19:34:29 -0000	1.3
  @@ -36,8 +36,6 @@
   public class PortletWindowImpl implements PortletWindow, PortletWindowCtrl, Serializable
   {
       private ObjectID objectId = null;
  -    private int id;
  -    private int portletEntityId;
       private PortletEntity portletEntity = null;
   
       //counter used to generate unique id's
  @@ -45,7 +43,7 @@
   
       public PortletWindowImpl(String id)
       {
  -        this.id = JetspeedObjectID.createFromString(id).intValue();
  +        this.objectId = JetspeedObjectID.createFromString(id);
       }
   
       public PortletWindowImpl(ObjectID oid)
  @@ -65,10 +63,6 @@
       **/
       public ObjectID getId()
       {
  -        if (objectId == null)
  -        {
  -            objectId = new JetspeedObjectID(id);
  -        }
           return objectId;
       }
       /**
  @@ -89,8 +83,7 @@
        */
       public void setId(String id)
       {
  -        this.id = JetspeedObjectID.createFromString(id).intValue();
  -        objectId = null;
  +        objectId = JetspeedObjectID.createFromString(id);
       }
   
       /**
  
  
  
  1.1                  jakarta-jetspeed-2/components/registry/src/test/org/apache/jetspeed/components/portletentity/TestPortletEntityAccessComponent.java
  
  Index: TestPortletEntityAccessComponent.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.components.portletentity;
  
  import java.util.Iterator;
  import java.util.Locale;
  
  import junit.framework.Test;
  
  import org.apache.jetspeed.components.AbstractComponentAwareTestCase;
  import org.apache.jetspeed.components.ComponentAwareTestSuite;
  import org.apache.jetspeed.components.persistence.store.PersistenceStore;
  import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
  import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
  import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
  import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
  import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
  import org.apache.jetspeed.util.JetspeedObjectID;
  import org.apache.pluto.om.entity.PortletEntity;
  import org.apache.pluto.om.portlet.PortletApplicationDefinition;
  import org.apache.pluto.om.portlet.PortletDefinition;
  import org.apache.pluto.om.portlet.PortletDefinitionList;
  import org.picocontainer.MutablePicoContainer;
  
  /**
   * Test Portlet Entity Accessor
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: TestPortletEntityAccessComponent.java,v 1.1 2004/03/15 19:34:29 taylor
Exp $
   */
  public class TestPortletEntityAccessComponent extends AbstractComponentAwareTestCase 
  {
      private static MutablePicoContainer container = null;
      private static PortletEntityAccessComponent entityAccess = null;
      private static PortletRegistryComponent registry = null;
      private static final String TEST_APP = "EntityTestApp";
      private static final String TEST_PORTLET = "EntityTestPortlet";
      private static final String TEST_ENTITY = "user5/entity-9";
      
      /*
       * (non-Javadoc)
       * 
       * @see junit.framework.TestCase#setUp()
       */
      protected void setUp() throws Exception
      {        
          super.setUp();
          if (container == null)
          {
              container = (MutablePicoContainer) getContainer();
              entityAccess = (PortletEntityAccessComponent) container.getComponentInstance(PortletEntityAccessComponent.class);
              registry = (PortletRegistryComponent) container.getComponentInstance(PortletRegistryComponent.class);
          }
          setupTestData();                   
      }
  
      /*
       * (non-Javadoc)
       * 
       * @see junit.framework.TestCase#tearDown()
       */
      protected void tearDown() throws Exception
      {        
          super.tearDown();
          teardownTestData();        
      }
  
      public static Test suite()
      {
          ComponentAwareTestSuite suite = new ComponentAwareTestSuite(TestPortletEntityAccessComponent.class);
          suite.setScript("org/apache/jetspeed/containers/test-entity.groovy");
          
          return suite;
      }
  
      
  
      /**
       * @param testName
       */
      public TestPortletEntityAccessComponent(String testName)
      {
          super(testName, "./src/test/Log4j.properties");
      }
          
      public void testEntities() throws Exception
      {
          assertNotNull(container);
          
          PortletApplicationDefinition pa = registry.getPortletApplication(TEST_APP);
          assertNotNull("Portlet Application", pa);
          System.out.println("pa = " + pa.getId());
          PortletDefinitionList portlets = pa.getPortletDefinitionList(); //.get(JetspeedObjectID.createFromString(TEST_PORTLET));
          Iterator pi = portlets.iterator();
          PortletDefinition pd = null;
          while (pi.hasNext())
          {
              pd = (PortletDefinition)pi.next();
              assertTrue("Portlet Def not found", pd.getName().equals("EntityTestPortlet"));
          }
          assertNotNull("Portlet Def is null", pd);
          StoreablePortletEntityDelegate entity = entityAccess.newPortletEntityInstance(pd);
          entity.setId(TEST_ENTITY);
          entityAccess.storePortletEntity(entity);
          
          StoreablePortletEntityDelegate entity2 = entityAccess.getPortletEntity(JetspeedObjectID.createFromString(TEST_ENTITY));
          assertTrue("entity id ", entity2.getId().toString().equals(TEST_ENTITY));
          assertNotNull("entity's portlet ", entity2.getPortletDefinition());
          
          // TODO: test preferences
          System.out.println("PortletEntity Test completed.");
      }
          
      private void setupTestData()
      throws Exception
      {
          // TODO: this should strictly use the registry api only         
          PersistenceStore store = registry.getPersistenceStore();
          store.getTransaction().begin();
          PortletApplicationDefinitionImpl app = new PortletApplicationDefinitionImpl();
          app.setName(TEST_APP);
          app.setApplicationIdentifier(TEST_APP);
                  
          WebApplicationDefinitionImpl webApp = new WebApplicationDefinitionImpl();
          webApp.setContextRoot("/app1");
          webApp.addDescription(Locale.FRENCH, "Description: La fromage est dans ma pantalon!");
          webApp.addDisplayName(Locale.FRENCH, "Display Name: La fromage est dans ma pantalon!");
          
          PortletDefinitionComposite portlet = new PortletDefinitionImpl();
          portlet.setClassName("org.apache.Portlet");
          portlet.setName(TEST_PORTLET);
          portlet.addDescription(Locale.getDefault(),"Portlet description.");
          portlet.addDisplayName(Locale.getDefault(),"Portlet display Name.");
          
          portlet.addInitParameter("testparam", "test value", "This is a test portlet parameter",
Locale.getDefault());
                          
          app.addPortletDefinition(portlet);
          app.setWebApplicationDefinition(webApp);
          store.makePersistent(app);
          store.getTransaction().commit();              
      }
      
      private void teardownTestData()
      throws Exception
      {
          PortletApplicationDefinition pa = registry.getPortletApplication(TEST_APP);
          if (pa != null)
          {
              registry.removeApplication(pa);
          }
          StoreablePortletEntityDelegate entity = entityAccess.getPortletEntity(JetspeedObjectID.createFromString(TEST_ENTITY));
          if (entity != null)
          {
              entityAccess.removePortletEntity(entity);
          }
  
      }
      
  }
  
  
  
  1.1                  jakarta-jetspeed-2/components/registry/src/test/org/apache/jetspeed/containers/test-entity.groovy
  
  Index: test-entity.groovy
  ===================================================================
  import org.picocontainer.defaults.DefaultPicoContainer
  
  import org.apache.jetspeed.components.util.NanoQuickAssembler
  import java.io.File
  
  // WARNING!!!!!!
  // DO NOT use {Class}.class as it appears to be broken in Groovy
  // You end getting a Class instance of the type java.lang.Class
  // instead of the requested type!  This causes AssignabilityExceptions
  // in pico.  You need to use Class.forName() instead.
  
  
  
  // create the root container
  container = new DefaultPicoContainer()
  
  ClassLoader cl = Thread.currentThread().getContextClassLoader()
  
  NanoQuickAssembler.assemble(cl, "org/apache/jetspeed/containers/rdbms.container.groovy",
container)
  
  NanoQuickAssembler.assemble(cl, "org/apache/jetspeed/containers/persistence.container.groovy",
container)
  
  //
  // Portlet Registry
  //
  
  NanoQuickAssembler.assemble(cl, "org/apache/jetspeed/containers/registry.container.groovy",
container)
  
  return container
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message