mcconnell 2003/02/27 15:19:30
Added: assembly/src/test/org/apache/avalon/assembly/engine
FactoryTestCase.java
assembly/src/test/org/apache/avalon/playground/factory
CustomAppliance.java CustomApplianceFactory.java
CustomApplianceFactory.xinfo CustomComponent.java
CustomComponent.xinfo CustomService.java
Log:
Added testcase for full component based apliance factory.
Revision Changes Path
1.1
avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/FactoryTestCase.java
Index: FactoryTestCase.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;
import java.io.File;
import java.util.Map;
import java.util.Hashtable;
import junit.framework.TestCase;
import org.apache.avalon.framework.Version;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.assembly.locator.DefaultLocator;
import org.apache.avalon.meta.info.*;
import org.apache.avalon.meta.model.*;
import org.apache.avalon.assembly.TestBase;
import org.apache.avalon.assembly.engine.Engine;
import org.apache.avalon.assembly.appliance.Appliance;
import org.apache.avalon.assembly.appliance.ApplianceContext;
import org.apache.avalon.assembly.appliance.DefaultApplianceContext;
import org.apache.avalon.assembly.appliance.DependencyGraph;
import org.apache.avalon.assembly.util.ExceptionHelper;
import org.apache.excalibur.mpool.DefaultPoolManager;
import org.apache.excalibur.mpool.PoolManager;
import org.apache.excalibur.event.command.CommandManager;
import org.apache.excalibur.event.command.TPCThreadManager;
/**
* A testcase for the [EMAIL PROTECTED] DefaultEngine} implementation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public class FactoryTestCase extends TestBase
{
protected EngineClassLoader m_engine;
protected DependencyGraph graph = new DependencyGraph();
public FactoryTestCase()
{
this( "EngineTestCase" );
}
public FactoryTestCase( String name )
{
super( name );
}
protected void setUp() throws Exception
{
super.setUp();
m_engine = setUpEngine( true );
}
public void testDirect()
{
final String locator =
"org.apache.avalon.assembly.lifecycle.context.DefaultContextualizer";
final String factory =
"org.apache.avalon.playground.factory.CustomApplianceFactory";
final String classname =
"org.apache.avalon.playground.factory.CustomComponent";
try
{
m_engine.register( locator );
m_engine.register( factory );
m_engine.register( classname );
Type type = m_engine.getRepository().getTypeManager().getType( classname
);
Profile profile =
m_engine.getRepository().getProfileManager().getProfile( type );
DefaultApplianceContext context = new DefaultApplianceContext( profile );
context.makeReadOnly();
Appliance appliance = m_engine.createAppliance( context, false );
appliance.assemble( graph );
assertTrue( appliance.resolve( this ) != null );
}
catch( Throwable e )
{
String error = ExceptionHelper.packException(
"failure for create type using : " + classname, e );
getLogger().error( error );
assertTrue( false );
}
}
protected EngineClassLoader setUpEngine( boolean bootstrap ) throws Exception
{
try
{
EngineClassLoader engine = new EngineClassLoader();
engine.enableLogging( getLogger() );
DefaultLocator context = new DefaultLocator();
context.put( "urn:assembly:engine.bootstrap", "" + bootstrap );
context.put( "urn:assembly:logging.manager", m_logManager );
context.put( "urn:assembly:threads.manager", getPoolManager() );
context.makeReadOnly();
engine.contextualize( context );
engine.initialize();
return engine;
}
catch( Exception e )
{
ExceptionHelper.printException( "Engine setup failure.", e, this, true );
assertTrue( false );
throw e;
}
}
private PoolManager getPoolManager( ) throws Exception
{
try
{
//
// Set up the ThreadManager that the CommandManager uses
//
TPCThreadManager threadManager = new TPCThreadManager();
threadManager.enableLogging( getLogger().getChildLogger( "threads" ) );
Parameters params = new Parameters();
params.setParameter( "threads-per-processor", "2" );
params.setParameter( "sleep-time", "1000" );
params.setParameter( "block-timeout", "250" );
threadManager.parameterize( params );
threadManager.initialize();
//
// Set up the CommandManager that the PoolManager uses.
//
CommandManager commandManager = new CommandManager();
threadManager.register( commandManager );
//
// Set up the PoolManager that the pooled lifecycle helper needs
//
DefaultPoolManager poolManager =
new DefaultPoolManager( commandManager.getCommandSink() );
return poolManager;
}
catch( Throwable e )
{
final String error =
"Internal error during establishment of the default pool manager.
Cause: ";
throw new Exception( error + e.toString() );
}
}
}
1.1
avalon-sandbox/assembly/src/test/org/apache/avalon/playground/factory/CustomAppliance.java
Index: CustomAppliance.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.playground.factory;
import org.apache.avalon.assembly.appliance.DefaultAppliance;
public class CustomAppliance extends DefaultAppliance
{
}
1.1
avalon-sandbox/assembly/src/test/org/apache/avalon/playground/factory/CustomApplianceFactory.java
Index: CustomApplianceFactory.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.playground.factory;
import org.apache.avalon.assembly.appliance.DefaultApplianceFactory;
public class CustomApplianceFactory extends DefaultApplianceFactory
{
}
1.1
avalon-sandbox/assembly/src/test/org/apache/avalon/playground/factory/CustomApplianceFactory.xinfo
Index: CustomApplianceFactory.xinfo
===================================================================
<?xml version="1.0"?>
<!DOCTYPE type
PUBLIC "-//AVALON/Component Type DTD Version 1.0//EN"
"http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
<!--
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.
@author Avalon Development Team
@version 1.0 12/03/2001
-->
<type>
<info>
<name>custom-appliance-factory</name>
</info>
<context>
<!--
the appliance factroy uses a custom contextualization strategy
which is declared under the following context attributes
-->
<attributes>
<attribute
key="urn:assembly:lifecycle.context.strategy"
value="org.apache.avalon.assembly.locator.Contextualizable"/>
</attributes>
<!--
the appliance repository and logging manager are supplied to the
factory under the custom contextualization phase
-->
<entry
key="urn:assembly:appliance.repository"
type="org.apache.avalon.assembly.appliance.ApplianceRepository"/>
<entry
key="urn:assembly:logging"
type="org.apache.avalon.assembly.logging.LoggingManager"/>
</context>
<services>
<service type="org.apache.avalon.assembly.appliance.ApplianceFactory"/>
</services>
</type>
1.1
avalon-sandbox/assembly/src/test/org/apache/avalon/playground/factory/CustomComponent.java
Index: CustomComponent.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.avalon.playground.factory;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
/**
* This is a demonstration component that declares no interface but
* has declares a custom appliance factory.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public class CustomComponent extends AbstractLogEnabled
implements CustomService, Initializable, Disposable
{
//=======================================================================
// Initializable
//=======================================================================
/**
* Initialization of the componet.
* @exception Exception if an initialization error occurs
*/
public void initialize()
throws Exception
{
if( getLogger().isInfoEnabled() )
{
getLogger().info( "initialize" );
}
}
//=======================================================================
// Disposable
//=======================================================================
/**
* Dispose of the component.
*/
public void dispose()
{
if( getLogger().isInfoEnabled() )
{
getLogger().info( "dispose" );
}
}
}
1.1
avalon-sandbox/assembly/src/test/org/apache/avalon/playground/factory/CustomComponent.xinfo
Index: CustomComponent.xinfo
===================================================================
<?xml version="1.0"?>
<!DOCTYPE type
PUBLIC "-//AVALON/Component Type DTD Version 1.0//EN"
"http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
<!--
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.
@author Avalon Development Team
@version 1.0 12/03/2001
-->
<type>
<info>
<name>custom</name>
<attributes>
<attribute key="urn:assembly:appliance.factory"
value="org.apache.avalon.playground.factory.CustomApplianceFactory"/>
</attributes>
</info>
<services>
<service type="org.apache.avalon.playground.factory.CustomService"/>
</services>
</type>
1.1
avalon-sandbox/assembly/src/test/org/apache/avalon/playground/factory/CustomService.java
Index: CustomService.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.avalon.playground.factory;
/**
* The <code>CustomService</code> doesn't do anything.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public interface CustomService
{
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]