weaver      2004/02/23 16:41:48

  Modified:    
components/registry/src/test/org/apache/jetspeed/components/portletregistry
                        TestRegistry.java
  Log:
  TestRegistry now actually tests ;)
  
  Revision  Changes    Path
  1.2       +329 -398  
jakarta-jetspeed-2/components/registry/src/test/org/apache/jetspeed/components/portletregistry/TestRegistry.java
  
  Index: TestRegistry.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/registry/src/test/org/apache/jetspeed/components/portletregistry/TestRegistry.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestRegistry.java 22 Feb 2004 22:40:01 -0000      1.1
  +++ TestRegistry.java 24 Feb 2004 00:41:48 -0000      1.2
  @@ -52,21 +52,57 @@
    * <http://www.apache.org/>.
    */
   package org.apache.jetspeed.components.portletregistry;
  -
  -import junit.framework.TestCase;
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.Locale;
  +import javax.naming.NameAlreadyBoundException;
  +import javax.portlet.PortletMode;
  +import junit.framework.Test;
  +import org.apache.jetspeed.components.AbstractComponentAwareTestCase;
  +import org.apache.jetspeed.components.ComponentAwareTestSuite;
  +import org.apache.jetspeed.components.datasource.DatasourceComponent;
  +import org.apache.jetspeed.components.jndi.JNDIComponent;
  +import org.apache.jetspeed.components.persistence.store.Filter;
  +import org.apache.jetspeed.components.persistence.store.PersistenceStore;
  +import org.apache.jetspeed.components.persistence.store.PersistenceStoreContainer;
  +import org.apache.jetspeed.components.persistence.store.impl.LockFailedException;
  +import org.apache.jetspeed.components.portletregsitry.PortletRegistryComponent;
  +import org.apache.jetspeed.om.common.DublinCore;
  +import org.apache.jetspeed.om.common.portlet.ContentTypeComposite;
  +import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  +import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
  +import org.apache.jetspeed.om.common.preference.PreferenceComposite;
  +import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
  +import org.apache.jetspeed.om.impl.PortletInitParameterImpl;
  +import org.apache.jetspeed.om.portlet.impl.ContentTypeImpl;
  +import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
  +import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
  +import org.apache.jetspeed.om.preference.impl.DefaultPreferenceImpl;
  +import org.apache.jetspeed.om.servlet.impl.WebApplicationDefinitionImpl;
  +import org.apache.jetspeed.util.JetspeedLocale;
  +import org.apache.ojb.otm.lock.LockingException;
  +import org.apache.pluto.om.common.Description;
  +import org.apache.pluto.om.common.DisplayName;
  +import org.apache.pluto.om.common.ParameterSetCtrl;
  +import org.apache.pluto.om.portlet.ContentType;
  +import org.apache.pluto.om.portlet.PortletDefinition;
  +import org.apache.pluto.om.servlet.WebApplicationDefinition;
  +import org.picocontainer.MutablePicoContainer;
   
   /**
    * 
    * TestRegistry runs a suite tests creating, updating, retreiving and deleting
    * portlet information from the registry.
    * 
  - * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
    * @version $Id$
  - *
  + *  
    */
  -public class TestRegistry extends TestCase
  +public class TestRegistry extends AbstractComponentAwareTestCase
   {
  -    /*private static final String PORTLET_0_CLASS = "com.portlet.MyClass0";
  +    private MutablePicoContainer container;
  +    private static final String PORTLET_0_CLASS = "com.portlet.MyClass0";
       private static final String PORTLET_0_NAME = "Portlet 0";
       private static final String PORTLET_1_CLASS = "com.portlet.MyClass";
       private static final String PORTLET_1_NAME = "Portlet 1";
  @@ -75,219 +111,266 @@
       private static final String MODE_HELP = "HELP";
       private static final String MODE_VIEW = "VIEW";
       private static final String MODE_EDIT = "EDIT";
  -
       private static int testPasses = 0;
  -    
  -    private OMFactory omFactory;
  +    public static final String APP_1_NAME = "RegistryTestPortlet";
  +    private static PortletRegistryComponent registry;
  +    private static PersistenceStore store;
   
  -    
  +    public void testContainer()
  +    {
  +        assertNotNull(container);
  +    }
   
  -    public static Test suite()
  +    /*
  +     * (non-Javadoc)
  +     * 
  +     * @see junit.framework.TestCase#setUp()
  +     */
  +    protected void setUp() throws Exception
       {
  -        // All methods starting with "test" will be executed in the test suite.
  -        JetspeedTestSuite testSuite = new JetspeedTestSuite(TestRegistry.class);
  -        
  -        PersistenceStore store = Jetspeed.getPersistenceStore();
  +        super.setUp();
  +        container = (MutablePicoContainer) getContainer();
  +        registry = (PortletRegistryComponent) 
container.getComponentInstance(PortletRegistryComponent.class);
           try
           {
  -            store.getTransaction().begin();
  -            List allPortletDefinitions = 
Jetspeed.getPortletRegistry().getAllPortletDefinitions();
  -            List allPortletApps = 
Jetspeed.getPortletRegistry().getPortletApplications();
  -            removeCollection(allPortletApps, store);
  -            removeCollection(allPortletDefinitions, store);
  -            store.getTransaction().commit();
  +            DatasourceComponent ds = (DatasourceComponent) 
container.getComponentInstance(DatasourceComponent.class);
  +            JNDIComponent jndi = (JNDIComponent) 
container.getComponentInstance(JNDIComponent.class);
  +            jndi.bindObject("comp/env/jdbc/jetspeed", ds.getDatasource());
           }
  -        catch (Exception e)
  +        catch (NameAlreadyBoundException e)
           {
  -            try
  -            {
  -                             store.getTransaction().rollback();
  -            }
  -            catch (Exception e1)
  -            {
  -                e1.printStackTrace();
  -            }
  -
  -            throw new RuntimeException("Test suite failed: " + e.toString());
  +            // ignore
  +        }
  +        PersistenceStoreContainer pContainer = (PersistenceStoreContainer) container
  +        .getComponentInstanceOfType(PersistenceStoreContainer.class);
  +        try
  +        {
  +            store = pContainer.getStoreForThread("jetspeed");
  +        } catch (Throwable e1)
  +        {
  +            
  +            // TODO Auto-generated catch block
  +            e1.printStackTrace();
  +            throw (Exception)e1;
           }
  -        return testSuite;
  +        clean();
  +        buildTestPortletApp();
  +        testPasses++;
  +    }
   
  +    /*
  +     * (non-Javadoc)
  +     * 
  +     * @see junit.framework.TestCase#tearDown()
  +     */
  +    protected void tearDown() throws Exception
  +    {
  +        clean();
  +        super.tearDown();
       }
   
  -    protected static void removeCollection(Collection col, PersistenceStore store) 
throws Exception
  +    public static Test suite()
       {
  +        // return new TestSuite(TestRegistry.class);
  +        ComponentAwareTestSuite suite = new 
ComponentAwareTestSuite(TestRegistry.class);
  +        suite.setScript("org/apache/jetspeed/containers/registry.container.groovy");
  +        return suite;
  +    }
   
  -        Iterator itr = col.iterator();
  +    //    public static Test suite()
  +    //    {
  +    //        // All methods starting with "test" will be executed in the test 
suite.
  +    //               JetspeedTestSuite testSuite = new 
JetspeedTestSuite(TestRegistry.class);
  +    //               registry = (PortletRegistryComponent)
  +    // Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
  +    //               PersistenceStoreContainer pContainer = 
(PersistenceStoreContainer)
  +    // Jetspeed.getComponentManager().getComponent(PersistenceStoreContainer.class);
  +    //               store = pContainer.getStoreForThread("jetspeed");
  +    //        try
  +    //        {
  +    //            
  +    //            List allPortletDefinitions = registry.getAllPortletDefinitions();
  +    //            List allPortletApps = registry.getPortletApplications();
  +    //            removeCollection(allPortletApps, store);
  +    //            removeCollection(allPortletDefinitions, store);
  +    //            store.getTransaction().commit();
  +    //        }
  +    //        catch (Exception e)
  +    //        {
  +    //                       store.getTransaction().rollback();
  +    //
  +    //            throw new RuntimeException("Test suite failed: " + e.toString());
  +    //        }
  +    //        return testSuite;
  +    //
  +    //    }
   
  +    protected static void removeCollection(Collection col, PersistenceStore store) 
throws LockingException, 
  +    LockFailedException
  +    {
  +        Iterator itr = col.iterator();
           while (itr.hasNext())
           {
  -
  -                     store.deletePersistent(itr.next());
  -
  +            store.deletePersistent(itr.next());
           }
       }
   
  -    public static final String APP_1_NAME = "RegistryTestPortlet";
   
  -    *//**
  +    /**
        * @param testName
  -     *//*
  +     */
       public TestRegistry(String testName)
       {
           super(testName);
       }
  -    *//**
  +
  +    /**
        * @see 
org.apache.jetspeed.test.JetspeedTest#overrideProperties(org.apache.commons.configuration.Configuration)
  -     *//*
  +     */
       //    public void overrideProperties(Configuration properties)
       //    {
       //        super.overrideProperties(properties);
       //    }
  -
       protected void buildTestPortletApp()
       {
           try
           {
  -            
  -            MutablePortletApplication pac =
  -                (MutablePortletApplication) 
omFactory.newInstance(PortletApplicationDefinition.class);
  -            MutableWebApplication wac =
  -                (MutableWebApplication) 
omFactory.newInstance(WebApplicationDefinition.class);
  -
  +            MutablePortletApplication pac = new PortletApplicationDefinitionImpl();
  +            MutableWebApplication wac = new WebApplicationDefinitionImpl();
               pac.setName(APP_1_NAME);
               pac.setDescription("This is a Registry Test Portlet.");
               pac.setVersion("1.0");
  -
  +            DublinCore dc = pac.getDublinCore();
  +            dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 1");
  +            dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 2");
  +            dc.addTitle(JetspeedLocale.getDefaultLocale(), "Test title 3");
  +            dc.addContributor(JetspeedLocale.getDefaultLocale(), "Contrib 1");
  +            dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 1");
  +            dc.addCoverage(JetspeedLocale.getDefaultLocale(), "Coverage 2");
  +            dc.addCreator(JetspeedLocale.getDefaultLocale(), "Creator 1");
  +            dc.addDescription(JetspeedLocale.getDefaultLocale(), "Description 1");
  +            dc.addFormat(JetspeedLocale.getDefaultLocale(), "Format 1");
  +            dc.addIdentifier(JetspeedLocale.getDefaultLocale(), "Identifier 1");
  +            dc.addLanguage(JetspeedLocale.getDefaultLocale(), "Language 1");
  +            dc.addPublisher(JetspeedLocale.getDefaultLocale(), "Publisher 1");
  +            dc.addRelation(JetspeedLocale.getDefaultLocale(), "Relation 1");
  +            dc.addRight(JetspeedLocale.getDefaultLocale(), "Right 1");
  +            dc.addSource(JetspeedLocale.getDefaultLocale(), "Source 1");
  +            dc.addSubject(JetspeedLocale.getDefaultLocale(), "Subject 1");
  +            dc.addType(JetspeedLocale.getDefaultLocale(), "Type 1");
               wac.setContextRoot("/root");
  -            wac.addDescription(Jetspeed.getDefaultLocale(), "This is an english 
desrcitpion");
  -            wac.addDisplayName(Jetspeed.getDefaultLocale(), "This is an english 
display name");
  -
  +            wac.addDescription(JetspeedLocale.getDefaultLocale(), "This is an 
english desrcitpion");
  +            wac.addDisplayName(JetspeedLocale.getDefaultLocale(), "This is an 
english display name");
               pac.setWebApplicationDefinition(wac);
   
               //add a portlet
  -            PortletDefinitionComposite portlet0 =
  -                (PortletDefinitionComposite) 
omFactory.newInstance(PortletDefinition.class);
  -
  +            PortletDefinitionComposite portlet0 = new PortletDefinitionImpl();
               portlet0.setClassName(PORTLET_0_CLASS);
               portlet0.setPortletIdentifier(PORTLET_0_UID);
               portlet0.setName(PORTLET_0_NAME);
               pac.addPortletDefinition(portlet0);
  -
  -
  -                     Jetspeed.getPortletRegistry().registerPortletApplication(pac);
  -                     Jetspeed.getPersistenceStore().getTransaction().commit();
  -                     
  -                     // Makes sure that subsequent calls will use the DB
  -                     invalidateAll(new Object[] {pac, portlet0, wac});
  -
  +            registry.registerPortletApplication(pac);
  +            store.getTransaction().commit();
  +            
  +            // invalidate(new Object[] {wac, portlet0, pac});
           }
  -        catch (Throwable e)
  +        catch (Exception e)
           {
               e.printStackTrace();
  -            try
  -            {
  -                Jetspeed.getPersistenceStore().getTransaction().rollback();
  -            }
  -            catch (Exception e1)
  -            {
  -                e1.printStackTrace();
  -            }
  -
  -            throw new AssertionFailedError(e.toString());
           }
       }
   
       public void testAddApplication() throws Throwable
       {
  -     
           try
           {
  -            
  -            MutablePortletApplication appExists = 
Jetspeed.getPortletRegistry().getPortletApplication(APP_1_NAME);
  +            store.getTransaction().begin();
  +            MutablePortletApplication appExists = 
registry.getPortletApplication(APP_1_NAME);
               assertNotNull(appExists);
   
               // test that the web app exists
               WebApplicationDefinition wad = appExists.getWebApplicationDefinition();
               assertNotNull(wad);
  -
  -            assertNotNull(wad.getDescription(Jetspeed.getDefaultLocale()));
  -            assertNotNull(wad.getDisplayName(Jetspeed.getDefaultLocale()));
  -
  +            assertNotNull(wad.getDescription(JetspeedLocale.getDefaultLocale()));
  +            assertNotNull(wad.getDisplayName(JetspeedLocale.getDefaultLocale()));
               PortletDefinition checkPd = 
appExists.getPortletDefinitionByName(PORTLET_0_NAME);
  -
               assertNotNull(appExists.getName() + " did not have a portlet named \"" 
+ PORTLET_0_NAME + "\"", checkPd);
  -
               String checkName = checkPd.getName();
  -
               checkPd = null;
   
  -            // Jetspeed.getPortletRegistry().clearCache();
  -
  -            PortletDefinitionComposite pdc0 =
  -                (PortletDefinitionComposite) 
Jetspeed.getPortletRegistry().getPortletDefinitionByIndetifier(PORTLET_0_UID);
  -
  -            PortletDefinitionComposite pdc2 =
  -                (PortletDefinitionComposite) 
Jetspeed.getPortletRegistry().getPortletDefinitionByUniqueName(
  -                    APP_1_NAME + "::" + PORTLET_0_NAME);
  +            // registry.clearCache();
   
  +            PortletDefinitionComposite pdc0 = 
  +            (PortletDefinitionComposite) 
registry.getPortletDefinitionByIndetifier(PORTLET_0_UID);
  +            PortletDefinitionComposite pdc2 = 
  +            (PortletDefinitionComposite) registry.getPortletDefinitionByUniqueName(
  +            APP_1_NAME + "::" + PORTLET_0_NAME);
               assertNotNull(
  -                "Could not locate PortletDefinition with unique name \"" + 
APP_1_NAME + "::" + PORTLET_0_UID + "\"",
  -                pdc2);
  -
  +            "Could not locate PortletDefinition with unique name \"" + APP_1_NAME + 
"::" + PORTLET_0_UID + "\"", 
  +            pdc2);
               assertNotNull(pdc0);
               assertEquals(checkName, pdc0.getName());
               assertNotNull(
  -                pdc0.getName() + " does not have a PortletApplicationDefinition.",
  -                pdc0.getPortletApplicationDefinition());
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  +            pdc0.getName() + " does not have a PortletApplicationDefinition.", 
  +            pdc0.getPortletApplicationDefinition());
  +            store.getTransaction().commit();
           }
  -        catch (Throwable e)
  +        catch (Exception e)
           {
  -            Jetspeed.getPersistenceStore().getTransaction().rollback();
  +            store.getTransaction().rollback();
               throw e;
           }
  +    }
   
  +    public void testDublinCore() throws Throwable
  +    {
  +        MutablePortletApplication appExists = 
registry.getPortletApplication(APP_1_NAME);
  +        assertNotNull(appExists);
  +        DublinCore dc = appExists.getDublinCore();
  +        assertEquals(dc.getTitles().size(), 3);
  +        assertEquals(dc.getContributors().size(), 1);
  +        assertEquals(dc.getCoverages().size(), 2);
  +        assertEquals(dc.getCreators().size(), 1);
  +        assertEquals(dc.getDescriptions().size(), 1);
  +        assertEquals(dc.getFormats().size(), 1);
  +        assertEquals(dc.getIdentifiers().size(), 1);
  +        assertEquals(dc.getLanguages().size(), 1);
  +        assertEquals(dc.getPublishers().size(), 1);
  +        assertEquals(dc.getRelations().size(), 1);
  +        assertEquals(dc.getRights().size(), 1);
  +        assertEquals(dc.getSources().size(), 1);
  +        assertEquals(dc.getSubjects().size(), 1);
  +        assertEquals(dc.getTypes().size(), 1);
       }
   
  -    public void testAddingPortlet() throws Exception
  +    public void testAddingPortlet() throws Throwable
       {
           try
           {
  -                        
  -            MutablePortletApplication app = 
Jetspeed.getPortletRegistry().getPortletApplication(APP_1_NAME);
  -
  +            MutablePortletApplication app = 
registry.getPortletApplication(APP_1_NAME);
               assertNotNull(app);
  -            
  -            //add a portlet
  -            PortletDefinitionComposite portlet1 =
  -                (PortletDefinitionComposite) 
omFactory.newInstance(PortletDefinition.class);
   
  +
  +            //add a portlet
  +            PortletDefinitionComposite portlet1 = new PortletDefinitionImpl();
               portlet1.setClassName(PORTLET_1_CLASS);
               portlet1.setName(PORTLET_1_NAME);
               portlet1.setPortletIdentifier(PORTLET_1_UID);
               app.addPortletDefinition(portlet1);
  -
  -            portlet1.addDisplayName(Jetspeed.getDefaultLocale(), "Portlet 1 Display 
Name");
  -            portlet1.addDescription(Jetspeed.getDefaultLocale(), "Portlet 1 
Description");
  -
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  -            
  -            // Invalidate all test objects within the cache
  -            invalidateAll(new Object[]{portlet1, app});              
  -      
  +            portlet1.addDisplayName(JetspeedLocale.getDefaultLocale(), "Portlet 1 
Display Name");
  +            portlet1.addDescription(JetspeedLocale.getDefaultLocale(), "Portlet 1 
Description");
  +            registry.updatePortletApplication(app);
  +            store.getTransaction().commit();
           }
  -        catch (Exception e)
  +        catch (Throwable e)
           {
               e.printStackTrace();
  -            Jetspeed.getPersistenceStore().getTransaction().rollback();
  +            store.getTransaction().rollback();
               throw e;
           }
  -
           try
           {
  -            
  -            //               test that portlet application exists
  -            MutablePortletApplication app = 
Jetspeed.getPortletRegistry().getPortletApplication(APP_1_NAME);
  +            MutablePortletApplication app = 
registry.getPortletApplication(APP_1_NAME);
               assertNotNull(app);
               int count = 0;
               Iterator countItr = app.getPortletDefinitionList().iterator();
  @@ -297,67 +380,54 @@
                   count++;
               }
               assertEquals(2, count);
  -
  -            PortletDefinitionComposite portlet1 = (PortletDefinitionComposite) 
app.getPortletDefinitionByName(PORTLET_1_NAME);
  -
  -            PortletDefinitionComposite portlet1_2 = 
Jetspeed.getPortletRegistry().getPortletDefinitionByIndetifier(PORTLET_1_UID);
  -
  +            PortletDefinitionComposite portlet1 = (PortletDefinitionComposite) app
  +            .getPortletDefinitionByName(PORTLET_1_NAME);
  +            PortletDefinitionComposite portlet1_2 = 
registry.getPortletDefinitionByIndetifier(PORTLET_1_UID);
               assertNotNull(portlet1);
  -            
  -                     Description desc = 
portlet1.getDescription(Jetspeed.getDefaultLocale());
  -
  -                     assertNotNull("Description for portlet definition was null.", 
desc);
  -
  -            DisplayName displayName = 
portlet1.getDisplayName(Jetspeed.getDefaultLocale());
  -
  +            Description desc = 
portlet1.getDescription(JetspeedLocale.getDefaultLocale());
  +            assertNotNull("Description for portlet definition was null.", desc);
  +            System.out.println("Default local description for Portlet 1 is " + 
desc.getDescription());
  +            DisplayName displayName = 
portlet1.getDisplayName(JetspeedLocale.getDefaultLocale());
               assertNotNull("DisplayName for portlet definition was null.", 
displayName);
  -
               System.out.println("Default local displayName  for Portlet 1 is " + 
displayName.getDisplayName());
  -
  -
  -            System.out.println("Default local description for Portlet 1 is " + 
desc.getDescription());
  -
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  +            store.getTransaction().commit();
           }
           catch (Exception e)
           {
               e.printStackTrace();
  -            Jetspeed.getPersistenceStore().getTransaction().rollback();
  +            store.getTransaction().rollback();
               throw e;
           }
  -
       }
   
       public void testAddPortletInfo() throws Throwable
       {
           try
           {
  -
  -            MutablePortletApplication app = 
Jetspeed.getPortletRegistry().getPortletApplication(APP_1_NAME);
  -
  +            MutablePortletApplication app = 
registry.getPortletApplication(APP_1_NAME);
               assertNotNull(app);
  -            
  -            PortletDefinitionComposite pdc = (PortletDefinitionComposite) 
app.getPortletDefinitionByName(PORTLET_0_NAME);
  +            PortletDefinitionComposite pdc = (PortletDefinitionComposite) app
  +            .getPortletDefinitionByName(PORTLET_0_NAME);
               assertNotNull(pdc);
   
               // add 2 parameters
  -             ((ParameterSetCtrl) pdc.getInitParameterSet()).add("param 1", "value 
1");
  +            ((ParameterSetCtrl) pdc.getInitParameterSet()).add("param 1", "value 
1");
               ((ParameterSetCtrl) pdc.getInitParameterSet()).add("param 2", "value 
2");
   
               // add a language
               pdc.addLanguage(
  -                Jetspeed.getPortletRegistry().createLanguage(
  -                    Locale.getDefault(),
  -                    "Test Portlet 0",
  -                    PORTLET_0_NAME,
  -                    "This is Portlet 0",
  -                    null));
  +            registry.createLanguage(
  +            Locale.getDefault(), 
  +            "Test Portlet 0", 
  +            PORTLET_0_NAME, 
  +            "This is Portlet 0", 
  +            null));
   
               //add content types
  -            ContentTypeComposite html =
  -                (ContentTypeComposite) omFactory.newInstance(ContentType.class);
  +            ContentTypeComposite html = 
  +            new ContentTypeImpl();
               html.setContentType("html/text");
  -            ContentTypeComposite wml = (ContentTypeComposite) 
omFactory.newInstance(ContentType.class);
  +            ContentTypeComposite wml = new ContentTypeImpl();
               html.addPortletMode(new PortletMode(MODE_EDIT));
               html.addPortletMode(new PortletMode(MODE_VIEW));
               html.addPortletMode(new PortletMode(MODE_HELP));
  @@ -366,174 +436,109 @@
               wml.addPortletMode(new PortletMode(MODE_VIEW));
               pdc.addContentType(html);
               pdc.addContentType(wml);
  -
  -            PreferenceComposite pref = pdc.addPreference("preference 1", new 
String[] { "pref 1 values 1", "pref 1 value 2" });
  -
  -            pref.addDescription(Jetspeed.getDefaultLocale(), "Preference 1 
description");
  -
  -            pdc.addDisplayName(Jetspeed.getDefaultLocale(), "Portlet 0 Display 
Name");
  -            pdc.addDescription(Jetspeed.getDefaultLocale(), "Portlet 0 
Description");
  -
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  -            
  -            // Invalidate cached objects
  -            invalidateAll(new Object[] {app, pdc, html, wml, pref});
  -
  +            PreferenceComposite pref = pdc.addPreference("preference 1", new 
String[]{"pref 1 values 1", 
  +            "pref 1 value 2"});
  +            pref.addDescription(JetspeedLocale.getDefaultLocale(), "Preference 1 
description");
  +            pdc.addDisplayName(JetspeedLocale.getDefaultLocale(), "Portlet 0 
Display Name");
  +            pdc.addDescription(JetspeedLocale.getDefaultLocale(), "Portlet 0 
Description");
  +            store.getTransaction().commit();
           }
  -        catch (Throwable e)
  +        catch (Exception e)
           {
  -            try
  -            {
  -                Jetspeed.getPersistenceStore().getTransaction().rollback();
  -            }
  -            catch (Exception e1)
  -            {
  -                e1.printStackTrace();
  -            }
  -            throw e;
  +            store.getTransaction().rollback();
           }
  -
  -      
  -            doTestContentType();
  -            doTestParameters();
  -        
  -        
  +        doTestContentType();
  +        doTestParameters();
       }
   
       protected void doTestContentType() throws Throwable
       {
  -        try
  -        {
  -        
  -            MutablePortletApplication app = 
Jetspeed.getPortletRegistry().getPortletApplication(APP_1_NAME);
  -            assertNotNull(app);
  -            PortletDefinitionComposite pdc = (PortletDefinitionComposite) 
app.getPortletDefinitionByName(PORTLET_0_NAME);
  -            assertNotNull(pdc);
  -
  -            ContentType html = pdc.getContentTypeSet().get("html/text");
  -            assertNotNull(html);
  -            if (html == null)
  -                return;
  -            System.out.println("Content Type : " + html.getContentType());
  -            Iterator modes = html.getPortletModes();
  -
  -            boolean modeView = false;
  -            boolean modeHelp = false;
  -            boolean modeEdit = false;
  -
  -            while (modes.hasNext())
  -            {
  -                PortletMode mode = (PortletMode) modes.next();
  -                if (!modeView)
  -                {
  -                    modeView = mode.toString().equals(PortletMode.VIEW.toString());
  -                }
  -
  -                if (!modeHelp)
  -                {
  -                    modeHelp = mode.toString().equals(PortletMode.HELP.toString());
  -                }
  -
  -                if (!modeEdit)
  -                {
  -                    modeEdit = mode.toString().equals(PortletMode.EDIT.toString());
  -                }
  -                System.out.println("   - Available Mode: " + mode);
  +        MutablePortletApplication app = registry.getPortletApplication(APP_1_NAME);
  +        assertNotNull(app);
  +        PortletDefinitionComposite pdc = (PortletDefinitionComposite) app
  +        .getPortletDefinitionByName(PORTLET_0_NAME);
  +        assertNotNull(pdc);
  +        ContentType html = pdc.getContentTypeSet().get("html/text");
  +        assertNotNull(html);
  +        if (html == null)
  +            return;
  +        System.out.println("Content Type : " + html.getContentType());
  +        Iterator modes = html.getPortletModes();
  +        boolean modeView = false;
  +        boolean modeHelp = false;
  +        boolean modeEdit = false;
  +        while (modes.hasNext())
  +        {
  +            PortletMode mode = (PortletMode) modes.next();
  +            if (!modeView)
  +            {
  +                modeView = mode.toString().equals(PortletMode.VIEW.toString());
  +            }
  +            if (!modeHelp)
  +            {
  +                modeHelp = mode.toString().equals(PortletMode.HELP.toString());
               }
  -
  -            assertTrue("All 3 portlet modes for \"html/text\" were not found.", 
(modeEdit && modeView & modeHelp));
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  -        }
  -        catch (Throwable e)
  -        {
  -            try
  -            {
  -                Jetspeed.getPersistenceStore().getTransaction().rollback();
  -            }
  -            catch (Exception e1)
  +            if (!modeEdit)
               {
  -                e1.printStackTrace();
  +                modeEdit = mode.toString().equals(PortletMode.EDIT.toString());
               }
  -            throw e;
  +            System.out.println("   - Available Mode: " + mode);
           }
  +        assertTrue("All 3 portlet modes for \"html/text\" were not found.", 
(modeEdit && modeView & modeHelp));
       }
   
       protected void doTestParameters() throws Throwable
       {
  -        try
  -        {         
  -             Jetspeed.getPersistenceStore().getTransaction().begin();
  -            System.out.println("Number of parameters in the DB " + 
Jetspeed.getPersistenceStore().getExtent(PortletInitParameterImpl.class).size());
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  -            MutablePortletApplication app = 
Jetspeed.getPortletRegistry().getPortletApplication(APP_1_NAME);
  -            assertNotNull(app);
  -            PortletDefinitionComposite pdc = (PortletDefinitionComposite) 
app.getPortletDefinitionByName(PORTLET_0_NAME);
  -            assertNotNull(pdc);
  -
  -            Iterator itr = pdc.getInitParameterSet().iterator();
  -            int count = 0;
  -            for (; itr.hasNext(); count++)
  -                itr.next();
  -
  -            assertTrue(count == 2);
  -            System.out.println("Testing cascading delete of parameters.  Removing 
Portlet Application now...");
  -
  -            Jetspeed.getPortletRegistry().removeApplication(app);
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  -
  -            Jetspeed.getPersistenceStore().getTransaction().begin();
  -            int paramSize = 
Jetspeed.getPersistenceStore().getExtent(PortletInitParameterImpl.class).size();
  -            assertEquals("Not all parameters were deleted.  " + paramSize + " left 
remain.", 0, paramSize);
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  -        }
  -        catch (Throwable e)
  -        {
  -            try
  -            {
  -                Jetspeed.getPersistenceStore().getTransaction().rollback();
  -            }
  -            catch (Exception e1)
  -            {
  -                e1.printStackTrace();
  -            }
  -            throw e;
  -        }
   
  +        // System.out.println("Number of parameters in the DB " +
  +        // registry.getPortletInitParameters(null).size());
  +        MutablePortletApplication app = registry.getPortletApplication(APP_1_NAME);
  +        assertNotNull(app);
  +        PortletDefinitionComposite pdc = (PortletDefinitionComposite) app
  +        .getPortletDefinitionByName(PORTLET_0_NAME);
  +        assertNotNull(pdc);
  +        Iterator itr = pdc.getInitParameterSet().iterator();
  +        int count = 0;
  +        for (; itr.hasNext(); count++)
  +            itr.next();
  +        assertTrue(count == 2);
  +        System.out.println("Testing cascading delete of parameters.  Removing 
Portlet Application now...");
  +        registry.removeApplication(app);
  +        store.getTransaction().commit();
  +
  +        // Make sure all parameters were deleted
  +        store.getTransaction().begin();
  +        int paramSize = store.getExtent(PortletInitParameterImpl.class).size();
  +        assertEquals("Not all parameters were deleted.  " + paramSize + " left 
remain.", 0, paramSize);
  +        store.getTransaction().commit();
       }
   
       public void testPreferences() throws Exception
       {
           try
           {
  -                     
               PortletDefinitionComposite pdc = null;
  -            PortletDefinitionComposite pdc1 =
  -                (PortletDefinitionComposite) 
Jetspeed.getPortletRegistry().getPortletDefinitionByIndetifier(PORTLET_0_UID);
  +            PortletDefinitionComposite pdc1 = 
  +            (PortletDefinitionComposite) 
registry.getPortletDefinitionByIndetifier(PORTLET_0_UID);
   
  -            
  -            pdc =
  -                (PortletDefinitionComposite) 
Jetspeed.getPortletRegistry().getPortletDefinitionByUniqueName(
  -                    APP_1_NAME + "::" + PORTLET_0_NAME);
  -
  -            assertNotNull("Could not locate PortletDefinition with unique name \"" 
+ APP_1_NAME + "::" + PORTLET_0_UID + "\"", pdc);
  +            // registry.clearCache();
   
  -            PreferenceComposite pc =
  -                (PreferenceComposite) 
OMHelper.getOMFactory("pluto.om").newInstance(PreferenceComposite.DEFAULT_PREFERENCE);
  +            pdc = 
  +            (PortletDefinitionComposite) registry.getPortletDefinitionByUniqueName(
  +            APP_1_NAME + "::" + PORTLET_0_NAME);
  +            assertNotNull("Could not locate PortletDefinition with unique name \"" 
+ APP_1_NAME + "::" + PORTLET_0_UID
  +            + "\"", pdc);
  +            PreferenceComposite pc = new DefaultPreferenceImpl();
               pc.setName("preference 1");
               pc.addValue("value 1");
               pc.addValue("value 2");
  -            pc.addDescription(Jetspeed.getDefaultLocale(), "Preference 
Description");
  +            pc.addDescription(JetspeedLocale.getDefaultLocale(), "Preference 
Description");
               pdc.addPreference(pc);
  -
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  -            
  -            invalidateAll(new Object[]{pdc, pc});
  -                     
  -                     Jetspeed.getPersistenceStore().getTransaction().begin();
  -          
  -            pdc = (PortletDefinitionComposite) 
Jetspeed.getPortletRegistry().getPortletDefinitionByIndetifier(PORTLET_0_UID);
  +            store.getTransaction().commit();
  +            pdc = (PortletDefinitionComposite) 
registry.getPortletDefinitionByIndetifier(PORTLET_0_UID);
               assertNotNull("Portlet definition \"com.portlet.MyClass0.Portlet 0\" 
does not exist.", pdc);
  -            assertNotNull("PreferenceSet for \"com.portlet.MyClass0.Portlet 0\" 
should not be null", pdc.getPreferenceSet());
  +            assertNotNull("PreferenceSet for \"com.portlet.MyClass0.Portlet 0\" 
should not be null", pdc
  +            .getPreferenceSet());
               Iterator itr = pdc.getPreferenceSet().iterator();
               int count = 0;
               while (itr.hasNext())
  @@ -541,22 +546,16 @@
                   count++;
                   PreferenceComposite pref = (PreferenceComposite) itr.next();
                   System.out.println("Preference: " + pref.getName());
  -
  -                assertNotNull(pref.getDescription(Jetspeed.getDefaultLocale()));
  -
  -                System.out.println("Preference Description: " + 
pref.getDescription(Jetspeed.getDefaultLocale()));
  -
  +                
assertNotNull(pref.getDescription(JetspeedLocale.getDefaultLocale()));
  +                System.out.println("Preference Description: " + 
pref.getDescription(JetspeedLocale.getDefaultLocale()));
                   Iterator prefValues = pref.getValues();
                   while (prefValues.hasNext())
                   {
                       System.out.println("   -value:" + prefValues.next().toString());
                   }
               }
  -
               PreferenceComposite pref1 = (PreferenceComposite) 
pdc.getPreferenceSet().get("preference 1");
  -
               assertNotNull("could not locate \"preference 1\" ", pref1);
  -
               Iterator valItr = pref1.getValues();
               int valueCount = 0;
               while (valItr.hasNext())
  @@ -564,15 +563,13 @@
                   valueCount++;
                   valItr.next();
               }
  -
               assertTrue("\"preference 1\" should have 2 values not " + valueCount, 
valueCount == 2);
  -
               assertTrue(count == 1);
  -                     Jetspeed.getPersistenceStore().getTransaction().commit();
  +            store.getTransaction().commit();
           }
           catch (Exception e)
           {
  -            Jetspeed.getPersistenceStore().getTransaction().rollback();
  +            store.getTransaction().rollback();
               throw e;
           }
       }
  @@ -580,7 +577,7 @@
       public void testCascadeDelete()
       {
           clean();
  -        List allPortletDefinitions = 
Jetspeed.getPortletRegistry().getAllPortletDefinitions();
  +        List allPortletDefinitions = registry.getAllPortletDefinitions();
           Iterator itr = allPortletDefinitions.iterator();
           while (itr.hasNext())
           {
  @@ -590,106 +587,40 @@
           assertEquals("Cascade delete failed, some PortletDefinitions exist.", 0, 
allPortletDefinitions.size());
       }
   
  -    *//**
  -     * @see junit.framework.TestCase#tearDown()
  -     *//*
  -    public void tearDown() throws Exception
  -    {
  -        clean();
  -        super.tearDown();
  -    }
  -
       protected void clean()
       {
  -        // // Jetspeed.getPortletRegistry().clearCache();
  -
           try
  -        {            
  -            Iterator itr = 
Jetspeed.getPortletRegistry().getPortletApplications().iterator();
  -
  -            while (itr.hasNext())
  -            {
  -                MutablePortletApplication pac = (MutablePortletApplication) 
itr.next();
  -
  -                Jetspeed.getPortletRegistry().removeApplication(pac);
  -
  -            }
  -            Jetspeed.getPersistenceStore().getTransaction().commit();
  -
  +        {
  +            store.getTransaction().begin();
  +            Filter filter1 = store.newFilter();
  +            Filter filter2 = store.newFilter();
  +            store.deleteAll(store.newQuery(PortletDefinitionImpl.class, filter1));
  +            store.deleteAll(store.newQuery(PortletApplicationDefinitionImpl.class, 
filter2));
  +            store.getTransaction().commit();
           }
           catch (Exception e)
           {
  -            try
  -            {
  -                Jetspeed.getPersistenceStore().getTransaction().rollback();
  -            }
  -            catch (Exception e1)
  -            {
  -                e1.printStackTrace();
  -            }
  -            System.out.println("Unable to tear down test.");
  +            store.getTransaction().rollback();
  +            System.out.println("Unable to clean test.");
               e.printStackTrace();
           }
  -
  -        Iterator pitr = 
Jetspeed.getPortletRegistry().getAllPortletDefinitions().iterator();
  -        while (pitr.hasNext())
  -        {
  -            PortletDefinition pd = (PortletDefinition) pitr.next();
  -            System.err.println("Test pass [" + testPasses + "]: Left over 
PortletDefinition: " + pd.getId() + ":" + pd.getName());
  -        }
  -
       }
   
  -    *//**
  -     * @see junit.framework.TestCase#setUp()
  -     *//*
  -    public void setUp() throws Exception
  +    protected void clearExtent(Class clazz) throws LockFailedException
       {
  -        super.setUp();
  -             omFactory = OMHelper.getOMFactory("pluto.om");       
  -        clean();
  -        buildTestPortletApp();
  -        testPasses++;
  +        store.getTransaction().begin();
  +        Filter filter = store.newFilter();
  +        store.deleteAll(store.newQuery(clazz, filter));
  +        store.getTransaction().commit();
       }
  -
  -    protected void clearExtent(Class clazz)
  +    
  +    protected void invalidate(Object[] objs) throws LockFailedException
       {
  -     
  -             PersistenceStore store = Jetspeed.getPersistenceStore();
  -             
  -        Filter c = store.newFilter();
  -
  -        Collection aColl = store.getCollectionByQuery(store.newQuery(clazz, c));
  -
  -        Iterator anItr = aColl.iterator();
  -
  -        try
  +        store.getTransaction().begin();
  +        for(int i=0; i<objs.length; i++)
           {
  -                     store.getTransaction().begin();
  -            while (anItr.hasNext())
  -            {
  -                             store.deletePersistent(anItr.next());
  -            }
  -                     store.getTransaction().commit();
  +            store.invalidate(objs[i]);
           }
  -        catch (Exception e)
  -        {
  -            System.err.println("Unable to tear down test case!");
  -            e.printStackTrace();
  -        }
  -
  +        store.getTransaction().commit();
       }
  -    
  -    private void invalidateAll(Object [] objs) throws LockFailedException
  -    {
  -             Jetspeed.getPersistenceStore().getTransaction().begin();               
                 
  -     for(int i=0; i<objs.length; i++)
  -     {
  -             Object obj = 
Jetspeed.getPersistenceStore().getObjectByIdentity(objs[i]);
  -             
  -     }
  -             Jetspeed.getPersistenceStore().getTransaction().commit();
  -    }*/
  -    
  -
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to