You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2004/09/23 10:41:56 UTC

cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestConfigurationUtils.java

ebourg      2004/09/23 01:41:56

  Modified:    configuration/src/java/org/apache/commons/configuration
                        ConfigurationUtils.java
               configuration/src/test/org/apache/commons/configuration
                        TestConfigurationUtils.java
  Log:
  Added tests for ConfigurationUtils.getBasePath()
  
  Revision  Changes    Path
  1.8       +5 -4      jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationUtils.java
  
  Index: ConfigurationUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ConfigurationUtils.java	22 Sep 2004 17:17:30 -0000	1.7
  +++ ConfigurationUtils.java	23 Sep 2004 08:41:55 -0000	1.8
  @@ -323,7 +323,8 @@
       }
   
       /**
  -     * Return the path without the file name, for example http://xyz.net/foo/bar.xml results in http://xyz.net/foo/
  +     * Return the path without the file name, for example http://xyz.net/foo/bar.xml
  +     * results in http://xyz.net/foo/
        *
        * @param url
        * @return
  @@ -332,13 +333,13 @@
       {
           String s = url.toString();
   
  -        if (s.endsWith("/"))
  +        if (s.endsWith("/") || StringUtils.isEmpty(url.getPath()))
           {
               return s;
           }
           else
           {
  -            return s.substring(0, s.lastIndexOf("/") + 1); // todo: doesn't work for http://xyz.net !
  +            return s.substring(0, s.lastIndexOf("/") + 1);
           }
       }
   
  
  
  
  1.6       +19 -0     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
  
  Index: TestConfigurationUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestConfigurationUtils.java	12 Jul 2004 14:35:29 -0000	1.5
  +++ TestConfigurationUtils.java	23 Sep 2004 08:41:56 -0000	1.6
  @@ -93,4 +93,23 @@
   		assertEquals(absFile.toURL(),
   		ConfigurationUtils.getURL(absFile.getParent(), "config.xml"));
       }
  +
  +    public void testGetBasePath() throws Exception
  +    {
  +        URL url = new URL("http://xyz.net/foo/bar.xml");
  +        assertEquals("base path of " + url, "http://xyz.net/foo/", ConfigurationUtils.getBasePath(url));
  +
  +        url = new URL("http://xyz.net/foo/");
  +        assertEquals("base path of " + url, "http://xyz.net/foo/", ConfigurationUtils.getBasePath(url));
  +
  +        url = new URL("http://xyz.net/foo");
  +        assertEquals("base path of " + url, "http://xyz.net/", ConfigurationUtils.getBasePath(url));
  +
  +        url = new URL("http://xyz.net/");
  +        assertEquals("base path of " + url, "http://xyz.net/", ConfigurationUtils.getBasePath(url));
  +
  +        url = new URL("http://xyz.net");
  +        assertEquals("base path of " + url, "http://xyz.net", ConfigurationUtils.getBasePath(url));
  +    }
  +
   }
  
  
  

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