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 2006/05/15 15:39:33 UTC
svn commit: r406628 [10/10] - in /incubator/activemq/trunk/openwire-cpp: ./
src/gram/java/org/apache/activemq/openwire/tool/ src/gram/script/
src/main/cpp/activemq/ src/main/cpp/activemq/command/
src/main/cpp/activemq/protocol/ src/main/cpp/activemq/pr...
Added: incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSuite.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSuite.cpp?rev=406628&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSuite.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSuite.cpp Mon May 15 06:38:57 2006
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * 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.
+ */
+#include "TestSuite.hpp"
+
+#include "TestSynchQueue.hpp"
+#include "TestAsynchQueue.hpp"
+#include "TestAsynchTopic.hpp"
+#include "TestLocalTXCommit.hpp"
+
+/*
+ *
+ */
+TestSuite::TestSuite()
+{
+ this->name = NULL ;
+ this->trace = false ;
+ this->connection = NULL ;
+}
+
+/*
+ *
+ */
+TestSuite::~TestSuite()
+{
+ // no-op
+}
+
+/*
+ *
+ */
+void TestSuite::setURI(const char* uri)
+{
+ this->uri = new Uri(uri) ;
+}
+
+/*
+ *
+ */
+void TestSuite::setSingle(const char* name)
+{
+ this->name = name ;
+}
+
+/*
+ *
+ */
+void TestSuite::setUp() throw (TraceException)
+{
+ p<IConnectionFactory> factory ;
+
+ cout << "Connecting to ActiveMQ broker..." << endl ;
+ factory = new ConnectionFactory( this->uri ) ;
+ connection = factory->createConnection() ;
+
+ this->unitTests["SynchQueue"] = new TestSynchQueue( connection ) ;
+ this->unitTests["AsynchQueue"] = new TestAsynchQueue( connection ) ;
+ this->unitTests["AsynchTopic"] = new TestAsynchTopic( connection ) ;
+ this->unitTests["LocalTXCommit"] = new TestLocalTXCommit( connection ) ;
+}
+
+/*
+ *
+ */
+void TestSuite::execute() throw (TraceException)
+{
+
+ try
+ {
+ // Set up test suite
+ setUp() ;
+ }
+ catch( TraceException& e )
+ {
+ cout << "Failed to set up test suite. " << e.what() << endl ;
+ exit(-1) ;
+ }
+
+ if( name != NULL )
+ runSingle( name ) ;
+ else
+ runAll() ;
+
+ try
+ {
+ // Tear down test suite
+ tearDown() ;
+ }
+ catch( TraceException& e )
+ {
+ cout << "Failed to tear down test suite. " << e.what() << endl ;
+ exit(-1) ;
+ }
+}
+
+/*
+ *
+ */
+void TestSuite::tearDown() throw (TraceException)
+{
+ if( connection != NULL )
+ connection->close() ;
+}
+
+/*
+ *
+ */
+p<string> TestSuite::toString()
+{
+ p<string> str = new string("ActiveMQ C++ Client Test Suite") ;
+ return str ;
+}
+
+/*
+ *
+ */
+void TestSuite::runSingle(const char* name) throw (TraceException)
+{
+ // Find unit test
+ map< string, p<IUnitTest> >::iterator tempIter ;
+ string key = string(name) ;
+
+ try
+ {
+ // Locate given unit test
+ tempIter = unitTests.find(key) ;
+ if( tempIter == unitTests.end() )
+ {
+ cout << "No unit test named [" << name << "] found." << endl ;
+ exit(-1) ;
+ }
+ string info ;
+
+ info.assign( tempIter->second->toString()->c_str() ) ;
+
+ // Pad with spaces up to 71 chars
+ for( int i = (int)info.length() ; i < 71 ; i++ )
+ info.append(" ") ;
+
+ cout << info.c_str() ;
+
+ tempIter->second->setUp() ;
+ tempIter->second->execute() ;
+ tempIter->second->tearDown() ;
+
+ cout << "[ OK ]" << endl ;
+ }
+ catch( TraceException& e )
+ {
+ cout << "[FAILED]" << endl ;
+ cout << " " << e.what() << endl ;
+ }
+}
+
+/*
+ *
+ */
+void TestSuite::runAll() throw (TraceException)
+{
+ map< string, p<IUnitTest> >::iterator tempIter ;
+
+ // Loop through and execute all unit tests
+ for( tempIter = unitTests.begin() ;
+ tempIter != unitTests.end() ;
+ tempIter++ )
+ {
+ string info ;
+
+ info.assign( tempIter->second->toString()->c_str() ) ;
+
+ // Pad with spaces up to 71 chars
+ for( int i = (int)info.length() ; i < 71 ; i++ )
+ info.append(" ") ;
+
+ cout << info.c_str() ;
+
+ try
+ {
+ tempIter->second->setUp() ;
+ tempIter->second->execute() ;
+ tempIter->second->tearDown() ;
+
+ cout << "[ OK ]" << endl ;
+ }
+ catch( TraceException& e )
+ {
+ cout << "[FAILED]" << endl ;
+ cout << " " << e.what() << endl ;
+ }
+ }
+}
+
+/*
+ * Main entry point.
+ */
+int main(int argc, char *argv[])
+{
+ TestSuite suite ;
+
+ // Print usage if no arguments was supplied
+ if( argc <= 1 )
+ {
+ cout << "usage: test \"uri\" [name]" << endl ;
+ cout << " uri The URI to the ActiveMQ broker, surrounded with quotation marks" << endl ;
+ cout << " name The name of a single unit test to execute" << endl ;
+ exit(-1) ;
+ }
+
+ // Check cmdline args for URI
+ // Sample URI: "tcp://192.168.64.142:61616?trace=false&protocol=openwire&encoding=none"
+ for( int i = 0 ; i < argc ; i++ )
+ {
+ // Skip program name
+ if( i == 0 )
+ continue ;
+
+ // Assume URI
+ if( i == 1 )
+ suite.setURI( argv[i] ) ;
+ // Assume unit test name
+ if( i == 2 )
+ suite.setSingle( argv[i] ) ;
+ }
+ suite.execute() ;
+}
Added: incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSuite.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSuite.hpp?rev=406628&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSuite.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSuite.hpp Mon May 15 06:38:57 2006
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * 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.
+ */
+#ifndef TestSuite_hpp_
+#define TestSuite_hpp_
+
+#include <exception>
+#include <iostream>
+#include <map>
+#include <string>
+
+#include "cms/IConnection.hpp"
+#include "cms/IConnectionFactory.hpp"
+#include "activemq/ConnectionFactory.hpp"
+#include "activemq/Connection.hpp"
+#include "ppr/TraceException.hpp"
+#include "ppr/net/Uri.hpp"
+#include "ppr/util/ifr/p"
+
+#include "IUnitTest.hpp"
+
+using namespace apache::activemq;
+using namespace apache::cms;
+using namespace apache::ppr;
+using namespace apache::ppr::net;
+using namespace ifr;
+using namespace std;
+
+class TestSuite : public IUnitTest
+{
+private:
+ p<IConnection> connection ;
+ p<Uri> uri ;
+ map< string, p<IUnitTest> > unitTests ;
+ const char* name ;
+ bool trace ;
+
+public:
+ TestSuite() ;
+ virtual ~TestSuite() ;
+
+ virtual void setURI(const char* uri) ;
+ virtual void setSingle(const char* name) ;
+
+ virtual void setUp() throw (TraceException) ;
+ virtual void execute() throw (TraceException) ;
+ virtual void tearDown() throw (TraceException) ;
+ virtual p<string> toString() ;
+
+protected:
+ void runSingle(const char* name) throw (TraceException) ;
+ void runAll() throw (TraceException) ;
+} ;
+
+#endif /*TestSuite_hpp_*/
Added: incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSynchQueue.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSynchQueue.cpp?rev=406628&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSynchQueue.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSynchQueue.cpp Mon May 15 06:38:57 2006
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * 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.
+ */
+#include "TestSynchQueue.hpp"
+
+/*
+ *
+ */
+TestSynchQueue::TestSynchQueue(p<IConnection> connection)
+{
+ this->connection = connection ;
+}
+
+/*
+ *
+ */
+TestSynchQueue::~TestSynchQueue()
+{
+ // no-op
+}
+
+/*
+ *
+ */
+void TestSynchQueue::setUp() throw (exception)
+{
+ // Create a session
+ session = connection->createSession() ;
+}
+
+/*
+ *
+ */
+void TestSynchQueue::execute() throw (exception)
+{
+ p<IQueue> queue ;
+ p<IMessageConsumer> consumer ;
+ p<IMessageProducer> producer ;
+ p<ITextMessage> reqMessage,
+ rspMessage ;
+ p<PropertyMap> props ;
+ MapItemHolder item ;
+
+ // Connect to queue
+ queue = session->getQueue("FOO.BAR") ;
+
+ // Create a consumer and producer
+ consumer = session->createConsumer(queue) ;
+ producer = session->createProducer(queue) ;
+ producer->setPersistent(true) ;
+
+ // Create a message
+ reqMessage = session->createTextMessage("Hello World!") ;
+ reqMessage->setJMSCorrelationID("abc") ;
+ reqMessage->setJMSXGroupID("cheese") ;
+ props = reqMessage->getProperties() ;
+ (*props)["someHeader"] = MapItemHolder( "James" ) ;
+
+ // Send message
+ producer->send(reqMessage) ;
+
+ // Receive and wait for a message
+ rspMessage = p_dyncast<ITextMessage> (consumer->receive()) ;
+ if( rspMessage == NULL )
+ throw TraceException("Received a null message") ;
+ else
+ {
+ props = rspMessage->getProperties() ;
+ item = (*props)["someHeader"] ;
+
+ // Verify message
+ if( rspMessage->getJMSCorrelationID()->compare("abc") != 0 )
+ throw TraceException("Returned message has invalid correlation ID") ;
+ if( rspMessage->getJMSXGroupID()->compare("cheese") != 0 )
+ throw TraceException("Returned message has invalid group ID") ;
+ if( rspMessage->getText()->compare("Hello World!") != 0 )
+ throw TraceException("Returned message has altered body text") ;
+ if( item.getString()->compare("James") != 0 )
+ throw TraceException("Returned message has invalid properties") ;
+ }
+}
+
+/*
+ *
+ */
+void TestSynchQueue::tearDown() throw (exception)
+{
+ // Clean up
+ session->close() ;
+ session = NULL ;
+}
+
+p<string> TestSynchQueue::toString()
+{
+ p<string> str = new string("Send/receive a text message to a queue synchronously") ;
+ return str ;
+}
Added: incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSynchQueue.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSynchQueue.hpp?rev=406628&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSynchQueue.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/test/cpp/TestSynchQueue.hpp Mon May 15 06:38:57 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * 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.
+ */
+#ifndef TestSynchQueue_hpp_
+#define TestSynchQueue_hpp_
+
+#include <exception>
+#include <string>
+
+#include "cms/IConnection.hpp"
+#include "ppr/TraceException.hpp"
+#include "ppr/util/ifr/p"
+
+#include "IUnitTest.hpp"
+
+using namespace apache::cms;
+using namespace apache::ppr;
+using namespace ifr;
+using namespace std;
+
+class TestSynchQueue : public IUnitTest
+{
+private:
+ p<IConnection> connection ;
+ p<ISession> session ;
+
+public:
+ TestSynchQueue(p<IConnection> connection) ;
+ virtual ~TestSynchQueue() ;
+
+ virtual void setUp() throw (exception) ;
+ virtual void execute() throw (exception) ;
+ virtual void tearDown() throw (exception) ;
+ virtual p<string> toString() ;
+} ;
+
+#endif /*TestSynchQueue_hpp_*/