[asterisk-scf-commits] asterisk-scf/integration/routing.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Thu Sep 16 17:32:56 CDT 2010
branch "master" has been updated
via fa4a5c47a5c099524f9ef6c6571b9080b4f5040e (commit)
from 6e97cdd14ec23fa68073bf42a4ab7797c74456c6 (commit)
Summary of changes:
test/CMakeLists.txt | 13 +
test/MockBridge.cpp | 98 +++++++
test/MockBridge.h | 49 ++++
test/MockBridgeManager.cpp | 54 ++++
test/MockBridgeManager.h | 40 +++
test/MockEndpointLocator.cpp | 101 +++++++
test/MockEndpointLocator.h | 46 ++++
test/MockSession.cpp | 103 +++++++
test/MockSession.h | 56 ++++
test/MockSessionEndpoint.cpp | 66 +++++
test/MockSessionEndpoint.h | 52 ++++
test/SharedTestData.h | 59 ++++
test/TestRouting.cpp | 604 +++++++-----------------------------------
13 files changed, 829 insertions(+), 512 deletions(-)
create mode 100644 test/MockBridge.cpp
create mode 100644 test/MockBridge.h
create mode 100644 test/MockBridgeManager.cpp
create mode 100644 test/MockBridgeManager.h
create mode 100644 test/MockEndpointLocator.cpp
create mode 100644 test/MockEndpointLocator.h
create mode 100644 test/MockSession.cpp
create mode 100644 test/MockSession.h
create mode 100644 test/MockSessionEndpoint.cpp
create mode 100644 test/MockSessionEndpoint.h
create mode 100644 test/SharedTestData.h
- Log -----------------------------------------------------------------
commit fa4a5c47a5c099524f9ef6c6571b9080b4f5040e
Author: Ken Hunt <ken.hunt at digium.com>
Date: Thu Sep 16 17:30:47 2010 -0500
Refactoring unit test classes into multiple files for readability.
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 06b43e6..658f5e5 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -4,7 +4,20 @@ hydra_component_add_slice(RoutingTest RoutingIf)
hydra_component_add_slice(RoutingTest ServiceLocatorIf)
hydra_component_add_slice(RoutingTest SessionCommunicationsIf)
hydra_component_add_slice(RoutingTest BridgingIf)
+
hydra_component_add_file(RoutingTest TestRouting.cpp)
+hydra_component_add_file(RoutingTest SharedTestData.h)
+hydra_component_add_file(RoutingTest MockBridgeManager.h)
+hydra_component_add_file(RoutingTest MockBridgeManager.cpp)
+hydra_component_add_file(RoutingTest MockBridge.h)
+hydra_component_add_file(RoutingTest MockBridge.cpp)
+hydra_component_add_file(RoutingTest MockSession.h)
+hydra_component_add_file(RoutingTest MockSession.cpp)
+hydra_component_add_file(RoutingTest MockSessionEndpoint.h)
+hydra_component_add_file(RoutingTest MockSessionEndpoint.cpp)
+hydra_component_add_file(RoutingTest MockEndpointLocator.h)
+hydra_component_add_file(RoutingTest MockEndpointLocator.cpp)
+
hydra_component_add_ice_libraries(RoutingTest IceStorm)
hydra_component_add_boost_libraries(RoutingTest unit_test_framework)
hydra_component_build_standalone(RoutingTest)
diff --git a/test/MockBridge.cpp b/test/MockBridge.cpp
new file mode 100644
index 0000000..65dca0d
--- /dev/null
+++ b/test/MockBridge.cpp
@@ -0,0 +1,98 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#define BOOST_TEST_DYN_LINK
+
+#include <Ice/Ice.h>
+
+#include "MockBridge.h"
+#include "SharedTestData.h"
+
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::Bridging::V1;
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+class BridgeSessionListener : public SessionListener
+{
+public:
+ BridgeSessionListener(MockBridge *bridge)
+ {
+ }
+
+ // The listener overrides...
+
+ virtual void connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session, const ::Ice::Current& = ::Ice::Current())
+ {
+ mBridge->connected(session);
+ }
+
+ virtual void flashed(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
+ {
+ }
+
+ virtual void held(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
+ {
+ }
+
+ virtual void progressing(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current& = ::Ice::Current())
+ {
+ }
+
+ virtual void ringing(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
+ {
+ }
+
+ virtual void stopped(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current& = ::Ice::Current())
+ {
+ }
+
+ virtual void unheld(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
+ {
+ }
+
+private:
+ MockBridge *mBridge;
+};
+typedef IceUtil::Handle<BridgeSessionListener> BridgeSessionListenerPtr;
+
+
+MockBridge::MockBridge(SessionSeq sessions, BridgeListenerPrx listener) : mSessions(sessions)
+{
+ mListener = new BridgeSessionListener(this);
+ Ice::ObjectPrx objectPrx = SharedTestData::instance.adapter_in->addWithUUID(mListener);
+ SessionListenerPrx listenerPrx = SessionListenerPrx::checkedCast(objectPrx);
+
+ SessionSeq::iterator s;
+ for (s = mSessions.begin(); s != mSessions.end(); ++s)
+ {
+ (*s)->addListener(listenerPrx);
+ }
+}
+
+MockBridge::~MockBridge()
+{
+ SharedTestData::instance.adapter_in->remove(SharedTestData::instance.communicator_in->stringToIdentity(mListener->ice_id()));
+}
+
+void MockBridge::addSessions(const SessionSeq& newSessions, const ::Ice::Current&)
+{
+ mSessions.reserve( mSessions.size() + newSessions.size());
+ mSessions.insert( mSessions.end(), newSessions.begin(), newSessions.end());
+}
+
+
+void MockBridge::connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session)
+{
+ SharedTestData::instance.mConnected = true;
+}
+
+}; // RoutingTest
+}; // AsteriskSCF
\ No newline at end of file
diff --git a/test/MockBridge.h b/test/MockBridge.h
new file mode 100644
index 0000000..d29e678
--- /dev/null
+++ b/test/MockBridge.h
@@ -0,0 +1,49 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#pragma once
+
+#include <Ice/Ice.h>
+#include "SessionCommunications/Bridging/BridgingIf.h"
+#include "SessionCommunications/SessionCommunicationsIf.h"
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+class BridgeSessionListener;
+typedef IceUtil::Handle<BridgeSessionListener> BridgeSessionListenerPtr;
+
+class MockBridge : public AsteriskSCF::SessionCommunications::Bridging::V1::Bridge
+{
+public:
+ MockBridge(AsteriskSCF::SessionCommunications::V1::SessionSeq sessions, AsteriskSCF::SessionCommunications::Bridging::V1::BridgeListenerPrx listener);
+ ~MockBridge();
+
+ virtual void addSessions(const AsteriskSCF::SessionCommunications::V1::SessionSeq& newSessions, const ::Ice::Current&);
+ virtual void destroy(const ::Ice::Current& ) {}
+ virtual void removeSessions(const AsteriskSCF::SessionCommunications::V1::SessionSeq&, const ::Ice::Current&) {}
+
+ virtual AsteriskSCF::SessionCommunications::V1::SessionSeq listSessions(const ::Ice::Current&)
+ {
+ return mSessions;
+ }
+
+ virtual void shutdown(const ::Ice::Current&) {}
+ virtual void addListener(const AsteriskSCF::SessionCommunications::Bridging::V1::BridgeListenerPrx&, const ::Ice::Current& ) {}
+ virtual void removeListener(const AsteriskSCF::SessionCommunications::Bridging::V1::BridgeListenerPrx&, const ::Ice::Current& ) {}
+
+ void connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session);
+
+private:
+ AsteriskSCF::SessionCommunications::V1::SessionSeq mSessions;
+ BridgeSessionListenerPtr mListener;
+};
+
+}; // RoutingTest
+}; // AsteriskSCF
diff --git a/test/MockBridgeManager.cpp b/test/MockBridgeManager.cpp
new file mode 100644
index 0000000..dc4b82e
--- /dev/null
+++ b/test/MockBridgeManager.cpp
@@ -0,0 +1,54 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#define BOOST_TEST_DYN_LINK
+
+#include <Ice/Ice.h>
+
+#include "MockBridgeManager.h"
+#include "MockBridge.h"
+#include "SharedTestData.h"
+
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::Bridging::V1;
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+void MockBridgeManager::addListener(const BridgeManagerListenerPrx&, const ::Ice::Current& )
+{
+}
+
+BridgePrx MockBridgeManager::createBridge(const SessionSeq& sessions, const BridgeListenerPrx& listener, const ::Ice::Current&)
+{
+ BridgePtr bridge = new MockBridge(sessions, listener);
+ mBridgeServants.push_back(bridge);
+
+ Ice::ObjectPrx objectPrx = SharedTestData::instance.adapter_in->addWithUUID(bridge);
+ BridgePrx bridgePrx = BridgePrx::checkedCast(objectPrx);
+ mBridges.push_back(bridgePrx);
+
+ return bridgePrx;
+}
+
+void MockBridgeManager::removeListener(const BridgeManagerListenerPrx&, const ::Ice::Current& )
+{
+}
+
+BridgeSeq MockBridgeManager::listBridges(const ::Ice::Current&)
+{
+ return mBridges;
+}
+
+void MockBridgeManager::shutdown(const ::Ice::Current&)
+{
+}
+
+}; // RoutingTest
+}; // AsteriskSCF
\ No newline at end of file
diff --git a/test/MockBridgeManager.h b/test/MockBridgeManager.h
new file mode 100644
index 0000000..2d402ca
--- /dev/null
+++ b/test/MockBridgeManager.h
@@ -0,0 +1,40 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#pragma once
+
+#include <Ice/Ice.h>
+#include "SessionCommunications/Bridging/BridgingIf.h"
+#include "SessionCommunications/SessionCommunicationsIf.h"
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+class MockBridgeManager : public AsteriskSCF::SessionCommunications::Bridging::V1::BridgeManager
+{
+public:
+ MockBridgeManager()
+ {
+ }
+
+ virtual void addListener(const AsteriskSCF::SessionCommunications::Bridging::V1::BridgeManagerListenerPrx&, const ::Ice::Current& );
+ virtual AsteriskSCF::SessionCommunications::Bridging::V1::BridgePrx createBridge(const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions, const AsteriskSCF::SessionCommunications::Bridging::V1::BridgeListenerPrx& listener, const ::Ice::Current&);
+ virtual void removeListener(const AsteriskSCF::SessionCommunications::Bridging::V1::BridgeManagerListenerPrx&, const ::Ice::Current& );
+ virtual AsteriskSCF::SessionCommunications::Bridging::V1::BridgeSeq listBridges(const ::Ice::Current& = ::Ice::Current());
+ virtual void shutdown(const ::Ice::Current& = ::Ice::Current());
+
+private:
+ std::vector<AsteriskSCF::SessionCommunications::Bridging::V1::BridgePtr> mBridgeServants;
+ AsteriskSCF::SessionCommunications::Bridging::V1::BridgeSeq mBridges;
+};
+typedef ::IceInternal::Handle<MockBridgeManager> MockBridgeManagerPtr;
+
+
+}; // RoutingTest
+}; // AsteriskSCF
diff --git a/test/MockEndpointLocator.cpp b/test/MockEndpointLocator.cpp
new file mode 100644
index 0000000..0840a50
--- /dev/null
+++ b/test/MockEndpointLocator.cpp
@@ -0,0 +1,101 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#define BOOST_TEST_DYN_LINK
+
+#include <Ice/Ice.h>
+
+#include "EndpointIf.h"
+#include "RoutingIf.h"
+#include "MockEndpointLocator.h"
+#include "SharedTestData.h"
+
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::Bridging::V1;
+using namespace AsteriskSCF::Core::Routing::V1;
+using namespace AsteriskSCF::Core::Endpoint::V1;
+using namespace std;
+
+typedef AsteriskSCF::Core::Endpoint::V1::EndpointSeq::iterator EndpointIterator;
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+AsteriskSCF::Core::Endpoint::V1::EndpointSeq MockEndpointLocator::lookup(const ::std::string& destination, const ::Ice::Current&)
+{
+ AsteriskSCF::Core::Endpoint::V1::EndpointSeq endpoints;
+ cout << "MockEndpointLocator::lookup() entered with destination = " << destination << endl << flush;
+
+ for (EndpointIterator e=mEndpointPrxList.begin(); e!= mEndpointPrxList.end();++e)
+ {
+ cout << "MockEndpointLocator::lookup() comparing destination to " << (*e)->getId() << endl << flush;
+
+ BaseEndpointPrx ep = *e;
+ if ((*e)->getId() == destination)
+ {
+ cout << "MockEndpointLocator::lookup() found a match." << endl << flush;
+ endpoints.push_back(ep);
+ }
+ }
+
+ if (endpoints.size() == 0)
+ {
+ throw DestinationNotFoundException(destination);
+ }
+ return endpoints;
+}
+
+void MockEndpointLocator::perTestCleanup()
+{
+ vector<MockSessionEndpointPtr>::iterator i;
+ for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+ {
+ (*i)->perTestCleanup();
+ }
+}
+
+void MockEndpointLocator::clear()
+{
+ vector<MockSessionEndpointPtr>::iterator i;
+ for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+ {
+ SharedTestData::instance.adapter_in->remove(SharedTestData::instance.communicator_in->stringToIdentity((*i)->ice_id()));
+ }
+
+ mEndpointPrxList.clear();
+ mEndpoints.clear();
+}
+
+MockSessionEndpointPtr MockEndpointLocator::addEndpoint(string id)
+{
+ MockSessionEndpointPtr endpoint = new MockSessionEndpoint(id);
+ mEndpoints.push_back(endpoint);
+ Ice::ObjectPrx prx = SharedTestData::instance.adapter_in->addWithUUID(endpoint);
+ mEndpointPrxList.push_back(BaseEndpointPrx::checkedCast(prx));
+ return endpoint;
+}
+
+/**
+ * Like lookup, but for the local channel we are simulating.
+ */
+MockSessionEndpointPtr MockEndpointLocator::localLookup(string id)
+{
+ vector<MockSessionEndpointPtr>::iterator i;
+ for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+ {
+ if ((*i)->getId() == id)
+ {
+ return (*i);
+ }
+ }
+ return 0;
+}
+
+}; // RoutingTest
+}; // As
\ No newline at end of file
diff --git a/test/MockEndpointLocator.h b/test/MockEndpointLocator.h
new file mode 100644
index 0000000..32f7075
--- /dev/null
+++ b/test/MockEndpointLocator.h
@@ -0,0 +1,46 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#pragma once
+
+#include <Ice/Ice.h>
+
+#include "MockSessionEndpoint.h"
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+/**
+ * A locator for our mock channel's endpoints.
+ */
+class MockEndpointLocator : public AsteriskSCF::Core::Routing::V1::EndpointLocator
+{
+public:
+ // Overrides
+ virtual AsteriskSCF::Core::Endpoint::V1::EndpointSeq lookup(const ::std::string& destination, const ::Ice::Current&);
+
+ // Implementation
+ void perTestCleanup();
+ void clear();
+ MockSessionEndpointPtr addEndpoint(std::string id);
+
+ /**
+ * Like lookup, but for the local channel we are simulating.
+ */
+ MockSessionEndpointPtr localLookup(std::string id);
+
+private:
+ AsteriskSCF::Core::Endpoint::V1::EndpointSeq mEndpointPrxList;
+ std::vector<MockSessionEndpointPtr> mEndpoints;
+};
+typedef ::IceInternal::Handle<MockEndpointLocator> MockEndpointLocatorPtr;
+
+}; // RoutingTest
+}; // AsteriskSCF
+
diff --git a/test/MockSession.cpp b/test/MockSession.cpp
new file mode 100644
index 0000000..db8d5ab
--- /dev/null
+++ b/test/MockSession.cpp
@@ -0,0 +1,103 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#define BOOST_TEST_DYN_LINK
+
+#include <Ice/Ice.h>
+
+#include "MockSession.h"
+#include "SharedTestData.h"
+
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::Bridging::V1;
+using namespace std;
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+SessionInfoPtr MockSession::addListener(const SessionListenerPrx& listener, const Ice::Current&)
+{
+ mListeners.push_back(listener);
+
+ return mSessionInfo;
+}
+
+void MockSession::connect(const Ice::Current&)
+{
+ vector<SessionListenerPrx>::iterator i;
+ for(i = mListeners.begin(); i != mListeners.end(); ++i)
+ {
+ (*i)->connected(mMyPrx);
+ }
+}
+
+void MockSession::flash(const Ice::Current&)
+{
+}
+
+SessionEndpointPrx MockSession::getEndpoint(const Ice::Current&)
+{
+ return mEndpointPrx;
+}
+
+SessionInfoPtr MockSession::getInfo(const Ice::Current&)
+{
+ return mSessionInfo;
+}
+
+AsteriskSCF::Media::V1::SessionPrx MockSession::getMediaSession(const Ice::Current&)
+{
+ return 0;
+}
+
+void MockSession::hold(const ::Ice::Current&)
+{
+}
+
+void MockSession::progress(const ResponseCodePtr&, const ::Ice::Current&)
+{
+}
+
+void MockSession::removeListener(const SessionListenerPrx&, const ::Ice::Current&)
+{
+}
+
+void MockSession::ring(const ::Ice::Current&)
+{
+}
+
+void MockSession::start(const ::Ice::Current&)
+{
+ cout << "Session started." << endl;
+
+ vector<SessionListenerPrx>::iterator i;
+ for(i = mListeners.begin(); i != mListeners.end(); ++i)
+ {
+ // Auto-answer!
+ (*i)->connected(mMyPrx);
+ }
+}
+
+void MockSession::stop(const ResponseCodePtr&, const ::Ice::Current&)
+{
+ cout << "Session stopped." << endl;
+}
+
+void MockSession::unhold(const ::Ice::Current&)
+{
+}
+
+void MockSession::setProxy(SessionPrx sessionPrx)
+{
+ mMyPrx = sessionPrx;
+}
+
+
+}; // RoutingTest
+}; // AsteriskSCF
diff --git a/test/MockSession.h b/test/MockSession.h
new file mode 100644
index 0000000..7a42d68
--- /dev/null
+++ b/test/MockSession.h
@@ -0,0 +1,56 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#pragma once
+
+#include <Ice/Ice.h>
+#include "SessionCommunicationsIf.h"
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+class MockSession : public AsteriskSCF::SessionCommunications::V1::Session
+{
+public:
+ MockSession(std::string sessionId, AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx endpointPrx)
+ : mId(sessionId), mEndpointPrx(endpointPrx), mSessionInfo(new AsteriskSCF::SessionCommunications::V1::SessionInfo())
+ {
+ }
+
+public:
+ // Overrides
+
+ virtual AsteriskSCF::SessionCommunications::V1::SessionInfoPtr addListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current&);
+ virtual void connect(const Ice::Current&);
+ virtual void flash(const Ice::Current&);
+ virtual AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx getEndpoint(const Ice::Current&);
+ virtual AsteriskSCF::SessionCommunications::V1::SessionInfoPtr getInfo(const Ice::Current&);
+ virtual AsteriskSCF::Media::V1::SessionPrx getMediaSession(const Ice::Current&);
+ virtual void hold(const ::Ice::Current&);
+ virtual void progress(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current&);
+ virtual void removeListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, const ::Ice::Current&);
+ virtual void ring(const ::Ice::Current&);
+ virtual void start(const ::Ice::Current&);
+ virtual void stop(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current&);
+ virtual void unhold(const ::Ice::Current&);
+
+public:
+ void setProxy(AsteriskSCF::SessionCommunications::V1::SessionPrx sessionPrx);
+
+private:
+ std::string mId;
+ AsteriskSCF::SessionCommunications::V1::SessionPrx mMyPrx;
+ AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx mEndpointPrx;
+ std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> mListeners;
+ AsteriskSCF::SessionCommunications::V1::SessionInfoPtr mSessionInfo;
+};
+typedef IceUtil::Handle<MockSession> MockSessionPtr;
+
+}; // RoutingTest
+}; // AsteriskSCF
diff --git a/test/MockSessionEndpoint.cpp b/test/MockSessionEndpoint.cpp
new file mode 100644
index 0000000..904d825
--- /dev/null
+++ b/test/MockSessionEndpoint.cpp
@@ -0,0 +1,66 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#define BOOST_TEST_DYN_LINK
+
+#include <boost/lexical_cast.hpp>
+#include <boost/test/test_tools.hpp>
+#include <Ice/Ice.h>
+
+#include "MockSessionEndpoint.h"
+#include "SharedTestData.h"
+
+using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace std;
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+SessionPrx MockSessionEndpoint::createSession(const string& dest, const SessionListenerPrx& listener, const ::Ice::Current&)
+{
+ string sessionId = dest + "_" + mId + "_" + boost::lexical_cast<string>(++mCounter);
+
+ BOOST_MESSAGE("SessionEndpoint creating session with Id = " + sessionId);
+
+ MockSessionPtr session = new MockSession(sessionId, mProxy);
+ mSessions.push_back(session);
+
+ Ice::ObjectPrx prx = SharedTestData::instance.adapter_in->add(session, SharedTestData::instance.communicator_in->stringToIdentity(sessionId));
+ SessionPrx sessionPrx = SessionPrx::checkedCast(prx);
+ mSessionPrxList.push_back(sessionPrx);
+
+ session->setProxy(sessionPrx);
+
+ return sessionPrx;
+}
+
+SessionSeq MockSessionEndpoint::getSessions(const ::Ice::Current&)
+{
+ return mSessionPrxList;
+}
+
+void MockSessionEndpoint::setProxy(SessionEndpointPrx proxy)
+{
+ mProxy = proxy;
+}
+
+void MockSessionEndpoint::perTestCleanup()
+{
+ vector<MockSessionPtr>::iterator i;
+ for(i = mSessions.begin(); i != mSessions.end(); ++i)
+ {
+ string id = (*i)->ice_id();
+ SharedTestData::instance.adapter_in->remove(SharedTestData::instance.communicator_in->stringToIdentity(id));
+ }
+
+ mSessions.clear();
+}
+
+}; // RoutingTest
+}; // AsteriskSCF
\ No newline at end of file
diff --git a/test/MockSessionEndpoint.h b/test/MockSessionEndpoint.h
new file mode 100644
index 0000000..1daad6c
--- /dev/null
+++ b/test/MockSessionEndpoint.h
@@ -0,0 +1,52 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#pragma once
+
+#include <Ice/Ice.h>
+#include "SessionCommunicationsIf.h"
+#include "MockSession.h"
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+
+/**
+ * A simple endpoint implemenation.
+ */
+ class MockSessionEndpoint : public AsteriskSCF::SessionCommunications::V1::SessionEndpoint
+{
+public:
+ // Constructors
+ MockSessionEndpoint(const std::string& id) : mId(id), mCounter(0) {}
+
+public:
+ // Overrides
+
+ virtual AsteriskSCF::SessionCommunications::V1::SessionPrx createSession(const std::string& dest, const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const ::Ice::Current& = ::Ice::Current());
+ virtual AsteriskSCF::SessionCommunications::V1::SessionSeq getSessions(const ::Ice::Current&);
+
+public:
+ // Implementation
+
+ void setProxy(AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx proxy);
+ std::string getId(const Ice::Current& = ::Ice::Current()) {return mId;}
+ void perTestCleanup();
+
+private:
+ std::vector<MockSessionPtr> mSessions;
+ std::vector<AsteriskSCF::SessionCommunications::V1::SessionPrx> mSessionPrxList;
+ std::string mId;
+ AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx mProxy;
+ int mCounter;
+};
+typedef IceUtil::Handle<MockSessionEndpoint> MockSessionEndpointPtr;
+
+
+}; // RoutingTest
+}; // AsteriskSCF
diff --git a/test/SharedTestData.h b/test/SharedTestData.h
new file mode 100644
index 0000000..bbc4197
--- /dev/null
+++ b/test/SharedTestData.h
@@ -0,0 +1,59 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+#pragma once
+
+#include <Ice/Ice.h>
+
+#include "MockBridgeManager.h"
+#include "MockEndpointLocator.h"
+
+#include "RoutingIf.h"
+#include "ServiceLocatorIf.h"
+#include "BridgingIf.h"
+#include "SessionCommunicationsIf.h"
+
+namespace AsteriskSCF
+{
+namespace RoutingTest
+{
+/**
+ * Pseudo singleton for sharing data among test artifacts.
+ */
+class SharedTestData
+{
+public:
+ static SharedTestData instance;
+
+ // Communicator for outgoing stuff.
+ Ice::CommunicatorPtr communicator_out;
+
+ // Communicator for incoming stuff. This is where we add the test servants.
+ Ice::CommunicatorPtr communicator_in;
+
+ Ice::ObjectAdapterPtr adapter_in;
+ Ice::ObjectAdapterPtr adapter_out;
+
+ //A proxy to the actual routing service
+ AsteriskSCF::Core::Routing::V1::LocatorRegistryPrx locatorRegistry;
+ AsteriskSCF::SessionCommunications::V1::SessionRouterPrx sessionRouter;
+
+ // Our own EndpointLocator to server up endpoints to the RoutingService, emulating a channel.
+ MockEndpointLocatorPtr mEndpointLocator;
+ AsteriskSCF::Core::Routing::V1::EndpointLocatorPrx mEndpointLocatorPrx;
+ AsteriskSCF::Core::Routing::V1::RegExSeq mRegExIds;
+
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx mServiceLocatorManagement;
+
+ MockBridgeManagerPtr mBridgeManager;
+
+ bool mConnected;
+};
+
+}; // RoutingTest
+}; // AsteriskSCF
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index 76bae90..8f36516 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -9,17 +9,21 @@
#define BOOST_TEST_MODULE ServiceLocatorTestSuite
#define BOOST_TEST_NO_MAIN
-#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/debug.hpp>
#include <Ice/Ice.h>
+#include "SharedTestData.h"
+#include "MockBridge.h"
+#include "MockBridgeManager.h"
+#include "MockSession.h"
+#include "MockSessionEndpoint.h"
+
+#include "RoutingIf.h"
+#include "BridgingIf.h"
#include "ServiceLocatorIf.h"
-#include "Core/Routing/RoutingIf.h"
-#include "SessionCommunications/Bridging/BridgingIf.h"
-#include "Core/Discovery/ServiceLocatorIf.h"
-#include "SessionCommunications/SessionCommunicationsIf.h"
+#include "SessionCommunicationsIf.h"
using namespace std;
using namespace AsteriskSCF::Core::Routing::V1;
@@ -27,197 +31,12 @@ using namespace AsteriskSCF::Core::Endpoint::V1;
using namespace AsteriskSCF::SessionCommunications::V1;
using namespace AsteriskSCF::SessionCommunications::Bridging::V1;
using namespace AsteriskSCF::Core::Discovery::V1;
-
-class TestEndpointLocatorImpl;
-typedef ::IceInternal::Handle<TestEndpointLocatorImpl> TestEndpointLocatorImplPtr;
-
-class BridgeSessionListener;
-typedef IceUtil::Handle<BridgeSessionListener> BridgeSessionListenerPtr;
-
-class BridgeManagerImpl;
-typedef IceUtil::Handle<BridgeManagerImpl> BridgeManagerImplPtr;
-
-class BridgeImpl;
+using namespace AsteriskSCF::RoutingTest;
/**
- * Sharing global setup stuff here.
+ * Instantiate our shared data.
*/
-struct SharedTestData
-{
-public:
- // Communicator for outgoing stuff
- Ice::CommunicatorPtr communicator_out;
-
- // Communicator for incoming stuff
- Ice::CommunicatorPtr communicator_in;
-
- Ice::ObjectAdapterPtr adapter_in;
- Ice::ObjectAdapterPtr adapter_out;
-
- //A proxy to the actual routing service
- LocatorRegistryPrx locatorRegistry;
- SessionRouterPrx sessionRouter;
-
- // Our own EndpointLocator to server up endpoints to the RoutingService, emulating a channel.
- TestEndpointLocatorImplPtr mEndpointLocator;
- EndpointLocatorPrx mEndpointLocatorPrx;
- RegExSeq mRegExIds;
-
- ServiceLocatorPrx mServiceLocator;
- ServiceLocatorManagementPrx mServiceLocatorManagement;
-
- BridgeManagerImplPtr mBridgeManager;
-
- bool mConnected;
-};
-static SharedTestData Testbed;
-
-
-class BridgeImpl : public Bridge
-{
-public:
- BridgeImpl(SessionSeq sessions, BridgeListenerPrx listener);
- ~BridgeImpl();
-
- virtual void addSessions(const SessionSeq& newSessions, const ::Ice::Current&);
- virtual void destroy(const ::Ice::Current& ) {}
- virtual void removeSessions(const SessionSeq&, const ::Ice::Current&) {}
-
- virtual SessionSeq listSessions(const ::Ice::Current&)
- {
- return mSessions;
- }
-
- virtual void shutdown(const ::Ice::Current&) {}
- virtual void addListener(const BridgeListenerPrx&, const ::Ice::Current& ) {}
- virtual void removeListener(const BridgeListenerPrx&, const ::Ice::Current& ) {}
-
- void connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session);
-
-private:
- SessionSeq mSessions;
- BridgeSessionListenerPtr mListener;
-};
-
-class BridgeSessionListener : public SessionListener
-{
-public:
- BridgeSessionListener(BridgeImpl *bridge)
- {
- }
-
- // The listener overrides...
-
- virtual void connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session, const ::Ice::Current& = ::Ice::Current())
- {
- mBridge->connected(session);
- }
-
- virtual void flashed(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
- {
- }
-
- virtual void held(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
- {
- }
-
- virtual void progressing(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current& = ::Ice::Current())
- {
- }
-
- virtual void ringing(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
- {
- }
-
- virtual void stopped(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const ::Ice::Current& = ::Ice::Current())
- {
- }
-
- virtual void unheld(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx&, const ::Ice::Current& = ::Ice::Current())
- {
- }
-
-private:
- BridgeImpl *mBridge;
-};
-typedef IceUtil::Handle<BridgeSessionListener> BridgeSessionListenerPtr;
-
-
-BridgeImpl::BridgeImpl(SessionSeq sessions, BridgeListenerPrx listener) : mSessions(sessions)
-{
- mListener = new BridgeSessionListener(this);
- Ice::ObjectPrx objectPrx = Testbed.adapter_in->addWithUUID(mListener);
- SessionListenerPrx listenerPrx = SessionListenerPrx::checkedCast(objectPrx);
-
- SessionSeq::iterator s;
- for (s = mSessions.begin(); s != mSessions.end(); ++s)
- {
- (*s)->addListener(listenerPrx);
- }
-}
-
-BridgeImpl::~BridgeImpl()
-{
- Testbed.adapter_in->remove(Testbed.communicator_in->stringToIdentity(mListener->ice_id()));
-}
-
-void BridgeImpl::addSessions(const SessionSeq& newSessions, const ::Ice::Current&)
-{
- mSessions.reserve( mSessions.size() + newSessions.size());
- mSessions.insert( mSessions.end(), newSessions.begin(), newSessions.end());
-}
-
-
-void BridgeImpl::connected(const ::AsteriskSCF::SessionCommunications::V1::SessionPrx& session)
-{
- Testbed.mConnected = true;
-}
-
-class BridgeManagerImpl : public BridgeManager
-{
-public:
- BridgeManagerImpl()
- {
- }
-
- virtual void addListener(const BridgeManagerListenerPrx&, const ::Ice::Current& )
- {
- }
-
- virtual BridgePrx createBridge(const SessionSeq& sessions, const BridgeListenerPrx& listener, const ::Ice::Current&)
- {
- BridgePtr bridge = new BridgeImpl(sessions, listener);
- mBridgeServants.push_back(bridge);
-
- Ice::ObjectPrx objectPrx = Testbed.adapter_in->addWithUUID(bridge);
- BridgePrx bridgePrx = BridgePrx::checkedCast(objectPrx);
- mBridges.push_back(bridgePrx);
-
- return bridgePrx;
- }
-
- virtual void removeListener(const BridgeManagerListenerPrx&, const ::Ice::Current& )
- {
- }
-
- virtual BridgeSeq listBridges(const ::Ice::Current& = ::Ice::Current())
- {
- return mBridges;
- }
-
- virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
- {
- }
-
-private:
- vector<BridgePtr> mBridgeServants;
- BridgeSeq mBridges;
-};
-
-typedef AsteriskSCF::Core::Endpoint::V1::EndpointSeq::iterator EndpointIterator;
-
-class SessionEndpointImpl;
-typedef IceUtil::Handle<SessionEndpointImpl> SessionEndpointImplPtr;
+SharedTestData SharedTestData::instance;
/* Cache the command line arguments so that Ice can be initialized within the global fixture. */
struct ArgCacheType
@@ -230,342 +49,103 @@ static ArgCacheType mCachedArgs;
const string LocatorObjectId("TestLocator");
-class SessionEndpointImpl;
-
-class SessionImpl : public Session
-{
-public:
- SessionImpl(string sessionId, SessionEndpointPrx endpointPrx)
- : mId(sessionId), mEndpointPrx(endpointPrx), mSessionInfo(new SessionInfo())
- {
- }
-
-public:
- // Overrides
-
- virtual SessionInfoPtr addListener(const SessionListenerPrx& listener, const Ice::Current&)
- {
- mListeners.push_back(listener);
-
- return mSessionInfo;
- }
-
- virtual void connect(const Ice::Current&)
- {
- vector<SessionListenerPrx>::iterator i;
- for(i = mListeners.begin(); i != mListeners.end(); ++i)
- {
- (*i)->connected(mMyPrx);
- }
- }
-
- virtual void flash(const Ice::Current&)
- {
- }
-
- virtual SessionEndpointPrx getEndpoint(const Ice::Current&)
- {
- return mEndpointPrx;
- }
-
- virtual SessionInfoPtr getInfo(const Ice::Current&)
- {
- return mSessionInfo;
- }
-
- virtual AsteriskSCF::Media::V1::SessionPrx getMediaSession(const Ice::Current&)
- {
- return 0;
- }
-
- virtual void hold(const ::Ice::Current&)
- {
- }
-
- virtual void progress(const ResponseCodePtr&, const ::Ice::Current&)
- {
- }
-
- virtual void removeListener(const SessionListenerPrx&, const ::Ice::Current&)
- {
- }
-
- virtual void ring(const ::Ice::Current&)
- {
- }
-
- virtual void start(const ::Ice::Current&)
- {
- cout << "Session started." << endl;
-
- vector<SessionListenerPrx>::iterator i;
- for(i = mListeners.begin(); i != mListeners.end(); ++i)
- {
- // Auto-answer!
- (*i)->connected(mMyPrx);
- }
- }
-
- virtual void stop(const ResponseCodePtr&, const ::Ice::Current&)
- {
- cout << "Session stopped." << endl;
- }
-
- virtual void unhold(const ::Ice::Current&)
- {
- }
-
- void setProxy(SessionPrx sessionPrx)
- {
- mMyPrx = sessionPrx;
- }
-
-private:
- string mId;
- SessionPrx mMyPrx;
- SessionEndpointPrx mEndpointPrx;
- vector<SessionListenerPrx> mListeners;
- SessionInfoPtr mSessionInfo;
-};
-typedef IceUtil::Handle<SessionImpl> SessionImplPtr;
-
/**
- * A simple endpoint implemenation.
+ * A global fixture for Ice initialization.
+ * Provides setup/teardown for the entire set of tests.
*/
-class SessionEndpointImpl : public SessionEndpoint
+struct GlobalIceFixture
{
-public:
- SessionEndpointImpl(const std::string& id) : mId(id), mCounter(0) {}
-
- virtual SessionPrx createSession(const string& dest, const SessionListenerPrx& listener, const ::Ice::Current& = ::Ice::Current())
+ GlobalIceFixture()
{
- string sessionId = dest + "_" + mId + "_" + boost::lexical_cast<string>(++mCounter);
+ BOOST_TEST_MESSAGE("Setting up Basic Rounting Service test fixture");
- BOOST_MESSAGE("SessionEndpoint creating session with Id=" + sessionId);
+ ::boost::debug::detect_memory_leaks(false);
+ ::boost::unit_test::unit_test_log.set_stream( std::cout );
- SessionImplPtr session = new SessionImpl(sessionId, mProxy);
- mSessions.push_back(session);
+ int status = 0;
+ try
+ {
+ Ice::PropertiesPtr props = Ice::createProperties(mCachedArgs.argc, mCachedArgs.argv);
+ Ice::InitializationData initData;
+ initData.properties = props;
- Ice::ObjectPrx prx = Testbed.adapter_in->add(session, Testbed.communicator_in->stringToIdentity(sessionId));
- SessionPrx sessionPrx = SessionPrx::checkedCast(prx);
- mSessionPrxList.push_back(sessionPrx);
+ // Set up incoming adapter. This is where we'll publish our proxies.
+ SharedTestData::instance.communicator_in = Ice::initialize(initData);
- session->setProxy(sessionPrx);
+ string test = props->getProperty("LocatorRegistry.Proxy");
- return sessionPrx;
- }
+ SharedTestData::instance.adapter_in = SharedTestData::instance.communicator_in->createObjectAdapterWithEndpoints("TestRoutingAdapterIn", "default -p 10070");
- virtual SessionSeq getSessions(const ::Ice::Current&)
- {
- return mSessionPrxList;
- }
+ // Serve up our own EndpointLocator, since we're emulating a channel.
+ MockEndpointLocator *locator = new MockEndpointLocator();
+ SharedTestData::instance.mEndpointLocator = locator;
+ SharedTestData::instance.adapter_in->add(SharedTestData::instance.mEndpointLocator, SharedTestData::instance.communicator_in->stringToIdentity(LocatorObjectId));
- void setProxy(SessionEndpointPrx proxy)
- {
- mProxy = proxy;
- }
+ SharedTestData::instance.adapter_in->activate();
- std::string getId(const Ice::Current& = ::Ice::Current()) {return mId;}
+ // Now that the adapter has been activated, get a local proxy to our EndpointLocator.
+ Ice::ObjectPrx locatorObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(LocatorObjectId));
+ SharedTestData::instance.mEndpointLocatorPrx = EndpointLocatorPrx::checkedCast(locatorObjectPrx);
- void perTestCleanup()
- {
- vector<SessionImplPtr>::iterator i;
- for(i = mSessions.begin(); i != mSessions.end(); ++i)
- {
- string id = (*i)->ice_id();
- Testbed.adapter_in->remove(Testbed.communicator_in->stringToIdentity(id));
- }
+ // Now set up outgoing adapter. This will be used for proxies we want to call out to the
+ // the unit under test on.
+ SharedTestData::instance.communicator_out = Ice::initialize(initData);
+ SharedTestData::instance.adapter_out = SharedTestData::instance.communicator_out->createObjectAdapterWithEndpoints("TestRoutingAdapterOut", "default -p 10071");
- mSessions.clear();
- }
+ // Get ref to Routing Service so we can test it. Getting direct for now, but
+ // need to test acquiring reference via ServiceLocator as well.
+ Ice::ObjectPrx locatorObj = SharedTestData::instance.communicator_out->propertyToProxy("LocatorRegistry.Proxy");
+ SharedTestData::instance.locatorRegistry = LocatorRegistryPrx::checkedCast(locatorObj);
-private:
- vector<SessionImplPtr> mSessions;
- vector<SessionPrx> mSessionPrxList;
- std::string mId;
- SessionEndpointPrx mProxy;
- int mCounter;
-};
+ // Get the ServiceLocator and ServiceLocator manager
-/**
- * A locator for our test channel's endpoints.
- */
-class TestEndpointLocatorImpl : public EndpointLocator
-{
-public:
- virtual AsteriskSCF::Core::Endpoint::V1::EndpointSeq lookup(const ::std::string& destination, const ::Ice::Current&)
- {
- AsteriskSCF::Core::Endpoint::V1::EndpointSeq endpoints;
- cout << "TestEndpointLocatorImpl::lookup() entered with destination = " << destination << endl << flush;
- for (EndpointIterator e=mEndpointPrxList.begin(); e!= mEndpointPrxList.end();++e)
- {
- cout << "TestEndpointLocatorImpl::lookup() comparing destination to " << (*e)->getId() << endl << flush;
+ if (!SharedTestData::instance.locatorRegistry)
+ {
+ throw "Invalid LocatorRegistry";
+ }
- BaseEndpointPrx ep = *e;
- if ((*e)->getId() == destination)
+ Ice::ObjectPrx routerObj = SharedTestData::instance.communicator_out->propertyToProxy("SessionRouter.Proxy");
+ SharedTestData::instance.sessionRouter = SessionRouterPrx::checkedCast(routerObj);
+
+ if (!SharedTestData::instance.sessionRouter)
{
- cout << "TestEndpointLocatorImpl::lookup() found a match." << endl << flush;
- endpoints.push_back(ep);
- }
- }
+ throw "Invalid SessionRouter";
+ }
- if (endpoints.size() == 0)
- {
- throw DestinationNotFoundException(destination);
- }
- return endpoints;
- }
+ PopulateEndpoints();
- void perTestCleanup()
- {
- vector<SessionEndpointImplPtr>::iterator i;
- for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
- {
- (*i)->perTestCleanup();
+ RegisterWithServiceLocator();
}
- }
-
- void clear()
- {
- vector<SessionEndpointImplPtr>::iterator i;
- for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+ catch (const Ice::Exception& ex)
{
- Testbed.adapter_in->remove(Testbed.communicator_in->stringToIdentity((*i)->ice_id()));
+ cerr << ex << endl;
+ status = 1;
}
-
- mEndpointPrxList.clear();
- mEndpoints.clear();
- }
-
- SessionEndpointImplPtr addEndpoint(string id)
- {
- SessionEndpointImplPtr endpoint = new SessionEndpointImpl(id);
- mEndpoints.push_back(endpoint);
- Ice::ObjectPrx prx = Testbed.adapter_in->addWithUUID(endpoint);
- mEndpointPrxList.push_back(BaseEndpointPrx::checkedCast(prx));
- return endpoint;
- }
-
- /**
- * Like lookup, but for the local channel we are simulating.
- */
- SessionEndpointImplPtr localLookup(string id)
- {
- vector<SessionEndpointImplPtr>::iterator i;
- for(i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+ catch (const char* msg)
{
- if ((*i)->getId() == id)
- {
- return (*i);
- }
+ cerr << msg << endl;
+ status = 1;
}
- return 0;
- }
-
- AsteriskSCF::Core::Endpoint::V1::EndpointSeq mEndpointPrxList;
- vector<SessionEndpointImplPtr> mEndpoints;
-};
-typedef ::IceInternal::Handle<TestEndpointLocatorImpl> TestEndpointLocatorImplPtr;
-
-/**
- * A global fixture for Ice initialization.
- * Provides setup/teardown for the entire set of tests.
- */
-struct GlobalIceFixture
-{
- GlobalIceFixture()
- {
- BOOST_TEST_MESSAGE("Setting up Basic Rounting Service test fixture");
-
- ::boost::debug::detect_memory_leaks(false);
- ::boost::unit_test::unit_test_log.set_stream( std::cout );
-
- int status = 0;
- try
- {
- Ice::PropertiesPtr props = Ice::createProperties(mCachedArgs.argc, mCachedArgs.argv);
- Ice::InitializationData initData;
- initData.properties = props;
-
- // Set up incoming adapter. This is where we'll publish our proxies.
- Testbed.communicator_in = Ice::initialize(initData);
-
- string test = props->getProperty("LocatorRegistry.Proxy");
-
- Testbed.adapter_in = Testbed.communicator_in->createObjectAdapterWithEndpoints("TestRoutingAdapterIn", "default -p 10070");
-
- // Serve up our own EndpointLocator, since we're emulating a channel.
- TestEndpointLocatorImpl *locator = new TestEndpointLocatorImpl();
- Testbed.mEndpointLocator = locator;
- Testbed.adapter_in->add(Testbed.mEndpointLocator, Testbed.communicator_in->stringToIdentity(LocatorObjectId));
-
- Testbed.adapter_in->activate();
-
- // Now that the adapter has been activated, get a local proxy to our EndpointLocator.
- Ice::ObjectPrx locatorObjectPrx = Testbed.adapter_in->createDirectProxy(Testbed.communicator_in->stringToIdentity(LocatorObjectId));
- Testbed.mEndpointLocatorPrx = EndpointLocatorPrx::checkedCast(locatorObjectPrx);
-
- // Now set up outgoing adapter. This will be used for proxies we want to call out to the
- // the unit under test on.
- Testbed.communicator_out = Ice::initialize(initData);
- Testbed.adapter_out = Testbed.communicator_out->createObjectAdapterWithEndpoints("TestRoutingAdapterOut", "default -p 10071");
-
- // Get ref to Routing Service so we can test it. Getting direct for now, but
- // need to test acquiring reference via ServiceLocator as well.
- Ice::ObjectPrx locatorObj = Testbed.communicator_out->propertyToProxy("LocatorRegistry.Proxy");
- Testbed.locatorRegistry = LocatorRegistryPrx::checkedCast(locatorObj);
-
- // Get the ServiceLocator and ServiceLocator manager
-
-
- if (!Testbed.locatorRegistry)
- {
- throw "Invalid LocatorRegistry";
- }
-
- Ice::ObjectPrx routerObj = Testbed.communicator_out->propertyToProxy("SessionRouter.Proxy");
- Testbed.sessionRouter = SessionRouterPrx::checkedCast(routerObj);
-
- if (!Testbed.sessionRouter)
- {
- throw "Invalid SessionRouter";
- }
-
- PopulateEndpoints();
-
- RegisterWithServiceLocator();
- }
- catch (const Ice::Exception& ex)
- {
- cerr << ex << endl;
- status = 1;
- }
- catch (const char* msg)
- {
- cerr << msg << endl;
- status = 1;
- }
-
- } // end Fixture() constructor
+ } // end Fixture() constructor
void RegisterWithServiceLocator()
{
// Get a proxy to the management interface for the Service Locator, so we can add
// our mock BridgeManager to the system.
- Testbed.mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(Testbed.communicator_in->propertyToProxy("LocatorServiceManagement.Proxy"));
+ SharedTestData::instance.mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(SharedTestData::instance.communicator_in->propertyToProxy("LocatorServiceManagement.Proxy"));
- if (Testbed.mServiceLocatorManagement == 0)
+ if (SharedTestData::instance.mServiceLocatorManagement == 0)
{
cout << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. Tests can't run without it. (not yet, anyway)" << endl;
return;
}
- Testbed.mBridgeManager = new BridgeManagerImpl();
+ SharedTestData::instance.mBridgeManager = new MockBridgeManager();
- Ice::ObjectPrx bridgeManagerObject = Testbed.adapter_in->add(Testbed.mBridgeManager, Testbed.communicator_in->stringToIdentity(Testbed.communicator_in->getProperties()->getProperty("BridgeManager.ServiceLocatorId")));
+ Ice::ObjectPrx bridgeManagerObject = SharedTestData::instance.adapter_in->add(SharedTestData::instance.mBridgeManager, SharedTestData::instance.communicator_in->stringToIdentity(SharedTestData::instance.communicator_in->getProperties()->getProperty("BridgeManager.ServiceLocatorId")));
BridgeManagerPrx bridgeManagerPrx = BridgeManagerPrx::checkedCast(bridgeManagerObject);
- ServiceManagementPrx management = ServiceManagementPrx::uncheckedCast(Testbed.mServiceLocatorManagement->addService(bridgeManagerPrx, "BridgeService"));
+ ServiceManagementPrx management = ServiceManagementPrx::uncheckedCast(SharedTestData::instance.mServiceLocatorManagement->addService(bridgeManagerPrx, "BridgeService"));
ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
genericparams->category = BridgeServiceDiscoveryCategory;
@@ -574,16 +154,16 @@ struct GlobalIceFixture
void PopulateEndpoints()
{
- Testbed.mEndpointLocator->clear();
+ SharedTestData::instance.mEndpointLocator->clear();
- Testbed.mEndpointLocator->addEndpoint("101");
- Testbed.mEndpointLocator->addEndpoint("102");
- Testbed.mEndpointLocator->addEndpoint("103");
+ SharedTestData::instance.mEndpointLocator->addEndpoint("101");
+ SharedTestData::instance.mEndpointLocator->addEndpoint("102");
+ SharedTestData::instance.mEndpointLocator->addEndpoint("103");
// Initialize the regular expressions for the ids that this channel will support.
// Use two strings just for kicks.
- Testbed.mRegExIds.push_back("101");
- Testbed.mRegExIds.push_back("10[23]"); // 102 or 103
+ SharedTestData::instance.mRegExIds.push_back("101");
+ SharedTestData::instance.mRegExIds.push_back("10[23]"); // 102 or 103
}
~GlobalIceFixture()
@@ -591,15 +171,15 @@ struct GlobalIceFixture
BOOST_TEST_MESSAGE("Tearing down service discovery test fixture");
- if (Testbed.communicator_in)
+ if (SharedTestData::instance.communicator_in)
{
- Testbed.communicator_in->shutdown();
- Testbed.communicator_in = 0;
+ SharedTestData::instance.communicator_in->shutdown();
+ SharedTestData::instance.communicator_in = 0;
}
- if (Testbed.communicator_out)
+ if (SharedTestData::instance.communicator_out)
{
- Testbed.communicator_out->shutdown();
- Testbed.communicator_out = 0;
+ SharedTestData::instance.communicator_out->shutdown();
+ SharedTestData::instance.communicator_out = 0;
}
}
private:
@@ -627,7 +207,7 @@ public:
{
try
{
- Testbed.locatorRegistry->addEndpointLocator("TestChannel", Testbed.mRegExIds, Testbed.mEndpointLocatorPrx);
+ SharedTestData::instance.locatorRegistry->addEndpointLocator("TestChannel", SharedTestData::instance.mRegExIds, SharedTestData::instance.mEndpointLocatorPrx);
}
catch (...)
{
@@ -639,8 +219,8 @@ public:
{
try
{
- Testbed.locatorRegistry->removeEndpointLocator("TestChannel");
- Testbed.mEndpointLocator->perTestCleanup();
+ SharedTestData::instance.locatorRegistry->removeEndpointLocator("TestChannel");
+ SharedTestData::instance.mEndpointLocator->perTestCleanup();
}
catch (...)
{
@@ -657,7 +237,7 @@ BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
bool addLocatorSucceeded(true);
try
{
- Testbed.locatorRegistry->addEndpointLocator("TestChannel", Testbed.mRegExIds, Testbed.mEndpointLocatorPrx);
+ SharedTestData::instance.locatorRegistry->addEndpointLocator("TestChannel", SharedTestData::instance.mRegExIds, SharedTestData::instance.mEndpointLocatorPrx);
}
catch (...)
{
@@ -670,7 +250,7 @@ BOOST_AUTO_TEST_CASE(AddAndRemoveEndpointLocator)
bool removeLocatorSucceeded(true);
try
{
- Testbed.locatorRegistry->removeEndpointLocator("TestChannel");
+ SharedTestData::instance.locatorRegistry->removeEndpointLocator("TestChannel");
}
catch (...)
@@ -693,7 +273,7 @@ BOOST_FIXTURE_TEST_CASE(LookupOwnEndpoint, PerTestFixture)
{
BOOST_TEST_MESSAGE("Looking up endpoint via Routing Service...");
string lookupVal = "102";
- AsteriskSCF::Core::Endpoint::V1::EndpointSeq seq = Testbed.locatorRegistry->lookup(lookupVal);
+ AsteriskSCF::Core::Endpoint::V1::EndpointSeq seq = SharedTestData::instance.locatorRegistry->lookup(lookupVal);
BOOST_TEST_MESSAGE(" ...lookup completed.");
@@ -729,18 +309,18 @@ BOOST_FIXTURE_TEST_CASE(RouteSession, PerTestFixture)
BOOST_TEST_MESSAGE("Local lookup of an endpoint...");
// Get our local 101 endpoint
- SessionEndpointImplPtr session101Endpoint = Testbed.mEndpointLocator->localLookup("101");
+ MockSessionEndpointPtr session101Endpoint = SharedTestData::instance.mEndpointLocator->localLookup("101");
BOOST_TEST_MESSAGE("Creating a session on our test endpoint...");
SessionPrx session = session101Endpoint->createSession("102", 0);
BOOST_CHECK(session != 0);
- Testbed.mConnected = false;
+ SharedTestData::instance.mConnected = false;
BOOST_TEST_MESSAGE("Routing the session...");
- Testbed.sessionRouter->routeSession(session, "102");
+ SharedTestData::instance.sessionRouter->routeSession(session, "102");
- BOOST_CHECK(Testbed.mConnected);
+ BOOST_CHECK(SharedTestData::instance.mConnected);
}
catch(const IceUtil::Exception &ie)
{
-----------------------------------------------------------------------
--
asterisk-scf/integration/routing.git
More information about the asterisk-scf-commits
mailing list