avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/assembly/src/test/org/apache/excalibur/assembly/type TypeManagerTestCase.java
Date Fri, 22 Nov 2002 23:43:03 GMT
mcconnell    2002/11/22 15:43:03

  Added:       assembly/src/test/org/apache/excalibur/assembly
                        TestCaseBase.java
               assembly/src/test/org/apache/excalibur/assembly/type
                        TypeManagerTestCase.java
  Log:
  Test case for TypeManager.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/assembly/src/test/org/apache/excalibur/assembly/TestCaseBase.java
  
  Index: TestCaseBase.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;
  
  import java.io.File;
  import junit.framework.TestCase;
  import org.apache.excalibur.merlin.assembly.DefaultLoggerManager;
  import org.apache.avalon.framework.logger.*;
  
  /**
   * A testcase for the @link{TypeManager}.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   */
  public abstract class TestCaseBase extends TestCase
  {
  
      protected ClassLoader m_loader;
      protected DefaultLoggerManager m_logManager;
  
      public TestCaseBase( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          m_loader = Thread.currentThread().getContextClassLoader();
          final File base = new File( System.getProperty( "user.dir" ) );
          m_logManager = new DefaultLoggerManager( base );
      }
  
      protected Logger getLogger()
      {
          return m_logManager.getLoggerForCategory("test");
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/assembly/src/test/org/apache/excalibur/assembly/type/TypeManagerTestCase.java
  
  Index: TypeManagerTestCase.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.type;
  
  import java.io.File;
  import junit.framework.TestCase;
  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.meta.info.*;
  import org.apache.excalibur.assembly.TestCaseBase;
  
  /**
   * A testcase for the @link{TypeManager}.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   */
  public class TypeManagerTestCase extends TestCaseBase
  {
  
      public TypeManagerTestCase()
      {
          this( "TypeManagerTestCase" );
      }
  
      public TypeManagerTestCase( String name )
      {
          super( name );
      }
  
      public void testTypeManagerStaticOperationsBasic()
      {
          final String classname = "org.apache.excalibur.playground.BasicComponent";
            
          try
          {
              assertTrue( doStaticCreation( classname ) != null );
          }
          catch( Throwable e )
          {
              System.out.println("static operation failure for create type using : " + classname
);
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testTypeManagerStaticOperationsSimple()
      {
          final String classname = "org.apache.excalibur.playground.SimpleComponent";
            
          try
          {
              assertTrue( doStaticCreation( classname ) != null );
          }
          catch( Throwable e )
          {
              System.out.println("static operation failure for create type using : " + classname
);
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testTypeManagerStaticOperationsComplex()
      {
          final String classname = "org.apache.excalibur.playground.ComplexComponent";
            
          try
          {
              assertTrue( doStaticCreation( classname ) != null );
          }
          catch( Throwable e )
          {
              System.out.println("static operation failure for create type using : " + classname
);
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testTypeManagerStaticOperationsNull()
      {          
          try
          {
              doStaticCreation( null );
              assertTrue( false );
          }
          catch( NullPointerException e )
          {
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println("static operation failure for create type using : " + null
);
              assertTrue( false );
              e.printStackTrace();
          }
      }
  
      public void testTypeManagerStaticOperationsBadType()
      {          
          final String classname = "org.something.else";
          try
          {
              Type type = DefaultTypeManager.createType( classname, m_loader );
              doStaticCreation( classname );
              assertTrue( false );
          }
          catch( TypeException e )
          {
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println(
                "static operation anti-failure for creation of invalid type using : " 
                + classname );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
     /**
      * Validation of the creation of the default type manager implememtation.
      */
      public void testTypeManagerCreation()
      {
          try
          {
              assertTrue( createTypeManager() != null );
          }
          catch( Throwable e )
          {
              assertTrue( false );
          }
      }
  
      public void testTypeRegistrationAndRetrival() throws Exception
      {
          final String complex = "org.apache.excalibur.playground.ComplexComponent";
          final String basic = "org.apache.excalibur.playground.BasicComponent";
          final String simple = "org.apache.excalibur.playground.SimpleComponent";
  
          DefaultTypeManager manager = createTypeManager();
          Type complexType = doStaticCreation( complex );
          Type basicType = doStaticCreation( basic );
          Type simpleType = doStaticCreation( simple );
          try
          {
  
              manager.addType( complexType );
              manager.addType( basicType );
              manager.addType( simpleType );
  
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println( "type addition failure" );
              e.printStackTrace();
              assertTrue( false );
          }
  
          //
          // validate type retrival by classname
          //
  
          try
          {
              complexType.equals( manager.getType( complex ) );
              basicType.equals( manager.getType( basic ) );
              simpleType.equals( manager.getType( simple ) );
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println( "type retrival by classname failure" );
              e.printStackTrace();
              assertTrue( false );
          }
  
          //
          // validate retrival by dependency
          //
  
          DependencyDescriptor constraint = complexType.getDependency( "simple" );
          Type[] solutions = manager.getTypes( constraint );
  
      }
  
     /**
      * Validation of the creation of the default type manager implememtation.
      */
      public DefaultTypeManager createTypeManager() throws Exception
      {
          DefaultServiceManager services = new DefaultServiceManager();
          services.enableLogging( getLogger().getChildLogger("services") );
          DefaultContext serviceContext = new DefaultContext();
          serviceContext.put( "assembly:classloader", m_loader );
          serviceContext.makeReadOnly();
          services.contextualize( serviceContext );
          services.initialize();
  
          DefaultTypeManager manager = new DefaultTypeManager();
          manager.enableLogging( getLogger().getChildLogger("types") );
          DefaultContext typeContext = new DefaultContext();
          typeContext.put( "assembly:classloader", m_loader );
          typeContext.put( "assembly:services", services );
          typeContext.makeReadOnly();
          manager.contextualize( typeContext );
          manager.initialize();
          return manager;
      }
  
      private Type doStaticCreation( String classname ) throws Exception
      {          
          Class clazz = m_loader.loadClass( classname );
          return DefaultTypeManager.createType( clazz );
      }
  
      protected void tearDown() throws Exception
      {
          m_loader = null;
      }
  
  }
  
  
  

--
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