You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/07/03 06:34:44 UTC

cvs commit: avalon-sandbox/merlin/assembly/src/test/org/apache/avalon/assembly/model CompositionTestCase.java ClasspathTestCase.java AbstractTestCase.java

mcconnell    2003/07/02 21:34:44

  Added:       merlin/assembly/src/test/org/apache/avalon/assembly/model
                        CompositionTestCase.java ClasspathTestCase.java
                        AbstractTestCase.java
  Log:
  Test-cases for meta-model composition, containment and deployment model creation and execution.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/merlin/assembly/src/test/org/apache/avalon/assembly/model/CompositionTestCase.java
  
  Index: CompositionTestCase.java
  ===================================================================
  
  
  package org.apache.avalon.assembly.model;
  
  import java.io.File;
  import java.io.IOException;
  import java.net.URL;
  
  import org.apache.avalon.assembly.repository.impl.FileRepository;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.meta.data.CompositionProfile;
  import org.apache.avalon.meta.data.ClassLoaderDirective;
  import org.apache.avalon.meta.data.builder.XMLCompositionProfileCreator;
  
  import junit.framework.TestCase;
  
  public class CompositionTestCase extends AbstractTestCase
  {
     //-------------------------------------------------------
     // state
     //-------------------------------------------------------
  
     /**
      * The composition meta-model.
      */
      private CompositionModel m_model;
  
     //-------------------------------------------------------
     // constructor
     //-------------------------------------------------------
  
      public CompositionTestCase( )
      {
          this( "data" );
      }
  
      public CompositionTestCase( String name )
      {
          super( name );
      }
  
     //-------------------------------------------------------
     // tests
     //-------------------------------------------------------
  
     /**
      * After internalizing the block xml description and constructing a 
      * block mata-data object and a meta model 
      */
      public void testCompositionModel() throws Exception
      {
          m_logger.info( "composition test case" );
          ClassLoader classloader = m_model.getImplementation().getClassLoader();
          assertTrue( 
            classloader.loadClass( 
              "org.apache.avalon.assembly.model.testa.TestA" ) != null );
          assertTrue( 
            classloader.loadClass( 
              "org.apache.avalon.assembly.model.testb.TestB" ) != null );
          assertTrue( 
            classloader.loadClass( 
              "org.apache.avalon.assembly.model.testc.TestC" ) != null );
          assertTrue( 
            classloader.loadClass( 
              "org.apache.avalon.assembly.model.testd.TestD" ) != null );
      }
  
     //-------------------------------------------------------
     // setup
     //-------------------------------------------------------
  
     protected String getPath()
     {
        return "block.xml";
     }
  
     /**
      * The setup process covers the establishment of the base
      * directory (from which relative references for extension directories
      * and fileset base directories are resolved), a file repository (not
      * used in this test case at this time), and a class loader model from 
      * which a classpath will be established.
      *
      * @exception Exception if things don't work out
      */
      public void setUp() throws Exception
      {
          super.setUp();
  
          //
          // create the composition model
          //
  
          ClassLoader loader = Thread.currentThread().getContextClassLoader();
          m_model = new CompositionModel( getLogger(), m_base, m_repository, loader, m_profile );
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/test/org/apache/avalon/assembly/model/ClasspathTestCase.java
  
  Index: ClasspathTestCase.java
  ===================================================================
  
  
  package org.apache.avalon.assembly.model;
  
  import java.io.File;
  import java.io.IOException;
  import java.net.URL;
  
  import org.apache.avalon.assembly.repository.impl.FileRepository;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.meta.data.CompositionProfile;
  import org.apache.avalon.meta.data.ClassLoaderDirective;
  import org.apache.avalon.meta.data.builder.XMLCompositionProfileCreator;
  
  import junit.framework.TestCase;
  
  public class ClasspathTestCase extends AbstractTestCase
  {
     //-------------------------------------------------------
     // state
     //-------------------------------------------------------
  
     /**
      * The classloader meta-data extracted from the block meta-data.
      */
      private ClassLoaderDirective m_date;
  
     /**
      * The classloader meta-model created using the classloader meta-data.
      */
      private ClassLoaderModel m_model;
  
  
     //-------------------------------------------------------
     // constructor
     //-------------------------------------------------------
  
      public ClasspathTestCase( )
      {
          this( "data" );
      }
  
      public ClasspathTestCase( String name )
      {
          super( name );
      }
  
     //-------------------------------------------------------
     // tests
     //-------------------------------------------------------
  
     /**
      * After internalizing the block xml description and constructing a 
      * block mata-data object and a meta model 
      */
      public void testClasspath() throws Exception
      {
          assertTrue( 
            m_profile.getImplementation().
              getClassLoaderDirective( false ) != null );
          assertTrue( 
            m_profile.getImplementation().getClassLoaderDirective().
              getClasspathDirective().getFilesets().length == 1 );
          assertTrue( 
            m_profile.getImplementation().getClassLoaderDirective().
              getClasspathDirective().getRepositoryDirectives().length == 1 );
  
  
          getLogger().info( "listing classpath:" );
          Logger classpath = getLogger().getChildLogger( "classpath" );
  
          URL[] urls = m_model.getClasspath();
          for( int i=0; i<urls.length; i++ )
          {
              classpath.info( urls[i].toString() );
          }
  
          assertTrue( m_model.getClasspath().length == 4 );
          getLogger().info( "classpath ok" );
  
      }
  
     //-------------------------------------------------------
     // setup
     //-------------------------------------------------------
  
     protected String getPath()
     {
        return "classpath.xml";
     }
  
     /**
      * The setup process covers the establishment of the base
      * directory (from which relative references for extension directories
      * and fileset base directories are resolved), a file repository (not
      * used in this test case at this time), and a class loader model from 
      * which a classpath will be established.
      *
      * @exception Exception if things don't work out
      */
      public void setUp() throws Exception
      {
          super.setUp();
  
          //
          // create the classloader model
          //
  
          Logger logger = getLogger().getChildLogger( "classloader" );
          ClassLoaderDirective classLoaderDirective = 
            m_profile.getImplementation().getClassLoaderDirective( true );
          m_model = new ClassLoaderModel( logger, m_base, m_repository, classLoaderDirective );
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/test/org/apache/avalon/assembly/model/AbstractTestCase.java
  
  Index: AbstractTestCase.java
  ===================================================================
  
  
  package org.apache.avalon.assembly.model;
  
  import java.io.File;
  import java.io.IOException;
  import java.net.URL;
  
  import org.apache.avalon.assembly.repository.impl.FileRepository;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.meta.data.CompositionProfile;
  import org.apache.avalon.meta.data.ClassLoaderDirective;
  import org.apache.avalon.meta.data.builder.XMLCompositionProfileCreator;
  
  import junit.framework.TestCase;
  
  public abstract class AbstractTestCase extends TestCase
  {
     //-------------------------------------------------------
     // state
     //-------------------------------------------------------
  
     /**
      * Source XML.
      */
      protected String m_path;
  
     /**
      * Internal logger.
      */
      protected Logger m_logger;
  
     /**
      * Setup argument for resolving relative references.
      */
      protected File m_base;
  
     /**
      * Setup argument (not used)
      */
      protected FileRepository m_repository;
  
     /**
      * The block profile.
      */
      protected CompositionProfile m_profile;
  
     /**
      * The classloader meta-model created using the classloader meta-data.
      */
      protected ClassLoaderModel m_model;
  
      public AbstractTestCase( )
      {
          this( "data" );
      }
  
      public AbstractTestCase( String name )
      {
          super( name );
      }
  
     //-------------------------------------------------------
     // setup
     //-------------------------------------------------------
  
     /**
      * The setup process covers the establishment of the base
      * directory (from which relative references for extension directories
      * and fileset base directories are resolved), a file repository (not
      * used in this test case at this time), and a class loader model from 
      * which a classpath will be established.
      *
      * @exception Exception if things don't work out
      */
      public void setUp() throws Exception
      {
          setUpCommon();
  
          if( m_base == null )
          {
              throw new NullPointerException( "base" );
          }
  
          //
          // load the meta data
          File conf = new File( m_base, getPath() );
          m_profile = setUpProfile( conf );
  
          //
          // create the classloader model
          //
  
          ClassLoaderDirective classLoaderDirective = 
            m_profile.getImplementation().getClassLoaderDirective( true );
          m_model = new ClassLoaderModel( getLogger(), m_base, m_repository, classLoaderDirective );
      }
  
      protected abstract String getPath();
  
      protected void setUpCommon() throws Exception
      {
          m_logger = setUpLogger();
          m_base = new File( getTestDir(), "test-classes" );
          File repository = new File( m_base, "repository" );
          m_repository = setUpRepository( repository );
      }
  
      protected Logger setUpLogger()
      {
          return new ConsoleLogger();
      }
  
      protected Logger getLogger()
      {
          return m_logger;
      }
  
      protected FileRepository setUpRepository( File root ) throws Exception
      {
          FileRepository repository = new FileRepository();
          repository.enableLogging( new ConsoleLogger() );
          DefaultContext context = new DefaultContext();
          context.put( FileRepository.BASE_KEY, root );
          context.makeReadOnly();
          repository.contextualize( context );
          return repository;
      }
  
      protected CompositionProfile setUpProfile( File file )
        throws Exception
      {
          XMLCompositionProfileCreator creator = new XMLCompositionProfileCreator();
          DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
          Configuration config = builder.buildFromFile( file );
          return creator.createCompositionProfile( config );
      }
  
      protected static File getTestDir()
      {
          return new File( System.getProperty( "basedir" ), "target" );
      }
  }
  
  
  

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