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/10 22:30:51 UTC

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

bloritsch    2003/07/10 13:30:51

  Modified:    meta/api/src/java/org/apache/avalon/meta/info
                        EntryDescriptor.java
               meta/api/src/test/org/apache/avalon/meta/info/test
                        AbstractDescriptorTestCase.java
  Added:       meta/api/src/test/org/apache/avalon/meta/info/test
                        ContextDescriptorTestCase.java
  Log:
  Add testcase for ContextDescriptor, and provide some fixes for the EntryDescriptor.  uncovered issue with merging entries.
  
  Revision  Changes    Path
  1.2       +32 -2     avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/EntryDescriptor.java
  
  Index: EntryDescriptor.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/EntryDescriptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EntryDescriptor.java	10 Jul 2003 16:00:05 -0000	1.1
  +++ EntryDescriptor.java	10 Jul 2003 20:30:51 -0000	1.2
  @@ -103,7 +103,6 @@
        * Construct an Entry.
        * @param key the context entry key
        * @param type the classname of the context entry
  -     * @param alias an alternative key used by the component to reference the key
        * @param optional TRUE if this is an optional entry
        * @exception NullPointerException if the key or type value are null
        */
  @@ -191,5 +190,36 @@
       public boolean isRequired()
       {
           return !isOptional();
  +    }
  +
  +    public boolean equals(Object other)
  +    {
  +        boolean isEqual = other instanceof EntryDescriptor;
  +
  +        if (isEqual)
  +        {
  +            EntryDescriptor entry = (EntryDescriptor)other;
  +
  +            isEqual = isEqual && m_key.equals( entry.m_key );
  +            isEqual = isEqual && m_type.equals( entry.m_type );
  +            isEqual = isEqual && m_optional == entry.m_optional;
  +
  +            isEqual = isEqual && (m_alias == null) ?
  +                    entry.m_alias == null : m_alias.equals( entry.m_alias );
  +        }
  +
  +        return isEqual;
  +    }
  +
  +    public int hashCode()
  +    {
  +        int hash = m_key.hashCode();
  +        hash >>>= 13;
  +        hash ^= (null != m_alias) ? m_alias.hashCode() : 0;
  +        hash >>>= 13;
  +        hash ^= m_type.hashCode();
  +        hash >>>= (m_optional) ? 1 : 3;
  +
  +        return hash;
       }
   }
  
  
  
  1.2       +1 -0      avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/AbstractDescriptorTestCase.java
  
  Index: AbstractDescriptorTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/AbstractDescriptorTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractDescriptorTestCase.java	10 Jul 2003 19:48:57 -0000	1.1
  +++ AbstractDescriptorTestCase.java	10 Jul 2003 20:30:51 -0000	1.2
  @@ -118,6 +118,7 @@
           ObjectInputStream ois = new ObjectInputStream( new FileInputStream( file ) );
           Descriptor serialized = (Descriptor)ois.readObject();
           ois.close();
  +        file.delete();
   
           assertTrue( desc != serialized ); // Ensure this is not the same instance
           checkDescriptor( serialized );
  
  
  
  1.1                  avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/ContextDescriptorTestCase.java
  
  Index: ContextDescriptorTestCase.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.Descriptor;
  import org.apache.avalon.meta.info.ContextDescriptor;
  import org.apache.avalon.meta.info.ReferenceDescriptor;
  import org.apache.avalon.meta.info.EntryDescriptor;
  import org.apache.avalon.framework.Version;
  
  /**
   * ContextDescriptorTestCase does XYZ
   *
   * @author <a href="bloritsch.at.apache.org">Berin Loritsch</a>
   * @version CVS $ Revision: 1.1 $
   */
  public class ContextDescriptorTestCase extends AbstractDescriptorTestCase
  {
      private ReferenceDescriptor m_reference;
      private EntryDescriptor[] m_entries;
  
      public ContextDescriptorTestCase( String name )
      {
          super( name );
      }
  
      protected Descriptor getDescriptor()
      {
          return new ContextDescriptor(m_reference, m_entries, getProperties() );
      }
  
      protected void checkDescriptor( Descriptor desc )
      {
          super.checkDescriptor( desc );
          ContextDescriptor ctxd = (ContextDescriptor) desc;
  
          assertEquals( m_reference, ctxd.getReference() );
          assertEquals( m_entries.length, ctxd.getEntries().length );
  
          EntryDescriptor[] entries = ctxd.getEntries();
  
          for (int i = 0; i < m_entries.length; i++)
          {
              assertEquals( m_entries[i], entries[i]);
              assertEquals( m_entries[i], ctxd.getEntry(m_entries[i].getKey()));
          }
      }
  
      public void testJoin()
      {
          ContextDescriptor desc = (ContextDescriptor)getDescriptor();
          EntryDescriptor[] good = new EntryDescriptor[] {
              new EntryDescriptor( "key", String.class.getName() ),
              new EntryDescriptor( "no conflict", String.class.getName() )
          };
          EntryDescriptor[] bad = new EntryDescriptor[] {
              new EntryDescriptor("key", Integer.class.getName())
          };
  
          checkDescriptor( desc );
          desc.merge(good);
          checkDescriptor( desc );
  
          assertEquals( m_entries[0], desc.getEntry( m_entries[0].getKey() ) );
          assertEquals( good[0], desc.getEntry( good[0].getKey() ) );
          assertEquals( good[1], desc.getEntry( good[1].getKey() ) );
  
          try
          {
              desc.merge(bad);
              fail("Did not throw expected IllegalArgumentException");
          }
          catch(IllegalArgumentException iae)
          {
              // Success!!
          }
      }
  
      public void setUp()
      {
          m_reference = new ReferenceDescriptor(ContextDescriptorTestCase.class.getName(), new Version(1,0,0) );
          m_entries = new EntryDescriptor[] {
              new EntryDescriptor("key", String.class.getName())
          };
      }
  }
  
  

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