You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by nm...@apache.org on 2008/01/05 23:07:08 UTC

svn commit: r609227 - in /activemq/activemq-cpp/trunk/src: main/ main/activemq/cmsutil/ test/ test/activemq/cmsutil/

Author: nmittler
Date: Sat Jan  5 14:07:06 2008
New Revision: 609227

URL: http://svn.apache.org/viewvc?rev=609227&view=rev
Log:
AMQCPP-152 - Adding classes for support of CmsTemplate

Added:
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.h
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnection.h
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnectionFactory.h
Modified:
    activemq/activemq-cpp/trunk/src/main/Makefile.am
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h
    activemq/activemq-cpp/trunk/src/test/Makefile.am
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummySession.h

Modified: activemq/activemq-cpp/trunk/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/Makefile.am?rev=609227&r1=609226&r2=609227&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/main/Makefile.am Sat Jan  5 14:07:06 2008
@@ -24,6 +24,8 @@
     activemq/util/URISupport.cpp \
     activemq/cmsutil/DynamicDestinationResolver.cpp \
     activemq/cmsutil/ResourceLifecycleManager.cpp \
+    activemq/cmsutil/CmsAccessor.cpp \
+    activemq/cmsutil/CmsDestinationAccessor.cpp \
     activemq/core/ActiveMQConsumer.cpp \
     activemq/core/ActiveMQConnection.cpp \
     activemq/core/ActiveMQSession.cpp \

