avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test VerifierTestCase.java config1.xml config10.xml config11.xml config12.xml config13.xml config2.xml config3.xml config4.xml config5.xml config6.xml config7.xml config8.xml config9.xml
Date Sat, 07 Sep 2002 05:48:02 GMT
donaldp     2002/09/06 22:48:02

  Modified:    loader/src/java/org/apache/excalibur/loader/verifier
                        ClassLoaderVerifier.java
               loader/src/test/org/apache/excalibur/loader/builder/test
                        ReaderTestCase.java
               loader/src/test/org/apache/excalibur/loader/test
                        LoaderTestSuite.java
  Added:       loader/src/test/org/apache/excalibur/loader/builder/test
                        config2.xml config3.xml config4.xml
               loader/src/test/org/apache/excalibur/loader/test
                        AbstractLoaderTestCase.java
               loader/src/test/org/apache/excalibur/loader/verifier/test
                        VerifierTestCase.java config1.xml config10.xml
                        config11.xml config12.xml config13.xml config2.xml
                        config3.xml config4.xml config5.xml config6.xml
                        config7.xml config8.xml config9.xml
  Log:
  Add in some unit tests for verification process.
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/loader/verifier/ClassLoaderVerifier.java
  
  Index: ClassLoaderVerifier.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/loader/src/java/org/apache/excalibur/loader/verifier/ClassLoaderVerifier.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassLoaderVerifier.java	1 Sep 2002 05:54:59 -0000	1.1
  +++ ClassLoaderVerifier.java	7 Sep 2002 05:48:01 -0000	1.2
  @@ -126,7 +126,7 @@
           {
               final ClassLoaderDef classLoader = classLoaders[ i ];
               final String parent = classLoader.getParent();
  -            if( isLoaderDefined( parent, set ) )
  +            if( !isLoaderDefined( parent, set ) )
               {
                   final String message =
                       REZ.getString( "invalid-parent.error",
  
  
  
  1.6       +48 -44    jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/builder/test/ReaderTestCase.java
  
  Index: ReaderTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/builder/test/ReaderTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ReaderTestCase.java	7 Sep 2002 01:58:36 -0000	1.5
  +++ ReaderTestCase.java	7 Sep 2002 05:48:01 -0000	1.6
  @@ -7,12 +7,9 @@
    */
   package org.apache.excalibur.loader.builder.test;
   
  -import java.io.InputStream;
  -import junit.framework.TestCase;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.excalibur.loader.builder.ClassLoaderSetBuilder;
   import org.apache.excalibur.loader.metadata.ClassLoaderSetDef;
  +import org.apache.excalibur.loader.test.AbstractLoaderTestCase;
   
   /**
    * TestCase for {@link ClassLoaderSetBuilder}.
  @@ -20,55 +17,18 @@
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
    */
   public class ReaderTestCase
  -    extends TestCase
  +    extends AbstractLoaderTestCase
   {
  -    private static final String[] BASE_PREDEFINED =
  -        new String[]{"*system*"};
  -
       public ReaderTestCase( final String name )
       {
           super( name );
       }
   
  -    private ClassLoaderSetDef build( final InputStream stream,
  -                                     final String[] predefined )
  -        throws Exception
  -    {
  -        try
  -        {
  -            final ClassLoaderSetBuilder builder = new ClassLoaderSetBuilder();
  -            final Configuration config = load( stream );
  -            return builder.build( config, predefined );
  -        }
  -        catch( final Exception e )
  -        {
  -            fail( "Error building ClassLoaderSet: " + e );
  -            return null;
  -        }
  -    }
  -
  -    private Configuration load( final InputStream stream )
  -        throws Exception
  -    {
  -        final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  -        return builder.build( stream );
  -    }
  -
  -    private ClassLoaderSetDef build( final String resource )
  -        throws Exception
  -    {
  -        final InputStream stream = getClass().getResourceAsStream( resource );
  -        if( null == stream )
  -        {
  -            fail( "Missing resource " + resource );
  -        }
  -        return build( stream, BASE_PREDEFINED );
  -    }
  -
       public void testConfig1()
           throws Exception
       {
  -        final ClassLoaderSetDef defs = build( "config1.xml" );
  +        final ClassLoaderSetDef defs =
  +            buildFromResource( "config1.xml" );
   
           assertEquals( "ClassLoader Default",
                         "join2",
  @@ -163,6 +123,50 @@
           assertEquals( "Join join2.refs[1] Name",
                         defs.getJoin( "join2" ).getClassloaders()[ 1 ],
                         "cl2" );
  +    }
  +
  +    public void testConfig2()
  +        throws Exception
  +    {
  +        try
  +        {
  +            buildFromResource( "config2.xml" );
  +        }
  +        catch( final Throwable t )
  +        {
  +            return;
  +        }
  +        fail( "Should have failed as loaded a " +
  +              "configuration with no default set" );
  +    }
   
  +    public void testConfig3()
  +        throws Exception
  +    {
  +        try
  +        {
  +            buildFromResource( "config3.xml" );
  +        }
  +        catch( final Throwable t )
  +        {
  +            return;
  +        }
  +        fail( "Should have failed as loaded a " +
  +              "configuration with no version set" );
  +    }
  +
  +    public void testConfig4()
  +        throws Exception
  +    {
  +        try
  +        {
  +            buildFromResource( "config4.xml" );
  +        }
  +        catch( final Throwable t )
  +        {
  +            return;
  +        }
  +        fail( "Should have failed as loaded a " +
  +              "configuration with bad version" );
       }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/builder/test/config2.xml
  
  Index: config2.xml
  ===================================================================
  <classloaders version="1.0">
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/builder/test/config3.xml
  
  Index: config3.xml
  ===================================================================
  <classloaders default="*system*">
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/builder/test/config4.xml
  
  Index: config4.xml
  ===================================================================
  <classloaders default="*system*" version="1.2">
  
  </classloaders>
  
  
  1.3       +2 -0      jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/test/LoaderTestSuite.java
  
  Index: LoaderTestSuite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/test/LoaderTestSuite.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LoaderTestSuite.java	7 Sep 2002 01:42:10 -0000	1.2
  +++ LoaderTestSuite.java	7 Sep 2002 05:48:01 -0000	1.3
  @@ -10,6 +10,7 @@
   import junit.framework.Test;
   import junit.framework.TestSuite;
   import org.apache.excalibur.loader.builder.test.ReaderTestCase;
  +import org.apache.excalibur.loader.verifier.test.VerifierTestCase;
   
   /**
    * A basic test suite that tests all the Loader package.
  @@ -20,6 +21,7 @@
       {
           final TestSuite suite = new TestSuite( "Loader Utilities" );
           suite.addTest( new TestSuite( ReaderTestCase.class ) );
  +        suite.addTest( new TestSuite( VerifierTestCase.class ) );
           return suite;
       }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/test/AbstractLoaderTestCase.java
  
  Index: AbstractLoaderTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.loader.test;
  
  import java.io.InputStream;
  import junit.framework.TestCase;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.excalibur.loader.builder.ClassLoaderSetBuilder;
  import org.apache.excalibur.loader.metadata.ClassLoaderSetDef;
  
  /**
   *
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/09/07 05:48:01 $
   */
  public class AbstractLoaderTestCase extends TestCase
  {
      private static final String[] BASE_PREDEFINED =
          new String[]{"*system*"};
  
      protected ClassLoaderSetDef buildFromStream( final InputStream stream,
                                                   final String[] predefined )
          throws Exception
      {
          try
          {
              final ClassLoaderSetBuilder builder = new ClassLoaderSetBuilder();
              final Configuration config = load( stream );
              return builder.build( config, predefined );
          }
          catch( final Exception e )
          {
              fail( "Error building ClassLoaderSet: " + e );
              return null;
          }
      }
  
      protected Configuration load( final InputStream stream )
          throws Exception
      {
          final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
          return builder.build( stream );
      }
  
      protected ClassLoaderSetDef buildFromResource( final String resource )
          throws Exception
      {
          return buildFromResource( resource, BASE_PREDEFINED );
      }
  
      protected ClassLoaderSetDef buildFromResource( final String resource,
                                                     final String[] predefines )
          throws Exception
      {
          final InputStream stream = getClass().getResourceAsStream( resource );
          if( null == stream )
          {
              fail( "Missing resource " + resource );
          }
          return buildFromStream( stream, predefines );
      }
  
      public AbstractLoaderTestCase( String name )
      {
          super( name );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/VerifierTestCase.java
  
  Index: VerifierTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.loader.verifier.test;
  
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.excalibur.loader.builder.ClassLoaderSetBuilder;
  import org.apache.excalibur.loader.metadata.ClassLoaderSetDef;
  import org.apache.excalibur.loader.test.AbstractLoaderTestCase;
  import org.apache.excalibur.loader.verifier.ClassLoaderVerifier;
  
  /**
   * TestCase for {@link ClassLoaderSetBuilder}.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  public class VerifierTestCase
      extends AbstractLoaderTestCase
  {
      public VerifierTestCase( final String name )
      {
          super( name );
      }
  
      public void testConfig1()
          throws Exception
      {
          try
          {
              verifyResource( "config1.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as specified " +
                "bad name for join" );
      }
  
      public void testConfig2()
          throws Exception
      {
          try
          {
              verifyResource( "config2.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as specified " +
                "bad name for classloader" );
      }
  
      public void testConfig3()
          throws Exception
      {
          try
          {
              verifyResource( "config3.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as specified " +
                "bad parent for classloader" );
      }
  
      public void testConfig4()
          throws Exception
      {
          try
          {
              verifyResource( "config4.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as specified " +
                "non existing ClassLoader in Join " +
                "classloader-ref" );
      }
  
      public void testConfig5()
          throws Exception
      {
          try
          {
              verifyResource( "config5.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as specified " +
                "default classloader does not exist." );
      }
  
      public void testConfig6()
          throws Exception
      {
          try
          {
              verifyResource( "config6.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as specified " +
                "join classloader links against same " +
                "classloader multiple times." );
      }
  
      public void testConfig7()
          throws Exception
      {
          try
          {
              verifyResource( "config7.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as specified " +
                "classloader has entry multiple times." );
      }
  
      public void testConfig8()
          throws Exception
      {
          try
          {
              verifyResource( "config8.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as a " +
                "join had same name as another join." );
      }
  
      public void testConfig9()
          throws Exception
      {
          try
          {
              verifyResource( "config9.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as a " +
                "join had same name as a " +
                "classloader." );
      }
  
      public void testConfig10()
          throws Exception
      {
          try
          {
              verifyResource( "config10.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as a " +
                "join had same name as another " +
                "predefined classloader." );
      }
  
      public void testConfig11()
          throws Exception
      {
          try
          {
              verifyResource( "config11.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as a " +
                "classloader had same name as another " +
                "classloader." );
      }
  
      public void testConfig12()
          throws Exception
      {
          try
          {
              verifyResource( "config12.xml" );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as a " +
                "classloader had same name as a " +
                "predefined classloader." );
      }
  
      public void testConfig13()
          throws Exception
      {
          try
          {
              final String[] predefines =
                  new String[]{ "*system*", "*system*"};
              final ClassLoaderSetDef defs =
                  buildFromResource( "config13.xml", predefines );
              verify( defs );
          }
          catch( final Throwable t )
          {
              return;
          }
  
          fail( "Expected verify to fail as a " +
                "predefined had same name as another " +
                "predefined." );
      }
  
      private void verifyResource( final String resource )
          throws Exception
      {
          final ClassLoaderSetDef defs = buildFromResource( resource );
          verify( defs );
      }
  
      private void verify( final ClassLoaderSetDef defs )
          throws Exception
      {
          final ClassLoaderVerifier verifier = new ClassLoaderVerifier();
          verifier.enableLogging( new ConsoleLogger() );
          verifier.verifyClassLoaderSet( defs );
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config1.xml
  
  Index: config1.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <join name="join$3">
      </join>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config10.xml
  
  Index: config10.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <join name="*system*"/>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config11.xml
  
  Index: config11.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <classloader name="X" parent="*system*"/>
      <classloader name="X" parent="*system*"/>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config12.xml
  
  Index: config12.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <classloader name="*system*" parent="*system*"/>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config13.xml
  
  Index: config13.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config2.xml
  
  Index: config2.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <classloader name="cl&" parent="*system*">
      </classloader>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config3.xml
  
  Index: config3.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <classloader name="cl" parent="missing-parent"/>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config4.xml
  
  Index: config4.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <join name="jl">
          <classloader-ref name="non-existent"/>
      </join>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config5.xml
  
  Index: config5.xml
  ===================================================================
  <classloaders default="iNoExist" version="1.0">
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config6.xml
  
  Index: config6.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <join name="jl">
          <classloader-ref name="*system*"/>
          <classloader-ref name="*system*"/>
      </join>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config7.xml
  
  Index: config7.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <classloader name="cl" parent="*system*">
          <entry location="someFile.jar"/>
          <entry location="someFile.jar"/>
      </classloader>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config8.xml
  
  Index: config8.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <join name="jl"/>
      <join name="jl"/>
  
  </classloaders>
  
  
  1.1                  jakarta-avalon-excalibur/loader/src/test/org/apache/excalibur/loader/verifier/test/config9.xml
  
  Index: config9.xml
  ===================================================================
  <classloaders default="*system*" version="1.0">
  
      <join name="j1"/>
  
      <classloader name="j1" parent="*system*"/>
  
  </classloaders>
  
  

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


Mime
View raw message