mcconnell    2002/11/23 09:45:41

  Added:       assembly/src/test/org/apache/excalibur/assembly/profile
                        ProfileManagerTestCase.java
  Log:
  ProfileManager unit test.
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon-excalibur/assembly/src/test/org/apache/excalibur/assembly/profile/ProfileManagerTestCase.java
  
  Index: ProfileManagerTestCase.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.assembly.profile;
  
  import java.io.File;
  import junit.framework.TestCase;
  import org.apache.avalon.framework.Version;
  import org.apache.avalon.framework.context.*;
  import org.apache.avalon.framework.logger.*;
  import org.apache.excalibur.assembly.service.*;
  import org.apache.excalibur.assembly.type.*;
  import org.apache.excalibur.assembly.profile.*;
  import org.apache.excalibur.meta.info.*;
  import org.apache.excalibur.meta.model.*;
  import org.apache.excalibur.assembly.TestCaseBase;
  
  /**
   * A testcase for the @link{ProfileManager}.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Stephen McConnell</a>
   */
  public class ProfileManagerTestCase extends TestCaseBase
  {
  
      private ProfileManager m_manager;
      private TypeManager m_types;
  
      public ProfileManagerTestCase()
      {
          this( "ProfileManagerTestCase" );
      }
  
      public ProfileManagerTestCase( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
          m_types = createTypeManager();
          m_manager = createProfileManager();
      }
  
      public void testPackagedProfileImport()
      {
          final String classname = "org.apache.excalibur.playground.BasicComponent";
            
          try
          {
              Type type = m_types.createType( classname );
              Profile[] profiles = m_manager.loadProfiles( type );
              assertTrue( profiles.length > 0 );
          }
          catch( Throwable e )
          {
              System.out.println("failure to create packaged profiles for : " + 
classname );
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testProfileRegistrationAndRetrival() throws Exception
      {
          final String classname = "org.apache.excalibur.playground.BasicComponent";
          
          ReferenceDescriptor ref = 
            new ReferenceDescriptor(
              "org.apache.excalibur.playground.BasicService",
              Version.getVersion( "1.1" ) );
  
          DependencyDescriptor dep = 
            new DependencyDescriptor( "test", ref );
  
          try
          {
              Type type = m_types.createType( classname );
              Profile[] profiles = m_manager.loadProfiles( type );
              for( int i=0; i<profiles.length; i++ )
              {
                  m_manager.addProfile( profiles[i] );
              }
  
              Profile[] candidates = m_manager.getProfiles( dep );
              assertTrue( candidates.length > 0 );
          }
          catch( Throwable e )
          {
              System.out.println("failure to resolve profile for : " + ref );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      protected void tearDown() throws Exception
      {
          m_manager = null;
          m_types = null;
      }
  
      private TypeManager createTypeManager() throws Exception
      {
          DefaultTypeManager manager = new DefaultTypeManager();
          manager.enableLogging( getLogger().getChildLogger("types") );
          DefaultContext context = new DefaultContext();
          context.put( "assembly:classloader", m_loader );
          context.makeReadOnly();
          manager.contextualize( context );
          manager.initialize();
          return manager;
      }
  
      private ProfileManager createProfileManager() throws Exception
      {
          DefaultProfileManager manager = new DefaultProfileManager();
          manager.enableLogging( getLogger().getChildLogger("profiles") );
          DefaultContext context = new DefaultContext();
          context.put( "assembly:classloader", m_loader );
          context.makeReadOnly();
          manager.contextualize( context );
          manager.initialize();
          return manager;
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to