fixed SPRNET-1251

This commit is contained in:
eeichinger
2009-09-03 22:37:02 +00:00
parent 9fe54d243c
commit 51419efa67
4 changed files with 116 additions and 25 deletions

View File

@@ -22,33 +22,52 @@
using System;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Aop.Framework;
using Spring.Core.IO;
using Spring.Objects;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Xml;
#endregion
namespace Spring.Remoting
{
/// <summary>
/// Unit tests for the SaoExporter class.
/// </summary>
/// <author>Bruno Baia</author>
/// <author>Mark Pollack</author>
[TestFixture]
public class SaoExporterTests : BaseRemotingTestFixture
{
/// <summary>
/// Unit tests for the SaoExporter class.
/// </summary>
/// <author>Bruno Baia</author>
/// <author>Mark Pollack</author>
[TestFixture]
public class SaoExporterTests : BaseRemotingTestFixture
{
[Test]
[ExpectedException(typeof(ArgumentException))]
public void BailsWhenNotConfigured ()
{
SaoExporter exp = new SaoExporter();
exp.AfterPropertiesSet();
}
[ExpectedException(typeof(ArgumentException))]
public void BailsWhenNotConfigured()
{
SaoExporter exp = new SaoExporter();
exp.AfterPropertiesSet();
}
[Test]
[ExpectedException(typeof(NoSuchObjectDefinitionException))]
public void BailsIfTargetNotFound()
{
using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
{
SaoExporter saoExporter = new SaoExporter();
saoExporter.ObjectFactory = of;
saoExporter.TargetName = "DOESNOTEXIST";
saoExporter.ServiceName = "RemotedSaoSingletonCounter";
saoExporter.AfterPropertiesSet();
}
}
[Test]
public void ExportSingleton()
{
using(DefaultListableObjectFactory of = new DefaultListableObjectFactory())
using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
{
of.RegisterSingleton("simpleCounter", new SimpleCounter());
SaoExporter saoExporter = new SaoExporter();
@@ -58,7 +77,7 @@ namespace Spring.Remoting
saoExporter.AfterPropertiesSet();
of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()!
ISimpleCounter client = (ISimpleCounter) Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoSingletonCounter" );
ISimpleCounter client = (ISimpleCounter)Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoSingletonCounter");
client.Count();
client.Count();
@@ -69,7 +88,7 @@ namespace Spring.Remoting
[Test]
public void ExportSingleCall()
{
using(DefaultListableObjectFactory of = new DefaultListableObjectFactory())
using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
{
of.RegisterObjectDefinition("simpleCounter", new RootObjectDefinition(typeof(SimpleCounter), false));
SaoExporter saoExporter = new SaoExporter();
@@ -79,11 +98,62 @@ namespace Spring.Remoting
saoExporter.AfterPropertiesSet();
of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()!
ISimpleCounter client = (ISimpleCounter) Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoSingleCallCounter" );
ISimpleCounter client = (ISimpleCounter)Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoSingleCallCounter");
client.Count();
client.Count();
Assert.AreEqual(0, client.Counter);
}
}
}
/// <summary>
/// Checks that exp an IFactoryObject.ObjectType returns an interface type,
/// </summary>
[Test(Description = "http://jira.springframework.org/browse/SPRNET-1251")]
public void CanExportFromInterfaceTargetType()
{
using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
{
MockRepository mocks = new MockRepository();
IFactoryObject simpleCounterFactory = (IFactoryObject) mocks.DynamicMock(typeof (IFactoryObject));
Expect.Call(simpleCounterFactory.ObjectType).Return(typeof (ISimpleCounter));
Expect.Call(simpleCounterFactory.IsSingleton).Return(true);
Expect.Call(simpleCounterFactory.GetObject()).Return(new SimpleCounter());
mocks.ReplayAll();
of.RegisterSingleton("simpleCounter", simpleCounterFactory);
SaoExporter saoExporter = new SaoExporter();
saoExporter.ObjectFactory = of;
saoExporter.TargetName = "simpleCounter";
saoExporter.ServiceName = "RemotedSaoCallCounter";
saoExporter.AfterPropertiesSet();
// XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
// reader.LoadObjectDefinitions(new StringResource(
// @"<?xml version='1.0' encoding='UTF-8' ?>
//<objects xmlns='http://www.springframework.net' xmlns:r='http://www.springframework.net/remoting'>
//
// <r:saoExporter id='ISimpleCounterExporter' targetName='ISimpleCounterProxy' serviceName='RemotedSaoCounterProxy' />
//
// <object id='ISimpleCounter' type='Spring.Remoting.SimpleCounter, Spring.Services.Tests' />
//
// <object id='ISimpleCounterProxy' type='Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop'>
// <property name='proxyInterfaces' value='Spring.Remoting.ISimpleCounter' />
// <property name='target' ref='ISimpleCounter'/>
// </object>
//</objects>
//"));
// SaoExporter saoExporter = (SaoExporter) of.GetObject("ISimpleCounterExporter");
// Assert.IsNotNull(saoExporter);
ISimpleCounter client = (ISimpleCounter)Activator.GetObject(typeof(ISimpleCounter), "tcp://localhost:8005/RemotedSaoCallCounter");
client.Count();
client.Count();
Assert.AreEqual(2, client.Counter);
mocks.VerifyAll();
}
}
}
}