SPRNET-1279 Create integration test project for NMS

(run tests in standard nunit - without ncover as it hangs with ncover)
This commit is contained in:
markpollack
2009-12-08 03:04:54 +00:00
parent 5e9f148982
commit 41b8c4091c
11 changed files with 328 additions and 6 deletions

View File

@@ -432,12 +432,12 @@ Commandline Examples:
<nant buildfile="src/Spring/Spring.Template.Velocity/Spring.Template.Velocity.build" target="build" if="${build-velocity}"/>
<!-- test assemblies -->
<nant buildfile="test/Spring/Spring.Core.Tests/Spring.Core.Tests.build" target="test"/>
<nant buildfile="test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.build" target="test" if="${build-aop}"/>
<nant buildfile="test/Spring/Spring.Data.Tests/Spring.Data.Tests.build" target="test" if="${build-data}"/>
<!--
<nant buildfile="test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.build" target="test" if="${build-data}"/>
<!-- nant buildfile="test/Spring/Spring.Data.NHibernate12.Tests/Spring.Data.NHibernate12.Tests.build" target="test" if="${build-data and (nant.settings.currentframework == 'net-1.1' or nant.settings.currentframework == 'net-2.0')}"/ -->
<!-- nant buildfile="test/Spring/Spring.Data.NHibernate12.Integration.Tests/Spring.Data.NHibernate12.Integration.Tests.build" target="test" if="${build-data and (nant.settings.currentframework == 'net-1.1' or nant.settings.currentframework == 'net-2.0')}"/ -->
<nant buildfile="test/Spring/Spring.Data.NHibernate20.Tests/Spring.Data.NHibernate20.Tests.build" target="test"
if="${build-data and nant.settings.currentframework == 'net-2.0'}"/>
<nant buildfile="test/Spring/Spring.Data.NHibernate20.Integration.Tests/Spring.Data.NHibernate20.Integration.Tests.build" target="test"
@@ -456,15 +456,19 @@ Commandline Examples:
<nant buildfile="test/Spring/Spring.Testing.Microsoft.Tests/Spring.Testing.Microsoft.Tests.build" target="test" if="${build-testing-microsoft and nant.settings.currentframework == 'net-2.0'}"/>
<nant buildfile="test/Spring/Spring.Messaging.Ems.Tests/Spring.Messaging.Ems.Tests.build" target="test" if="${build-ems and (nant.settings.currentframework == 'net-2.0') and not net-3.0}"/>
<nant buildfile="test/Spring/Spring.Messaging.Ems.Integration.Tests/Spring.Messaging.Ems.Integration.Tests.build" target="test" if="${build-ems and (nant.settings.currentframework == 'net-2.0') and not net-3.0}"/>
-->
<nant buildfile="test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.build" target="test" if="${build-nms}"/>
<nant buildfile="test/Spring/Spring.Messaging.Nms.Integration.Tests/Spring.Messaging.Nms.Integration.Tests.build" target="test" if="${build-nms}"/>
<nant buildfile="test/Spring/Spring.Scheduling.Quartz.Tests/Spring.Scheduling.Quartz.Tests.build" target="build" if="${build-quartz}"/>
<nant buildfile="test/Spring/Spring.Messaging.Tests/Spring.Messaging.Tests.build" target="test" if="${build-msmq}"/>
<nant buildfile="test/Spring/Spring.Template.Velocity.Tests/Spring.Template.Velocity.Tests.build" target="test" if="${build-velocity}"/>
<!-- build examples -->
<!--
<nant buildfile="examples/Spring/Spring.Examples.build" target="build" if="${build-examples}"/>
-->
<!-- build coverage summary -->
<!-- build coverage summary -->
<exec program="${tool.dir}/ncoverexplorer/ncoverexplorer.console.exe" workingdir="${current.bin.dir}" failonerror="false">
<arg value="/xml:&quot;${current.bin.dir}/TestCoverageSummary.xml&quot;" />
<arg value="/report:ModuleClassFunctionSummary" />

View File

@@ -189,6 +189,7 @@ ${tool.dir} : dir for tools
-->
<call target="common.run-tests.ncover" />
</target>
<!--

View File

@@ -0,0 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("Spring.Messaging.Nms Integration Tests")]
[assembly: AssemblyDescription("Integration tests for Spring.Messaging.Nms assembly")]

View File

