You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2003/07/11 15:02:28 UTC

cvs commit: avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test EntryDescriptorTestCase.java CategoryDescriptorTestCase.java

bloritsch    2003/07/11 06:02:28

  Modified:    meta/api/src/java/org/apache/avalon/meta/info
                        CategoryDescriptor.java
               meta/api/src/test/org/apache/avalon/meta/info/test
                        CategoryDescriptorTestCase.java
  Added:       meta/api/src/test/org/apache/avalon/meta/info/test
                        EntryDescriptorTestCase.java
  Log:
  Make CategoryDescriptorTestCase more in line with the others--taking advantage of the AbstractDescriptorTestCase.  Add the EntryDescriptorTestCase
  
  Revision  Changes    Path
  1.3       +7 -7      avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/CategoryDescriptor.java
  
  Index: CategoryDescriptor.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/CategoryDescriptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CategoryDescriptor.java	10 Jul 2003 21:44:13 -0000	1.2
  +++ CategoryDescriptor.java	11 Jul 2003 13:02:27 -0000	1.3
  @@ -53,13 +53,13 @@
   import java.util.Properties;
   
   /**
  - * A descriptor describing the {@link org.apache.avalon.framework.Logger} 
  - * child instances that the component will create using the 
  - * {@link org.apache.avalon.framework.Logger#getChildLogger}  
  - * method. The name of each category is relative to the component.  For 
  + * A descriptor describing the {@link org.apache.avalon.framework.logger.Logger}
  + * child instances that the component will create using the
  + * {@link org.apache.avalon.framework.logger.Logger#getChildLogger}
  + * method. The name of each category is relative to the component.  For
    * example, a component with an internal logging category named "data"
  - * would aquire a logger for that category using the 
  - * <code>m_logger.getChildLogger( "data" );</code>. The establishment 
  + * would aquire a logger for that category using the
  + * <code>m_logger.getChildLogger( "data" );</code>. The establishment
    * of logging channels and targets for the returned channel is container
    * concern facilities by type-level category declarations.
    *
  
  
  
  1.3       +13 -50    avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/CategoryDescriptorTestCase.java
  
  Index: CategoryDescriptorTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/CategoryDescriptorTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CategoryDescriptorTestCase.java	10 Jul 2003 23:28:28 -0000	1.2
  +++ CategoryDescriptorTestCase.java	11 Jul 2003 13:02:27 -0000	1.3
  @@ -51,6 +51,9 @@
   
   import junit.framework.TestCase;
   import org.apache.avalon.meta.info.CategoryDescriptor;
  +import org.apache.avalon.meta.info.Descriptor;
  +import org.apache.avalon.meta.info.ContextDescriptor;
  +import org.apache.avalon.meta.info.EntryDescriptor;
   
   import java.io.*;
   import java.util.Properties;
  @@ -61,66 +64,26 @@
    * @author <a href="mcconnell.at.apache.org">Stephen McConnell</a>
    * @version CVS $ Revision: 1.1 $
    */
  -public class CategoryDescriptorTestCase extends TestCase
  +public class CategoryDescriptorTestCase extends AbstractDescriptorTestCase
   {
  +    private final String m_name = "name";
  +
       public CategoryDescriptorTestCase( String name )
       {
           super( name );
       }
   
  -    public void testCategory()
  +    protected Descriptor getDescriptor()
       {
  -        String name = "name";
  -
  -        Properties props = new Properties();
  -        String[] names = new String[]{ "aaa", "bbb", "ccc" };
  -        String[] values = new String[]{ "AAA", "BBB", "CCC" };
  -        props.setProperty( "aaa", "AAA" );
  -        props.setProperty( "bbb", "BBB" );
  -        props.setProperty( "ccc", "CCC" );
  -
  -        CategoryDescriptor cat = new CategoryDescriptor( name, props );
  -        testCategory( cat, name, names, values );
  -    }
  -
  -    public void testCategory( 
  -      CategoryDescriptor category, String name, String[] names, String[] values )
  -    {
  -        assertEquals( "name", name, category.getName() );
  -        for( int i=0; i<names.length; i++ )
  -        {
  -            assertEquals( "property (" + i + ")", 
  -              values[i], category.getAttribute( names[i] ) );
  -        }
  +        return new CategoryDescriptor(m_name, getProperties());
       }
   
   
  -    public void testSerialization() throws IOException, ClassNotFoundException
  +    protected void checkDescriptor( Descriptor desc )
       {
  -        File file = new File("name.test");
  -        String name = "name";
  -        Properties props = new Properties();
  -
  -        String[] names = new String[]{ "aaa", "bbb", "ccc" };
  -        String[] values = new String[]{ "AAA", "BBB", "CCC" };
  -        props.setProperty( "aaa", "AAA" );
  -        props.setProperty( "bbb", "BBB" );
  -        props.setProperty( "ccc", "CCC" );
  -
  -        CategoryDescriptor original = new CategoryDescriptor( name, props );
  -        testCategory( original, name, names, values );
  -
  -        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
  -        oos.writeObject(original);
  -        oos.close();
  -
  -        ObjectInputStream ois = new ObjectInputStream( new FileInputStream(file));
  -        CategoryDescriptor serialized = (CategoryDescriptor)ois.readObject();
  -        ois.close();
  -        file.delete();
  -
  -        testCategory( serialized, name, names, values );
  -        assertEquals( original, serialized );
  -        assertEquals( original.hashCode(), serialized.hashCode() );
  +        super.checkDescriptor( desc );
  +        CategoryDescriptor cat = (CategoryDescriptor) desc;
  +
  +        assertEquals( m_name, cat.getName() );
       }
   }
  
  
  
  1.1                  avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/EntryDescriptorTestCase.java
  
  Index: EntryDescriptorTestCase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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/>.
  
  */
  package org.apache.avalon.meta.info.test;
  
  import junit.framework.TestCase;
  import org.apache.avalon.meta.info.EntryDescriptor;
  
  import java.io.*;
  
  /**
   * EntryDescriptorTestCase does XYZ
   *
   * @author <a href="bloritsch.at.apache.org">Berin Loritsch</a>
   * @version CVS $ Revision: 1.1 $
   */
  public class EntryDescriptorTestCase extends TestCase
  {
      private static final String m_key = "key";
      private static final String m_alias = "otherVal";
      private static final String m_type = EntryDescriptor.class.getName();
      private static final boolean m_optional = true;
  
      public EntryDescriptorTestCase( String name )
      {
          super( name );
      }
  
      public void testEntryDescriptor()
      {
          EntryDescriptor entry = new EntryDescriptor(m_key, m_alias, m_type, m_optional);
          checkEntry(entry, m_key, m_alias, m_type, m_optional);
  
          entry = new EntryDescriptor(m_key, m_type);
          checkEntry(entry, m_key, null, m_type, false);
  
          entry = new EntryDescriptor(m_key, m_type, m_optional);
          checkEntry(entry, m_key, null, m_type, m_optional);
  
          try
          {
              new EntryDescriptor(null, m_type);
              fail("Did not throw expected NullPointerException");
          }
          catch(NullPointerException npe)
          {
              // Success!!
          }
  
          try
          {
              new EntryDescriptor( m_key, null );
              fail( "Did not throw expected NullPointerException" );
          }
          catch ( NullPointerException npe )
          {
              // Success!!
          }
      }
  
      private void checkEntry(EntryDescriptor desc, String key, String alias, String type, boolean isOptional)
      {
          assertNotNull( desc );
          assertEquals( key, desc.getKey() );
          assertEquals( alias, desc.getType() );
          assertEquals( type, desc.getAlias() );
          assertEquals( isOptional, desc.isOptional() );
          assertEquals( ! isOptional, desc.isRequired() );
      }
  
      public void testSerialization() throws IOException, ClassNotFoundException
      {
          EntryDescriptor entry = new EntryDescriptor(m_key, m_alias, m_type, m_optional);
          checkEntry(entry, m_key, m_alias, m_type, m_optional);
  
          File file = new File("test.out");
          ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
          oos.writeObject(entry);
          oos.close();
  
          ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
          EntryDescriptor serialized = (EntryDescriptor)ois.readObject();
          ois.close();
          file.delete();
  
          checkEntry(serialized, m_key, m_alias, m_type, m_optional);
  
          assertEquals( entry, serialized );
          assertEquals( entry.hashCode(), serialized.hashCode() );
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org