[asterisk-scf-commits] asterisk-scf/integration/routing.git branch "transfer" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Oct 13 20:43:21 CDT 2010


branch "transfer" has been updated
       via  d4c31d85cb3e32eaa9e723ab82e572a841ff0565 (commit)
      from  d8fcd1f7f0b249215fc53ae804997b2579920263 (commit)

Summary of changes:
 test/MockBridge.cpp          |   61 +++++++++++++++++++++++++++----
 test/MockBridge.h            |   24 +++++++------
 test/MockBridgeManager.cpp   |    6 ++--
 test/MockSession.cpp         |   18 +++++++++-
 test/MockSession.h           |   13 ++-----
 test/MockSessionEndpoint.cpp |    2 +-
 test/TestRouting.cpp         |   81 ++++++++++++++++++++++++++++++++++++++---
 7 files changed, 165 insertions(+), 40 deletions(-)


- Log -----------------------------------------------------------------
commit d4c31d85cb3e32eaa9e723ab82e572a841ff0565
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Wed Oct 13 20:42:50 2010 -0500

    Testing for call transfer operations.

diff --git a/test/MockBridge.cpp b/test/MockBridge.cpp
index e804aa0..7ff928a 100644
--- a/test/MockBridge.cpp
+++ b/test/MockBridge.cpp
@@ -63,17 +63,16 @@ private:
 typedef IceUtil::Handle<BridgeSessionListener> BridgeSessionListenerPtr;
 
 
-MockBridge::MockBridge(const SessionSeq& sessions, const BridgeListenerPrx& listener) : 
-    mSessions(sessions)
+MockBridge::MockBridge(const SessionSeq& sessions, const BridgeListenerPrx& listener) 
 {
    mListener = new BridgeSessionListener(this);
-   Ice::ObjectPrx objectPrx = SharedTestData::instance.adapterIn->addWithUUID(mListener);
-   SessionListenerPrx listenerPrx = SessionListenerPrx::checkedCast(objectPrx);
+   Ice::ObjectPrx listernerObjectPrx = SharedTestData::instance.adapterIn->addWithUUID(mListener);
+   mListenerPrx = SessionListenerPrx::checkedCast(listernerObjectPrx);
 
-   for (SessionSeq::iterator s = mSessions.begin(); s != mSessions.end(); ++s)
-   {
-      (*s)->addListener(listenerPrx);
-   }
+   Ice::ObjectPrx bridgeObjectPrx = SharedTestData::instance.adapterIn->addWithUUID(this);
+   mBridgePrx = BridgePrx::checkedCast(bridgeObjectPrx);
+
+   addSessions(sessions);
 }
 
 MockBridge::~MockBridge()
@@ -85,17 +84,63 @@ void MockBridge::addSessions(const SessionSeq& newSessions, const Ice::Current&)
 {
    mSessions.reserve( mSessions.size() + newSessions.size());
    mSessions.insert( mSessions.end(), newSessions.begin(), newSessions.end());
+
+   for (SessionSeq::const_iterator s = newSessions.begin(); s != newSessions.end(); ++s)
+   {
+       (*s)->setBridge(mBridgePrx, mListenerPrx);
+   }
+}
+
+void MockBridge::removeSessions(const SessionSeq& sessions, const Ice::Current&)
+{
+    for(SessionSeq::const_iterator s = sessions.begin(); s != sessions.end(); ++s)
+    {
+        removeSession(*s);
+    }
+}
+
+void MockBridge::removeSession(const SessionPrx& session)
+{
+    for(SessionSeq::iterator s = mSessions.begin(); s != mSessions.end(); ++s)
+    {
+        if ((*s) == session)
+        {
+            mSessions.erase(s);
+            return;
+        }
+    }
+    session->removeBridge(mListenerPrx);
+}
+
+SessionSeq MockBridge::listSessions(const Ice::Current&)
+{
+    return mSessions;
+}
+
+void MockBridge::addListener(const AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx&, const Ice::Current& )
+{
 }
 
 void MockBridge::removeListener(const AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx&, const Ice::Current& )
 {
 }
 
