SPRNET-1280 - Create integration test project for TIBCO EMS

This commit is contained in:
markpollack
2009-12-07 22:22:38 +00:00
parent 6e10b8b9ca
commit 13d4e32b61
6 changed files with 179 additions and 2 deletions

View File

@@ -34,6 +34,7 @@ using Spring.Messaging.Ems.Listener;
using Spring.Objects.Factory.Xml;
using Spring.Testing.NUnit;
using TIBCO.EMS;
using TIBCO.EMS.ADMIN;
#endregion
@@ -51,23 +52,84 @@ namespace Spring.Messaging.Ems.Core
protected IConnectionFactory cachingJndiConnectionFactory;
protected EmsTemplate emsTemplate;
protected SimpleGateway simpleGateway;
private Admin admin;
private string queueName = "INT_TEST_QUEUE";
private Hashtable env = new Hashtable();
private LookupContext lookupContext;
/// <summary>
/// Default constructor for EmsTemplateTests.
/// </summary>
public EmsTemplateTests()
{
this.PopulateProtectedVariables = true;
env.Add(LookupContext.PROVIDER_URL, "tibjmsnaming://localhost:7222");
env.Add(LookupContext.SECURITY_PRINCIPAL, "admin");
env.Add(LookupContext.SECURITY_CREDENTIALS, "");
lookupContext = new LookupContext(env);
}
protected override void OnSetUp()
{
admin = new Admin("tcp://localhost:7222", "admin", "");
Destination destination = (Destination)lookupContext.Lookup(queueName);
if (destination != null) admin.DestroyQueue(queueName);
admin.CreateQueue(new QueueInfo(queueName));
admin.BindQueue(queueName, queueName);
admin.PurgeQueue(queueName);
}
[Test]
public void SendAndReceive()
public void ConvertAndSend()
{
Assert.NotNull(emsConnectionFactory);
Assert.NotNull(connectionFactory);
Assert.NotNull(jndiEmsConnectionFactory);
Assert.NotNull(cachingJndiConnectionFactory);
Assert.NotNull(emsTemplate);
string msgText = "Hello World";
//Use with destination set at runtime
emsTemplate.ConvertAndSend("APP.TESTING", msgText);
AssertRecievedHelloWorldMessage(msgText, emsTemplate.ReceiveAndConvert("APP.TESTING"));
//Now using default destination set via property
emsTemplate.DefaultDestinationName = "APP.TESTING";
emsTemplate.ConvertAndSend(msgText);
AssertRecievedHelloWorldMessage(msgText, emsTemplate.ReceiveAndConvert());
//Now using destination oject
Destination destination = (Destination)lookupContext.Lookup(queueName);
emsTemplate.ConvertAndSend(destination, msgText);
AssertRecievedHelloWorldMessage(msgText, emsTemplate.ReceiveAndConvert(destination));
}
[Test]
public void SimpleMessageListenerContainer()
{
}
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

@@ -44,6 +44,10 @@
<property name="ConnectionFactory" ref="connectionFactory" />
</object>
<object id="emsTemplate" type="Spring.Messaging.Ems.Core.EmsTemplate, Spring.Messaging.Ems">
<property name="ConnectionFactory" ref="connectionFactory" />
</object>
<object id="cachingJndiConnectionFactory" type="Spring.Messaging.Ems.Connections.CachingConnectionFactory, Spring.Messaging.Ems">
<property name="SessionCacheSize" value="10" />

View File

@@ -8,7 +8,7 @@ namespace Spring.Messaging.Ems.Core
public class SimpleGateway : EmsGatewaySupport
{
public void Publish(string ticker, double price)
{
{
EmsTemplate.SendWithDelegate("APP.STOCK.MARKETDATA",
delegate(ISession session)
{

View File

@@ -0,0 +1,69 @@
#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.Ems.Core;
using Spring.Testing.NUnit;
namespace Spring.Messaging.Ems.Listener
{
/// <summary>
/// Integration tests for SimpleMessageListenerContainer
/// </summary>
/// <author>Mark Pollack </author>
[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.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.Ems.Integration.Tests/Spring.Messaging.Ems.Listener/SimpleMessageListenerContainerTests.xml" }; }
}
#endregion
}
}

View File

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

View File

@@ -48,6 +48,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\TIBCO.EMS.dll</HintPath>
</Reference>
<Reference Include="TIBCO.EMS.ADMIN, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5b83db8ff05c64ba, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\TIBCO.EMS.ADMIN.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
@@ -60,6 +64,7 @@
<Compile Include="Messaging\Ems\Core\SimpleGateway.cs" />
<Compile Include="Messaging\Ems\Core\SimpleMessageListener.cs" />
<Compile Include="Messaging\Ems\Core\SimplePublisher.cs" />
<Compile Include="Messaging\Ems\Listener\SimpleMessageListenerContainerTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spring\Spring.Aop\Spring.Aop.2008.csproj">
@@ -96,6 +101,9 @@
<ItemGroup>
<EmbeddedResource Include="Messaging\Ems\Config\EmsNamespaceHandlerTests.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Messaging\Ems\Listener\SimpleMessageListenerContainerTests.xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>