portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlest...@apache.org
Subject cvs commit: jakarta-jetspeed-2/components/prefs/src/test Log4j.properties
Date Sat, 06 Mar 2004 18:35:13 GMT
dlestrat    2004/03/06 10:35:13

  Modified:    components/prefs/src/test/org/apache/jetspeed/prefs
                        TestPropertyManager.java TestPreferences.java
               components/prefs/src/test Log4j.properties
  Log:
  Prefs tests.
  
  Revision  Changes    Path
  1.4       +91 -255   jakarta-jetspeed-2/components/prefs/src/test/org/apache/jetspeed/prefs/TestPropertyManager.java
  
  Index: TestPropertyManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/prefs/src/test/org/apache/jetspeed/prefs/TestPropertyManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestPropertyManager.java	1 Mar 2004 02:04:05 -0000	1.3
  +++ TestPropertyManager.java	6 Mar 2004 18:35:13 -0000	1.4
  @@ -42,7 +42,7 @@
   /**
    * <p>Unit testing for {@link PropertyManager}.</p>
    *
  - * @author <a href="dlestrat@yahoo.com">David Le Strat</a>
  + * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
    */
   public class TestPropertyManager extends AbstractComponentAwareTestCase
   {
  @@ -77,15 +77,10 @@
       public void setUp() throws Exception
       {
           super.setUp();
  +        System.out.println("_________ SET UP ___________");
  +        System.setProperty("java.util.prefs.PreferencesFactory", "org.apache.jetspeed.prefs.impl.PreferencesFactoryImpl");
           container = (MutablePicoContainer) getContainer();
           pms = (PropertyManager) container.getComponentInstance(PropertyManager.class);
  -        try
  -        {
  -            destroyPropertySetDefTestObject(true);
  -        }
  -        catch (PropertyException exc)
  -        {
  -        }
       }
   
       /**
  @@ -94,13 +89,8 @@
       public void tearDown() throws Exception
       {
           super.tearDown();
  -        try
  -        {
  -            destroyPropertySetDefTestObject(true);
  -        }
  -        catch (PropertyException exc)
  -        {
  -        }
  +        System.out.println("_________ CLEAN ___________");
  +        clean();
       }
   
       /**
  @@ -124,285 +114,131 @@
       }
   
       /**
  -     * <p>Test add property set definition.</p>
  +     * <p>Test add property keys to a {@link Preferences} node.</p>
        */
  -    public void testAddPropertySetDef() throws PropertyException
  +    public void testAddPropertyKeys() throws PropertyException
       {
  +        System.out.println("___1");
  +        Map propertyKeys = initPropertyKeysMap();
  +        System.out.println("___2");
  +        Preferences pref = Preferences.userRoot().node("/user/principal1/propertyset1");

  +        System.out.println("___3"); 
           try
           {
  -            pms.addPropertySetDef("propertyset0", USER_PROPERTY_SET_TYPE);
  +            pms.addPropertyKeys(pref, propertyKeys);
           }
           catch (PropertyException pex)
           {
  -            // Property set defintion already exists.
  -            assertTrue("property set definition already exists. exception caught: " + pex,
false);
  +            assertTrue("could not add property keys to node: " + pex, false);
           }
  +    }
   
  -        destroyPropertySetDefTestObject(false);
  +    /**
  +     * <p>Test get property key.</p>
  +     */
  +    public void testGetPropertyKeys()
  +    {
  +        initPropertyKeys();
  +        Preferences pref = Preferences.userRoot().node("/user/principal1/propertyset1");
  +        Map propertyKeys = pms.getPropertyKeys(pref);
  +        assertEquals("should have 4 keys, " + propertyKeys.size(), 4, propertyKeys.size());
       }
   
       /**
  -     * <p>Test update the property set definition.</p>
  +     * <p>Test update property key.</p>
        */
  -    public void testUpdatePropertySetDef() throws PropertyException
  +    public void testUpdatePropertyKey() throws PropertyException
       {
  +        initPropertyKeys();
  +        Preferences pref = Preferences.userRoot().node("/user/principal1/propertyset1");
           try
           {
  -            initPropertySetDefTestObject(false);
  +            // New key
  +            HashMap newKey = new HashMap(1);
  +            newKey.put("newPropertyName0", new Short("0"));
  +            pms.updatePropertyKey("propertyName0", pref, newKey);
  +            Map propKeys = pms.getPropertyKeys(pref);
  +            assertTrue("should contain newPropertyName0", propKeys.containsKey("newPropertyName0"));
  +            HashMap oldKey = new HashMap(1);
  +            oldKey.put("propertyName0", new Short("0"));
  +            pms.updatePropertyKey("NewPropertyName0", pref, oldKey);
           }
           catch (PropertyException pex)
           {
  -            assertTrue("could not initialize property set definition. exception caught:
" + pex, false);
  +            assertTrue("could not update property key. exception caught: " + pex, false);
           }
  +    }
   
  +    /**
  +     * <p>Test remove property keys.</p>
  +     */
  +    public void testRemovePropertyKeys() throws PropertyException
  +    {
  +        initPropertyKeys();
  +        Preferences pref = Preferences.userRoot().node("/user/principal1/propertyset1");
           try
           {
  -            pms.updatePropertySetDef("propertysetupdate0", "propertyset0", USER_PROPERTY_SET_TYPE);
  -            Collection propertySetsByType = pms.getAllPropertySetsByType(USER_PROPERTY_SET_TYPE);
  -            //updatedPropertySetDefId = pms.getPropertySetDefIdByType("propertysetupdate0",
USER_PROPERTY_SET_TYPE);
  -            assertTrue(
  -                "should contain property set definition named propertysetupdate0.",
  -                propertySetsByType.contains("propertysetupdate0"));
  -            pms.updatePropertySetDef("propertyset0", "propertysetupdate0", USER_PROPERTY_SET_TYPE);
  +            Map propertyKeys = pms.getPropertyKeys(pref);
  +            pms.removePropertyKeys(pref, propertyKeys.keySet());
  +            propertyKeys = pms.getPropertyKeys(pref);
  +            assertEquals("should have 0 keys, " + propertyKeys.size(), 0, propertyKeys.size());
           }
           catch (PropertyException pex)
           {
  -            assertTrue("could not get property set definition id. exception caught: " +
pex, false);
  +            assertTrue("could not delete property keys. exception caught: " + pex, false);
           }
  -
  -        destroyPropertySetDefTestObject(false);
       }
  -    
  -        /**
  -         * <p>Test get all property sets by types.</p>
  -         */
  -        public void testGetAllPropertySetByType() throws PropertyException
  -        {
  -            try
  -            {
  -                initPropertySetDefTestObject(true);
  -            }
  -            catch (PropertyException pex)
  -            {
  -                assertTrue("could not initialize property set definition. exception caught:
" + pex, false);
  -            }
  -    
  -            try
  -            {
  -                Collection propertySetsByType = pms.getAllPropertySetsByType(USER_PROPERTY_SET_TYPE);
  -                assertTrue("property set should contain: propertyset0, ", propertySetsByType.contains("propertyset0"));
  -                assertTrue("property set should contain: propertyset1, ", propertySetsByType.contains("propertyset1"));
  -                assertTrue("property set should contain: propertyset2, ", propertySetsByType.contains("propertyset2"));
  -            }
  -            catch (PropertyException pex)
  -            {
  -                assertTrue("could not get property set map: " + pex, false);
  -            }
  -    
  -            destroyPropertySetDefTestObject(true);
  -        }
  -    
  -        /**
  -         * <p>Test remove property set definition.</p>
  -         */
  -        public void testRemovePropertySetDef()
  -        {
  -            try
  -            {
  -                initPropertySetDefTestObject(false);
  -            }
  -            catch (PropertyException pex)
  -            {
  -                assertTrue("could not initialize property set definition. exception caught:
" + pex, false);
  -            }
  -    
  -            try
  -            {
  -                pms.removePropertySetDef("propertyset0", USER_PROPERTY_SET_TYPE);
  -            }
  -            catch (PropertyException pex)
  -            {
  -                assertTrue("could not remove property set definition. exception caught:
" + pex, false);
  -            }
  -    
  -            try
  -            {
  -                Collection propertySetsByType = pms.getAllPropertySetsByType(USER_PROPERTY_SET_TYPE);
  -                assertFalse("property set not should contain: propertyset0, ", propertySetsByType.contains("propertyset0"));
  -            }
  -            catch (PropertyException pex)
  -            {
  -                assertTrue("could not find property set type. exception caught: " + pex,
false);
  -            }
  -        }
  -    
  -        /**
  -         * <p>Test add property keys to a set.</p>
  -         */
  -        public void testAddUpdatePropertyKeys() throws PropertyException
  -        {
  -            try
  -            {
  -                initPropertySetDefTestObject(true);
  -            }
  -            catch (PropertyException pex)
  -            {
  -                assertTrue("could not initialize property set definition. exception caught:
" + pex, false);
  -            }
  -    
  -            try
  -            {
  -                pms.updatePropertyKey("propertyNameUpdate0", "propertyName0", "propertyset0",
USER_PROPERTY_SET_TYPE);
  -                Collection updatedPropertyKeys = pms.getPropertyKeysBySetDef("propertyset0",
USER_PROPERTY_SET_TYPE);
  -                assertTrue(
  -                    "updated property set map should contain: propertyNameUpdate0.",
  -                    updatedPropertyKeys.contains("propertyNameUpdate0"));
  -            }
  -            catch (PropertyException pex)
  -            {
  -                assertTrue("could not get updated property set map: " + pex, false);
  -            }
  -    
  -            destroyPropertySetDefTestObject(true);
  -        }
  -    
  -//        /**
  -//         * <p>Test remove property keys.</p>
  -//         */
  -//        public void testRemovePropertyKeys()
  -//        {
  -//            String userNodeName = "user";
  -//            String principalNodeName = "principal";
  -//            String propertySetNodeName = "propertyset1";
  -//            String fullPropertySetPath = "/" + userNodeName + "/" + principalNodeName
+ "/" + propertySetNodeName;
  -//            int[] propertySetDefs = new int[1];
  -//    
  -//            try
  -//            {
  -//                // Create a node.
  -//                Preferences prefs1 = Preferences.userRoot().node(fullPropertySetPath);
  -//                // Create the set definition.
  -//                pms.addPropertySetDef("propertyset0", USER_PROPERTY_SET_TYPE);
  -//    
  -//                // Build a few property keys.
  -//                Collection propertyKeys = new ArrayList(1);
  -//    
  -//                Map propertyKey0 = new HashMap();
  -//                propertyKey0.put(PropertyManager.PROPERTYKEY_NAME, "propertyName0");
  -//                propertyKey0.put(PropertyManager.PROPERTYKEY_TYPE, new Short("0"));
  -//    
  -//                propertyKeys.add(propertyKey0);
  -//                pms.addPropertyKeys("propertyset0", USER_PROPERTY_SET_TYPE, propertyKeys);
  -//    
  -//                prefs1.put("propertyName0", "true");
  -//            }
  -//            catch (PropertyException pex)
  -//            {
  -//                assertTrue("could not add property keys: " + pex, false);
  -//            }
  -//    
  -//            // Now let's remove the keys.
  -//            try
  -//            {
  -//                for (Iterator i = (pms.getPropertyKeysBySetDef(propertySetDefs[0]).keySet()).iterator();
i.hasNext();)
  -//                {
  -//                    pms.removePropertyKey(((Integer) i.next()).intValue());
  -//                }
  -//            }
  -//            catch (PropertyException pex)
  -//            {
  -//                assertTrue("could not remove property keys: " + pex, false);
  -//            }
  -//    
  -//            // Let's verify it was removed.
  -//            try
  -//            {
  -//                Map propKeysCol = pms.getPropertyKeysBySetDef(propertySetDefs[0]);
  -//                assertEquals("expected property key map size == 0, ", 0, propKeysCol.size());
  -//            }
  -//            catch (PropertyException pex)
  -//            {
  -//                assertTrue("could not get property keys: " + pex, false);
  -//            }
  -//    
  -//            // Clean up everything else.
  -//            try
  -//            {
  -//                Preferences prefs2 = Preferences.userRoot().node("/" + userNodeName);
  -//                prefs2.removeNode();
  -//            }
  -//            catch (BackingStoreException bse)
  -//            {
  -//                assertTrue("backing store exception: " + bse, false);
  -//            }
  -//            try
  -//            {
  -//                pms.removePropertySetDef(propertySetDefs[0]);
  -//            }
  -//            catch (PropertyException pex)
  -//            {
  -//                assertTrue("could not remove property set definition: " + pex, false);
  -//            }
  -//    
  -//        }
  -
  -    /**
  -     * <p>Init property set definition object.</p>
  -     */
  -    protected void initPropertySetDefTestObject(boolean isAll) throws PropertyException
  -    {
  -        // Create the set definition.
  -        pms.addPropertySetDef("propertyset0", USER_PROPERTY_SET_TYPE);
  -
  -        if (isAll)
  -        {
  -            pms.addPropertySetDef("propertyset1", USER_PROPERTY_SET_TYPE);
  -            pms.addPropertySetDef("propertyset2", USER_PROPERTY_SET_TYPE);
  -            pms.addPropertySetDef("propertyset3", SYSTEM_PROPERTY_SET_TYPE);
  -        }
   
  +    /**
  +     * <p>Init property property keys map.</p>
  +     */
  +    protected Map initPropertyKeysMap()
  +    {
           // Build a few property keys.
  -        Collection propertyKeys = new ArrayList();
  -
  -        Map propertyKey0 = new HashMap();
  -        propertyKey0.put(PropertyManager.PROPERTYKEY_NAME, "propertyName0");
  -        propertyKey0.put(PropertyManager.PROPERTYKEY_TYPE, new Short("0"));
  -
  -        propertyKeys.add(propertyKey0);
  -
  -        Map propertyKey1 = new HashMap();
  -        propertyKey1.put(PropertyManager.PROPERTYKEY_NAME, "propertyName1");
  -        propertyKey1.put(PropertyManager.PROPERTYKEY_TYPE, new Short("1"));
  -
  -        propertyKeys.add(propertyKey1);
  -
  -        Map propertyKey2 = new HashMap();
  -        propertyKey2.put(PropertyManager.PROPERTYKEY_NAME, "propertyName2");
  -        propertyKey2.put(PropertyManager.PROPERTYKEY_TYPE, new Short("2"));
  +        Map propertyKeys = new HashMap();
  +        propertyKeys.put("propertyName0", new Short("0"));
  +        propertyKeys.put("propertyName1", new Short("1"));
  +        propertyKeys.put("propertyName2", new Short("2"));
  +        propertyKeys.put("propertyName3", new Short("3"));
   
  -        propertyKeys.add(propertyKey2);
  -
  -        Map propertyKey3 = new HashMap();
  -        propertyKey3.put(PropertyManager.PROPERTYKEY_NAME, "propertyName3");
  -        propertyKey3.put(PropertyManager.PROPERTYKEY_TYPE, new Short("3"));
  +        return propertyKeys;
  +    }
   
  -        propertyKeys.add(propertyKey3);
  +    /**
  +     * <p>Init property property keys.</p>
  +     */
  +    protected void initPropertyKeys()
  +    {
  +        Map propertyKeys = initPropertyKeysMap();
  +        Preferences pref = Preferences.userRoot().node("/user/principal1/propertyset1");
   
  -        pms.addPropertyKeys("propertyset0", USER_PROPERTY_SET_TYPE, propertyKeys);
  +        try
  +        {
  +            pms.addPropertyKeys(pref, propertyKeys);
  +        }
  +        catch (PropertyException pex)
  +        {
  +        }
       }
   
       /**
  -     * <p>Destroy profile test object.</p>
  +     * <p>Clean properties.</p>
        */
  -    protected void destroyPropertySetDefTestObject(boolean isAll) throws PropertyException
  +    protected void clean()
       {
  -        pms.removePropertySetDef("propertyset0", USER_PROPERTY_SET_TYPE);
  -
  -        if (isAll)
  +        Preferences pref = Preferences.userRoot().node("/user/principal1/propertyset1");
  +        try
  +        {
  +            Map propertyKeys = pms.getPropertyKeys(pref);
  +            pms.removePropertyKeys(pref, propertyKeys.keySet());
  +            Preferences.userRoot().node("/user").removeNode();
  +        }
  +        catch (PropertyException pex)
  +        {
  +        }
  +        catch (BackingStoreException bse)
           {
  -            pms.removePropertySetDef("propertyset1", USER_PROPERTY_SET_TYPE);
  -            pms.removePropertySetDef("propertyset2", USER_PROPERTY_SET_TYPE);
  -            pms.removePropertySetDef("propertyset3", SYSTEM_PROPERTY_SET_TYPE);
  +            System.out.println("BackingStoreException" + bse);
           }
       }
   
  
  
  
  1.4       +155 -220  jakarta-jetspeed-2/components/prefs/src/test/org/apache/jetspeed/prefs/TestPreferences.java
  
  Index: TestPreferences.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/prefs/src/test/org/apache/jetspeed/prefs/TestPreferences.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestPreferences.java	1 Mar 2004 02:04:05 -0000	1.3
  +++ TestPreferences.java	6 Mar 2004 18:35:13 -0000	1.4
  @@ -25,6 +25,7 @@
   
   import junit.framework.Test;
   
  +//import org.apache.jetspeed.test.JetspeedTestSuite;
   import org.apache.jetspeed.components.AbstractComponentAwareTestCase;
   import org.apache.jetspeed.components.ComponentAwareTestSuite;
   import org.apache.jetspeed.components.datasource.DatasourceComponent;
  @@ -75,10 +76,10 @@
       public void setUp() throws Exception
       {
           super.setUp();
  +        System.setProperty("java.util.prefs.PreferencesFactory", "org.apache.jetspeed.prefs.impl.PreferencesFactoryImpl");
  +        System.out.println("java.util.prefs.PreferencesFactory:" + System.getProperty("java.util.prefs.PreferencesFactory"));
           container = (MutablePicoContainer) getContainer();
           pms = (PropertyManager) container.getComponentInstance(PropertyManager.class);
  -        //destroyRootNodes();
  -        //destroyPropertySetDefTestObject();
       }
   
       /**
  @@ -87,7 +88,7 @@
       public void tearDown() throws Exception
       {
           super.tearDown();
  -        //destroyPropertySetDefTestObject();
  +        clean();
       }
   
       /**
  @@ -142,222 +143,156 @@
           }
       }
   
  -//    /**
  -//     * <p>Test children names.</p>
  -//     */
  -//    public void testChildrenNames()
  -//    {
  -//        Preferences prefs = Preferences.userRoot();
  -//        // Test without children.
  -//        try
  -//        {
  -//            String[] childrenNames = prefs.childrenNames();
  -//            if (childrenNames.length > 0)
  -//            {
  -//                assertTrue("expected no children, " + childrenNames.length + ", " + childrenNames[0],
childrenNames.length == 0);
  -//            }
  -//        }
  -//        catch (BackingStoreException bse)
  -//        {
  -//            assertTrue("backing store exception: " + bse, false);
  -//        }
  -//
  -//        // TODO Test with children.
  -//    }
  -//
  -//    /**
  -//     * <p>Test node.</p>
  -//     */
  -//    public void testNode()
  -//    {
  -//        String testRelNodeName = "rn1/srn1";
  -//        String testAbsNodeName0 = "/an1";
  -//        String testAbsNodeName1 = "/san1";
  -//        String testAbsNodeName = testAbsNodeName0 + testAbsNodeName1;
  -//
  -//        // Absolute path.
  -//        // 1. The node does not exist. Create it.
  -//        Preferences prefs0 = Preferences.userRoot().node(testAbsNodeName);
  -//        if (null != prefs0)
  -//        {
  -//            assertTrue(
  -//                "expected node == '" + testAbsNodeName + "', " + prefs0.absolutePath(),
  -//                prefs0.absolutePath().equals(testAbsNodeName));
  -//        }
  -//        else
  -//        {
  -//            assertTrue("expected node == '" + testAbsNodeName + "', " + prefs0, false);
  -//        }
  -//
  -//        // 2. If node exists. Get it.
  -//        Preferences prefs1 = Preferences.userRoot().node(testAbsNodeName);
  -//        if (null != prefs1)
  -//        {
  -//            assertTrue(
  -//                "expected node == '" + testAbsNodeName + "', " + prefs1.absolutePath(),
  -//                prefs1.absolutePath().equals(testAbsNodeName));
  -//        }
  -//        else
  -//        {
  -//            assertTrue("expected node == '" + testAbsNodeName + "', " + prefs1, false);
  -//        }
  -//
  -//        //Relative path.
  -//        Preferences prefs3 = Preferences.userRoot().node(testAbsNodeName0);
  -//        Preferences prefs4 = prefs3.node(testRelNodeName);
  -//        if (null != prefs4)
  -//        {
  -//            assertTrue(
  -//                "expected node == '" + testAbsNodeName0 + "/" + testRelNodeName + "',
" + prefs4.absolutePath(),
  -//                prefs4.absolutePath().equals(testAbsNodeName0 + "/" + testRelNodeName));
  -//        }
  -//        else
  -//        {
  -//            assertTrue("expected node == '" + testAbsNodeName0 + "/" + testRelNodeName
+ "', " + prefs4, false);
  -//        }
  -//
  -//        // Remove all nodes.
  -//        try
  -//        {
  -//            prefs3.removeNode();
  -//        }
  -//        catch (BackingStoreException bse)
  -//        {
  -//            assertTrue("backing store exception: " + bse, false);
  -//        }
  -//    }
  -//
  -//    /**
  -//     * <p>Test adding properties to a property set node.</p>
  -//     */
  -//    public void testProperty()
  -//    {
  -//        String userNodeName = "user";
  -//        String principalNodeName = "principal";
  -//        String propertySetNodeName = "propertyset1";
  -//        String fullPropertySetPath = "/" + userNodeName + "/" + principalNodeName + "/"
+ propertySetNodeName;
  -//        int[] propertySetDefIds = new int[2];
  -//
  -//        try
  -//        {
  -//            initPropertySetDefTestObject();
  -//        }
  -//        catch (PropertyException pe)
  -//        {
  -//            assertTrue(false);
  -//        }
  -//
  -//        // 1. Current node is not defined as property set.
  -//        Preferences prefs0 = Preferences.userRoot();
  -//        prefs0.put("propertyName00", "true");
  -//        String prop0 = prefs0.get("propertyName00", null);
  -//        if (null != prop0)
  -//        {
  -//            assertTrue(false);
  -//        }
  -//
  -//        // 2. Current node is defined as property set.
  -//        Preferences prefs1 = Preferences.userRoot().node(fullPropertySetPath);
  -//        prefs1.put("propertyName00", "true");
  -//        String prop1 = prefs1.get("propertyName00", null);
  -//        assertTrue("expected prop1 == true, " + prop1, prop1.equals("true"));
  -//
  -//        // Test remove property.
  -//        prefs1.remove("propertyName00");
  -//        prop1 = prefs1.get("propertyName00", null);
  -//        if (null != prop1)
  -//        {
  -//            assertTrue(false);
  -//        }
  -//
  -//        // Remove all nodes with properties assigned to property sets.
  -//        prefs1.put("propertyName00", "true");
  -//        prop1 = prefs1.get("propertyName00", null);
  -//        if (!prop1.equals("true"))
  -//        {
  -//            assertTrue(false);
  -//        }
  -//
  -//        try
  -//        {
  -//            Preferences prefs2 = Preferences.userRoot().node("/" + userNodeName);
  -//            prefs2.removeNode();
  -//        }
  -//        catch (BackingStoreException bse)
  -//        {
  -//            assertTrue("backing store exception: " + bse, false);
  -//        }
  -//    }
  -//
  -//    /**
  -//     * <p>Init property set definition object.</p>
  -//     */
  -//    protected void initPropertySetDefTestObject() throws PropertyException
  -//    {
  -//        // Create the set definition.
  -//        pms.addPropertySetDef("propertyset1", USER_PROPERTY_SET_TYPE);
  -//        // Build a few property keys.
  -//        Collection propertyKeys = new ArrayList();
  -//        Map propertyKey00 = new HashMap();
  -//        propertyKey00.put(PropertyManager.PROPERTYKEY_NAME, "propertyName00");
  -//        propertyKey00.put(PropertyManager.PROPERTYKEY_TYPE, new Short("0"));
  -//        propertyKeys.add(propertyKey00);
  -//        Map propertyKey01 = new HashMap();
  -//        propertyKey01.put(PropertyManager.PROPERTYKEY_NAME, "propertyName01");
  -//        propertyKey01.put(PropertyManager.PROPERTYKEY_TYPE, new Short("1"));
  -//        propertyKeys.add(propertyKey01);
  -//        Map propertyKey02 = new HashMap();
  -//        propertyKey02.put(PropertyManager.PROPERTYKEY_NAME, "propertyName02");
  -//        propertyKey02.put(PropertyManager.PROPERTYKEY_TYPE, new Short("2"));
  -//        propertyKeys.add(propertyKey02);
  -//        Map propertyKey03 = new HashMap();
  -//        propertyKey03.put(PropertyManager.PROPERTYKEY_NAME, "propertyName03");
  -//        propertyKey03.put(PropertyManager.PROPERTYKEY_TYPE, new Short("3"));
  -//        propertyKeys.add(propertyKey03);
  -//        pms.addPropertyKeys("propertyset1", USER_PROPERTY_SET_TYPE, propertyKeys);
  -//        // Add another set.
  -//        // Create the set definition.
  -//        pms.addPropertySetDef("propertyset2", USER_PROPERTY_SET_TYPE);
  -//        // Build a few property keys.
  -//        Collection propertyKeys1 = new ArrayList();
  -//        Map propertyKey10 = new HashMap();
  -//        propertyKey10.put(PropertyManager.PROPERTYKEY_NAME, "propertyName10");
  -//        propertyKey10.put(PropertyManager.PROPERTYKEY_TYPE, new Short("0"));
  -//        propertyKeys1.add(propertyKey10);
  -//        Map propertyKey11 = new HashMap();
  -//        propertyKey11.put(PropertyManager.PROPERTYKEY_NAME, "propertyName11");
  -//        propertyKey11.put(PropertyManager.PROPERTYKEY_TYPE, new Short("1"));
  -//        propertyKeys1.add(propertyKey11);
  -//        pms.addPropertyKeys("propertyset2", USER_PROPERTY_SET_TYPE, propertyKeys1);
  -//    }
  -//
  -//    /**
  -//     * <p>Destroy profile test object.</p>
  -//     */
  -//    protected void destroyPropertySetDefTestObject()
  -//    {
  -//        try
  -//        {
  -//            pms.removePropertySetDef("propertyset1", USER_PROPERTY_SET_TYPE);
  -//            pms.removePropertySetDef("propertyset2", USER_PROPERTY_SET_TYPE);
  -//        }
  -//        catch (PropertyException pex)
  -//        {
  -//        }
  -//    }
  -//
  -//    /**
  -//     * <p>Destroy possible existing root nodes.</p>
  -//     */
  -//    protected void destroyRootNodes() throws Exception
  -//    {
  -//        // Remove user, group and role root nodes.
  -//        Preferences groupRootPrefs = Preferences.userRoot().node("/group");
  -//        groupRootPrefs.removeNode();
  -//        Preferences roleRootPrefs = Preferences.userRoot().node("/role");
  -//        roleRootPrefs.removeNode();
  -//        Preferences userRootPrefs = Preferences.userRoot().node("/user");
  -//        userRootPrefs.removeNode();
  -//    }
  +    /**
  +     * <p>Test children names.</p>
  +     */
  +    public void testChildrenNames()
  +    {
  +        Preferences prefs = Preferences.userRoot();
  +        // Test without children.
  +        try
  +        {
  +            String[] childrenNames = prefs.childrenNames();
  +            if (childrenNames.length > 0)
  +            {
  +                assertTrue("expected no children, " + childrenNames.length + ", " + childrenNames[0],
childrenNames.length == 0);
  +            }
  +        }
  +        catch (BackingStoreException bse)
  +        {
  +            assertTrue("backing store exception: " + bse, false);
  +        }
  +
  +        // TODO Test with children.
  +    }
  +
  +    /**
  +     * <p>Test node.</p>
  +     */
  +    public void testNode()
  +    {
  +        // Absolute path.
  +        // 1. The node does not exist. Create it.
  +        Preferences prefs0 = Preferences.userRoot().node("/an1/san1");
  +        assertNotNull("should not be null", prefs0);
  +        assertTrue("expected node == /an1/san1, " + prefs0.absolutePath(), prefs0.absolutePath().equals("/an1/san1"));
  +
  +        // 2. If node exists. Get it.
  +        Preferences prefs1 = Preferences.userRoot().node("/an1/san1");
  +        assertNotNull("should not be null", prefs1);
  +        assertTrue("expected node == /an1/san1, " + prefs1.absolutePath(), prefs1.absolutePath().equals("/an1/san1"));
  +
  +        //Relative path.
  +        Preferences prefs3 = Preferences.userRoot().node("/an1");
  +        Preferences prefs4 = prefs3.node("rn1/srn1");
  +        assertNotNull("should not be null", prefs4);
  +        assertTrue("expected node == /an1/rn1/srn1, " + prefs4.absolutePath(), prefs4.absolutePath().equals("/an1/rn1/srn1"));
  +
  +        // Remove all nodes.
  +        try
  +        {
  +            prefs3.removeNode();
  +        }
  +        catch (BackingStoreException bse)
  +        {
  +            assertTrue("backing store exception: " + bse, false);
  +        }
  +    }
  +
  +    /**
  +     * <p>Test adding properties to a property set node.</p>
  +     */
  +    public void testProperty()
  +    {
  +
  +        // 1. Current node does not have any property associated to it.
  +        Preferences pref0 = Preferences.userRoot();
  +        pref0.put("propertyName0", "true");
  +        String prop = pref0.get("propertyName0", null);
  +        assertNull("should be null.", prop);
  +
  +        // 2. Current node has properties associated to it.
  +        initPropertyKeys();
  +        Preferences pref1 = Preferences.userRoot().node("/user/principal1/propertyset1");
  +        pref1.put("propertyName0", "true");
  +        String prop1 = pref1.get("propertyName0", null);
  +        assertTrue("expected prop1 == true, " + prop1, prop1.equals("true"));
  +
  +        // Test remove property.
  +        pref1.remove("propertyName0");
  +        prop1 = pref1.get("propertyName0", null);
  +        assertNull("should be null.", prop);
  +
  +        // Remove all nodes with properties assigned to property sets.
  +        pref1.put("propertyName0", "true");
  +        prop1 = pref1.get("propertyName0", null);
  +        assertTrue("expected prop1 == true, " + prop1, prop1.equals("true"));
  +
  +        try
  +        {
  +            Preferences pref2 = Preferences.userRoot().node("/user");
  +            pref2.removeNode();
  +        }
  +        catch (BackingStoreException bse)
  +        {
  +            assertTrue("backing store exception: " + bse, false);
  +        }
  +    }
  +
  +    /**
  +     * <p>Init property property keys map.</p>
  +     */
  +    protected Map initPropertyKeysMap()
  +    {
  +        // Build a few property keys.
  +        Map propertyKeys = new HashMap();
  +        propertyKeys.put("propertyName0", new Short("0"));
  +        propertyKeys.put("propertyName1", new Short("1"));
  +        propertyKeys.put("propertyName2", new Short("2"));
  +        propertyKeys.put("propertyName3", new Short("3"));
  +
  +        return propertyKeys;
  +    }
  +
  +    /**
  +     * <p>Init property property keys.</p>
  +     */
  +    protected void initPropertyKeys()
  +    {
  +        Map propertyKeys = initPropertyKeysMap();
  +        Preferences pref = Preferences.userRoot().node("/user/principal1/propertyset1");
  +
  +        try
  +        {
  +            pms.addPropertyKeys(pref, propertyKeys);
  +        }
  +        catch (PropertyException pex)
  +        {
  +        }
  +    }
  +
  +    /**
  +     * <p>Clean properties.</p>
  +     */
  +    protected void clean()
  +    {
  +        Preferences pref = Preferences.userRoot().node("/user/principal1/propertyset1");
  +        try
  +        {
  +            Map propertyKeys = pms.getPropertyKeys(pref);
  +            pms.removePropertyKeys(pref, propertyKeys.keySet());
  +            Preferences.userRoot().node("/user").removeNode();
  +            Preferences.userRoot().node("/an1").removeNode();
  +            Preferences.userRoot().node("/rn1").removeNode();
  +        }
  +        catch (PropertyException pex)
  +        {
  +            System.out.println("PropertyException" + pex);
  +        }
  +        catch (BackingStoreException bse)
  +        {
  +            System.out.println("BackingStoreException" + bse);
  +        }
  +    }
   
   }
  
  
  
  1.2       +9 -7      jakarta-jetspeed-2/components/prefs/src/test/Log4j.properties
  
  Index: Log4j.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/prefs/src/test/Log4j.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Log4j.properties	26 Feb 2004 04:30:46 -0000	1.1
  +++ Log4j.properties	6 Mar 2004 18:35:13 -0000	1.2
  @@ -27,13 +27,15 @@
   #
   # OJB Logfile
   #
  -log4j.category.org.apache.ojb.broker.accesslayer = DEBUG, console
  -log4j.category.org.apache.ojb.broker.core = DEBUG, console
  +log4j.org.apache.ojb.broker.accesslayer = INFO, console
  +log4j.org.apache.ojb.broker.accesslayer.sql = INFO, console
  +log4j.category.org.apache.ojb.broker = INFO, console
  +log4j.category.org.apache.ojb.broker.metadata = INFO, console
  +log4j.category.org.apache.ojb.otm = INFO, console
  +log4j.category.org.apache.ojb.core = INFO, console
  +log4j.category.org.apache.ojb.cache = INFO, console
   log4j.additivity.org.apache.ojb= false
   
  -
  -
  -
   #
   # Console
   #
  @@ -41,4 +43,4 @@
   log4j.appender.console.layout=org.apache.log4j.PatternLayout
   
   # Pattern to output the caller's file name and line number.
  -log4j.appender.console.layout.ConversionPattern=%5p: %m%n
  +log4j.appender.console.layout.ConversionPattern=%5p: %c - %m%n
  
  
  

---------------------------------------------------------------------
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