git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272375 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,293 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon; | |||||
import java.io.IOException; | |||||
import java.util.ArrayList; | |||||
import java.util.Collection; | |||||
import java.util.Iterator; | |||||
import jdepend.framework.JDepend; | |||||
import jdepend.framework.JavaPackage; | |||||
import junit.framework.TestCase; | |||||
/** | |||||
* An abstract Unit test that can be used to test Dependency metrics | |||||
* fall in acceptable limits. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class DependencyMetricsTestCase | |||||
extends TestCase | |||||
{ | |||||
private JDepend m_jDepend; | |||||
public DependencyMetricsTestCase( final String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Sets up the test fixture. | |||||
* | |||||
* Called before every test case method. | |||||
*/ | |||||
protected void setUp() | |||||
{ | |||||
m_jDepend = new JDepend(); | |||||
try | |||||
{ | |||||
m_jDepend.addDirectory( "src/java" ); | |||||
//m_jDepend.addDirectory( "src/main" ); | |||||
} | |||||
catch( final IOException ioe ) | |||||
{ | |||||
fail( ioe.getMessage() ); | |||||
} | |||||
m_jDepend.analyze(); | |||||
} | |||||
/** | |||||
* Tears down the test fixture. | |||||
* | |||||
* Called after every test case method. | |||||
*/ | |||||
protected void tearDown() | |||||
{ | |||||
m_jDepend = null; | |||||
} | |||||
/** | |||||
* Utility method to retrieve JDpenden instance that contains statistics. | |||||
*/ | |||||
protected final JDepend getJDepend() | |||||
{ | |||||
return m_jDepend; | |||||
} | |||||
/** | |||||
* Make sure that the launcher classes in org.apache.myrmidon.launcher.* | |||||
* are completely decoupled from the rest of the system. | |||||
*/ | |||||
public void testLauncherDecoupled() | |||||
{ | |||||
final JDepend jDepend = getJDepend(); | |||||
final String name = "org.apache.myrmidon.launcher"; | |||||
final JavaPackage javaPackage = jDepend.getPackage( name ); | |||||
final Collection efferentSet = javaPackage.getEfferents(); | |||||
final Iterator afferents = efferentSet.iterator(); | |||||
while( afferents.hasNext() ) | |||||
{ | |||||
final JavaPackage efferent = (JavaPackage)afferents.next(); | |||||
final String efferentName = efferent.getName(); | |||||
if( ! isSubPackage( name, efferentName ) ) | |||||
{ | |||||
fail( "The launcher package " + name + " depends on external classes " + | |||||
"contained in " + efferentName + ". No classes besides " + | |||||
"those in the launcher hierarchy should be referenced" ); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Make sure that the implementations of the myrmidon kernel components | |||||
* (ie org.apache.myrmidon.component.X.*) are not referenced by anyone | |||||
* except by other objects in the same package or child packages. | |||||
*/ | |||||
public void testNoComponentImplSharing() | |||||
{ | |||||
final JDepend jDepend = getJDepend(); | |||||
final Collection packageSet = jDepend.getPackages(); | |||||
final Iterator packages = packageSet.iterator(); | |||||
while( packages.hasNext() ) | |||||
{ | |||||
final JavaPackage javaPackage = (JavaPackage)packages.next(); | |||||
final String name = javaPackage.getName(); | |||||
final String componentPackage = "org.apache.myrmidon.components."; | |||||
if( !name.startsWith( componentPackage ) ) | |||||
{ | |||||
continue; | |||||
} | |||||
// Extract the component package | |||||
final int start = componentPackage.length() + 1; | |||||
final int end = name.indexOf( '.', start ); | |||||
final String component; | |||||
if( end > -1 ) | |||||
{ | |||||
component = name.substring( end ); | |||||
} | |||||
else | |||||
{ | |||||
component = name; | |||||
} | |||||
// Make sure that all the afferent packages of this package (i.e. | |||||
// those that refer to this package) are sub-packages of the | |||||
// component package | |||||
final Collection afferentSet = javaPackage.getAfferents(); | |||||
final Iterator afferents = afferentSet.iterator(); | |||||
while( afferents.hasNext() ) | |||||
{ | |||||
final JavaPackage efferent = (JavaPackage)afferents.next(); | |||||
final String efferentName = efferent.getName(); | |||||
if( !isSubPackage( component, efferentName ) ) | |||||
{ | |||||
fail( "The package " + name + " is referred to by classes " + | |||||
"contained in " + efferentName + ". No classes besides " + | |||||
"those part of the particular implementation of kernel " + | |||||
"component should reference the implementations" ); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Make sure that aut does not depend on any other ant classes | |||||
* and thus can be cleanly decoupled. | |||||
*/ | |||||
public void testAutDecoupled() | |||||
{ | |||||
final String packageName = "org.apache.aut"; | |||||
final String[] badEfferents = new String[] | |||||
{ | |||||
"org.apache.myrmidon", "org.apache.antlib", "org.apache.tools.ant" | |||||
}; | |||||
doTestDecoupled( packageName, badEfferents ); | |||||
} | |||||
/** | |||||
* Make sure that myrmidon package does not have any | |||||
* unwanted dependencies. | |||||
*/ | |||||
/* | |||||
public void testMyrmidonDecoupled() | |||||
{ | |||||
final String packageName = "org.apache.myrmidon"; | |||||
final String[] badEfferents = new String[] | |||||
{ | |||||
"org.apache.antlib", "org.apache.tools.ant" | |||||
}; | |||||
doTestDecoupled( packageName, badEfferents ); | |||||
} | |||||
*/ | |||||
/** | |||||
* Make sure that antlib package does not have any | |||||
* unwanted dependencies. | |||||
*/ | |||||
/* | |||||
public void testAntlibDecoupled() | |||||
{ | |||||
final String packageName = "org.apache.antlib"; | |||||
final String[] badEfferents = new String[] | |||||
{ | |||||
"org.apache.tools.ant" | |||||
}; | |||||
doTestDecoupled( packageName, badEfferents ); | |||||
} | |||||
*/ | |||||
/** | |||||
* Make sure there are no circular dependencies between packages because | |||||
* circular dependencies are evil!!! | |||||
*/ | |||||
public void testNoCircularity() | |||||
{ | |||||
final JDepend jDepend = getJDepend(); | |||||
final Collection packageSet = jDepend.getPackages(); | |||||
final Iterator packages = packageSet.iterator(); | |||||
while( packages.hasNext() ) | |||||
{ | |||||
final JavaPackage javaPackage = (JavaPackage)packages.next(); | |||||
if( javaPackage.containsCycle() ) | |||||
{ | |||||
final ArrayList cycle = new ArrayList(); | |||||
javaPackage.collectCycle( cycle ); | |||||
final ArrayList names = getPackageNames( cycle ); | |||||
fail( "The package " + javaPackage.getName() + " contains a cycle " + | |||||
"with a path " + names ); | |||||
} | |||||
} | |||||
} | |||||
private ArrayList getPackageNames( final ArrayList cycle ) | |||||
{ | |||||
final ArrayList names = new ArrayList(); | |||||
final int size = cycle.size(); | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
final JavaPackage javaPackage = (JavaPackage)cycle.get( i ); | |||||
names.add( javaPackage.getName() ); | |||||
} | |||||
return names; | |||||
} | |||||
/** | |||||
* Make sure that the specified package does not depend on any | |||||
* of the specified package hierarchies. | |||||
*/ | |||||
private void doTestDecoupled( final String packageName, | |||||
final String[] invalidEfferents ) | |||||
{ | |||||
final JDepend jDepend = getJDepend(); | |||||
final Collection packageSet = jDepend.getPackages(); | |||||
final Iterator packages = packageSet.iterator(); | |||||
while( packages.hasNext() ) | |||||
{ | |||||
final JavaPackage javaPackage = (JavaPackage)packages.next(); | |||||
final String name = javaPackage.getName(); | |||||
if( !isSubPackage( packageName, name ) ) | |||||
{ | |||||
continue; | |||||
} | |||||
final Collection efferentSet = javaPackage.getEfferents(); | |||||
final Iterator efferents = efferentSet.iterator(); | |||||
while( efferents.hasNext() ) | |||||
{ | |||||
final JavaPackage efferent = (JavaPackage)efferents.next(); | |||||
final String efferentName = efferent.getName(); | |||||
for( int i = 0; i < invalidEfferents.length; i++ ) | |||||
{ | |||||
final String other = invalidEfferents[ i ]; | |||||
if( isSubPackage( other, efferentName ) ) | |||||
{ | |||||
fail( "The package " + name + " has an unwanted dependency " + | |||||
"on classes contained in " + efferentName ); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Determines if a package is a sub-package of another package. | |||||
* | |||||
* @return true if <code>subpackage</code> is either the same package as | |||||
* <code>basePackage</code>, or a sub-package of it. | |||||
*/ | |||||
private boolean isSubPackage( final String basePackage, | |||||
final String subpackage ) | |||||
{ | |||||
if( ! subpackage.startsWith( basePackage ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
return ( subpackage.length() == basePackage.length() | |||||
|| subpackage.charAt( basePackage.length() ) == '.' ); | |||||
} | |||||
} |
@@ -1,249 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components; | |||||
import java.io.File; | |||||
import java.util.ArrayList; | |||||
import java.util.HashMap; | |||||
import java.util.Iterator; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import org.apache.aut.converter.Converter; | |||||
import org.apache.avalon.framework.activity.Initializable; | |||||
import org.apache.avalon.framework.context.Context; | |||||
import org.apache.avalon.framework.context.Contextualizable; | |||||
import org.apache.avalon.framework.context.DefaultContext; | |||||
import org.apache.avalon.framework.logger.LogEnabled; | |||||
import org.apache.avalon.framework.logger.Logger; | |||||
import org.apache.avalon.framework.service.DefaultServiceManager; | |||||
import org.apache.avalon.framework.service.ServiceManager; | |||||
import org.apache.avalon.framework.service.Serviceable; | |||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
import org.apache.myrmidon.components.classloader.DefaultClassLoaderManager; | |||||
import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||||
import org.apache.myrmidon.components.converter.DefaultMasterConverter; | |||||
import org.apache.myrmidon.components.deployer.DefaultDeployer; | |||||
import org.apache.myrmidon.components.executor.DefaultExecutor; | |||||
import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | |||||
import org.apache.myrmidon.components.property.DefaultPropertyResolver; | |||||
import org.apache.myrmidon.components.role.DefaultRoleManager; | |||||
import org.apache.myrmidon.components.type.DefaultTypeManager; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager; | |||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | |||||
import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | |||||
import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
import org.apache.myrmidon.interfaces.executor.Executor; | |||||
import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
/** | |||||
* A base class for tests for the default components. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
*/ | |||||
public abstract class AbstractComponentTest | |||||
extends AbstractMyrmidonTest | |||||
{ | |||||
private DefaultServiceManager m_serviceManager; | |||||
public static final String DATA_TYPE_ROLE = "data-type"; | |||||
public static final String CONVERTER_ROLE = "converter"; | |||||
public static final String SERVICE_FACTORY_ROLE = "service-factory"; | |||||
public AbstractComponentTest( final String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Returns the component manager containing the components to test. | |||||
*/ | |||||
protected final ServiceManager getServiceManager() throws Exception | |||||
{ | |||||
if( m_serviceManager == null ) | |||||
{ | |||||
Logger logger = getLogger(); | |||||
// Create the components | |||||
m_serviceManager = new DefaultServiceManager(); | |||||
List components = new ArrayList(); | |||||
Object component = createComponent( Converter.ROLE, DefaultMasterConverter.class ); | |||||
m_serviceManager.put( Converter.ROLE, component ); | |||||
m_serviceManager.put( ConverterRegistry.ROLE, component ); | |||||
components.add( component ); | |||||
component = createComponent( TypeManager.ROLE, DefaultTypeManager.class ); | |||||
m_serviceManager.put( TypeManager.ROLE, component ); | |||||
components.add( component ); | |||||
component = createComponent( Configurer.ROLE, DefaultConfigurer.class ); | |||||
m_serviceManager.put( Configurer.ROLE, component ); | |||||
components.add( component ); | |||||
component = createComponent( Deployer.ROLE, DefaultDeployer.class ); | |||||
m_serviceManager.put( Deployer.ROLE, component ); | |||||
components.add( component ); | |||||
component = createComponent( Executor.ROLE, DefaultExecutor.class ); | |||||
m_serviceManager.put( Executor.ROLE, component ); | |||||
components.add( component ); | |||||
component = createComponent( ClassLoaderManager.ROLE, DefaultClassLoaderManager.class ); | |||||
m_serviceManager.put( ClassLoaderManager.ROLE, component ); | |||||
components.add( component ); | |||||
component = createComponent( ExtensionManager.ROLE, DefaultExtensionManager.class ); | |||||
m_serviceManager.put( ExtensionManager.ROLE, component ); | |||||
components.add( component ); | |||||
component = createComponent( RoleManager.ROLE, DefaultRoleManager.class ); | |||||
m_serviceManager.put( RoleManager.ROLE, component ); | |||||
components.add( component ); | |||||
component = createComponent( PropertyResolver.ROLE, DefaultPropertyResolver.class ); | |||||
m_serviceManager.put( PropertyResolver.ROLE, component ); | |||||
components.add( component ); | |||||
// Log enable the components | |||||
for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||||
{ | |||||
Object obj = iterator.next(); | |||||
if( obj instanceof LogEnabled ) | |||||
{ | |||||
final LogEnabled logEnabled = (LogEnabled)obj; | |||||
logEnabled.enableLogging( logger ); | |||||
} | |||||
} | |||||
// Contextualise the components | |||||
final Context context = new DefaultContext( getParameters() ); | |||||
for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||||
{ | |||||
Object obj = iterator.next(); | |||||
if( obj instanceof Contextualizable ) | |||||
{ | |||||
final Contextualizable contextualizable = (Contextualizable)obj; | |||||
contextualizable.contextualize( context ); | |||||
} | |||||
} | |||||
// Compose the components | |||||
for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||||
{ | |||||
Object obj = iterator.next(); | |||||
if( obj instanceof Serviceable ) | |||||
{ | |||||
final Serviceable serviceable = (Serviceable)obj; | |||||
serviceable.service( m_serviceManager ); | |||||
} | |||||
} | |||||
// Initialise the components | |||||
for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||||
{ | |||||
Object obj = iterator.next(); | |||||
if( obj instanceof Initializable ) | |||||
{ | |||||
final Initializable initializable = (Initializable)obj; | |||||
initializable.initialize(); | |||||
} | |||||
} | |||||
// Register some standard roles | |||||
// Add some core roles | |||||
final RoleManager roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | |||||
roleManager.addRole( new RoleInfo( DataType.ROLE, DATA_TYPE_ROLE, DataType.class ) ); | |||||
roleManager.addRole( new RoleInfo( Converter.ROLE, CONVERTER_ROLE, Converter.class ) ); | |||||
roleManager.addRole( new RoleInfo( ServiceFactory.ROLE, SERVICE_FACTORY_ROLE, ServiceFactory.class ) ); | |||||
} | |||||
return m_serviceManager; | |||||
} | |||||
/** | |||||
* Creates the parameters for the test. Sub-classes can override this | |||||
* method to set-up the parameters. | |||||
*/ | |||||
protected Map getParameters() | |||||
{ | |||||
final Map parameters = new HashMap(); | |||||
final File homeDir = getInstallDirectory(); | |||||
parameters.put( "myrmidon.home", homeDir ); | |||||
parameters.put( "myrmidon.ext.path", new File[] { new File ( homeDir, "ext" ) } ); | |||||
return parameters; | |||||
} | |||||
/** | |||||
* Creates an instance of a test component. Sub-classes can override this | |||||
* method to add a particular implementation to the set of test components. | |||||
*/ | |||||
protected Object createComponent( final String role, final Class defaultImpl ) | |||||
throws Exception | |||||
{ | |||||
if( role.equals( ClassLoaderManager.ROLE ) ) | |||||
{ | |||||
return new DefaultClassLoaderManager( getClass().getClassLoader() ); | |||||
} | |||||
return defaultImpl.newInstance(); | |||||
} | |||||
/** | |||||
* Returns the type manager. | |||||
*/ | |||||
protected TypeManager getTypeManager() | |||||
throws Exception | |||||
{ | |||||
return (TypeManager)getServiceManager().lookup( TypeManager.ROLE ); | |||||
} | |||||
/** | |||||
* Utility method to register a role. | |||||
*/ | |||||
protected void registerRole( final RoleInfo roleInfo ) | |||||
throws Exception | |||||
{ | |||||
RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | |||||
roleMgr.addRole( roleInfo ); | |||||
} | |||||
/** | |||||
* Utility method to register a type. | |||||
*/ | |||||
protected void registerType( final String roleName, | |||||
final String typeName, | |||||
final Class type ) | |||||
throws Exception | |||||
{ | |||||
final ClassLoader loader = getClass().getClassLoader(); | |||||
final DefaultTypeFactory factory = new DefaultTypeFactory( loader ); | |||||
factory.addNameClassMapping( typeName, type.getName() ); | |||||
getTypeManager().registerType( roleName, typeName, factory ); | |||||
} | |||||
/** | |||||
* Utility method to register a Converter. | |||||
*/ | |||||
protected void registerConverter( final Class converterClass, | |||||
final Class sourceClass, | |||||
final Class destClass ) | |||||
throws Exception | |||||
{ | |||||
ConverterRegistry converterRegistry = (ConverterRegistry)getServiceManager().lookup( ConverterRegistry.ROLE ); | |||||
converterRegistry.registerConverter( converterClass.getName(), sourceClass.getName(), destClass.getName() ); | |||||
DefaultTypeFactory factory = new DefaultTypeFactory( getClass().getClassLoader() ); | |||||
factory.addNameClassMapping( converterClass.getName(), converterClass.getName() ); | |||||
getTypeManager().registerType( Converter.ROLE, converterClass.getName(), factory ); | |||||
} | |||||
} |
@@ -1,302 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.builder.test; | |||||
import java.io.File; | |||||
import java.util.Arrays; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.avalon.excalibur.io.FileUtil; | |||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
import org.apache.myrmidon.components.builder.DefaultProjectBuilder; | |||||
import org.apache.myrmidon.components.builder.DefaultProject; | |||||
import org.apache.myrmidon.interfaces.builder.ProjectException; | |||||
import org.apache.myrmidon.interfaces.model.Project; | |||||
/** | |||||
* Test cases for {@link org.apache.myrmidon.components.builder.DefaultProjectBuilder}. | |||||
* | |||||
* @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class DefaultProjectBuilderTestCase | |||||
extends AbstractMyrmidonTest | |||||
{ | |||||
private final static Resources REZ = getResourcesForTested( DefaultProjectBuilderTestCase.class ); | |||||
private DefaultProjectBuilder m_builder; | |||||
public DefaultProjectBuilderTestCase( String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
protected void setUp() throws Exception | |||||
{ | |||||
super.setUp(); | |||||
m_builder = new DefaultProjectBuilder(); | |||||
m_builder.enableLogging( getLogger() ); | |||||
} | |||||
/** | |||||
* Creates a project, with default values set. | |||||
*/ | |||||
private DefaultProject createProject( final File projFile ) | |||||
{ | |||||
final DefaultProject project = new DefaultProject(); | |||||
project.setProjectName( FileUtil.removeExtension( projFile.getName() ) ); | |||||
project.setBaseDirectory( getTestDirectory( "." ) ); | |||||
project.setDefaultTargetName( "main" ); | |||||
return project; | |||||
} | |||||
/** | |||||
* Tests bad project file name. | |||||
*/ | |||||
public void testProjectFileName() throws Exception | |||||
{ | |||||
// Test with a file that does not exist | |||||
File projFile = getTestResource( "unknown.ant", false ); | |||||
try | |||||
{ | |||||
m_builder.build( projFile.getAbsolutePath() ); | |||||
fail(); | |||||
} | |||||
catch( ProjectException e ) | |||||
{ | |||||
final String[] messages = | |||||
{ | |||||
REZ.getString( "ant.project-build.error", projFile.getAbsolutePath() ), | |||||
REZ.getString( "ant.no-project-file.error" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
// Test with a directory | |||||
projFile = getTestDirectory( "some-dir" ); | |||||
try | |||||
{ | |||||
m_builder.build( projFile.getAbsolutePath() ); | |||||
fail(); | |||||
} | |||||
catch( ProjectException e ) | |||||
{ | |||||
final String[] messages = | |||||
{ | |||||
REZ.getString( "ant.project-build.error", projFile.getAbsolutePath() ), | |||||
REZ.getString( "ant.no-project-file.error" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests error reporting when the project file contains badly formed XML. | |||||
*/ | |||||
public void testBadlyFormedFile() throws Exception | |||||
{ | |||||
final File projFile = getTestResource( "bad-xml.ant" ); | |||||
try | |||||
{ | |||||
m_builder.build( projFile.getAbsolutePath() ); | |||||
fail(); | |||||
} | |||||
catch( ProjectException e ) | |||||
{ | |||||
final String[] messages = | |||||
{ | |||||
REZ.getString( "ant.project-build.error", projFile.getAbsolutePath() ), | |||||
REZ.getString( "ant.project-parse.error" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests building a project with default values for project name, base dir | |||||
* and default target. | |||||
*/ | |||||
public void testDefaults() throws Exception | |||||
{ | |||||
// Build project | |||||
final File projFile = getTestResource( "defaults.ant" ); | |||||
Project project = m_builder.build( projFile.getAbsolutePath() ); | |||||
// Compare against expected project | |||||
DefaultProject expected = createProject( projFile ); | |||||
assertSameProject( expected, project ); | |||||
} | |||||
/** | |||||
* Tests setting the project name. | |||||
*/ | |||||
public void testProjectName() throws Exception | |||||
{ | |||||
// Build project | |||||
final File projFile = getTestResource( "set-project-name.ant" ); | |||||
Project project = m_builder.build( projFile.getAbsolutePath() ); | |||||
// Compare against expected project | |||||
DefaultProject expected = createProject( projFile ); | |||||
expected.setProjectName( "some-project" ); | |||||
assertSameProject( expected, project ); | |||||
} | |||||
/** | |||||
* Tests setting the base directory. | |||||
*/ | |||||
public void testBaseDirectory() throws Exception | |||||
{ | |||||
// Build project | |||||
final File projFile = getTestResource( "set-base-dir.ant" ); | |||||
Project project = m_builder.build( projFile.getAbsolutePath() ); | |||||
// Compare against expected project | |||||
DefaultProject expected = createProject( projFile ); | |||||
final File baseDir = getTestDirectory( "other-base-dir" ); | |||||
expected.setBaseDirectory( baseDir ); | |||||
assertSameProject( expected, project ); | |||||
} | |||||
/** | |||||
* Tests setting the default target name. | |||||
*/ | |||||
public void testDefaultTarget() throws Exception | |||||
{ | |||||
// Build project | |||||
final File projFile = getTestResource( "set-default-target.ant" ); | |||||
Project project = m_builder.build( projFile.getAbsolutePath() ); | |||||
// Compare against expected project | |||||
DefaultProject expected = createProject( projFile ); | |||||
expected.setDefaultTargetName( "some-target" ); | |||||
assertSameProject( expected, project ); | |||||
} | |||||
/** | |||||
* Tests missing, invalid and incompatible project version. | |||||
*/ | |||||
public void testProjectVersion() throws Exception | |||||
{ | |||||
// No version | |||||
File projFile = getTestResource( "no-version.ant" ); | |||||
try | |||||
{ | |||||
m_builder.build( projFile.getAbsolutePath() ); | |||||
fail(); | |||||
} | |||||
catch( ProjectException e ) | |||||
{ | |||||
final String[] messages = | |||||
{ | |||||
REZ.getString( "ant.project-build.error", projFile.getAbsolutePath() ), | |||||
REZ.getString( "ant.version-missing.error" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
// Badly formed version | |||||
projFile = getTestResource( "bad-version.ant" ); | |||||
try | |||||
{ | |||||
m_builder.build( projFile.getAbsolutePath() ); | |||||
fail(); | |||||
} | |||||
catch( ProjectException e ) | |||||
{ | |||||
final String[] messages = | |||||
{ | |||||
REZ.getString( "ant.project-build.error", projFile.getAbsolutePath() ), | |||||
REZ.getString( "ant.malformed.version", "ant2" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
// Incompatible version | |||||
projFile = getTestResource( "mismatched-version.ant" ); | |||||
try | |||||
{ | |||||
m_builder.build( projFile.getAbsolutePath() ); | |||||
fail(); | |||||
} | |||||
catch( ProjectException e ) | |||||
{ | |||||
final String[] messages = | |||||
{ | |||||
REZ.getString( "ant.project-build.error", projFile.getAbsolutePath() ), | |||||
REZ.getString( "ant.bad-version.error", "2.0.0", "1.0.2" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
} | |||||
/** | |||||
* Asserts that 2 projects are identical. | |||||
*/ | |||||
protected void assertSameProject( final Project expected, | |||||
final Project project ) | |||||
{ | |||||
assertEquals( expected.getProjectName(), project.getProjectName() ); | |||||
assertEquals( expected.getBaseDirectory(), project.getBaseDirectory() ); | |||||
assertEquals( expected.getDefaultTargetName(), project.getDefaultTargetName() ); | |||||
// TODO - make sure each of the projects are the same | |||||
assertTrue( Arrays.equals( expected.getProjectNames(), project.getProjectNames() ) ); | |||||
// TODO - make sure the implicit targets are the same | |||||
// TODO - make sure each of the targets are the same | |||||
assertTrue( Arrays.equals( expected.getTargetNames(), project.getTargetNames() ) ); | |||||
// TODO - implement TypeLib.equals(), or use a comparator | |||||
assertTrue( Arrays.equals( expected.getTypeLibs(), project.getTypeLibs() ) ); | |||||
} | |||||
/** | |||||
* Tests validation of project and target names. | |||||
*/ | |||||
public void testNameValidation() throws Exception | |||||
{ | |||||
// Check bad project name | |||||
final File badProjectFile = getTestResource( "bad-project-name.ant" ); | |||||
try | |||||
{ | |||||
m_builder.build( badProjectFile.getAbsolutePath() ); | |||||
fail(); | |||||
} | |||||
catch( Exception e ) | |||||
{ | |||||
final String[] messages = | |||||
{ | |||||
REZ.getString( "ant.project-build.error", badProjectFile.getAbsolutePath() ), | |||||
REZ.getString( "ant.project-bad-name.error" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
// Check bad target name | |||||
final File badTargetFile = getTestResource( "bad-target-name.ant" ); | |||||
try | |||||
{ | |||||
m_builder.build( badTargetFile.getAbsolutePath() ); | |||||
fail(); | |||||
} | |||||
catch( Exception e ) | |||||
{ | |||||
final String[] messages = | |||||
{ | |||||
REZ.getString( "ant.project-build.error", badTargetFile.getAbsolutePath() ), | |||||
// TODO - check error message | |||||
null | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
} | |||||
} |
@@ -1,4 +0,0 @@ | |||||
<!-- Project with an invalid name --> | |||||
<project version="2.0" name="!badname"> | |||||
<target name="main"/> | |||||
</project> |
@@ -1,5 +0,0 @@ | |||||
<!-- Target with an invalid name --> | |||||
<project version="2.0" name="ok name"> | |||||
<target name="main"/> | |||||
<target name="bad ^ name"/> | |||||
</project> |
@@ -1,3 +0,0 @@ | |||||
<!-- Project with invalid version --> | |||||
<project version="ant2"> | |||||
</project> |
@@ -1 +0,0 @@ | |||||
this ain't xml. |
@@ -1,3 +0,0 @@ | |||||
<!-- Use all the defaults --> | |||||
<project version="2.0"> | |||||
</project> |
@@ -1,3 +0,0 @@ | |||||
<!-- Project with mismatched version --> | |||||
<project version="1.0.2"> | |||||
</project> |
@@ -1,3 +0,0 @@ | |||||
<!-- Project with no version attribute --> | |||||
<project> | |||||
</project> |
@@ -1,3 +0,0 @@ | |||||
<!-- Project with a non-default base directory --> | |||||
<project version="2.0" basedir="other-base-dir"> | |||||
</project> |
@@ -1,3 +0,0 @@ | |||||
<!-- Project with a non-default default target --> | |||||
<project version="2.0" default="some-target"> | |||||
</project> |
@@ -1,3 +0,0 @@ | |||||
<!-- Project with non-default name --> | |||||
<project name="some-project" version="2.0"> | |||||
</project > |
@@ -1,364 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.classloader.test; | |||||
import java.io.File; | |||||
import java.net.URL; | |||||
import java.net.URLClassLoader; | |||||
import java.util.Enumeration; | |||||
import java.util.Map; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.myrmidon.components.AbstractComponentTest; | |||||
import org.apache.myrmidon.components.classloader.DefaultClassLoaderManager; | |||||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderException; | |||||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager; | |||||
/** | |||||
* Test cases for the DefaultClassLoaderManager. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class DefaultClassLoaderManagerTestCase | |||||
extends AbstractComponentTest | |||||
{ | |||||
private static final String UNSHARED_PKG_NAME = | |||||
getPackageName( DefaultClassLoaderManagerTestCase.class ) + ".libs.unshared"; | |||||
private static final String UNSHARED_RES_NAME = getResourceName( UNSHARED_PKG_NAME, "unshared.txt" ); | |||||
private static final String UNSHARED_CLASS_NAME = UNSHARED_PKG_NAME + ".UnsharedClass"; | |||||
private static final String SHARED_PKG_NAME = | |||||
getPackageName( DefaultClassLoaderManagerTestCase.class ) + ".libs.shared"; | |||||
private static final String SHARED_RES_NAME = getResourceName( SHARED_PKG_NAME, "shared.txt" ); | |||||
private static final String SHARED_CLASS_NAME = SHARED_PKG_NAME + ".SharedClass"; | |||||
private static final String EXTN_PKG_NAME = | |||||
getPackageName( DefaultClassLoaderManagerTestCase.class ) + ".libs.extn"; | |||||
private static final String EXTN_RES_NAME = getResourceName( EXTN_PKG_NAME, "extn.txt" ); | |||||
private static final String EXTN_CLASS_NAME = EXTN_PKG_NAME + ".ExtnClass"; | |||||
private File m_commonJar; | |||||
private ClassLoader m_commonClassLoader; | |||||
private ClassLoaderManager m_loaderManager; | |||||
public DefaultClassLoaderManagerTestCase( final String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Sets up the test. | |||||
*/ | |||||
protected void setUp() throws Exception | |||||
{ | |||||
m_commonJar = getTestResource( "common.jar" ); | |||||
final URL commonJarUrl = m_commonJar.toURL(); | |||||
m_commonClassLoader = new URLClassLoader( new URL[]{commonJarUrl} ); | |||||
assertClassFound( m_commonClassLoader, SHARED_CLASS_NAME ); | |||||
assertResourcesFound( m_commonClassLoader, SHARED_RES_NAME, m_commonJar ); | |||||
// Create the classloader mgr | |||||
m_loaderManager = (ClassLoaderManager)getServiceManager().lookup( ClassLoaderManager.ROLE ); | |||||
} | |||||
/** | |||||
* Creates an instance of a test component. | |||||
*/ | |||||
protected Object createComponent( final String role, final Class defaultImpl ) | |||||
throws Exception | |||||
{ | |||||
if( role.equals( ClassLoaderManager.ROLE ) ) | |||||
{ | |||||
return new DefaultClassLoaderManager( m_commonClassLoader ); | |||||
} | |||||
else | |||||
{ | |||||
return super.createComponent( role, defaultImpl ); | |||||
} | |||||
} | |||||
/** | |||||
* Creates the parameters for the test. Sub-classes can override this | |||||
* method to set-up the parameters. | |||||
*/ | |||||
protected Map getParameters() | |||||
{ | |||||
final Map parameters = super.getParameters(); | |||||
parameters.put( "myrmidon.ext.path", new File[] { getTestDirectory( "ext" ) } ); | |||||
return parameters; | |||||
} | |||||
/** | |||||
* Returns the name of a resource in a package. | |||||
*/ | |||||
private static String getResourceName( final String pkgName, | |||||
final String resname ) | |||||
{ | |||||
return pkgName.replace( '.', '/' ) + '/' + resname; | |||||
} | |||||
/** | |||||
* Asserts that a class is not available in a classloader. | |||||
*/ | |||||
private void assertClassNotFound( final ClassLoader classLoader, | |||||
final String className ) | |||||
{ | |||||
try | |||||
{ | |||||
classLoader.loadClass( className ); | |||||
fail( "Class " + className + " should not be available." ); | |||||
} | |||||
catch( ClassNotFoundException e ) | |||||
{ | |||||
} | |||||
} | |||||
/** | |||||
* Asserts that a class is available in a classloader. | |||||
*/ | |||||
private void assertClassFound( final ClassLoader classLoader, | |||||
final String className ) | |||||
throws Exception | |||||
{ | |||||
assertClassFound( classLoader, className, classLoader ); | |||||
} | |||||
/** | |||||
* Asserts that a class is available in a classloader. | |||||
*/ | |||||
private void assertClassFound( final ClassLoader classLoader, | |||||
final String className, | |||||
final ClassLoader expectedClassLoader ) | |||||
throws Exception | |||||
{ | |||||
try | |||||
{ | |||||
final Class cls = classLoader.loadClass( className ); | |||||
assertSame( expectedClassLoader, cls.getClassLoader() ); | |||||
if( classLoader != expectedClassLoader ) | |||||
{ | |||||
final Class expectedCls = expectedClassLoader.loadClass( className ); | |||||
assertSame( expectedCls, cls ); | |||||
} | |||||
} | |||||
catch( ClassNotFoundException e ) | |||||
{ | |||||
fail( "Class " + className + " not found." ); | |||||
} | |||||
} | |||||
/** | |||||
* Asserts that a resouce is not available in a classloader. | |||||
*/ | |||||
private void assertResourceNotFound( final ClassLoader classLoader, | |||||
final String resName ) | |||||
throws Exception | |||||
{ | |||||
assertNull( classLoader.getResource( resName ) ); | |||||
assertNull( classLoader.getResourceAsStream( resName ) ); | |||||
final Enumeration enum = classLoader.getResources( resName ); | |||||
assertTrue( !enum.hasMoreElements() ); | |||||
} | |||||
/** | |||||
* Asserts that a resource is available in a classloader. | |||||
*/ | |||||
private void assertResourcesFound( final ClassLoader classLoader, | |||||
final String resName, | |||||
final File expectedJar ) | |||||
throws Exception | |||||
{ | |||||
assertResourcesFound( classLoader, resName, new File[]{expectedJar} ); | |||||
} | |||||
/** | |||||
* Asserts that a resource is available in a classloader. | |||||
*/ | |||||
private void assertResourcesFound( final ClassLoader classLoader, | |||||
final String resName, | |||||
final File[] expectedJars ) | |||||
throws Exception | |||||
{ | |||||
final String[] expectedLocations = new String[ expectedJars.length ]; | |||||
for( int i = 0; i < expectedJars.length; i++ ) | |||||
{ | |||||
final File jar = expectedJars[ i ]; | |||||
expectedLocations[ i ] = "jar:" + jar.toURL() + "!/" + resName; | |||||
} | |||||
assertResourcesFound( classLoader, resName, expectedLocations ); | |||||
} | |||||
/** | |||||
* Asserts that a resource is available in a classloader. | |||||
*/ | |||||
private void assertResourcesFound( final ClassLoader classLoader, | |||||
final String resName, | |||||
final String[] expectedLocations ) | |||||
throws Exception | |||||
{ | |||||
// Use the first in the list of expected locations as the location | |||||
// of the resource returned by getResource() | |||||
final URL resUrl = classLoader.getResource( resName ); | |||||
assertNotNull( resUrl ); | |||||
assertEquals( expectedLocations[ 0 ], resUrl.toString() ); | |||||
// Now check all of the resources returned by getResources() | |||||
final Enumeration resources = classLoader.getResources( resName ); | |||||
for( int i = 0; i < expectedLocations.length; i++ ) | |||||
{ | |||||
final String expectedLocation = expectedLocations[ i ]; | |||||
assertTrue( resources.hasMoreElements() ); | |||||
final URL location = (URL)resources.nextElement(); | |||||
assertEquals( expectedLocation, location.toString() ); | |||||
} | |||||
assertTrue( !resources.hasMoreElements() ); | |||||
} | |||||
/** | |||||
* Tests for a Jar with no required extensions. | |||||
*/ | |||||
public void testNoDependencies() throws Exception | |||||
{ | |||||
// Make some assumptions about the common classloader | |||||
assertClassNotFound( m_commonClassLoader, UNSHARED_CLASS_NAME ); | |||||
assertResourceNotFound( m_commonClassLoader, UNSHARED_RES_NAME ); | |||||
// Build the classloader | |||||
final File jarFile = getTestResource( "no-dependencies.jar" ); | |||||
final ClassLoader classLoader = m_loaderManager.getClassLoader( jarFile ); | |||||
// Check shared classes/resources | |||||
assertClassFound( classLoader, SHARED_CLASS_NAME, m_commonClassLoader ); | |||||
assertResourcesFound( classLoader, SHARED_RES_NAME, new File[]{m_commonJar, jarFile} ); | |||||
// Check unshared classes/resources | |||||
assertClassFound( classLoader, UNSHARED_CLASS_NAME ); | |||||
assertResourcesFound( classLoader, UNSHARED_RES_NAME, jarFile ); | |||||
} | |||||
/** | |||||
* Tests ClassLoader caching. | |||||
*/ | |||||
public void testClassLoaderReuse() throws Exception | |||||
{ | |||||
final File jarFile = getTestResource( "no-dependencies.jar" ); | |||||
final ClassLoader classLoader1 = m_loaderManager.getClassLoader( jarFile ); | |||||
final ClassLoader classLoader2 = m_loaderManager.getClassLoader( jarFile ); | |||||
assertSame( classLoader1, classLoader2 ); | |||||
} | |||||
/** | |||||
* Tests for a Jar with a single required extension. | |||||
*/ | |||||
public void testOneDependency() throws Exception | |||||
{ | |||||
// Make some assumptions about the common classloader | |||||
assertClassNotFound( m_commonClassLoader, UNSHARED_CLASS_NAME ); | |||||
assertResourceNotFound( m_commonClassLoader, UNSHARED_RES_NAME ); | |||||
assertClassNotFound( m_commonClassLoader, EXTN_CLASS_NAME ); | |||||
assertResourceNotFound( m_commonClassLoader, EXTN_RES_NAME ); | |||||
// Build the extension classloader | |||||
final File extnJarFile = getTestResource( "ext/simple-extension.jar" ); | |||||
final ClassLoader extnClassLoader = m_loaderManager.getClassLoader( extnJarFile ); | |||||
// Build the Jar classloader | |||||
final File jarFile = getTestResource( "one-dependency.jar" ); | |||||
final ClassLoader classLoader = m_loaderManager.getClassLoader( jarFile ); | |||||
// Check shared classes/resources | |||||
assertClassFound( classLoader, SHARED_CLASS_NAME, m_commonClassLoader ); | |||||
assertResourcesFound( classLoader, SHARED_RES_NAME, new File[]{m_commonJar, extnJarFile, jarFile} ); | |||||
// Check extension classes/resources | |||||
assertClassFound( classLoader, EXTN_CLASS_NAME, extnClassLoader ); | |||||
assertResourcesFound( classLoader, EXTN_RES_NAME, extnJarFile ); | |||||
// Check unshared classes/resources | |||||
assertClassFound( classLoader, UNSHARED_CLASS_NAME ); | |||||
assertResourcesFound( classLoader, UNSHARED_RES_NAME, jarFile ); | |||||
} | |||||
/** | |||||
* Tests that classes from extensions can be shared across classloaders. | |||||
*/ | |||||
public void testShareClasses() throws Exception | |||||
{ | |||||
// Build the extension classloader | |||||
final File extnJarFile = getTestResource( "ext/simple-extension.jar" ); | |||||
final ClassLoader extnClassLoader = m_loaderManager.getClassLoader( extnJarFile ); | |||||
// Build the Jar classloaders | |||||
final File jarFile1 = getTestResource( "one-dependency.jar" ); | |||||
final ClassLoader classLoader1 = m_loaderManager.getClassLoader( jarFile1 ); | |||||
final File jarFile2 = getTestResource( "one-dependency-2.jar" ); | |||||
final ClassLoader classLoader2 = m_loaderManager.getClassLoader( jarFile2 ); | |||||
// Check extension classes/resources | |||||
assertClassFound( classLoader1, EXTN_CLASS_NAME, extnClassLoader ); | |||||
assertResourcesFound( classLoader1, EXTN_RES_NAME, extnJarFile ); | |||||
assertClassFound( classLoader2, EXTN_CLASS_NAME, extnClassLoader ); | |||||
assertResourcesFound( classLoader2, EXTN_RES_NAME, extnJarFile ); | |||||
} | |||||
/** | |||||
* Tests detection of dependency cycles in extensions. | |||||
*/ | |||||
public void testCycle() throws Exception | |||||
{ | |||||
final File jarFile = getTestResource( "ext/cycle-extension-1.jar" ); | |||||
try | |||||
{ | |||||
m_loaderManager.getClassLoader( jarFile ); | |||||
fail(); | |||||
} | |||||
catch( final ClassLoaderException e ) | |||||
{ | |||||
final Resources rez = getResourcesForTested( DefaultClassLoaderManager.class ); | |||||
final String[] messages = { | |||||
rez.getString( "create-classloader-for-file.error", jarFile ), | |||||
rez.getString( "dependency-cycle.error", jarFile ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
} | |||||
/** | |||||
* add some classes to common loader only. | |||||
* | |||||
* unknown extension | |||||
* multiple versions of the same extension | |||||
* extn with requirement on itself | |||||
* | |||||
* jar with 1 and 2 extns: | |||||
* class/resources in parent | |||||
* class/resources in jar | |||||
* class/resources in extn | |||||
* class/resources in all | |||||
* | |||||
* jar with transitive extn | |||||
* class/resources in 2nd extn | |||||
* | |||||
* jar with transitive extn + explicit extn on same jar | |||||
* class/resources in 2nd extn | |||||
* | |||||
* Same classes: | |||||
* get extn explicitly and implicitly, and check classes are the same | |||||
* extn shared by 2 jars, using same extn and different extns | |||||
* classes in common classloader, shared by 2 jars | |||||
* | |||||
* multiple files: | |||||
* fetch classloader twice | |||||
* different path ordering | |||||
* | |||||
* tools.jar | |||||
*/ | |||||
} |
@@ -1,10 +0,0 @@ | |||||
Extension-Name: test.cycle1 | |||||
Specification-Title: Test Extension | |||||
Specification-Version: 1.0.0 | |||||
Specification-Vendor: Jakarta Apache | |||||
Implementation-Vendor-Id: org.apache.myrmidon | |||||
Implementation-Vendor: Apache Myrmidon Project | |||||
Implementation-Version: 3.0 | |||||
Extension-List: cycle2 | |||||
cycle2-Extension-Name: test.cycle2 | |||||
cycle2-Specification-Version: 1.0 |
@@ -1,10 +0,0 @@ | |||||
Extension-Name: test.cycle2 | |||||
Specification-Title: Test Extension | |||||
Specification-Version: 1.0.0 | |||||
Specification-Vendor: Jakarta Apache | |||||
Implementation-Vendor-Id: org.apache.myrmidon | |||||
Implementation-Vendor: Apache Myrmidon Project | |||||
Implementation-Version: 1.709.2 | |||||
Extension-List: cycle1 | |||||
cycle1-Extension-Name: test.cycle1 | |||||
cycle1-Specification-Version: 1.0 |
@@ -1,21 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.classloader.test.libs.extn; | |||||
import org.apache.myrmidon.components.classloader.test.libs.shared.SharedClass; | |||||
/** | |||||
* A test class loaded from an extension. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ExtnClass | |||||
{ | |||||
public SharedClass m_test = new SharedClass(); | |||||
} |
@@ -1 +0,0 @@ | |||||
A test resource loaded from an extension. |
@@ -1,3 +0,0 @@ | |||||
Extension-List: extension1 | |||||
extension1-Extension-Name: test.simple | |||||
extension1-Specification-Version: 1.0 |
@@ -1,18 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.classloader.test.libs.shared; | |||||
/** | |||||
* A test class. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class SharedClass | |||||
{ | |||||
} |
@@ -1 +0,0 @@ | |||||
A shared resource. |
@@ -1,7 +0,0 @@ | |||||
Extension-Name: test.simple | |||||
Specification-Title: Test Simple Extension | |||||
Specification-Version: 1.0.0 | |||||
Specification-Vendor: Jakarta Apache | |||||
Implementation-Vendor-Id: org.apache.myrmidon | |||||
Implementation-Vendor: Apache Myrmidon Project | |||||
Implementation-Version: 1.0.2 |
@@ -1,21 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.classloader.test.libs.unshared; | |||||
import org.apache.myrmidon.components.classloader.test.libs.shared.SharedClass; | |||||
/** | |||||
* A test class. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class UnsharedClass | |||||
{ | |||||
public SharedClass m_test = new SharedClass(); | |||||
} |
@@ -1 +0,0 @@ | |||||
An unshared resource. |
@@ -1,36 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test; | |||||
import org.apache.avalon.framework.configuration.Configurable; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
/** | |||||
* Simple class to test {@link org.apache.avalon.framework.configuration.Configurable}. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestConfigurable | |||||
implements Configurable | |||||
{ | |||||
private Configuration m_configuration; | |||||
public void configure( Configuration configuration ) | |||||
throws ConfigurationException | |||||
{ | |||||
m_configuration = configuration; | |||||
} | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
final ConfigTestConfigurable other = (ConfigTestConfigurable)object; | |||||
return m_configuration == other.m_configuration; | |||||
} | |||||
} |
@@ -1,896 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test; | |||||
import java.io.File; | |||||
import org.apache.aut.converter.lib.StringToIntegerConverter; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.avalon.framework.ExceptionUtil; | |||||
import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
import org.apache.avalon.framework.configuration.DefaultConfiguration; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
import org.apache.myrmidon.components.AbstractComponentTest; | |||||
import org.apache.myrmidon.components.store.DefaultPropertyStore; | |||||
import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestAttributeConvert; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestConfigAdder; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestContent; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestEmpty; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestIdResolve; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestIgnoreStringMethods; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestInterfaceAdder; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestMismatchedRefType; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestMultipleTypedAdder; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestNestedErrors; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestNonInterfaceAdder; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestPropResolution; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceAttribute; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceConversion; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceElement; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetAndAdd; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetAttribute; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetElement; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdder; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdderConversion; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdderReference; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdderRole; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedConfigAdder; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestUnknownReference; | |||||
import org.apache.myrmidon.components.workspace.DefaultTaskContext; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | |||||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
/** | |||||
* Test cases for the default configurer and related classes. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class DefaultConfigurerTestCase | |||||
extends AbstractComponentTest | |||||
{ | |||||
private final static Resources REZ = | |||||
getResourcesForTested( DefaultConfigurerTestCase.class ); | |||||
private Configurer m_configurer; | |||||
private DefaultTaskContext m_context; | |||||
public DefaultConfigurerTestCase( String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Setup the test case - prepares a set of components, including the | |||||
* configurer. | |||||
*/ | |||||
protected void setUp() throws Exception | |||||
{ | |||||
super.setUp(); | |||||
// Find the configurer | |||||
m_configurer = (Configurer)getServiceManager().lookup( Configurer.ROLE ); | |||||
// Setup a context | |||||
final DefaultPropertyStore store = new DefaultPropertyStore(); | |||||
m_context = | |||||
new DefaultTaskContext( getServiceManager(), getLogger(), store ); | |||||
final File baseDir = new File( "." ).getAbsoluteFile(); | |||||
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | |||||
} | |||||
/** | |||||
* Creates an instance of a component. Sub-classes can override this | |||||
* method to add a particular implementation to the set of test components. | |||||
*/ | |||||
protected Object createComponent( final String role, final Class defaultImpl ) | |||||
throws Exception | |||||
{ | |||||
if( role.equals( Configurer.ROLE) ) | |||||
{ | |||||
return new DefaultConfigurer(); | |||||
} | |||||
else | |||||
{ | |||||
return super.createComponent( role, defaultImpl ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests setting an attribute, via a setter method. | |||||
*/ | |||||
public void testSetAttribute() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final String value1 = "some value"; | |||||
config.setAttribute( "some-prop", value1 ); | |||||
final ConfigTestSetAttribute test = new ConfigTestSetAttribute(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Check result | |||||
final ConfigTestSetAttribute expected = new ConfigTestSetAttribute(); | |||||
expected.setSomeProp( value1 ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests attribute conversion. | |||||
*/ | |||||
public void testAttributeConvert() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "int-prop", "90" ); | |||||
config.setAttribute( "integer-prop", "-401" ); | |||||
// Register the converter | |||||
registerConverter( StringToIntegerConverter.class, String.class, Integer.class ); | |||||
final ConfigTestAttributeConvert test = new ConfigTestAttributeConvert(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Check result | |||||
final ConfigTestAttributeConvert expected = new ConfigTestAttributeConvert(); | |||||
expected.setIntProp( 90 ); | |||||
expected.setIntegerProp( new Integer( -401 ) ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests setting an unknown attribute. | |||||
*/ | |||||
public void testSetUnknownAttribute() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "unknown", "some value" ); | |||||
final ConfigTestEmpty test = new ConfigTestEmpty(); | |||||
// Configure the object | |||||
try | |||||
{ | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( final ConfigurationException ce ) | |||||
{ | |||||
final String message = REZ.getString( "no-such-attribute.error", "test", "unknown" ); | |||||
assertSameMessage( message, ce ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests setting a nested element, via adder and setter methods. | |||||
*/ | |||||
public void testSetElement() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration child1 = new DefaultConfiguration( "prop", "test" ); | |||||
final String value1 = "some value"; | |||||
child1.setAttribute( "some-prop", value1 ); | |||||
config.addChild( child1 ); | |||||
final DefaultConfiguration child2 = new DefaultConfiguration( "prop", "test" ); | |||||
final String value2 = "another value"; | |||||
child2.setAttribute( "some-prop", value2 ); | |||||
config.addChild( child2 ); | |||||
final ConfigTestSetElement test = new ConfigTestSetElement(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Check result | |||||
final ConfigTestSetElement expected = new ConfigTestSetElement(); | |||||
ConfigTestSetElement elem = new ConfigTestSetElement(); | |||||
elem.setSomeProp( value1 ); | |||||
expected.addProp( elem ); | |||||
elem = new ConfigTestSetElement(); | |||||
elem.setSomeProp( value2 ); | |||||
expected.addProp( elem ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests setting an unknown element. | |||||
*/ | |||||
public void testSetUnknownElement() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration elem = new DefaultConfiguration( "unknown", "test" ); | |||||
config.addChild( elem ); | |||||
final ConfigTestEmpty test = new ConfigTestEmpty(); | |||||
// Configure the object | |||||
try | |||||
{ | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( final ConfigurationException ce ) | |||||
{ | |||||
final String message = REZ.getString( "no-such-element.error", "test", "unknown" ); | |||||
assertSameMessage( message, ce ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests setting the content of an object. | |||||
*/ | |||||
public void testContent() | |||||
throws Exception | |||||
{ | |||||
// Create the test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final String value1 = "some value"; | |||||
config.setValue( value1 ); | |||||
final ConfigTestContent test = new ConfigTestContent(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Check result | |||||
final ConfigTestContent expected = new ConfigTestContent(); | |||||
expected.addContent( value1 ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests setting the content of an object that does not handle it. | |||||
*/ | |||||
public void testUnexpectedContent() | |||||
throws Exception | |||||
{ | |||||
// Create the test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setValue( "some value" ); | |||||
final ConfigTestEmpty test = new ConfigTestEmpty(); | |||||
// Configure the object | |||||
try | |||||
{ | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( final ConfigurationException ce ) | |||||
{ | |||||
final String message = REZ.getString( "no-content.error", "test" ); | |||||
assertSameMessage( message, ce ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests property resolution. | |||||
*/ | |||||
public void testPropResolution() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "prop", "some ${prop-a} value" ); | |||||
final ConfigTestPropResolution test = new ConfigTestPropResolution(); | |||||
m_context.setProperty( "prop-a", "other" ); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Check the configured object | |||||
final ConfigTestPropResolution expected = new ConfigTestPropResolution(); | |||||
expected.setProp( "some other value" ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests reference resolution via an attribute. | |||||
*/ | |||||
public void testReferenceAttribute() throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "some-prop-ref", "prop-a" ); | |||||
final ConfigTestReferenceAttribute test = new ConfigTestReferenceAttribute(); | |||||
m_context.setProperty( "prop-a", "some value" ); | |||||
// Configure the object | |||||
try | |||||
{ | |||||
configure( test, config ); | |||||
} | |||||
catch( ConfigurationException e ) | |||||
{ | |||||
//Expected to fail as -ref no longer supported | |||||
//pattern for attributes | |||||
return; | |||||
} | |||||
fail( "-ref pattern on attributes no longer supported" ); | |||||
// Check the configured object | |||||
//final ConfigTestReferenceAttribute expected = new ConfigTestReferenceAttribute(); | |||||
//expected.setSomeProp( "some value" ); | |||||
//assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests reference resolution via a nested element. | |||||
*/ | |||||
public void testReferenceElement() throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration elem = new DefaultConfiguration( "some-prop-ref", "test" ); | |||||
elem.setAttribute( "id", "prop-a" ); | |||||
config.addChild( elem ); | |||||
final ConfigTestReferenceElement test = new ConfigTestReferenceElement(); | |||||
m_context.setProperty( "prop-a", "some value" ); | |||||
// Configure the object | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
// Check the configured object | |||||
final ConfigTestReferenceElement expected = new ConfigTestReferenceElement(); | |||||
expected.addSomeProp( "some value" ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests that extra content is not allowed in a reference element. | |||||
*/ | |||||
public void testReferenceElementExtra() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration elem = new DefaultConfiguration( "some-prop-ref", "test" ); | |||||
elem.setAttribute( "id", "prop-a" ); | |||||
elem.setAttribute( "extra-attr", "some value" ); | |||||
config.addChild( elem ); | |||||
final ConfigTestReferenceElement test = new ConfigTestReferenceElement(); | |||||
try | |||||
{ | |||||
// Configure the object | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( ConfigurationException e ) | |||||
{ | |||||
final String[] messages = new String[] | |||||
{ | |||||
REZ.getString( "bad-configure-element.error", "some-prop-ref" ), | |||||
REZ.getString( "extra-config-for-ref.error" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests reference type conversion. | |||||
*/ | |||||
public void testReferenceConversion() throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "prop-a-ref", "id" ); | |||||
final Integer refValue = new Integer( 21 ); | |||||
m_context.setProperty( "id", refValue ); | |||||
registerConverter( ObjectToMyRole1Converter.class, Object.class, MyRole1.class ); | |||||
final ConfigTestReferenceConversion test = new ConfigTestReferenceConversion(); | |||||
// Configure | |||||
try | |||||
{ | |||||
configure( test, config ); | |||||
} | |||||
catch( ConfigurationException e ) | |||||
{ | |||||
//Good should no longer work | |||||
return; | |||||
} | |||||
fail( "-ref pattern on attributes no longer supported" ); | |||||
// Check result | |||||
//final ConfigTestReferenceConversion expected = new ConfigTestReferenceConversion(); | |||||
//expected.setPropA( new MyRole1Adaptor( refValue ) ); | |||||
//assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests that the role's default type is used for interface typed | |||||
* elements. | |||||
*/ | |||||
public void testInterfaceAdder() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration child = new DefaultConfiguration( "prop-a", "test" ); | |||||
config.addChild( child ); | |||||
registerRole( new RoleInfo( "myrole1", null, MyRole1.class, "default-type" ) ); | |||||
registerType( "myrole1", "default-type", MyType1.class ); | |||||
final ConfigTestInterfaceAdder test = new ConfigTestInterfaceAdder(); | |||||
// Configure object | |||||
configure( test, config ); | |||||
// Check result | |||||
final ConfigTestInterfaceAdder expected = new ConfigTestInterfaceAdder(); | |||||
expected.addPropA( new MyType1() ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests whether an object with a non-iterface typed adder causes an | |||||
* exception. | |||||
*/ | |||||
public void testNonInterfaceTypedAdder() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final ConfigTestNonInterfaceAdder test = new ConfigTestNonInterfaceAdder(); | |||||
try | |||||
{ | |||||
// Configure the object | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( final ConfigurationException ce ) | |||||
{ | |||||
final String[] messages = { | |||||
REZ.getString( "bad-configure-element.error", "test" ), | |||||
REZ.getString( "typed-adder-non-interface.error", | |||||
ConfigTestNonInterfaceAdder.class.getName(), | |||||
Integer.class.getName() ) | |||||
}; | |||||
assertSameMessage( messages, ce ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests whether an object with multiple typed adders causes an exception. | |||||
*/ | |||||
public void testMultipleTypedAdder() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final ConfigTestMultipleTypedAdder test = new ConfigTestMultipleTypedAdder(); | |||||
try | |||||
{ | |||||
// Configure the object | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( final ConfigurationException ce ) | |||||
{ | |||||
final String[] messages = new String[] | |||||
{ | |||||
REZ.getString( "bad-configure-element.error", "test" ), | |||||
REZ.getString( "multiple-methods-for-element.error", | |||||
ConfigTestMultipleTypedAdder.class.getName(), | |||||
"add" ) | |||||
}; | |||||
assertSameMessage( messages, ce ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests to see if typed adder works, with iterface types. | |||||
*/ | |||||
public void testTypedAdder() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration child1 = new DefaultConfiguration( "my-type1", "test" ); | |||||
final DefaultConfiguration child2 = new DefaultConfiguration( "my-type2", "test" ); | |||||
config.addChild( child1 ); | |||||
config.addChild( child2 ); | |||||
registerRole( new RoleInfo( MyRole1.ROLE, "my-role1", MyRole1.class ) ); | |||||
registerType( MyRole1.ROLE, "my-type1", MyType1.class ); | |||||
registerType( MyRole1.ROLE, "my-type2", MyType2.class ); | |||||
final ConfigTestTypedAdder test = new ConfigTestTypedAdder(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
final ConfigTestTypedAdder expected = new ConfigTestTypedAdder(); | |||||
expected.add( new MyType1() ); | |||||
expected.add( new MyType2() ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests to check that role is used for typed adder. | |||||
*/ | |||||
public void testTypedAdderRole() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration child1 = new DefaultConfiguration( "my-type1", "test" ); | |||||
config.addChild( child1 ); | |||||
// Register incompatible types with the same name, as data-type and myrole1. | |||||
registerRole( new RoleInfo( "myrole1", "myrole1", MyRole1.class ) ); | |||||
registerType( "myrole1", "my-type1", MyType1.class ); | |||||
registerType( DataType.ROLE, "my-type1", StringBuffer.class ); | |||||
final ConfigTestTypedAdderRole test = new ConfigTestTypedAdderRole(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Check the result | |||||
final ConfigTestTypedAdderRole expected = new ConfigTestTypedAdderRole(); | |||||
expected.add( new MyType1() ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests conversion with a typed adder. | |||||
*/ | |||||
public void testTypedAdderConversion() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration child = new DefaultConfiguration( "some-type", "test" ); | |||||
child.setAttribute( "prop", "some value" ); | |||||
config.addChild( child ); | |||||
registerType( DataType.ROLE, "some-type", ConfigTestTypedAdderConversion.class ); | |||||
registerConverter( ObjectToMyRole1Converter.class, Object.class, MyRole1.class ); | |||||
final ConfigTestTypedAdderConversion test = new ConfigTestTypedAdderConversion(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Check the result | |||||
final ConfigTestTypedAdderConversion expected = new ConfigTestTypedAdderConversion(); | |||||
final ConfigTestTypedAdderConversion nested = new ConfigTestTypedAdderConversion(); | |||||
nested.setProp( "some value" ); | |||||
expected.add( new MyRole1Adaptor( nested ) ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests to see if typed adder works, with Configuration type. | |||||
*/ | |||||
public void testTypedConfigAdder() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration child1 = new DefaultConfiguration( "my-type1", "test" ); | |||||
final DefaultConfiguration child2 = new DefaultConfiguration( "my-type2", "test" ); | |||||
config.addChild( child1 ); | |||||
config.addChild( child2 ); | |||||
final ConfigTestTypedConfigAdder test = new ConfigTestTypedConfigAdder(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
final ConfigTestTypedConfigAdder expected = new ConfigTestTypedConfigAdder(); | |||||
expected.add( child1 ); | |||||
expected.add( child2 ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests to see if adder works, with Configuration objects. | |||||
*/ | |||||
public void testConfigAdder() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration child1 = new DefaultConfiguration( "config", "test" ); | |||||
final DefaultConfiguration child2 = new DefaultConfiguration( "config", "test" ); | |||||
config.addChild( child1 ); | |||||
config.addChild( child2 ); | |||||
final ConfigTestConfigAdder test = new ConfigTestConfigAdder(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
final ConfigTestConfigAdder expected = new ConfigTestConfigAdder(); | |||||
expected.addConfig( child1 ); | |||||
expected.addConfig( child2 ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests to check that Configurable is handled properly. | |||||
*/ | |||||
public void testConfigurable() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final ConfigTestConfigurable test = new ConfigTestConfigurable(); | |||||
// Configure the object | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
final ConfigTestConfigurable expected = new ConfigTestConfigurable(); | |||||
expected.configure( config ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Test resolving properties in an id. | |||||
*/ | |||||
public void testIdResolve() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "some-prop-ref", "${id}" ); | |||||
final ConfigTestIdResolve test = new ConfigTestIdResolve(); | |||||
m_context.setProperty( "id", "prop-a" ); | |||||
m_context.setProperty( "prop-a", "some indirect value" ); | |||||
// Configure the object | |||||
try | |||||
{ | |||||
configure( test, config ); | |||||
} | |||||
catch( ConfigurationException e ) | |||||
{ | |||||
return; | |||||
} | |||||
fail( "-ref pattern on attributes no longer supported" ); | |||||
// Check the configured object | |||||
//final ConfigTestIdResolve expected = new ConfigTestIdResolve(); | |||||
//expected.setSomeProp( "some indirect value" ); | |||||
//assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests an unknown reference. | |||||
*/ | |||||
public void __testUnknownReference() | |||||
throws Exception | |||||
{ | |||||
//Should rework | |||||
fail( "-ref pattern on attributes no longer supported" ); | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "some-prop-ref", "unknown-prop" ); | |||||
final ConfigTestUnknownReference test = new ConfigTestUnknownReference(); | |||||
// Configure the object | |||||
try | |||||
{ | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( ConfigurationException e ) | |||||
{ | |||||
final String[] messages = new String[] | |||||
{ | |||||
REZ.getString( "bad-set-attribute.error", "test", "some-prop-ref" ), | |||||
REZ.getString( "unknown-reference.error", "unknown-prop" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests handling of mismatched reference type. | |||||
*/ | |||||
public void __testMismatchedRefType() | |||||
throws Exception | |||||
{ | |||||
//FIXME: rework testcase | |||||
fail( "-ref pattern on attributes no longer supported" ); | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "some-prop-ref", "prop-a" ); | |||||
final ConfigTestMismatchedRefType test = new ConfigTestMismatchedRefType(); | |||||
m_context.setProperty( "prop-a", new Integer( 23 ) ); | |||||
// Configure the object | |||||
try | |||||
{ | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( ConfigurationException e ) | |||||
{ | |||||
final String[] messages = new String[] | |||||
{ | |||||
REZ.getString( "bad-set-attribute.error", "test", "some-prop-ref" ), | |||||
REZ.getString( "mismatch-ref-types.error", | |||||
"prop-a", | |||||
"some-prop" ) | |||||
}; | |||||
assertSameMessage( messages, e ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests using a reference with a typed adder. Tests using an attribute | |||||
* and a nested element. | |||||
*/ | |||||
public void testTypedAdderReference() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration child = new DefaultConfiguration( "my-role1-ref", "test" ); | |||||
child.setAttribute( "id", "id2" ); | |||||
config.addChild( child ); | |||||
// Add role mapping, and add to reference to context | |||||
registerRole( new RoleInfo( "my-role1", MyRole1.class ) ); | |||||
m_context.setProperty( "id2", new MyType2() ); | |||||
final ConfigTestTypedAdderReference test = new ConfigTestTypedAdderReference(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Compare against expected value | |||||
final ConfigTestTypedAdderReference expected = new ConfigTestTypedAdderReference(); | |||||
expected.add( new MyType2() ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests reporting of nested errors. | |||||
*/ | |||||
public void testNestedErrors() throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
final DefaultConfiguration elem = new DefaultConfiguration( "prop", "test" ); | |||||
elem.setAttribute( "not-a-prop", "not-a-value" ); | |||||
config.addChild( elem ); | |||||
final ConfigTestNestedErrors test = new ConfigTestNestedErrors(); | |||||
try | |||||
{ | |||||
// Configure the object | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
fail(); | |||||
} | |||||
catch( ConfigurationException e ) | |||||
{ | |||||
final String message = REZ.getString( "no-such-attribute.error", | |||||
"prop", | |||||
"not-a-prop" ); | |||||
assertSameMessage( message, e ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests that string setter/adder/creators are ignored when there | |||||
* are multiple. | |||||
*/ | |||||
public void testIgnoreStringMethods() | |||||
throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "prop1", "some-value" ); | |||||
config.setValue( "99" ); | |||||
DefaultConfiguration elem = new DefaultConfiguration( "prop2", "test" ); | |||||
config.addChild( elem ); | |||||
elem = new DefaultConfiguration( "my-type1", "test" ); | |||||
config.addChild( elem ); | |||||
registerConverter( ObjectToMyRole1Converter.class, String.class, MyRole1.class ); | |||||
registerConverter( StringToIntegerConverter.class, String.class, Integer.class ); | |||||
registerType( DataType.ROLE, "my-type1", MyType1.class ); | |||||
final ConfigTestIgnoreStringMethods test = new ConfigTestIgnoreStringMethods(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Test expected value | |||||
final ConfigTestIgnoreStringMethods expected = new ConfigTestIgnoreStringMethods(); | |||||
expected.setProp1( new MyRole1Adaptor( "some-value" ) ); | |||||
expected.addProp2( new ConfigTestIgnoreStringMethods() ); | |||||
expected.add( new MyType1() ); | |||||
expected.addContent( 99 ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
/** | |||||
* Tests that a class with a setter and adder with the same property name | |||||
* is handled correctly. | |||||
*/ | |||||
public void testSetAndAdd() throws Exception | |||||
{ | |||||
// Setup test data | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | |||||
config.setAttribute( "prop", "some value" ); | |||||
DefaultConfiguration elem = new DefaultConfiguration( "prop", "test" ); | |||||
elem.setAttribute( "prop", "another value" ); | |||||
config.addChild( elem ); | |||||
final ConfigTestSetAndAdd test = new ConfigTestSetAndAdd(); | |||||
// Configure the object | |||||
configure( test, config ); | |||||
// Test expected value | |||||
final ConfigTestSetAndAdd expected = new ConfigTestSetAndAdd(); | |||||
expected.setProp( "some value" ); | |||||
final ConfigTestSetAndAdd nested = new ConfigTestSetAndAdd(); | |||||
nested.setProp( "another value" ); | |||||
expected.addProp( nested ); | |||||
assertEquals( expected, test ); | |||||
} | |||||
private void configure( final Object test, | |||||
final DefaultConfiguration config ) | |||||
throws ConfigurationException | |||||
{ | |||||
try | |||||
{ | |||||
m_configurer.configureElement( test, config, m_context ); | |||||
} | |||||
catch( final ConfigurationException ce ) | |||||
{ | |||||
ExceptionUtil.printStackTrace( ce ); | |||||
throw ce; | |||||
} | |||||
} | |||||
} |
@@ -1,22 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
/** | |||||
* A basic interface to test configurer. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public interface MyRole1 | |||||
extends DataType | |||||
{ | |||||
String ROLE = MyRole1.class.getName(); | |||||
} |
@@ -1,34 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test; | |||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* Adapts an Object to MyRole | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class MyRole1Adaptor | |||||
implements MyRole1 | |||||
{ | |||||
private final Object m_object; | |||||
public MyRole1Adaptor( final Object o ) | |||||
{ | |||||
m_object = o; | |||||
} | |||||
public boolean equals( Object obj ) | |||||
{ | |||||
final MyRole1Adaptor adaptor = (MyRole1Adaptor)obj; | |||||
return AbstractMyrmidonTest.equals( m_object, adaptor.m_object ); | |||||
} | |||||
} |
@@ -1,18 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test; | |||||
/** | |||||
* A basic interface to test configurer. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public interface MyRole2 | |||||
{ | |||||
} |
@@ -1,25 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* A basic implementation of MyRole1 to test configurer. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class MyType1 | |||||
implements MyRole1 | |||||
{ | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
return object.getClass() == getClass(); | |||||
} | |||||
} |
@@ -1,25 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* A basic implementation of MyRole1 to test configurer. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class MyType2 | |||||
implements MyRole1 | |||||
{ | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
return object.getClass() == getClass(); | |||||
} | |||||
} |
@@ -1,34 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test; | |||||
import org.apache.aut.converter.AbstractConverter; | |||||
import org.apache.aut.converter.ConverterException; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1Adaptor; | |||||
/** | |||||
* Converts from Object to MyRole1. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ObjectToMyRole1Converter | |||||
extends AbstractConverter | |||||
{ | |||||
public ObjectToMyRole1Converter() | |||||
{ | |||||
super( Object.class, MyRole1.class ); | |||||
} | |||||
protected Object convert( Object original, Object context ) | |||||
throws ConverterException | |||||
{ | |||||
return new MyRole1Adaptor( original ); | |||||
} | |||||
} |
@@ -1,46 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import org.apache.myrmidon.components.AbstractComponentTest; | |||||
/** | |||||
* A class for testing conversion. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
*/ | |||||
public class ConfigTestAttributeConvert | |||||
{ | |||||
private int m_intProp; | |||||
private Integer m_integerProp; | |||||
public void setIntProp( final int intProp ) | |||||
{ | |||||
m_intProp = intProp; | |||||
} | |||||
public void setIntegerProp( final Integer integerProp ) | |||||
{ | |||||
m_integerProp = integerProp; | |||||
} | |||||
public boolean equals( Object obj ) | |||||
{ | |||||
ConfigTestAttributeConvert test = (ConfigTestAttributeConvert)obj; | |||||
if( m_intProp != test.m_intProp ) | |||||
{ | |||||
return false; | |||||
} | |||||
if( !AbstractComponentTest.equals( m_integerProp, test.m_integerProp ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
} |
@@ -1,33 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
/** | |||||
* Simple class to test adder for Configurations. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestConfigAdder | |||||
{ | |||||
private ArrayList m_configurations = new ArrayList(); | |||||
public void addConfig( final Configuration configuration ) | |||||
{ | |||||
m_configurations.add( configuration ); | |||||
} | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
final ConfigTestConfigAdder other = (ConfigTestConfigAdder)object; | |||||
return m_configurations.equals( other.m_configurations ); | |||||
} | |||||
} |
@@ -1,42 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
/** | |||||
* A simple test class with string properties. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestContent | |||||
implements DataType | |||||
{ | |||||
private String m_content; | |||||
public boolean equals( final Object obj ) | |||||
{ | |||||
final ConfigTestContent test = (ConfigTestContent)obj; | |||||
if( !DefaultConfigurerTestCase.equals( m_content, test.m_content ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
else | |||||
{ | |||||
return true; | |||||
} | |||||
} | |||||
public void addContent( final String content ) | |||||
{ | |||||
m_content = content; | |||||
} | |||||
} |
@@ -1,20 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
/** | |||||
* An empty class. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestEmpty | |||||
implements DataType | |||||
{ | |||||
} |
@@ -1,42 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
/** | |||||
* A simple test class with string properties. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestIdResolve | |||||
implements DataType | |||||
{ | |||||
private String m_someProp; | |||||
public boolean equals( final Object obj ) | |||||
{ | |||||
final ConfigTestIdResolve test = (ConfigTestIdResolve)obj; | |||||
if( !DefaultConfigurerTestCase.equals( m_someProp, test.m_someProp ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
else | |||||
{ | |||||
return true; | |||||
} | |||||
} | |||||
public void setSomeProp( final String value ) | |||||
{ | |||||
m_someProp = value; | |||||
} | |||||
} |
@@ -1,105 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* A test class with multiple setters/adders/creators for a property. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestIgnoreStringMethods | |||||
{ | |||||
private MyRole1 m_prop1; | |||||
private ArrayList m_prop2 = new ArrayList(); | |||||
private int m_content; | |||||
private ArrayList m_typed = new ArrayList(); | |||||
public boolean equals( Object obj ) | |||||
{ | |||||
ConfigTestIgnoreStringMethods test = (ConfigTestIgnoreStringMethods)obj; | |||||
if( !DefaultConfigurerTestCase.equals( m_prop1, test.m_prop1 ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
if( !m_prop2.equals( test.m_prop2 ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
if( m_content != test.m_content ) | |||||
{ | |||||
return false; | |||||
} | |||||
if( !m_typed.equals( test.m_typed ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
// | |||||
// Multiple Setters | |||||
// | |||||
public void setProp1( final String value ) | |||||
{ | |||||
throw new AssertionFailedError(); | |||||
} | |||||
public void setProp1( final MyRole1 value ) | |||||
{ | |||||
m_prop1 = value; | |||||
} | |||||
// | |||||
// Multiple Adders | |||||
// | |||||
public void addProp2( final String value ) | |||||
{ | |||||
throw new AssertionFailedError(); | |||||
} | |||||
public void addProp2( final ConfigTestIgnoreStringMethods value ) | |||||
{ | |||||
m_prop2.add( value ); | |||||
} | |||||
// | |||||
// Multiple typed adders | |||||
// | |||||
public void add( final String value ) | |||||
{ | |||||
throw new AssertionFailedError(); | |||||
} | |||||
public void add( final MyRole1 value ) | |||||
{ | |||||
m_typed.add( value ); | |||||
} | |||||
// | |||||
// Multiple content setters | |||||
// | |||||
public void addContent( final int value ) | |||||
{ | |||||
m_content = value; | |||||
} | |||||
public void addContent( final String value ) | |||||
{ | |||||
throw new AssertionFailedError(); | |||||
} | |||||
} |
@@ -1,33 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* A test class with an interface property. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestInterfaceAdder | |||||
{ | |||||
private final ArrayList m_elems = new ArrayList(); | |||||
public void addPropA( final MyRole1 role1 ) | |||||
{ | |||||
m_elems.add( role1 ); | |||||
} | |||||
public boolean equals( Object obj ) | |||||
{ | |||||
final ConfigTestInterfaceAdder test = (ConfigTestInterfaceAdder)obj; | |||||
return m_elems.equals( test.m_elems ); | |||||
} | |||||
} |
@@ -1,26 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
/** | |||||
* A simple test class with string properties. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestMismatchedRefType | |||||
implements DataType | |||||
{ | |||||
public void setSomeProp( final String value ) | |||||
{ | |||||
} | |||||
} |
@@ -1,28 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole2; | |||||
/** | |||||
* Simple class with more than one typed adder method. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestMultipleTypedAdder | |||||
{ | |||||
public void add( final MyRole1 role1 ) | |||||
{ | |||||
} | |||||
public void add( final MyRole2 role2 ) | |||||
{ | |||||
} | |||||
} |
@@ -1,20 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
/** | |||||
* A simple test class. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestNestedErrors | |||||
{ | |||||
public void addProp( final ConfigTestEmpty test ) | |||||
{ | |||||
} | |||||
} |
@@ -1,23 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
/** | |||||
* Simple class to test typed adder. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestNonInterfaceAdder | |||||
{ | |||||
public void add( final Integer integer ) | |||||
{ | |||||
System.out.println( "This should not have been called as " + | |||||
"Integer is not an interface" ); | |||||
} | |||||
} |
@@ -1,41 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.List; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
/** | |||||
* Simple class to test typed adder. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestPropResolution | |||||
{ | |||||
private String m_prop; | |||||
public boolean equals( final Object obj ) | |||||
{ | |||||
final ConfigTestPropResolution test = (ConfigTestPropResolution)obj; | |||||
if( !DefaultConfigurerTestCase.equals( m_prop, test.m_prop ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
else | |||||
{ | |||||
return true; | |||||
} | |||||
} | |||||
public void setProp( final String value ) | |||||
{ | |||||
m_prop = value; | |||||
} | |||||
} |
@@ -1,41 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.List; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
/** | |||||
* Simple class to test typed adder. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestReferenceAttribute | |||||
{ | |||||
private String m_someProp; | |||||
public boolean equals( final Object obj ) | |||||
{ | |||||
final ConfigTestReferenceAttribute test = (ConfigTestReferenceAttribute)obj; | |||||
if( !DefaultConfigurerTestCase.equals( m_someProp, test.m_someProp ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
else | |||||
{ | |||||
return true; | |||||
} | |||||
} | |||||
public void setSomeProp( final String value ) | |||||
{ | |||||
m_someProp = value; | |||||
} | |||||
} |
@@ -1,32 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* A simple test class. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestReferenceConversion | |||||
{ | |||||
private final ArrayList m_elems = new ArrayList(); | |||||
public void setPropA( final MyRole1 role1 ) | |||||
{ | |||||
m_elems.add( role1 ); | |||||
} | |||||
public boolean equals( Object obj ) | |||||
{ | |||||
final ConfigTestReferenceConversion test = (ConfigTestReferenceConversion)obj; | |||||
return m_elems.equals( test.m_elems ); | |||||
} | |||||
} |
@@ -1,37 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
/** | |||||
* A simple test class. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestReferenceElement | |||||
{ | |||||
private String m_someProp; | |||||
public boolean equals( Object obj ) | |||||
{ | |||||
ConfigTestReferenceElement test = (ConfigTestReferenceElement)obj; | |||||
if( !DefaultConfigurerTestCase.equals( m_someProp, test.m_someProp ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
public void addSomeProp( final String value ) | |||||
{ | |||||
m_someProp = value; | |||||
} | |||||
} |
@@ -1,50 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
/** | |||||
* A test class with a setter and adder with the same property name. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestSetAndAdd | |||||
{ | |||||
private String m_prop; | |||||
private ArrayList m_nested = new ArrayList(); | |||||
public void setProp( final String prop ) | |||||
{ | |||||
m_prop = prop; | |||||
} | |||||
public void addProp( final ConfigTestSetAndAdd elem ) | |||||
{ | |||||
m_nested.add( elem ); | |||||
} | |||||
public boolean equals( final Object obj ) | |||||
{ | |||||
ConfigTestSetAndAdd test = (ConfigTestSetAndAdd)obj; | |||||
if( ! AbstractMyrmidonTest.equals( m_prop, test.m_prop) ) | |||||
{ | |||||
return false; | |||||
} | |||||
else if( ! m_nested.equals( test.m_nested ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
else | |||||
{ | |||||
return true; | |||||
} | |||||
} | |||||
} |
@@ -1,41 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.List; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
/** | |||||
* Simple class to test setter. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestSetAttribute | |||||
{ | |||||
private String m_someProp; | |||||
public boolean equals( final Object obj ) | |||||
{ | |||||
final ConfigTestSetAttribute test = (ConfigTestSetAttribute)obj; | |||||
if( !DefaultConfigurerTestCase.equals( m_someProp, test.m_someProp ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
else | |||||
{ | |||||
return true; | |||||
} | |||||
} | |||||
public void setSomeProp( final String value ) | |||||
{ | |||||
m_someProp = value; | |||||
} | |||||
} |
@@ -1,47 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import org.apache.myrmidon.components.configurer.test.DefaultConfigurerTestCase; | |||||
/** | |||||
* A simple test class. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestSetElement | |||||
{ | |||||
private List m_propList = new ArrayList(); | |||||
private String m_someProp; | |||||
public boolean equals( Object obj ) | |||||
{ | |||||
ConfigTestSetElement test = (ConfigTestSetElement)obj; | |||||
if( !m_propList.equals( test.m_propList ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
else if( !DefaultConfigurerTestCase.equals( m_someProp, test.m_someProp ) ) | |||||
{ | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
public void setSomeProp( final String value ) | |||||
{ | |||||
m_someProp = value; | |||||
} | |||||
public void addProp( final ConfigTestSetElement test ) | |||||
{ | |||||
m_propList.add( test ); | |||||
} | |||||
} |
@@ -1,33 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* Simple class to test adder for Configurations. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestTypedAdder | |||||
{ | |||||
private ArrayList m_roles = new ArrayList(); | |||||
public void add( final MyRole1 role ) | |||||
{ | |||||
m_roles.add( role ); | |||||
} | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
final ConfigTestTypedAdder other = (ConfigTestTypedAdder)object; | |||||
return m_roles.equals( other.m_roles ); | |||||
} | |||||
} |
@@ -1,40 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
/** | |||||
* Simple class to test typed adder. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestTypedAdderConversion | |||||
implements DataType | |||||
{ | |||||
private ArrayList m_roles = new ArrayList(); | |||||
private String m_prop; | |||||
public void setProp( final String prop ) | |||||
{ | |||||
m_prop = prop; | |||||
} | |||||
public void add( final MyRole1 role1 ) | |||||
{ | |||||
m_roles.add( role1 ); | |||||
} | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
final ConfigTestTypedAdderConversion other = (ConfigTestTypedAdderConversion)object; | |||||
return m_roles.equals( other.m_roles ); | |||||
} | |||||
} |
@@ -1,33 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* Simple class to test typed adder. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestTypedAdderReference | |||||
{ | |||||
private ArrayList m_roles = new ArrayList(); | |||||
public void add( final MyRole1 role1 ) | |||||
{ | |||||
m_roles.add( role1 ); | |||||
} | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
final ConfigTestTypedAdderReference other = (ConfigTestTypedAdderReference)object; | |||||
return m_roles.equals( other.m_roles ); | |||||
} | |||||
} |
@@ -1,33 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.myrmidon.components.configurer.test.MyRole1; | |||||
/** | |||||
* Simple class to test typed adder. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestTypedAdderRole | |||||
{ | |||||
private ArrayList m_roles = new ArrayList(); | |||||
public void add( final MyRole1 role1 ) | |||||
{ | |||||
m_roles.add( role1 ); | |||||
} | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
final ConfigTestTypedAdderRole other = (ConfigTestTypedAdderRole)object; | |||||
return m_roles.equals( other.m_roles ); | |||||
} | |||||
} |
@@ -1,33 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import java.util.ArrayList; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
/** | |||||
* Simple class to test adder for Configurations. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ConfigTestTypedConfigAdder | |||||
{ | |||||
private ArrayList m_configurations = new ArrayList(); | |||||
public void add( final Configuration configuration ) | |||||
{ | |||||
m_configurations.add( configuration ); | |||||
} | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
final ConfigTestTypedConfigAdder other = (ConfigTestTypedConfigAdder)object; | |||||
return m_configurations.equals( other.m_configurations ); | |||||
} | |||||
} |
@@ -1,23 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.configurer.test.data; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
/** | |||||
* A simple test class with string properties. | |||||
* | |||||
* @author Adam Murdoch | |||||
*/ | |||||
public class ConfigTestUnknownReference | |||||
implements DataType | |||||
{ | |||||
public void setSomeProp( final String value ) | |||||
{ | |||||
} | |||||
} |
@@ -1,203 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.deployer.test; | |||||
import java.io.File; | |||||
import org.apache.aut.converter.Converter; | |||||
import org.apache.aut.converter.ConverterException; | |||||
import org.apache.myrmidon.components.AbstractComponentTest; | |||||
import org.apache.myrmidon.components.deployer.DefaultDeployer; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | |||||
import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | |||||
import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||||
import org.apache.myrmidon.interfaces.type.TypeException; | |||||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||||
/** | |||||
* Test cases for the default deployer. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
*/ | |||||
public class DefaultDeployerTestCase | |||||
extends AbstractComponentTest | |||||
{ | |||||
private static final String TEST_TYPE1_NAME = "test-type1"; | |||||
private Deployer m_deployer; | |||||
private Converter m_converter; | |||||
public DefaultDeployerTestCase( final String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Setup the test case - prepares the set of components, including the | |||||
* deployer. | |||||
*/ | |||||
protected void setUp() throws Exception | |||||
{ | |||||
super.setUp(); | |||||
m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE ); | |||||
m_converter = (Converter)getServiceManager().lookup( Converter.ROLE ); | |||||
} | |||||
/** | |||||
* Creates an instance of a component. Sub-classes can override this | |||||
* method to add a particular implementation to the set of test components. | |||||
*/ | |||||
protected Object createComponent( final String role, final Class defaultImpl ) | |||||
throws Exception | |||||
{ | |||||
if( role.equals( Deployer.ROLE) ) | |||||
{ | |||||
return new DefaultDeployer(); | |||||
} | |||||
else | |||||
{ | |||||
return super.createComponent( role, defaultImpl ); | |||||
} | |||||
} | |||||
/** | |||||
* Tests deployment of a single type from a ClassLoader. | |||||
*/ | |||||
public void testSingleType() throws Exception | |||||
{ | |||||
final String typeName = TEST_TYPE1_NAME; | |||||
final String classname = TestType1.class.getName(); | |||||
// Determine the shorthand for the DataType role | |||||
// Create the type definition | |||||
final TypeDefinition typeDef = new TypeDefinition( typeName, DATA_TYPE_ROLE, classname ); | |||||
final ClassLoader classLoader = getClass().getClassLoader(); | |||||
final TypeDeployer typeDeployer = m_deployer.createDeployer( classLoader ); | |||||
// Make sure the test types have not been deployed | |||||
assertTypesNotRegistered(); | |||||
// Deploy the type | |||||
typeDeployer.deployType( typeDef ); | |||||
// Check the type has been registered | |||||
final TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||||
final Object result = typeFactory.create( typeName ); | |||||
assertTrue( result instanceof TestType1 ); | |||||
} | |||||
/** | |||||
* Tests deployment of a single converter from a ClassLoader. | |||||
*/ | |||||
public void testSingleConverter() throws Exception | |||||
{ | |||||
// Create the type definition | |||||
final String classname = TestConverter1.class.getName(); | |||||
final String source = "java.lang.String"; | |||||
final String destClass = TestType1.class.getName(); | |||||
final ConverterDefinition typeDef = | |||||
new ConverterDefinition( classname, source, destClass ); | |||||
final ClassLoader classLoader = getClass().getClassLoader(); | |||||
final TypeDeployer typeDeployer = m_deployer.createDeployer( classLoader ); | |||||
// Make sure the test types have not been deployed | |||||
assertTypesNotRegistered(); | |||||
// Deploy the type | |||||
typeDeployer.deployType( typeDef ); | |||||
// Try to convert from string to test type | |||||
final Object result = m_converter.convert( TestType1.class, "some-string", null ); | |||||
assertTrue( result instanceof TestType1 ); | |||||
} | |||||
/** | |||||
* Tests deployment of types from a typelib descriptor. | |||||
*/ | |||||
public void testLibDescriptor() throws Exception | |||||
{ | |||||
final File typelib = getTestResource( "test.atl" ); | |||||
final TypeDeployer typeDeployer = m_deployer.createDeployer( typelib ); | |||||
// Make sure the test types have not been deployed | |||||
assertTypesNotRegistered(); | |||||
// Deploy all the types from the descriptor | |||||
typeDeployer.deployAll(); | |||||
// Make sure the test types have been deployed | |||||
assertTypesRegistered(); | |||||
} | |||||
/** | |||||
* Ensures that the test types have not ben deployed. | |||||
*/ | |||||
private void assertTypesNotRegistered() throws Exception | |||||
{ | |||||
// Check the data-type | |||||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||||
try | |||||
{ | |||||
typeFactory.create( TEST_TYPE1_NAME ); | |||||
fail(); | |||||
} | |||||
catch( TypeException e ) | |||||
{ | |||||
// TODO - check error message | |||||
} | |||||
// Check the custom role implementation | |||||
try | |||||
{ | |||||
typeFactory = getTypeManager().getFactory( TestRole1.ROLE ); | |||||
typeFactory.create( TEST_TYPE1_NAME ); | |||||
fail(); | |||||
} | |||||
catch( TypeException e ) | |||||
{ | |||||
// TODO - check error message | |||||
} | |||||
// Check the converter | |||||
try | |||||
{ | |||||
m_converter.convert( TestType1.class, "some string", null ); | |||||
fail(); | |||||
} | |||||
catch( ConverterException e ) | |||||
{ | |||||
// TODO - check error message | |||||
} | |||||
} | |||||
/** | |||||
* Ensures the types from the test typelib descriptor have been correctly | |||||
* deployed. | |||||
*/ | |||||
private void assertTypesRegistered() throws Exception | |||||
{ | |||||
// Check the data-type | |||||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||||
Object object = typeFactory.create( TEST_TYPE1_NAME ); | |||||
assertTrue( object instanceof TestType1 ); | |||||
// Check the custom role implementation | |||||
typeFactory = getTypeManager().getFactory( TestRole1.ROLE ); | |||||
object = typeFactory.create( TEST_TYPE1_NAME ); | |||||
assertTrue( object instanceof TestType1 ); | |||||
// Check the converter | |||||
object = m_converter.convert( TestType1.class, "some string", null ); | |||||
assertTrue( object instanceof TestType1 ); | |||||
} | |||||
} |
@@ -1,29 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.deployer.test; | |||||
import org.apache.aut.converter.Converter; | |||||
import org.apache.aut.converter.ConverterException; | |||||
/** | |||||
* A test converter. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
*/ | |||||
public class TestConverter1 | |||||
implements Converter | |||||
{ | |||||
/** | |||||
* Convert original to destination type. | |||||
*/ | |||||
public Object convert( Class destination, Object original, Object context ) | |||||
throws ConverterException | |||||
{ | |||||
return new TestType1(); | |||||
} | |||||
} |
@@ -1,18 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.deployer.test; | |||||
/** | |||||
* A test role interface. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
*/ | |||||
public interface TestRole1 | |||||
{ | |||||
String ROLE = TestRole1.class.getName(); | |||||
} |
@@ -1,21 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.deployer.test; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
import org.apache.myrmidon.components.deployer.test.TestRole1; | |||||
/** | |||||
* A test data-type. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
*/ | |||||
public class TestType1 | |||||
implements DataType, TestRole1 | |||||
{ | |||||
} |
@@ -1,18 +0,0 @@ | |||||
<ant-lib version="1.0"> | |||||
<types> | |||||
<!-- Register a data-type --> | |||||
<data-type name="test-type1" | |||||
classname="org.apache.myrmidon.components.deployer.test.TestType1"/> | |||||
<!-- Register a custom role implementation --> | |||||
<test-role1 name="test-type1" | |||||
classname="org.apache.myrmidon.components.deployer.test.TestType1"/> | |||||
<!-- Register a converter --> | |||||
<converter classname="org.apache.myrmidon.components.deployer.test.TestConverter1" | |||||
source="java.lang.String" | |||||
destination="org.apache.myrmidon.components.deployer.test.TestType1"/> | |||||
</types> | |||||
</ant-lib> |
@@ -1,4 +0,0 @@ | |||||
<roles version="1.0"> | |||||
<!-- A custom role --> | |||||
<role shorthand="test-role1" name="org.apache.myrmidon.components.deployer.test.TestRole1"/> | |||||
</roles> |
@@ -1,136 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.embeddor.test; | |||||
import java.io.File; | |||||
import java.util.HashMap; | |||||
import org.apache.avalon.framework.context.DefaultContext; | |||||
import org.apache.avalon.framework.logger.Logger; | |||||
import org.apache.myrmidon.AbstractProjectTest; | |||||
import org.apache.myrmidon.LogMessageTracker; | |||||
import org.apache.myrmidon.components.embeddor.DefaultEmbeddor; | |||||
import org.apache.myrmidon.interfaces.embeddor.Embeddor; | |||||
import org.apache.myrmidon.interfaces.model.Project; | |||||
import org.apache.myrmidon.interfaces.model.Target; | |||||
import org.apache.myrmidon.interfaces.workspace.Workspace; | |||||
import org.apache.myrmidon.listeners.ProjectListener; | |||||
/** | |||||
* Test cases for the default embeddor. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class DefaultEmbeddorTest | |||||
extends AbstractProjectTest | |||||
{ | |||||
private DefaultEmbeddor m_embeddor; | |||||
public DefaultEmbeddorTest( String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Tear-down the test. | |||||
*/ | |||||
protected void tearDown() throws Exception | |||||
{ | |||||
if( m_embeddor != null ) | |||||
{ | |||||
m_embeddor.dispose(); | |||||
m_embeddor = null; | |||||
} | |||||
} | |||||
/** | |||||
* Returns an embeddor which can be used to build and execute projects. | |||||
*/ | |||||
protected Embeddor getEmbeddor() throws Exception | |||||
{ | |||||
if( m_embeddor == null ) | |||||
{ | |||||
// Need to set the context classloader - The default embeddor uses it | |||||
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() ); | |||||
final Logger logger = getLogger(); | |||||
m_embeddor = new DefaultEmbeddor(); | |||||
m_embeddor.enableLogging( logger ); | |||||
final DefaultContext context = new DefaultContext(); | |||||
context.put( "myrmidon.home", getInstallDirectory() ); | |||||
m_embeddor.contextualize( context ); | |||||
m_embeddor.initialize(); | |||||
m_embeddor.start(); | |||||
} | |||||
return m_embeddor; | |||||
} | |||||
/** | |||||
* Tests that a project is successfully built from a file. | |||||
*/ | |||||
public void testProjectBuilder() throws Exception | |||||
{ | |||||
// Build the project | |||||
final File projectFile = getTestResource( "project-builder.ant" ); | |||||
final Project project = getEmbeddor().createProject( projectFile.getAbsolutePath(), null, null ); | |||||
// Verify the project. | |||||
assertEquals( "test-project", project.getProjectName() ); | |||||
assertEquals( "main-target", project.getDefaultTargetName() ); | |||||
assertEquals( projectFile.getParentFile(), project.getBaseDirectory() ); | |||||
assertEquals( 0, project.getProjectNames().length ); | |||||
assertEquals( 0, project.getTypeLibs().length ); | |||||
assertEquals( 1, project.getTargetNames().length ); | |||||
final Target implicitTarget = project.getImplicitTarget(); | |||||
assertEquals( 1, implicitTarget.getTasks().length ); | |||||
assertEquals( "property", implicitTarget.getTasks()[ 0 ].getName() ); | |||||
final Target target = project.getTarget( "main-target" ); | |||||
assertEquals( 1, target.getTasks().length ); | |||||
assertEquals( "log", target.getTasks()[ 0 ].getName() ); | |||||
} | |||||
/** | |||||
* Tests that a listener can be created. | |||||
*/ | |||||
public void testCreateListener() throws Exception | |||||
{ | |||||
final ProjectListener listener = getEmbeddor().createListener( "default" ); | |||||
assertNotNull( listener ); | |||||
} | |||||
/** | |||||
* Tests that a workspace can execute a project file. | |||||
*/ | |||||
public void testWorkspaceCreate() throws Exception | |||||
{ | |||||
// Build the project | |||||
final File projectFile = getTestResource( "project-builder.ant" ); | |||||
final Embeddor embeddor = getEmbeddor(); | |||||
final Project project = embeddor.createProject( projectFile.getAbsolutePath(), null, null ); | |||||
// Build the workspace | |||||
final Workspace workspace = embeddor.createWorkspace( new HashMap() ); | |||||
// Install a listener | |||||
final LogMessageTracker listener = new LogMessageTracker(); | |||||
workspace.addProjectListener( listener ); | |||||
listener.addExpectedMessage( "main-target", "A log message" ); | |||||
// Execute the default target | |||||
final String target = project.getDefaultTargetName(); | |||||
workspace.executeProject( project, target ); | |||||
// Cleanup | |||||
listener.assertComplete(); | |||||
} | |||||
} |
@@ -1,6 +0,0 @@ | |||||
<project version="2.0" name="test-project" default="main-target"> | |||||
<property name="some-prop" value="some-value"/> | |||||
<target name="main-target"> | |||||
<log>A log message</log> | |||||
</target> | |||||
</project> |
@@ -1,171 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.property.test; | |||||
import java.io.File; | |||||
import java.util.Date; | |||||
import org.apache.aut.converter.lib.ObjectToStringConverter; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.avalon.framework.service.DefaultServiceManager; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
import org.apache.myrmidon.components.AbstractComponentTest; | |||||
import org.apache.myrmidon.components.workspace.DefaultTaskContext; | |||||
import org.apache.myrmidon.components.property.DefaultPropertyResolver; | |||||
import org.apache.myrmidon.components.store.DefaultPropertyStore; | |||||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||||
import org.apache.myrmidon.interfaces.property.PropertyStore; | |||||
/** | |||||
* General-purpose property resolver test cases. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public abstract class AbstractPropertyResolverTestCase | |||||
extends AbstractComponentTest | |||||
{ | |||||
protected PropertyResolver m_resolver; | |||||
protected TaskContext m_context; | |||||
public AbstractPropertyResolverTestCase( final String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
protected void setUp() throws Exception | |||||
{ | |||||
m_resolver = (PropertyResolver)getServiceManager().lookup( PropertyResolver.ROLE ); | |||||
final PropertyStore store = new DefaultPropertyStore(); | |||||
m_context = | |||||
new DefaultTaskContext( new DefaultServiceManager(), getLogger(), store ); | |||||
m_context.setProperty( "intProp", new Integer( 333 ) ); | |||||
m_context.setProperty( "stringProp", "String property" ); | |||||
registerConverter( ObjectToStringConverter.class, Object.class, String.class ); | |||||
} | |||||
/** | |||||
* Creates an instance of a component. Sub-classes can override this | |||||
* method to add a particular implementation to the set of test components. | |||||
*/ | |||||
protected Object createComponent( String role, Class defaultImpl ) | |||||
throws Exception | |||||
{ | |||||
if( role.equals( PropertyResolver.ROLE) ) | |||||
{ | |||||
return createResolver(); | |||||
} | |||||
else | |||||
{ | |||||
return super.createComponent( role, defaultImpl ); | |||||
} | |||||
} | |||||
/** | |||||
* Creates the resolver to test. | |||||
*/ | |||||
protected abstract PropertyResolver createResolver(); | |||||
/** | |||||
* Test property resolution with various different typed properties. | |||||
*/ | |||||
public void testPropertyTypes() throws Exception | |||||
{ | |||||
testPropertyValue( new String( "String value" ) ); | |||||
testPropertyValue( new Date() ); | |||||
testPropertyValue( new Integer( Integer.MIN_VALUE ) ); | |||||
testPropertyValue( new Double( 24234.98453 ) ); | |||||
testPropertyValue( this.getClass() ); | |||||
testPropertyValue( File.createTempFile( "PropertyResolverTest", null ) ); | |||||
} | |||||
/** | |||||
* Simple tests with property on it's own, and accompanied by text. | |||||
*/ | |||||
private void testPropertyValue( final Object propObject ) | |||||
throws Exception | |||||
{ | |||||
m_context.setProperty( "typedProp", propObject ); | |||||
final String propString = propObject.toString(); | |||||
doTestResolution( "${typedProp}", propObject, m_context ); | |||||
doTestResolution( "${typedProp} with following text", | |||||
propString + " with following text", m_context ); | |||||
doTestResolution( "Preceding text with ${typedProp}", | |||||
"Preceding text with " + propString, m_context ); | |||||
} | |||||
/** | |||||
* Tests multiple property declarations in a single value. | |||||
*/ | |||||
public void testMultipleProperties() throws Exception | |||||
{ | |||||
m_context.setProperty( "prop1", "value1" ); | |||||
m_context.setProperty( "prop2", "value2" ); | |||||
m_context.setProperty( "int1", new Integer( 123 ) ); | |||||
doTestResolution( "${prop1}${prop2}", "value1value2", m_context ); | |||||
doTestResolution( "${prop1}${prop1}${prop1}", "value1value1value1", m_context ); | |||||
doTestResolution( "before ${prop2} between ${prop1} after", | |||||
"before value2 between value1 after", m_context ); | |||||
doTestResolution( "${prop1}-${int1}-${prop2}", "value1-123-value2", m_context ); | |||||
} | |||||
/** | |||||
* Tests illegal property syntax. | |||||
*/ | |||||
public void testInvalidTypeDeclarations() throws Exception | |||||
{ | |||||
final Resources rez = getResourcesForTested( DefaultPropertyResolver.class ); | |||||
doTestFailure( "${unclosed", | |||||
rez.getString( "prop.mismatched-braces.error" ), | |||||
m_context ); | |||||
doTestFailure( "${", | |||||
rez.getString( "prop.mismatched-braces.error" ), | |||||
m_context ); | |||||
/* TODO - need to handle these cases. */ | |||||
// testFailure( "${bad${}", "", m_context ); | |||||
// testFailure( "${ }", "", m_context ); | |||||
} | |||||
/** | |||||
* Resolves the property using the supplied context, and checks the result. | |||||
*/ | |||||
protected void doTestResolution( final String value, | |||||
final Object expected, | |||||
final TaskContext context ) | |||||
throws Exception | |||||
{ | |||||
final Object resolved = m_resolver.resolveProperties( value, context ); | |||||
assertEquals( expected, resolved ); | |||||
} | |||||
/** | |||||
* Attempts to resolve the value using the supplied context, expecting to | |||||
* fail with the supplied error message. | |||||
*/ | |||||
protected void doTestFailure( final String value, | |||||
final String expectedErrorMessage, | |||||
final TaskContext context ) | |||||
{ | |||||
try | |||||
{ | |||||
m_resolver.resolveProperties( value, context ); | |||||
fail( "Unexpected sucess - test should have failed." ); | |||||
} | |||||
catch( TaskException e ) | |||||
{ | |||||
assertSameMessage( expectedErrorMessage, e ); | |||||
} | |||||
} | |||||
} |
@@ -1,42 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.property.test; | |||||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||||
import org.apache.myrmidon.components.property.test.AbstractPropertyResolverTestCase; | |||||
import org.apache.myrmidon.components.property.ClassicPropertyResolver; | |||||
/** | |||||
* A test for {@link org.apache.myrmidon.components.property.ClassicPropertyResolver}. | |||||
* | |||||
* @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ClassicPropertyResolverTestCase | |||||
extends AbstractPropertyResolverTestCase | |||||
{ | |||||
public ClassicPropertyResolverTestCase( String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
protected PropertyResolver createResolver() | |||||
{ | |||||
return new ClassicPropertyResolver(); | |||||
} | |||||
/** | |||||
* Tests handing undefined property. | |||||
*/ | |||||
public void testUndefinedProp() throws Exception | |||||
{ | |||||
final String undefinedProp = "undefinedProperty"; | |||||
final String propRef = "${" + undefinedProp + "}"; | |||||
doTestResolution( propRef, propRef, m_context ); | |||||
} | |||||
} |
@@ -1,51 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.property.test; | |||||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||||
import org.apache.myrmidon.components.property.test.AbstractPropertyResolverTestCase; | |||||
import org.apache.myrmidon.components.property.DefaultPropertyResolver; | |||||
import org.apache.myrmidon.components.store.DefaultPropertyStore; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
/** | |||||
* Functional tests for {@link org.apache.myrmidon.components.property.DefaultPropertyResolver}. | |||||
* | |||||
* @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class DefaultPropertyResolverTestCase | |||||
extends AbstractPropertyResolverTestCase | |||||
{ | |||||
public DefaultPropertyResolverTestCase( final String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
protected PropertyResolver createResolver() | |||||
{ | |||||
return new DefaultPropertyResolver(); | |||||
} | |||||
/** | |||||
* Tests handing undefined property. | |||||
*/ | |||||
public void testUndefinedProp() throws Exception | |||||
{ | |||||
final Resources rez = getResourcesForTested( DefaultPropertyStore.class ); | |||||
final String undefinedProp = "undefinedProperty"; | |||||
doTestFailure( "${" + undefinedProp + "}", | |||||
rez.getString( "unknown-prop.error", undefinedProp ), | |||||
m_context ); | |||||
//TODO - "" should be disallowed as a property name | |||||
doTestFailure( "${}", | |||||
rez.getString( "unknown-prop.error", "" ), | |||||
m_context ); | |||||
} | |||||
} |
@@ -1,182 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.role.test; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
import org.apache.myrmidon.components.role.DefaultRoleManager; | |||||
import org.apache.myrmidon.api.Task; | |||||
import org.apache.myrmidon.interfaces.role.RoleException; | |||||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
/** | |||||
* Test cases for the DefaultRoleManager. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class DefaultRoleManagerTestCase | |||||
extends AbstractMyrmidonTest | |||||
{ | |||||
private final static Resources REZ = getResourcesForTested( DefaultRoleManagerTestCase.class ); | |||||
private RoleManager m_roleManager; | |||||
public DefaultRoleManagerTestCase( String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
protected void setUp() throws Exception | |||||
{ | |||||
m_roleManager = new DefaultRoleManager(); | |||||
} | |||||
/** | |||||
* Tests looking up a role by name, shorthand and type. | |||||
*/ | |||||
public void testLookup() throws Exception | |||||
{ | |||||
final String roleName = "role-name"; | |||||
final String shorthand = "role-shorthand"; | |||||
final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
m_roleManager.addRole( origRole ); | |||||
// Lookup the role | |||||
RoleInfo role = m_roleManager.getRole( roleName ); | |||||
assertTrue( origRole.equals( role ) ); | |||||
// Lookup the role by shorthand | |||||
role = m_roleManager.getRoleByShorthandName( shorthand ); | |||||
assertTrue( origRole.equals( role ) ); | |||||
// Lookup the role by type | |||||
role = m_roleManager.getRoleByType( Task.class ); | |||||
assertTrue( origRole.equals( role ) ); | |||||
// Lookup an unknown role | |||||
RoleInfo unknownRole = m_roleManager.getRole( "unknown" ); | |||||
assertNull( unknownRole ); | |||||
// Lookup an unknown shorthand | |||||
unknownRole = m_roleManager.getRoleByShorthandName( "unknown" ); | |||||
assertNull( unknownRole ); | |||||
// Lookup an unknown role | |||||
unknownRole = m_roleManager.getRoleByType( DefaultRoleManagerTestCase.class ); | |||||
assertNull( unknownRole ); | |||||
} | |||||
/** | |||||
* Tests inheriting roles from parent role manager. | |||||
*/ | |||||
public void testParent() throws Exception | |||||
{ | |||||
final String roleName = "role-name"; | |||||
final String shorthand = "shorthand"; | |||||
final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
m_roleManager.addRole( origRole ); | |||||
final RoleManager roleManager = new DefaultRoleManager( m_roleManager ); | |||||
// Lookup by name | |||||
RoleInfo roleInfo = roleManager.getRole( roleName ); | |||||
assertTrue( origRole.equals( roleInfo ) ); | |||||
// Lookup by shorthand | |||||
roleInfo = roleManager.getRoleByShorthandName( shorthand ); | |||||
assertTrue( origRole.equals( roleInfo ) ); | |||||
// Lookup by type | |||||
roleInfo = roleManager.getRoleByType( Task.class ); | |||||
assertTrue( origRole.equals( roleInfo ) ); | |||||
} | |||||
/** | |||||
* Tests overriding a role in a child role manager. | |||||
*/ | |||||
public void testOverrideName() throws Exception | |||||
{ | |||||
final String roleName = "role-name"; | |||||
final String shorthand = "shorthand"; | |||||
// Add original role | |||||
final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
m_roleManager.addRole( origRole ); | |||||
// Override role | |||||
final RoleManager roleManager = new DefaultRoleManager( m_roleManager ); | |||||
final RoleInfo overrideNameRole = new RoleInfo( roleName, "shorthand1" ); | |||||
roleManager.addRole( overrideNameRole ); | |||||
final RoleInfo overrideShorthandRole = new RoleInfo( "role2", shorthand ); | |||||
roleManager.addRole( overrideShorthandRole ); | |||||
final RoleInfo overrideTypeRole = new RoleInfo( "role3", "shorthand3", Task.class ); | |||||
roleManager.addRole( overrideTypeRole ); | |||||
// Lookup role by name | |||||
RoleInfo roleInfo = roleManager.getRole( roleName ); | |||||
assertTrue( overrideNameRole.equals( roleInfo ) ); | |||||
// Lookup role by shorthand | |||||
roleInfo = roleManager.getRoleByShorthandName( shorthand ); | |||||
assertTrue( overrideShorthandRole.equals( roleInfo ) ); | |||||
// Lookup role by type | |||||
roleInfo = roleManager.getRoleByType( Task.class ); | |||||
assertTrue( overrideTypeRole.equals( roleInfo ) ); | |||||
} | |||||
/** | |||||
* Tests adding duplicate roles. | |||||
*/ | |||||
public void testDuplicate() throws Exception | |||||
{ | |||||
final String roleName = "role-name"; | |||||
final String shorthand = "shorthand"; | |||||
final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
m_roleManager.addRole( origRole ); | |||||
// Duplicate role name | |||||
try | |||||
{ | |||||
m_roleManager.addRole( new RoleInfo( roleName ) ); | |||||
fail(); | |||||
} | |||||
catch( RoleException exc ) | |||||
{ | |||||
final String message = REZ.getString( "duplicate-role.error", roleName ); | |||||
assertSameMessage( message, exc ); | |||||
} | |||||
// Duplicate shorthand | |||||
try | |||||
{ | |||||
m_roleManager.addRole( new RoleInfo( "another-role", shorthand ) ); | |||||
fail(); | |||||
} | |||||
catch( RoleException exc ) | |||||
{ | |||||
final String message = REZ.getString( "duplicate-shorthand.error", shorthand ); | |||||
assertSameMessage( message, exc ); | |||||
} | |||||
// Duplicate type | |||||
try | |||||
{ | |||||
m_roleManager.addRole( new RoleInfo( null, Task.class ) ); | |||||
fail(); | |||||
} | |||||
catch( RoleException exc ) | |||||
{ | |||||
final String message = REZ.getString( "duplicate-type.error", Task.class.getName() ); | |||||
assertSameMessage( message, exc ); | |||||
} | |||||
} | |||||
} |
@@ -1,152 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.service.test; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.avalon.framework.parameters.Parameters; | |||||
import org.apache.avalon.framework.service.ServiceException; | |||||
import org.apache.avalon.framework.context.DefaultContext; | |||||
import org.apache.myrmidon.components.AbstractComponentTest; | |||||
import org.apache.myrmidon.components.service.InstantiatingServiceManager; | |||||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
/** | |||||
* Test cases for the default service manager. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class InstantiatingServiceManagerTestCase | |||||
extends AbstractComponentTest | |||||
{ | |||||
private final static Resources REZ = getResourcesForTested( InstantiatingServiceManagerTestCase.class ); | |||||
private InstantiatingServiceManager m_serviceManager; | |||||
public InstantiatingServiceManagerTestCase( final String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Setup the test case - prepares the set of components. | |||||
*/ | |||||
protected void setUp() | |||||
throws Exception | |||||
{ | |||||
// Set-up the service manager | |||||
m_serviceManager = new InstantiatingServiceManager(); | |||||
m_serviceManager.enableLogging( getLogger() ); | |||||
m_serviceManager.contextualize( new DefaultContext() ); | |||||
m_serviceManager.service( getServiceManager() ); | |||||
m_serviceManager.parameterize( new Parameters() ); | |||||
} | |||||
/** | |||||
* Tests service instantiation. | |||||
*/ | |||||
public void testCreateService() throws Exception | |||||
{ | |||||
final String serviceRoleName = "test-service"; | |||||
// Setup the test service | |||||
registerFactory( serviceRoleName, TestService.class, TestServiceFactory1.class ); | |||||
// Create the service | |||||
Object service = m_serviceManager.lookup( serviceRoleName ); | |||||
// Check service is of the expected class (don't use instanceof) | |||||
assertTrue( service.getClass() == TestServiceImpl1.class ); | |||||
} | |||||
/** | |||||
* Tests service lookup. | |||||
*/ | |||||
public void testLookup() throws Exception | |||||
{ | |||||
final String serviceRoleName = "test-service"; | |||||
// Setup the test service | |||||
registerFactory( serviceRoleName, TestService.class, TestServiceFactory1.class ); | |||||
// Check whether the service can be instantiated | |||||
boolean hasService = m_serviceManager.hasService( serviceRoleName ); | |||||
assertTrue( hasService ); | |||||
} | |||||
/** | |||||
* Tests that a service factory and service instance are taken through | |||||
* the lifecycle steps. | |||||
*/ | |||||
public void testLifecycle() throws Exception | |||||
{ | |||||
final String serviceRoleName = "test-service"; | |||||
// Setup the test service | |||||
registerFactory( serviceRoleName, TestService.class, TestServiceFactory2.class ); | |||||
// Create the service | |||||
TestService service = (TestService)m_serviceManager.lookup( serviceRoleName ); | |||||
// Check service is of the expected class (don't use instanceof) | |||||
assertTrue( service.getClass() == TestServiceImpl2.class ); | |||||
// Assert the service has been setup correctly | |||||
LifecycleValidator validate = (LifecycleValidator)service; | |||||
validate.assertSetup(); | |||||
// Cleanup | |||||
m_serviceManager.dispose(); | |||||
// Assert the service has been shutdown correctly | |||||
validate.assertDisposed(); | |||||
} | |||||
/** | |||||
* Tests looking up an unknown service. | |||||
*/ | |||||
public void testUnknownService() throws Exception | |||||
{ | |||||
// Make sure that hasService() works correctly | |||||
final String serviceRole = "some-unknown-service"; | |||||
assertTrue( !m_serviceManager.hasService( serviceRole ) ); | |||||
// Make sure that lookup() fails | |||||
try | |||||
{ | |||||
m_serviceManager.lookup( serviceRole ); | |||||
fail(); | |||||
} | |||||
catch( ServiceException e ) | |||||
{ | |||||
final String message = REZ.getString( "create-service.error", serviceRole ); | |||||
assertSameMessage( message, e ); | |||||
} | |||||
} | |||||
/** | |||||
* Registers a service factory. | |||||
*/ | |||||
private void registerFactory( final String serviceRoleName, | |||||
final Class serviceType, | |||||
final Class factoryClass ) | |||||
throws Exception | |||||
{ | |||||
// TODO - add stuff to TypeDeployer to do this instead | |||||
final RoleManager roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | |||||
roleManager.addRole( new RoleInfo( serviceRoleName, null, serviceType ) ); | |||||
final DefaultTypeFactory typeFactory = new DefaultTypeFactory( getClass().getClassLoader() ); | |||||
typeFactory.addNameClassMapping( serviceRoleName, factoryClass.getName() ); | |||||
final TypeManager typeManager = (TypeManager)getServiceManager().lookup( TypeManager.ROLE ); | |||||
typeManager.registerType( ServiceFactory.ROLE, serviceRoleName, typeFactory ); | |||||
} | |||||
} |
@@ -1,90 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.service.test; | |||||
import junit.framework.Assert; | |||||
import org.apache.avalon.framework.activity.Initializable; | |||||
import org.apache.avalon.framework.activity.Disposable; | |||||
import org.apache.avalon.framework.logger.LogEnabled; | |||||
import org.apache.avalon.framework.logger.Logger; | |||||
import org.apache.avalon.framework.parameters.ParameterException; | |||||
import org.apache.avalon.framework.parameters.Parameterizable; | |||||
import org.apache.avalon.framework.parameters.Parameters; | |||||
import org.apache.avalon.framework.service.ServiceException; | |||||
import org.apache.avalon.framework.service.ServiceManager; | |||||
import org.apache.avalon.framework.service.Serviceable; | |||||
import org.apache.avalon.framework.context.Contextualizable; | |||||
import org.apache.avalon.framework.context.Context; | |||||
import org.apache.avalon.framework.context.ContextException; | |||||
/** | |||||
* A basic class that asserts that the object is correctly set-up. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class LifecycleValidator | |||||
extends Assert | |||||
implements LogEnabled, Contextualizable, Serviceable, Parameterizable, Initializable, Disposable | |||||
{ | |||||
private String m_state = STATE_NOT_INIT; | |||||
private final static String STATE_NOT_INIT = "not-prepared"; | |||||
private final static String STATE_LOG_ENABLED = "log-enabled"; | |||||
private final static String STATE_SERVICED = "serviced"; | |||||
private final static String STATE_PARAMETERISED = "parameterised"; | |||||
private final static String STATE_INITIALISED = "initialised"; | |||||
private final static String STATE_CONTEXTUALISED = "contextualised"; | |||||
private final static String STATE_DISPOSED = "disposed"; | |||||
public void enableLogging( final Logger logger ) | |||||
{ | |||||
assertEquals( STATE_NOT_INIT, m_state ); | |||||
m_state = STATE_LOG_ENABLED; | |||||
} | |||||
public void contextualize( final Context context ) throws ContextException | |||||
{ | |||||
assertEquals( STATE_LOG_ENABLED, m_state ); | |||||
m_state = STATE_CONTEXTUALISED; | |||||
} | |||||
public void service( final ServiceManager serviceManager ) throws ServiceException | |||||
{ | |||||
assertEquals( STATE_CONTEXTUALISED, m_state ); | |||||
m_state = STATE_SERVICED; | |||||
} | |||||
public void parameterize( final Parameters parameters ) throws ParameterException | |||||
{ | |||||
assertEquals( STATE_SERVICED, m_state ); | |||||
m_state = STATE_PARAMETERISED; | |||||
} | |||||
public void initialize() throws Exception | |||||
{ | |||||
assertEquals( STATE_PARAMETERISED, m_state ); | |||||
m_state = STATE_INITIALISED; | |||||
} | |||||
public void dispose() | |||||
{ | |||||
assertEquals( STATE_INITIALISED, m_state ); | |||||
m_state = STATE_DISPOSED; | |||||
} | |||||
protected void assertSetup() | |||||
{ | |||||
assertEquals( STATE_INITIALISED, m_state ); | |||||
} | |||||
protected void assertDisposed() | |||||
{ | |||||
assertEquals( STATE_DISPOSED, m_state ); | |||||
} | |||||
} |
@@ -1,19 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.service.test; | |||||
/** | |||||
* A service interface. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public interface TestService | |||||
{ | |||||
void doWork(); | |||||
} |
@@ -1,30 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.service.test; | |||||
import org.apache.myrmidon.interfaces.service.AntServiceException; | |||||
import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||||
/** | |||||
* A test service factory. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class TestServiceFactory1 | |||||
implements ServiceFactory | |||||
{ | |||||
/** | |||||
* Create a service that coresponds to this factory. | |||||
*/ | |||||
public Object createService() | |||||
throws AntServiceException | |||||
{ | |||||
return new TestServiceImpl1(); | |||||
} | |||||
} |
@@ -1,34 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.service.test; | |||||
import org.apache.myrmidon.interfaces.service.AntServiceException; | |||||
import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||||
import org.apache.myrmidon.components.service.test.LifecycleValidator; | |||||
/** | |||||
* A test service factory, which asserts that the factory has been properly | |||||
* set-up before it is used. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class TestServiceFactory2 | |||||
extends LifecycleValidator | |||||
implements ServiceFactory | |||||
{ | |||||
/** | |||||
* Create a service that corresponds to this factory. | |||||
*/ | |||||
public Object createService() | |||||
throws AntServiceException | |||||
{ | |||||
assertSetup(); | |||||
return new TestServiceImpl2(); | |||||
} | |||||
} |
@@ -1,24 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.service.test; | |||||
import org.apache.myrmidon.components.service.test.TestService; | |||||
/** | |||||
* A test service implementation. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class TestServiceImpl1 | |||||
implements TestService | |||||
{ | |||||
public void doWork() | |||||
{ | |||||
} | |||||
} |
@@ -1,27 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.components.service.test; | |||||
import org.apache.myrmidon.components.service.test.LifecycleValidator; | |||||
import org.apache.myrmidon.components.service.test.TestService; | |||||
/** | |||||
* A test service that asserts it has been set-up correctly. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class TestServiceImpl2 | |||||
extends LifecycleValidator | |||||
implements TestService | |||||
{ | |||||
public void doWork() | |||||
{ | |||||
assertSetup(); | |||||
} | |||||
} |
@@ -1,123 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.interfaces.model.test; | |||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
import org.apache.myrmidon.interfaces.model.DefaultNameValidator; | |||||
/** | |||||
* TestCases for {@link org.apache.myrmidon.interfaces.model.DefaultNameValidator}. | |||||
* | |||||
* @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class DefaultNameValidatorTestCase | |||||
extends AbstractMyrmidonTest | |||||
{ | |||||
private DefaultNameValidator m_validator = new DefaultNameValidator(); | |||||
public DefaultNameValidatorTestCase( String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Test valid names for the default validator. | |||||
*/ | |||||
public void testValidNames() throws Exception | |||||
{ | |||||
testValid( "aName" ); | |||||
testValid( "123456" ); | |||||
testValid( "s p a ce s" ); | |||||
testValid( "d-a-s-h-e-s-" ); | |||||
testValid( "d.o.t.s." ); | |||||
testValid( "_u_n_d_e_r_s_c_o_r_e_s" ); | |||||
testValid( "a" ); | |||||
testValid( "1" ); | |||||
testValid( "_" ); | |||||
} | |||||
/** | |||||
* Test invalid names for the default validator. | |||||
*/ | |||||
public void testInvalidNames() throws Exception | |||||
{ | |||||
testInvalid( "" ); | |||||
testInvalid( " " ); | |||||
testInvalid( " " ); | |||||
testInvalid( " bad" ); | |||||
testInvalid( "bad " ); | |||||
testInvalid( " bad " ); | |||||
testInvalid( "-dashfirst" ); | |||||
testInvalid( ".dotfirst" ); | |||||
testInvalid( "question?" ); | |||||
} | |||||
/** | |||||
* Test that certain characters are disallowed in the default validator. | |||||
*/ | |||||
public void testReservedChars() throws Exception | |||||
{ | |||||
String reserved = "!@#$%^&*()+=~`{}[]|\\/?<>,:;"; | |||||
for( int pos = 0; pos < reserved.length(); pos++ ) | |||||
{ | |||||
char chr = reserved.charAt( pos ); | |||||
testReservedChar( chr ); | |||||
} | |||||
} | |||||
private void testReservedChar( char chr ) throws Exception | |||||
{ | |||||
String test = "a" + String.valueOf( chr ); | |||||
testInvalid( test ); | |||||
} | |||||
/** | |||||
* Test validation using a restrictive set of validation rules. | |||||
*/ | |||||
public void testStrictNames() throws Exception | |||||
{ | |||||
m_validator = new DefaultNameValidator( false, false, "", false, false, "." ); | |||||
testValid( "name" ); | |||||
testValid( "a" ); | |||||
testValid( "yep.ok" ); | |||||
testInvalid( "_nogood" ); | |||||
testInvalid( "no_good" ); | |||||
testInvalid( "nope1" ); | |||||
testInvalid( "123" ); | |||||
testInvalid( "not ok" ); | |||||
} | |||||
private void testValid( String name ) | |||||
{ | |||||
try | |||||
{ | |||||
m_validator.validate( name ); | |||||
} | |||||
catch( Exception e ) | |||||
{ | |||||
fail( e.getMessage() ); | |||||
} | |||||
} | |||||
private void testInvalid( String name ) | |||||
{ | |||||
try | |||||
{ | |||||
m_validator.validate( name ); | |||||
fail( "Name \"" + name + "\" should be invalid." ); | |||||
} | |||||
catch( Exception e ) | |||||
{ | |||||
} | |||||
} | |||||
} |
@@ -1,22 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.interfaces.type.test; | |||||
/** | |||||
* A basic implementation of a type to test the type factory. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class MyType1 | |||||
{ | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
return object.getClass() == getClass(); | |||||
} | |||||
} |
@@ -1,22 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.interfaces.type.test; | |||||
/** | |||||
* A basic implementation of a type to test the type factory. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class MyType2 | |||||
{ | |||||
public boolean equals( final Object object ) | |||||
{ | |||||
return object.getClass() == getClass(); | |||||
} | |||||
} |
@@ -1,85 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.interfaces.type.test; | |||||
import java.io.File; | |||||
import java.net.URL; | |||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||||
import org.apache.myrmidon.interfaces.type.ReloadingTypeFactory; | |||||
import org.apache.myrmidon.interfaces.type.TypeException; | |||||
/** | |||||
* These are unit tests that test the basic operation of TypeFactories. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class TypeFactoryTestCase | |||||
extends AbstractMyrmidonTest | |||||
{ | |||||
private final static String TYPE_NAME1 = "my-type1"; | |||||
private final static String TYPE_NAME2 = "my-type2"; | |||||
private final static Class TYPE_CLASS1 = MyType1.class; | |||||
private final static Class TYPE_CLASS2 = MyType2.class; | |||||
private final static String TYPE_CLASSNAME1 = TYPE_CLASS1.getName(); | |||||
private final static String TYPE_CLASSNAME2 = TYPE_CLASS2.getName(); | |||||
public TypeFactoryTestCase( final String name ) | |||||
{ | |||||
super( name ); | |||||
} | |||||
/** | |||||
* Make sure that you can load a basic type from DefaultTypeManager. | |||||
*/ | |||||
public void testBasicType() | |||||
{ | |||||
final ClassLoader classLoader = getClass().getClassLoader(); | |||||
final DefaultTypeFactory factory = new DefaultTypeFactory( classLoader ); | |||||
factory.addNameClassMapping( TYPE_NAME2, TYPE_CLASSNAME2 ); | |||||
try | |||||
{ | |||||
final Object type = factory.create( TYPE_NAME2 ); | |||||
final Class typeClass = type.getClass(); | |||||
assertEquals( "The type loaded for factory should be same class as in current classloader", | |||||
typeClass, TYPE_CLASS2 ); | |||||
} | |||||
catch( TypeException e ) | |||||
{ | |||||
fail( "Unable to create Type due to " + e ); | |||||
} | |||||
} | |||||
/** | |||||
* Make sure that when you load a type from a RelaodableTypeFactory | |||||
* that it is actually reloaded. | |||||
*/ | |||||
public void testReloadingTypeFactory() | |||||
throws Exception | |||||
{ | |||||
final File file = getTestResource( "types.jar" ); | |||||
final URL[] classpath = new URL[]{file.toURL()}; | |||||
final ReloadingTypeFactory factory = new ReloadingTypeFactory( classpath, null ); | |||||
factory.addNameClassMapping( TYPE_NAME1, TYPE_CLASSNAME1 ); | |||||
try | |||||
{ | |||||
final Object type = factory.create( TYPE_NAME1 ); | |||||
final Class typeClass = type.getClass(); | |||||
final boolean sameClass = typeClass == TYPE_CLASS1; | |||||
assertTrue( "The type loaded for factory should not be same class as in current classloader", | |||||
!sameClass ); | |||||
} | |||||
catch( TypeException e ) | |||||
{ | |||||
fail( "Unable to create Type due to " + e ); | |||||
} | |||||
} | |||||
} |