@@ -31,6 +31,8 @@ namespace Spring.Messaging.Nms.Core
protected IConnectionFactory connectionFactory;
protected NmsTemplate nmsTemplate;
/// <summary>
/// Default constructor for NmsTemplateTests.
/// </summary>
@@ -39,11 +41,33 @@ namespace Spring.Messaging.Nms.Core
this.PopulateProtectedVariables = true;
}
[Test]
public void SendAndReceive()
public void ConvertAndSend()
{
Assert.NotNull(nmsConnectionFactory);
Assert.NotNull(connectionFactory);
Assert.NotNull(connectionFactory);
Assert.NotNull(nmsTemplate);
string msgText = "Hello World";
//Use with destination set at runtime
nmsTemplate.ConvertAndSend("APP.TESTING", msgText);
AssertRecievedHelloWorldMessage(msgText, nmsTemplate.ReceiveAndConvert("APP.TESTING"));
//Now using default destination set via property
nmsTemplate.DefaultDestinationName = "APP.TESTING";
nmsTemplate.ConvertAndSend(msgText);
AssertRecievedHelloWorldMessage(msgText, nmsTemplate.ReceiveAndConvert());
}
private void AssertRecievedHelloWorldMessage(string msgText, object message)
{
Assert.NotNull(message);
string text = message as string;
Assert.NotNull(text);
Assert.AreEqual(msgText, text);
}
#region Overrides of AbstractDependencyInjectionSpringContextTests

View File

@@ -18,4 +18,8 @@
</property>
</object>
<object id="nmsTemplate" type="Spring.Messaging.Nms.Core.NmsTemplate, Spring.Messaging.Nms">
<property name="ConnectionFactory" ref="connectionFactory" />
</object>
</objects>

View File

@@ -0,0 +1,57 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Collections;
using Apache.NMS;
namespace Spring.Messaging.Nms.Core
{
public class SimpleGateway: NmsGatewaySupport
{
public void Publish(string ticker, double price)
{
NmsTemplate.SendWithDelegate("APP.STOCK.MARKETDATA",
delegate(ISession session)
{
IMapMessage message = session.CreateMapMessage();
message.Body.SetString("TICKER", ticker);
message.Body.SetDouble("PRICE", price);
message.NMSPriority = MsgPriority.Normal;
return message;
});
}
public void PublishUsingDict(string ticker, double price)
{
IDictionary marketData = new Hashtable();
marketData.Add("TICKER", ticker);
marketData.Add("PRICE", price);
NmsTemplate.ConvertAndSendWithDelegate("APP.STOCK.MARKETDATA", marketData,
delegate(IMessage message)
{
message.NMSPriority = MsgPriority.Normal;
message.NMSCorrelationID = new Guid().ToString();
return message;
});
}
}
}

View File

@@ -0,0 +1,58 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using Apache.NMS;
using Common.Logging;
namespace Spring.Messaging.Nms.Core
{
public class SimpleMessageListener : IMessageListener
{
private static readonly ILog LOG = LogManager.GetLogger(typeof(SimpleMessageListener));
private int messageCount;
public int MessageCount
{
get { return messageCount; }
}
#region Implementation of IMessageListener
public void OnMessage(IMessage message)
{
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
ITextMessage textMessage = message as ITextMessage;
if (textMessage != null)
{
LOG.Info("Message Text = " + textMessage.Text);
}
else
{
LOG.Warn("Can not process message of type " + message.GetType());
}
}
#endregion
}
}

View File

