dobbs       02/03/13 07:43:04

  Modified:    src/java/org/apache/stratum/component ComponentLoader.java
               src/test/org/apache/stratum/component
                        TestComponentLoader.java
  Removed:     src/java/org/apache/stratum/component
                        ComponentDescriptor.java
  Log:
  Backing out the refactoring from yesterday because it cannot help make
  the mock object more conventional.  And if it doesn't help with the
  testing, then it doesn't justify maintaining an addional class.
  
  Little more info: With a conventional mock object, you need to have
  the mock object before and after you call the method being tested.
  That doesn't work when the method being tested is loading the class.
  So I'll have to stick with the unconventional mock object I'm
  currently using.
  
  Revision  Changes    Path
  1.3       +21 -19    
jakarta-turbine-stratum/src/java/org/apache/stratum/component/ComponentLoader.java
  
  Index: ComponentLoader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/component/ComponentLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ComponentLoader.java      12 Mar 2002 20:19:59 -0000      1.2
  +++ ComponentLoader.java      13 Mar 2002 15:43:04 -0000      1.3
  @@ -61,12 +61,11 @@
   import org.apache.stratum.configuration.PropertiesConfiguration;
   import org.apache.stratum.lifecycle.Configurable;
   import org.apache.stratum.lifecycle.Initializable;
  -import org.apache.stratum.component.ComponentDescriptor;
   
   /**
    * @author <a href="mailto:eric NOSPAM dobbse.net">Eric Dobbs</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Poeschl</a>
  - * @version $Id: ComponentLoader.java,v 1.2 2002/03/12 20:19:59 dobbs Exp $
  + * @version $Id: ComponentLoader.java,v 1.3 2002/03/13 15:43:04 dobbs Exp $
    */
   public class ComponentLoader
   {
  @@ -91,11 +90,13 @@
       }
   
       /**
  -     * <p>Load all the components listed in the ComponentLoader's configuration.
  -     * Log any errors, but throw no exceptions if components cannot be loaded.</p>
  +     * <p>Load all the components listed in the ComponentLoader's
  +     * configuration.  Log any errors, but throw no exceptions if
  +     * components cannot be loaded.</p>
        *
        * Configuration notes:<br/>
  -     * Components are identified in the properties file as follows:<br/>
  +     * Components are identified in the properties file as
  +     * follows:<br/>
        * <code>
        * component.name=NAME
        * component.NAME.classname = com.mycompany.components.SomeComponent
  @@ -117,9 +118,7 @@
               log.info("loading component: name=" + componentName + " class="
                       + componentClassName + " config=" + componentConfig);
   
  -            ComponentDescriptor cd = new ComponentDescriptor(componentClassName,
  -                                                             componentConfig);
  -            loadComponent(cd);
  +            loadComponent(componentClassName,componentConfig);
           }
       }
   
  @@ -127,41 +126,43 @@
        * load the given component, configure it with the given config
        * file, and initialize it.
        *
  -     * @param cd the ComponentDescriptor of the component to load
  +     * @param className the String class name of the component to load
  +     * @param configFile the String path name of the component's
  +     * config file
        */
  -    public void loadComponent(ComponentDescriptor cd)
  +    public void loadComponent(String className, String configFile)
       {
           if (log.isDebugEnabled())
           {
  -            log.debug("attempting to load '" + cd.getClassname()
  -                      + "' with the config file '" + cd.getConfigfile());
  +            log.debug("attempting to load '" + className
  +                      + "' with the config file '" + configFile + "'.");
           }
           
           try
           {
  -            Object component = cd.newInstance();
  +            Object component = Class.forName(className).newInstance();
   
               // configure component using the given config file
               ((Configurable) component)
  -                .configure(new PropertiesConfiguration(cd.getConfigfile()));
  +                .configure(new PropertiesConfiguration(configFile));
   
               // initialize component
               ((Initializable) component).initialize();
   
               if (log.isDebugEnabled())
               {
  -                log.debug("good news! " + cd.getClassname()
  +                log.debug("good news! " + className
                             + " successfully configured and initialized");
               }
           }
           catch (IOException ioe)
           {
  -            log.error(cd.getClassname() + " could not be configured with file '"
  -                      + cd.getConfigfile() + "'.", ioe);
  +            log.error(className + " could not be configured with file '"
  +                      + configFile + "'.", ioe);
           }
           catch (Exception e)
           {
  -            log.error(cd.getClassname() + " could not be initialized!", e);
  +            log.error(className + " could not be initialized!", e);
           }
       }
   
  @@ -176,7 +177,8 @@
        */
       private String getComponentClassname(String name)
       {
  -        return configuration.getString(COMPONENT + '.' + name + '.' + CLASSNAME);
  +        return configuration.getString(COMPONENT + '.' + name
  +                                       + '.' + CLASSNAME);
       }
   
       /**
  
  
  
  1.4       +3 -12     
jakarta-turbine-stratum/src/test/org/apache/stratum/component/TestComponentLoader.java
  
  Index: TestComponentLoader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/test/org/apache/stratum/component/TestComponentLoader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestComponentLoader.java  13 Mar 2002 00:47:34 -0000      1.3
  +++ TestComponentLoader.java  13 Mar 2002 15:43:04 -0000      1.4
  @@ -62,7 +62,6 @@
   import org.apache.stratum.configuration.Configuration;
   import org.apache.stratum.configuration.PropertiesConfiguration;
   import org.apache.stratum.component.ComponentLoader;
  -import org.apache.stratum.component.ComponentDescriptor;
   
   public class TestComponentLoader extends TestCase
   {
  @@ -105,22 +104,14 @@
           String badClassName   = "org.apache.stratum.component.MissingMockComponent";
           String badConfigFile  = "bin/classes/MissingTestComponentLoader.properties";
   
  -        ComponentDescriptor goodCd = new ComponentDescriptor(goodClassName,
  -                                                             goodConfigFile);
  -        ComponentDescriptor badCd1 = new ComponentDescriptor(badClassName,
  -                                                             goodConfigFile);
  -        ComponentDescriptor badCd2 = new ComponentDescriptor(goodClassName,
  -                                                             badConfigFile);
  -        
  -
           // test loading with a mock component
  -        cl.loadComponent(goodCd);
  +        cl.loadComponent(goodClassName,goodConfigFile);
   
           // test that loadComponent() catches the IOException
  -        cl.loadComponent(badCd1);
  +        cl.loadComponent(badClassName,goodConfigFile);
   
           // test that loadComponent() catches the ClassNotFoundException
  -        cl.loadComponent(badCd2);
  +        cl.loadComponent(goodClassName,badConfigFile);
       }
   
       public void testLoad()
  
  
  

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

Reply via email to