You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2007/07/03 11:49:40 UTC

svn commit: r552770 - in /felix/trunk/configadmin/src: main/java/org/apache/felix/cm/file/ main/java/org/apache/felix/cm/impl/ test/java/org/apache/felix/cm/ test/java/org/apache/felix/cm/file/

Author: fmeschbe
Date: Tue Jul  3 02:49:39 2007
New Revision: 552770

URL: http://svn.apache.org/viewvc?view=rev&rev=552770
Log:
FELIX-316 Configuration Admin should use the bundle data storage area by default.

Added:
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java
Removed:
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FileNameTest.java
Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundleContext.java
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java?view=diff&rev=552770&r1=552769&r2=552770
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java Tue Jul  3 02:49:39 2007
@@ -28,7 +28,6 @@
 import java.util.BitSet;
 import java.util.Dictionary;
 import java.util.Enumeration;
-import java.util.Hashtable;
 import java.util.NoSuchElementException;
 import java.util.Stack;
 
@@ -42,11 +41,17 @@
  * properties-like files inside a given directory. All configuration files are
  * located in the same directory.
  * <p>
- * The configuration directory may be set by using the
- * {@link #FilePersistenceManager(String)} naming the path to the directry. When
- * this persistence manager is used by the Configuration Admin Service, the
- * location may be configured using the {@link #CM_CONFIG_DIR} bundle context
- * property.
+ * The configuration directory is set by either the
+ * {@link #FilePersistenceManager(String)} constructor or the
+ * {@link #FilePersistenceManager(BundleContext, String)} constructor. Refer
+ * to the respective JavaDocs for more information.
+ * <p>
+ * When this persistence manager is used by the Configuration Admin Service,
+ * the location may be configured using the
+ * {@link org.apache.felix.cm.impl.ConfigurationManager#CM_CONFIG_DIR} bundle
+ * context property. That is the Configuration Admin Service creates an instance
+ * of this class calling
+ * <code>new FilePersistenceManager(bundleContext, bundleContext.getProperty(CM_CONFIG_DIR))</code>.
  * <p>
  * If the location is not set, the <code>config</code> directory in the current
  * working directory (as set in the <code>user.dir</code> system property) is
@@ -65,7 +70,7 @@
  * <tr><th>PID</th><th>Configuration File Name</th></tr>
  * <tr><td><code>sample</code><td><code>sample.config</code></tr>
  * <tr><td><code>org.apache.felix.log.LogService</code><td><code>org/apache/felix/log/LogService.config</code></tr>
- * <tr><td><code>sample.fl�che</code><td><code>sample/fl%00e8che.config</code></tr>
+ * <tr><td><code>sample.fl&auml;che</code><td><code>sample/fl%00e8che.config</code></tr>
  * </table>
  *
  * @author fmeschbe
@@ -74,6 +79,12 @@
 {
 
     /**
+     * The default configuration data directory if no location is configured
+     * (value is "config").
+     */
+    public static final String DEFAULT_CONFIG_DIR = "config";
+
+    /**
      * The extension of the configuration files.
      */
     private static final String FILE_EXT = ".config";
@@ -111,25 +122,181 @@
 
 
     /**
+     * Encodes a Service PID to a filesystem path as described in the class
+     * JavaDoc above.
+     * <p>
+     * This method is not part of the API of this class and is declared package
+     * private to enable JUnit testing on it. This method may be removed or
+     * modified at any time without notice.
+     * 
+     * @param pid The Service PID to encode into a relative path name.
+     * 
+     * @return The relative path name corresponding to the Service PID.
+     */
+    static String encodePid( String pid )
+    {
+
+        // replace dots by File.separatorChar
+        pid = pid.replace( '.', File.separatorChar );
+
+        // replace slash by File.separatorChar if different
+        if ( File.separatorChar != '/' )
+        {
+            pid = pid.replace( '/', File.separatorChar );
+        }
+
+        // scan for first non-valid character (if any)
+        int first = 0;
+        while ( first < pid.length() && VALID_PATH_CHARS.get( pid.charAt( first ) ) )
+        {
+            first++;
+        }
+
+        // check whether we exhausted
+        if ( first < pid.length() )
+        {
+            StringBuffer buf = new StringBuffer( pid.substring( 0, first ) );
+
+            for ( int i = first; i < pid.length(); i++ )
+            {
+                char c = pid.charAt( i );
+                if ( VALID_PATH_CHARS.get( c ) )
+                {
+                    buf.append( c );
+                }
+                else
+                {
+                    String val = "000" + Integer.toHexString( c );
+                    buf.append( '%' );
+                    buf.append( val.substring( val.length() - 4 ) );
+                }
+            }
+
+            pid = buf.toString();
+        }
+
+        return pid;
+    }
+
+
+    /**
      * Creates an instance of this persistence manager using the given location
      * as the directory to store and retrieve the configuration files.
+     * <p>
+     * This constructor resolves the configuration file location as follows:
+     * <ul>
+     * <li>If <code>location</code> is <code>null</code>, the <code>config</code>
+     * directory in the current working directory as specified in the
+     * <code>user.dir</code> system property is assumed.</li>
+     * <li>Otherwise the named directory is used.</li>
+     * <li>If the directory name resolved in the first or second step is not an
+     * absolute path, it is resolved to an absolute path calling the
+     * <code>File.getAbsoluteFile()</code> method.</li>
+     * <li>If a non-directory file exists as the location found in the previous
+     * step or the named directory (including any parent directories) cannot be
+     * created, an <code>IllegalArgumentException</code> is thrown.</li>
+     * </ul>
+     * <p>
+     * This constructor is equivalent to calling
+     * {@link #FilePersistenceManager(BundleContext, String)} with a
+     * <code>null</code> <code>BundleContext</code>.
      * 
      * @param location The configuration file location. If this is
      *      <code>null</code> the <code>config</code> directory below the current
      *      working directory is used.
      * 
+     * @throws IllegalArgumentException If the <code>location</code> exists but
+     *      is not a directory or does not exist and cannot be created.
+     */
+    public FilePersistenceManager( String location )
+    {
+        this( null, location );
+    }
+
+
+    /**
+     * Creates an instance of this persistence manager using the given location
+     * as the directory to store and retrieve the configuration files.
+     * <p>
+     * This constructor resolves the configuration file location as follows:
+     * <ul>
+     * <li>If <code>location</code> is <code>null</code>, the <code>config</code>
+     * directory in the persistent storage area of the bundle identified by
+     * <code>bundleContext</code> is used.</li>
+     * <li>If the framework does not support persistent storage area for bundles
+     * in the filesystem or if <code>bundleContext</code> is <code>null</code>,
+     * the <code>config</code> directory in the current working directory as
+     * specified in the <code>user.dir</code> system property is assumed.</li>
+     * <li>Otherwise the named directory is used.</li>
+     * <li>If the directory name resolved in the first, second or third step is
+     * not an absolute path and a <code>bundleContext</code> is provided which
+     * provides access to persistent storage area, the directory name is
+     * resolved as being inside the persistent storage area. Otherwise the
+     * directory name is resolved to an absolute path calling the
+     * <code>File.getAbsoluteFile()</code> method.</li>
+     * <li>If a non-directory file exists as the location found in the previous
+     * step or the named directory (including any parent directories) cannot be
+     * created, an <code>IllegalArgumentException</code> is thrown.</li>
+     * </ul>
+     * 
+     * @param bundleContext The <code>BundleContext</code> to optionally get
+     *      the data location for the configuration files. This may be
+     *      <code>null</code>, in which case this constructor acts exactly the
+     *      same as calling {@link #FilePersistenceManager(String)}.
+     * @param location The configuration file location. If this is
+     *      <code>null</code> the <code>config</code> directory below the current
+     *      working directory is used.
+     * 
      * @throws IllegalArgumentException If the location exists but is not a
      *      directory or does not exist and cannot be created.
+     * @throws IllegalStateException If the <code>bundleContext</code> is not
+     *      valid.
      */
-    public FilePersistenceManager( String location )
+    public FilePersistenceManager( BundleContext bundleContext, String location )
     {
+        File locationFile = null;
+
+        // no configured location, use the config dir in the bundle persistent
+        // area
+        if ( location == null && bundleContext != null )
+        {
+            locationFile = bundleContext.getDataFile( DEFAULT_CONFIG_DIR );
+            if ( locationFile != null )
+            {
+                location = locationFile.getAbsolutePath();
+            }
+        }
+
+        // fall back to the current working directory if the platform does
+        // not support filesystem based data area
         if ( location == null )
         {
             location = System.getProperty( "user.dir" ) + "/config";
         }
 
+        // ensure the File object for the location (may have been set already)
+        if ( locationFile == null )
+        {
+            locationFile = new File( location );
+        }
+
+        // ensure the file is absolute
+        if ( !locationFile.isAbsolute() )
+        {
+            if ( bundleContext != null )
+            {
+                File bundleLocationFile = bundleContext.getDataFile( locationFile.getPath() );
+                if ( bundleLocationFile != null )
+                {
+                    locationFile = bundleLocationFile;
+                }
+            }
+            
+            // ensure the file object is an absolute file object
+            locationFile = locationFile.getAbsoluteFile();
+        }
+        
         // check the location
-        File locationFile = new File( location );
         if ( !locationFile.isDirectory() )
         {
             if ( locationFile.exists() )
@@ -148,6 +315,18 @@
 
 
     /**
+     * Returns the directory in which the configuration files are written as
+     * a <code>File</code> object.
+     * 
+     * @return The configuration file location.
+     */
+    public File getLocation()
+    {
+        return location;
+    }
+
+
+    /**
      * Loads configuration data from the configuration location and returns
      * it as <code>Dictionary</code> objects.
      * <p>
@@ -298,46 +477,7 @@
      */
     private File getFile( String pid )
     {
-        // replace dots by File.separatorChar
-        pid = pid.replace( '.', File.separatorChar );
-
-        // replace slash by File.separatorChar if different
-        if ( File.separatorChar != '/' )
-        {
-            pid = pid.replace( '/', File.separatorChar );
-        }
-
-        // scan for first non-valid character (if any)
-        int first = 0;
-        while ( first < pid.length() && VALID_PATH_CHARS.get( pid.charAt( first ) ) )
-        {
-            first++;
-        }
-
-        // check whether we exhausted
-        if ( first < pid.length() )
-        {
-            StringBuffer buf = new StringBuffer( pid.substring( 0, first ) );
-
-            for ( int i = first; i < pid.length(); i++ )
-            {
-                char c = pid.charAt( i );
-                if ( VALID_PATH_CHARS.get( c ) )
-                {
-                    buf.append( c );
-                }
-                else
-                {
-                    String val = "000" + Integer.toHexString( c );
-                    buf.append( '%' );
-                    buf.append( val.substring( val.length() - 4 ) );
-                }
-            }
-
-            pid = buf.toString();
-        }
-
-        return new File( location, pid + FILE_EXT );
+        return new File( location, encodePid( pid ) + FILE_EXT );
     }
 
     /**

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java?view=diff&rev=552770&r1=552769&r2=552770
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java Tue Jul  3 02:49:39 2007
@@ -172,7 +172,8 @@
         // set up the location (might throw IllegalArgumentException)
         try
         {
-            FilePersistenceManager fpm = new FilePersistenceManager( bundleContext.getProperty( CM_CONFIG_DIR ) );
+            FilePersistenceManager fpm = new FilePersistenceManager( bundleContext,
+                bundleContext.getProperty( CM_CONFIG_DIR ) );
             Hashtable props = new Hashtable();
             props.put( Constants.SERVICE_PID, fpm.getClass().getName() );
             props.put( Constants.SERVICE_DESCRIPTION, "Platform Filesystem Persistence Manager" );

Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundleContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundleContext.java?view=diff&rev=552770&r1=552769&r2=552770
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundleContext.java (original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundleContext.java Tue Jul  3 02:49:39 2007
@@ -34,7 +34,12 @@
 import org.osgi.framework.ServiceRegistration;
 
 /**
- * The <code>MockBundleContext</code> TODO
+ * The <code>MockBundleContext</code> is a dummy implementation of the
+ * <code>BundleContext</code> interface. No methods are implemented here, that
+ * is all methods have no effect and return <code>null</code> if a return
+ * value is specified.
+ * <p>
+ * Extensions may overwrite methods as see fit.
  *
  * @author fmeschbe
  */
@@ -46,8 +51,6 @@
      */
     public void addBundleListener( BundleListener arg0 )
     {
-        // TODO Auto-generated method stub
-
     }
 
 
@@ -56,8 +59,6 @@
      */
     public void addFrameworkListener( FrameworkListener arg0 )
     {
-        // TODO Auto-generated method stub
-
     }
 
 
@@ -66,8 +67,6 @@
      */
     public void addServiceListener( ServiceListener arg0 )
     {
-        // TODO Auto-generated method stub
-
     }
 
 
@@ -76,8 +75,6 @@
      */
     public void addServiceListener( ServiceListener arg0, String arg1 ) throws InvalidSyntaxException
     {
-        // TODO Auto-generated method stub
-
     }
 
 
@@ -86,7 +83,6 @@
      */
     public Filter createFilter( String arg0 ) throws InvalidSyntaxException
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -96,7 +92,6 @@
      */
     public ServiceReference[] getAllServiceReferences( String arg0, String arg1 ) throws InvalidSyntaxException
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -106,7 +101,6 @@
      */
     public Bundle getBundle()
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -116,7 +110,6 @@
      */
     public Bundle getBundle( long arg0 )
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -126,7 +119,6 @@
      */
     public Bundle[] getBundles()
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -136,7 +128,6 @@
      */
     public File getDataFile( String arg0 )
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -146,7 +137,6 @@
      */
     public String getProperty( String arg0 )
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -156,7 +146,6 @@
      */
     public Object getService( ServiceReference arg0 )
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -166,7 +155,6 @@
      */
     public ServiceReference getServiceReference( String arg0 )
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -176,7 +164,6 @@
      */
     public ServiceReference[] getServiceReferences( String arg0, String arg1 ) throws InvalidSyntaxException
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -186,7 +173,6 @@
      */
     public Bundle installBundle( String arg0 ) throws BundleException
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -196,7 +182,6 @@
      */
     public Bundle installBundle( String arg0, InputStream arg1 ) throws BundleException
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -206,7 +191,6 @@
      */
     public ServiceRegistration registerService( String[] arg0, Object arg1, Dictionary arg2 )
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -216,7 +200,6 @@
      */
     public ServiceRegistration registerService( String arg0, Object arg1, Dictionary arg2 )
     {
-        // TODO Auto-generated method stub
         return null;
     }
 
@@ -226,8 +209,6 @@
      */
     public void removeBundleListener( BundleListener arg0 )
     {
-        // TODO Auto-generated method stub
-
     }
 
 
@@ -236,8 +217,6 @@
      */
     public void removeFrameworkListener( FrameworkListener arg0 )
     {
-        // TODO Auto-generated method stub
-
     }
 
 
@@ -246,8 +225,6 @@
      */
     public void removeServiceListener( ServiceListener arg0 )
     {
-        // TODO Auto-generated method stub
-
     }
 
 
@@ -256,8 +233,6 @@
      */
     public boolean ungetService( ServiceReference arg0 )
     {
-        // TODO Auto-generated method stub
         return false;
     }
-
 }

Added: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java?view=auto&rev=552770
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java (added)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java Tue Jul  3 02:49:39 2007
@@ -0,0 +1,152 @@
+/*
+ * $Url: $
+ * $Id: $
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.felix.cm.file;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Dictionary;
+
+import org.apache.felix.cm.MockBundleContext;
+import org.apache.felix.cm.impl.ConfigurationManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+import junit.framework.TestCase;
+
+/**
+ * The <code>FilePersistenceManagerConstructorTest</code> TODO
+ */
+public class FilePersistenceManagerConstructorTest extends TestCase
+{
+
+    /**
+     * Test method for {@link org.apache.felix.cm.file.FilePersistenceManager#FilePersistenceManager(java.lang.String)}.
+     */
+    public void testFilePersistenceManagerString()
+    {
+        // variables used in these tests
+        FilePersistenceManager fpm;
+        String relPath;
+        String absPath;
+        
+        // with null
+        fpm = new FilePersistenceManager(null);
+        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR).getAbsoluteFile() );
+        
+        // with a relative path
+        relPath = "test";
+        fpm = new FilePersistenceManager(relPath);
+        assertFpm(fpm, new File(relPath).getAbsoluteFile() );
+        
+        // with an absolute path
+        absPath = new File("test").getAbsolutePath();
+        fpm = new FilePersistenceManager(absPath);
+        assertFpm(fpm, new File(absPath).getAbsoluteFile() );
+    }
+
+
+    /**
+     * Test method for {@link org.apache.felix.cm.file.FilePersistenceManager#FilePersistenceManager(org.osgi.framework.BundleContext, java.lang.String)}.
+     */
+    public void testFilePersistenceManagerBundleContextString()
+    {
+        // variables used in these tests
+        BundleContext bundleContext;
+        FilePersistenceManager fpm;
+        String relPath;
+        String absPath;
+        
+        // first suite: no BundleContext at all
+        
+        // with null
+        fpm = new FilePersistenceManager(null);
+        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR).getAbsoluteFile() );
+        
+        // with a relative path
+        relPath = "test";
+        fpm = new FilePersistenceManager(relPath);
+        assertFpm(fpm, new File(relPath).getAbsoluteFile() );
+        
+        // with an absolute path
+        absPath = new File("test").getAbsolutePath();
+        fpm = new FilePersistenceManager(absPath);
+        assertFpm(fpm, new File(absPath).getAbsoluteFile() );
+        
+        
+        // second suite: BundleContext without data file
+        bundleContext = new FilePersistenceManagerBundleContext(null);
+        
+        // with null
+        fpm = new FilePersistenceManager(bundleContext, null);
+        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR).getAbsoluteFile() );
+        
+        // with a relative path
+        relPath = "test";
+        fpm = new FilePersistenceManager(bundleContext, relPath);
+        assertFpm(fpm, new File(relPath).getAbsoluteFile() );
+        
+        // with an absolute path
+        absPath = new File("test").getAbsolutePath();
+        fpm = new FilePersistenceManager(bundleContext, absPath);
+        assertFpm(fpm, new File(absPath).getAbsoluteFile() );
+
+        
+        // third suite: BundleContext with data file
+        File dataArea = new File("bundleData");
+        bundleContext = new FilePersistenceManagerBundleContext(dataArea);
+        
+        // with null
+        fpm = new FilePersistenceManager(bundleContext, null);
+        assertFpm(fpm, new File(dataArea, FilePersistenceManager.DEFAULT_CONFIG_DIR).getAbsoluteFile() );
+        
+        // with a relative path
+        relPath = "test";
+        fpm = new FilePersistenceManager(bundleContext, relPath);
+        assertFpm(fpm, new File(dataArea, relPath).getAbsoluteFile() );
+        
+        // with an absolute path
+        absPath = new File("test").getAbsolutePath();
+        fpm = new FilePersistenceManager(bundleContext, absPath);
+        assertFpm(fpm, new File(absPath).getAbsoluteFile() );
+    }
+
+    
+    private void assertFpm(FilePersistenceManager fpm, File expected) {
+        assertEquals( expected, fpm.getLocation() );
+    }
+    
+    private static final class FilePersistenceManagerBundleContext extends MockBundleContext {
+
+        private File dataArea;
+        
+        private FilePersistenceManagerBundleContext( File dataArea )
+        {
+            this.dataArea = (dataArea != null) ? dataArea.getAbsoluteFile() : null;
+        }
+        
+        public File getDataFile( String path )
+        {
+            return (dataArea != null) ? new File(dataArea, path) : null;
+        }
+    }
+}

Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java?view=diff&rev=552770&r1=552769&r2=552770
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java (original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java Tue Jul  3 02:49:39 2007
@@ -64,6 +64,19 @@
     }
 
 
+    public void testPidPlain()
+    {
+        assertEquals( "plain", FilePersistenceManager.encodePid( "plain" ) );
+        assertEquals( "plain" + File.separatorChar + "path", FilePersistenceManager.encodePid( "plain.path" ) );
+        assertEquals( "encod%00e8", FilePersistenceManager.encodePid( "encod\u00E8" ) );
+        assertEquals( "encod%00e8" + File.separatorChar + "path", FilePersistenceManager.encodePid( "encod\u00E8/path" ) );
+        assertEquals( "encode" + File.separatorChar + "%1234" + File.separatorChar + "path", FilePersistenceManager
+            .encodePid( "encode/\u1234/path" ) );
+        assertEquals( "encode" + File.separatorChar + " %0025 " + File.separatorChar + "path", FilePersistenceManager
+            .encodePid( "encode/ % /path" ) );
+    }
+
+
     public void testCreateDir()
     {
         assertTrue( file.isDirectory() );