commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prick...@apache.org
Subject cvs commit: jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database DriverServiceGetInitTest.java
Date Fri, 29 Nov 2002 01:52:44 GMT
prickett    2002/11/28 17:52:44

  Modified:    periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
                        DriverMetaDataService.java
                        PeriodicityDriverService.java
               periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database
                        DriverServiceGetInitTest.java
  Log:
  Removed throws clause from getMetaData in DriverMetaDataService
  
  Removed an invalid restriction on adding a driver after service initialization
  
  Added an initialization exception in PeriodicityDriverService.init() if no
  drivers are found
  
  Implemented getMetaData(String) and getDrivers();
  
  Added a method to the GetInit test that will log the drivers found in
  databases.xml
  
  Revision  Changes    Path
  1.5       +8 -11     jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaDataService.java
  
  Index: DriverMetaDataService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaDataService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DriverMetaDataService.java	28 Nov 2002 22:42:36 -0000	1.4
  +++ DriverMetaDataService.java	29 Nov 2002 01:52:44 -0000	1.5
  @@ -61,7 +61,7 @@
    *
    */ 
   
  -
  +import java.util.Iterator;
   import org.apache.fulcrum.Service;
   
   interface DriverMetaDataService extends Service
  @@ -83,15 +83,12 @@
        *         name.
        */
       
  -    public DriverMetaData getMetaData(String driverName) throws Exception;
  +    public DriverMetaData getMetaData(String driverName);
   
       /**
  -     * The purpose of this method is to add a driver to this service.
  -     * This method should only add drivers to services that have not
  -     * yet been initialized.
  -     * @param newDriver The new driver to be added to the meta data service
  +     * The purpose of this method is to return all the drivers in an Iterator
  +     * @return All the drivers supported by this service as an iterator
        */
  -    
  -    void addDriver(DriverMetaData newDriver) throws Exception;
  +    public Iterator getDrivers(); 
   
   }    
  
  
  
  1.6       +41 -10    jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/PeriodicityDriverService.java
  
  Index: PeriodicityDriverService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/PeriodicityDriverService.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PeriodicityDriverService.java	28 Nov 2002 22:42:36 -0000	1.5
  +++ PeriodicityDriverService.java	29 Nov 2002 01:52:44 -0000	1.6
  @@ -68,6 +68,9 @@
   import java.io.BufferedInputStream;
   import java.util.Map;
   import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.Set;
  +import java.util.Collection;
   import javax.xml.parsers.SAXParserFactory;
   import javax.xml.parsers.SAXParser;
   import org.xml.sax.InputSource;
  @@ -157,7 +160,7 @@
       private void addDriver(DriverMetaData newDriver) 
              throws InitializationException
       {
  -        if(newDriver != null && newDriver.getName() != null && isInitialized())
  +        if(newDriver != null && newDriver.getName() != null)
           {
               if(drivers == null)
               {
  @@ -173,10 +176,6 @@
           {
               throw new InitializationException("newDriver.getName() == null");
           }
  -        else if(!isInitialized())
  -        {
  -            throw new InitializationException("Service already initialized.");
  -        }
           else
           {
               throw new InitializationException("UNEXPECTED EXCEPTION");
  @@ -236,6 +235,11 @@
                           {
                               addDrivers(drivers);
                           }    
  +                        else
  +                        {
  +                            throw new InitializationException(
  +                                   "No Drivers Found.");
  +                        }           
                       }
                       else if(parser == null)
                       {
  @@ -272,8 +276,35 @@
           }    
       } 
   
  -    public DriverMetaData getMetaData(String driverName) throws Exception
  +    public DriverMetaData getMetaData(String driverName)
       {
  -        return null;
  +        if(drivers != null)
  +        {
  +            return (DriverMetaData) drivers.get(driverName);
  +        }
  +        else
  +        {
  +            return null;
  +        }
       }
  +
  +    public Iterator getDrivers()
  +    {
  +        if(drivers != null)
  +        {
  +            Collection values = drivers.values();
  +            if(values != null)
  +            {
  +                return values.iterator();
  +            }
  +            else
  +            {
  +                return null;
  +            }
  +        }
  +        else
  +        {
  +            return null;
  +        }
  +    }    
   }    
  
  
  
  1.6       +53 -12    jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DriverServiceGetInitTest.java
  
  Index: DriverServiceGetInitTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DriverServiceGetInitTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DriverServiceGetInitTest.java	28 Nov 2002 22:42:36 -0000	1.5
  +++ DriverServiceGetInitTest.java	29 Nov 2002 01:52:44 -0000	1.6
  @@ -63,6 +63,7 @@
    */ 
   
   
  +import java.util.Iterator;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import org.apache.commons.configuration.BaseConfiguration;
  @@ -89,7 +90,7 @@
   
       public static final String PERIODICITY_DRIVER_SERVICE_NAME =
              "PeriodicityDriverService";
  -
  +    
       public DriverServiceGetInitTest(String name)
       {
           super(name);
  @@ -116,19 +117,15 @@
                   turbineServices.setApplicationRoot(".");
                   turbineServices.init();
                   BaseConfiguration config = new BaseConfiguration();
  -                if(getLogger() != null)
  -                {
  -                    getLogger().info("Getting Driver Service");
  -                }    
                   PeriodicityDriverService driverService = 
                          (PeriodicityDriverService) turbineServices.getService(
                          PERIODICITY_DRIVER_SERVICE_NAME);
  -                if(getLogger() != null)
  -                {
  -                    getLogger().info("Got driver service");
  -                }    
                   assertTrue("Service should have been initialized.", 
                          driverService.isInitialized());
  +                if(driverService != null)
  +                {
  +                    logDrivers(driverService);
  +                }    
               }
               else
               {
  @@ -140,6 +137,50 @@
               fail(e.getMessage() + "\n" + JUnitUtils.getStackTraceAsString(e));
           }
       }
  +
  +    private void logDrivers(PeriodicityDriverService service)
  +    {
  +        if(service != null)
  +        {
  +            Iterator iter = service.getDrivers();
  +            if(iter != null && getLogger() != null)
  +            {
  +                getLogger().info("BEGIN DRIVERS");
  +                while(iter.hasNext())
  +                {
  +                    getLogger().info(
  +                           getLogMessage((DriverMetaData) iter.next()));
  +                }
  +                getLogger().info("END DRIVERS");
  +            }
  +        }
  +    }    
  +    
  +    private String getLogMessage(DriverMetaData meta)
  +    {
  +        if(meta != null)
  +        {
  +            StringBuffer buffy = new StringBuffer();
  +            buffy.append(meta.getName());
  +            buffy.append("\n");
  +            buffy.append("getShortDescription()=\"");
  +            buffy.append(meta.getShortDescription());
  +            buffy.append("\"\ngetDescription()=\"");
  +            buffy.append(meta.getDescription());
  +            buffy.append("\"\ngetWebUrl()=\"");
  +            buffy.append(meta.getWebUrl());
  +            buffy.append("\"\ngetClassName()=\"");
  +            buffy.append(meta.getClassName());
  +            buffy.append("\"\n");
  +            return buffy.toString();
  +        }
  +        else
  +        {
  +            return null;
  +        }
  +    }    
  +            
  +                        
   
       public static Test suite()
       {
  
  
  

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


Mime
View raw message