explicitly deploy a type. These replace the multi-arg deployX() methods. * ConverterDef now sub-classes AbstractTypeDef. * Changed AbstractTypeDef to use TypeDefinition objects, and to configure them using the configurer. Removed all setX() methods from AbstractTypeDef and sub-classes. * Added some units tests for DefaultDeployer. * Moved component set-up from DefaultConfigurerTest -> super class. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271072 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -480,7 +480,7 @@ Legal: | |||||
| </zip> | </zip> | ||||
| <junit printsummary="on" | <junit printsummary="on" | ||||
| fork="false"> | |||||
| fork="true"> | |||||
| <formatter type="brief" usefile="false"/> | <formatter type="brief" usefile="false"/> | ||||
| <classpath refid="project.class.path"/> | <classpath refid="project.class.path"/> | ||||
| <classpath location="${test.classes}"/> | <classpath location="${test.classes}"/> | ||||
| @@ -492,7 +492,9 @@ Legal: | |||||
| <sysproperty key="test.ftp.uri" value="ftp://${vfs.user}:${vfs.password}@${vfs.host}/home/${vfs.user}/vfs"/> | <sysproperty key="test.ftp.uri" value="ftp://${vfs.user}:${vfs.password}@${vfs.host}/home/${vfs.user}/vfs"/> | ||||
| <batchtest> | <batchtest> | ||||
| <fileset dir="${test.classes}" includes="**/*Test.class"> | |||||
| <fileset dir="${test.classes}"> | |||||
| <include name="**/*Test.class" unless="single.test"/> | |||||
| <include name="**/${single.test}Test.class" if="single.test"/> | |||||
| <exclude name="**/SmbFileSystemTest.class" unless="test.smb"/> | <exclude name="**/SmbFileSystemTest.class" unless="test.smb"/> | ||||
| <exclude name="**/FtpFileSystemTest.class" unless="test.ftp"/> | <exclude name="**/FtpFileSystemTest.class" unless="test.ftp"/> | ||||
| </fileset> | </fileset> | ||||
| @@ -7,13 +7,9 @@ | |||||
| */ | */ | ||||
| package org.apache.antlib.runtime; | package org.apache.antlib.runtime; | ||||
| import java.io.File; | |||||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
| import org.apache.avalon.excalibur.i18n.Resources; | |||||
| import org.apache.myrmidon.api.AbstractTask; | |||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||||
| import org.apache.myrmidon.framework.AbstractTypeDef; | |||||
| import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | |||||
| /** | /** | ||||
| * Task to define a converter. | * Task to define a converter. | ||||
| @@ -21,71 +17,11 @@ import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public class ConverterDef | public class ConverterDef | ||||
| extends AbstractTask | |||||
| extends AbstractTypeDef | |||||
| { | { | ||||
| private final static Resources REZ = | |||||
| ResourceManager.getPackageResources( ConverterDef.class ); | |||||
| private String m_sourceType; | |||||
| private String m_destinationType; | |||||
| private File m_lib; | |||||
| private String m_classname; | |||||
| public void setLib( final File lib ) | |||||
| { | |||||
| m_lib = lib; | |||||
| } | |||||
| public void setClassname( final String classname ) | |||||
| { | |||||
| m_classname = classname; | |||||
| } | |||||
| public void setSourceType( final String sourceType ) | |||||
| protected TypeDefinition createTypeDefinition() | |||||
| { | { | ||||
| m_sourceType = sourceType; | |||||
| } | |||||
| public void setDestinationType( final String destinationType ) | |||||
| { | |||||
| m_destinationType = destinationType; | |||||
| } | |||||
| public void execute() | |||||
| throws TaskException | |||||
| { | |||||
| if( null == m_classname ) | |||||
| { | |||||
| final String message = REZ.getString( "converterdef.no-classname.error" ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| else if( null == m_sourceType ) | |||||
| { | |||||
| final String message = REZ.getString( "converterdef.no-source.error" ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| else if( null == m_destinationType ) | |||||
| { | |||||
| final String message = REZ.getString( "converterdef.no-destination.error" ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| else if( null == m_lib ) | |||||
| { | |||||
| final String message = REZ.getString( "converterdef.no-lib.error" ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| try | |||||
| { | |||||
| // Locate the deployer, then deploy the converter | |||||
| final Deployer deployer = (Deployer)getService( Deployer.class ); | |||||
| final TypeDeployer typeDeployer = deployer.createDeployer( m_lib ); | |||||
| typeDeployer.deployConverter( m_classname, m_sourceType, m_destinationType ); | |||||
| } | |||||
| catch( final Exception e ) | |||||
| { | |||||
| final String message = REZ.getString( "converterdef.no-register.error", m_classname ); | |||||
| throw new TaskException( message, e ); | |||||
| } | |||||
| return new ConverterDefinition(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,9 +1,3 @@ | |||||
| converterdef.no-classname.error=Must specify classname parameter. | |||||
| converterdef.no-source.error=Must specify the source-type parameter. | |||||
| converterdef.no-destination.error=Must specify the destination-type parameter. | |||||
| converterdef.no-lib.error=Must specify the lib parameter. | |||||
| converterdef.no-register.error=Failed to register converter {0}. | |||||
| facility.no-create.error=Failed to create aspect handler of type {0}. | facility.no-create.error=Failed to create aspect handler of type {0}. | ||||
| facility.multi-element.error=Expected one sub-element to configure facility. | facility.multi-element.error=Expected one sub-element to configure facility. | ||||
| facility.no-namespace.error=Must specify namespace parameter. | facility.no-namespace.error=Must specify namespace parameter. | ||||
| @@ -8,6 +8,8 @@ | |||||
| package org.apache.antlib.runtime; | package org.apache.antlib.runtime; | ||||
| import org.apache.myrmidon.framework.AbstractTypeDef; | import org.apache.myrmidon.framework.AbstractTypeDef; | ||||
| import org.apache.myrmidon.interfaces.deployer.GeneralTypeDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | |||||
| /** | /** | ||||
| * Task to define a type. | * Task to define a type. | ||||
| @@ -17,15 +19,9 @@ import org.apache.myrmidon.framework.AbstractTypeDef; | |||||
| public class TypeDef | public class TypeDef | ||||
| extends AbstractTypeDef | extends AbstractTypeDef | ||||
| { | { | ||||
| private String m_type; | |||||
| public void setType( final String type ) | |||||
| protected TypeDefinition createTypeDefinition() | |||||
| { | { | ||||
| m_type = type; | |||||
| } | |||||
| protected String getRoleShorthand() | |||||
| { | |||||
| return m_type; | |||||
| return new GeneralTypeDefinition(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -110,7 +110,7 @@ public class DefaultDeployer | |||||
| } | } | ||||
| catch( Exception e ) | catch( Exception e ) | ||||
| { | { | ||||
| final String message = REZ.getString( "deploy-from-classloader.error" ); | |||||
| final String message = REZ.getString( "deploy-from-classloader.error", loader ); | |||||
| throw new DeploymentException( message, e ); | throw new DeploymentException( message, e ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -27,7 +27,9 @@ import org.apache.avalon.framework.configuration.SAXConfigurationHandler; | |||||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | import org.apache.avalon.framework.logger.AbstractLogEnabled; | ||||
| import org.apache.myrmidon.converter.Converter; | import org.apache.myrmidon.converter.Converter; | ||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | ||||
| import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.DeploymentException; | import org.apache.myrmidon.interfaces.deployer.DeploymentException; | ||||
| import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | ||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| @@ -178,44 +180,62 @@ class Deployment | |||||
| /** | /** | ||||
| * Deploys a single type from the type library. | * Deploys a single type from the type library. | ||||
| */ | */ | ||||
| public void deployType( String roleShorthand, String typeName, String className ) | |||||
| public void deployType( final TypeDefinition typeDef ) | |||||
| throws DeploymentException | throws DeploymentException | ||||
| { | { | ||||
| try | |||||
| { | |||||
| handleType( roleShorthand, typeName, className ); | |||||
| } | |||||
| catch( Exception e ) | |||||
| final String typeName = typeDef.getName(); | |||||
| final String roleShorthand = typeDef.getRoleShorthand(); | |||||
| final String className = typeDef.getClassname(); | |||||
| if( null == className ) | |||||
| { | { | ||||
| final String message = REZ.getString( "deploy-type.error", roleShorthand, typeName ); | |||||
| throw new DeploymentException( message, e ); | |||||
| final String message = REZ.getString( "typedef.no-classname.error" ); | |||||
| throw new DeploymentException( message ); | |||||
| } | } | ||||
| } | |||||
| /** | |||||
| * Deploys a converter from the type library. The converter definition | |||||
| * is read from the type library descriptor. | |||||
| */ | |||||
| public void deployConverter( String className ) | |||||
| throws DeploymentException | |||||
| { | |||||
| // TODO - implement this | |||||
| throw new DeploymentException( "Not implemented." ); | |||||
| } | |||||
| /** | |||||
| * Deploys a converter from the type library. | |||||
| */ | |||||
| public void deployConverter( String className, String srcClass, String destClass ) | |||||
| throws DeploymentException | |||||
| { | |||||
| try | try | ||||
| { | { | ||||
| handleConverter( className, srcClass, destClass ); | |||||
| if( typeDef instanceof ConverterDefinition ) | |||||
| { | |||||
| // Validate the definition | |||||
| final ConverterDefinition converterDef = (ConverterDefinition)typeDef; | |||||
| final String srcClass = converterDef.getSourceType(); | |||||
| final String destClass = converterDef.getDestinationType(); | |||||
| if( null == srcClass ) | |||||
| { | |||||
| final String message = REZ.getString( "converterdef.no-source.error" ); | |||||
| throw new DeploymentException( message ); | |||||
| } | |||||
| if( null == destClass ) | |||||
| { | |||||
| final String message = REZ.getString( "converterdef.no-destination.error" ); | |||||
| throw new DeploymentException( message ); | |||||
| } | |||||
| // Deploy the converter | |||||
| handleConverter( className, srcClass, destClass ); | |||||
| } | |||||
| else | |||||
| { | |||||
| // Validate the definition | |||||
| if( null == roleShorthand ) | |||||
| { | |||||
| final String message = REZ.getString( "typedef.no-role.error" ); | |||||
| throw new DeploymentException( message ); | |||||
| } | |||||
| else if( null == typeName ) | |||||
| { | |||||
| final String message = REZ.getString( "typedef.no-name.error" ); | |||||
| throw new DeploymentException( message ); | |||||
| } | |||||
| // Deploy general-purpose type | |||||
| handleType( roleShorthand, typeName, className ); | |||||
| } | |||||
| } | } | ||||
| catch( Exception e ) | catch( Exception e ) | ||||
| { | { | ||||
| final String message = REZ.getString( "deploy-converter.error", srcClass, destClass ); | |||||
| final String message = REZ.getString( "deploy-type.error", roleShorthand, typeName ); | |||||
| throw new DeploymentException( message, e ); | throw new DeploymentException( message, e ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,4 +1,4 @@ | |||||
| register-converter.notice=Registered converter that converts from {1} to {2}. | |||||
| register-converter.notice=Registered converter that converts from {0} to {1}. | |||||
| register-type.notice=Registered type {0}/{1}. | register-type.notice=Registered type {0}/{1}. | ||||
| register-role.notice=Registered role {0} with shorthand name {1}. | register-role.notice=Registered role {0} with shorthand name {1}. | ||||
| url-deploy-types.notice=Registering types from "{0}". | url-deploy-types.notice=Registering types from "{0}". | ||||
| @@ -12,6 +12,11 @@ deploy-type.error=Could not register type {0}/{1}. | |||||
| unknown-role4name.error=Unknown role "{0}". | unknown-role4name.error=Unknown role "{0}". | ||||
| no-file.error=Could not find type library "{0}". | no-file.error=Could not find type library "{0}". | ||||
| file-is-dir.error=Type library "{0}" is a directory. | file-is-dir.error=Type library "{0}" is a directory. | ||||
| typedef.no-classname.error=Must specify the classname parameter. | |||||
| typedef.no-name.error=Must specify name parameter. | |||||
| typedef.no-role.error=Must specify type parameter. | |||||
| converterdef.no-source.error=Must specify the source-type parameter. | |||||
| converterdef.no-destination.error=Must specify the destination-type parameter. | |||||
| available-extensions.notice=The list of available extensions for type library includes; {0} | available-extensions.notice=The list of available extensions for type library includes; {0} | ||||
| required-extensions.notice=The list of required extensions for type library includes; {0} | required-extensions.notice=The list of required extensions for type library includes; {0} | ||||
| @@ -10,10 +10,13 @@ package org.apache.myrmidon.framework; | |||||
| import java.io.File; | import java.io.File; | ||||
| 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.AbstractTask; | |||||
| import org.apache.avalon.framework.configuration.Configurable; | |||||
| import org.apache.avalon.framework.configuration.Configuration; | |||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
| import org.apache.myrmidon.interfaces.deployer.DeploymentException; | import org.apache.myrmidon.interfaces.deployer.DeploymentException; | ||||
| import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | ||||
| /** | /** | ||||
| @@ -24,53 +27,66 @@ import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public abstract class AbstractTypeDef | public abstract class AbstractTypeDef | ||||
| extends AbstractTask | |||||
| extends AbstractContainerTask | |||||
| implements Configurable | |||||
| { | { | ||||
| private final static Resources REZ = | private final static Resources REZ = | ||||
| ResourceManager.getPackageResources( AbstractTypeDef.class ); | ResourceManager.getPackageResources( AbstractTypeDef.class ); | ||||
| // TODO - replace lib with class-path | |||||
| private File m_lib; | private File m_lib; | ||||
| private String m_name; | |||||
| private String m_className; | |||||
| private TypeDefinition m_typeDef; | |||||
| public void setLib( final File lib ) | |||||
| /** | |||||
| * Configures this task. | |||||
| */ | |||||
| public void configure( Configuration configuration ) throws ConfigurationException | |||||
| { | { | ||||
| //In the future this would be replaced by ClassPath sub-element | |||||
| m_lib = lib; | |||||
| } | |||||
| m_typeDef = createTypeDefinition(); | |||||
| public void setName( final String name ) | |||||
| { | |||||
| m_name = name; | |||||
| } | |||||
| // Configure attributes | |||||
| final String[] attrs = configuration.getAttributeNames(); | |||||
| for( int i = 0; i < attrs.length; i++ ) | |||||
| { | |||||
| final String name = attrs[ i ]; | |||||
| final String value = configuration.getAttribute( name ); | |||||
| if( name.equalsIgnoreCase( "lib" ) ) | |||||
| { | |||||
| m_lib = (File)convert( File.class, value ); | |||||
| } | |||||
| else | |||||
| { | |||||
| configure( m_typeDef, name, value ); | |||||
| } | |||||
| } | |||||
| public void setClassname( final String className ) | |||||
| { | |||||
| m_className = className; | |||||
| // Configure nested elements | |||||
| final Configuration[] elements = configuration.getChildren(); | |||||
| for( int i = 0; i < elements.length; i++ ) | |||||
| { | |||||
| Configuration element = elements[ i ]; | |||||
| configure( m_typeDef, element ); | |||||
| } | |||||
| } | } | ||||
| /** | |||||
| * Executes the task. | |||||
| */ | |||||
| public void execute() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( null == m_name ) | |||||
| { | |||||
| final String message = REZ.getString( "typedef.no-name.error" ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| else if( null == m_className ) | |||||
| if( null == m_lib ) | |||||
| { | { | ||||
| final String message = REZ.getString( "typedef.no-classname.error" ); | |||||
| final String message = REZ.getString( "typedef.no-lib.error" ); | |||||
| throw new TaskException( message ); | throw new TaskException( message ); | ||||
| } | } | ||||
| final String shorthand = getRoleShorthand(); | |||||
| try | try | ||||
| { | { | ||||
| // Locate the deployer, and use it to deploy the type | // Locate the deployer, and use it to deploy the type | ||||
| final Deployer deployer = (Deployer)getService( Deployer.class ); | final Deployer deployer = (Deployer)getService( Deployer.class ); | ||||
| final TypeDeployer typeDeployer = deployer.createDeployer( m_lib ); | final TypeDeployer typeDeployer = deployer.createDeployer( m_lib ); | ||||
| typeDeployer.deployType( shorthand, m_name, m_className ); | |||||
| typeDeployer.deployType( m_typeDef ); | |||||
| } | } | ||||
| catch( DeploymentException e ) | catch( DeploymentException e ) | ||||
| { | { | ||||
| @@ -78,5 +94,8 @@ public abstract class AbstractTypeDef | |||||
| } | } | ||||
| } | } | ||||
| protected abstract String getRoleShorthand(); | |||||
| /** | |||||
| * Creates the definition for the type to be deployed. | |||||
| */ | |||||
| protected abstract TypeDefinition createTypeDefinition(); | |||||
| } | } | ||||
| @@ -3,10 +3,7 @@ container.bad-resolve.error=Error resolving value ({0}). | |||||
| container.bad-config.error=Error converting value. | container.bad-config.error=Error converting value. | ||||
| container.no-factory.error=Could not locate the type factory for type "{0}". | container.no-factory.error=Could not locate the type factory for type "{0}". | ||||
| typedef.no-name.error=Must specify name parameter. | |||||
| typedef.no-classname.error=Must specify classname parameter. | |||||
| typedef.no-register.error=Failed to register type. | |||||
| typedef.bad-classloader.error=Failed to build classLoader due to: {0}. | |||||
| typedef.no-lib.error=Must specify the lib parameter. | |||||
| condition.no-resolve.error=Error resolving {0}. | condition.no-resolve.error=Error resolving {0}. | ||||
| @@ -338,7 +338,7 @@ public class CLIMain | |||||
| if( getLogger().isInfoEnabled() ) | if( getLogger().isInfoEnabled() ) | ||||
| { | { | ||||
| final String message = REZ.getString( "buildfile.notice", buildFile ); | final String message = REZ.getString( "buildfile.notice", buildFile ); | ||||
| getLogger().warn( message ); | |||||
| getLogger().info( message ); | |||||
| } | } | ||||
| if( getLogger().isInfoEnabled() ) | if( getLogger().isInfoEnabled() ) | ||||
| @@ -0,0 +1,68 @@ | |||||
| /* | |||||
| * 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.deployer; | |||||
| /** | |||||
| * A converter definition. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| */ | |||||
| public class ConverterDefinition | |||||
| extends TypeDefinition | |||||
| { | |||||
| private String m_sourceType; | |||||
| private String m_destinationType; | |||||
| /** | |||||
| * Returns the type's role. | |||||
| */ | |||||
| public String getRoleShorthand() | |||||
| { | |||||
| return "converter"; | |||||
| } | |||||
| /** | |||||
| * Returns the type's name. | |||||
| */ | |||||
| public String getName() | |||||
| { | |||||
| return getClassname(); | |||||
| } | |||||
| /** | |||||
| * Returns the converter's source type. | |||||
| */ | |||||
| public String getSourceType() | |||||
| { | |||||
| return m_sourceType; | |||||
| } | |||||
| /** | |||||
| * Sets the converter's source type. | |||||
| */ | |||||
| public void setSourceType( final String sourceType ) | |||||
| { | |||||
| m_sourceType = sourceType; | |||||
| } | |||||
| /** | |||||
| * Returns the converter's destination type. | |||||
| */ | |||||
| public String getDestinationType() | |||||
| { | |||||
| return m_destinationType; | |||||
| } | |||||
| /** | |||||
| * Sets the converter's destination type. | |||||
| */ | |||||
| public void setDestinationType( final String destinationType ) | |||||
| { | |||||
| m_destinationType = destinationType; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,52 @@ | |||||
| /* | |||||
| * 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.deployer; | |||||
| /** | |||||
| * A general-purpose type definition. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| */ | |||||
| public class GeneralTypeDefinition | |||||
| extends TypeDefinition | |||||
| { | |||||
| private String m_name; | |||||
| private String m_roleShorthand; | |||||
| /** | |||||
| * Returns the type's role. | |||||
| */ | |||||
| public String getRoleShorthand() | |||||
| { | |||||
| return m_roleShorthand; | |||||
| } | |||||
| /** | |||||
| * Sets the type's role. | |||||
| */ | |||||
| public void setType( String roleShorthand ) | |||||
| { | |||||
| m_roleShorthand = roleShorthand; | |||||
| } | |||||
| /** | |||||
| * Returns the type's name. | |||||
| */ | |||||
| public String getName() | |||||
| { | |||||
| return m_name; | |||||
| } | |||||
| /** | |||||
| * Sets the type's name. | |||||
| */ | |||||
| public void setName( String name ) | |||||
| { | |||||
| m_name = name; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,45 @@ | |||||
| /* | |||||
| * 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.deployer; | |||||
| /** | |||||
| * A basic type definition. This class is used to build a type definition, | |||||
| * from a typelib descriptor, or via introspection. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| */ | |||||
| public abstract class TypeDefinition | |||||
| { | |||||
| private String m_className; | |||||
| /** | |||||
| * Returns the type's name. | |||||
| */ | |||||
| public abstract String getName(); | |||||
| /** | |||||
| * Returns the type's role. | |||||
| */ | |||||
| public abstract String getRoleShorthand(); | |||||
| /** | |||||
| * Returns the type's implementation class name. | |||||
| */ | |||||
| public String getClassname() | |||||
| { | |||||
| return m_className; | |||||
| } | |||||
| /** | |||||
| * Sets the type's implementation class name. | |||||
| */ | |||||
| public void setClassname( final String className ) | |||||
| { | |||||
| m_className = className; | |||||
| } | |||||
| } | |||||
| @@ -11,7 +11,7 @@ package org.apache.myrmidon.interfaces.deployer; | |||||
| * A deployer for a type library. Allows individual elements from a type | * A deployer for a type library. Allows individual elements from a type | ||||
| * library to be deployed. | * library to be deployed. | ||||
| * | * | ||||
| * @author Adam Murdoch | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| */ | */ | ||||
| public interface TypeDeployer | public interface TypeDeployer | ||||
| { | { | ||||
| @@ -26,29 +26,23 @@ public interface TypeDeployer | |||||
| * read from the type library descriptor. | * read from the type library descriptor. | ||||
| * | * | ||||
| * @param roleShorthand | * @param roleShorthand | ||||
| * The <em>shorthand</em> for the role. | |||||
| * The shorthand name for the role. | |||||
| * | |||||
| * @param typeName | * @param typeName | ||||
| * The type name. | |||||
| * The type name. | |||||
| * | |||||
| * @throws DeploymentException | |||||
| * If the type cannot be deployed. | |||||
| */ | */ | ||||
| void deployType( String roleShorthand, String typeName ) | void deployType( String roleShorthand, String typeName ) | ||||
| throws DeploymentException; | throws DeploymentException; | ||||
| /** | /** | ||||
| * Deploys a single type from the type library. | * Deploys a single type from the type library. | ||||
| * | |||||
| * @param typeDef | |||||
| * The type definition. | |||||
| */ | */ | ||||
| void deployType( String roleShorthand, String typeName, String className ) | |||||
| throws DeploymentException; | |||||
| /** | |||||
| * Deploys a converter from the type library. The converter definition | |||||
| * is read from the type library descriptor. | |||||
| */ | |||||
| void deployConverter( String className ) | |||||
| throws DeploymentException; | |||||
| /** | |||||
| * Deploys a converter from the type library. | |||||
| */ | |||||
| void deployConverter( String className, String srcClass, String destClass ) | |||||
| void deployType( TypeDefinition typeDef ) | |||||
| throws DeploymentException; | throws DeploymentException; | ||||
| } | } | ||||
| @@ -0,0 +1,173 @@ | |||||
| /* | |||||
| * 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.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.List; | |||||
| import junit.framework.TestCase; | |||||
| import org.apache.avalon.framework.component.Component; | |||||
| import org.apache.avalon.framework.component.ComponentException; | |||||
| import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.component.Composable; | |||||
| import org.apache.avalon.framework.component.DefaultComponentManager; | |||||
| import org.apache.avalon.framework.logger.LogEnabled; | |||||
| import org.apache.avalon.framework.logger.LogKitLogger; | |||||
| import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.log.Hierarchy; | |||||
| import org.apache.log.LogTarget; | |||||
| import org.apache.log.Priority; | |||||
| import org.apache.log.format.PatternFormatter; | |||||
| import org.apache.log.output.io.StreamTarget; | |||||
| import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||||
| import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | |||||
| import org.apache.myrmidon.components.converter.DefaultMasterConverter; | |||||
| import org.apache.myrmidon.components.deployer.DefaultDeployer; | |||||
| import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | |||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeManager; | |||||
| import org.apache.myrmidon.interfaces.configurer.Configurer; | |||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | |||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | |||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
| import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| 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 class ComponentTestBase extends TestCase | |||||
| { | |||||
| private DefaultComponentManager m_componentManager; | |||||
| private Logger m_logger; | |||||
| private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}"; | |||||
| public ComponentTestBase( String s ) | |||||
| { | |||||
| super( s ); | |||||
| } | |||||
| /** | |||||
| * Returns the component manager containing the components to test. | |||||
| */ | |||||
| protected ComponentManager getComponentManager() | |||||
| { | |||||
| return m_componentManager; | |||||
| } | |||||
| /** | |||||
| * Returns the type manager. | |||||
| */ | |||||
| protected TypeManager getTypeManager() throws ComponentException | |||||
| { | |||||
| return (TypeManager)getComponentManager().lookup( TypeManager.ROLE ); | |||||
| } | |||||
| /** | |||||
| * Setup the test case - prepares the set of components. | |||||
| */ | |||||
| protected void setUp() throws Exception | |||||
| { | |||||
| // Setup a logger | |||||
| final Priority priority = Priority.DEBUG; | |||||
| final org.apache.log.Logger targetLogger = Hierarchy.getDefaultHierarchy().getLoggerFor( "myrmidon" ); | |||||
| final PatternFormatter formatter = new PatternFormatter( PATTERN ); | |||||
| final StreamTarget target = new StreamTarget( System.out, formatter ); | |||||
| targetLogger.setLogTargets( new LogTarget[]{target} ); | |||||
| targetLogger.setPriority( priority ); | |||||
| m_logger = new LogKitLogger( targetLogger ); | |||||
| // Create the components | |||||
| m_componentManager = new DefaultComponentManager(); | |||||
| List components = new ArrayList(); | |||||
| Component component = new DefaultMasterConverter(); | |||||
| m_componentManager.put( MasterConverter.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultConverterRegistry(); | |||||
| m_componentManager.put( ConverterRegistry.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultTypeManager(); | |||||
| m_componentManager.put( TypeManager.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultConfigurer(); | |||||
| m_componentManager.put( Configurer.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultDeployer(); | |||||
| m_componentManager.put( Deployer.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultExtensionManager(); | |||||
| m_componentManager.put( ExtensionManager.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultRoleManager(); | |||||
| m_componentManager.put( RoleManager.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( m_logger ); | |||||
| } | |||||
| } | |||||
| // Compose the components | |||||
| for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||||
| { | |||||
| Object obj = iterator.next(); | |||||
| if( obj instanceof Composable ) | |||||
| { | |||||
| final Composable composable = (Composable)obj; | |||||
| composable.compose( m_componentManager ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Asserts that an exception contains the expected message. | |||||
| * | |||||
| * TODO - should take the expected exception, rather than the message, | |||||
| * to check the entire cause chain. | |||||
| */ | |||||
| protected void assertSameMessage( final String msg, final Throwable exc ) | |||||
| { | |||||
| assertEquals( msg, exc.getMessage() ); | |||||
| } | |||||
| /** | |||||
| * Compares 2 objects for equality, nulls are equal. Used by the test | |||||
| * classes' equals() methods. | |||||
| */ | |||||
| public static boolean equals( final Object o1, final Object o2 ) | |||||
| { | |||||
| if( o1 == null && o2 == null ) | |||||
| { | |||||
| return true; | |||||
| } | |||||
| if( o1 == null || o2 == null ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| return o1.equals( o2 ); | |||||
| } | |||||
| } | |||||
| @@ -8,36 +8,16 @@ | |||||
| package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.List; | |||||
| import junit.framework.AssertionFailedError; | import junit.framework.AssertionFailedError; | ||||
| import junit.framework.TestCase; | |||||
| 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.avalon.framework.component.Component; | |||||
| import org.apache.avalon.framework.component.Composable; | |||||
| import org.apache.avalon.framework.component.DefaultComponentManager; | |||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
| import org.apache.avalon.framework.configuration.DefaultConfiguration; | import org.apache.avalon.framework.configuration.DefaultConfiguration; | ||||
| import org.apache.avalon.framework.logger.LogEnabled; | |||||
| import org.apache.avalon.framework.logger.LogKitLogger; | |||||
| import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.log.Hierarchy; | |||||
| import org.apache.log.LogTarget; | |||||
| import org.apache.log.Priority; | |||||
| import org.apache.log.format.PatternFormatter; | |||||
| import org.apache.log.output.io.StreamTarget; | |||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | |||||
| import org.apache.myrmidon.components.converter.DefaultMasterConverter; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeManager; | |||||
| import org.apache.myrmidon.components.ComponentTestBase; | |||||
| import org.apache.myrmidon.components.workspace.DefaultTaskContext; | import org.apache.myrmidon.components.workspace.DefaultTaskContext; | ||||
| import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | |||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | |||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| /** | /** | ||||
| * Test cases for the default configurer and related classes. | * Test cases for the default configurer and related classes. | ||||
| @@ -45,19 +25,14 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| * @author Adam Murdoch | * @author Adam Murdoch | ||||
| */ | */ | ||||
| public class DefaultConfigurerTest | public class DefaultConfigurerTest | ||||
| extends TestCase | |||||
| extends ComponentTestBase | |||||
| { | { | ||||
| private final static Resources REZ = | private final static Resources REZ = | ||||
| ResourceManager.getPackageResources( DefaultConfigurerTest.class ); | ResourceManager.getPackageResources( DefaultConfigurerTest.class ); | ||||
| private DefaultComponentManager m_componentManager; | |||||
| private Configurer m_configurer; | private Configurer m_configurer; | ||||
| private TypeManager m_typeManager; | |||||
| private Logger m_logger; | |||||
| private DefaultTaskContext m_context; | private DefaultTaskContext m_context; | ||||
| private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}"; | |||||
| public DefaultConfigurerTest( String name ) | public DefaultConfigurerTest( String name ) | ||||
| { | { | ||||
| super( name ); | super( name ); | ||||
| @@ -66,78 +41,18 @@ public class DefaultConfigurerTest | |||||
| /** | /** | ||||
| * Setup the test case - prepares a set of components, including the | * Setup the test case - prepares a set of components, including the | ||||
| * configurer. | * configurer. | ||||
| * | |||||
| * TODO - refactor to a sub-class, so this setup can be reused. | |||||
| */ | */ | ||||
| protected void setUp() throws Exception | protected void setUp() throws Exception | ||||
| { | { | ||||
| final Priority priority = Priority.DEBUG; | |||||
| final org.apache.log.Logger targetLogger = Hierarchy.getDefaultHierarchy().getLoggerFor( "myrmidon" ); | |||||
| final PatternFormatter formatter = new PatternFormatter( PATTERN ); | |||||
| final StreamTarget target = new StreamTarget( System.out, formatter ); | |||||
| targetLogger.setLogTargets( new LogTarget[]{target} ); | |||||
| targetLogger.setPriority( priority ); | |||||
| // Create the logger | |||||
| m_logger = new LogKitLogger( targetLogger ); | |||||
| // Create the components | |||||
| m_componentManager = new DefaultComponentManager(); | |||||
| List components = new ArrayList(); | |||||
| super.setUp(); | |||||
| Component component = new DefaultMasterConverter(); | |||||
| m_componentManager.put( MasterConverter.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultConverterRegistry(); | |||||
| m_componentManager.put( ConverterRegistry.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultTypeManager(); | |||||
| m_componentManager.put( TypeManager.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultConfigurer(); | |||||
| m_componentManager.put( Configurer.ROLE, component ); | |||||
| components.add( component ); | |||||
| // Find the configurer | |||||
| m_configurer = (Configurer)getComponentManager().lookup( Configurer.ROLE ); | |||||
| // Setup a context | // Setup a context | ||||
| m_context = new DefaultTaskContext(); | |||||
| components.add( m_context ); | |||||
| // 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( m_logger ); | |||||
| } | |||||
| } | |||||
| // Compose the components | |||||
| for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||||
| { | |||||
| Object obj = iterator.next(); | |||||
| if( obj instanceof Composable ) | |||||
| { | |||||
| final Composable composable = (Composable)obj; | |||||
| composable.compose( m_componentManager ); | |||||
| } | |||||
| } | |||||
| // Configure the context | |||||
| m_context = new DefaultTaskContext( getComponentManager() ); | |||||
| final File baseDir = new File( "." ).getAbsoluteFile(); | final File baseDir = new File( "." ).getAbsoluteFile(); | ||||
| m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | ||||
| // Find the configurer | |||||
| m_configurer = (Configurer)m_componentManager.lookup( Configurer.ROLE ); | |||||
| // Find the typeManager | |||||
| m_typeManager = (TypeManager)m_componentManager.lookup( TypeManager.ROLE ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -366,7 +281,8 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests reference resolution via a nested element. | |||||
| * Tests whether an object with a non-iterface typed adder causes an | |||||
| * exception. | |||||
| */ | */ | ||||
| public void testNonInterfaceTypedAdder() | public void testNonInterfaceTypedAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -380,6 +296,7 @@ public class DefaultConfigurerTest | |||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | m_configurer.configure( test, config, m_context ); | ||||
| fail(); | |||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| { | { | ||||
| @@ -391,7 +308,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests whether a object with multiple typed adders causes an exception. | |||||
| * Tests whether an object with multiple typed adders causes an exception. | |||||
| */ | */ | ||||
| public void testMultipleTypedAdder() | public void testMultipleTypedAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -405,6 +322,7 @@ public class DefaultConfigurerTest | |||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | m_configurer.configure( test, config, m_context ); | ||||
| fail(); | |||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| { | { | ||||
| @@ -415,7 +333,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests to see if typed adder works. | |||||
| * Tests to see if typed adder works, with iterface types. | |||||
| */ | */ | ||||
| public void testTypedAdder() | public void testTypedAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -431,8 +349,8 @@ public class DefaultConfigurerTest | |||||
| final DefaultTypeFactory factory = new DefaultTypeFactory( loader ); | final DefaultTypeFactory factory = new DefaultTypeFactory( loader ); | ||||
| factory.addNameClassMapping( "my-type1", MyType1.class.getName() ); | factory.addNameClassMapping( "my-type1", MyType1.class.getName() ); | ||||
| factory.addNameClassMapping( "my-type2", MyType2.class.getName() ); | factory.addNameClassMapping( "my-type2", MyType2.class.getName() ); | ||||
| m_typeManager.registerType( MyRole1.class, "my-type1", factory ); | |||||
| m_typeManager.registerType( MyRole1.class, "my-type2", factory ); | |||||
| getTypeManager().registerType( MyRole1.class, "my-type1", factory ); | |||||
| getTypeManager().registerType( MyRole1.class, "my-type2", factory ); | |||||
| final ConfigTest6 test = new ConfigTest6(); | final ConfigTest6 test = new ConfigTest6(); | ||||
| @@ -446,7 +364,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests to see if typed adder works. | |||||
| * Tests to see if typed adder works, with Configuration type. | |||||
| */ | */ | ||||
| public void testTypedConfigAdder() | public void testTypedConfigAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -470,7 +388,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests to see if typed adder works. | |||||
| * Tests to see if typed adder works, with Configuration objects. | |||||
| */ | */ | ||||
| public void testConfigAdder() | public void testConfigAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -494,7 +412,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests to see if typed adder works. | |||||
| * Tests to check that Configurable is handled properly. | |||||
| */ | */ | ||||
| public void testConfigable() | public void testConfigable() | ||||
| throws Exception | throws Exception | ||||
| @@ -648,32 +566,4 @@ public class DefaultConfigurerTest | |||||
| expected.addProp3( new ConfigTest1() ); | expected.addProp3( new ConfigTest1() ); | ||||
| assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
| } | } | ||||
| /** | |||||
| * Asserts that an exception contains the expected message. | |||||
| * | |||||
| * TODO - should take the expected exception, rather than the message, | |||||
| * to check the entire cause chain. | |||||
| */ | |||||
| protected void assertSameMessage( final String msg, final Throwable exc ) | |||||
| { | |||||
| assertEquals( msg, exc.getMessage() ); | |||||
| } | |||||
| /** | |||||
| * Compares 2 objects for equality, nulls are equal. Used by the test | |||||
| * classes' equals() methods. | |||||
| */ | |||||
| public static boolean equals( final Object o1, final Object o2 ) | |||||
| { | |||||
| if( o1 == null && o2 == null ) | |||||
| { | |||||
| return true; | |||||
| } | |||||
| if( o1 == null || o2 == null ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| return o1.equals( o2 ); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,96 @@ | |||||
| /* | |||||
| * 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; | |||||
| import org.apache.myrmidon.components.ComponentTestBase; | |||||
| import org.apache.myrmidon.framework.DataType; | |||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | |||||
| import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
| import org.apache.myrmidon.interfaces.deployer.GeneralTypeDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| 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 DefaultDeployerTest | |||||
| extends ComponentTestBase | |||||
| { | |||||
| private Deployer m_deployer; | |||||
| public DefaultDeployerTest( String s ) | |||||
| { | |||||
| super( s ); | |||||
| } | |||||
| /** | |||||
| * Setup the test case - prepares the set of components, including the | |||||
| * deployer. | |||||
| */ | |||||
| protected void setUp() throws Exception | |||||
| { | |||||
| super.setUp(); | |||||
| m_deployer = (Deployer)getComponentManager().lookup( Deployer.ROLE ); | |||||
| } | |||||
| /** | |||||
| * Tests deployment of a single type from a ClassLoader. | |||||
| */ | |||||
| public void testSingleType() throws Exception | |||||
| { | |||||
| // Determine the shorthand for the DataType role | |||||
| final RoleManager roleManager = (RoleManager)getComponentManager().lookup( RoleManager.ROLE ); | |||||
| roleManager.addNameRoleMapping( "data-type", DataType.ROLE ); | |||||
| // Create the type definition | |||||
| final GeneralTypeDefinition typeDef = new GeneralTypeDefinition(); | |||||
| typeDef.setType( "data-type" ); | |||||
| typeDef.setName( "test-type1" ); | |||||
| typeDef.setClassname( TestType1.class.getName() ); | |||||
| // Deploy the type | |||||
| final ClassLoader classLoader = getClass().getClassLoader(); | |||||
| final TypeDeployer typeDeployer = m_deployer.createDeployer( classLoader ); | |||||
| typeDeployer.deployType( typeDef ); | |||||
| // Create an instance | |||||
| final TypeFactory typeFactory = getTypeManager().getFactory( DataType.class ); | |||||
| Object obj = typeFactory.create( "test-type1" ); | |||||
| // Check the type | |||||
| assertTrue( obj instanceof TestType1 ); | |||||
| } | |||||
| /** | |||||
| * Tests deployment of a single converter from a ClassLoader. | |||||
| */ | |||||
| public void testSingleConverter() throws Exception | |||||
| { | |||||
| // Create the type definition | |||||
| final ConverterDefinition typeDef = new ConverterDefinition(); | |||||
| typeDef.setClassname( TestConverter1.class.getName() ); | |||||
| typeDef.setSourceType( "java.lang.String" ); | |||||
| typeDef.setDestinationType( TestType1.class.getName() ); | |||||
| // Deploy the type | |||||
| final ClassLoader classLoader = getClass().getClassLoader(); | |||||
| final TypeDeployer typeDeployer = m_deployer.createDeployer( classLoader ); | |||||
| typeDeployer.deployType( typeDef ); | |||||
| // Try to convert from string to test type | |||||
| final MasterConverter converter = (MasterConverter)getComponentManager().lookup( MasterConverter.ROLE ); | |||||
| Object obj = converter.convert( TestType1.class, "some-string", null ); | |||||
| // Check the type | |||||
| assertTrue( obj instanceof TestType1 ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,30 @@ | |||||
| /* | |||||
| * 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; | |||||
| import org.apache.myrmidon.converter.Converter; | |||||
| import org.apache.myrmidon.converter.ConverterException; | |||||
| import org.apache.avalon.framework.context.Context; | |||||
| /** | |||||
| * 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, Context context ) | |||||
| throws ConverterException | |||||
| { | |||||
| return new TestType1(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,20 @@ | |||||
| /* | |||||
| * 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; | |||||
| import org.apache.myrmidon.framework.DataType; | |||||
| /** | |||||
| * A test data-type. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| */ | |||||
| public class TestType1 | |||||
| implements DataType | |||||
| { | |||||
| } | |||||
| @@ -0,0 +1,173 @@ | |||||
| /* | |||||
| * 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.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.List; | |||||
| import junit.framework.TestCase; | |||||
| import org.apache.avalon.framework.component.Component; | |||||
| import org.apache.avalon.framework.component.ComponentException; | |||||
| import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.component.Composable; | |||||
| import org.apache.avalon.framework.component.DefaultComponentManager; | |||||
| import org.apache.avalon.framework.logger.LogEnabled; | |||||
| import org.apache.avalon.framework.logger.LogKitLogger; | |||||
| import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.log.Hierarchy; | |||||
| import org.apache.log.LogTarget; | |||||
| import org.apache.log.Priority; | |||||
| import org.apache.log.format.PatternFormatter; | |||||
| import org.apache.log.output.io.StreamTarget; | |||||
| import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||||
| import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | |||||
| import org.apache.myrmidon.components.converter.DefaultMasterConverter; | |||||
| import org.apache.myrmidon.components.deployer.DefaultDeployer; | |||||
| import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | |||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeManager; | |||||
| import org.apache.myrmidon.interfaces.configurer.Configurer; | |||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | |||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | |||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
| import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| 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 class ComponentTestBase extends TestCase | |||||
| { | |||||
| private DefaultComponentManager m_componentManager; | |||||
| private Logger m_logger; | |||||
| private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}"; | |||||
| public ComponentTestBase( String s ) | |||||
| { | |||||
| super( s ); | |||||
| } | |||||
| /** | |||||
| * Returns the component manager containing the components to test. | |||||
| */ | |||||
| protected ComponentManager getComponentManager() | |||||
| { | |||||
| return m_componentManager; | |||||
| } | |||||
| /** | |||||
| * Returns the type manager. | |||||
| */ | |||||
| protected TypeManager getTypeManager() throws ComponentException | |||||
| { | |||||
| return (TypeManager)getComponentManager().lookup( TypeManager.ROLE ); | |||||
| } | |||||
| /** | |||||
| * Setup the test case - prepares the set of components. | |||||
| */ | |||||
| protected void setUp() throws Exception | |||||
| { | |||||
| // Setup a logger | |||||
| final Priority priority = Priority.DEBUG; | |||||
| final org.apache.log.Logger targetLogger = Hierarchy.getDefaultHierarchy().getLoggerFor( "myrmidon" ); | |||||
| final PatternFormatter formatter = new PatternFormatter( PATTERN ); | |||||
| final StreamTarget target = new StreamTarget( System.out, formatter ); | |||||
| targetLogger.setLogTargets( new LogTarget[]{target} ); | |||||
| targetLogger.setPriority( priority ); | |||||
| m_logger = new LogKitLogger( targetLogger ); | |||||
| // Create the components | |||||
| m_componentManager = new DefaultComponentManager(); | |||||
| List components = new ArrayList(); | |||||
| Component component = new DefaultMasterConverter(); | |||||
| m_componentManager.put( MasterConverter.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultConverterRegistry(); | |||||
| m_componentManager.put( ConverterRegistry.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultTypeManager(); | |||||
| m_componentManager.put( TypeManager.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultConfigurer(); | |||||
| m_componentManager.put( Configurer.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultDeployer(); | |||||
| m_componentManager.put( Deployer.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultExtensionManager(); | |||||
| m_componentManager.put( ExtensionManager.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultRoleManager(); | |||||
| m_componentManager.put( RoleManager.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( m_logger ); | |||||
| } | |||||
| } | |||||
| // Compose the components | |||||
| for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||||
| { | |||||
| Object obj = iterator.next(); | |||||
| if( obj instanceof Composable ) | |||||
| { | |||||
| final Composable composable = (Composable)obj; | |||||
| composable.compose( m_componentManager ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Asserts that an exception contains the expected message. | |||||
| * | |||||
| * TODO - should take the expected exception, rather than the message, | |||||
| * to check the entire cause chain. | |||||
| */ | |||||
| protected void assertSameMessage( final String msg, final Throwable exc ) | |||||
| { | |||||
| assertEquals( msg, exc.getMessage() ); | |||||
| } | |||||
| /** | |||||
| * Compares 2 objects for equality, nulls are equal. Used by the test | |||||
| * classes' equals() methods. | |||||
| */ | |||||
| public static boolean equals( final Object o1, final Object o2 ) | |||||
| { | |||||
| if( o1 == null && o2 == null ) | |||||
| { | |||||
| return true; | |||||
| } | |||||
| if( o1 == null || o2 == null ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| return o1.equals( o2 ); | |||||
| } | |||||
| } | |||||
| @@ -8,36 +8,16 @@ | |||||
| package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.List; | |||||
| import junit.framework.AssertionFailedError; | import junit.framework.AssertionFailedError; | ||||
| import junit.framework.TestCase; | |||||
| 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.avalon.framework.component.Component; | |||||
| import org.apache.avalon.framework.component.Composable; | |||||
| import org.apache.avalon.framework.component.DefaultComponentManager; | |||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
| import org.apache.avalon.framework.configuration.DefaultConfiguration; | import org.apache.avalon.framework.configuration.DefaultConfiguration; | ||||
| import org.apache.avalon.framework.logger.LogEnabled; | |||||
| import org.apache.avalon.framework.logger.LogKitLogger; | |||||
| import org.apache.avalon.framework.logger.Logger; | |||||
| import org.apache.log.Hierarchy; | |||||
| import org.apache.log.LogTarget; | |||||
| import org.apache.log.Priority; | |||||
| import org.apache.log.format.PatternFormatter; | |||||
| import org.apache.log.output.io.StreamTarget; | |||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | |||||
| import org.apache.myrmidon.components.converter.DefaultMasterConverter; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeManager; | |||||
| import org.apache.myrmidon.components.ComponentTestBase; | |||||
| import org.apache.myrmidon.components.workspace.DefaultTaskContext; | import org.apache.myrmidon.components.workspace.DefaultTaskContext; | ||||
| import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | |||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | |||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| /** | /** | ||||
| * Test cases for the default configurer and related classes. | * Test cases for the default configurer and related classes. | ||||
| @@ -45,19 +25,14 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| * @author Adam Murdoch | * @author Adam Murdoch | ||||
| */ | */ | ||||
| public class DefaultConfigurerTest | public class DefaultConfigurerTest | ||||
| extends TestCase | |||||
| extends ComponentTestBase | |||||
| { | { | ||||
| private final static Resources REZ = | private final static Resources REZ = | ||||
| ResourceManager.getPackageResources( DefaultConfigurerTest.class ); | ResourceManager.getPackageResources( DefaultConfigurerTest.class ); | ||||
| private DefaultComponentManager m_componentManager; | |||||
| private Configurer m_configurer; | private Configurer m_configurer; | ||||
| private TypeManager m_typeManager; | |||||
| private Logger m_logger; | |||||
| private DefaultTaskContext m_context; | private DefaultTaskContext m_context; | ||||
| private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}"; | |||||
| public DefaultConfigurerTest( String name ) | public DefaultConfigurerTest( String name ) | ||||
| { | { | ||||
| super( name ); | super( name ); | ||||
| @@ -66,78 +41,18 @@ public class DefaultConfigurerTest | |||||
| /** | /** | ||||
| * Setup the test case - prepares a set of components, including the | * Setup the test case - prepares a set of components, including the | ||||
| * configurer. | * configurer. | ||||
| * | |||||
| * TODO - refactor to a sub-class, so this setup can be reused. | |||||
| */ | */ | ||||
| protected void setUp() throws Exception | protected void setUp() throws Exception | ||||
| { | { | ||||
| final Priority priority = Priority.DEBUG; | |||||
| final org.apache.log.Logger targetLogger = Hierarchy.getDefaultHierarchy().getLoggerFor( "myrmidon" ); | |||||
| final PatternFormatter formatter = new PatternFormatter( PATTERN ); | |||||
| final StreamTarget target = new StreamTarget( System.out, formatter ); | |||||
| targetLogger.setLogTargets( new LogTarget[]{target} ); | |||||
| targetLogger.setPriority( priority ); | |||||
| // Create the logger | |||||
| m_logger = new LogKitLogger( targetLogger ); | |||||
| // Create the components | |||||
| m_componentManager = new DefaultComponentManager(); | |||||
| List components = new ArrayList(); | |||||
| super.setUp(); | |||||
| Component component = new DefaultMasterConverter(); | |||||
| m_componentManager.put( MasterConverter.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultConverterRegistry(); | |||||
| m_componentManager.put( ConverterRegistry.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultTypeManager(); | |||||
| m_componentManager.put( TypeManager.ROLE, component ); | |||||
| components.add( component ); | |||||
| component = new DefaultConfigurer(); | |||||
| m_componentManager.put( Configurer.ROLE, component ); | |||||
| components.add( component ); | |||||
| // Find the configurer | |||||
| m_configurer = (Configurer)getComponentManager().lookup( Configurer.ROLE ); | |||||
| // Setup a context | // Setup a context | ||||
| m_context = new DefaultTaskContext(); | |||||
| components.add( m_context ); | |||||
| // 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( m_logger ); | |||||
| } | |||||
| } | |||||
| // Compose the components | |||||
| for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||||
| { | |||||
| Object obj = iterator.next(); | |||||
| if( obj instanceof Composable ) | |||||
| { | |||||
| final Composable composable = (Composable)obj; | |||||
| composable.compose( m_componentManager ); | |||||
| } | |||||
| } | |||||
| // Configure the context | |||||
| m_context = new DefaultTaskContext( getComponentManager() ); | |||||
| final File baseDir = new File( "." ).getAbsoluteFile(); | final File baseDir = new File( "." ).getAbsoluteFile(); | ||||
| m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | ||||
| // Find the configurer | |||||
| m_configurer = (Configurer)m_componentManager.lookup( Configurer.ROLE ); | |||||
| // Find the typeManager | |||||
| m_typeManager = (TypeManager)m_componentManager.lookup( TypeManager.ROLE ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -366,7 +281,8 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests reference resolution via a nested element. | |||||
| * Tests whether an object with a non-iterface typed adder causes an | |||||
| * exception. | |||||
| */ | */ | ||||
| public void testNonInterfaceTypedAdder() | public void testNonInterfaceTypedAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -380,6 +296,7 @@ public class DefaultConfigurerTest | |||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | m_configurer.configure( test, config, m_context ); | ||||
| fail(); | |||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| { | { | ||||
| @@ -391,7 +308,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests whether a object with multiple typed adders causes an exception. | |||||
| * Tests whether an object with multiple typed adders causes an exception. | |||||
| */ | */ | ||||
| public void testMultipleTypedAdder() | public void testMultipleTypedAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -405,6 +322,7 @@ public class DefaultConfigurerTest | |||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | m_configurer.configure( test, config, m_context ); | ||||
| fail(); | |||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| { | { | ||||
| @@ -415,7 +333,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests to see if typed adder works. | |||||
| * Tests to see if typed adder works, with iterface types. | |||||
| */ | */ | ||||
| public void testTypedAdder() | public void testTypedAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -431,8 +349,8 @@ public class DefaultConfigurerTest | |||||
| final DefaultTypeFactory factory = new DefaultTypeFactory( loader ); | final DefaultTypeFactory factory = new DefaultTypeFactory( loader ); | ||||
| factory.addNameClassMapping( "my-type1", MyType1.class.getName() ); | factory.addNameClassMapping( "my-type1", MyType1.class.getName() ); | ||||
| factory.addNameClassMapping( "my-type2", MyType2.class.getName() ); | factory.addNameClassMapping( "my-type2", MyType2.class.getName() ); | ||||
| m_typeManager.registerType( MyRole1.class, "my-type1", factory ); | |||||
| m_typeManager.registerType( MyRole1.class, "my-type2", factory ); | |||||
| getTypeManager().registerType( MyRole1.class, "my-type1", factory ); | |||||
| getTypeManager().registerType( MyRole1.class, "my-type2", factory ); | |||||
| final ConfigTest6 test = new ConfigTest6(); | final ConfigTest6 test = new ConfigTest6(); | ||||
| @@ -446,7 +364,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests to see if typed adder works. | |||||
| * Tests to see if typed adder works, with Configuration type. | |||||
| */ | */ | ||||
| public void testTypedConfigAdder() | public void testTypedConfigAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -470,7 +388,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests to see if typed adder works. | |||||
| * Tests to see if typed adder works, with Configuration objects. | |||||
| */ | */ | ||||
| public void testConfigAdder() | public void testConfigAdder() | ||||
| throws Exception | throws Exception | ||||
| @@ -494,7 +412,7 @@ public class DefaultConfigurerTest | |||||
| } | } | ||||
| /** | /** | ||||
| * Tests to see if typed adder works. | |||||
| * Tests to check that Configurable is handled properly. | |||||
| */ | */ | ||||
| public void testConfigable() | public void testConfigable() | ||||
| throws Exception | throws Exception | ||||
| @@ -648,32 +566,4 @@ public class DefaultConfigurerTest | |||||
| expected.addProp3( new ConfigTest1() ); | expected.addProp3( new ConfigTest1() ); | ||||
| assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
| } | } | ||||
| /** | |||||
| * Asserts that an exception contains the expected message. | |||||
| * | |||||
| * TODO - should take the expected exception, rather than the message, | |||||
| * to check the entire cause chain. | |||||
| */ | |||||
| protected void assertSameMessage( final String msg, final Throwable exc ) | |||||
| { | |||||
| assertEquals( msg, exc.getMessage() ); | |||||
| } | |||||
| /** | |||||
| * Compares 2 objects for equality, nulls are equal. Used by the test | |||||
| * classes' equals() methods. | |||||
| */ | |||||
| public static boolean equals( final Object o1, final Object o2 ) | |||||
| { | |||||
| if( o1 == null && o2 == null ) | |||||
| { | |||||
| return true; | |||||
| } | |||||
| if( o1 == null || o2 == null ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| return o1.equals( o2 ); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,96 @@ | |||||
| /* | |||||
| * 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; | |||||
| import org.apache.myrmidon.components.ComponentTestBase; | |||||
| import org.apache.myrmidon.framework.DataType; | |||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | |||||
| import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
| import org.apache.myrmidon.interfaces.deployer.GeneralTypeDefinition; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| 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 DefaultDeployerTest | |||||
| extends ComponentTestBase | |||||
| { | |||||
| private Deployer m_deployer; | |||||
| public DefaultDeployerTest( String s ) | |||||
| { | |||||
| super( s ); | |||||
| } | |||||
| /** | |||||
| * Setup the test case - prepares the set of components, including the | |||||
| * deployer. | |||||
| */ | |||||
| protected void setUp() throws Exception | |||||
| { | |||||
| super.setUp(); | |||||
| m_deployer = (Deployer)getComponentManager().lookup( Deployer.ROLE ); | |||||
| } | |||||
| /** | |||||
| * Tests deployment of a single type from a ClassLoader. | |||||
| */ | |||||
| public void testSingleType() throws Exception | |||||
| { | |||||
| // Determine the shorthand for the DataType role | |||||
| final RoleManager roleManager = (RoleManager)getComponentManager().lookup( RoleManager.ROLE ); | |||||
| roleManager.addNameRoleMapping( "data-type", DataType.ROLE ); | |||||
| // Create the type definition | |||||
| final GeneralTypeDefinition typeDef = new GeneralTypeDefinition(); | |||||
| typeDef.setType( "data-type" ); | |||||
| typeDef.setName( "test-type1" ); | |||||
| typeDef.setClassname( TestType1.class.getName() ); | |||||
| // Deploy the type | |||||
| final ClassLoader classLoader = getClass().getClassLoader(); | |||||
| final TypeDeployer typeDeployer = m_deployer.createDeployer( classLoader ); | |||||
| typeDeployer.deployType( typeDef ); | |||||
| // Create an instance | |||||
| final TypeFactory typeFactory = getTypeManager().getFactory( DataType.class ); | |||||
| Object obj = typeFactory.create( "test-type1" ); | |||||
| // Check the type | |||||
| assertTrue( obj instanceof TestType1 ); | |||||
| } | |||||
| /** | |||||
| * Tests deployment of a single converter from a ClassLoader. | |||||
| */ | |||||
| public void testSingleConverter() throws Exception | |||||
| { | |||||
| // Create the type definition | |||||
| final ConverterDefinition typeDef = new ConverterDefinition(); | |||||
| typeDef.setClassname( TestConverter1.class.getName() ); | |||||
| typeDef.setSourceType( "java.lang.String" ); | |||||
| typeDef.setDestinationType( TestType1.class.getName() ); | |||||
| // Deploy the type | |||||
| final ClassLoader classLoader = getClass().getClassLoader(); | |||||
| final TypeDeployer typeDeployer = m_deployer.createDeployer( classLoader ); | |||||
| typeDeployer.deployType( typeDef ); | |||||
| // Try to convert from string to test type | |||||
| final MasterConverter converter = (MasterConverter)getComponentManager().lookup( MasterConverter.ROLE ); | |||||
| Object obj = converter.convert( TestType1.class, "some-string", null ); | |||||
| // Check the type | |||||
| assertTrue( obj instanceof TestType1 ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,30 @@ | |||||
| /* | |||||
| * 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; | |||||
| import org.apache.myrmidon.converter.Converter; | |||||
| import org.apache.myrmidon.converter.ConverterException; | |||||
| import org.apache.avalon.framework.context.Context; | |||||
| /** | |||||
| * 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, Context context ) | |||||
| throws ConverterException | |||||
| { | |||||
| return new TestType1(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,20 @@ | |||||
| /* | |||||
| * 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; | |||||
| import org.apache.myrmidon.framework.DataType; | |||||
| /** | |||||
| * A test data-type. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| */ | |||||
| public class TestType1 | |||||
| implements DataType | |||||
| { | |||||
| } | |||||