prickett    2002/11/30 16:28:38

  Modified:    
periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
                        DatabaseContentHandler.java
                        DatabaseMetaDataImpl.java
                        PeriodicityDbMetaService.java
               
periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database
                        DatabaseMDNullValueTests.java
                        DatabaseMDSetGetTests.java
  Added:       
periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database
                        DatabaseServiceGetInitTest.java
                        DatabaseServiceTestSuite.java
  Log:
  Removed an unneeded thrown exception
  
  Added code to add a database entry from the xml file to the databases set
  
  Removed adminPath variable from DatabaseContentHandler
  
  Fixed the DatabaseMetaDataImpl constructor to only take the type argument
  
  Made setName public in DatabaseMetaDataImpl
  
  Keyed db map on type instead of name
  
  Changed DriverContentHandler to DatabaseContentHandler in
  PeriodicityDbMetaService
  
  Minor changes to a couple of test files
  
  Revision  Changes    Path
  1.3       +8 -15     
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseContentHandler.java
  
  Index: DatabaseContentHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseContentHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatabaseContentHandler.java       30 Nov 2002 22:05:16 -0000      1.2
  +++ DatabaseContentHandler.java       1 Dec 2002 00:28:38 -0000       1.3
  @@ -112,9 +112,6 @@
       /** A variable to hold the web url */
       private String webUrl = null;
       
  -    /** A variable to hold the administration path */
  -    private String adminPath = null;
  -    
       /** A buffer to hold the current character information until it
           is stored in its respective variable */
       private StringBuffer buffy = null;
  @@ -149,10 +146,6 @@
                       throw new SAXException(
                              "The name attribute in the database element is null.");
                   }
  -                else
  -                {
  -                    throw new SAXException("UNEXPECTED EXCEPTION 1");
  -                }
               }
               else if(attributes == null)
               {
  @@ -186,6 +179,11 @@
                   {
                       databases = new HashSet();
                   }
  +                DatabaseMetaDataImpl db = new DatabaseMetaDataImpl(dbtype);
  +                db.setShortDescription(shortDescription);
  +                db.setDescription(description);
  +                db.setWebUrl(webUrl);
  +                databases.add(db);
               }
               else if(lookForDatabases && qName != null && 
                      qName.equals(SHORT_DESC_QNAME))
  @@ -202,11 +200,6 @@
               {
                   webUrl = buffy.toString();
               }
  -            else if(lookForDatabases && qName != null &&
  -                   qName.equals(ADMIN_PATH_QNAME))
  -            {
  -                adminPath = buffy.toString();
  -            }    
               else if(qName == null)
               {
                   throw new SAXException("qName == null");
  
  
  
  1.9       +6 -17     
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseMetaDataImpl.java
  
  Index: DatabaseMetaDataImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseMetaDataImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DatabaseMetaDataImpl.java 30 Nov 2002 22:05:16 -0000      1.8
  +++ DatabaseMetaDataImpl.java 1 Dec 2002 00:28:38 -0000       1.9
  @@ -106,30 +106,19 @@
       /**
        * The purpose of this method is to create a new database meta data
        * implementation given a name and a type.
  -     * @param newName The name of the new database to create.
        * @param newType The type of the new database to create.
        */
  -    DatabaseMetaDataImpl(String newName, String newType, String newUrl) 
  +    DatabaseMetaDataImpl(String newType) 
              throws Exception
       {
  -        if(newName != null && newType != null && newUrl != null)
  +        if(newType != null)
           {
  -            setName(newName);
               setType(newType);
  -            setUrl(newUrl);
  -        }
  -        else if(newName == null)
  -        {
  -            throw new Exception("newName == null");
           }
           else if(newType == null)
           {
               throw new Exception("newType == null");
           }
  -        else if(newUrl == null)
  -        {
  -            throw new Exception("newUrl == null");
  -        }    
           else
           {
               throw new Exception("UNEXPECTED - Unexpected Exception");
  @@ -157,7 +146,7 @@
        * is represented by this meta data object.
        * @param newval The new name of the database as a string.
        */
  -    private void setName(String newval) throws Exception
  +    public void setName(String newval) throws Exception
       {
           if(newval != null)
           {
  
  
  
  1.4       +26 -11    
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/PeriodicityDbMetaService.java
  
  Index: PeriodicityDbMetaService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/PeriodicityDbMetaService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PeriodicityDbMetaService.java     30 Nov 2002 22:05:16 -0000      1.3
  +++ PeriodicityDbMetaService.java     1 Dec 2002 00:28:38 -0000       1.4
  @@ -77,6 +77,8 @@
   import org.apache.velocity.VelocityContext;
   import org.apache.fulcrum.BaseService;
   import org.apache.fulcrum.InitializationException;
  +import org.apache.log4j.Logger;
  +import org.apache.log4j.LogManager;
   import org.apache.commons.configuration.Configuration;
   import org.apache.commons.periodicity.util.JUnitUtils;
   
  @@ -84,13 +86,13 @@
          implements DbMetaDataService
   {
   
  -    public static final String SERVICE_NAME = "PeriodicityDriverService";
  -    
       public static final String DATABASE_META_DATA_FILE_KEY = 
              "db.meta.data.file";
       
       private Map databases = null;
   
  +    private static Logger logger = null;
  +
       public PeriodicityDbMetaService()
       {
       }
  @@ -161,19 +163,19 @@
       private void addDatabase(DatabaseMetaData newDatabase) 
              throws InitializationException
       {
  -        if(newDatabase != null && newDatabase.getName() != null)
  +        if(newDatabase != null && newDatabase.getType() != null)
           {
               if(databases == null)
               {
                   databases = new HashMap();
               }
  -            databases.put(newDatabase.getName(), newDatabase);
  +            databases.put(newDatabase.getType(), newDatabase);
           }
           else if(newDatabase == null)
           {
               throw new InitializationException("newDatabase == null");
           }
  -        else if(newDatabase.getName() == null)
  +        else if(newDatabase.getType() == null)
           {
               throw new InitializationException("newDatabase.getName() == null");
           }
  @@ -231,10 +233,14 @@
                           dbFile.getAbsolutePath());
                           BufferedInputStream fbin = new BufferedInputStream(fin);
                           InputSource isource = new InputSource(fbin);
  -                        DriverContentHandler dhandler = 
  -                               new DriverContentHandler();
  +                        DatabaseContentHandler dhandler = 
  +                               new DatabaseContentHandler();
                           parser.parse(isource, dhandler);
  -                        Set databases = dhandler.getDrivers();
  +                        if(getLogger() != null)
  +                        {
  +                            getLogger().debug(dhandler.toString());
  +                        }    
  +                        Set databases = dhandler.getDatabases();
                           if(databases != null)
                           {
                               addDatabases(databases);
  @@ -359,5 +365,14 @@
           }
           buffy.append("END - PERIODICITY DB META SERVICE - toString()\n");
           return buffy.toString();
  +    }
  +
  +    private Logger getLogger()
  +    {
  +        if(logger == null)
  +        {
  +            logger = LogManager.getRootLogger();
  +        }
  +        return logger;
       }    
   }    
  
  
  
  1.3       +4 -55     
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseMDNullValueTests.java
  
  Index: DatabaseMDNullValueTests.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseMDNullValueTests.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatabaseMDNullValueTests.java     29 Nov 2002 04:34:01 -0000      1.2
  +++ DatabaseMDNullValueTests.java     1 Dec 2002 00:28:38 -0000       1.3
  @@ -69,18 +69,6 @@
       public static final String TEST_NAME = 
              "DatabaseMetaDataImpl.null_tests";
       
  -    public static final String VALID_DB_NAME = "valid_db_name";
  -
  -    public static final String VALID_DB_TYPE = "valid_db_type";
  -
  -    public static final String VALID_DB_URL = "jdbc:db:db";
  -
  -    public static final String EXPECT_EXCEPTION_WHEN_NEW_NAME_AND_TYPE_NULL =
  -           "An exception is expected when both the name and type are null.";
  -    
  -    public static final String EXPECT_EXCEPTION_WHEN_NEW_TYPE_NULL =
  -           "An exception is expected when the type is null.";
  -    
       public static final String EXPECT_EXCEPTION_WHEN_NEW_NAME_NULL =
              "An exception is expected when the name is null.";
              
  @@ -95,46 +83,7 @@
           try
           {
               DatabaseMetaDataImpl dbmeta = new DatabaseMetaDataImpl(
  -                   null, null, null);
  -            fail(EXPECT_EXCEPTION_WHEN_NEW_NAME_AND_TYPE_NULL);
  -        }
  -        catch(Exception e)
  -        {
  -            if(getLogger() != null)
  -            {
  -                getLogger().info("Expected Exception", e);
  -            }
  -        }
  -        try
  -        {
  -            DatabaseMetaDataImpl dbmeta = new DatabaseMetaDataImpl(
  -                   VALID_DB_NAME, null, null);
  -            fail(EXPECT_EXCEPTION_WHEN_NEW_TYPE_NULL);
  -        }
  -        catch(Exception e)
  -        {
  -            if(getLogger() != null)
  -            {
  -                getLogger().info("Expected Exception", e);
  -            }
  -        }
  -        try
  -        {
  -            DatabaseMetaDataImpl dbmeta = new DatabaseMetaDataImpl(
  -                   null, VALID_DB_TYPE, null);
  -            fail(EXPECT_EXCEPTION_WHEN_NEW_NAME_NULL);
  -        }
  -        catch(Exception e)
  -        {
  -            if(getLogger() != null)
  -            {
  -                getLogger().info("Expected Exception", e);
  -            }
  -        }
  -        try
  -        {
  -            DatabaseMetaDataImpl dbmeta = new DatabaseMetaDataImpl(
  -                   null, null, VALID_DB_URL);
  +                   null);
               fail(EXPECT_EXCEPTION_WHEN_NEW_NAME_NULL);
           }
           catch(Exception e)
  
  
  
  1.3       +6 -7      
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseMDSetGetTests.java
  
  Index: DatabaseMDSetGetTests.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseMDSetGetTests.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatabaseMDSetGetTests.java        29 Nov 2002 04:34:01 -0000      1.2
  +++ DatabaseMDSetGetTests.java        1 Dec 2002 00:28:38 -0000       1.3
  @@ -71,11 +71,9 @@
              "DatabaseMetaDataImpl.set_get_tests";
       
       public static final String VALID_DB_NAME = "valid_db_name";
  -
  +    
       public static final String VALID_DB_TYPE = "valid_db_type";
   
  -    public static final String VALID_DB_URL = "jdbc:db:db";
  -
       public DatabaseMDSetGetTests()
       {
           super(TEST_NAME);
  @@ -86,7 +84,8 @@
           try
           {
               DatabaseMetaDataImpl dbmeta = new DatabaseMetaDataImpl(
  -                   VALID_DB_NAME, VALID_DB_TYPE, VALID_DB_URL);
  +                   VALID_DB_TYPE);
  +            dbmeta.setName(VALID_DB_NAME);       
               String name = dbmeta.getName();
               assertEquals("The name that was set does not match the name " +
                      "that was retrieved.", VALID_DB_NAME, name);
  
  
  
  1.1                  
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseServiceGetInitTest.java
  
  Index: DatabaseServiceGetInitTest.java
  ===================================================================
  
  package org.apache.commons.periodicity.database;
  
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseServiceGetInitTest.java,v
 1.1 2002/12/01 00:28:38 prickett Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/01 00:28:38 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  
  import java.util.Iterator;
  import java.util.Collection;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import org.apache.commons.configuration.BaseConfiguration;
  import org.apache.fulcrum.TurbineServices;
  import org.apache.fulcrum.ServiceManager;
  import org.apache.fulcrum.BaseServiceBroker;
  import org.apache.commons.periodicity.junit.TestWithMavenLogging;
  import org.apache.commons.periodicity.util.JUnitUtils;
  
  
  public class DatabaseServiceGetInitTest extends TestWithMavenLogging
  {
  
      public static final String TEST_NAME = 
             "DriverServiceGetInitTest.getInit()";
             
      public static final String FILE_NAME = "./src/xml/databases.xml";
  
      public static final String PERIODICITY_DRIVER_SERVICE_CLASS_NAME_KEY =
             "services.PeriodicityDbMetaService.classname";
      
      public static final String PERIODICITY_DRIVER_SERVICE_CLASS_NAME =
             "org.apache.commons.periodicity.database.PeriodicityDbMetaService";
  
      public static final String PERIODICITY_DRIVER_SERVICE_NAME =
             "PeriodicityDbMetaService";
      
      public static final String[] DRIVERS = 
             { "mysql.default", "postgresql.default", "oracle.default",
               "axion.default", "cloudscape.default", "hypersonic.default",
               "interbase.default" };
      
      public DatabaseServiceGetInitTest(String name)
      {
          super(name);
      }
  
      protected void runTest()
      {
          if(getLogger() != null)
          {
              getLogger().info("BEGIN DATABASE SERVICE TEST.");
          }    
          try
          {
              ServiceManager turbineServices = 
                     TurbineServices.getInstance();
              if(turbineServices != null)
              {
                  BaseConfiguration turbineConfig = new BaseConfiguration();
                  turbineConfig.addProperty(
                         PERIODICITY_DRIVER_SERVICE_CLASS_NAME_KEY,
                         PERIODICITY_DRIVER_SERVICE_CLASS_NAME);
                  turbineConfig.addProperty(
                         BaseServiceBroker.SERVICE_PREFIX +
                         PERIODICITY_DRIVER_SERVICE_NAME + "." +
                         PeriodicityDbMetaService.DATABASE_META_DATA_FILE_KEY,
                         FILE_NAME);
                  turbineServices.setConfiguration(turbineConfig);       
                  turbineServices.setApplicationRoot(".");
                  turbineServices.init();
                  BaseConfiguration config = new BaseConfiguration();
                  PeriodicityDbMetaService driverService = 
                         (PeriodicityDbMetaService) turbineServices.getService(
                         PERIODICITY_DRIVER_SERVICE_NAME);
                  assertTrue("Service should have been initialized.", 
                         driverService.isInitialized());
                  if(driverService != null && getLogger() != null)
                  {
                      getLogger().info(driverService.toString());
                  }    
                  else
                  {
                      getLogger().info("driverService == null");
                  }    
              }
              else
              {
                  fail("turbineServices == null");
              }    
          }
          catch(Exception e)
          {
              fail(e.getMessage() + "\n" + JUnitUtils.getStackTraceAsString(e));
          }
          if(getLogger() != null)
          {
              getLogger().info("END DATABASE SERVICE TEST");
          }    
      }
  
      public static Test suite()
      {
          return new DriverServiceGetInitTest(TEST_NAME);
      }
  }    
  
  
  
  1.1                  
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseServiceTestSuite.java
  
  Index: DatabaseServiceTestSuite.java
  ===================================================================
  
  package org.apache.commons.periodicity.database;
  
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseServiceTestSuite.java,v
 1.1 2002/12/01 00:28:38 prickett Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/01 00:28:38 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  public class DatabaseServiceTestSuite extends TestSuite
  {
  
      public static Test suite()
      {
          DatabaseServiceTestSuite returnValue = new DatabaseServiceTestSuite();
          returnValue.addTest(new DatabaseServiceGetInitTest(
                 DatabaseServiceGetInitTest.TEST_NAME));
          return returnValue;       
      }
  
  }
  
  
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to