mcconnell 2003/11/23 21:30:08
Added: repository/test/src/test/org/apache/avalon/repository/main
InitialRepositoryFactoryTest.java LoaderTest.java
Removed: repository/test/src/test/org/apache/avalon/repository
InitialRepositoryFactoryTest.java LoaderTest.java
StandardTest.java
Log:
Housekeeping.
Revision Changes Path
1.1
avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/main/InitialRepositoryFactoryTest.java
Index: InitialRepositoryFactoryTest.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.repository.main ;
import java.io.File;
import java.net.URL;
import junit.framework.TestCase ;
import org.apache.avalon.repository.Artifact ;
import org.apache.avalon.repository.ClassicArtifact ;
import org.apache.avalon.repository.Repository ;
import org.apache.avalon.repository.RepositoryException ;
import org.apache.avalon.repository.criteria.Criteria ;
import org.apache.avalon.repository.criteria.Factory ;
import org.apache.avalon.repository.meta.TargetMeta ;
/**
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class InitialRepositoryFactoryTest extends TestCase
{
public static void main(String[] args)
{
junit.textui.TestRunner.run(InitialRepositoryFactoryTest.class);
}
/**
* Constructor for InitialRepositoryFactoryTest.
* @param name the test name
*/
public InitialRepositoryFactoryTest( String name )
{
super( name );
}
public void testRepositoryBootstrap() throws Exception
{
String[] bootstrap = getBootstrapRepositorySet();
Factory factory = new InitialRepositoryFactory( bootstrap );
assertNotNull( factory );
Criteria criteria = factory.createDefaultCriteria();
String[] repositories = getWorkingRepositorySet();
criteria.setValue( "avalon.repository.remote.url", repositories );
Repository repository = (Repository) factory.create( criteria ) ;
assertNotNull( repository ) ;
repository.getArtifact(
"avalon-framework", "avalon-framework-api", "4.1.5", "jar" );
}
public void testClassloaderCreation() throws Exception
{
//
// create the initial repo factory and
// get a context object and customize it
// to suite our usage scenario
//
String[] bootstrap = getBootstrapRepositorySet();
Factory factory =
new InitialRepositoryFactory( bootstrap );
Criteria criteria = factory.createDefaultCriteria();
String[] repositories = getWorkingRepositorySet();
criteria.setValue( "avalon.repository.remote.url", repositories );
Repository repository = (Repository) factory.create( criteria.getMap() ) ;
//
// create an artifact that contains a bunch of
// dependencies (about 30 in this example) spread
// across a classloader chain (api/spi/impl)
//
Artifact artifact =
ClassicArtifact.createJarArtifact(
"merlin", "merlin-kernel-impl", "3.2.1-dev" );
//
// create a classloader based on the artifact
//
ClassLoader loader =
repository.getClassLoader( artifact );
//
// grab a class from the classloader just to show that
// everything is working nicely
//
Class clazz =
loader.loadClass( "org.apache.avalon.merlin.kernel.Kernel" );
assertNotNull( clazz );
}
private static String[] getBootstrapRepositorySet()
{
return new String[]{
"file:///" + System.getProperty( "basedir" ) + "/target/repository",
};
}
private static String[] getWorkingRepositorySet()
{
return new String[]{
"file:///" + System.getProperty( "basedir" ) + "/target/repository",
"http://dpml.net/",
"http://www.ibiblio.org/maven/"
};
}
}
1.1
avalon-sandbox/repository/test/src/test/org/apache/avalon/repository/main/LoaderTest.java
Index: LoaderTest.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.repository.main ;
import java.io.File;
import java.net.URL;
import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute;
import junit.framework.TestCase ;
import org.apache.avalon.repository.Artifact ;
import org.apache.avalon.repository.ClassicArtifact ;
import org.apache.avalon.repository.Repository ;
import org.apache.avalon.repository.RepositoryException ;
import org.apache.avalon.repository.criteria.Criteria ;
import org.apache.avalon.repository.criteria.Factory ;
import org.apache.avalon.repository.meta.TargetMeta ;
/**
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class LoaderTest extends TestCase
{
private Repository m_repository;
/**
* Constructor for InitialRepositoryFactoryTest.
* @param name the name of the testcase
*/
public LoaderTest( String name )
{
super( name );
}
protected void setUp() throws Exception
{
String[] bootstrap = getBootstrapRepositorySet();
Factory factory = new InitialRepositoryFactory( bootstrap );
Criteria criteria = factory.createDefaultCriteria();
String[] repositories = getWorkingRepositorySet();
criteria.setValue( "avalon.repository.remote.url", repositories );
m_repository = (Repository) factory.create( criteria.getMap() ) ;
}
//----------------------------------------------------------------------
// tests
//----------------------------------------------------------------------
public void testEmbeddingScenario() throws Exception
{
Artifact spec = Artifact.createArtifact( "test", "test" );
Attributes attributes = m_repository.getArtifactAttributes( spec );
assertNotNull( "attributes-not-null", attributes );
TargetMeta target = new TargetMeta( attributes );
Artifact implementation = target.getImplementation();
assertNotNull( "implementation", implementation );
String classname = target.getFactoryClassname();
assertNotNull( "factory-classname", classname );
//
// create a classloader using the artifact referenced by the target
// using the context classloader as the parent
//
ClassLoader parent = Thread.currentThread().getContextClassLoader();
ClassLoader loader = m_repository.getClassLoader( parent, implementation );
Class c = loader.loadClass( target.getFactoryClassname() );
Factory factory = (Factory) c.newInstance();
Criteria criteria = factory.createDefaultCriteria();
assertNotNull( "criteria", criteria );
//
// populate the criteria with stuff
//
criteria.setValue(
"urn:merlin:base.dir",
new File( getBaseDirectory(), "home" ) );
criteria.setValue(
"urn:merlin:policy.info",
new Boolean( true ) );
criteria.setValue(
"urn:merlin:policy.debug",
new Boolean( true ) );
criteria.setValue(
"urn:merlin:policy.server",
new Boolean( false ) );
//
// instantiate the application
//
Object app = factory.create( criteria.getMap() );
System.out.println( "APP: " + app );
}
//----------------------------------------------------------------------
// utilities
//----------------------------------------------------------------------
private static String[] getBootstrapRepositorySet()
{
return new String[]{
"file:///" + System.getProperty( "basedir" ) + "/target/repository",
};
}
private static String[] getWorkingRepositorySet()
{
return new String[]{
"file:///" + System.getProperty( "basedir" ) + "/target/repository",
"http://dpml.net/",
"http://www.ibiblio.org/maven/"
};
}
private File getBaseDirectory()
{
String work = System.getProperty( "user.dir" );
String base = System.getProperty( "basedir", work );
return new File( base );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]