mcconnell 2002/11/23 04:59:20
Added: assembly/src/test/org/apache/excalibur/assembly/service
DefaultServiceManagerTestCase.java
Log:
Initial commit of the default service manager unit test.
Revision Changes Path
1.1
jakarta-avalon-excalibur/assembly/src/test/org/apache/excalibur/assembly/service/DefaultServiceManagerTestCase.java
Index: DefaultServiceManagerTestCase.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.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.meta.info.*;
import org.apache.excalibur.assembly.TestCaseBase;
/**
* A testcase for the @link{DefaultServiceManager}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public class DefaultServiceManagerTestCase extends TestCaseBase
{
public DefaultServiceManagerTestCase()
{
this( "DefaultServiceManager" );
}
public DefaultServiceManagerTestCase( String name )
{
super( name );
}
public void testStaticOperations()
{
final String classname = "org.apache.excalibur.playground.BasicService";
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 testStaticOperationsNull()
{
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 testStaticOperationsBadType()
{
final String classname = "org.something.else";
try
{
Service service = DefaultServiceManager.createService( classname,
m_loader );
doStaticCreation( 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 );
}
}
/**
* Validation of the creation of the default type manager implememtation.
*/
public void testCreation()
{
try
{
assertTrue( createServiceManager() != null );
}
catch( Throwable e )
{
assertTrue( false );
}
}
public void testServiceRegistrationAndRetrival() throws Exception
{
final String classname = "org.apache.excalibur.playground.BasicService";
DefaultServiceManager manager = createServiceManager();
Service service = doStaticCreation( classname );
try
{
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
{
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( 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( manager.getService( service.getClassname(), version ) );
System.out.println( "service retrival by classname/version failure on
bad version" );
assertTrue( false );
}
catch( Throwable e )
{
assertTrue( true );
}
}
/**
* Validation of the creation of the default type manager implememtation.
*/
public DefaultServiceManager createServiceManager() 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();
return services;
}
private Service doStaticCreation( String classname ) throws Exception
{
Class clazz = m_loader.loadClass( classname );
return DefaultServiceManager.createService( clazz );
}
protected void tearDown() throws Exception
{
m_loader = null;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>