Added: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp?rev=609227&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp Sat Jan  5 14:07:06 2008
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+#include "CmsAccessor.h"
+
+using namespace activemq::cmsutil;
+
+////////////////////////////////////////////////////////////////////////////////
+CmsAccessor::CmsAccessor() {
+    sessionAcknowledgeMode = cms::Session::AUTO_ACKNOWLEDGE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CmsAccessor::~CmsAccessor() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Connection* CmsAccessor::createConnection() throw (cms::CMSException) {
+    
+    // Create the connection.
+    cms::Connection* c = getConnectionFactory()->createConnection();
+    
+    // Manage the lifecycle of this resource.
+    getResourceLifecycleManager()->addConnection(c);
+    
+    return c;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Session* CmsAccessor::createSession(cms::Connection* con) 
+    throw (cms::CMSException) {
+    
+    // Create the session.
+    cms::Session* s = con->createSession(getSessionAcknowledgeMode());
+    
+    // Manage the lifecycle of this resource.
+    getResourceLifecycleManager()->addSession(s);
+    
+    return s;
+}

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h?rev=609227&r1=609226&r2=609227&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h Sat Jan  5 14:07:06 2008
@@ -18,6 +18,7 @@
 #define _ACTIVEMQ_CMSUTIL_CMSACCESSOR_H_
 
 #include <cms/ConnectionFactory.h>
+#include <activemq/cmsutil/ResourceLifecycleManager.h>
 
 namespace activemq {
 namespace cmsutil {
@@ -38,26 +39,44 @@
     
     private:
     
+        ResourceLifecycleManager resourceLifecycleManager;
+        
         cms::ConnectionFactory* connectionFactory;
     
-        bool sessionTransacted;
-    
-        int sessionAcknowledgeMode;
+        cms::Session::AcknowledgeMode sessionAcknowledgeMode;
     
     public:
         
-        CmsAccessor() {
-            sessionTransacted = false;
-            sessionAcknowledgeMode = cms::Session::AUTO_ACKNOWLEDGE;
+        CmsAccessor();
+        
+        virtual ~CmsAccessor();
+        
+        /**
+         * Initializes this object and prepares it for use.  This should be called
+         * before any other methds are called.
+         */
+        virtual void init() throw (cms::CMSException) {            
+        }
+        
+        /**
+         * Shuts down this object and destroys any allocated resources.
+         */
+        virtual void destroy() throw (cms::CMSException) {
+            resourceLifecycleManager.destroy();
         }
         
-        virtual ~CmsAccessor() {            
+        virtual ResourceLifecycleManager* getResourceLifecycleManager() {
+            return &resourceLifecycleManager;
+        }
+        
+        virtual const ResourceLifecycleManager* getResourceLifecycleManager() const {
+            return &resourceLifecycleManager;
         }
     
         /**
          * Set the ConnectionFactory to use for obtaining CMS Connections.
          */
-        virtual void setConnectionFactory(ConnectionFactory* connectionFactory) {
+        virtual void setConnectionFactory(cms::ConnectionFactory* connectionFactory) {
             this->connectionFactory = connectionFactory;
         }
     
@@ -65,7 +84,7 @@
          * Return the ConnectionFactory that this accessor uses for
          * obtaining CMS Connections.
          */
-        virtual const ConnectionFactory* getConnectionFactory() const {
+        virtual const cms::ConnectionFactory* getConnectionFactory() const {
             return this->connectionFactory;
         }
     
@@ -73,37 +92,18 @@
          * Return the ConnectionFactory that this accessor uses for
          * obtaining CMS Connections.
          */
-        virtual ConnectionFactory* getConnectionFactory() {
+        virtual cms::ConnectionFactory* getConnectionFactory() {
             return this->connectionFactory;
         }
     
         /**
-         * Set the transaction mode that is used when creating a CMS Session.
-         * Default is "false".
-         * 
-         * @param sessionTransacted the transaction mode
-         */
-        virtual void setSessionTransacted(bool sessionTransacted) {
-            this->sessionTransacted = sessionTransacted;
-        }
-    
-        /**
-         * Return whether the CMS sessions used by this
-         * accessor are supposed to be transacted.
-         * @return <code>true</code> if the CMS Sessions used are transacted
-         * @see #setSessionTransacted(bool)
-         */
-        virtual bool isSessionTransacted() const {
-            return this->sessionTransacted;
-        }
-    
-        /**
          * Set the CMS acknowledgement mode that is used when creating a CMS
          * Session to send a message.
          * <p>Default is <code>AUTO_ACKNOWLEDGE</code>.
          * @param sessionAcknowledgeMode the acknowledgement mode
          */
-        virtual void setSessionAcknowledgeMode(int sessionAcknowledgeMode) {
+        virtual void setSessionAcknowledgeMode(
+                cms::Session::AcknowledgeMode sessionAcknowledgeMode) {
             this->sessionAcknowledgeMode = sessionAcknowledgeMode;
         }
     
@@ -111,7 +111,7 @@
          * Return the acknowledgement mode for CMS sessions.
          * @return the acknowledgement mode applied by this accessor
          */
-        virtual int getSessionAcknowledgeMode() const {
+        virtual cms::Session::AcknowledgeMode getSessionAcknowledgeMode() const {
             return this->sessionAcknowledgeMode;
         }
     
@@ -122,9 +122,7 @@
          * @return the new CMS Connection
          * @throws cms::CMSException if thrown by CMS API methods
          */
-        virtual cms::Connection* createConnection() throw (cms::CMSException) {
-            return getConnectionFactory()->createConnection();
-        }
+        virtual cms::Connection* createConnection() throw (cms::CMSException);
     
         /**
          * Create a CMS Session for the given Connection.
@@ -132,19 +130,8 @@
          * @return the new CMS Session
          * @throws cms::CMSException if thrown by CMS API methods
          */
-        virtual cms::Session* createSession(cms::Connection* con) throw (cms::CMSException) {
-            return con->createSession(isSessionTransacted(), getSessionAcknowledgeMode());
-        }
-    
-        /**
-         * Determine whether the given Session is in client acknowledge mode.
-         * @param session the CMS Session to check
-         * @return whether the given Session is in client acknowledge mode
-         * @throws cms::CMSException if thrown by CMS API methods
-         */
-        virtual bool isClientAcknowledge(cms::Session* session) throws JMSException {
-            return (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE);
-        }
+        virtual cms::Session* createSession(cms::Connection* con) 
+            throw (cms::CMSException);
     
     };
 

Added: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp?rev=609227&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp Sat Jan  5 14:07:06 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+#include "CmsDestinationAccessor.h"
+
+using namespace activemq::cmsutil;
+
+////////////////////////////////////////////////////////////////////////////////
+CmsDestinationAccessor::CmsDestinationAccessor() {
+    
+    // Default to using queues.
+    pubSubDomain = false;
+    
+    // Start with the default destinationResolver.
+    destinationResolver = &defaultDestinationResolver;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CmsDestinationAccessor::~CmsDestinationAccessor() {    
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsDestinationAccessor::init() throw (cms::CMSException) {
+    setDestinationResolver(destinationResolver);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsDestinationAccessor::setDestinationResolver( DestinationResolver* destRes ) {
+    this->destinationResolver = destRes; 
+    destRes->setResourceLifecycleManager(getResourceLifecycleManager());
+}
+  
+////////////////////////////////////////////////////////////////////////////////
+cms::Destination* CmsDestinationAccessor::resolveDestinationName( 
+    cms::Session* session, 
+    const std::string& destName ) throw (cms::CMSException) {
+    
+    getDestinationResolver()->resolveDestinationName(session, 
+            destName, 
+            isPubSubDomain());
+}
+
+
+

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h?rev=609227&r1=609226&r2=609227&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h Sat Jan  5 14:07:06 2008
@@ -18,6 +18,7 @@
 #define _ACTIVEMQ_CMSUTIL_CMSDESTINATIONACCESSOR_H_
 
 #include <activemq/cmsutil/CmsAccessor.h>
+#include <activemq/cmsutil/DynamicDestinationResolver.h>
 
 namespace activemq {
 namespace cmsutil {
@@ -51,14 +52,16 @@
     
     public:
         
-        CmsDestinationAccessor() {
-            pubSubDomain = false;             
-            destinationResolver = &defaultDestinationResolver;
-        }
+        CmsDestinationAccessor();
         
-        virtual ~CmsDestinationAccessor() {            
-        }
+        virtual ~CmsDestinationAccessor();
         
+        /**
+         * Initializes this object and prepares it for use.  This should be called
+         * before any other methds are called.
+         */
+        virtual void init() throw (cms::CMSException);
+                
         virtual bool isPubSubDomain() const {
             return this->pubSubDomain;
         }
@@ -75,9 +78,7 @@
             return destinationResolver;
         }
         
-        virtual void setDestinationResolver( DestinationResolver* destRes ) {
-            this->destinationResolver = destRes;
-        }
+        virtual void setDestinationResolver( DestinationResolver* destRes );
         
     protected:
         
@@ -92,12 +93,7 @@
          */
         virtual cms::Destination* resolveDestinationName( 
                 cms::Session* session, 
-                const std::string& destName ) throws (cms::CMSException) {
-            
-            getDestinationResolver().resolveDestinationName(session, 
-                    destName, 
-                    isPubSubDomain());
-        }
+                const std::string& destName ) throw (cms::CMSException);
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/Makefile.am?rev=609227&r1=609226&r2=609227&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/test/Makefile.am Sat Jan  5 14:07:06 2008
@@ -61,6 +61,8 @@
   activemq/core/ActiveMQConnectionTest.cpp \
   activemq/core/ActiveMQSessionTest.cpp \
   activemq/cmsutil/DynamicDestinationResolverTest.cpp \
+  activemq/cmsutil/CmsAccessorTest.cpp \
+  activemq/cmsutil/CmsDestinationAccessorTest.cpp \
   activemq/exceptions/ActiveMQExceptionTest.cpp \
   activemq/transport/IOTransportTest.cpp \
   activemq/transport/filters/ResponseCorrelatorTest.cpp \

Added: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.cpp?rev=609227&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.cpp Sat Jan  5 14:07:06 2008
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#include "CmsAccessorTest.h"
+#include <activemq/cmsutil/DynamicDestinationResolver.h>
+#include <activemq/cmsutil/ResourceLifecycleManager.h>
+#include "DummyConnectionFactory.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::cmsutil::CmsAccessorTest );
+
+using namespace activemq;
+using namespace activemq::cmsutil;
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsAccessorTest::setUp() {
+    cf = new DummyConnectionFactory();
+    accessor = new MyAccessor();
+    accessor->setConnectionFactory(cf);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsAccessorTest::tearDown() {    
+    delete accessor;
+    delete cf;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsAccessorTest::testConnectionFactory() {
+
+    CPPUNIT_ASSERT(accessor->getConnectionFactory() == cf);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsAccessorTest::testAckMode() {
+
+    CPPUNIT_ASSERT(accessor->getSessionAcknowledgeMode() == cms::Session::AUTO_ACKNOWLEDGE);
+    
+    accessor->setSessionAcknowledgeMode(cms::Session::CLIENT_ACKNOWLEDGE);
+    
+    CPPUNIT_ASSERT(accessor->getSessionAcknowledgeMode() == cms::Session::CLIENT_ACKNOWLEDGE) ;   
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsAccessorTest::testCreateResources() {
+
+    cms::Connection* c = accessor->createConnection();
+    CPPUNIT_ASSERT( c != NULL);
+    
+    cms::Session* s = accessor->createSession(c);
+    CPPUNIT_ASSERT( s != NULL);
+    
+    CPPUNIT_ASSERT(s->getAcknowledgeMode() == cms::Session::AUTO_ACKNOWLEDGE);
+    
+    accessor->setSessionAcknowledgeMode(cms::Session::CLIENT_ACKNOWLEDGE);
+    
+    s = accessor->createSession(c);
+    CPPUNIT_ASSERT( s != NULL);
+    
+    CPPUNIT_ASSERT(s->getAcknowledgeMode() == cms::Session::CLIENT_ACKNOWLEDGE);
+}
+

Added: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.h?rev=609227&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsAccessorTest.h Sat Jan  5 14:07:06 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_CMSUTIL_CMSACCESSORTEST_H_
+#define _ACTIVEMQ_CMSUTIL_CMSACCESSORTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/cmsutil/CmsAccessor.h>
+
+namespace activemq{
+namespace cmsutil{
+
+    class DummyConnectionFactory;
+    
+    class CmsAccessorTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE( CmsAccessorTest );
+        CPPUNIT_TEST( testConnectionFactory );
+        CPPUNIT_TEST( testAckMode );
+        CPPUNIT_TEST( testCreateResources );
+        CPPUNIT_TEST_SUITE_END();               
+
+        class MyAccessor : public CmsAccessor {
+        
+        public:
+            
+            virtual ~MyAccessor(){}
+            
+            virtual cms::Connection* createConnection() throw (cms::CMSException) {
+                return CmsAccessor::createConnection();
+            }
+                
+            virtual cms::Session* createSession(cms::Connection* con) 
+                throw (cms::CMSException) {
+                return CmsAccessor::createSession(con);
+            }
+        };
+        
+        MyAccessor* accessor;
+        DummyConnectionFactory* cf;
+        
+    public:
+
+        CmsAccessorTest() {}
+        virtual ~CmsAccessorTest() {}
+
+        virtual void setUp();
+        virtual void tearDown();
+        
+        void testConnectionFactory();
+        void testAckMode();
+        void testCreateResources();
+    };
+
+}}
+
+#endif /*_ACTIVEMQ_CMSUTIL_CMSACCESSORTEST_H_*/

Added: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp?rev=609227&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp Sat Jan  5 14:07:06 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#include "CmsDestinationAccessorTest.h"
+#include <activemq/cmsutil/DynamicDestinationResolver.h>
+#include <activemq/cmsutil/ResourceLifecycleManager.h>
+#include "DummyConnectionFactory.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::cmsutil::CmsDestinationAccessorTest );
+
+using namespace activemq;
+using namespace activemq::cmsutil;
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsDestinationAccessorTest::setUp() {
+    cf = new DummyConnectionFactory();
+    accessor = new MyAccessor();
+    accessor->setConnectionFactory(cf);
+    accessor->init();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsDestinationAccessorTest::tearDown() {
+    accessor->destroy();
+    delete accessor;
+    delete cf;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsDestinationAccessorTest::test() {
+
+    DummySession s;
+    
+    // Create a queue destination
+    cms::Destination* d = accessor->resolveDestinationName(&s, "hello");
+    CPPUNIT_ASSERT( d != NULL );
+    
+    // Make sure it's a queue.
+    cms::Queue* queue1 = dynamic_cast<cms::Queue*>(d);
+    CPPUNIT_ASSERT( queue1 != NULL );
+    
+    // Get the same queue again and make sure it's the same object
+    d = accessor->resolveDestinationName(&s, "hello");
+    cms::Queue* queue2 = dynamic_cast<cms::Queue*>(d);
+    CPPUNIT_ASSERT( queue2 == queue1 );
+    
+    // Change type to topics
+    accessor->setPubSubDomain(true);
+    CPPUNIT_ASSERT( accessor->isPubSubDomain() == true );
+    
+    // Get the same dest and make sure it's a topic.
+    d = accessor->resolveDestinationName(&s, "hello");
+    cms::Topic* topic1 = dynamic_cast<cms::Topic*>(d);
+    CPPUNIT_ASSERT( topic1 != NULL );    
+}
+
+

Added: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h?rev=609227&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h Sat Jan  5 14:07:06 2008
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_CMSUTIL_CMSDESTINATIONACCESSORTEST_H_
+#define _ACTIVEMQ_CMSUTIL_CMSDESTINATIONACCESSORTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/cmsutil/CmsDestinationAccessor.h>
+
+namespace activemq{
+namespace cmsutil{
+
+    class DummyConnectionFactory;
+    
+    class CmsDestinationAccessorTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE( CmsDestinationAccessorTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();               
+             
+
+        class MyAccessor : public CmsDestinationAccessor {
+        
+        public:
+            
+            virtual ~MyAccessor(){}
+            
+            virtual cms::Connection* createConnection() throw (cms::CMSException) {
+                return CmsDestinationAccessor::createConnection();
+            }
+                
+            virtual cms::Session* createSession(cms::Connection* con) 
+                throw (cms::CMSException) {
+                return CmsDestinationAccessor::createSession(con);
+            }
+            virtual cms::Destination* resolveDestinationName( 
+                cms::Session* session, 
+                const std::string& destName ) throw (cms::CMSException) {
+                return CmsDestinationAccessor::resolveDestinationName(session,destName);
+            }
+        };
+        
+        MyAccessor* accessor;
+        DummyConnectionFactory* cf;
+        
+    public:
+
+        CmsDestinationAccessorTest() {}
+        virtual ~CmsDestinationAccessorTest() {}
+
+        virtual void setUp();
+        virtual void tearDown();
+        
+        void test();
+    };
+
+}}
+
+#endif /*_ACTIVEMQ_CMSUTIL_CMSDESTINATIONACCESSORTEST_H_*/

Added: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnection.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnection.h?rev=609227&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnection.h (added)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnection.h Sat Jan  5 14:07:06 2008
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+#ifndef ACTIVEMQ_CMSUTIL_DUMMYCONNECTION_H_
+#define ACTIVEMQ_CMSUTIL_DUMMYCONNECTION_H_
+
+#include <cms/Connection.h>
+#include <activemq/cmsutil/DummySession.h>
+
+namespace activemq {
+namespace cmsutil {
+
+    class DummyConnection : public cms::Connection {
+    private:
+        
+        cms::ExceptionListener* listener;
+        std::string clientId;
+        
+    public:
+
+        virtual ~DummyConnection() {}
+
+        virtual void close() throw( cms::CMSException ) {            
+        }
+        
+        virtual void start() throw( cms::CMSException ) {            
+        }
+        
+        virtual void stop() throw( cms::CMSException ) {            
+        }
+
+        virtual cms::Session* createSession() throw ( cms::CMSException ) {
+            return new DummySession();
+        }
+                
+        virtual cms::Session* createSession( cms::Session::AcknowledgeMode ackMode ) 
+            throw ( cms::CMSException ) {
+            
+            DummySession* s = new DummySession();
+            s->setAcknowledgeMode(ackMode);
+            return s;
+        }
+
+        virtual std::string getClientID() const {
+            return clientId;
+        }
+        
+        virtual void setClientID( const std::string& id ) {
+            this->clientId = id;
+        }
+
+        virtual cms::ExceptionListener* getExceptionListener() const {
+            return listener;
+        }
+
+        virtual void setExceptionListener( cms::ExceptionListener* listener ) {
+            this->listener = listener;
+        }
+    };
+    
+}}
+
+#endif /*ACTIVEMQ_CMSUTIL_DUMMYCONNECTION_H_*/

Added: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnectionFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnectionFactory.h?rev=609227&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnectionFactory.h (added)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummyConnectionFactory.h Sat Jan  5 14:07:06 2008
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+#ifndef ACTIVEMQ_CMSUTIL_DUMMYCONNECTIONFACTORY_H_
+#define ACTIVEMQ_CMSUTIL_DUMMYCONNECTIONFACTORY_H_
+
+#include <cms/ConnectionFactory.h>
+#include <activemq/cmsutil/DummyConnection.h>
+
+namespace activemq {
+namespace cmsutil {
+
+    class DummyConnectionFactory : public cms::ConnectionFactory {
+        
+    public:
+
+        virtual ~DummyConnectionFactory() {}
+
+        virtual cms::Connection* createConnection() throw ( cms::CMSException ) {
+            
+            return new DummyConnection();
+        }
+
+        virtual cms::Connection* createConnection( const std::string& username,
+                                                   const std::string& password )
+            throw ( cms::CMSException ) {
+            
+            return new DummyConnection();
+        }
+
+        virtual cms::Connection* createConnection( const std::string& username,
+                                                   const std::string& password,
+                                                   const std::string& clientId )
+            throw ( cms::CMSException ) {
+            
+            DummyConnection* c = new DummyConnection();
+            c->setClientID(clientId);
+            
+            return c;
+        }
+    };
+    
+}}
+
+#endif /*ACTIVEMQ_CMSUTIL_DUMMYCONNECTIONFACTORY_H_*/

Modified: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummySession.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummySession.h?rev=609227&r1=609226&r2=609227&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummySession.h (original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DummySession.h Sat Jan  5 14:07:06 2008
@@ -1,3 +1,20 @@
+/*
+ * 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.
+ */
+
 #ifndef ACTIVEMQ_CMSUTIL_DUMMYSESSION_H_
 #define ACTIVEMQ_CMSUTIL_DUMMYSESSION_H_
 
@@ -9,88 +26,100 @@
 namespace cmsutil {
 
     class DummySession : public cms::Session {
+    
+    private:
+        
+        cms::Session::AcknowledgeMode mode;
         
     public:
 
-            virtual ~DummySession() {}
+        DummySession() {
+            this->mode = cms::Session::AUTO_ACKNOWLEDGE;
+        }
+        
+        virtual ~DummySession() {}
 
-            virtual void close() throw( cms::CMSException ){}
+        virtual void close() throw( cms::CMSException ){}
             
-            virtual void commit() throw ( cms::CMSException ) {}
+        virtual void commit() throw ( cms::CMSException ) {}
             
-            virtual void rollback() throw ( cms::CMSException ) {}
+        virtual void rollback() throw ( cms::CMSException ) {}
 
-            virtual cms::MessageConsumer* createConsumer(
-                const cms::Destination* destination )
-                    throw ( cms::CMSException ) { return NULL; }
-
-            virtual cms::MessageConsumer* createConsumer( 
-                const cms::Destination* destination,
-                const std::string& selector )
-                    throw ( cms::CMSException ) {
-                return NULL;
-            }
-            
-            virtual cms::MessageConsumer* createConsumer( 
-                const cms::Destination* destination,
-                const std::string& selector,
-                bool noLocal )
-                    throw ( cms::CMSException ) { return NULL; }
-
-            virtual cms::MessageConsumer* createDurableConsumer(
-                const cms::Topic* destination,
-                const std::string& name,
-                const std::string& selector,
-                bool noLocal = false )
-                    throw ( cms::CMSException ) { return NULL; }
-
-            virtual cms::MessageProducer* createProducer( const cms::Destination* destination )
+        virtual cms::MessageConsumer* createConsumer(
+            const cms::Destination* destination )
                 throw ( cms::CMSException ) { return NULL; }
 
-            virtual cms::Queue* createQueue( const std::string& queueName )
-                throw ( cms::CMSException ) {
-                return new activemq::connector::stomp::StompQueue(queueName);
-            }
-            
-            virtual cms::Topic* createTopic( const std::string& topicName )
+        virtual cms::MessageConsumer* createConsumer( 
+            const cms::Destination* destination,
+            const std::string& selector )
                 throw ( cms::CMSException ) {
-                return new activemq::connector::stomp::StompTopic(topicName);
-            }
+            return NULL;
+        }
+        
+        virtual cms::MessageConsumer* createConsumer( 
+            const cms::Destination* destination,
+            const std::string& selector,
+            bool noLocal )
+                throw ( cms::CMSException ) { return NULL; }
 
-            virtual cms::TemporaryQueue* createTemporaryQueue()
+        virtual cms::MessageConsumer* createDurableConsumer(
+            const cms::Topic* destination,
+            const std::string& name,
+            const std::string& selector,
+            bool noLocal = false )
                 throw ( cms::CMSException ) { return NULL; }
 
-            virtual cms::TemporaryTopic* createTemporaryTopic()
-                throw ( cms::CMSException ){ return NULL; }
+        virtual cms::MessageProducer* createProducer( const cms::Destination* destination )
+            throw ( cms::CMSException ) { return NULL; }
+
+        virtual cms::Queue* createQueue( const std::string& queueName )
+            throw ( cms::CMSException ) {
+            return new activemq::connector::stomp::StompQueue(queueName);
+        }
+            
+        virtual cms::Topic* createTopic( const std::string& topicName )
+            throw ( cms::CMSException ) {
+            return new activemq::connector::stomp::StompTopic(topicName);
+        }
 
-            virtual cms::Message* createMessage() 
-                throw ( cms::CMSException ){ return NULL; }
+        virtual cms::TemporaryQueue* createTemporaryQueue()
+            throw ( cms::CMSException ) { return NULL; }
 
-            virtual cms::BytesMessage* createBytesMessage() 
-                throw ( cms::CMSException){ return NULL; }
+        virtual cms::TemporaryTopic* createTemporaryTopic()
+            throw ( cms::CMSException ){ return NULL; }
 
-            virtual cms::BytesMessage* createBytesMessage(
-                const unsigned char* bytes,
-                std::size_t bytesSize ) 
-                    throw ( cms::CMSException){
-                return NULL;
-            }
+        virtual cms::Message* createMessage() 
+            throw ( cms::CMSException ){ return NULL; }
 
-            virtual cms::TextMessage* createTextMessage() 
-                throw ( cms::CMSException ){ return NULL; }
+        virtual cms::BytesMessage* createBytesMessage() 
+            throw ( cms::CMSException){ return NULL; }
 
-            virtual cms::TextMessage* createTextMessage( const std::string& text ) 
-                throw ( cms::CMSException ){ return NULL; }
+        virtual cms::BytesMessage* createBytesMessage(
+            const unsigned char* bytes,
+            std::size_t bytesSize ) 
+                throw ( cms::CMSException){
+            return NULL;
+        }
 
-            virtual cms::MapMessage* createMapMessage() 
-                throw ( cms::CMSException ){ return NULL; }
+        virtual cms::TextMessage* createTextMessage() 
+            throw ( cms::CMSException ){ return NULL; }
 
-            virtual cms::Session::AcknowledgeMode getAcknowledgeMode() const { return cms::Session::AUTO_ACKNOWLEDGE; }
+        virtual cms::TextMessage* createTextMessage( const std::string& text ) 
+            throw ( cms::CMSException ){ return NULL; }
 
-            virtual bool isTransacted() const{ return false; }
+        virtual cms::MapMessage* createMapMessage() 
+            throw ( cms::CMSException ){ return NULL; }
+
+        virtual cms::Session::AcknowledgeMode getAcknowledgeMode() const { return mode; }
+        virtual void setAcknowledgeMode(cms::Session::AcknowledgeMode mode) { 
+            this->mode = mode; 
+        }
+
+        virtual bool isTransacted() const{ return mode==cms::Session::SESSION_TRANSACTED; }
  
-            virtual void unsubscribe( const std::string& name ) 
-                throw ( cms::CMSException ){}
+        virtual void unsubscribe( const std::string& name ) 
+            throw ( cms::CMSException ){}
+        
     };
     
 }}