avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/service DefaultServiceRepositoryTestCase.java DefaultServiceManagerTestCase.java
Date Fri, 27 Dec 2002 16:24:55 GMT
mcconnell    2002/12/27 08:24:55

  Added:       assembly/src/test/org/apache/avalon/assembly/service
                        DefaultServiceRepositoryTestCase.java
  Removed:     assembly/src/test/org/apache/avalon/assembly/service
                        DefaultServiceManagerTestCase.java
  Log:
  renaming
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/service/DefaultServiceRepositoryTestCase.java
  
  Index: DefaultServiceRepositoryTestCase.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.avalon.assembly.engine.service;
  
  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.avalon.assembly.engine.service.*;
  import org.apache.avalon.assembly.engine.type.*;
  import org.apache.avalon.meta.info.*;
  import org.apache.avalon.assembly.TestCaseBase;
  
  /**
   * A testcase for the @link{DefaultServiceRepository}.
   *
   * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a>
   */
  public class DefaultServiceRepositoryTestCase extends TestCaseBase
  {
  
      private ServiceRepository m_manager;
      protected ClassLoader m_loader = Thread.currentThread().getContextClassLoader();
  
      public DefaultServiceRepositoryTestCase()
      {
          this( "DefaultServiceRepository" );
      }
  
      public DefaultServiceRepositoryTestCase( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
          ServiceRepository manager = new ServiceRepository( m_loader );
          manager.enableLogging( getLogger().getChildLogger("services") );
          m_manager = manager;
      }
  
      public void testCreateBasicService()
      {
          final String classname = "org.apache.avalon.playground.basic.BasicService";
            
          try
          {
              assertTrue( m_manager.createService( classname ) != null );
          }
          catch( Throwable e )
          {
              System.out.println("static operation failure for create type using : " + classname
);
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      public void testCreateNull()
      {          
          try
          {
              m_manager.createService( (String) 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 testCreateBadService()
      {          
          final String classname = "org.something.else";
          try
          {
              Service service = m_manager.createService( classname );
              assertTrue( false );
          }
          catch( ServiceException e )
          {
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println(
                "static operation anti-failure for creation of invalid service using : " 
                + classname );
              e.printStackTrace();
              assertTrue( false );
          }
      }
  
      public void testServiceRegistrationAndRetrival() throws Exception
      {
          final String classname = "org.apache.avalon.playground.basic.BasicService";
  
          Service service = m_manager.createService( classname );
          try
          {
              m_manager.addService( service );
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println( "type addition failure" );
              e.printStackTrace();
              assertTrue( false );
          }
  
          //
          // try to add the service again (which should fail)
          //
  
          try
          {
              m_manager.addService( service );
              System.out.println( "type replacement check failure" );
              assertTrue( false );
          }
          catch( Throwable e )
          {
              assertTrue( true );
          }
  
          //
          // validate service retrival by classname and version
          //
  
          try
          {
              service.equals( m_manager.getService( service.getClassname(), service.getVersion()
) );
              assertTrue( true );
          }
          catch( Throwable e )
          {
              System.out.println( "service retrival by classname/version failure" );
              e.printStackTrace();
              assertTrue( false );
          }
  
          //
          // validate service retrival by classname and version using a bad version
          //
  
          try
          {
              Version version = Version.getVersion( "111.111" );
              service.equals( m_manager.getService( service.getClassname(), version ) );
              System.out.println( "service retrival by classname/version failure on bad version"
);
              assertTrue( false );
          }
          catch( Throwable e )
          {
              assertTrue( true );
          }
      }
  
      protected void tearDown() throws Exception
      {
          m_loader = null;
          m_manager = 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