geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/rmi RMIClassLoaderSpiImplTest.java
Date Sat, 30 Aug 2003 10:22:52 GMT
jdillon     2003/08/30 03:22:52

  Modified:    modules/core/src/conf boot-service.xml
               modules/core/src/java/org/apache/geronimo/rmi
                        RMIClassLoaderSpiImpl.java
               modules/core/src/test/org/apache/geronimo/rmi
                        RMIClassLoaderSpiImplTest.java
  Log:
   o Removed code duplication
   o Attempted to make testcase play better with different operating systems
  
  Revision  Changes    Path
  1.10      +10 -1     incubator-geronimo/modules/core/src/conf/boot-service.xml
  
  Index: boot-service.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/conf/boot-service.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- boot-service.xml	28 Aug 2003 11:19:17 -0000	1.9
  +++ boot-service.xml	30 Aug 2003 10:22:52 -0000	1.10
  @@ -3,6 +3,15 @@
   <!-- $Revision$ $Date$ -->
   
   <components>
  +  <!-- Log4j Logging Service -->
  +  <mbean code="org.apache.geronimo.core.logging.log4j.Log4jService" name="geronimo.core:role=Logging">
  +    <constructor>
  +      <arg type="java.net.URL">
  +        ${geronimo.home}/etc/log4j.xml
  +      </arg>
  +    </constructor>
  +  </mbean>
  +  
     <!-- RMI adaptor to support MX4J -->
     <mbean code="mx4j.tools.naming.NamingService" name="Naming:type=rmiregistry">
     </mbean>
  
  
  
  1.2       +32 -26    incubator-geronimo/modules/core/src/java/org/apache/geronimo/rmi/RMIClassLoaderSpiImpl.java
  
  Index: RMIClassLoaderSpiImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/rmi/RMIClassLoaderSpiImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RMIClassLoaderSpiImpl.java	29 Aug 2003 12:30:37 -0000	1.1
  +++ RMIClassLoaderSpiImpl.java	30 Aug 2003 10:22:52 -0000	1.2
  @@ -111,53 +111,59 @@
           return delegate.getClassAnnotation(type);
       }
       
  -    static String normalizeCodebase(String codebase)
  +    static String normalizeCodebase(String input)
           throws MalformedURLException
       {
  -        assert codebase != null;
  +        assert input != null;
  +        // System.out.println("Input codebase: " + input);
           
  -        StringBuffer codebaseBuff = new StringBuffer();
  -        StringBuffer buff = new StringBuffer();
  -        StringTokenizer stok = new StringTokenizer(codebase, " \t\n\r\f", true);
  +        StringBuffer codebase = new StringBuffer();
  +        StringBuffer working = new StringBuffer();
  +        StringTokenizer stok = new StringTokenizer(input, " \t\n\r\f", true);
           
           while (stok.hasMoreTokens()) {
               String item = stok.nextToken();
               try {
                   URL url = new URL(item);
  +                // System.out.println("Created URL: " + url);
                   
                   // If we got this far then item is a valid url, so commit the current
                   // buffer and start collecting any trailing bits from where we are now
                   
  -                // Put spaces back in for URL delims
  -                if (codebaseBuff.length() != 0) {
  -                    codebaseBuff.append(" ");
  -                }
  -                
  -                // Normalize the URL
  -                url = normalizeURL(new URL(buff.toString()));
  -                codebaseBuff.append(url);
  -                
  -                // Reset the working buffer
  -                buff.setLength(0);
  +                updateCodebase(working, codebase);
               }
               catch (MalformedURLException ignore) {
                   // just keep going & append to the working buffer
               }
               
  -            buff.append(item);
  +            working.append(item);
  +            // System.out.println("Added to working buffer: " + item);
           }
           
  -        // handle trainling elements
  -        if (buff.length() != 0) {
  -            URL url = normalizeURL(new URL(buff.toString()));
  +        // Handle trailing elements
  +        updateCodebase(working, codebase);
  +        
  +        // System.out.println("Normalized codebase: " + codebase);
  +        return codebase.toString();
  +    }
  +    
  +    private static void updateCodebase(final StringBuffer working, final StringBuffer codebase)
  +        throws MalformedURLException
  +    {
  +        if (working.length() != 0) {
  +            // Normalize the URL
  +            URL url = normalizeURL(new URL(working.toString()));
  +            // System.out.println("Created normalized URL: " + url);
               
  -            if (codebaseBuff.length() != 0) {
  -                codebaseBuff.append(" ");
  +            // Put spaces back in for URL delims
  +            if (codebase.length() != 0) {
  +                codebase.append(" ");
               }
  -            codebaseBuff.append(url);
  +            codebase.append(url);
  +            
  +            // Reset the working buffer
  +            working.setLength(0);
           }
  -        
  -        return codebaseBuff.toString();
       }
       
       static URL normalizeURL(URL url)
  
  
  
  1.2       +29 -17    incubator-geronimo/modules/core/src/test/org/apache/geronimo/rmi/RMIClassLoaderSpiImplTest.java
  
  Index: RMIClassLoaderSpiImplTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/rmi/RMIClassLoaderSpiImplTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RMIClassLoaderSpiImplTest.java	29 Aug 2003 12:30:37 -0000	1.1
  +++ RMIClassLoaderSpiImplTest.java	30 Aug 2003 10:22:52 -0000	1.2
  @@ -59,6 +59,8 @@
   import java.net.MalformedURLException;
   import java.net.URL;
   
  +import java.io.File;
  +
   import junit.framework.TestCase;
   
   /**
  @@ -69,30 +71,40 @@
   public class RMIClassLoaderSpiImplTest
       extends TestCase
   {
  -    public void testNormalizeURL()
  +    private String baseURL;
  +    private String normalizedBaseURL;
  +    
  +    protected void setUp() throws Exception
       {
  -        URL url = null;
  -        try {
  -            url = new URL("file:/Program Files/Apache Group/Geronimo");
  +        File dir = new File(System.getProperty("user.home"));
  +        
  +        baseURL = dir.toURL().toString();
  +        if (baseURL.endsWith("/")) {
  +            baseURL = baseURL.substring(0, baseURL.length() - 1);
           }
  -        catch (MalformedURLException e) {
  -            fail("Unexpected MUE: " + e);
  +        
  +        normalizedBaseURL = dir.toURI().toURL().toString();
  +        if (normalizedBaseURL.endsWith("/")) {
  +            normalizedBaseURL = normalizedBaseURL.substring(0, normalizedBaseURL.length()
- 1);
           }
           
  +        System.out.println("Using base URL: " + baseURL);
  +        System.out.println("Using normalized base URL: " + normalizedBaseURL);
  +    }
  +    
  +    public void testNormalizeURL() throws MalformedURLException
  +    {
  +        URL url = new URL(baseURL + "/Apache Group/Geronimo");
           URL normal = RMIClassLoaderSpiImpl.normalizeURL(url);
  -        assertEquals("file:/Program%20Files/Apache%20Group/Geronimo", normal.toString());
  +        assertEquals(normalizedBaseURL + "/Apache%20Group/Geronimo", normal.toString());
       }
       
  -    public void testNormalizeCodebase()
  +    public void testNormalizeCodebase() throws MalformedURLException
       {
  -        String codebase = "file:/Program Files/Apache Group/Geronimo file:/Program Files/Apache
Group/Whatever";
  +        String codebase = baseURL + "/Apache Group/Geronimo " + baseURL + "/Apache Group/Apache2";
           
  -        try {
  -            String normal = RMIClassLoaderSpiImpl.normalizeCodebase(codebase);
  -            assertEquals("file:/Program%20Files/Apache%20Group/Geronimo file:/Program%20Files/Apache%20Group/Whatever",
normal);
  -        }
  -        catch (MalformedURLException e) {
  -            fail("Unexpected MUE: " + e);
  -        }
  +        String normal = RMIClassLoaderSpiImpl.normalizeCodebase(codebase);
  +        assertEquals(normalizedBaseURL + "/Apache%20Group/Geronimo " + 
  +                     normalizedBaseURL + "/Apache%20Group/Apache2", normal);
       }
   }
  
  
  

Mime
View raw message