Permalink
Browse files

Updating test configuration. Adding more unit tests.

  • Loading branch information...
1 parent 3844f22 commit 3e557b9b093bef1e6fb9ba3d18f57afb03471076 @joefitzgerald joefitzgerald committed Oct 24, 2011
Showing with 297 additions and 75 deletions.
  1. +10 −2 src/Spring.Messaging.Amqp.Rabbit/Config/AbstractExchangeParser.cs
  2. +7 −0 src/Spring.Messaging.Amqp.Rabbit/Config/RabbitNamespaceHandler.cs
  3. +23 −22 src/Spring.Messaging.Amqp.Rabbit/Config/spring-rabbit.xsd
  4. +1 −1 src/Spring.Messaging.Amqp.Rabbit/Spring.Messaging.Amqp.Rabbit.2010.csproj
  5. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/AdminParserTests-0-context.xml
  6. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/AdminParserTests-1-context.xml
  7. +3 −4 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/AdminParserTests-2-context.xml
  8. +27 −18 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/AdminParserTests.cs
  9. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/ConnectionFactoryParserTests-context.xml
  10. +51 −0 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/ConnectionFactoryParserTests.cs
  11. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/ExchangeParserIntegrationTests-context.xml
  12. +5 −4 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/ExchangeParserTests-context.xml
  13. +106 −0 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/ExchangeParserTests.cs
  14. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/ListenerContainerParserTests-context.xml
  15. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/ListenerContainerPlaceholderParserTests-context.xml
  16. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/QueueParserIllegalAnonymousTests-context.xml
  17. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/QueueParserIntegrationTests-context.xml
  18. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/QueueParserPlaceholderTests-context.xml
  19. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/QueueParserTests-context.xml
  20. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/RabbitNamespaceHandlerTests-context.xml
  21. +1 −2 test/Spring.Messaging.Amqp.Rabbit.Tests/Config/TemplateParserTests-context.xml
  22. +3 −0 test/Spring.Messaging.Amqp.Rabbit.Tests/Spring.Messaging.Amqp.Rabbit.Tests.2010.csproj
  23. +49 −0 test/Spring.Messaging.Amqp.Rabbit.Tests/Test/XmlObjectFactoryExtensions.cs
