testsuite/src/c++/TestQos.cpp

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------
00002 Name:      TestQos.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Testing the ClientProperty Features
00006 -----------------------------------------------------------------------------*/
00007 #include "TestSuite.h"
00008 #include <iostream>
00009 #include <util/qos/SessionQos.h>
00010 #include <util/qos/StatusQosFactory.h>
00011 
00012 using namespace std;
00013 using namespace org::xmlBlaster::util;
00014 using namespace org::xmlBlaster::util::qos;
00015 
00021 namespace org { namespace xmlBlaster { namespace test {
00022 
00023 class TestQos : public TestSuite {
00024    
00025 private:
00026    string ME;
00027    Global& global_;
00028    I_Log&  log_;
00029    int     count_;
00030 public:
00031    TestQos(Global& global, const string& name) 
00032       : TestSuite(global.getArgs(), global.getArgc(), name, false),
00033         ME(name), 
00034         global_(global),
00035         log_(global.getLog("test")) 
00036    {
00037       count_ = 0;
00038    }
00039 
00040    virtual ~TestQos()
00041    {
00042    }
00043 
00044    void testSessionQos() 
00045    {
00046       log_.info(ME, "testSessionQos(): Starting tests ...");
00047       try {
00048          {
00049             string qos = "<session name='/node/http:/client/ticheta/3' timeout='86400000' maxSessions='10' \n" +
00050                  string("         clearSessions='false' reconnectSameClientOnly='false' sessionId='IIOP:01110728321B0222011028'/>\n");
00051      
00052             SessionQosFactory factory(global_);
00053             SessionQosData data = factory.readObject(qos);
00054 
00055             assertEquals(log_, ME, 3L, data.getPubSessionId(), "public sessionId");
00056             assertEquals(log_, ME, "ticheta", data.getSubjectId(), "subjectId");
00057             assertEquals(log_, ME, "http:", data.getClusterNodeId(), "http:");
00058             assertEquals(log_, ME, 86400000L, data.getTimeout(), "timeout");
00059             assertEquals(log_, ME, 10, data.getMaxSessions(), "maxSessions");
00060             assertEquals(log_, ME, false, data.getClearSessions(), "clearSessions");
00061             assertEquals(log_, ME, false, data.getReconnectSameClientOnly(), "reconnectSameClientOnly");
00062             assertEquals(log_, ME, "IIOP:01110728321B0222011028", data.getSecretSessionId(), "secret sessionId");
00063          }
00064       }
00065       catch(bad_cast b) {
00066          cout << "EXCEPTION: " << b.what() << endl;
00067          assert(0);
00068       }
00069    }
00070 
00071    void testStatusQos() 
00072    {
00073       log_.info(ME, "testSessionQos(): Starting tests ...");
00074       try {
00075          {
00076             StatusQosData data(global_);
00077             data.setState("OK");
00078             data.setStateInfo("OK-INFO");
00079             data.setKeyOid("dummyKey");
00080             data.setPersistent(true);
00081             data.setSubscriptionId("subId3");
00082 
00083             assertEquals(log_, ME, "OK", data.getState(), "state");
00084             assertEquals(log_, ME, "OK-INFO", data.getStateInfo(), "stateInfo");
00085             assertEquals(log_, ME, "dummyKey", data.getKeyOid(), "key");
00086             assertEquals(log_, ME, true, data.isPersistent(), "persistent");
00087             assertEquals(log_, ME, "subId3", data.getSubscriptionId(), "subId");
00088 
00089             StatusQosFactory factory(global_);
00090             StatusQosData data2 = factory.readObject(data.toXml());
00091 
00092             assertEquals(log_, ME, "OK", data2.getState(), "state");
00093             assertEquals(log_, ME, "OK-INFO", data2.getStateInfo(), "stateInfo");
00094             assertEquals(log_, ME, "dummyKey", data2.getKeyOid(), "key");
00095             assertEquals(log_, ME, true, data2.isPersistent(), "persistent");
00096             assertEquals(log_, ME, "subId3", data2.getSubscriptionId(), "subId");
00097 
00098          }
00099       }
00100       catch(bad_cast b) {
00101          cout << "EXCEPTION: " << b.what() << endl;
00102          assert(0);
00103       }
00104    }
00105 
00106    void setUp() {
00107    }
00108 
00109    void tearDown() {
00110    }
00111 };
00112    
00113 }}} // namespace
00114 
00115 
00116 
00117 using namespace org::xmlBlaster::test;
00118 
00119 int main(int args, char *argv[]) 
00120 {
00121    Global& glob = Global::getInstance();
00122    glob.initialize(args, argv);
00123 
00124    TestQos testObj(glob, "TestQos");
00125 
00126    testObj.setUp();
00127    testObj.testSessionQos();
00128    testObj.tearDown();
00129 
00130    testObj.setUp();
00131    testObj.testStatusQos();
00132    testObj.tearDown();
00133 
00134    return 0;
00135 }
00136 
00137