mschachter    01/06/22 12:04:17

  Modified:    resources build.xml
               resources/src/java/org/apache/commons/resources
                        ConfigurationReader.java FileResourceFactory.java
                        LocalStrings.properties
                        MessageResourcesFactory.java Resource.java
  Added:       resources/src/test/org/apache/commons/resources/tests
                        AllTests.java ConfigurationReaderTest.java
  Log:
   - modified build.xml to add beanutils, digester and crimson.jar to
     test.classpath for running tests
   - modified ConfigurationReader.java so it works
   - modified FileResourceFactory so it works
   - added more message strings
   - added setName(String) to resource interface
   - added basic unit test for ConfigurationReader
  
  Revision  Changes    Path
  1.3       +26 -9     jakarta-commons-sandbox/resources/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/build.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.xml 2001/06/22 01:30:47     1.2
  +++ build.xml 2001/06/22 19:04:04     1.3
  @@ -3,7 +3,7 @@
   
   <!--
           "Resource Facilities" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.2 2001/06/22 01:30:47 mschachter Exp $
  +        $Id: build.xml,v 1.3 2001/06/22 19:04:04 mschachter Exp $
   -->
   
   
  @@ -17,16 +17,22 @@
   
   <!-- ========== External Dependencies ===================================== -->
   
  +  <!-- The home directory for jaxp 1.1 -->
  +  <property name="jaxp.home"               value="/usr/local/jaxp1.1"/>
   
     <!-- The home directory for the Commons collection classes distribution -->
     <property name="commons-collections.home" value="../collections/dist"/>
     
     <!-- The home directory for the Digester package -->
     <property name="commons-digester.home" value="../digester/dist" />
  +  
  +  <!-- The home directory for the BeanUtils package -->
  +  <property name="commons-beanutils.home" value="../beanutils/dist" />
   
     <!-- The directory containing your binary distribution of JUnit,
          version 3.2 or later -->
  -  <property name="junit.home"              value="/usr/local/junit3.5"/>
  +  <property name="junit.home"              value="/usr/local/junit3.5" />
  +  
     
   
   <!-- ========== Derived Values ============================================ -->
  @@ -34,13 +40,20 @@
   
     <!-- The pathname of the collections classes JAR file -->
     <property name="commons-collections.jar" 
value="${commons-collections.home}/commons-collections.jar"/>
  -
  -  <!-- The pathname of the "junit.jar" JAR file -->
  -  <property name="junit.jar"               value="${junit.home}/junit.jar"/>
     
  +  <!-- The pathname of the beanutils JAR file -->
  +  <property name="commons-beanutils.jar" 
value="${commons-beanutils.home}/commons-beanutils.jar"/>
  +  
     <!-- The pathname of the "digester.jar" JAR file -->
     <property name="commons-digester.jar" 
value="${commons-digester.home}/commons-digester.jar" />
  -
  +  
  +  <!-- The pathname of the "junit.jar" JAR file -->
  +  <property name="junit.jar"               value="${junit.home}/junit.jar"/>
  +  
  +  <!-- The pathname of the jaxp parser's JAR file -->
  +  <property name="jaxp.parser.jar" value="${jaxp.home}/crimson.jar" />
  +  
  +  
   
   <!-- ========== Component Declarations ==================================== -->
   
  @@ -102,6 +115,11 @@
       <pathelement location="${build.home}/tests"/>
       <pathelement location="${commons-collections.jar}"/>
       <pathelement location="${junit.jar}"/>
  +    <pathelement location="${jaxp.parser.jar}"/>
  +    <pathelement location="${build.home}/classes"/>
  +    <pathelement location="${commons-collections.jar}"/>
  +    <pathelement location="${commons-digester.jar}"/>
  +    <pathelement location="${commons-beanutils.jar}"/>
     </path>
   
     <!-- Should all tests fail if one does? -->
  @@ -222,13 +240,12 @@
   
    <target name="test.resources">
       <echo message="Running Resources tests ..."/>
  -<!--
  +    
       <java classname="${test.runner}" fork="yes"
           failonerror="${test.failonerror}">
  -      <arg value="org.apache.commons.resources.ResourcesTestCase"/>
  +      <arg value="org.apache.commons.resources.tests.AllTests"/>
         <classpath refid="test.classpath"/>
       </java>
  --->
     </target>
   
   
  
  
  
  1.3       +14 -1     
jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/ConfigurationReader.java
  
  Index: ConfigurationReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/ConfigurationReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConfigurationReader.java  2001/06/22 01:30:48     1.2
  +++ ConfigurationReader.java  2001/06/22 19:04:07     1.3
  @@ -4,6 +4,7 @@
   import java.io.IOException;
   
   import java.util.Map;
  +import java.util.HashMap;
   import java.util.Collection;
   
   import org.xml.sax.Attributes;
  @@ -51,6 +52,10 @@
        * Read the URL "config" and populate the internal resource Map with data
        */
       public void read(InputStream inputStream) throws ResourceException, IOException 
{
  +        //wipe out the old resources
  +        resources = null;
  +        resources = new HashMap();
  +        //parse the config file
           Digester digester = new Digester();
           digester.addRule("resources-config/resources/resource", 
                           new AddResourceRule(digester, this));
  @@ -86,11 +91,12 @@
           //create instance of resource from factory instance
           String factoryClass = attributes.getValue("", "factory");
           String config = attributes.getValue("", "config");
  +        String name = attributes.getValue("", "name");
           Resource resource = null;
           try {
               ResourceFactory factory;
               Class cFactory  = Class.forName(factoryClass);
  -            if (cFactory.isAssignableFrom(ResourceFactory.class)) {
  +            if ((ResourceFactory.class).isAssignableFrom(cFactory)) {
                   factory = (ResourceFactory) cFactory.newInstance();
                   resource = factory.createResource(config);
               }
  @@ -119,6 +125,13 @@
                                               "resources.config.instantiation",
                                               factoryClass), ie);
           }
  +        if (resource == null) {
  +            throw new ResourceException(
  +                ConfigurationReader.messageResources.getMessage(
  +                                            "resources.config.createresource",
  +                                            factoryClass, config));
  +        }
  +        resource.setName(name);
           //push to top of digester stack for property population
           digester.push(resource);
       }
  
  
  
  1.2       +1 -1      
jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/FileResourceFactory.java
  
  Index: FileResourceFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/FileResourceFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileResourceFactory.java  2001/06/22 01:30:48     1.1
  +++ FileResourceFactory.java  2001/06/22 19:04:08     1.2
  @@ -9,7 +9,7 @@
       
    
       public Resource createResource(String config) {
  -        return null;       
  +        return new FileResource();      
       }
       
   }
  
  
  
  1.3       +4 -3      
jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/LocalStrings.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocalStrings.properties   2001/06/22 01:30:48     1.2
  +++ LocalStrings.properties   2001/06/22 19:04:09     1.3
  @@ -1,8 +1,9 @@
   resources.file.ioexception=[FileResource] problem opening file {0}
   resources.file.filenotfound=[FileResource] file {0} not found
   resources.manager.ioexception=[ResourceManager] IOException
  -resources.config.invalidfactory=[ConfigurationReader] factory class is not of type 
org.apache.commons.resources.ResourceFactory, but type {1}
  +resources.config.invalidfactory=[ConfigurationReader] factory class is not of type 
org.apache.commons.resources.ResourceFactory, but type {0}
   resources.config.classnotfound=[ConfigurationReader] class {0} not found
  -resources.config.instantiation=InstantiationException for class {0}
  -resources.config.sax=[ConfigurationReader]SAXException while parsing configuration
  +resources.config.instantiation=[ConfigurationReader] InstantiationException for 
class {0}
  +resources.config.sax=[ConfigurationReader] SAXException while parsing configuration
   resources.config.illegalaccess=[ConfigurationReader] IllegalAccessException
  +resources.config.createresource=[ConfigurationReader] no resource created for 
factory {0} with config String {1}
  
  
  
  1.3       +5 -5      
jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/MessageResourcesFactory.java
  
  Index: MessageResourcesFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/MessageResourcesFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MessageResourcesFactory.java      2001/06/22 01:30:49     1.2
  +++ MessageResourcesFactory.java      2001/06/22 19:04:10     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/MessageResourcesFactory.java,v
 1.2 2001/06/22 01:30:49 mschachter Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/06/22 01:30:49 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/MessageResourcesFactory.java,v
 1.3 2001/06/22 19:04:10 mschachter Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/06/22 19:04:10 $
    *
    * ====================================================================
    * 
  @@ -81,7 +81,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2001/06/22 01:30:49 $
  + * @version $Revision: 1.3 $ $Date: 2001/06/22 19:04:10 $
    */
   
   public abstract class MessageResourcesFactory
  @@ -141,7 +141,7 @@
        * <code>MessageResourcesFactory</code> instances.
        */
       protected static String factoryClass =
  -        "org.apache.common.resources.PropertyMessageResourcesFactory";
  +        "org.apache.commons.resources.PropertyMessageResourcesFactory";
   
       public static String getFactoryClass() {
           return (MessageResourcesFactory.factoryClass);
  
  
  
  1.3       +6 -0      
jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/Resource.java
  
  Index: Resource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/Resource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Resource.java     2001/06/20 21:16:18     1.2
  +++ Resource.java     2001/06/22 19:04:11     1.3
  @@ -47,6 +47,12 @@
       public String getName();
       
       /**
  +     * Set the name of this resource
  +     * @param name A logical String representation of the name of this resource
  +     */
  +    public void setName(String name);
  +    
  +    /**
        * Retrieves content based on the locale and time zone specified.  Note
        * that this method has the potential to cause memory problems for content
        * that is relatively large.
  
  
  
  1.1                  
jakarta-commons-sandbox/resources/src/test/org/apache/commons/resources/tests/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  package org.apache.commons.resources.tests;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  public class AllTests {
      
      public static void main(String args[]) {
          junit.textui.TestRunner.run (suite());      
      }
      
      public static Test suite() {
          TestSuite suite = new TestSuite("Resource Test Package");
          suite.addTest(ConfigurationReaderTest.suite());
          
          return suite;
      }
      
      
      
  }
  
  
  
  
  
  1.1                  
jakarta-commons-sandbox/resources/src/test/org/apache/commons/resources/tests/ConfigurationReaderTest.java
  
  Index: ConfigurationReaderTest.java
  ===================================================================
  package org.apache.commons.resources.tests;
  
  import java.io.IOException;
  import java.io.InputStream;
  
  import java.util.Map;
  import java.util.Collection;
  
  import org.xml.sax.SAXException;
  
  import org.apache.commons.resources.*;
  
  import junit.framework.*;
  
  public class ConfigurationReaderTest extends TestCase {
   
      public static String RESOURCE_TEST_FILE = 
                                  
"/org/apache/commons/resources/tests/config-test.xml";
      
      protected ConfigurationReader configReader;
      protected InputStream inputStream;
      
      public ConfigurationReaderTest(String test) {
          super(test);
      }
      
      public static void main(String args[]) {
          junit.textui.TestRunner.run(ConfigurationReaderTest.class);
      }
      
      protected void setUp() {
          inputStream = null;
          configReader = null;
          inputStream = this.getClass().getResourceAsStream(RESOURCE_TEST_FILE);
          configReader = new ConfigurationReader();
      }
      
      /**
       * Test the parsing of the config reader
       */
      public void testParse() throws ResourceException, IOException {
         configReader.read(inputStream);
      }
      
      /**
       * Test the getResourceMap() method and it's results, they should be
       * consistent with the resources delcared in
       * /org/apache/commons/resources/test/config-test.xml.
       */
      public void testGetResourceMap() throws ResourceException, IOException {
          configReader.read(inputStream);        
          Map resourceMap = configReader.getResourceMap();
          
          Resource fileResource = (Resource) resourceMap.get("file");
          assertNotNull(fileResource);
          assertEquals(fileResource.getClass().getName(),
                                          "org.apache.commons.resources.FileResource");
          
          Resource messageResource = (Resource) resourceMap.get("message");
          assertNotNull(messageResource);
          assertEquals(messageResource.getClass().getName(),
                                          
"org.apache.commons.resources.PropertyMessageResources");
          String config = ((MessageResources) messageResource).getConfig();
          assertEquals(config, "org.apache.commons.resources.tests.ExampleStrings");
      }   
      
      public static Test suite() {
          return new TestSuite(ConfigurationReaderTest.class);       
      }
  }
  
  
  

Reply via email to