* Added general purpose Object -> String converter that simply uses Object.toString(). * Reorganised AbstractComponentTestCase, to give sub-classes the opportunity to replace the default implementation of a component, with a particular implementation. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271942 13f79535-47bb-0310-9956-ffa450edef68master
@@ -0,0 +1,38 @@ | |||||
/* | |||||
* 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.antlib.core; | |||||
import org.apache.aut.converter.AbstractConverter; | |||||
import org.apache.aut.converter.ConverterException; | |||||
/** | |||||
* A general-purpose converter that converts an Object to a String using | |||||
* its toString() method. | |||||
* | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
* | |||||
* @ant:converter source="java.lang.Object" destination="java.lang.String" | |||||
*/ | |||||
public class ObjectToStringConverter | |||||
extends AbstractConverter | |||||
{ | |||||
public ObjectToStringConverter() | |||||
{ | |||||
super( Object.class, String.class ); | |||||
} | |||||
/** | |||||
* Converts an object. | |||||
*/ | |||||
protected Object convert( final Object original, final Object context ) | |||||
throws ConverterException | |||||
{ | |||||
return original.toString(); | |||||
} | |||||
} |
@@ -7,10 +7,15 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.property; | package org.apache.myrmidon.components.property; | ||||
import org.apache.aut.converter.Converter; | |||||
import org.apache.aut.converter.ConverterException; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.avalon.framework.service.ServiceException; | |||||
import org.apache.avalon.framework.service.ServiceManager; | |||||
import org.apache.avalon.framework.service.Serviceable; | |||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | import org.apache.myrmidon.interfaces.property.PropertyResolver; | ||||
/** | /** | ||||
@@ -21,11 +26,18 @@ import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class DefaultPropertyResolver | public class DefaultPropertyResolver | ||||
implements PropertyResolver | |||||
implements PropertyResolver, Serviceable | |||||
{ | { | ||||
private final static Resources REZ = | private final static Resources REZ = | ||||
ResourceManager.getPackageResources( DefaultPropertyResolver.class ); | ResourceManager.getPackageResources( DefaultPropertyResolver.class ); | ||||
private Converter m_converter; | |||||
public void service( final ServiceManager serviceManager ) throws ServiceException | |||||
{ | |||||
m_converter = (Converter)serviceManager.lookup( Converter.ROLE ); | |||||
} | |||||
/** | /** | ||||
* Resolve a string property. This evaluates all property | * Resolve a string property. This evaluates all property | ||||
* substitutions based on specified context. | * substitutions based on specified context. | ||||
@@ -66,9 +78,9 @@ public class DefaultPropertyResolver | |||||
while( true ) | while( true ) | ||||
{ | { | ||||
final Object propertyValue = | |||||
getPropertyValue( content.substring( start + 2, end ), | |||||
context ); | |||||
final String propertyValue = | |||||
getPropertyStringValue( content.substring( start + 2, end ), | |||||
context ); | |||||
sb.append( content.substring( lastPlace, start ) ); | sb.append( content.substring( lastPlace, start ) ); | ||||
sb.append( propertyValue ); | sb.append( propertyValue ); | ||||
@@ -127,7 +139,7 @@ public class DefaultPropertyResolver | |||||
{ | { | ||||
final String propertyName = content.substring( start + 2, end ); | final String propertyName = content.substring( start + 2, end ); | ||||
final Object key = recursiveResolveProperty( propertyName, context ); | final Object key = recursiveResolveProperty( propertyName, context ); | ||||
final Object value = getPropertyValue( key.toString(), context ); | |||||
final String value = getPropertyStringValue( key.toString(), context ); | |||||
sb.append( content.substring( lastPlace, start ) ); | sb.append( content.substring( lastPlace, start ) ); | ||||
sb.append( value ); | sb.append( value ); | ||||
@@ -228,6 +240,28 @@ public class DefaultPropertyResolver | |||||
throw new TaskException( message ); | throw new TaskException( message ); | ||||
} | } | ||||
/** | |||||
* Returns a property's value, converted to a String. | |||||
*/ | |||||
private String getPropertyStringValue( final String propertyName, | |||||
final TaskContext context ) | |||||
throws TaskException | |||||
{ | |||||
final Object value = getPropertyValue( propertyName, context ); | |||||
if( value instanceof String ) | |||||
{ | |||||
return (String)value; | |||||
} | |||||
try | |||||
{ | |||||
return (String)m_converter.convert( String.class, value, context ); | |||||
} | |||||
catch( final ConverterException e ) | |||||
{ | |||||
throw new TaskException( e.getMessage(), e ); | |||||
} | |||||
} | |||||
/** | /** | ||||
* Retrieve a value from the specified context using the specified key. | * Retrieve a value from the specified context using the specified key. | ||||
* | * | ||||
@@ -73,27 +73,27 @@ public abstract class AbstractComponentTest | |||||
m_serviceManager = new DefaultServiceManager(); | m_serviceManager = new DefaultServiceManager(); | ||||
List components = new ArrayList(); | List components = new ArrayList(); | ||||
Object component = new DefaultMasterConverter(); | |||||
Object component = createComponent( Converter.ROLE, DefaultMasterConverter.class ); | |||||
m_serviceManager.put( Converter.ROLE, component ); | m_serviceManager.put( Converter.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultConverterRegistry(); | |||||
component = createComponent( ConverterRegistry.ROLE, DefaultConverterRegistry.class ); | |||||
m_serviceManager.put( ConverterRegistry.ROLE, component ); | m_serviceManager.put( ConverterRegistry.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultTypeManager(); | |||||
component = createComponent( TypeManager.ROLE, DefaultTypeManager.class ); | |||||
m_serviceManager.put( TypeManager.ROLE, component ); | m_serviceManager.put( TypeManager.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultConfigurer(); | |||||
component = createComponent( Configurer.ROLE, DefaultConfigurer.class ); | |||||
m_serviceManager.put( Configurer.ROLE, component ); | m_serviceManager.put( Configurer.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultDeployer(); | |||||
component = createComponent( Deployer.ROLE, DefaultDeployer.class ); | |||||
m_serviceManager.put( Deployer.ROLE, component ); | m_serviceManager.put( Deployer.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultExecutor(); | |||||
component = createComponent( Executor.ROLE, DefaultExecutor.class ); | |||||
m_serviceManager.put( Executor.ROLE, component ); | m_serviceManager.put( Executor.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
@@ -102,15 +102,15 @@ public abstract class AbstractComponentTest | |||||
m_serviceManager.put( ClassLoaderManager.ROLE, classLoaderMgr ); | m_serviceManager.put( ClassLoaderManager.ROLE, classLoaderMgr ); | ||||
components.add( classLoaderMgr ); | components.add( classLoaderMgr ); | ||||
component = new DefaultExtensionManager(); | |||||
component = createComponent( ExtensionManager.ROLE, DefaultExtensionManager.class ); | |||||
m_serviceManager.put( ExtensionManager.ROLE, component ); | m_serviceManager.put( ExtensionManager.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultRoleManager(); | |||||
component = createComponent( RoleManager.ROLE, DefaultRoleManager.class ); | |||||
m_serviceManager.put( RoleManager.ROLE, component ); | m_serviceManager.put( RoleManager.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultPropertyResolver(); | |||||
component = createComponent( PropertyResolver.ROLE, DefaultPropertyResolver.class ); | |||||
m_serviceManager.put( PropertyResolver.ROLE, component ); | m_serviceManager.put( PropertyResolver.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
@@ -147,6 +147,16 @@ public abstract class AbstractComponentTest | |||||
return m_serviceManager; | return m_serviceManager; | ||||
} | } | ||||
/** | |||||
* 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 | |||||
{ | |||||
return defaultImpl.newInstance(); | |||||
} | |||||
/** | /** | ||||
* Returns the type manager. | * Returns the type manager. | ||||
*/ | */ | ||||
@@ -15,6 +15,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
import org.apache.avalon.framework.configuration.DefaultConfiguration; | import org.apache.avalon.framework.configuration.DefaultConfiguration; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.components.AbstractComponentTest; | import org.apache.myrmidon.components.AbstractComponentTest; | ||||
import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestAttributeConvert; | 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.ConfigTestConfigAdder; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestContent; | import org.apache.myrmidon.components.configurer.test.data.ConfigTestContent; | ||||
@@ -30,6 +31,7 @@ import org.apache.myrmidon.components.configurer.test.data.ConfigTestPropResolut | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceAttribute; | 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.ConfigTestReferenceConversion; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceElement; | 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.ConfigTestSetAttribute; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetElement; | 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.ConfigTestTypedAdder; | ||||
@@ -38,7 +40,6 @@ import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdderR | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdderRole; | 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.ConfigTestTypedConfigAdder; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestUnknownReference; | import org.apache.myrmidon.components.configurer.test.data.ConfigTestUnknownReference; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetAndAdd; | |||||
import org.apache.myrmidon.components.workspace.DefaultTaskContext; | import org.apache.myrmidon.components.workspace.DefaultTaskContext; | ||||
import org.apache.myrmidon.framework.DataType; | import org.apache.myrmidon.framework.DataType; | ||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
@@ -80,6 +81,23 @@ public class DefaultConfigurerTestCase | |||||
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | 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. | * Tests setting an attribute, via a setter method. | ||||
*/ | */ | ||||
@@ -11,6 +11,7 @@ import java.io.File; | |||||
import org.apache.aut.converter.Converter; | import org.apache.aut.converter.Converter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.myrmidon.components.AbstractComponentTest; | import org.apache.myrmidon.components.AbstractComponentTest; | ||||
import org.apache.myrmidon.components.deployer.DefaultDeployer; | |||||
import org.apache.myrmidon.framework.DataType; | import org.apache.myrmidon.framework.DataType; | ||||
import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | ||||
import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
@@ -48,6 +49,23 @@ public class DefaultDeployerTestCase | |||||
m_converter = (Converter)getServiceManager().lookup( Converter.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. | * Tests deployment of a single type from a ClassLoader. | ||||
*/ | */ | ||||
@@ -9,10 +9,11 @@ package org.apache.myrmidon.components.property.test; | |||||
import java.io.File; | import java.io.File; | ||||
import java.util.Date; | import java.util.Date; | ||||
import org.apache.antlib.core.ObjectToStringConverter; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.components.AbstractComponentTest; | |||||
import org.apache.myrmidon.components.workspace.DefaultTaskContext; | import org.apache.myrmidon.components.workspace.DefaultTaskContext; | ||||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | import org.apache.myrmidon.interfaces.property.PropertyResolver; | ||||
@@ -23,25 +24,44 @@ import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public abstract class AbstractPropertyResolverTestCase | public abstract class AbstractPropertyResolverTestCase | ||||
extends AbstractMyrmidonTest | |||||
extends AbstractComponentTest | |||||
{ | { | ||||
protected final static Resources REZ = getResourcesForTested( AbstractPropertyResolverTestCase.class ); | protected final static Resources REZ = getResourcesForTested( AbstractPropertyResolverTestCase.class ); | ||||
protected PropertyResolver m_resolver; | protected PropertyResolver m_resolver; | ||||
protected DefaultTaskContext m_context; | protected DefaultTaskContext m_context; | ||||
public AbstractPropertyResolverTestCase( String name ) | |||||
public AbstractPropertyResolverTestCase( final String name ) | |||||
{ | { | ||||
super( name ); | super( name ); | ||||
} | } | ||||
protected void setUp() throws Exception | protected void setUp() throws Exception | ||||
{ | { | ||||
m_resolver = createResolver(); | |||||
m_resolver = (PropertyResolver)getServiceManager().lookup( PropertyResolver.ROLE ); | |||||
m_context = new DefaultTaskContext( null, null, getLogger() ); | m_context = new DefaultTaskContext( null, null, getLogger() ); | ||||
m_context.setProperty( "intProp", new Integer( 333 ) ); | m_context.setProperty( "intProp", new Integer( 333 ) ); | ||||
m_context.setProperty( "stringProp", "String property" ); | 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 ); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
@@ -65,7 +85,7 @@ public abstract class AbstractPropertyResolverTestCase | |||||
/** | /** | ||||
* Simple tests with property on it's own, and accompanied by text. | * Simple tests with property on it's own, and accompanied by text. | ||||
*/ | */ | ||||
private void testPropertyValue( Object propObject ) | |||||
private void testPropertyValue( final Object propObject ) | |||||
throws Exception | throws Exception | ||||
{ | { | ||||
m_context.setProperty( "typedProp", propObject ); | m_context.setProperty( "typedProp", propObject ); | ||||
@@ -73,27 +73,27 @@ public abstract class AbstractComponentTest | |||||
m_serviceManager = new DefaultServiceManager(); | m_serviceManager = new DefaultServiceManager(); | ||||
List components = new ArrayList(); | List components = new ArrayList(); | ||||
Object component = new DefaultMasterConverter(); | |||||
Object component = createComponent( Converter.ROLE, DefaultMasterConverter.class ); | |||||
m_serviceManager.put( Converter.ROLE, component ); | m_serviceManager.put( Converter.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultConverterRegistry(); | |||||
component = createComponent( ConverterRegistry.ROLE, DefaultConverterRegistry.class ); | |||||
m_serviceManager.put( ConverterRegistry.ROLE, component ); | m_serviceManager.put( ConverterRegistry.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultTypeManager(); | |||||
component = createComponent( TypeManager.ROLE, DefaultTypeManager.class ); | |||||
m_serviceManager.put( TypeManager.ROLE, component ); | m_serviceManager.put( TypeManager.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultConfigurer(); | |||||
component = createComponent( Configurer.ROLE, DefaultConfigurer.class ); | |||||
m_serviceManager.put( Configurer.ROLE, component ); | m_serviceManager.put( Configurer.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultDeployer(); | |||||
component = createComponent( Deployer.ROLE, DefaultDeployer.class ); | |||||
m_serviceManager.put( Deployer.ROLE, component ); | m_serviceManager.put( Deployer.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultExecutor(); | |||||
component = createComponent( Executor.ROLE, DefaultExecutor.class ); | |||||
m_serviceManager.put( Executor.ROLE, component ); | m_serviceManager.put( Executor.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
@@ -102,15 +102,15 @@ public abstract class AbstractComponentTest | |||||
m_serviceManager.put( ClassLoaderManager.ROLE, classLoaderMgr ); | m_serviceManager.put( ClassLoaderManager.ROLE, classLoaderMgr ); | ||||
components.add( classLoaderMgr ); | components.add( classLoaderMgr ); | ||||
component = new DefaultExtensionManager(); | |||||
component = createComponent( ExtensionManager.ROLE, DefaultExtensionManager.class ); | |||||
m_serviceManager.put( ExtensionManager.ROLE, component ); | m_serviceManager.put( ExtensionManager.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultRoleManager(); | |||||
component = createComponent( RoleManager.ROLE, DefaultRoleManager.class ); | |||||
m_serviceManager.put( RoleManager.ROLE, component ); | m_serviceManager.put( RoleManager.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultPropertyResolver(); | |||||
component = createComponent( PropertyResolver.ROLE, DefaultPropertyResolver.class ); | |||||
m_serviceManager.put( PropertyResolver.ROLE, component ); | m_serviceManager.put( PropertyResolver.ROLE, component ); | ||||
components.add( component ); | components.add( component ); | ||||
@@ -147,6 +147,16 @@ public abstract class AbstractComponentTest | |||||
return m_serviceManager; | return m_serviceManager; | ||||
} | } | ||||
/** | |||||
* 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 | |||||
{ | |||||
return defaultImpl.newInstance(); | |||||
} | |||||
/** | /** | ||||
* Returns the type manager. | * Returns the type manager. | ||||
*/ | */ | ||||
@@ -15,6 +15,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
import org.apache.avalon.framework.configuration.DefaultConfiguration; | import org.apache.avalon.framework.configuration.DefaultConfiguration; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.components.AbstractComponentTest; | import org.apache.myrmidon.components.AbstractComponentTest; | ||||
import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestAttributeConvert; | 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.ConfigTestConfigAdder; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestContent; | import org.apache.myrmidon.components.configurer.test.data.ConfigTestContent; | ||||
@@ -30,6 +31,7 @@ import org.apache.myrmidon.components.configurer.test.data.ConfigTestPropResolut | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceAttribute; | 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.ConfigTestReferenceConversion; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceElement; | 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.ConfigTestSetAttribute; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetElement; | 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.ConfigTestTypedAdder; | ||||
@@ -38,7 +40,6 @@ import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdderR | |||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdderRole; | 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.ConfigTestTypedConfigAdder; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestUnknownReference; | import org.apache.myrmidon.components.configurer.test.data.ConfigTestUnknownReference; | ||||
import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetAndAdd; | |||||
import org.apache.myrmidon.components.workspace.DefaultTaskContext; | import org.apache.myrmidon.components.workspace.DefaultTaskContext; | ||||
import org.apache.myrmidon.framework.DataType; | import org.apache.myrmidon.framework.DataType; | ||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
@@ -80,6 +81,23 @@ public class DefaultConfigurerTestCase | |||||
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | 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. | * Tests setting an attribute, via a setter method. | ||||
*/ | */ | ||||
@@ -11,6 +11,7 @@ import java.io.File; | |||||
import org.apache.aut.converter.Converter; | import org.apache.aut.converter.Converter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.myrmidon.components.AbstractComponentTest; | import org.apache.myrmidon.components.AbstractComponentTest; | ||||
import org.apache.myrmidon.components.deployer.DefaultDeployer; | |||||
import org.apache.myrmidon.framework.DataType; | import org.apache.myrmidon.framework.DataType; | ||||
import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | ||||
import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
@@ -48,6 +49,23 @@ public class DefaultDeployerTestCase | |||||
m_converter = (Converter)getServiceManager().lookup( Converter.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. | * Tests deployment of a single type from a ClassLoader. | ||||
*/ | */ | ||||
@@ -9,10 +9,11 @@ package org.apache.myrmidon.components.property.test; | |||||
import java.io.File; | import java.io.File; | ||||
import java.util.Date; | import java.util.Date; | ||||
import org.apache.antlib.core.ObjectToStringConverter; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.components.AbstractComponentTest; | |||||
import org.apache.myrmidon.components.workspace.DefaultTaskContext; | import org.apache.myrmidon.components.workspace.DefaultTaskContext; | ||||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | import org.apache.myrmidon.interfaces.property.PropertyResolver; | ||||
@@ -23,25 +24,44 @@ import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public abstract class AbstractPropertyResolverTestCase | public abstract class AbstractPropertyResolverTestCase | ||||
extends AbstractMyrmidonTest | |||||
extends AbstractComponentTest | |||||
{ | { | ||||
protected final static Resources REZ = getResourcesForTested( AbstractPropertyResolverTestCase.class ); | protected final static Resources REZ = getResourcesForTested( AbstractPropertyResolverTestCase.class ); | ||||
protected PropertyResolver m_resolver; | protected PropertyResolver m_resolver; | ||||
protected DefaultTaskContext m_context; | protected DefaultTaskContext m_context; | ||||
public AbstractPropertyResolverTestCase( String name ) | |||||
public AbstractPropertyResolverTestCase( final String name ) | |||||
{ | { | ||||
super( name ); | super( name ); | ||||
} | } | ||||
protected void setUp() throws Exception | protected void setUp() throws Exception | ||||
{ | { | ||||
m_resolver = createResolver(); | |||||
m_resolver = (PropertyResolver)getServiceManager().lookup( PropertyResolver.ROLE ); | |||||
m_context = new DefaultTaskContext( null, null, getLogger() ); | m_context = new DefaultTaskContext( null, null, getLogger() ); | ||||
m_context.setProperty( "intProp", new Integer( 333 ) ); | m_context.setProperty( "intProp", new Integer( 333 ) ); | ||||
m_context.setProperty( "stringProp", "String property" ); | 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 ); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
@@ -65,7 +85,7 @@ public abstract class AbstractPropertyResolverTestCase | |||||
/** | /** | ||||
* Simple tests with property on it's own, and accompanied by text. | * Simple tests with property on it's own, and accompanied by text. | ||||
*/ | */ | ||||
private void testPropertyValue( Object propObject ) | |||||
private void testPropertyValue( final Object propObject ) | |||||
throws Exception | throws Exception | ||||
{ | { | ||||
m_context.setProperty( "typedProp", propObject ); | m_context.setProperty( "typedProp", propObject ); | ||||