+void MockBridge::destroy(const Ice::Current&) 
+{
+}
+
+void MockBridge::shutdown(const Ice::Current&) 
+{
+}
+
 void MockBridge::replaceSession(const AsteriskSCF::SessionCommunications::V1::SessionPrx& sessionToReplace,
   const AsteriskSCF::SessionCommunications::V1::SessionSeq& newSessions,
   const Ice::Current&)
 {
     SharedTestData::instance.mSessionReplaced = true;
+
+    removeSession(sessionToReplace);
+    addSessions(newSessions);
 }
 
 void MockBridge::connected(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session)
diff --git a/test/MockBridge.h b/test/MockBridge.h
index 4b98987..32dcf20 100644
--- a/test/MockBridge.h
+++ b/test/MockBridge.h
@@ -25,28 +25,30 @@ public:
       const AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx& listener);
     ~MockBridge();
 
-    void addSessions(const AsteriskSCF::SessionCommunications::V1::SessionSeq& newSessions, const Ice::Current&);
-    void destroy(const Ice::Current& ) {}
-    void removeSessions(const AsteriskSCF::SessionCommunications::V1::SessionSeq&, const Ice::Current&) {}
-
-    AsteriskSCF::SessionCommunications::V1::SessionSeq listSessions(const Ice::Current&)
-    {
-        return mSessions;
-    }
-
-    void shutdown(const Ice::Current&) {}
-    void addListener(const AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx&, const Ice::Current& ) {}
+    // Overrides
+    void addSessions(const AsteriskSCF::SessionCommunications::V1::SessionSeq& newSessions, const Ice::Current& = ::Ice::Current());
+    void destroy(const Ice::Current& ) ;
+    void removeSessions(const AsteriskSCF::SessionCommunications::V1::SessionSeq&, const Ice::Current&);
+    AsteriskSCF::SessionCommunications::V1::SessionSeq listSessions(const Ice::Current&);
+
+    void shutdown(const Ice::Current&) ;
+    void addListener(const AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx&, const Ice::Current& );
     void removeListener(const AsteriskSCF::SessionCommunications::V1::BridgeListenerPrx&, const Ice::Current& );
 
     void replaceSession(const AsteriskSCF::SessionCommunications::V1::SessionPrx& sessionToReplace,
       const AsteriskSCF::SessionCommunications::V1::SessionSeq& newSessions,
       const Ice::Current&);
 
+    // Implementation
     void connected(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session);
+    void removeSession(const AsteriskSCF::SessionCommunications::V1::SessionPrx& session);
+    AsteriskSCF::SessionCommunications::V1::BridgePrx getProxy() {return mBridgePrx;}
 
 private:
     AsteriskSCF::SessionCommunications::V1::SessionSeq mSessions;
     BridgeSessionListenerPtr mListener;
+    AsteriskSCF::SessionCommunications::V1::SessionListenerPrx mListenerPrx;
+    AsteriskSCF::SessionCommunications::V1::BridgePrx mBridgePrx;
 };
 
 } // RoutingTest