@@ -0,0 +1,68 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System.Threading;
using NUnit.Framework;
using Spring.Messaging.Nms.Core;
using Spring.Testing.NUnit;
namespace Spring.Messaging.Nms.Listener
{
[TestFixture]
public class SimpleMessageListenerContainerTests : AbstractDependencyInjectionSpringContextTests
{
protected SimpleGateway simpleGateway;
protected SimpleMessageListener simpleMessageListener;
/// <summary>
/// Enable DI based on protected field names
/// </summary>
public SimpleMessageListenerContainerTests()
{
this.PopulateProtectedVariables = true;
}
[Test]
public void SendAndRecieveAsync()
{
Assert.NotNull(simpleGateway);
Assert.NotNull(simpleMessageListener);
Assert.AreEqual(0, simpleMessageListener.MessageCount);
simpleGateway.Publish("CSCO", 123.45);
Thread.Sleep(1000);
Assert.AreEqual(1, simpleMessageListener.MessageCount);
}
#region Overrides of AbstractDependencyInjectionSpringContextTests
protected override string[] ConfigLocations
{
get { return new string[] { "assembly://Spring.Messaging.Nms.Integration.Tests/Spring.Messaging.Nms.Listener/SimpleMessageListenerContainerTests.xml" }; }
}
#endregion
}
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:nms="http://www.springframework.net/nms">
<!-- the default ConnectionFactory -->
<object id="nmsConnectionFactory" type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
<constructor-arg index="0" value="tcp://localhost:61616"/>
</object>
<object id="connectionFactory" type="Spring.Messaging.Nms.Connections.CachingConnectionFactory, Spring.Messaging.Nms">
<property name="SessionCacheSize" value="10" />
<property name="TargetConnectionFactory">
<object type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
<constructor-arg index="0" value="tcp://localhost:61616"/>
</object>
</property>
</object>
<!-- Send messages -->
<object id="simpleGateway" type="Spring.Messaging.Nms.Core.SimpleGateway, Spring.Messaging.Nms.Integration.Tests">
<property name="ConnectionFactory" ref="connectionFactory" />
</object>
<!-- Listener Infrastructure -->
<nms:listener-container connection-factory="connectionFactory" concurrency="10">
<nms:listener ref="simpleMessageListener" destination="APP.STOCK.MARKETDATA" />
</nms:listener-container>
<!-- POCO based message processing -->
<object name="simpleMessageListener"
type="Spring.Messaging.Nms.Core.SimpleMessageListener, Spring.Messaging.Nms.Integration.Tests"/>
</objects>

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" ?>
<project name="Spring.Messaging.Nms.Integration.Tests" default="test" xmlns="http://nant.sf.net/schemas/nant.xsd">
<include buildfile="${spring.basedir}/common-project.include" />
<!--
Required properties:
* current.bin.dir - (path) root level to build to
* current.build.debug - (true|false) debug build?
* current.build.defines.csc - framework-specific build defines for C# compiler
-->
<target name="build">
<!-- build Spring.Messaging.Nms.Integration.Tests -->
<csc target="library" define="${current.build.defines.csc}"
warnaserror="true"
optimize="${build.optimize}"
debug="${current.build.debug}"
output="${current.bin.dir}/${project::get-name()}.dll"
doc="${current.bin.dir}/${project::get-name()}.xml">
<nowarn>
<warning number="${nowarn.numbers.test}" />
</nowarn>
<sources failonempty="true">
<include name="../Spring.Messaging.Nms.Integration.Tests/**/*.cs" />
<include name="**/*.cs" />
<exclude name="AssemblyInfo.cs" />
</sources>
<references basedir="${current.bin.dir}">
<include name="System.Data.dll" />
<include name="System.EnterpriseServices.dll" />
<include name="*.dll" />
<include name="Spring.Messaging.Nms.dll" />
</references>
<resources prefix="Spring" dynamicprefix="true" failonempty="true">
<include name="**/*.xml" />
<include name="**/*.sql" />
</resources>
<resources prefix="Spring" dynamicprefix="true" basedir="../Spring.Data.NHibernate.Integration.Tests" failonempty="true">
<include name="**/*.sql" />
</resources>
</csc>
<copy file="${project::get-base-directory()}/${project::get-name()}.dll.config"
tofile="${current.bin.dir}/${project::get-name()}.dll.config"/>
<copy todir="${current.bin.dir}" overwrite="true">
<fileset basedir="${project::get-base-directory()}">
<include name="Spring.Messaging.Nms.Integration.Tests.dll.config" />
</fileset>
</copy>
</target>
<target name="test" depends="build">
<property name="test.assemblyfile" value="${project::get-name()}.dll" />
<call target="common.run-tests.nunit" if="${test.integration.nms}" />
</target>
</project>

View File

@@ -62,6 +62,9 @@
</Compile>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Messaging\Nms\Core\NmsTemplateTests.cs" />
<Compile Include="Messaging\Nms\Core\SimpleGateway.cs" />
<Compile Include="Messaging\Nms\Core\SimpleMessageListener.cs" />
<Compile Include="Messaging\Nms\Listener\SimpleMessageListenerContainerTests.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Messaging\Nms\Core\NmsTemplateTests.xml" />
@@ -84,6 +87,9 @@
<Name>Spring.Core.Tests.2008</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Messaging\Nms\Listener\SimpleMessageListenerContainerTests.xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>