* A class may now be explicitly associated with a role, rather than being implicit in the role name. * Added RoleInfo to bundle up role meta-info. * Reworked the methods of RoleManager. * Added test-cases for DefaultRoleManager. * Make tests compile again. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271498 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -25,6 +25,7 @@ import org.apache.avalon.framework.service.Serviceable; | |||||
| 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; | ||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | import org.apache.myrmidon.interfaces.converter.MasterConverter; | ||||
| import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
| import org.apache.myrmidon.interfaces.type.TypeFactory; | import org.apache.myrmidon.interfaces.type.TypeFactory; | ||||
| @@ -468,7 +469,7 @@ public class DefaultConfigurer | |||||
| private PropertyConfigurer getConfigurerFromName( final ObjectConfigurer configurer, | private PropertyConfigurer getConfigurerFromName( final ObjectConfigurer configurer, | ||||
| final String name, | final String name, | ||||
| boolean ignoreRoleName ) | boolean ignoreRoleName ) | ||||
| throws NoSuchPropertyException | |||||
| throws Exception | |||||
| { | { | ||||
| // Try a named property | // Try a named property | ||||
| final NoSuchPropertyException exc; | final NoSuchPropertyException exc; | ||||
| @@ -486,8 +487,8 @@ public class DefaultConfigurer | |||||
| final PropertyConfigurer propertyConfigurer = configurer.getTypedProperty(); | final PropertyConfigurer propertyConfigurer = configurer.getTypedProperty(); | ||||
| if( !ignoreRoleName ) | if( !ignoreRoleName ) | ||||
| { | { | ||||
| final String roleShorthand = m_roleManager.getNameForRole( propertyConfigurer.getType().getName() ); | |||||
| if( !name.equalsIgnoreCase( roleShorthand ) ) | |||||
| final RoleInfo roleInfo = m_roleManager.getRoleByType( propertyConfigurer.getType() ); | |||||
| if( roleInfo == null || !name.equalsIgnoreCase( roleInfo.getShorthand() ) ) | |||||
| { | { | ||||
| // Rethrow the original exception | // Rethrow the original exception | ||||
| throw exc; | throw exc; | ||||
| @@ -24,6 +24,7 @@ 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.TypeDefinition; | ||||
| import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | ||||
| import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| import org.apache.myrmidon.interfaces.service.AntServiceManager; | import org.apache.myrmidon.interfaces.service.AntServiceManager; | ||||
| import org.apache.myrmidon.interfaces.service.ServiceFactory; | import org.apache.myrmidon.interfaces.service.ServiceFactory; | ||||
| @@ -146,12 +147,10 @@ public class DefaultDeployer | |||||
| final ServiceDefinition definition ) | final ServiceDefinition definition ) | ||||
| throws Exception | throws Exception | ||||
| { | { | ||||
| // Determine the service interface class name | |||||
| String serviceTypeName = getRoleForName( definition.getRoleShorthand() ); | |||||
| // Register the service factory | |||||
| final String roleShorthand = definition.getRoleShorthand(); | |||||
| final Class serviceType = getRoleType( roleShorthand ); | |||||
| final String factoryClassName = definition.getFactoryClass(); | final String factoryClassName = definition.getFactoryClass(); | ||||
| handleType( deployment, ServiceFactory.class, serviceTypeName, factoryClassName ); | |||||
| handleType( deployment, ServiceFactory.class, serviceType.getName(), factoryClassName ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -206,8 +205,7 @@ public class DefaultDeployer | |||||
| } | } | ||||
| // Deploy general-purpose type | // Deploy general-purpose type | ||||
| final String role = getRoleForName( roleShorthand ); | |||||
| final Class roleType = deployment.getClassLoader().loadClass( role ); | |||||
| final Class roleType = getRoleType( roleShorthand ); | |||||
| handleType( deployment, roleType, typeName, className ); | handleType( deployment, roleType, typeName, className ); | ||||
| if( getLogger().isDebugEnabled() ) | if( getLogger().isDebugEnabled() ) | ||||
| @@ -261,10 +259,13 @@ public class DefaultDeployer | |||||
| */ | */ | ||||
| public void deployRole( final Deployment deployment, | public void deployRole( final Deployment deployment, | ||||
| final RoleDefinition roleDef ) | final RoleDefinition roleDef ) | ||||
| throws Exception | |||||
| { | { | ||||
| final String name = roleDef.getShortHand(); | final String name = roleDef.getShortHand(); | ||||
| final String role = roleDef.getRoleName(); | final String role = roleDef.getRoleName(); | ||||
| m_roleManager.addNameRoleMapping( name, role ); | |||||
| final Class type = deployment.getClassLoader().loadClass( role ); | |||||
| final RoleInfo roleInfo = new RoleInfo( role, name, type ); | |||||
| m_roleManager.addRole( roleInfo ); | |||||
| if( getLogger().isDebugEnabled() ) | if( getLogger().isDebugEnabled() ) | ||||
| { | { | ||||
| @@ -274,19 +275,17 @@ public class DefaultDeployer | |||||
| } | } | ||||
| /** | /** | ||||
| * Determines the role name from shorthand name. | |||||
| * Determines the type for a role, from its shorthand. | |||||
| */ | */ | ||||
| private String getRoleForName( final String name ) | |||||
| private Class getRoleType( final String roleShorthand ) | |||||
| throws DeploymentException | throws DeploymentException | ||||
| { | { | ||||
| final String role = m_roleManager.getRoleForName( name ); | |||||
| if( null == role ) | |||||
| final RoleInfo roleInfo = m_roleManager.getRoleByShorthandName( roleShorthand ); | |||||
| if( null == roleInfo ) | |||||
| { | { | ||||
| final String message = REZ.getString( "unknown-role4name.error", name ); | |||||
| final String message = REZ.getString( "unknown-role4name.error", roleShorthand ); | |||||
| throw new DeploymentException( message ); | throw new DeploymentException( message ); | ||||
| } | } | ||||
| return role; | |||||
| return roleInfo.getType(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -267,15 +267,25 @@ class Deployment | |||||
| * Deploys the roles from a role descriptor. | * Deploys the roles from a role descriptor. | ||||
| */ | */ | ||||
| private void deployRoles( final RoleDescriptor descriptor ) | private void deployRoles( final RoleDescriptor descriptor ) | ||||
| throws DeploymentException | |||||
| { | { | ||||
| final String message = REZ.getString( "url-deploy-roles.notice", descriptor.getUrl() ); | |||||
| getLogger().info( message ); | |||||
| final RoleDefinition[] definitions = descriptor.getDefinitions(); | |||||
| for( int i = 0; i < definitions.length; i++ ) | |||||
| try | |||||
| { | { | ||||
| final RoleDefinition definition = definitions[ i ]; | |||||
| m_deployer.deployRole( this, definition ); | |||||
| final String message = REZ.getString( "url-deploy-roles.notice", descriptor.getUrl() ); | |||||
| getLogger().info( message ); | |||||
| final RoleDefinition[] definitions = descriptor.getDefinitions(); | |||||
| for( int i = 0; i < definitions.length; i++ ) | |||||
| { | |||||
| final RoleDefinition definition = definitions[ i ]; | |||||
| m_deployer.deployRole( this, definition ); | |||||
| } | |||||
| } | |||||
| catch( Exception e ) | |||||
| { | |||||
| final String message = REZ.getString( "deploy-roles.error", descriptor.getUrl() ); | |||||
| throw new DeploymentException( message, e ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -7,6 +7,7 @@ url-deploy-services.notice=Registering services from "{0}". | |||||
| deploy-from-classloader.error=Could not register types from ClassLoader. | deploy-from-classloader.error=Could not register types from ClassLoader. | ||||
| deploy-from-file.error=Could not register types from type library "{0}". | deploy-from-file.error=Could not register types from type library "{0}". | ||||
| deploy-roles.error=Could not register roles from "{0}". | |||||
| deploy-types.error=Could not register types from "{0}". | deploy-types.error=Could not register types from "{0}". | ||||
| deploy-services.error=Could not register services from "{0}". | deploy-services.error=Could not register services from "{0}". | ||||
| deploy-converter.error=Could not register converter that converts from {0} to {1}. | deploy-converter.error=Could not register converter that converts from {0} to {1}. | ||||
| @@ -10,6 +10,8 @@ package org.apache.myrmidon.components.role; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| 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.interfaces.role.RoleException; | |||||
| import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| /** | /** | ||||
| @@ -27,11 +29,14 @@ public class DefaultRoleManager | |||||
| /** Parent <code>RoleManager</code> for nested resolution */ | /** Parent <code>RoleManager</code> for nested resolution */ | ||||
| private final RoleManager m_parent; | private final RoleManager m_parent; | ||||
| /** Map for name to role mapping */ | |||||
| private final HashMap m_names = new HashMap(); | |||||
| /** Map from shorthand name -> RoleInfo. */ | |||||
| private final HashMap m_shorthandMap = new HashMap(); | |||||
| /** Map for role to name mapping */ | |||||
| private final HashMap m_roles = new HashMap(); | |||||
| /** Map from role name -> RoleInfo. */ | |||||
| private final HashMap m_nameMap = new HashMap(); | |||||
| /** Map from role type -> RoleInfo. */ | |||||
| private final HashMap m_typeMap = new HashMap(); | |||||
| /** | /** | ||||
| * constructor--this RoleManager has no parent. | * constructor--this RoleManager has no parent. | ||||
| @@ -53,66 +58,106 @@ public class DefaultRoleManager | |||||
| } | } | ||||
| /** | /** | ||||
| * Find Role name based on shorthand name. | |||||
| * Find role based on shorthand name. | |||||
| * | * | ||||
| * @param name the shorthand name | * @param name the shorthand name | ||||
| * @return the role | |||||
| * @return the role, or null if the role cannot be found. | |||||
| */ | */ | ||||
| public String getRoleForName( final String name ) | |||||
| public RoleInfo getRoleByShorthandName( final String name ) | |||||
| { | { | ||||
| final String role = (String)m_names.get( name ); | |||||
| final RoleInfo role = (RoleInfo)m_shorthandMap.get( name ); | |||||
| if( null == role && null != m_parent ) | if( null == role && null != m_parent ) | ||||
| { | { | ||||
| return m_parent.getRoleForName( name ); | |||||
| return m_parent.getRoleByShorthandName( name ); | |||||
| } | } | ||||
| return role; | return role; | ||||
| } | } | ||||
| /** | /** | ||||
| * Find name based on role. | |||||
| * Find role based on role type. | |||||
| * | * | ||||
| * @param role the role | |||||
| * @return the name | |||||
| * @param type the role type. | |||||
| * @return the role, or null if the role cannot be found. | |||||
| */ | */ | ||||
| public String getNameForRole( final String role ) | |||||
| public RoleInfo getRoleByType( final Class type ) | |||||
| { | { | ||||
| final String name = (String)m_roles.get( role ); | |||||
| final RoleInfo role = (RoleInfo)m_typeMap.get( type ); | |||||
| if( null == name && null != m_parent ) | |||||
| if( null == role && null != m_parent ) | |||||
| { | { | ||||
| return m_parent.getNameForRole( name ); | |||||
| return m_parent.getRoleByType( type ); | |||||
| } | } | ||||
| return name; | |||||
| return role; | |||||
| } | } | ||||
| /** | /** | ||||
| * Add a mapping between name and role | |||||
| * Find role based on name. | |||||
| * | * | ||||
| * @param name the shorthand name | |||||
| * @param role the role | |||||
| * @exception IllegalArgumentException if an name is already mapped to a different role | |||||
| * @param name the role name | |||||
| * @return the role, or null if the role cannot be found. | |||||
| */ | |||||
| public RoleInfo getRole( final String name ) | |||||
| { | |||||
| final RoleInfo role = (RoleInfo)m_nameMap.get( name ); | |||||
| if( null == role && null != m_parent ) | |||||
| { | |||||
| return m_parent.getRole( name ); | |||||
| } | |||||
| return role; | |||||
| } | |||||
| /** | |||||
| * Adds a role definition. | |||||
| */ | */ | ||||
| public void addNameRoleMapping( final String name, final String role ) | |||||
| throws IllegalArgumentException | |||||
| public void addRole( final RoleInfo role ) throws RoleException | |||||
| { | { | ||||
| final String oldRole = (String)m_names.get( name ); | |||||
| // Check for duplicate role names | |||||
| final String roleName = role.getName(); | |||||
| RoleInfo oldRole = (RoleInfo)m_nameMap.get( roleName ); | |||||
| if( null != oldRole && !oldRole.equals( role ) ) | if( null != oldRole && !oldRole.equals( role ) ) | ||||
| { | { | ||||
| final String message = REZ.getString( "duplicate-name.error", oldRole ); | |||||
| throw new IllegalArgumentException( message ); | |||||
| final String message = REZ.getString( "duplicate-role.error", roleName ); | |||||
| throw new RoleException( message ); | |||||
| } | } | ||||
| final String oldName = (String)m_roles.get( role ); | |||||
| if( null != oldName && !oldName.equals( name ) ) | |||||
| // Check for duplicate shorthand names | |||||
| final String shorthand = role.getShorthand(); | |||||
| if( shorthand != null ) | |||||
| { | { | ||||
| final String message = REZ.getString( "duplicate-role.error", oldName ); | |||||
| throw new IllegalArgumentException( message ); | |||||
| oldRole = (RoleInfo)m_shorthandMap.get( shorthand ); | |||||
| if( null != oldRole && !oldRole.equals( role ) ) | |||||
| { | |||||
| final String message = REZ.getString( "duplicate-shorthand.error", shorthand ); | |||||
| throw new RoleException( message ); | |||||
| } | |||||
| } | } | ||||
| m_names.put( name, role ); | |||||
| m_roles.put( role, name ); | |||||
| // Check for duplicate types | |||||
| final Class roleType = role.getType(); | |||||
| if( roleType != null ) | |||||
| { | |||||
| oldRole = (RoleInfo)m_typeMap.get( roleType ); | |||||
| if( null != oldRole && !oldRole.equals( role ) ) | |||||
| { | |||||
| final String message = REZ.getString( "duplicate-type.error", roleType.getName() ); | |||||
| throw new RoleException( message ); | |||||
| } | |||||
| } | |||||
| // Add the role to the maps | |||||
| m_nameMap.put( roleName, role ); | |||||
| if( shorthand != null ) | |||||
| { | |||||
| m_shorthandMap.put( shorthand, role ); | |||||
| } | |||||
| if( roleType != null ) | |||||
| { | |||||
| m_typeMap.put( roleType, role ); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,2 +1,3 @@ | |||||
| duplicate-name.error=Name already mapped to another role ({0}). | |||||
| duplicate-role.error=Role already mapped to another name ({0}). | |||||
| duplicate-shorthand.error=Duplicate roles with shorthand name "{0}". | |||||
| duplicate-type.error=Duplicate roles with type "{0}". | |||||
| duplicate-role.error=Duplicate roles with name "{0}". | |||||
| @@ -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.interfaces.role; | |||||
| import org.apache.avalon.framework.CascadingException; | |||||
| /** | |||||
| * An exception thrown by the RoleManager. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public class RoleException | |||||
| extends CascadingException | |||||
| { | |||||
| public RoleException( String s ) | |||||
| { | |||||
| super( s ); | |||||
| } | |||||
| public RoleException( String s, Throwable throwable ) | |||||
| { | |||||
| super( s, throwable ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,130 @@ | |||||
| /* | |||||
| * 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.role; | |||||
| /** | |||||
| * A role definition. Role definitions are immutable. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public final class RoleInfo | |||||
| { | |||||
| private final String m_name; | |||||
| private final String m_shorthand; | |||||
| private final Class m_type; | |||||
| /** | |||||
| * Creates a role definition. | |||||
| * | |||||
| * @param name The role name. | |||||
| */ | |||||
| public RoleInfo( final String name ) | |||||
| { | |||||
| m_name = name; | |||||
| m_shorthand = null; | |||||
| m_type = null; | |||||
| } | |||||
| /** | |||||
| * Creates a role definition. | |||||
| * | |||||
| * @param name The role name. | |||||
| * @param shorthand The role shorthand name. | |||||
| */ | |||||
| public RoleInfo( final String name, final String shorthand ) | |||||
| { | |||||
| m_name = name; | |||||
| m_shorthand = shorthand; | |||||
| m_type = null; | |||||
| } | |||||
| /** | |||||
| * Creates a role definition. | |||||
| * | |||||
| * @param name The role name. | |||||
| * @param shorthand The role shorthand name. May be null. | |||||
| * @param type The role type. May be null. | |||||
| */ | |||||
| public RoleInfo( final String name, final String shorthand, final Class type ) | |||||
| { | |||||
| m_name = name; | |||||
| m_shorthand = shorthand; | |||||
| m_type = type; | |||||
| } | |||||
| /** | |||||
| * Creates a role definition. The role type's fully-qualified name | |||||
| * is used as the role name. | |||||
| */ | |||||
| public RoleInfo( final String shorthand, final Class type ) | |||||
| { | |||||
| m_name = type.getName(); | |||||
| m_shorthand = shorthand; | |||||
| m_type = type; | |||||
| } | |||||
| /** | |||||
| * Compares a role to this role. | |||||
| */ | |||||
| public boolean equals( final RoleInfo role ) | |||||
| { | |||||
| if( role == null ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| if( ! m_name.equals( role.m_name ) ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| if( m_shorthand == null && role.m_shorthand != null ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| if( m_shorthand != null && ! m_shorthand.equals( role.m_shorthand ) ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| if( m_type != role.m_type ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| /** | |||||
| * Returns this role's name. This name uniquely identifies the role. | |||||
| */ | |||||
| public String getName() | |||||
| { | |||||
| return m_name; | |||||
| } | |||||
| /** | |||||
| * Returns this role's shorthand name. | |||||
| * | |||||
| * @return The shorthand name, or null if this role has none. | |||||
| */ | |||||
| public String getShorthand() | |||||
| { | |||||
| return m_shorthand; | |||||
| } | |||||
| /** | |||||
| * Returns this role's type. All implementations of this role must be | |||||
| * assignable to this type. | |||||
| * | |||||
| * @return The role type, or null if this role has no type. | |||||
| */ | |||||
| public Class getType() | |||||
| { | |||||
| return m_type; | |||||
| } | |||||
| } | |||||
| @@ -8,12 +8,13 @@ | |||||
| package org.apache.myrmidon.interfaces.role; | package org.apache.myrmidon.interfaces.role; | ||||
| /** | /** | ||||
| * Interface to manage roles and mapping to shorthand names. | |||||
| * Interface to manage roles. | |||||
| * | * | ||||
| * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a> | * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a> | ||||
| * @author <a href="mailto:ricardo@apache,org">Ricardo Rocha</a> | * @author <a href="mailto:ricardo@apache,org">Ricardo Rocha</a> | ||||
| * @author <a href="mailto:giacomo@apache,org">Giacomo Pati</a> | * @author <a href="mailto:giacomo@apache,org">Giacomo Pati</a> | ||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version CVS $Revision$ $Date$ | * @version CVS $Revision$ $Date$ | ||||
| */ | */ | ||||
| public interface RoleManager | public interface RoleManager | ||||
| @@ -21,27 +22,31 @@ public interface RoleManager | |||||
| String ROLE = RoleManager.class.getName(); | String ROLE = RoleManager.class.getName(); | ||||
| /** | /** | ||||
| * Find Role name based on shorthand name. | |||||
| * Find role based on shorthand name. | |||||
| * | * | ||||
| * @param name the shorthand name | * @param name the shorthand name | ||||
| * @return the role | |||||
| * @return the role, or null if the role cannot be found. | |||||
| */ | */ | ||||
| String getRoleForName( String name ); | |||||
| RoleInfo getRoleByShorthandName( String name ); | |||||
| /** | /** | ||||
| * Find name based on role. | |||||
| * Find role based on role type. | |||||
| * | * | ||||
| * @param role the role | |||||
| * @return the name | |||||
| * @param type the role type. | |||||
| * @return the role, or null if the role cannot be found. | |||||
| */ | */ | ||||
| String getNameForRole( String role ); | |||||
| RoleInfo getRoleByType( Class type ); | |||||
| /** | /** | ||||
| * Adds a role mapping. | |||||
| * Find role based on name. | |||||
| * | * | ||||
| * @param name the shorthand name. | |||||
| * @param role the role name. | |||||
| * @param name the role name | |||||
| * @return the role, or null if the role cannot be found. | |||||
| */ | */ | ||||
| void addNameRoleMapping( String name, String role ) | |||||
| throws IllegalArgumentException; | |||||
| RoleInfo getRole( String name ); | |||||
| /** | |||||
| * Adds a role definition. | |||||
| */ | |||||
| void addRole( RoleInfo role ) throws RoleException; | |||||
| } | } | ||||
| @@ -4,7 +4,7 @@ | |||||
| <role shorthand="listener" name="org.apache.myrmidon.listeners.ProjectListener"/> | <role shorthand="listener" name="org.apache.myrmidon.listeners.ProjectListener"/> | ||||
| <role shorthand="aspect" name="org.apache.myrmidon.aspects.AspectHandler"/> | <role shorthand="aspect" name="org.apache.myrmidon.aspects.AspectHandler"/> | ||||
| <role shorthand="project-builder" name="org.apache.myrmidon.interfaces.builder.ProjectBuilder"/> | <role shorthand="project-builder" name="org.apache.myrmidon.interfaces.builder.ProjectBuilder"/> | ||||
| <role shorthand="converter" name="org.apache.myrmidon.converter.Converter"/> | |||||
| <role shorthand="converter" name="org.apache.aut.converter.Converter"/> | |||||
| <role shorthand="configurer" name="org.apache.myrmidon.interfaces.configurer.Configurer"/> | <role shorthand="configurer" name="org.apache.myrmidon.interfaces.configurer.Configurer"/> | ||||
| <role shorthand="exec-manager" name="org.apache.aut.nativelib.ExecManager"/> | <role shorthand="exec-manager" name="org.apache.aut.nativelib.ExecManager"/> | ||||
| <role shorthand="file-system-manager" name="org.apache.aut.vfs.FileSystemManager"/> | <role shorthand="file-system-manager" name="org.apache.aut.vfs.FileSystemManager"/> | ||||
| @@ -10,11 +10,12 @@ package org.apache.myrmidon.components; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.List; | import java.util.List; | ||||
| import org.apache.aut.converter.Converter; | |||||
| import org.apache.avalon.framework.logger.LogEnabled; | import org.apache.avalon.framework.logger.LogEnabled; | ||||
| import org.apache.avalon.framework.logger.Logger; | import org.apache.avalon.framework.logger.Logger; | ||||
| import org.apache.avalon.framework.service.DefaultServiceManager; | import org.apache.avalon.framework.service.DefaultServiceManager; | ||||
| import org.apache.avalon.framework.service.ServiceManager; | |||||
| import org.apache.avalon.framework.service.ServiceException; | import org.apache.avalon.framework.service.ServiceException; | ||||
| import org.apache.avalon.framework.service.ServiceManager; | |||||
| import org.apache.avalon.framework.service.Serviceable; | import org.apache.avalon.framework.service.Serviceable; | ||||
| import org.apache.myrmidon.AbstractMyrmidonTest; | import org.apache.myrmidon.AbstractMyrmidonTest; | ||||
| import org.apache.myrmidon.components.configurer.DefaultConfigurer; | import org.apache.myrmidon.components.configurer.DefaultConfigurer; | ||||
| @@ -25,14 +26,15 @@ import org.apache.myrmidon.components.deployer.DefaultClassLoaderManager; | |||||
| import org.apache.myrmidon.components.deployer.DefaultDeployer; | import org.apache.myrmidon.components.deployer.DefaultDeployer; | ||||
| import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | ||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | import org.apache.myrmidon.components.role.DefaultRoleManager; | ||||
| import org.apache.myrmidon.components.service.DefaultAntServiceManager; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeManager; | import org.apache.myrmidon.components.type.DefaultTypeManager; | ||||
| import org.apache.aut.converter.Converter; | |||||
| 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.ConverterRegistry; | ||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | import org.apache.myrmidon.interfaces.converter.MasterConverter; | ||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
| import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | ||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| import org.apache.myrmidon.interfaces.service.AntServiceManager; | |||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| @@ -115,8 +117,8 @@ public abstract class AbstractComponentTest | |||||
| m_serviceManager.put( RoleManager.ROLE, component ); | m_serviceManager.put( RoleManager.ROLE, component ); | ||||
| components.add( component ); | components.add( component ); | ||||
| component = new DefaultServiceManager(); | |||||
| m_serviceManager.put( ServiceManager.ROLE, component ); | |||||
| component = new DefaultAntServiceManager(); | |||||
| m_serviceManager.put( AntServiceManager.ROLE, component ); | |||||
| components.add( component ); | components.add( component ); | ||||
| // Log enable the components | // Log enable the components | ||||
| @@ -13,12 +13,15 @@ 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.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.context.Context; | |||||
| 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.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; | ||||
| import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| /** | /** | ||||
| @@ -34,6 +37,7 @@ public class DefaultConfigurerTest | |||||
| private Configurer m_configurer; | private Configurer m_configurer; | ||||
| private DefaultTaskContext m_context; | private DefaultTaskContext m_context; | ||||
| private Context m_adaptor; | |||||
| public DefaultConfigurerTest( String name ) | public DefaultConfigurerTest( String name ) | ||||
| { | { | ||||
| @@ -55,6 +59,7 @@ public class DefaultConfigurerTest | |||||
| m_context = new DefaultTaskContext(); | m_context = new DefaultTaskContext(); | ||||
| 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 ); | ||||
| m_adaptor = new TaskContextAdapter( m_context ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -73,7 +78,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest1 test = new ConfigTest1(); | final ConfigTest1 test = new ConfigTest1(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -102,7 +107,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest10 test = new ConfigTest10(); | final ConfigTest10 test = new ConfigTest10(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest10 expected = new ConfigTest10(); | final ConfigTest10 expected = new ConfigTest10(); | ||||
| @@ -126,7 +131,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -156,7 +161,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest2 test = new ConfigTest2(); | final ConfigTest2 test = new ConfigTest2(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest2 expected = new ConfigTest2(); | final ConfigTest2 expected = new ConfigTest2(); | ||||
| @@ -185,7 +190,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -209,7 +214,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest1 test = new ConfigTest1(); | final ConfigTest1 test = new ConfigTest1(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -232,7 +237,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -257,7 +262,7 @@ public class DefaultConfigurerTest | |||||
| m_context.setProperty( "prop-a", "other" ); | m_context.setProperty( "prop-a", "other" ); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check the configured object | // Check the configured object | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -279,7 +284,7 @@ public class DefaultConfigurerTest | |||||
| m_context.setProperty( "prop-a", "some value" ); | m_context.setProperty( "prop-a", "some value" ); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check the configured object | // Check the configured object | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -303,7 +308,7 @@ public class DefaultConfigurerTest | |||||
| m_context.setProperty( "prop-a", "some value" ); | m_context.setProperty( "prop-a", "some value" ); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check the configured object | // Check the configured object | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -329,7 +334,7 @@ public class DefaultConfigurerTest | |||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
| @@ -354,7 +359,7 @@ public class DefaultConfigurerTest | |||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -380,7 +385,7 @@ public class DefaultConfigurerTest | |||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -415,7 +420,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest6 test = new ConfigTest6(); | final ConfigTest6 test = new ConfigTest6(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| final ConfigTest6 expected = new ConfigTest6(); | final ConfigTest6 expected = new ConfigTest6(); | ||||
| expected.add( new MyType1() ); | expected.add( new MyType1() ); | ||||
| @@ -435,13 +440,14 @@ public class DefaultConfigurerTest | |||||
| // Set up the converter and role | // Set up the converter and role | ||||
| RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | ||||
| roleMgr.addNameRoleMapping( "my-role1", MyRole1.ROLE ); | |||||
| final RoleInfo roleInfo = new RoleInfo("my-role1", MyRole1.class ); | |||||
| roleMgr.addRole( roleInfo ); | |||||
| registerConverter( StringToMyRole1Converter.class, String.class, MyRole1.class ); | registerConverter( StringToMyRole1Converter.class, String.class, MyRole1.class ); | ||||
| final ConfigTest6 test = new ConfigTest6(); | final ConfigTest6 test = new ConfigTest6(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest6 expected = new ConfigTest6(); | final ConfigTest6 expected = new ConfigTest6(); | ||||
| @@ -465,7 +471,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest7 test = new ConfigTest7(); | final ConfigTest7 test = new ConfigTest7(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| final ConfigTest7 expected = new ConfigTest7(); | final ConfigTest7 expected = new ConfigTest7(); | ||||
| expected.add( child1 ); | expected.add( child1 ); | ||||
| @@ -489,7 +495,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest8 test = new ConfigTest8(); | final ConfigTest8 test = new ConfigTest8(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| final ConfigTest8 expected = new ConfigTest8(); | final ConfigTest8 expected = new ConfigTest8(); | ||||
| expected.addConfig( child1 ); | expected.addConfig( child1 ); | ||||
| @@ -509,7 +515,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest9 test = new ConfigTest9(); | final ConfigTest9 test = new ConfigTest9(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| final ConfigTest9 expected = new ConfigTest9(); | final ConfigTest9 expected = new ConfigTest9(); | ||||
| expected.configure( config ); | expected.configure( config ); | ||||
| @@ -532,7 +538,7 @@ public class DefaultConfigurerTest | |||||
| m_context.setProperty( "prop-a", "some indirect value" ); | m_context.setProperty( "prop-a", "some indirect value" ); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check the configured object | // Check the configured object | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -555,7 +561,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
| @@ -583,7 +589,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
| @@ -612,14 +618,15 @@ public class DefaultConfigurerTest | |||||
| // Add role mapping, and add to reference to context | // Add role mapping, and add to reference to context | ||||
| final RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | final RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | ||||
| roleMgr.addNameRoleMapping( "my-role1", MyRole1.class.getName() ); | |||||
| final RoleInfo roleInfo = new RoleInfo( "my-role1", MyRole1.class ); | |||||
| roleMgr.addRole( roleInfo ); | |||||
| m_context.setProperty( "id", new MyType1() ); | m_context.setProperty( "id", new MyType1() ); | ||||
| m_context.setProperty( "id2", new MyType2() ); | m_context.setProperty( "id2", new MyType2() ); | ||||
| final ConfigTest6 test = new ConfigTest6(); | final ConfigTest6 test = new ConfigTest6(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Compare against expected value | // Compare against expected value | ||||
| final ConfigTest6 expected = new ConfigTest6(); | final ConfigTest6 expected = new ConfigTest6(); | ||||
| @@ -644,7 +651,7 @@ public class DefaultConfigurerTest | |||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
| @@ -675,7 +682,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest3 test = new ConfigTest3(); | final ConfigTest3 test = new ConfigTest3(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Test expected value | // Test expected value | ||||
| final ConfigTest3 expected = new ConfigTest3(); | final ConfigTest3 expected = new ConfigTest3(); | ||||
| @@ -15,6 +15,7 @@ import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | 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.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.type.TypeFactory; | import org.apache.myrmidon.interfaces.type.TypeFactory; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
| @@ -32,6 +33,7 @@ public class DefaultDeployerTest | |||||
| { | { | ||||
| private static final String TEST_TYPE1_NAME = "test-type1"; | private static final String TEST_TYPE1_NAME = "test-type1"; | ||||
| private static final String DATA_TYPE_ROLE = "data-type"; | private static final String DATA_TYPE_ROLE = "data-type"; | ||||
| private static final String CONVERTER_ROLE = "converter"; | |||||
| private Deployer m_deployer; | private Deployer m_deployer; | ||||
| private RoleManager m_roleManager; | private RoleManager m_roleManager; | ||||
| @@ -54,8 +56,8 @@ public class DefaultDeployerTest | |||||
| // Add some core roles | // Add some core roles | ||||
| m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | ||||
| m_roleManager.addNameRoleMapping( DATA_TYPE_ROLE, DataType.ROLE ); | |||||
| m_roleManager.addNameRoleMapping( "converter", Converter.ROLE ); | |||||
| m_roleManager.addRole( new RoleInfo( DataType.ROLE, DATA_TYPE_ROLE, DataType.class ) ); | |||||
| m_roleManager.addRole( new RoleInfo( Converter.ROLE, CONVERTER_ROLE, Converter.class ) ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,182 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.myrmidon.components.role; | |||||
| import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
| import org.apache.myrmidon.api.Task; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.role.RoleException; | |||||
| import org.apache.avalon.excalibur.i18n.Resources; | |||||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
| /** | |||||
| * Test cases for the DefaultRoleManager. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public class DefaultRoleManagerTest | |||||
| extends AbstractMyrmidonTest | |||||
| { | |||||
| private final static Resources REZ | |||||
| = ResourceManager.getPackageResources( DefaultRoleManagerTest.class ); | |||||
| private RoleManager m_roleManager; | |||||
| public DefaultRoleManagerTest( String name ) | |||||
| { | |||||
| super( name ); | |||||
| } | |||||
| protected void setUp() throws Exception | |||||
| { | |||||
| m_roleManager = new DefaultRoleManager(); | |||||
| } | |||||
| /** | |||||
| * Tests looking up a role by name, shorthand and type. | |||||
| */ | |||||
| public void testLookup() throws Exception | |||||
| { | |||||
| final String roleName = "role-name"; | |||||
| final String shorthand = "role-shorthand"; | |||||
| final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
| m_roleManager.addRole( origRole ); | |||||
| // Lookup the role | |||||
| RoleInfo role = m_roleManager.getRole( roleName ); | |||||
| assertTrue( origRole.equals(role) ); | |||||
| // Lookup the role by shorthand | |||||
| role = m_roleManager.getRoleByShorthandName( shorthand ); | |||||
| assertTrue( origRole.equals( role ) ); | |||||
| // Lookup the role by type | |||||
| role = m_roleManager.getRoleByType( Task.class ); | |||||
| assertTrue( origRole.equals( role ) ); | |||||
| // Lookup an unknown role | |||||
| RoleInfo unknownRole = m_roleManager.getRole( "unknown" ); | |||||
| assertNull( unknownRole ); | |||||
| // Lookup an unknown shorthand | |||||
| unknownRole = m_roleManager.getRoleByShorthandName( "unknown" ); | |||||
| assertNull( unknownRole ); | |||||
| // Lookup an unknown role | |||||
| unknownRole = m_roleManager.getRoleByType( DefaultRoleManagerTest.class ); | |||||
| assertNull( unknownRole ); | |||||
| } | |||||
| /** | |||||
| * Tests inheriting roles from parent role manager. | |||||
| */ | |||||
| public void testParent() throws Exception | |||||
| { | |||||
| final String roleName = "role-name"; | |||||
| final String shorthand = "shorthand"; | |||||
| final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
| m_roleManager.addRole( origRole ); | |||||
| final RoleManager roleManager = new DefaultRoleManager( m_roleManager ); | |||||
| // Lookup by name | |||||
| RoleInfo roleInfo = roleManager.getRole( roleName ); | |||||
| assertTrue( origRole.equals( roleInfo ) ); | |||||
| // Lookup by shorthand | |||||
| roleInfo = roleManager.getRoleByShorthandName( shorthand ); | |||||
| assertTrue( origRole.equals( roleInfo ) ); | |||||
| // Lookup by type | |||||
| roleInfo = roleManager.getRoleByType( Task.class ); | |||||
| assertTrue( origRole.equals( roleInfo ) ); | |||||
| } | |||||
| /** | |||||
| * Tests overriding a role in a child role manager. | |||||
| */ | |||||
| public void testOverrideName() throws Exception | |||||
| { | |||||
| final String roleName = "role-name"; | |||||
| final String shorthand = "shorthand"; | |||||
| // Add original role | |||||
| final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
| m_roleManager.addRole( origRole ); | |||||
| // Override role | |||||
| final RoleManager roleManager = new DefaultRoleManager( m_roleManager ); | |||||
| final RoleInfo overrideNameRole = new RoleInfo( roleName, "shorthand1" ); | |||||
| roleManager.addRole( overrideNameRole ); | |||||
| final RoleInfo overrideShorthandRole = new RoleInfo( "role2", shorthand ); | |||||
| roleManager.addRole( overrideShorthandRole ); | |||||
| final RoleInfo overrideTypeRole = new RoleInfo( "role3", "shorthand3", Task.class ); | |||||
| roleManager.addRole( overrideTypeRole ); | |||||
| // Lookup role by name | |||||
| RoleInfo roleInfo = roleManager.getRole( roleName ); | |||||
| assertTrue( overrideNameRole.equals( roleInfo ) ); | |||||
| // Lookup role by shorthand | |||||
| roleInfo = roleManager.getRoleByShorthandName( shorthand ); | |||||
| assertTrue( overrideShorthandRole.equals( roleInfo ) ); | |||||
| // Lookup role by type | |||||
| roleInfo = roleManager.getRoleByType( Task.class ); | |||||
| assertTrue( overrideTypeRole.equals( roleInfo ) ); | |||||
| } | |||||
| /** | |||||
| * Tests adding duplicate roles. | |||||
| */ | |||||
| public void testDuplicate() throws Exception | |||||
| { | |||||
| final String roleName = "role-name"; | |||||
| final String shorthand = "shorthand"; | |||||
| final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
| m_roleManager.addRole( origRole ); | |||||
| // Duplicate role name | |||||
| try | |||||
| { | |||||
| m_roleManager.addRole( new RoleInfo( roleName ) ); | |||||
| fail(); | |||||
| } | |||||
| catch( RoleException exc ) | |||||
| { | |||||
| final String message = REZ.getString( "duplicate-role.error", roleName ); | |||||
| assertSameMessage( message, exc ); | |||||
| } | |||||
| // Duplicate shorthand | |||||
| try | |||||
| { | |||||
| m_roleManager.addRole( new RoleInfo( "another-role", shorthand ) ); | |||||
| fail(); | |||||
| } | |||||
| catch( RoleException exc ) | |||||
| { | |||||
| final String message = REZ.getString( "duplicate-shorthand.error", shorthand ); | |||||
| assertSameMessage( message, exc ); | |||||
| } | |||||
| // Duplicate type | |||||
| try | |||||
| { | |||||
| m_roleManager.addRole( new RoleInfo( null, Task.class ) ); | |||||
| fail(); | |||||
| } | |||||
| catch( RoleException exc ) | |||||
| { | |||||
| final String message = REZ.getString( "duplicate-type.error", Task.class.getName() ); | |||||
| assertSameMessage( message, exc ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -10,11 +10,12 @@ package org.apache.myrmidon.components; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.List; | import java.util.List; | ||||
| import org.apache.aut.converter.Converter; | |||||
| import org.apache.avalon.framework.logger.LogEnabled; | import org.apache.avalon.framework.logger.LogEnabled; | ||||
| import org.apache.avalon.framework.logger.Logger; | import org.apache.avalon.framework.logger.Logger; | ||||
| import org.apache.avalon.framework.service.DefaultServiceManager; | import org.apache.avalon.framework.service.DefaultServiceManager; | ||||
| import org.apache.avalon.framework.service.ServiceManager; | |||||
| import org.apache.avalon.framework.service.ServiceException; | import org.apache.avalon.framework.service.ServiceException; | ||||
| import org.apache.avalon.framework.service.ServiceManager; | |||||
| import org.apache.avalon.framework.service.Serviceable; | import org.apache.avalon.framework.service.Serviceable; | ||||
| import org.apache.myrmidon.AbstractMyrmidonTest; | import org.apache.myrmidon.AbstractMyrmidonTest; | ||||
| import org.apache.myrmidon.components.configurer.DefaultConfigurer; | import org.apache.myrmidon.components.configurer.DefaultConfigurer; | ||||
| @@ -25,14 +26,15 @@ import org.apache.myrmidon.components.deployer.DefaultClassLoaderManager; | |||||
| import org.apache.myrmidon.components.deployer.DefaultDeployer; | import org.apache.myrmidon.components.deployer.DefaultDeployer; | ||||
| import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | ||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | import org.apache.myrmidon.components.role.DefaultRoleManager; | ||||
| import org.apache.myrmidon.components.service.DefaultAntServiceManager; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeManager; | import org.apache.myrmidon.components.type.DefaultTypeManager; | ||||
| import org.apache.aut.converter.Converter; | |||||
| 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.ConverterRegistry; | ||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | import org.apache.myrmidon.interfaces.converter.MasterConverter; | ||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
| import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | ||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| import org.apache.myrmidon.interfaces.service.AntServiceManager; | |||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| @@ -115,8 +117,8 @@ public abstract class AbstractComponentTest | |||||
| m_serviceManager.put( RoleManager.ROLE, component ); | m_serviceManager.put( RoleManager.ROLE, component ); | ||||
| components.add( component ); | components.add( component ); | ||||
| component = new DefaultServiceManager(); | |||||
| m_serviceManager.put( ServiceManager.ROLE, component ); | |||||
| component = new DefaultAntServiceManager(); | |||||
| m_serviceManager.put( AntServiceManager.ROLE, component ); | |||||
| components.add( component ); | components.add( component ); | ||||
| // Log enable the components | // Log enable the components | ||||
| @@ -13,12 +13,15 @@ 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.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.context.Context; | |||||
| 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.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; | ||||
| import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| /** | /** | ||||
| @@ -34,6 +37,7 @@ public class DefaultConfigurerTest | |||||
| private Configurer m_configurer; | private Configurer m_configurer; | ||||
| private DefaultTaskContext m_context; | private DefaultTaskContext m_context; | ||||
| private Context m_adaptor; | |||||
| public DefaultConfigurerTest( String name ) | public DefaultConfigurerTest( String name ) | ||||
| { | { | ||||
| @@ -55,6 +59,7 @@ public class DefaultConfigurerTest | |||||
| m_context = new DefaultTaskContext(); | m_context = new DefaultTaskContext(); | ||||
| 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 ); | ||||
| m_adaptor = new TaskContextAdapter( m_context ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -73,7 +78,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest1 test = new ConfigTest1(); | final ConfigTest1 test = new ConfigTest1(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -102,7 +107,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest10 test = new ConfigTest10(); | final ConfigTest10 test = new ConfigTest10(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest10 expected = new ConfigTest10(); | final ConfigTest10 expected = new ConfigTest10(); | ||||
| @@ -126,7 +131,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -156,7 +161,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest2 test = new ConfigTest2(); | final ConfigTest2 test = new ConfigTest2(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest2 expected = new ConfigTest2(); | final ConfigTest2 expected = new ConfigTest2(); | ||||
| @@ -185,7 +190,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -209,7 +214,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest1 test = new ConfigTest1(); | final ConfigTest1 test = new ConfigTest1(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -232,7 +237,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -257,7 +262,7 @@ public class DefaultConfigurerTest | |||||
| m_context.setProperty( "prop-a", "other" ); | m_context.setProperty( "prop-a", "other" ); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check the configured object | // Check the configured object | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -279,7 +284,7 @@ public class DefaultConfigurerTest | |||||
| m_context.setProperty( "prop-a", "some value" ); | m_context.setProperty( "prop-a", "some value" ); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check the configured object | // Check the configured object | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -303,7 +308,7 @@ public class DefaultConfigurerTest | |||||
| m_context.setProperty( "prop-a", "some value" ); | m_context.setProperty( "prop-a", "some value" ); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check the configured object | // Check the configured object | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -329,7 +334,7 @@ public class DefaultConfigurerTest | |||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
| @@ -354,7 +359,7 @@ public class DefaultConfigurerTest | |||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -380,7 +385,7 @@ public class DefaultConfigurerTest | |||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -415,7 +420,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest6 test = new ConfigTest6(); | final ConfigTest6 test = new ConfigTest6(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| final ConfigTest6 expected = new ConfigTest6(); | final ConfigTest6 expected = new ConfigTest6(); | ||||
| expected.add( new MyType1() ); | expected.add( new MyType1() ); | ||||
| @@ -435,13 +440,14 @@ public class DefaultConfigurerTest | |||||
| // Set up the converter and role | // Set up the converter and role | ||||
| RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | ||||
| roleMgr.addNameRoleMapping( "my-role1", MyRole1.ROLE ); | |||||
| final RoleInfo roleInfo = new RoleInfo("my-role1", MyRole1.class ); | |||||
| roleMgr.addRole( roleInfo ); | |||||
| registerConverter( StringToMyRole1Converter.class, String.class, MyRole1.class ); | registerConverter( StringToMyRole1Converter.class, String.class, MyRole1.class ); | ||||
| final ConfigTest6 test = new ConfigTest6(); | final ConfigTest6 test = new ConfigTest6(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check result | // Check result | ||||
| final ConfigTest6 expected = new ConfigTest6(); | final ConfigTest6 expected = new ConfigTest6(); | ||||
| @@ -465,7 +471,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest7 test = new ConfigTest7(); | final ConfigTest7 test = new ConfigTest7(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| final ConfigTest7 expected = new ConfigTest7(); | final ConfigTest7 expected = new ConfigTest7(); | ||||
| expected.add( child1 ); | expected.add( child1 ); | ||||
| @@ -489,7 +495,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest8 test = new ConfigTest8(); | final ConfigTest8 test = new ConfigTest8(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| final ConfigTest8 expected = new ConfigTest8(); | final ConfigTest8 expected = new ConfigTest8(); | ||||
| expected.addConfig( child1 ); | expected.addConfig( child1 ); | ||||
| @@ -509,7 +515,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest9 test = new ConfigTest9(); | final ConfigTest9 test = new ConfigTest9(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| final ConfigTest9 expected = new ConfigTest9(); | final ConfigTest9 expected = new ConfigTest9(); | ||||
| expected.configure( config ); | expected.configure( config ); | ||||
| @@ -532,7 +538,7 @@ public class DefaultConfigurerTest | |||||
| m_context.setProperty( "prop-a", "some indirect value" ); | m_context.setProperty( "prop-a", "some indirect value" ); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Check the configured object | // Check the configured object | ||||
| final ConfigTest1 expected = new ConfigTest1(); | final ConfigTest1 expected = new ConfigTest1(); | ||||
| @@ -555,7 +561,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
| @@ -583,7 +589,7 @@ public class DefaultConfigurerTest | |||||
| // Configure the object | // Configure the object | ||||
| try | try | ||||
| { | { | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
| @@ -612,14 +618,15 @@ public class DefaultConfigurerTest | |||||
| // Add role mapping, and add to reference to context | // Add role mapping, and add to reference to context | ||||
| final RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | final RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | ||||
| roleMgr.addNameRoleMapping( "my-role1", MyRole1.class.getName() ); | |||||
| final RoleInfo roleInfo = new RoleInfo( "my-role1", MyRole1.class ); | |||||
| roleMgr.addRole( roleInfo ); | |||||
| m_context.setProperty( "id", new MyType1() ); | m_context.setProperty( "id", new MyType1() ); | ||||
| m_context.setProperty( "id2", new MyType2() ); | m_context.setProperty( "id2", new MyType2() ); | ||||
| final ConfigTest6 test = new ConfigTest6(); | final ConfigTest6 test = new ConfigTest6(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Compare against expected value | // Compare against expected value | ||||
| final ConfigTest6 expected = new ConfigTest6(); | final ConfigTest6 expected = new ConfigTest6(); | ||||
| @@ -644,7 +651,7 @@ public class DefaultConfigurerTest | |||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| fail(); | fail(); | ||||
| } | } | ||||
| catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
| @@ -675,7 +682,7 @@ public class DefaultConfigurerTest | |||||
| final ConfigTest3 test = new ConfigTest3(); | final ConfigTest3 test = new ConfigTest3(); | ||||
| // Configure the object | // Configure the object | ||||
| m_configurer.configure( test, config, m_context ); | |||||
| m_configurer.configure( test, config, m_adaptor ); | |||||
| // Test expected value | // Test expected value | ||||
| final ConfigTest3 expected = new ConfigTest3(); | final ConfigTest3 expected = new ConfigTest3(); | ||||
| @@ -15,6 +15,7 @@ import org.apache.myrmidon.interfaces.deployer.Deployer; | |||||
| import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | 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.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.type.TypeFactory; | import org.apache.myrmidon.interfaces.type.TypeFactory; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
| @@ -32,6 +33,7 @@ public class DefaultDeployerTest | |||||
| { | { | ||||
| private static final String TEST_TYPE1_NAME = "test-type1"; | private static final String TEST_TYPE1_NAME = "test-type1"; | ||||
| private static final String DATA_TYPE_ROLE = "data-type"; | private static final String DATA_TYPE_ROLE = "data-type"; | ||||
| private static final String CONVERTER_ROLE = "converter"; | |||||
| private Deployer m_deployer; | private Deployer m_deployer; | ||||
| private RoleManager m_roleManager; | private RoleManager m_roleManager; | ||||
| @@ -54,8 +56,8 @@ public class DefaultDeployerTest | |||||
| // Add some core roles | // Add some core roles | ||||
| m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | ||||
| m_roleManager.addNameRoleMapping( DATA_TYPE_ROLE, DataType.ROLE ); | |||||
| m_roleManager.addNameRoleMapping( "converter", Converter.ROLE ); | |||||
| m_roleManager.addRole( new RoleInfo( DataType.ROLE, DATA_TYPE_ROLE, DataType.class ) ); | |||||
| m_roleManager.addRole( new RoleInfo( Converter.ROLE, CONVERTER_ROLE, Converter.class ) ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,182 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.myrmidon.components.role; | |||||
| import org.apache.myrmidon.AbstractMyrmidonTest; | |||||
| import org.apache.myrmidon.api.Task; | |||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| import org.apache.myrmidon.interfaces.role.RoleInfo; | |||||
| import org.apache.myrmidon.interfaces.role.RoleException; | |||||
| import org.apache.avalon.excalibur.i18n.Resources; | |||||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
| /** | |||||
| * Test cases for the DefaultRoleManager. | |||||
| * | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @version $Revision$ $Date$ | |||||
| */ | |||||
| public class DefaultRoleManagerTest | |||||
| extends AbstractMyrmidonTest | |||||
| { | |||||
| private final static Resources REZ | |||||
| = ResourceManager.getPackageResources( DefaultRoleManagerTest.class ); | |||||
| private RoleManager m_roleManager; | |||||
| public DefaultRoleManagerTest( String name ) | |||||
| { | |||||
| super( name ); | |||||
| } | |||||
| protected void setUp() throws Exception | |||||
| { | |||||
| m_roleManager = new DefaultRoleManager(); | |||||
| } | |||||
| /** | |||||
| * Tests looking up a role by name, shorthand and type. | |||||
| */ | |||||
| public void testLookup() throws Exception | |||||
| { | |||||
| final String roleName = "role-name"; | |||||
| final String shorthand = "role-shorthand"; | |||||
| final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
| m_roleManager.addRole( origRole ); | |||||
| // Lookup the role | |||||
| RoleInfo role = m_roleManager.getRole( roleName ); | |||||
| assertTrue( origRole.equals(role) ); | |||||
| // Lookup the role by shorthand | |||||
| role = m_roleManager.getRoleByShorthandName( shorthand ); | |||||
| assertTrue( origRole.equals( role ) ); | |||||
| // Lookup the role by type | |||||
| role = m_roleManager.getRoleByType( Task.class ); | |||||
| assertTrue( origRole.equals( role ) ); | |||||
| // Lookup an unknown role | |||||
| RoleInfo unknownRole = m_roleManager.getRole( "unknown" ); | |||||
| assertNull( unknownRole ); | |||||
| // Lookup an unknown shorthand | |||||
| unknownRole = m_roleManager.getRoleByShorthandName( "unknown" ); | |||||
| assertNull( unknownRole ); | |||||
| // Lookup an unknown role | |||||
| unknownRole = m_roleManager.getRoleByType( DefaultRoleManagerTest.class ); | |||||
| assertNull( unknownRole ); | |||||
| } | |||||
| /** | |||||
| * Tests inheriting roles from parent role manager. | |||||
| */ | |||||
| public void testParent() throws Exception | |||||
| { | |||||
| final String roleName = "role-name"; | |||||
| final String shorthand = "shorthand"; | |||||
| final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
| m_roleManager.addRole( origRole ); | |||||
| final RoleManager roleManager = new DefaultRoleManager( m_roleManager ); | |||||
| // Lookup by name | |||||
| RoleInfo roleInfo = roleManager.getRole( roleName ); | |||||
| assertTrue( origRole.equals( roleInfo ) ); | |||||
| // Lookup by shorthand | |||||
| roleInfo = roleManager.getRoleByShorthandName( shorthand ); | |||||
| assertTrue( origRole.equals( roleInfo ) ); | |||||
| // Lookup by type | |||||
| roleInfo = roleManager.getRoleByType( Task.class ); | |||||
| assertTrue( origRole.equals( roleInfo ) ); | |||||
| } | |||||
| /** | |||||
| * Tests overriding a role in a child role manager. | |||||
| */ | |||||
| public void testOverrideName() throws Exception | |||||
| { | |||||
| final String roleName = "role-name"; | |||||
| final String shorthand = "shorthand"; | |||||
| // Add original role | |||||
| final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
| m_roleManager.addRole( origRole ); | |||||
| // Override role | |||||
| final RoleManager roleManager = new DefaultRoleManager( m_roleManager ); | |||||
| final RoleInfo overrideNameRole = new RoleInfo( roleName, "shorthand1" ); | |||||
| roleManager.addRole( overrideNameRole ); | |||||
| final RoleInfo overrideShorthandRole = new RoleInfo( "role2", shorthand ); | |||||
| roleManager.addRole( overrideShorthandRole ); | |||||
| final RoleInfo overrideTypeRole = new RoleInfo( "role3", "shorthand3", Task.class ); | |||||
| roleManager.addRole( overrideTypeRole ); | |||||
| // Lookup role by name | |||||
| RoleInfo roleInfo = roleManager.getRole( roleName ); | |||||
| assertTrue( overrideNameRole.equals( roleInfo ) ); | |||||
| // Lookup role by shorthand | |||||
| roleInfo = roleManager.getRoleByShorthandName( shorthand ); | |||||
| assertTrue( overrideShorthandRole.equals( roleInfo ) ); | |||||
| // Lookup role by type | |||||
| roleInfo = roleManager.getRoleByType( Task.class ); | |||||
| assertTrue( overrideTypeRole.equals( roleInfo ) ); | |||||
| } | |||||
| /** | |||||
| * Tests adding duplicate roles. | |||||
| */ | |||||
| public void testDuplicate() throws Exception | |||||
| { | |||||
| final String roleName = "role-name"; | |||||
| final String shorthand = "shorthand"; | |||||
| final RoleInfo origRole = new RoleInfo( roleName, shorthand, Task.class ); | |||||
| m_roleManager.addRole( origRole ); | |||||
| // Duplicate role name | |||||
| try | |||||
| { | |||||
| m_roleManager.addRole( new RoleInfo( roleName ) ); | |||||
| fail(); | |||||
| } | |||||
| catch( RoleException exc ) | |||||
| { | |||||
| final String message = REZ.getString( "duplicate-role.error", roleName ); | |||||
| assertSameMessage( message, exc ); | |||||
| } | |||||
| // Duplicate shorthand | |||||
| try | |||||
| { | |||||
| m_roleManager.addRole( new RoleInfo( "another-role", shorthand ) ); | |||||
| fail(); | |||||
| } | |||||
| catch( RoleException exc ) | |||||
| { | |||||
| final String message = REZ.getString( "duplicate-shorthand.error", shorthand ); | |||||
| assertSameMessage( message, exc ); | |||||
| } | |||||
| // Duplicate type | |||||
| try | |||||
| { | |||||
| m_roleManager.addRole( new RoleInfo( null, Task.class ) ); | |||||
| fail(); | |||||
| } | |||||
| catch( RoleException exc ) | |||||
| { | |||||
| final String message = REZ.getString( "duplicate-type.error", Task.class.getName() ); | |||||
| assertSameMessage( message, exc ); | |||||
| } | |||||
| } | |||||
| } | |||||