avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test AbstractTestCase.java AssemblyTestCase.java SystemContextBuilder.java
Date Tue, 10 Feb 2004 16:24:48 GMT
mcconnell    2004/02/10 08:24:48

  Added:       merlin/composition/impl/src/test/org/apache/avalon/composition/model/test
                        AbstractTestCase.java AssemblyTestCase.java
                        SystemContextBuilder.java
  Log:
  Updating APIs and implemetation to enable seperation of the runtime aspects from model aspects
anabling full model-driven control.
  
  Revision  Changes    Path
  1.1                  avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/AbstractTestCase.java
  
  Index: AbstractTestCase.java
  ===================================================================
  
  
  package org.apache.avalon.composition.model.test;
  
  import java.io.File;
  
  import org.apache.avalon.repository.Artifact;
  
  import org.apache.avalon.composition.model.ComponentModel;
  import org.apache.avalon.composition.model.ContainmentModel;
  import org.apache.avalon.composition.model.DeploymentModel;
  import org.apache.avalon.composition.provider.SystemContext;
  import org.apache.avalon.composition.provider.ModelFactory;
  
  import org.apache.avalon.repository.provider.InitialContext;
  import org.apache.avalon.repository.main.DefaultInitialContext;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  
  import org.apache.avalon.util.exception.ExceptionHelper;
  import org.apache.avalon.util.env.Env;
  
  import junit.framework.TestCase;
  
  public abstract class AbstractTestCase extends TestCase
  {
      public int PRIORITY = ConsoleLogger.LEVEL_INFO;
  
     //-------------------------------------------------------
     // state
     //-------------------------------------------------------
  
      public ContainmentModel m_model;
  
      private Logger m_logger = new ConsoleLogger( PRIORITY );
  
      private String m_path;
  
     //-------------------------------------------------------
     // constructor
     //-------------------------------------------------------
  
     public AbstractTestCase( String path )
     {
         super( path );
         m_path = path;
     }
  
     //-------------------------------------------------------
     // constructor
     //-------------------------------------------------------
  
      protected Logger getLogger()
      {
          return m_logger;
      }
  
      protected File getTestDir()
      {
          return new File( System.getProperty( "basedir" ), "target" );
      }
  
      public void setUp() throws Exception
      {
          if( m_model == null )
          {
              File base = new File( getTestDir(), "test" );
              File root = new File( base, "repository" );
  
              File confDir = new File( base, "conf" );
              File source = new File( confDir, m_path );
  
              //
              // FIXME - need to read the current version for a 
              // properties file or something
              //
  
              InitialContext context = 
                new DefaultInitialContext( 
                  getMavenRepositoryDirectory() );
  
              try
              {
                  SystemContext system = 
                    SystemContextBuilder.createSystemContext( 
                      context, base, root, PRIORITY, true, 1000 );
                  ModelFactory factory = system.getModelFactory();
                  m_model = factory.createRootContainmentModel( source.toURL() );
              }
              catch( Throwable e )
              {
                  final String error = ExceptionHelper.packException( e, true );
                  System.err.println( error );
                  fail( error );
              }
          }
      }
  
      public void printModel( String lead, DeploymentModel model )
      {
          if( model instanceof ContainmentModel )
          {
              printContainmentModel( lead, (ContainmentModel) model );
          }
          else if( model instanceof ComponentModel ) 
          {
              printComponentModel( lead, (ComponentModel) model );
          }
      }
  
      public void printContainmentModel( String lead, ContainmentModel model )
      {
          printDeploymentModel( lead, model );
          DeploymentModel[] models = model.getModels();
          if( models.length > 0 )
          {
              System.out.println( lead + "  children:" );
              for( int i=0; i<models.length; i++ )
              {
                  DeploymentModel m = models[i];
                  printModel( "    " + lead, m );
              }
          }
          models = model.getStartupGraph();
          if( models.length > 0 )
          {
              System.out.println( lead + "  startup:" );
              for( int i=0; i<models.length; i++ )
              {
                  DeploymentModel m = models[i];
                  System.out.println( "    " + lead + (i+1) + ": " + m );
              }
          }
          models = ((ContainmentModel)model).getShutdownGraph();
          if( models.length > 0 )
          {
              System.out.println( lead + "  shutdown:" );
              for( int i=0; i<models.length; i++ )
              {
                  DeploymentModel m = models[i];
                  System.out.println( "    " + lead + (i+1) + ": " + m );
              }
          }
      }
  
      public void printComponentModel( String lead, ComponentModel model )
      {
          printDeploymentModel( lead, model );
      }
  
      public void printDeploymentModel( String lead, DeploymentModel model )
      {
          System.out.println( 
            lead 
            + "model:" 
            + model + "(" 
            + model.getDeploymentTimeout() 
            + ")" );
  
          DeploymentModel[] providers = model.getProviderGraph();
          DeploymentModel[] consumers = model.getConsumerGraph();
  
          if(( providers.length == 0 ) && ( consumers.length == 0 ))
          {
              return;
          }
  
          if( providers.length > 0 ) for( int i=0; i<providers.length; i++ )
          {
              DeploymentModel m = providers[i];
              System.out.println( lead + "  <-- " + m );
          }
  
          if( consumers.length > 0 ) for( int i=0; i<consumers.length; i++ )
          {
              DeploymentModel m = consumers[i];
              System.out.println( lead + "  --> " + m );
          }
      }
  
      private static File getMavenRepositoryDirectory()
      {
          return new File( getMavenHomeDirectory(), "repository" );
      }
  
      private static File getMavenHomeDirectory()
      {
          return new File( getMavenHome() );
      }
  
      private static String getMavenHome()
      {
          try
          {
              String local = 
                System.getProperty( 
                  "maven.home.local", 
                  Env.getEnvVariable( "MAVEN_HOME_LOCAL" ) );
              if( null != local ) return local;
  
              return System.getProperty( "user.home" ) + File.separator + ".maven";
  
          }
          catch( Throwable e )
          {
              final String error = 
                "Internal error while attempting to access environment.";
              final String message = 
                ExceptionHelper.packException( error, e, true );
              throw new RuntimeException( message );
          }
      }
  
  }
  
  
  
  1.5       +14 -1     avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/AssemblyTestCase.java
  
  
  
  
  1.1                  avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/test/SystemContextBuilder.java
  
  Index: SystemContextBuilder.java
  ===================================================================
  /* 
   * Copyright 2004 Apache Software Foundation
   * Licensed  under the  Apache License,  Version 2.0  (the "License");
   * you may not use  this file  except in  compliance with the License.
   * You may obtain a copy of the License at 
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed  under the  License is distributed on an "AS IS" BASIS,
   * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
   * implied.
   * 
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.avalon.composition.model.test;
  
  import java.io.File;
  import java.net.URL;
  import java.util.Map;
  
  import org.apache.avalon.composition.model.ContainmentModel;
  import org.apache.avalon.composition.model.impl.DefaultSystemContext;
  import org.apache.avalon.composition.provider.ModelFactory;
  import org.apache.avalon.composition.provider.SystemContext;
  
  import org.apache.avalon.logging.provider.LoggingManager;
  import org.apache.avalon.logging.data.CategoryDirective;
  
  import org.apache.avalon.repository.Artifact;
  import org.apache.avalon.repository.Repository;
  import org.apache.avalon.repository.provider.CacheManager;
  import org.apache.avalon.repository.provider.InitialContext;
  import org.apache.avalon.repository.provider.Builder;
  import org.apache.avalon.repository.provider.Factory;
  
  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.framework.parameters.Parameters;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  /**
   * Implementation of a system context that exposes a system wide set of parameters.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/02/10 16:24:48 $
   */
  public class SystemContextBuilder
  {
      //--------------------------------------------------------------
      // static
      //--------------------------------------------------------------
  
     /**
      * Convinience function to create a new system context. This function
      * is intended for test purposes only.
      *
      * @param context the intial repository context
      * @param base the base directory from which relative references 
      *   within a classpath or library directive shall be resolved
      * @param root a repository root directory
      * @param priority logging manager default priority
      * @return a system context
      */
      public static SystemContext createSystemContext( 
        InitialContext context, File base, File root,
        int priority, boolean secure, long timeout ) 
        throws Exception
      {
          //
          // ### FIX ME ##
          //
   
          Artifact artifact = Artifact.createArtifact( 
            "avalon-logging", "avalon-logkit-impl", "1.0-SNAPSHOT" );
  
          LoggingManager logging = 
            createLoggingManager( context, artifact, base, priority );
  
          Logger logger = logging.getLoggerForCategory( "" );
          CacheManager cache = createCacheManager( context, root );
          Repository repository = cache.createRepository();
  
          final File home = new File( base, "home" );
          final File temp = new File( base, "temp" );
   
          return new DefaultSystemContext( 
            context, null, logging, base, home, temp, repository, "system", 
            false, timeout, secure );
      }
  
      private static CacheManager createCacheManager( 
        InitialContext context, File root ) 
        throws Exception
      {
          String dpml = "http://dpml.net";
          String ibiblio = "http://www.ibiblio.org/maven";
          String[] hosts = new String[]{ dpml, ibiblio };
  
          Factory factory = context.getInitialFactory();
          Map criteria = factory.createDefaultCriteria();
          criteria.put( "avalon.repository.cache", root );
          criteria.put( "avalon.repository.hosts", hosts );
  
          return (CacheManager) factory.create( criteria );
      }
  
      private static LoggingManager createLoggingManager( 
        InitialContext context, Artifact artifact, File base, int priority ) 
        throws Exception
      {
          final String level = getStringPriority( priority );
          Builder builder = context.newBuilder( artifact );
          Factory factory = builder.getFactory();
          Map criteria = factory.createDefaultCriteria();
          File file = new File( base, "conf/logging.xml" );
          criteria.put( "avalon.logging.configuration", file );
          criteria.put( "avalon.logging.basedir", base );
          return (LoggingManager) factory.create( criteria );
      }
  
      private static String getStringPriority( int priority )
      {
          if( priority == ConsoleLogger.LEVEL_DISABLED )
          {
              return "NONE";
          }
          else if( priority == ConsoleLogger.LEVEL_DEBUG )
          {
              return "DEBUG";
          }
          else if( priority == ConsoleLogger.LEVEL_INFO )
          {
              return "INFO";
          }
          else if( priority == ConsoleLogger.LEVEL_WARN )
          {
              return "WARN";
          }
          else if( priority == ConsoleLogger.LEVEL_ERROR )
          {
              return "ERROR";
          }
          else if( priority == ConsoleLogger.LEVEL_FATAL )
          {
              return "FATAL";
          }
          else
          {
              final String error = 
               "Unrecognized logging priority: " + priority;
              throw new IllegalArgumentException( error );
          }
      }
  }
  
  
  

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


Mime
View raw message