Author: jgomes
Date: Mon Aug  4 16:55:52 2008
New Revision: 682543

URL: http://svn.apache.org/viewvc?rev=682543&view=rev
Log:
Refactored unit tests to load external configuration that can be customized for 
a run-time environment without having to modify and recompile the unit test 
code.
Fixes [AMQNET-92]. (See https://issues.apache.org/activemq/browse/AMQNET-92)

Added:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs
Removed:
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/BadConsumeTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/BytesMessageTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ConnectionTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ConsumerTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DurableTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TemporaryQueueTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestUtils.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TextMessage.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TransactionTest.cs
Modified:
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MapMessageTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSPropertyTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj

Added: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config?rev=682543&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config 
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nmsprovider-test.config 
Mon Aug  4 16:55:52 2008
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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.
+-->
+<configuration>
+       <defaultURI value="activemq:tcp://jgomesv1:61616">
+               <factoryParams>
+                       <param type="string" value="NMSTestClient"/>
+               </factoryParams>
+               <userName value="guest"/>
+               <passWord value="guest"/>
+       </defaultURI>
+
+       <openWireURI value="activemq:tcp://jgomesv1:61616">
+               <factoryParams>
+                       <param type="string" value="OpenWireTestClient"/>
+               </factoryParams>
+       </openWireURI>
+
+       <stompURI value="activemq:stomp://jgomesv1:61613">
+               <factoryParams>
+                       <param type="string" value="STOMPTestClient"/>
+               </factoryParams>
+       </stompURI>
+</configuration>

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs?rev=682543&r1=682542&r2=682543&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
 Mon Aug  4 16:55:52 2008
@@ -28,7 +28,7 @@
     /// </summary>
     public class ConnectionFactory : IConnectionFactory
     {
-               public const string DEFAULT_BROKER_URL = 
"tcp://localhost:61616";
+               public const string DEFAULT_BROKER_URL = 
"activemq:tcp://localhost:61616";
                public const string ENV_BROKER_URL = "ACTIVEMQ_BROKER_URL";
                
         private Uri brokerUri;

Added: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs?rev=682543&view=auto
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs
 (added)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs
 Mon Aug  4 16:55:52 2008
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+using NUnit.Framework;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+       [TestFixture]
+       public class BadConsumeTest : Apache.NMS.Test.BadConsumeTest
+       {
+       }
+
+       [TestFixture]
+       public class BytesMessageTest : Apache.NMS.Test.BytesMessageTest
+       {
+       }
+
+       [TestFixture]
+       public class ConnectionTest : Apache.NMS.Test.ConnectionTest
+       {
+       }
+
+       [TestFixture]
+       public class ConsumerTest : Apache.NMS.Test.ConsumerTest
+       {
+       }
+
+       [TestFixture]
+       public class DurableTest : Apache.NMS.Test.DurableTest
+       {
+       }
+
+       [TestFixture]
+       public class TemporaryQueueTest : Apache.NMS.Test.TemporaryQueueTest
+       {
+       }
+
+       [TestFixture]
+       public class TextMessage : Apache.NMS.Test.TextMessage
+       {
+       }
+
+       [TestFixture]
+       public class TransactionTest : Apache.NMS.Test.TransactionTest
+       {
+       }
+}

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MapMessageTest.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MapMessageTest.cs?rev=682543&r1=682542&r2=682543&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MapMessageTest.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/MapMessageTest.cs
 Mon Aug  4 16:55:52 2008
@@ -21,20 +21,11 @@
        [TestFixture]
        public class MapMessageTest_OpenWire : Apache.NMS.Test.MapMessageTest
        {
-               protected override IConnectionFactory CreateConnectionFactory()
-               {
-                       return TestUtils.CreateOpenWireConnectionFactory();
-               }
        }
 
        [TestFixture]
        public class MapMessageTest_Stomp : Apache.NMS.Test.MapMessageTest
        {
-               protected override IConnectionFactory CreateConnectionFactory()
-               {
-                       return TestUtils.CreateStompConnectionFactory();
-               }
-
                public override void SendAndSyncReceive()
                {
                        // TODO disable test
@@ -42,9 +33,8 @@
 
                protected override void AssertValidMessage(IMessage message)
                {
-                       System.Console.WriteLine("Received MapMessage: " + 
message);
-
                        Assert.IsTrue(message is IMapMessage, "Did not receive 
a MapMessage!");
+                       System.Console.WriteLine("Received MapMessage: " + 
message);
                }
        }
 }

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSPropertyTest.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSPropertyTest.cs?rev=682543&r1=682542&r2=682543&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSPropertyTest.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSPropertyTest.cs
 Mon Aug  4 16:55:52 2008
@@ -22,20 +22,11 @@
     [TestFixture]
     public class NMSPropertyTest_OpenWire : Apache.NMS.Test.NMSPropertyTest
     {
-        protected override IConnectionFactory CreateConnectionFactory()
-        {
-                       return TestUtils.CreateOpenWireConnectionFactory();
-               }
     }
 
        [TestFixture]
        public class NMSPropertyTest_Stomp : Apache.NMS.Test.NMSPropertyTest
        {
-               protected override IConnectionFactory CreateConnectionFactory()
-               {
-                       return TestUtils.CreateStompConnectionFactory();
-               }
-
                protected override void AssertNonStringProperties(IMessage 
message)
                {
                        // lets disable typesafe property testing as right now 
Stomp does not support them

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj?rev=682543&r1=682542&r2=682543&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj 
(original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj 
Mon Aug  4 16:55:52 2008
@@ -36,23 +36,17 @@
     <DebugType>full</DebugType>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="nunit.framework, Version=2.2.0.0, Culture=neutral, 
PublicKeyToken=96d09a1eb7f44a77">
-      <SpecificVersion>False</SpecificVersion>
-      
<HintPath>$(USERPROFILE)\.nant\repository\org.nunit\nunit\2.2.8\all\nunit.framework.dll</HintPath>
-    </Reference>
+    <Reference Include="nunit.framework, Version=2.4.7.0, Culture=neutral, 
PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
     <Reference Include="System" />
+    <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="src\test\csharp\BadConsumeTest.cs" />
-    <Compile Include="src\test\csharp\BytesMessageTest.cs" />
     <Compile Include="src\test\csharp\Commands\CommandTest.cs">
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="src\test\csharp\CommonAssemblyInfo.cs" />
-    <Compile Include="src\test\csharp\ConnectionTest.cs" />
-    <Compile Include="src\test\csharp\ConsumerTest.cs" />
-    <Compile Include="src\test\csharp\DurableTest.cs" />
+    <Compile Include="src\test\csharp\InheritedTests.cs" />
     <Compile Include="src\test\csharp\MapMessageTest.cs" />
     <Compile Include="src\test\csharp\NMSConnectionFactoryTest.cs" />
     <Compile Include="src\test\csharp\NMSPropertyTest.cs" />
@@ -66,13 +60,9 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="src\test\csharp\StompHelperTest.cs" />
-    <Compile Include="src\test\csharp\TemporaryQueueTest.cs" />
     <Compile Include="src\test\csharp\TestMain.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="src\test\csharp\TestUtils.cs" />
-    <Compile Include="src\test\csharp\TextMessage.cs" />
-    <Compile Include="src\test\csharp\TransactionTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="vendor\Apache.NMS\vs2008-nms-test.csproj">
@@ -90,6 +80,9 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="activemq-dotnet.snk" />
+    <Content Include="nmsprovider-test.config">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
 </Project>
\ No newline at end of file

Modified: 
activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs?rev=682543&r1=682542&r2=682543&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs 
(original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs 
Mon Aug  4 16:55:52 2008
@@ -17,6 +17,9 @@
 using Apache.NMS;
 using NUnit.Framework;
 using System;
+using System.IO;
+using System.Xml;
+using System.Collections;
 
 namespace Apache.NMS.Test
 {
@@ -32,13 +35,15 @@
                // enable/disable logging of message flows
                protected bool logging = true;
 
-               private IConnectionFactory factory;
+               private NMSConnectionFactory NMSFactory;
                private IConnection connection;
                private ISession session;
                private IDestination destination;
 
                protected TimeSpan receiveTimeout = 
TimeSpan.FromMilliseconds(5000);
-               protected string clientId;
+               protected virtual string clientId { get; set; }
+               protected virtual string passWord { get; set; }
+               protected virtual string userName { get; set; }
                protected bool persistent = true;
                protected DestinationType destinationType = 
DestinationType.Queue;
                protected AcknowledgementMode acknowledgementMode = 
AcknowledgementMode.ClientAcknowledge;
@@ -78,41 +83,40 @@
                {
                        get
                        {
-                               if(factory == null)
+                               if(null == NMSFactory)
                                {
-                                       factory = CreateConnectionFactory();
-                                       Assert.IsNotNull(factory, "no factory 
created");
+                                       Assert.IsTrue(CreateNMSFactory(), 
"Error creating factory.");
                                }
-                               return factory;
+
+                               return NMSFactory.ConnectionFactory;
                        }
-                       set { this.factory = value; }
                }
 
                public IConnection Connection
                {
                        get
                        {
-                               if(connection == null)
+                               if(null == connection)
                                {
                                        Connect();
                                }
+
                                return connection;
                        }
-                       set { this.connection = value; }
                }
 
                public ISession Session
                {
                        get
                        {
-                               if(session == null)
+                               if(null == session)
                                {
                                        session = 
Connection.CreateSession(acknowledgementMode);
                                        Assert.IsNotNull(session, "no session 
created");
                                }
+
                                return session;
                        }
-                       set { this.session = value; }
                }
 
                protected virtual void Connect()
@@ -165,31 +169,129 @@
 
                public virtual void SendAndSyncReceive()
                {
-                       using(ISession sendSession = Connection.CreateSession())
+                       // IDestination sendDestination = 
CreateDestination(Session);
+                       IMessageConsumer consumer = 
Session.CreateConsumer(Destination);
+                       IMessageProducer producer = 
Session.CreateProducer(Destination);
+
+                       producer.Persistent = persistent;
+
+                       IMessage request = CreateMessage();
+                       producer.Send(request);
+
+                       IMessage message = consumer.Receive(receiveTimeout);
+                       Assert.IsNotNull(message, "No message returned!");
+                       AssertValidMessage(message);
+               }
+
+               protected virtual string GetConnectionConfigFileName() { return 
"nmsprovider-test.config"; }
+
+               protected virtual string GetNameTestURI() { return 
"defaultURI"; }
+
+               protected bool CreateNMSFactory()
+               {
+                       return CreateNMSFactory(GetNameTestURI());
+               }
+
+               protected bool CreateNMSFactory(string nameTestURI)
+               {
+                       Uri brokerUri = null;
+                       object[] factoryParams = null;
+                       string connectionConfigFileName = 
GetConnectionConfigFileName();
+
+                       Assert.IsTrue(File.Exists(connectionConfigFileName), 
"Connection configuration file does not exist.");
+                       XmlDocument configDoc = new XmlDocument();
+
+                       configDoc.Load(connectionConfigFileName);
+                       XmlElement uriNode = (XmlElement) 
configDoc.SelectSingleNode(String.Format("/configuration/{0}", nameTestURI));
+
+                       if(null != uriNode)
                        {
-                               IDestination sendDestination = 
CreateDestination(sendSession);
-                               IMessageConsumer consumer = 
sendSession.CreateConsumer(sendDestination);
-                               IMessageProducer producer = 
sendSession.CreateProducer(sendDestination);
-                               producer.Persistent = persistent;
+                               brokerUri = new 
Uri(uriNode.GetAttribute("value"));
+                               factoryParams = GetFactoryParams(uriNode);
+       
+                               XmlElement userNameNode = (XmlElement) 
uriNode.SelectSingleNode("userName");
 
-                               IMessage request = sendSession.CreateMessage();
-                               producer.Send(request);
+                               if(null != userNameNode)
+                               {
+                                       userName = 
userNameNode.GetAttribute("value");
+                               }
+                               else
+                               {
+                                       userName = "guest";
+                               }
+
+                               XmlElement passWordNode = (XmlElement) 
uriNode.SelectSingleNode("passWord");
+
+                               if(null != passWordNode)
+                               {
+                                       passWord = 
passWordNode.GetAttribute("value");
+                               }
+                               else
+                               {
+                                       passWord = "guest";
+                               }
 
-                               IMessage message = 
consumer.Receive(receiveTimeout);
-                               Assert.IsNotNull(message, "No message 
returned!");
-                               AssertValidMessage(message);
+                               if(null == factoryParams)
+                               {
+                                       NMSFactory = new 
Apache.NMS.NMSConnectionFactory(brokerUri);
+                               }
+                               else
+                               {
+                                       NMSFactory = new 
Apache.NMS.NMSConnectionFactory(brokerUri, factoryParams);
+                               }
                        }
+
+                       return (null != NMSFactory);
                }
 
-               protected abstract IConnectionFactory CreateConnectionFactory();
+               protected object[] GetFactoryParams(XmlElement uriNode)
+               {
+                       ArrayList factoryParams = new ArrayList();
+                       XmlElement factoryParamsNode = (XmlElement) 
uriNode.SelectSingleNode("factoryParams");
+
+                       if(null != factoryParamsNode)
+                       {
+                               XmlNodeList nodeList = 
factoryParamsNode.SelectNodes("param");
+
+                               if(null != nodeList)
+                               {
+                                       foreach(XmlElement paramNode in 
nodeList)
+                                       {
+                                               string paramType = 
paramNode.GetAttribute("type");
+                                               string paramValue = 
paramNode.GetAttribute("value");
+
+                                               switch(paramType)
+                                               {
+                                               case "string":
+                                                       
factoryParams.Add(paramValue);
+                                               break;
+
+                                               case "int":
+                                                       
factoryParams.Add(int.Parse(paramValue));
+                                               break;
+
+                                               // TODO: Add more parameter 
types
+                                               }
+                                       }
+                               }
+                       }
+
+                       if(factoryParams.Count > 0)
+                       {
+                               return factoryParams.ToArray();
+                       }
+
+                       return null;
+               }
 
                protected virtual IConnection CreateConnection()
                {
-                       IConnection newConnection = Factory.CreateConnection();
+                       IConnection newConnection = 
Factory.CreateConnection(userName, passWord);
                        if(clientId != null)
                        {
                                newConnection.ClientId = clientId;
                        }
+
                        return newConnection;
                }
 

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj?rev=682543&r1=682542&r2=682543&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms-test.csproj Mon Aug  4 
16:55:52 2008
@@ -51,10 +51,7 @@
     <DebugType>full</DebugType>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="nunit.framework, Version=2.2.0.0, Culture=neutral, 
PublicKeyToken=96d09a1eb7f44a77">
-      <SpecificVersion>False</SpecificVersion>
-      
<HintPath>$(USERPROFILE)\.nant\repository\org.nunit\nunit\2.2.8\all\nunit.framework.dll</HintPath>
-    </Reference>
+    <Reference Include="nunit.framework, Version=2.4.7.0, Culture=neutral, 
PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
     <Reference Include="System" />
     <Reference Include="System.Xml" />
   </ItemGroup>


Reply via email to