1 /*-----------------------------------------------------------------------------
2 Name: TestDoubleGlobal.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Testing the Timeout Features
6 -----------------------------------------------------------------------------*/
7 #include <util/qos/ConnectQos.h>
8 #include <util/qos/ConnectQosFactory.h>
9 #include <util/XmlBlasterException.h>
10 #include <util/Global.h>
11 #include "TestSuite.h"
12 #include <iostream>
13
14 namespace org { namespace xmlBlaster { namespace test {
15
16 using namespace std;
17 using namespace org::xmlBlaster::util;
18 using namespace org::xmlBlaster::util::qos;
19 using namespace org::xmlBlaster::util::qos::storage;
20 using namespace org::xmlBlaster::util::qos::address;
21
22 class TestDoubleGlobal
23 {
24 private:
25 string ME;
26 Global& global_;
27 I_Log& log_;
28 Global *global2_;
29 bool useSessionMarker_; // Remove again at version 2.0
30
31 public:
32 TestDoubleGlobal(Global& glob)
33 : ME("TestDoubleGlobal"),
34 global_(glob),
35 log_(glob.getLog("test"))
36 {
37 SessionName sn(global_, "client/dummy");
38 useSessionMarker_ = sn.useSessionMarker();
39 }
40
41
42 void tearDown()
43 {
44 delete global2_;
45 global2_ = NULL;
46 }
47
48 virtual ~TestDoubleGlobal()
49 {
50 }
51
52 void setUp()
53 {
54 global2_ = new Global();
55 global2_->initialize();
56 bool overwrite = true;
57 global2_->getProperty().setProperty("session.name", "pinco/2", overwrite);
58 }
59
60
61 void sessionQos(Global& glob, const string& shouldSessionName)
62 {
63
64 string me = ME + ".testSessionQos";
65 log_.info(me, "testing creation, parsing and output of SessionQos: start");
66
67 string qos = string("<session name='/node/http:/client/ticheta/-3' timeout='86400000' maxSessions='10' \n") +
68 " clearSessions='false' sessionId='IIOP:01110728321B0222011028'/>\n";
69
70 SessionQosFactory factory(glob);
71
72 for (int i=0; i<2; i++) {
73 SessionQosData data = factory.readObject(qos);
74 if (useSessionMarker_)
75 assertEquals(log_, me, string("/node/http:/client/ticheta/session/-3"), data.getAbsoluteName(), "absolute name check");
76 else
77 assertEquals(log_, me, string("/node/http:/client/ticheta/-3"), data.getAbsoluteName(), "absolute name check");
78 assertEquals(log_, me, (long)86400000l, data.getTimeout(), "timeout check");
79 assertEquals(log_, me, 10, data.getMaxSessions(), "maxSessions check");
80 assertEquals(log_, me, false, data.getClearSessions(), "clearSessions check");
81 assertEquals(log_, me, string("IIOP:01110728321B0222011028"), data.getSecretSessionId(), "sessionId check");
82 SessionQosData ref(glob);
83 ref.setAbsoluteName("/node/http:/client/ticheta/-3");
84 ref.setTimeout(86400000l);
85 ref.setMaxSessions(10);
86 ref.setClearSessions(false);
87 ref.setSecretSessionId("IIOP:01110728321B0222011028");
88 string lit1 = data.toXml();
89 string lit2 = ref.toXml();
90 if (log_.trace()) {
91 log_.trace(me, string("xml is: ") + lit1);
92 log_.trace(me, string("xml should be: ") + lit2);
93 }
94 assertEquals(log_, me, lit2, lit1, "sessionId check");
95 }
96
97 // make sure the property 'session.name' has not been set on the command line or on the prop. file
98 string name = glob.getProperty().getStringProperty("session.name", "");
99 assertEquals(log_, me, shouldSessionName, name, "non setting of property 'session.name'");
100 SessionQosData data1(glob, "Fritz");
101 assertEquals(log_, me, string("client/Fritz"), data1.getAbsoluteName(), "checking constructor with 'user' and 'pubSessionId=0'");
102
103 glob.getProperty().setProperty("user", "PincoPallino");
104 name = glob.getProperty().getStringProperty("user", "");
105 assertEquals(log_, me, string("PincoPallino"), name, "checking if property 'user' has been set correctly");
106
107 // set the property now
108 glob.getProperty().setProperty("session.name", "/node/australia/client/Martin/4");
109 name = glob.getProperty().getStringProperty("session.name", "");
110 assertEquals(log_, me, string("/node/australia/client/Martin/4"), name, "checking if property 'session.name' has been set correctly");
111 data1 = SessionQosData(glob, "Nisse/3", 0);
112 assertEquals(log_, me, string("/node/australia/client/Martin/4"), name, "checking when 'session.name' is strongest");
113
114 data1 = SessionQosData(glob);
115 data1.setAbsoluteName("/node/frodo/client/whoMore/3");
116 if (useSessionMarker_)
117 assertEquals(log_, me, string("/node/frodo/client/whoMore/session/3"), data1.getAbsoluteName(), "checking when 'session.name' is weaker");
118 else
119 assertEquals(log_, me, string("/node/frodo/client/whoMore/3"), data1.getAbsoluteName(), "checking when 'session.name' is weaker");
120 log_.info(me, "testing creation, parsing and output of SessionQos: end");
121 }
122
123 void testSessionQos() {
124 sessionQos(global_, string(""));
125 sessionQos(*global2_, string("pinco/2"));
126 }
127
128
129 };
130
131 }}} // namespace
132
133
134 using namespace org::xmlBlaster::test;
135
136 /**
137 * Try
138 * <pre>
139 * java TestDoubleGlobal -help
140 * </pre>
141 * for usage help
142 */
143 int main(int args, char ** argv)
144 {
145 try {
146 org::xmlBlaster::util::Object_Lifetime_Manager::init();
147 Global& glob = Global::getInstance();
148 glob.initialize(args, argv);
149
150 TestDoubleGlobal testConnectQos(glob);
151
152 testConnectQos.setUp();
153 testConnectQos.testSessionQos();
154 testConnectQos.tearDown();
155
156 org::xmlBlaster::util::Object_Lifetime_Manager::fini();
157 }
158 catch (XmlBlasterException& ex) {
159 std::cout << ex.toXml() << std::endl;
160 }
161 catch (bad_exception& ex) {
162 cout << "bad_exception: " << ex.what() << endl;
163 }
164 catch (exception& ex) {
165 cout << " exception: " << ex.what() << endl;
166 }
167 catch (string& ex) {
168 cout << "string: " << ex << endl;
169 }
170 catch (char* ex) {
171 cout << "char* : " << ex << endl;
172 }
173
174 catch (...)
175 {
176 cout << "unknown exception occured" << endl;
177 XmlBlasterException e(INTERNAL_UNKNOWN, "main", "main thread");
178 cout << e.toXml() << endl;
179 }
180 return 0;
181 }
syntax highlighted by Code2HTML, v. 0.9.1