diff --git a/test/MockBridgeManager.cpp b/test/MockBridgeManager.cpp
index ab7b21a..dd9ee06 100644
--- a/test/MockBridgeManager.cpp
+++ b/test/MockBridgeManager.cpp
@@ -26,11 +26,11 @@ void MockBridgeManager::addListener(const BridgeManagerListenerPrx&, const Ice::
 
 BridgePrx MockBridgeManager::createBridge(const SessionSeq& sessions, const BridgeListenerPrx& listener, const Ice::Current&) 
 {
-    BridgePtr bridge = new MockBridge(sessions, listener);
+    MockBridge *mockBridge = new MockBridge(sessions, listener);
+    BridgePtr bridge(mockBridge);
     mBridgeServants.push_back(bridge);
 
-    Ice::ObjectPrx objectPrx = SharedTestData::instance.adapterIn->addWithUUID(bridge);
-    BridgePrx bridgePrx = BridgePrx::checkedCast(objectPrx);
+    BridgePrx bridgePrx = mockBridge->getProxy();
     mBridges.push_back(bridgePrx);
 
     return bridgePrx;
diff --git a/test/MockSession.cpp b/test/MockSession.cpp
index 24e43ab..0de6135 100644
--- a/test/MockSession.cpp
+++ b/test/MockSession.cpp
@@ -20,6 +20,18 @@ namespace AsteriskSCF
 namespace RoutingTest
 {
 
+MockSession::MockSession(const string& legId, const string& sessionId, const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& endpointPrx) 
+    : mLegId(legId),
+      mId(sessionId), 
+      mEndpointPrx(endpointPrx), 
+      mSessionInfo(new AsteriskSCF::SessionCommunications::V1::SessionInfo()),
+      mBridgeSet(false),
+      mBridgeReplaced(false),
+      mBridgePrx(0)
+{
+   mSessionInfo->role = legId; // for testing
+}
+
 SessionInfoPtr MockSession::addListener(const SessionListenerPrx& listener, const Ice::Current&)
 {
     mListeners.push_back(listener);
@@ -100,12 +112,16 @@ BridgePrx MockSession::getBridge(const Ice::Current &)
    return mBridgePrx;
 }
 
-void MockSession::setBridge(const BridgePrx& bridge, 
+SessionInfoPtr MockSession::setBridge(const BridgePrx& bridge, 
                const SessionListenerPrx& listener, 
                const Ice::Current &)
 {
     mBridgePrx = bridge;
     mBridgeSet = true;
+
+    mListeners.push_back(listener);
+
+    return mSessionInfo;
 }
 
 void MockSession::removeBridge(const SessionListenerPrx& listener, 
diff --git a/test/MockSession.h b/test/MockSession.h
index 4fb9193..1c9dc0b 100644
--- a/test/MockSession.h
+++ b/test/MockSession.h
@@ -18,15 +18,7 @@ namespace RoutingTest
 class MockSession : public AsteriskSCF::SessionCommunications::V1::Session
 {
 public:
-    MockSession(const std::string& sessionId, const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& endpointPrx) 
-        : mId(sessionId), 
-          mEndpointPrx(endpointPrx), 
-          mSessionInfo(new AsteriskSCF::SessionCommunications::V1::SessionInfo()),
-          mBridgeSet(false),
-          mBridgeReplaced(false),
-          mBridgePrx(0)
-    {
-    }
+    MockSession(const std::string& legId, const std::string& sessionId, const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& endpointPrx);
 
 public:
     // Overrides 
@@ -45,7 +37,7 @@ public:
     void stop(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const Ice::Current&);
     void unhold(const Ice::Current&);
     AsteriskSCF::SessionCommunications::V1::BridgePrx getBridge(const Ice::Current &);
-    void setBridge(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current &);
+    AsteriskSCF::SessionCommunications::V1::SessionInfoPtr setBridge(const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge, const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current &);
     void removeBridge(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current &);
 
 public:
@@ -54,6 +46,7 @@ public:
 
 private:
     std::string mId;
+    std::string mLegId;
     AsteriskSCF::SessionCommunications::V1::SessionPrx mMyPrx;
     AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx mEndpointPrx;
     std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> mListeners;
diff --git a/test/MockSessionEndpoint.cpp b/test/MockSessionEndpoint.cpp
index 69f316e..510016e 100644
--- a/test/MockSessionEndpoint.cpp
+++ b/test/MockSessionEndpoint.cpp
@@ -28,7 +28,7 @@ SessionPrx MockSessionEndpoint::createSession(const string& dest, const SessionL
 
     BOOST_MESSAGE("SessionEndpoint creating session with Id = " + sessionId);
 
-    MockSessionPtr session = new MockSession(sessionId, mProxy);
+    MockSessionPtr session = new MockSession(mId, sessionId, mProxy);
     mSessions.push_back(session);
 
     Ice::ObjectPrx prx = SharedTestData::instance.adapterIn->add(session, SharedTestData::instance.communicatorIn->stringToIdentity(sessionId));
diff --git a/test/TestRouting.cpp b/test/TestRouting.cpp
index 63b072d..3857388 100644
--- a/test/TestRouting.cpp
+++ b/test/TestRouting.cpp
@@ -409,7 +409,7 @@ BOOST_FIXTURE_TEST_CASE(RouteSession, PerTestFixture)
     catch(const IceUtil::Exception &ie)
     {
         bool IceException(false);
-        string msg = "Exception routing session:";
+        string msg = "Exception in RouteSession:";
         msg += ie.what();
         BOOST_TEST_MESSAGE(msg);
         BOOST_CHECK(IceException);
@@ -417,13 +417,13 @@ BOOST_FIXTURE_TEST_CASE(RouteSession, PerTestFixture)
     catch (...)
     {
         bool unknownException(false);
-        BOOST_TEST_MESSAGE("Exception routing session.");
+        BOOST_TEST_MESSAGE("Exception in RouteSession:");
         BOOST_CHECK(unknownException);
     }
 }
 
 /** 
- * This tests if we can support blind transfer. 
+ * This tests blind transfer. 
  */
 BOOST_FIXTURE_TEST_CASE(BlindTransfer, PerTestFixture)
 {
@@ -445,13 +445,13 @@ BOOST_FIXTURE_TEST_CASE(BlindTransfer, PerTestFixture)
         SharedTestData::instance.sessionRouter->routeSession(session, "102");
 
         BridgePrx bridge = session->getBridge();
+        BOOST_CHECK(bridge != 0);
         BOOST_CHECK(SharedTestData::instance.mBridgeConnected);
 
         // Now transfer to a new extension. 
- // TBD...
- //       SharedTestData::instance.sessionRouter->connectBridgedSessionsWithDestination(session, "103");
+        SharedTestData::instance.sessionRouter->connectBridgedSessionsWithDestination(session, "103");
 
- //       BOOST_CHECK(SharedTestData::instance.mSessionReplaced);
+        BOOST_CHECK(SharedTestData::instance.mSessionReplaced);
     }
     catch(const IceUtil::Exception &ie)
     {
@@ -468,3 +468,72 @@ BOOST_FIXTURE_TEST_CASE(BlindTransfer, PerTestFixture)
         BOOST_CHECK(unknownException);
     }
 }
+
+/** 
+ * This tests attended transfer. 
+ */
+BOOST_FIXTURE_TEST_CASE(AttendedTransfer, PerTestFixture)
+{
+    try
+    {
+        BOOST_TEST_MESSAGE("Local lookup of an endpoint...");
+
+        // Get our local 101 endpoint
+        MockSessionEndpointPtr session101Endpoint = SharedTestData::instance.endpointLocator->localLookup("101");
+
+        BOOST_TEST_MESSAGE("Creating a session on our test endpoint...");
+        SessionPrx session101 = session101Endpoint->createSession("102", 0, Ice::Current());
+        BOOST_CHECK(session101 != 0);
+
+        SharedTestData::instance.mBridgeConnected = false;
+
+        BOOST_TEST_MESSAGE("Routing for the first pair...");
+        SharedTestData::instance.sessionRouter->routeSession(session101, "102");
+
+        BOOST_CHECK(SharedTestData::instance.mBridgeConnected);
+
+        // Setup another pair of call legs
+        MockSessionEndpointPtr session103Endpoint = SharedTestData::instance.endpointLocator->localLookup("103");
+
+        BOOST_TEST_MESSAGE("Creating a session on our next endpoint...");
+        SessionPrx session103 = session103Endpoint->createSession("104", 0, Ice::Current());
+        BOOST_CHECK(session103 != 0);
+
+        SharedTestData::instance.mBridgeConnected = false;
+        SharedTestData::instance.mSessionReplaced = false;
+
+        BOOST_TEST_MESSAGE("Routing the second pair...");
+        SharedTestData::instance.sessionRouter->routeSession(session103, "104");
+
+        BOOST_CHECK(SharedTestData::instance.mBridgeConnected);
+
+        // Now bridge 102 and 104 into the first pair's bridge
+        BridgePrx survivingBridge = session101->getBridge(); // Cache for testing.
+        SharedTestData::instance.sessionRouter->connectBridgedSessions(session101, session103);
+
+        BOOST_CHECK(SharedTestData::instance.mSessionReplaced);
+
+        SessionSeq sessions = survivingBridge->listSessions();
+        BOOST_CHECK(sessions.size() == 2);
+        
+        for(SessionSeq::iterator s = sessions.begin(); s != sessions.end(); ++s)
+        {
+            SessionInfoPtr sessionInfo = (*s)->getInfo();
+            BOOST_CHECK(sessionInfo->role == "102" || sessionInfo->role == "104");
+        }
+    }
+    catch(const IceUtil::Exception &ie)
+    {
+        bool IceException(false);
+        string msg = "Exception in AttendedTransfer:";
+        msg += ie.what();
+        BOOST_TEST_MESSAGE(msg);
+        BOOST_CHECK(IceException);
+    }
+    catch (...)
+    {
+        bool unknownException(false);
+        BOOST_TEST_MESSAGE("Exception in AttendedTransfer:");
+        BOOST_CHECK(unknownException);
+    }
+}

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/routing.git



More information about the asterisk-scf-commits mailing list