resolved SPRNET-1086
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
@@ -101,6 +102,8 @@ namespace Spring.Objects.Factory.Support
|
||||
protected AbstractObjectDefinition(IObjectDefinition other)
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(other, "other");
|
||||
this.OverrideFrom(other);
|
||||
|
||||
AbstractObjectDefinition aod = other as AbstractObjectDefinition;
|
||||
if (aod != null)
|
||||
{
|
||||
@@ -668,22 +671,18 @@ namespace Spring.Objects.Factory.Support
|
||||
/// </param>
|
||||
public virtual void OverrideFrom(IObjectDefinition other)
|
||||
{
|
||||
AbstractObjectDefinition aod = other as AbstractObjectDefinition;
|
||||
if (aod != null)
|
||||
{
|
||||
if (aod.HasObjectType)
|
||||
{
|
||||
ObjectType = other.ObjectType;
|
||||
}
|
||||
MethodOverrides.AddAll(aod.MethodOverrides);
|
||||
DependencyCheck = aod.DependencyCheck;
|
||||
}
|
||||
AssertUtils.ArgumentNotNull(other, "other");
|
||||
|
||||
IsAbstract = other.IsAbstract;
|
||||
IsSingleton = other.IsSingleton;
|
||||
IsLazyInit = other.IsLazyInit;
|
||||
ConstructorArgumentValues.AddAll(other.ConstructorArgumentValues);
|
||||
PropertyValues.AddAll(other.PropertyValues.PropertyValues);
|
||||
EventHandlerValues.AddAll(other.EventHandlerValues);
|
||||
if (StringUtils.HasText(other.ObjectTypeName))
|
||||
{
|
||||
ObjectTypeName = other.ObjectTypeName;
|
||||
}
|
||||
if (StringUtils.HasText(other.InitMethodName))
|
||||
{
|
||||
InitMethodName = other.InitMethodName;
|
||||
@@ -700,10 +699,29 @@ namespace Spring.Objects.Factory.Support
|
||||
{
|
||||
FactoryMethodName = other.FactoryMethodName;
|
||||
}
|
||||
DependsOn = new string[other.DependsOn.Length];
|
||||
Array.Copy(other.DependsOn, DependsOn, other.DependsOn.Length);
|
||||
if (ArrayUtils.HasLength(other.DependsOn))
|
||||
{
|
||||
ArrayList deps = new ArrayList(other.DependsOn);
|
||||
if (ArrayUtils.HasLength(DependsOn))
|
||||
{
|
||||
deps.AddRange(DependsOn);
|
||||
}
|
||||
DependsOn = (string[]) deps.ToArray(typeof(string));
|
||||
}
|
||||
AutowireMode = other.AutowireMode;
|
||||
ResourceDescription = other.ResourceDescription;
|
||||
|
||||
AbstractObjectDefinition aod = other as AbstractObjectDefinition;
|
||||
if (aod != null)
|
||||
{
|
||||
if (aod.HasObjectType)
|
||||
{
|
||||
ObjectType = other.ObjectType;
|
||||
}
|
||||
|
||||
MethodOverrides.AddAll(aod.MethodOverrides);
|
||||
DependencyCheck = aod.DependencyCheck;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -31,96 +31,165 @@ using NUnit.Framework;
|
||||
|
||||
namespace Spring.Objects.Factory.Support
|
||||
{
|
||||
/// <summary>
|
||||
/// Unit tests for the RootObjectDefinition class.
|
||||
/// <summary>
|
||||
/// Unit tests for the RootObjectDefinition class.
|
||||
/// </summary>
|
||||
/// <author>Rick Evans</author>
|
||||
[TestFixture]
|
||||
[TestFixture]
|
||||
public sealed class RootObjectDefinitionTests
|
||||
{
|
||||
[Test]
|
||||
[ExpectedException (typeof (ApplicationException))]
|
||||
public void InstantiationWithClassName ()
|
||||
[ExpectedException( typeof( ApplicationException ) )]
|
||||
public void InstantiationWithClassName()
|
||||
{
|
||||
RootObjectDefinition def
|
||||
= new RootObjectDefinition (typeof (TestObject).AssemblyQualifiedName, new ConstructorArgumentValues (), new MutablePropertyValues ());
|
||||
Assert.IsFalse (def.HasObjectType);
|
||||
Assert.IsNull (def.ObjectType); // must bail...
|
||||
= new RootObjectDefinition( typeof( TestObject ).AssemblyQualifiedName, new ConstructorArgumentValues(), new MutablePropertyValues() );
|
||||
Assert.IsFalse( def.HasObjectType );
|
||||
Assert.IsNull( def.ObjectType ); // must bail...
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InstantiationFromOther () {
|
||||
public void InstantiationFromOther()
|
||||
{
|
||||
RootObjectDefinition other
|
||||
= new RootObjectDefinition (typeof (TestObject), AutoWiringMode.Constructor);
|
||||
= new RootObjectDefinition( typeof( TestObject ), AutoWiringMode.Constructor );
|
||||
other.IsSingleton = false;
|
||||
other.InitMethodName = "Umberto Eco";
|
||||
other.DestroyMethodName = "Pedulismus";
|
||||
other.ConstructorArgumentValues = new ConstructorArgumentValues ();
|
||||
other.ConstructorArgumentValues = new ConstructorArgumentValues();
|
||||
other.DependencyCheck = DependencyCheckingMode.Objects;
|
||||
other.DependsOn = new string [] {"Jimmy", "Joyce"};
|
||||
other.EventHandlerValues = new EventValues ();
|
||||
other.DependsOn = new string[] { "Jimmy", "Joyce" };
|
||||
other.EventHandlerValues = new EventValues();
|
||||
other.IsAbstract = true;
|
||||
other.IsLazyInit = true;
|
||||
other.FactoryMethodName = "IfINeedYouIllJustUseYourSimpleName";
|
||||
other.FactoryObjectName = "PerspirationShop";
|
||||
other.ResourceDescription = "Ohhh";
|
||||
other.PropertyValues = new MutablePropertyValues ();
|
||||
other.PropertyValues.Add ("Age", 100);
|
||||
other.PropertyValues = new MutablePropertyValues();
|
||||
other.PropertyValues.Add( "Age", 100 );
|
||||
InstanceEventHandlerValue handler =
|
||||
new InstanceEventHandlerValue (new TestObject (), "Ping");
|
||||
new InstanceEventHandlerValue( new TestObject(), "Ping" );
|
||||
handler.EventName = "Bing";
|
||||
other.EventHandlerValues.AddHandler (handler);
|
||||
other.ConstructorArgumentValues.AddGenericArgumentValue ("Wulf", "Sternhammer");
|
||||
other.EventHandlerValues.AddHandler( handler );
|
||||
other.ConstructorArgumentValues.AddGenericArgumentValue( "Wulf", "Sternhammer" );
|
||||
|
||||
RootObjectDefinition def = new RootObjectDefinition (other);
|
||||
RootObjectDefinition def = new RootObjectDefinition( other );
|
||||
|
||||
// ...
|
||||
Assert.AreEqual (typeof (TestObject), def.ObjectType);
|
||||
Assert.AreEqual (AutoWiringMode.Constructor, def.AutowireMode);
|
||||
Assert.IsFalse (def.IsSingleton);
|
||||
Assert.AreEqual ("Umberto Eco", def.InitMethodName);
|
||||
Assert.AreEqual ("Pedulismus", def.DestroyMethodName);
|
||||
Assert.AreEqual (DependencyCheckingMode.Objects, def.DependencyCheck);
|
||||
Assert.IsTrue (def.IsAbstract);
|
||||
Assert.IsTrue (def.IsLazyInit);
|
||||
Assert.AreEqual ("IfINeedYouIllJustUseYourSimpleName", def.FactoryMethodName);
|
||||
Assert.AreEqual ("PerspirationShop", def.FactoryObjectName);
|
||||
Assert.AreEqual ("Ohhh", def.ResourceDescription);
|
||||
Assert.IsTrue (def.HasConstructorArgumentValues);
|
||||
Assert.AreEqual (other.ConstructorArgumentValues.ArgumentCount, def.ConstructorArgumentValues.ArgumentCount);
|
||||
Assert.AreEqual (other.PropertyValues.PropertyValues.Length, def.PropertyValues.PropertyValues.Length);
|
||||
Assert.AreEqual (other.EventHandlerValues.Events.Count, def.EventHandlerValues.Events.Count);
|
||||
Assert.AreEqual( typeof( TestObject ), def.ObjectType );
|
||||
Assert.AreEqual( AutoWiringMode.Constructor, def.AutowireMode );
|
||||
Assert.IsFalse( def.IsSingleton );
|
||||
Assert.AreEqual( "Umberto Eco", def.InitMethodName );
|
||||
Assert.AreEqual( "Pedulismus", def.DestroyMethodName );
|
||||
Assert.AreEqual( DependencyCheckingMode.Objects, def.DependencyCheck );
|
||||
Assert.IsTrue( def.IsAbstract );
|
||||
Assert.IsTrue( def.IsLazyInit );
|
||||
Assert.AreEqual( "IfINeedYouIllJustUseYourSimpleName", def.FactoryMethodName );
|
||||
Assert.AreEqual( "PerspirationShop", def.FactoryObjectName );
|
||||
Assert.AreEqual( "Ohhh", def.ResourceDescription );
|
||||
Assert.IsTrue( def.HasConstructorArgumentValues );
|
||||
Assert.AreEqual( other.ConstructorArgumentValues.ArgumentCount, def.ConstructorArgumentValues.ArgumentCount );
|
||||
Assert.AreEqual( other.PropertyValues.PropertyValues.Length, def.PropertyValues.PropertyValues.Length );
|
||||
Assert.AreEqual( other.EventHandlerValues.Events.Count, def.EventHandlerValues.Events.Count );
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (ObjectDefinitionValidationException))]
|
||||
public void ValidateLazyAndPrototypeCausesBail ()
|
||||
public void OverrideFromOther()
|
||||
{
|
||||
RootObjectDefinition def
|
||||
= new RootObjectDefinition (typeof (TestObject), AutoWiringMode.No);
|
||||
def.IsLazyInit = true;
|
||||
def.IsSingleton = false;
|
||||
def.Validate ();
|
||||
RootObjectDefinition rod = new RootObjectDefinition( typeof( TestObject ), AutoWiringMode.Constructor );
|
||||
rod.IsSingleton = false;
|
||||
rod.InitMethodName = "Umberto Eco";
|
||||
rod.DestroyMethodName = "Pedulismus";
|
||||
rod.ConstructorArgumentValues = new ConstructorArgumentValues();
|
||||
rod.ConstructorArgumentValues.AddGenericArgumentValue( "Wulf", "Sternhammer" );
|
||||
rod.DependencyCheck = DependencyCheckingMode.Objects;
|
||||
rod.DependsOn = new string[] { "Jimmy", "Joyce" };
|
||||
rod.IsAbstract = true;
|
||||
rod.IsLazyInit = true;
|
||||
rod.FactoryMethodName = "IfINeedYouIllJustUseYourSimpleName";
|
||||
rod.FactoryObjectName = "PerspirationShop";
|
||||
rod.ResourceDescription = "Ohhh";
|
||||
rod.PropertyValues = new MutablePropertyValues();
|
||||
rod.PropertyValues.Add( "Age", 100 );
|
||||
rod.EventHandlerValues = new EventValues();
|
||||
InstanceEventHandlerValue handler = new InstanceEventHandlerValue( new TestObject(), "Ping" );
|
||||
handler.EventName = "Bing";
|
||||
rod.EventHandlerValues.AddHandler( handler );
|
||||
|
||||
ChildObjectDefinition cod = new ChildObjectDefinition( "parent" );
|
||||
cod.ObjectTypeName = "ChildObjectTypeName";
|
||||
cod.IsSingleton = true;
|
||||
cod.AutowireMode = AutoWiringMode.ByType;
|
||||
cod.InitMethodName = "InitChild";
|
||||
cod.DestroyMethodName = "DestroyChild";
|
||||
cod.ConstructorArgumentValues = new ConstructorArgumentValues();
|
||||
cod.ConstructorArgumentValues.AddNamedArgumentValue( "ctorarg", "ctorarg-value" );
|
||||
cod.DependencyCheck = DependencyCheckingMode.None;
|
||||
cod.DependsOn = new string[] { "Aleks", "Mark" };
|
||||
cod.IsAbstract = false;
|
||||
cod.IsLazyInit = false;
|
||||
cod.FactoryMethodName = "ChildFactoryMethodName";
|
||||
cod.FactoryObjectName = "ChildFactoryObjectName";
|
||||
cod.ResourceDescription = "ChildResourceDescription";
|
||||
cod.PropertyValues = new MutablePropertyValues();
|
||||
cod.PropertyValues.Add( "Prop1", "Val1" );
|
||||
cod.PropertyValues.Add( "Age", 50 );
|
||||
cod.EventHandlerValues = new EventValues();
|
||||
handler = new InstanceEventHandlerValue( new TestObject(), "Pong" );
|
||||
handler.EventName = "Bong";
|
||||
cod.EventHandlerValues.AddHandler( handler );
|
||||
|
||||
rod.OverrideFrom( cod );
|
||||
|
||||
// ...
|
||||
Assert.AreEqual( "ChildObjectTypeName", rod.ObjectTypeName );
|
||||
Assert.AreEqual( AutoWiringMode.ByType, rod.AutowireMode );
|
||||
Assert.AreEqual( true, rod.IsSingleton );
|
||||
Assert.AreEqual( "InitChild", rod.InitMethodName );
|
||||
Assert.AreEqual( "DestroyChild", rod.DestroyMethodName );
|
||||
Assert.AreEqual( DependencyCheckingMode.None, rod.DependencyCheck );
|
||||
Assert.AreEqual( 4, rod.DependsOn.Length);
|
||||
Assert.AreEqual( false, rod.IsAbstract );
|
||||
Assert.AreEqual( false, rod.IsLazyInit );
|
||||
Assert.AreEqual( "ChildFactoryMethodName", rod.FactoryMethodName );
|
||||
Assert.AreEqual( "ChildFactoryObjectName", rod.FactoryObjectName );
|
||||
Assert.AreEqual( "ChildResourceDescription", rod.ResourceDescription );
|
||||
Assert.AreEqual( 2, rod.ConstructorArgumentValues.ArgumentCount );
|
||||
Assert.AreEqual( 2, rod.PropertyValues.PropertyValues.Length );
|
||||
Assert.AreEqual( "Val1", rod.PropertyValues.GetPropertyValue("Prop1").Value);
|
||||
Assert.AreEqual( 50, rod.PropertyValues.GetPropertyValue("Age").Value);
|
||||
Assert.AreEqual( 2, rod.EventHandlerValues.Events.Count );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InstantiationWithNullCtorArgsAndNullPropsDoesNotResultInNullPropertyValues()
|
||||
{
|
||||
RootObjectDefinition def
|
||||
= new RootObjectDefinition (typeof (TestObject), null, null);
|
||||
Assert.IsNotNull(def.ConstructorArgumentValues,
|
||||
"Must never be null, but rather just empty.");
|
||||
Assert.AreEqual(0, def.ConstructorArgumentValues.ArgumentCount,
|
||||
"Must be empty if null was passed to the ctor.");
|
||||
Assert.IsNotNull(def.PropertyValues,
|
||||
"Must never be null, but rather just empty.");
|
||||
Assert.AreEqual(0, def.PropertyValues.PropertyValues.Length,
|
||||
"Must be empty if null was passed to the ctor.");
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException( typeof( ObjectDefinitionValidationException ) )]
|
||||
public void ValidateLazyAndPrototypeCausesBail()
|
||||
{
|
||||
RootObjectDefinition def
|
||||
= new RootObjectDefinition( typeof( TestObject ), AutoWiringMode.No );
|
||||
def.IsLazyInit = true;
|
||||
def.IsSingleton = false;
|
||||
def.Validate();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InstantiationWithNullCtorArgsAndNullPropsDoesNotResultInNullPropertyValues()
|
||||
{
|
||||
RootObjectDefinition def
|
||||
= new RootObjectDefinition( typeof( TestObject ), null, null );
|
||||
Assert.IsNotNull( def.ConstructorArgumentValues,
|
||||
"Must never be null, but rather just empty." );
|
||||
Assert.AreEqual( 0, def.ConstructorArgumentValues.ArgumentCount,
|
||||
"Must be empty if null was passed to the ctor." );
|
||||
Assert.IsNotNull( def.PropertyValues,
|
||||
"Must never be null, but rather just empty." );
|
||||
Assert.AreEqual( 0, def.PropertyValues.PropertyValues.Length,
|
||||
"Must be empty if null was passed to the ctor." );
|
||||
}
|
||||
}
|
||||
|
||||
internal class NoPublicCtors
|
||||
internal class NoPublicCtors
|
||||
{
|
||||
protected NoPublicCtors () {}
|
||||
protected NoPublicCtors() { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user