1 /*-----------------------------------------------------------------------------
  2 Name:      TestQos.cpp
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 Comment:   Testing the ClientProperty Features
  6 -----------------------------------------------------------------------------*/
  7 #include "TestSuite.h"
  8 #include <iostream>
  9 #include <util/qos/SessionQos.h>
 10 #include <util/qos/StatusQosFactory.h>
 11 
 12 using namespace std;
 13 using namespace org::xmlBlaster::util;
 14 using namespace org::xmlBlaster::util::qos;
 15 
 16 /**
 17  * Class test of ClientProperty.cpp
 18  * @see org::xmlBlaster::util::qos::ClientProperty 
 19  */
 20 
 21 namespace org { namespace xmlBlaster { namespace test {
 22 
 23 class TestQos : public TestSuite {
 24    
 25 private:
 26    string ME;
 27    Global& global_;
 28    I_Log&  log_;
 29    int     count_;
 30 public:
 31    TestQos(Global& global, const string& name) 
 32       : TestSuite(global.getArgs(), global.getArgc(), name, false),
 33         ME(name), 
 34         global_(global),
 35         log_(global.getLog("test")) 
 36    {
 37       count_ = 0;
 38    }
 39 
 40    virtual ~TestQos()
 41    {
 42    }
 43 
 44    void testSessionQos() 
 45    {
 46       log_.info(ME, "testSessionQos(): Starting tests ...");
 47       try {
 48          {
 49             string qos = "<session name='/node/http:/client/ticheta/3' timeout='86400000' maxSessions='10' \n" +
 50                  string("         clearSessions='false' reconnectSameClientOnly='false' sessionId='IIOP:01110728321B0222011028'/>\n");
 51      
 52             SessionQosFactory factory(global_);
 53             SessionQosData data = factory.readObject(qos);
 54 
 55             assertEquals(log_, ME, 3L, data.getPubSessionId(), "public sessionId");
 56             assertEquals(log_, ME, "ticheta", data.getSubjectId(), "subjectId");
 57             assertEquals(log_, ME, "http:", data.getClusterNodeId(), "http:");
 58             assertEquals(log_, ME, 86400000L, data.getTimeout(), "timeout");
 59             assertEquals(log_, ME, 10, data.getMaxSessions(), "maxSessions");
 60             assertEquals(log_, ME, false, data.getClearSessions(), "clearSessions");
 61             assertEquals(log_, ME, false, data.getReconnectSameClientOnly(), "reconnectSameClientOnly");
 62             assertEquals(log_, ME, "IIOP:01110728321B0222011028", data.getSecretSessionId(), "secret sessionId");
 63          }
 64       }
 65       catch(bad_cast b) {
 66          cout << "EXCEPTION: " << b.what() << endl;
 67          assert(0);
 68       }
 69    }
 70 
 71    void testStatusQos() 
 72    {
 73       log_.info(ME, "testSessionQos(): Starting tests ...");
 74       try {
 75          {
 76             StatusQosData data(global_);
 77             data.setState("OK");
 78             data.setStateInfo("OK-INFO");
 79             data.setKeyOid("dummyKey");
 80             data.setPersistent(true);
 81             data.setSubscriptionId("subId3");
 82 
 83             assertEquals(log_, ME, "OK", data.getState(), "state");
 84             assertEquals(log_, ME, "OK-INFO", data.getStateInfo(), "stateInfo");
 85             assertEquals(log_, ME, "dummyKey", data.getKeyOid(), "key");
 86             assertEquals(log_, ME, true, data.isPersistent(), "persistent");
 87             assertEquals(log_, ME, "subId3", data.getSubscriptionId(), "subId");
 88 
 89             StatusQosFactory factory(global_);
 90             StatusQosData data2 = factory.readObject(data.toXml());
 91 
 92             assertEquals(log_, ME, "OK", data2.getState(), "state");
 93             assertEquals(log_, ME, "OK-INFO", data2.getStateInfo(), "stateInfo");
 94             assertEquals(log_, ME, "dummyKey", data2.getKeyOid(), "key");
 95             assertEquals(log_, ME, true, data2.isPersistent(), "persistent");
 96             assertEquals(log_, ME, "subId3", data2.getSubscriptionId(), "subId");
 97 
 98          }
 99       }
100       catch(bad_cast b) {
101          cout << "EXCEPTION: " << b.what() << endl;
102          assert(0);
103       }
104    }
105 
106    void setUp() {
107    }
108 
109    void tearDown() {
110    }
111 };
112    
113 }}} // namespace
114 
115 
116 
117 using namespace org::xmlBlaster::test;
118 
119 int main(int args, char *argv[]) 
120 {
121    Global& glob = Global::getInstance();
122    glob.initialize(args, argv);
123 
124    TestQos testObj(glob, "TestQos");
125 
126    testObj.setUp();
127    testObj.testSessionQos();
128    testObj.tearDown();
129 
130    testObj.setUp();
131    testObj.testStatusQos();
132    testObj.tearDown();
133 
134    return 0;
135 }


syntax highlighted by Code2HTML, v. 0.9.1