You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by pr...@apache.org on 2002/12/01 22:46:23 UTC

cvs commit: jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database DatabaseServiceGetUrlTest.java DatabaseServiceTestSuite.java

prickett    2002/12/01 13:46:23

  Modified:    periodicity/src/plugins-build/database project.xml
               periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
                        DatabaseMetaData.java DatabaseMetaDataImpl.java
                        DriverMetaDataImpl.java
               periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database
                        DatabaseServiceTestSuite.java
  Added:       periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database
                        DatabaseServiceGetUrlTest.java
  Log:
  Added a dependency on commons-collections-2.0
  Added setName to DatabaseMetaData
  DatabaseMetaDataImpl implements Cloneable
  Removed the period form the Database Velocity context keys
  Added logging to DatabaseMetaDataImpl
  Fixed bug in getDatabasePort
  Initialize Velocity in a static code block in DatabaseMetaDataImpl
  Added DatabaseServiceGetUrlTest.java
  
  Revision  Changes    Path
  1.12      +4 -0      jakarta-commons-sandbox/periodicity/src/plugins-build/database/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/project.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- project.xml	24 Oct 2002 06:17:20 -0000	1.11
  +++ project.xml	1 Dec 2002 21:46:23 -0000	1.12
  @@ -58,6 +58,10 @@
         <version>1.0-dev</version>
       </dependency>  
       <dependency>
  +      <id>commons-collections</id>
  +      <version>2.0</version>
  +    </dependency>  
  +    <dependency>
         <id>log4j</id>
         <version>1.2.6</version>
       </dependency>  
  
  
  
  1.5       +10 -3     jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseMetaData.java
  
  Index: DatabaseMetaData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseMetaData.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DatabaseMetaData.java	30 Nov 2002 19:26:02 -0000	1.4
  +++ DatabaseMetaData.java	1 Dec 2002 21:46:23 -0000	1.5
  @@ -75,6 +75,13 @@
       public String getName();
   
       /**
  +     * The purpose of this method is to set the name of this database.
  +     * @param newval The new value for this database as a string.
  +     */
  +    public void setName(String newval) throws Exception; 
  +    
  +
  +    /**
        * The purpose of this method is to return the type of the database.
        * @return The type of the database as a string.
        */
  
  
  
  1.12      +43 -10    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DatabaseMetaDataImpl.java	1 Dec 2002 03:38:59 -0000	1.11
  +++ DatabaseMetaDataImpl.java	1 Dec 2002 21:46:23 -0000	1.12
  @@ -64,9 +64,11 @@
   import java.io.StringWriter;
   import org.apache.velocity.VelocityContext;
   import org.apache.velocity.app.Velocity;
  +import org.apache.log4j.Logger;
  +import org.apache.log4j.LogManager;
   
   
  -public class DatabaseMetaDataImpl implements DatabaseMetaData
  +public class DatabaseMetaDataImpl implements DatabaseMetaData, Cloneable
   {
   
       public static final String DEFAULT_DRIVER_NAME_EXTENSION = ".default";
  @@ -75,19 +77,19 @@
       public static final String SCHEME_KEY = "scheme";
   
       /** The key for the database name in the velocity context */
  -    public static final String DATABASE_NAME_KEY = "database.name";
  +    public static final String DATABASE_NAME_KEY = "databaseName";
   
       /** The key for the database port in the velocity context */
  -    public static final String DATABASE_PORT_KEY = "database.port";
  +    public static final String DATABASE_PORT_KEY = "databasePort";
   
       /** The key for the administration path in the velocity context */
  -    public static final String ADMIN_PATH_KEY = "admin.path";
  +    public static final String ADMIN_PATH_KEY = "adminPath";
   
       /** The key for the database path in the velocity context */
  -    public static final String DATABASE_PATH_KEY = "database.path";
  +    public static final String DATABASE_PATH_KEY = "databasePath";
       
       /** The key for the database host in the velocity context */
  -    public static final String DATABASE_HOST_KEY = "database.host";
  +    public static final String DATABASE_HOST_KEY = "databaseHost";
   
       /** A variable to hold the name of the database */
       private String name = null;
  @@ -131,6 +133,8 @@
       /** A variable to hold the default port for the database */
       private int defaultPort = -1;
   
  +    private static Logger logger = null;
  +
       /**
        * The purpose of this method is to create a new database meta data
        * implementation given a name and a type.
  @@ -223,6 +227,10 @@
        */
       public String getUrl() throws Exception
       {
  +        if(getLogger() != null)
  +        {
  +            getLogger().debug(toString());
  +        }    
           VelocityContext context = buildContext();
           if(context != null)
           {
  @@ -417,7 +425,7 @@
        */
       public int getDatabasePort()
       {
  -        if(defaultPort != -1)
  +        if(databasePort != -1)
           {
               return databasePort;
           }
  @@ -621,6 +629,31 @@
               throw new Exception("UNEXPECTED EXCEPTION");
           }    
       }    
  +
  +    static
  +    {
  +        try
  +        {
  +            Velocity.init();
  +        }
  +        catch(Exception e)
  +        {
  +            if(getLogger() != null)
  +            {
  +                getLogger().info(e);
  +            }
  +        }
  +    }
  +
  +    public static Logger getLogger()
  +    {
  +        if(logger == null)
  +        {
  +            logger = LogManager.getRootLogger();
  +        }
  +        return logger;
  +    }    
  +    
   
       public String toString()
       {
  
  
  
  1.13      +4 -4      jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaDataImpl.java
  
  Index: DriverMetaDataImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaDataImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DriverMetaDataImpl.java	30 Nov 2002 22:05:16 -0000	1.12
  +++ DriverMetaDataImpl.java	1 Dec 2002 21:46:23 -0000	1.13
  @@ -560,7 +560,7 @@
           return buffy.toString();
       }    
   
  -    private Logger getLogger()
  +    private static Logger getLogger()
       {
           if(logger == null)
           {
  
  
  
  1.2       +4 -2      jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseServiceTestSuite.java
  
  Index: DatabaseServiceTestSuite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseServiceTestSuite.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DatabaseServiceTestSuite.java	1 Dec 2002 00:28:38 -0000	1.1
  +++ DatabaseServiceTestSuite.java	1 Dec 2002 21:46:23 -0000	1.2
  @@ -73,6 +73,8 @@
           DatabaseServiceTestSuite returnValue = new DatabaseServiceTestSuite();
           returnValue.addTest(new DatabaseServiceGetInitTest(
                  DatabaseServiceGetInitTest.TEST_NAME));
  +        returnValue.addTest(new DatabaseServiceGetUrlTest(
  +               DatabaseServiceGetUrlTest.TEST_NAME));
           return returnValue;       
       }
   
  
  
  
  1.1                  jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseServiceGetUrlTest.java
  
  Index: DatabaseServiceGetUrlTest.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/DatabaseServiceGetUrlTest.java,v 1.1 2002/12/01 21:46:23 prickett Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/01 21:46:23 $
   *
   * ====================================================================
   * 
   * 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 apache@apache.org.
   *
   * 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 DatabaseServiceGetUrlTest 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.PeriodicityDriverService.classname";
      
      public static final String PERIODICITY_DRIVER_SERVICE_CLASS_NAME =
             "org.apache.commons.periodicity.database.PeriodicityDriverService";
  
      public static final String PERIODICITY_DRIVER_SERVICE_NAME =
             "PeriodicityDriverService";
      
      public static final String PERIODICITY_DATABASE_SERVICE_CLASS_NAME_KEY =
             "services.PeriodicityDbMetaService.classname";
      
      public static final String PERIODICITY_DATABASE_SERVICE_CLASS_NAME =
             "org.apache.commons.periodicity.database.PeriodicityDbMetaService";
  
      public static final String PERIODICITY_DATABASE_SERVICE_NAME =
             "PeriodicityDbMetaService";
             
      public static final String[] DRIVERS = 
             { "mysql.default", "postgresql.default", "oracle.default",
               "axion.default", "cloudscape.default", "hypersonic.default",
               "interbase.default" };
      
      public DatabaseServiceGetUrlTest(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);
                  turbineConfig.addProperty(
                         PERIODICITY_DATABASE_SERVICE_CLASS_NAME_KEY,
                         PERIODICITY_DATABASE_SERVICE_CLASS_NAME);
                  turbineConfig.addProperty(
                         BaseServiceBroker.SERVICE_PREFIX +
                         PERIODICITY_DATABASE_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_DATABASE_SERVICE_NAME);
                  assertTrue("Service should have been initialized.", 
                         driverService.isInitialized());
                  if(driverService != null && getLogger() != null)
                  {
                      getLogger().info(driverService.toString());
                  }    
                  else
                  {
                      getLogger().info("driverService == null");
                  }    
                  testGetUrl(driverService);
              }
              else
              {
                  fail("turbineServices == null");
              }    
          }
          catch(Exception e)
          {
              fail(e.getMessage() + "\n" + JUnitUtils.getStackTraceAsString(e));
          }
          if(getLogger() != null)
          {
              getLogger().info("END DATABASE SERVICE TEST");
          }    
      }
  
      public void testGetUrl(PeriodicityDbMetaService dbmetaService)
             throws Exception
      {
          if(dbmetaService != null)
          {
              DatabaseMetaData dbmeta = 
                     dbmetaService.getMetaData("mysql");
              if(dbmeta != null)
              {
                  dbmeta.setDatabaseHost("db.apache.org");
                  dbmeta.setName("periodicity");
                  assertEquals("jdbc:mysql://db.apache.org/periodicity",
                         dbmeta.getUrl());
              }
              else
              {
                  fail("dbmeta == null");
              }
              dbmeta =
                     dbmetaService.getMetaData("postgresql");
              if(dbmeta != null)
              {
                  dbmeta.setDatabaseHost("postgre.apache.org");
                  dbmeta.setName("postPeriodicity");
                  dbmeta.setDatabasePort(5432);
                  assertEquals(
                         "jdbc:postgresql://postgre.apache.org:5432/" + 
                         "postPeriodicity", dbmeta.getUrl());
              }
              dbmeta = dbmetaService.getMetaData("axion");
              if(dbmeta != null)
              {
                  dbmeta.setDatabasePath("/usr/local/axion/db");
                  dbmeta.setName("axionPeriodicity");
                  assertEquals(
                         "jdbc:axiondb:/usr/local/axion/db/axionPeriodicity",
                         dbmeta.getUrl());
              }           
          }
          else
          {
              fail("dbMetaService == null");
          }
      }    
                         
  
      public static Test suite()
      {
          return new DriverServiceGetInitTest(TEST_NAME);
      }
  }    
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>