You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/04/15 05:02:08 UTC
cvs commit: avalon-sandbox/merlin/merlin-core/src/test/org/apache/avalon/merlin/kernel KernelTestCase.java
mcconnell 2003/04/14 20:02:08
Added: merlin/merlin-core/src/test/BLOCK-INF block.xml
merlin/merlin-core/src/test/org/apache/avalon/merlin
AbstractTestCase.java PlaygroundTestCase.java
Removed: merlin/merlin-core/src/test/org/apache/avalon/merlin/kernel
KernelTestCase.java
Log:
Updated test cases to handle block.xml based initialization of the kernel.
Revision Changes Path
1.1 avalon-sandbox/merlin/merlin-core/src/test/BLOCK-INF/block.xml
Index: block.xml
===================================================================
<!--
Demonstration of an block implementation configuration file.
-->
<block>
<info>
<name>playground</name>
</info>
<implementation>
<!--
an implementation may contain a single engine declaration,
multiple components and multiple containers
-->
<component name="standard"
class="org.apache.avalon.playground.StandardComponent" activation="startup">
<context class="org.apache.avalon.playground.StandardContextImp"/>
<configuration>
<message>Message declared in block descriptor.</message>
</configuration>
</component>
<container name="test">
<component name="alternate"
class="org.apache.avalon.playground.StandardComponent" activation="startup">
<context class="org.apache.avalon.playground.StandardContextImp"/>
<configuration>
<message>Alternate component inside a nested container.</message>
</configuration>
</component>
</container>
</implementation>
</block>
1.1 avalon-sandbox/merlin/merlin-core/src/test/org/apache/avalon/merlin/AbstractTestCase.java
Index: AbstractTestCase.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 apache@apache.org.
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.merlin;
import java.io.File;
import junit.framework.TestCase;
import org.apache.avalon.assembly.locator.DefaultLocator;
import org.apache.avalon.assembly.logging.LoggingManager;
import org.apache.avalon.assembly.logging.TargetDescriptor;
import org.apache.avalon.assembly.logging.LoggingDescriptor;
import org.apache.avalon.assembly.logging.DefaultLoggingManager;
import org.apache.avalon.assembly.locator.DefaultLocator;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.meta.model.Category;
import org.apache.avalon.merlin.block.Block;
import org.apache.avalon.merlin.kernel.impl.DefaultKernel;
import org.apache.avalon.merlin.kernel.KernelException;
import org.apache.avalon.merlin.kernel.Kernel;
/**
* A testcase for the @link{DefaultTypeManager}.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
*/
public abstract class AbstractTestCase extends TestCase implements Kernel
{
private DefaultKernel m_kernel;
public AbstractTestCase( String name )
{
super( name );
}
protected void setUp() throws Exception
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
File base = new File( System.getProperty( "user.dir" ) );
File classes = new File( base, "target/test-classes" );
DefaultLocator context = new DefaultLocator();
context.put( "urn:merlin:home", base );
context.put( "urn:merlin:system", base );
context.put( "urn:merlin:classloader.common", loader );
context.put( "urn:merlin:classloader.system", loader );
context.put( "urn:merlin:debug", "WARN" );
context.put( "urn:merlin:logging.priority", "DEBUG" );
context.put( "urn:merlin:block.url", classes.toURL() );
context.makeReadOnly();
m_kernel = new DefaultKernel();
m_kernel.contextualize( context );
m_kernel.initialize();
}
public void tearDown() throws Exception
{
if( m_kernel != null )
{
m_kernel.shutdown();
}
}
//--------------------------------------------------
// Kernel
//--------------------------------------------------
/**
* Return the root block.
* @return the root block
*/
public Block getRootBlock()
{
if( m_kernel == null )
{
final String message =
"Kernel has not been initialized.";
throw new IllegalStateException( message );
}
return m_kernel.getRootBlock();
}
/**
* Initiate an orderly shutdown of the kernel.
*/
public void shutdown()
{
if( m_kernel == null )
{
final String message =
"Kernel has not been initialized.";
throw new IllegalStateException( message );
}
m_kernel.shutdown();
}
}
1.1 avalon-sandbox/merlin/merlin-core/src/test/org/apache/avalon/merlin/PlaygroundTestCase.java
Index: PlaygroundTestCase.java
===================================================================
package org.apache.avalon.merlin;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.util.Enumeration;
import java.util.List;
import java.util.Iterator;
import java.util.jar.JarFile;
import java.util.ArrayList;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.net.URLClassLoader;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.net.MalformedURLException;
import java.net.JarURLConnection;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.merlin.block.Block;
import org.apache.avalon.merlin.kernel.KernelException;
import org.apache.avalon.assembly.util.ExceptionHelper;
import org.apache.avalon.assembly.locator.DefaultLocator;
import org.apache.avalon.assembly.appliance.Appliance;
import org.apache.avalon.assembly.util.ExceptionHelper;
import junit.framework.TestCase;
public class PlaygroundTestCase extends AbstractTestCase
{
public PlaygroundTestCase( )
{
this( "playground" );
}
public PlaygroundTestCase( String name )
{
super( name );
}
public void testRoot() throws Exception
{
try
{
URL root = (URL) super.getRootBlock().getURL();
URL url = new URL( root, "/");
assertTrue( url.getContent() != null );
assertTrue( url.getContent() instanceof Block );
}
catch( Throwable e )
{
final String msg = "Root test failure.";
final String error = ExceptionHelper.packException( msg, e );
System.out.println( error );
assertTrue( false );
return;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org