@@ -61,8 +61,16 @@ protected override void DoParse(XmlElement element, ParserContext parserContext,
var argumentsElement = argumentsElements != null && argumentsElements.Count == 1 ? argumentsElements[0] as XmlElement : null;
if (argumentsElement != null)
{
- var map = parserContext.ParserHelper.ParseCustomElement(argumentsElement, builder.RawObjectDefinition);
- builder.AddConstructorArg(map);
+ try
+ {
+ var map = parserContext.ParserHelper.ParseCustomElement(argumentsElement, builder.RawObjectDefinition);
+ builder.AddConstructorArg(map);
+ }
+ catch (Exception e)
+ {
+ throw;
+ }
+
}
}
@@ -12,6 +12,13 @@ namespace Spring.Messaging.Amqp.Rabbit.Config
/// <summary>
/// Namespace handler for Rabbit.
/// </summary>
+ [
+ NamespaceParser(
+ Namespace = "http://www.springframework.net/schema/rabbit",
+ SchemaLocationAssemblyHint = typeof(RabbitNamespaceHandler),
+ SchemaLocation = "/Spring.Messaging.Amqp.Rabbit.Config/spring-rabbit.xsd"
+ )
+ ]
public class RabbitNamespaceHandler : NamespaceParserSupport
{
public override void Init()
@@ -71,7 +71,7 @@
</xsd:complexType>
</xsd:element>
- <xsd:element name="queue-arguments" type="mapType">
+ <xsd:element name="queue-arguments" type="map">
<xsd:annotation>
<xsd:documentation source="java:java.util.Map">
<![CDATA[
@@ -306,7 +306,7 @@
</xsd:attribute>
</xsd:complexType>
- <xsd:element name="exchange-arguments" type="mapType">
+ <xsd:element name="exchange-arguments" type="map">
<xsd:annotation>
<xsd:documentation source="java:java.util.Map">
<![CDATA[
@@ -381,7 +381,7 @@
</xsd:attribute>
</xsd:complexType>
- <xsd:element name="binding-arguments" type="mapType">
+ <xsd:element name="binding-arguments" type="map">
<xsd:annotation>
<xsd:documentation source="java:java.util.Map">
<![CDATA[
@@ -391,27 +391,28 @@
</xsd:annotation>
</xsd:element>
- <xsd:complexType name="mapType">
- <xsd:complexContent>
- <xsd:extension base="beans:mapType">
- <xsd:attribute name="ref" use="optional">
- <xsd:annotation>
- <xsd:documentation source="java:java.util.Map">
- <![CDATA[
- The bean name of the Map to pass to the broker when this component is declared.
- ]]>
- </xsd:documentation>
- <xsd:appinfo>
- <!--<tool:annotation kind="ref">
- <tool:expected-type type="java.util.Map" />
- </tool:annotation>-->
- </xsd:appinfo>
- </xsd:annotation>
- </xsd:attribute>
- </xsd:extension>
- </xsd:complexContent>
+ <xsd:complexType name="map">
+ <xsd:sequence>
+ <xsd:element ref="map"/>
+ </xsd:sequence>
</xsd:complexType>
+ <xsd:element name="map">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element maxOccurs="unbounded" ref="entry"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+
+ <xsd:element name="entry">
+ <xsd:complexType>
+ <xsd:attribute name="key" use="required"/>
+ <xsd:attribute name="value"/>
+ <xsd:attribute name="value-ref" type="xsd:NCName"/>
+ </xsd:complexType>
+ </xsd:element>
+
<xsd:element name="listener-container">
<xsd:annotation>
<xsd:documentation>
@@ -184,7 +184,7 @@
<None Include="..\..\Spring.Net.snk">
<Link>Spring.Net.snk</Link>
</None>
- <None Include="Config\spring-rabbit.xsd" />
+ <EmbeddedResource Include="Config\spring-rabbit.xsd" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:rabbit="http://www.springframework.net/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.net/schema/rabbit http://www.springframework.net/schema/rabbit/spring-rabbit-1.0.xsd">
+ xmlns:rabbit="http://www.springframework.net/schema/rabbit">
<object id="connectionFactory" type="Spring.Messaging.Amqp.Rabbit.Connection.CachingConnectionFactory, Spring.Messaging.Amqp.Rabbit" />
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:rabbit="http://www.springframework.net/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.net/schema/rabbit http://www.springframework.net/schema/rabbit/spring-rabbit-1.0.xsd">
+ xmlns:rabbit="http://www.springframework.net/schema/rabbit">
<!-- One of 'rabbit-template' or 'rabbit-connection-factory' attributes must be set - context load should fail -->
<rabbit:admin />
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:rabbit="http://www.springframework.net/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.net/schema/rabbit http://www.springframework.net/schema/rabbit/spring-rabbit-1.0.xsd">
+ xmlns:rabbit="http://www.springframework.net/schema/rabbit">
<object id="connectionFactory" type="Spring.Messaging.Amqp.Rabbit.Connection.CachingConnectionFactory, Spring.Messaging.Amqp.Rabbit" />
- <!-- Valid configuration -->
- <rabbit:admin id="admin-test" connection-factory="connectionFactory" auto-startup="false"/>
+ <!-- Valid configuration -->
+ <rabbit:admin id="admin-test" connection-factory="connectionFactory" auto-startup="false"/>
</objects>
@@ -14,8 +14,11 @@
using Spring.Context.Config;
using Spring.Context.Support;
using Spring.Core.IO;
+using Spring.Messaging.Amqp.Rabbit.Config;
+using Spring.Messaging.Amqp.Rabbit.Connection;
using Spring.Messaging.Amqp.Rabbit.Core;
using Spring.Messaging.Amqp.Rabbit.Tests.Test;
+using Spring.Objects.Factory;
using Spring.Objects.Factory.Parsing;
using Spring.Objects.Factory.Xml;
using Spring.Util;
@@ -27,7 +30,7 @@ namespace Spring.Messaging.Amqp.Rabbit.Tests.Config
/// AdminParser Tests
/// </summary>
[TestFixture]
- [Category(TestCategory.Integration)]
+ [Category(TestCategory.Unit)]
public class AdminParserTests
{
private static readonly ILog Logger = LogManager.GetCurrentClassLogger();
@@ -44,6 +47,12 @@ public class AdminParserTests
private string adminBeanName;
private bool initialisedWithTemplate;
+
+ [TestFixtureSetUp]
+ public void Setup()
+ {
+ NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
+ }
[Test]
public void TestInvalid()
@@ -75,19 +84,18 @@ private void DoTest()
RabbitAdmin admin;
if (StringUtils.HasText(adminBeanName))
{
- admin = beanFactory.GetObject(adminBeanName, typeof(RabbitAdmin)) as RabbitAdmin;
+ admin = beanFactory.GetObject<RabbitAdmin>(adminBeanName);
}
else
{
- admin = beanFactory.GetObject(typeof(RabbitAdmin).Name) as RabbitAdmin;
+ admin = beanFactory.GetObject<RabbitAdmin>();
}
Assert.AreEqual(expectedAutoStartup, admin.AutoStartup);
- Assert.AreEqual(
- beanFactory.GetObject(typeof(ConnectionFactory).Name), admin.RabbitTemplate.ConnectionFactory);
+ Assert.AreEqual(beanFactory.GetObject<IConnectionFactory>(), admin.RabbitTemplate.ConnectionFactory);
if (initialisedWithTemplate)
{
- Assert.AreEqual(beanFactory.GetObject(typeof(RabbitTemplate).Name), admin.RabbitTemplate);
+ Assert.AreEqual(beanFactory.GetObject<RabbitTemplate>(), admin.RabbitTemplate);
}
}
@@ -97,12 +105,6 @@ private XmlObjectFactory LoadContext()
XmlObjectFactory beanFactory = null;
try
{
- var resourceNames = typeof(AdminParserTests).Assembly.GetManifestResourceNames();
- foreach (var resourceNameString in resourceNames)
- {
- var info = typeof(AdminParserTests).Assembly.GetManifestResourceInfo(resourceNameString);
- Logger.Info(resourceNameString);
- }
// Resource file name template: <class-name>-<contextIndex>-context.xml
var resourceName = @"assembly://Spring.Messaging.Amqp.Rabbit.Tests/Spring.Messaging.Amqp.Rabbit.Tests.Config/" + typeof(AdminParserTests).Name + "-" + contextIndex + "-context.xml";
Logger.Info("Resource Name: " + resourceName);
@@ -113,15 +115,22 @@ private XmlObjectFactory LoadContext()
Assert.Fail("Context " + resource + " suppose to fail");
}
}
- catch (ObjectDefinitionParsingException e)
+ catch (Exception e)
{
- if (validContext)
+ if (e is ObjectDefinitionParsingException || e is ObjectDefinitionStoreException)
{
- // Context expected to be valid - throw an exception up
- throw e;
- }
+ if (validContext)
+ {
+ // Context expected to be valid - throw an exception up
+ throw e;
+ }
- Logger.Warn("Failure was expected", e);
+ Logger.Warn("Failure was expected", e);
+ }
+ else
+ {
+ throw;
+ }
}
return beanFactory;
}
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:rabbit="http://www.springframework.net/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.net/schema/rabbit http://www.springframework.net/schema/rabbit/spring-rabbit-1.0.xsd">
+ xmlns:rabbit="http://www.springframework.net/schema/rabbit">
<rabbit:connection-factory id="kitchenSink" host="foo" virtual-host="/bar" channel-cache-size="10" port="6888" username="user" password="password" />
@@ -0,0 +1,51 @@
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using NUnit.Framework;
+
+using Spring.Core.IO;
+using Spring.Messaging.Amqp.Rabbit.Config;
+using Spring.Messaging.Amqp.Rabbit.Connection;
+using Spring.Messaging.Amqp.Rabbit.Tests.Test;
+using Spring.Objects.Factory.Xml;
+
+namespace Spring.Messaging.Amqp.Rabbit.Tests.Config
+{
+ /// <summary>
+ /// ConnectionFactoryParser Tests
+ /// </summary>
+ [TestFixture]
+ [Category(TestCategory.Unit)]
+ public class ConnectionFactoryParserTests
+ {
+ private XmlObjectFactory beanFactory;
+
+ [TestFixtureSetUp]
+ public void Setup()
+ {
+ NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
+ var resourceName = @"assembly://Spring.Messaging.Amqp.Rabbit.Tests/Spring.Messaging.Amqp.Rabbit.Tests.Config/" + typeof(ConnectionFactoryParserTests).Name + "-context.xml";
+ var resource = new AssemblyResource(resourceName);
+ beanFactory = new XmlObjectFactory(resource);
+ }
+
+ [Test]
+ public void testKitchenSink()
+ {
+ var connectionFactory = beanFactory.GetObject<CachingConnectionFactory>("kitchenSink");
+ Assert.IsNotNull(connectionFactory);
+ Assert.AreEqual(10, connectionFactory.ChannelCacheSize);
+ }
+
+ [Test]
+ public void testNative()
+ {
+ var connectionFactory = beanFactory.GetObject<CachingConnectionFactory>("native");
+ Assert.IsNotNull(connectionFactory);
+ Assert.AreEqual(10, connectionFactory.ChannelCacheSize);
+ }
+ }
+}
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:rabbit="http://www.springframework.net/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.net/schema/rabbit http://www.springframework.net/schema/rabbit/spring-rabbit-1.0.xsd">
+ xmlns:rabbit="http://www.springframework.net/schema/rabbit">
<direct-exchange name="directTest">
<bindings>
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:rabbit="http://www.springframework.net/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.net/schema/rabbit http://www.springframework.net/schema/rabbit/spring-rabbit-1.0.xsd">
+ xmlns:rabbit="http://www.springframework.net/schema/rabbit">
<rabbit:direct-exchange name="direct" />
@@ -12,8 +11,10 @@
<direct-exchange name="direct-arguments" xmlns="http://www.springframework.net/schema/rabbit">
<exchange-arguments>
- <entry key="foo" value="bar" />
- </exchange-arguments>
+ <map>
+ <entry key="foo" value="bar" />
+ </map>
+ </exchange-arguments>
</direct-exchange>
<rabbit:topic-exchange name="topic" />
Oops, something went wrong.

0 comments on commit 3e557b9

Please sign in to comment.