TIBCO EMS Integration - SPRNET-982
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Messaging.Ems.Listener;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
using TIBCO.EMS;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Messaging.Ems.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id:$</version>
|
||||
[TestFixture]
|
||||
public class EmsNamespaceHandlerTests
|
||||
{
|
||||
|
||||
private static string DEFAULT_CONNECTION_FACTORY = "ConnectionFactory";
|
||||
|
||||
private static string EXPLICIT_CONNECTION_FACTORY = "testConnectionFactory";
|
||||
|
||||
|
||||
private IApplicationContext ctx;
|
||||
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
NamespaceParserRegistry.RegisterParser(typeof(EmsNamespaceParser));
|
||||
ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("EmsNamespaceHandlerTests.xml", GetType()));
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Registered()
|
||||
{
|
||||
Assert.IsNotNull(NamespaceParserRegistry.GetParser("http://www.springframework.net/ems"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ObjectsCreated()
|
||||
{
|
||||
IDictionary containers = ctx.GetObjectsOfType(typeof(SimpleMessageListenerContainer));
|
||||
Assert.AreEqual(3, containers.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContainerConfiguration()
|
||||
{
|
||||
IDictionary containers = ctx.GetObjectsOfType(typeof (SimpleMessageListenerContainer));
|
||||
ConnectionFactory defaultConnectionFactory = (ConnectionFactory) ctx.GetObject(DEFAULT_CONNECTION_FACTORY);
|
||||
ConnectionFactory explicitConnectionFactory = (ConnectionFactory) ctx.GetObject(EXPLICIT_CONNECTION_FACTORY);
|
||||
|
||||
|
||||
int defaultConnectionFactoryCount = 0;
|
||||
int explicitConnectionFactoryCount = 0;
|
||||
foreach (DictionaryEntry dictionaryEntry in containers)
|
||||
{
|
||||
SimpleMessageListenerContainer container = (SimpleMessageListenerContainer) dictionaryEntry.Value;
|
||||
if (container.ConnectionFactory.Equals(defaultConnectionFactory))
|
||||
{
|
||||
defaultConnectionFactoryCount++;
|
||||
}
|
||||
else if (container.ConnectionFactory.Equals(explicitConnectionFactory))
|
||||
{
|
||||
explicitConnectionFactoryCount++;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.AreEqual(1, defaultConnectionFactoryCount, "1 container should have the default connectionFactory");
|
||||
Assert.AreEqual(2, explicitConnectionFactoryCount, "2 containers should have the explicit connectionFactory");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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/ems">
|
||||
|
||||
<nms:listener-container connection-factory="testConnectionFactory"
|
||||
destination-resolver="testDestinationResolver" message-converter="testMessageConverter">
|
||||
<nms:listener id="listener1" destination="testDestination" ref="testObject1" method="SetName"/>
|
||||
<nms:listener id="listener2" destination="testDestination" ref="testObject2" method="SetName"
|
||||
response-destination="responseDestination"/>
|
||||
</nms:listener-container>
|
||||
|
||||
<nms:listener-container>
|
||||
<nms:listener destination="testDestination" ref="testObject3"/>
|
||||
</nms:listener-container>
|
||||
|
||||
|
||||
<!-- the default ConnectionFactory -->
|
||||
<object id="ConnectionFactory" type="TIBCO.EMS.ConnectionFactory, TIBCO.EMS"/>
|
||||
|
||||
<object id="testConnectionFactory" type="TIBCO.EMS.ConnectionFactory, TIBCO.EMS"/>
|
||||
|
||||
|
||||
<!--
|
||||
<bean id="testActivationSpecFactory" class="org.springframework.jms.listener.endpoint.StubJmsActivationSpecFactory"/>
|
||||
-->
|
||||
|
||||
<object id="testDestinationResolver" type="Spring.Messaging.Ems.Support.Destinations.DynamicDestinationResolver, Spring.Messaging.Ems"/>
|
||||
|
||||
<object id="testMessageConverter" type="Spring.Messaging.Ems.Support.Converter.SimpleMessageConverter, Spring.Messaging.Ems"/>
|
||||
|
||||
|
||||
<object id="testObject1" type="Spring.Objects.TestObject, Spring.Core.Tests"/>
|
||||
|
||||
<object id="testObject2" type="Spring.Objects.TestObject, Spring.Core.Tests"/>
|
||||
|
||||
<object id="testObject3" type="Spring.Messaging.Ems.Connections.TestMessageListener, Spring.Messaging.Ems.Tests"/>
|
||||
|
||||
</objects>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2008 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 TIBCO.EMS;
|
||||
|
||||
namespace Spring.Messaging.Ems.Connections
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <author>Mark Pollack</author>
|
||||
public class TestMessageListener : IMessageListener
|
||||
{
|
||||
private string message;
|
||||
|
||||
|
||||
public string Message
|
||||
{
|
||||
get { return message; }
|
||||
set { message = value; }
|
||||
}
|
||||
|
||||
#region IMessageListener Members
|
||||
|
||||
public void OnMessage(Message message)
|
||||
{
|
||||
this.message = "Test1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Common.Logging;
|
||||
using TIBCO.EMS;
|
||||
|
||||
namespace Spring.Messaging.Ems.Integration
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class LoggingExceptionHandler : IExceptionListener
|
||||
{
|
||||
#region Logging Definition
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof (LoggingExceptionHandler));
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IExceptionListener Members
|
||||
|
||||
public void OnException(EMSException e)
|
||||
{
|
||||
LOG.Error("Exception processing message", e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Common.Logging;
|
||||
using TIBCO.EMS;
|
||||
|
||||
namespace Spring.Messaging.Ems.Integration
|
||||
{
|
||||
public class SimpleMessageListener : IMessageListener
|
||||
{
|
||||
#region Logging Definition
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(SimpleMessageListener));
|
||||
#endregion
|
||||
|
||||
private Message lastReceivedMessage;
|
||||
private int messageCount;
|
||||
|
||||
public Message LastReceivedMessage
|
||||
{
|
||||
get { return lastReceivedMessage; }
|
||||
}
|
||||
|
||||
|
||||
public int MessageCount
|
||||
{
|
||||
get { return messageCount; }
|
||||
}
|
||||
|
||||
#region IMessageListener Members
|
||||
|
||||
public void OnMessage(Message message)
|
||||
{
|
||||
lastReceivedMessage = message;
|
||||
messageCount++;
|
||||
LOG.Debug("Message listener count = " + messageCount);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Spring.Messaging.Ems.Core;
|
||||
using Spring.Messaging.Ems.Listener;
|
||||
using Spring.Testing.NUnit;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Messaging.Ems.Integration
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains integration tests for the SimpleMessageListenerContainer
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id:$</version>
|
||||
[TestFixture]
|
||||
public class SimpleMessageListenerContainerTests : AbstractDependencyInjectionSpringContextTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
[Explicit]
|
||||
public void SendAndAsyncReceive()
|
||||
{
|
||||
SimpleMessageListenerContainer container =
|
||||
(SimpleMessageListenerContainer) applicationContext["SimpleMessageListenerContainer"];
|
||||
SimpleMessageListener listener = applicationContext["SimpleMessageListener"] as SimpleMessageListener;
|
||||
Assert.IsNotNull(container);
|
||||
Assert.IsNotNull(listener);
|
||||
|
||||
|
||||
EmsTemplate emsTemplate = (EmsTemplate) applicationContext["MessageTemplate"] as EmsTemplate;
|
||||
Assert.IsNotNull(emsTemplate);
|
||||
|
||||
Assert.AreEqual(0, listener.MessageCount);
|
||||
emsTemplate.ConvertAndSend("Hello World 1");
|
||||
|
||||
int waitInMillis = 2000;
|
||||
Thread.Sleep(waitInMillis);
|
||||
Assert.AreEqual(1,listener.MessageCount);
|
||||
|
||||
container.Stop();
|
||||
Console.WriteLine("container stopped.");
|
||||
emsTemplate.ConvertAndSend("Hello World 2");
|
||||
Thread.Sleep(waitInMillis);
|
||||
Assert.AreEqual(1, listener.MessageCount);
|
||||
|
||||
container.Start();
|
||||
Console.WriteLine("container started.");
|
||||
Thread.Sleep(waitInMillis);
|
||||
Assert.AreEqual(2, listener.MessageCount);
|
||||
|
||||
container.Shutdown();
|
||||
|
||||
Thread.Sleep(waitInMillis);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override string[] ConfigLocations
|
||||
{
|
||||
get { return new string[] { "assembly://Spring.Messaging.Ems.Tests/Spring.Messaging.Ems.Integration/SimpleMessageListenerContainerTests.xml" }; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
|
||||
<object id="ConnectionFactory" type="TIBCO.EMS.ConnectionFactory, TIBCO.EMS">
|
||||
<constructor-arg index="0" value="tcp://localhost:7222"/>
|
||||
</object>
|
||||
|
||||
|
||||
<object name="SimpleMessageListenerContainer" type="Spring.Messaging.Ems.Listener.SimpleMessageListenerContainer, Spring.Messaging.Ems">
|
||||
<property name="ConnectionFactory" ref="ConnectionFactory"/>
|
||||
<property name="DestinationName" value="test.queue"/>
|
||||
<property name="MessageListener" ref="SimpleMessageListener"/>
|
||||
<property name="ExceptionListener">
|
||||
<object type="Spring.Messaging.ems.Integration.LoggingExceptionHandler, Spring.Messaging.Ems.Tests"/>
|
||||
</property>
|
||||
</object>
|
||||
|
||||
<object id="SimpleMessageListener" type="Spring.Messaging.Ems.Integration.SimpleMessageListener, Spring.Messaging.Ems.Tests"/>
|
||||
|
||||
|
||||
<object name="MessageTemplate" type="Spring.Messaging.Ems.Core.EmsTemplate, Spring.Messaging.Ems">
|
||||
<property name="ConnectionFactory" ref="ConnectionFactory"/>
|
||||
<property name="DefaultDestinationName" value="test.queue"/>
|
||||
</object>
|
||||
</objects>
|
||||
Reference in New Issue
Block a user