ctkNetworkConnectorQtSoapTest.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * ctkNetworkConnectorQtSoapTest.cpp
  3. * ctkNetworkConnectorQtSoapTest
  4. *
  5. * Created by Daniele Giunchi on 16/07/10.
  6. * Copyright 2010 B3C. All rights reserved.
  7. *
  8. * See Licence at: http://tiny.cc/QXJ4D
  9. *
  10. */
  11. #include "ctkTestSuite.h"
  12. #include <ctkNetworkConnectorQtSoap.h>
  13. #include "ctkEventDefinitions.h"
  14. #include <ctkEventBusManager.h>
  15. #include <QApplication>
  16. #define WSDL_URL "http://localhost:7889/HelloWordService?wsdl"
  17. using namespace ctkEventBus;
  18. //-------------------------------------------------------------------------
  19. /**
  20. Class name: ctkObjectCustom
  21. Custom object needed for testing.
  22. */
  23. class testObjectCustomForNetworkConnectorSoap : public QObject {
  24. Q_OBJECT
  25. public:
  26. /// constructor.
  27. testObjectCustomForNetworkConnectorSoap();
  28. /// Return tha var's value.
  29. int var() {return m_Var;}
  30. public Q_SLOTS:
  31. /// Test slot that will increment the value of m_Var when an UPDATE_OBJECT event is raised.
  32. void updateObject();
  33. void setObjectValue(int v);
  34. Q_SIGNALS:
  35. void valueModified(int v);
  36. void objectModified();
  37. private:
  38. int m_Var; ///< Test var.
  39. };
  40. testObjectCustomForNetworkConnectorSoap::testObjectCustomForNetworkConnectorSoap() : m_Var(0) {
  41. }
  42. void testObjectCustomForNetworkConnectorSoap::updateObject() {
  43. m_Var++;
  44. }
  45. void testObjectCustomForNetworkConnectorSoap::setObjectValue(int v) {
  46. m_Var = v;
  47. }
  48. /**
  49. Class name: ctkNetworkConnectorQtSoapTest
  50. This class implements the test suite for ctkNetworkConnectorQtSoap.
  51. */
  52. //! <title>
  53. //ctkNetworkConnectorQtSoap
  54. //! </title>
  55. //! <description>
  56. //ctkNetworkConnectorQtSoap provides the connection with soap protocol, the qt class implement only the client
  57. //side. A C++ Server side implementation can be implemented with gSoap library.
  58. //It has been used qxmlrpc library.
  59. //! </description>
  60. class ctkNetworkConnectorQtSoapTest : public QObject {
  61. Q_OBJECT
  62. private Q_SLOTS:
  63. /// Initialize test variables
  64. void initTestCase() {
  65. m_EventBus = ctkEventBusManager::instance();
  66. m_NetWorkConnectorQtSoap = new ctkEventBus::ctkNetworkConnectorQtSoap;
  67. m_ObjectTest = new testObjectCustomForNetworkConnectorSoap;
  68. }
  69. /// Cleanup tes variables memory allocation.
  70. void cleanupTestCase() {
  71. delete m_ObjectTest;
  72. delete m_NetWorkConnectorQtSoap;
  73. m_EventBus->shutdown();
  74. }
  75. /// Check the existence of the ctkNetworkConnectorQtSoape singleton creation.
  76. void ctkNetworkConnectorQtSoapConstructorTest();
  77. /// service testing
  78. void ctkNetworkConnectorQtSoapCommunictionPassingStringTest();
  79. /// service testing
  80. void ctkNetworkConnectorQtSoapCommunictionPassingStringOnAxisServiceTest();
  81. /// service testing
  82. void ctkNetworkConnectorQtSoapCommunictionPassingStringArrayTest();
  83. /// gsoap service testing
  84. void ctkNetworkConnectorQtSoapCommunictionWithGSOAPServiceTest();
  85. private:
  86. ctkEventBusManager *m_EventBus; ///< event bus instance
  87. ctkNetworkConnectorQtSoap *m_NetWorkConnectorQtSoap; ///< EventBus test variable instance.
  88. testObjectCustomForNetworkConnectorSoap *m_ObjectTest;
  89. };
  90. void ctkNetworkConnectorQtSoapTest::ctkNetworkConnectorQtSoapConstructorTest() {
  91. QVERIFY(m_NetWorkConnectorQtSoap != NULL);
  92. //delete and recreate instance in order to cover different branch inside destructor
  93. delete m_NetWorkConnectorQtSoap;
  94. m_NetWorkConnectorQtSoap = NULL;
  95. m_NetWorkConnectorQtSoap = new ctkEventBus::ctkNetworkConnectorQtSoap;
  96. }
  97. void ctkNetworkConnectorQtSoapTest::ctkNetworkConnectorQtSoapCommunictionPassingStringTest() {
  98. //create soap client, initializing host and port
  99. m_NetWorkConnectorQtSoap->createClient("localhost", 7889);
  100. m_NetWorkConnectorQtSoap->setWSDL(WSDL_URL);
  101. // customize call
  102. ctkEventArgumentsList myList; // create list to send
  103. //inside there is ONE hash which has name, value
  104. ctkEventHash values;
  105. //this is value 1
  106. QString valueToSend = "EternoDolore";
  107. QVariant v(valueToSend);
  108. //set the name and the value
  109. values.insert("input", v);
  110. //append inside the list
  111. myList.push_back(ctkEventArgument(ctkEventHash, values));
  112. // send call
  113. m_NetWorkConnectorQtSoap->setAction("myEcho");
  114. m_NetWorkConnectorQtSoap->setPath(WSDL_URL);
  115. m_NetWorkConnectorQtSoap->send("myEcho", &myList);
  116. //wait for response from remote server
  117. QTime dieTime = QTime::currentTime().addSecs(5);
  118. while(QTime::currentTime() < dieTime) {
  119. QCoreApplication::processEvents(QEventLoop::AllEvents, 5);
  120. }
  121. // compare results
  122. QtSoapType *soapTypeResult = m_NetWorkConnectorQtSoap->response();
  123. if(soapTypeResult)
  124. qDebug("%s", soapTypeResult->toString().toLatin1().constData());
  125. }
  126. void ctkNetworkConnectorQtSoapTest::ctkNetworkConnectorQtSoapCommunictionPassingStringOnAxisServiceTest() {
  127. //create soap client, initializing host and port
  128. m_NetWorkConnectorQtSoap->createClient("localhost", 8280);
  129. m_NetWorkConnectorQtSoap->setWSDL("http://localhost:8280/services/echo?wsdl");
  130. // customize call
  131. ctkEventArgumentsList myList; // create list to send
  132. //inside there is ONE hash which has name, value
  133. ctkEventHash values;
  134. //this is value 1
  135. QString valueToSend = "IBM";
  136. QVariant v(valueToSend);
  137. //set the name and the value
  138. values.insert("in", v);
  139. //append inside the list
  140. myList.push_back(ctkEventArgument(ctkEventHash,values));
  141. QtSoapNamespaces &registry = QtSoapNamespaces::instance();
  142. registry.registerNamespace("ns", "http://echo.services.core.carbon.wso2.org");
  143. // send call
  144. m_NetWorkConnectorQtSoap->registerNamespace("ns", "http://echo.services.core.carbon.wso2.org");
  145. m_NetWorkConnectorQtSoap->setAction("urn:echoString");
  146. m_NetWorkConnectorQtSoap->setPath("http://localhost:8280/services/echo.echoHttpSoap11Endpoint");
  147. m_NetWorkConnectorQtSoap->send("ns:echoString", &myList);
  148. //wait for response from remote server
  149. QTime dieTime = QTime::currentTime().addSecs(5);
  150. while(QTime::currentTime() < dieTime) {
  151. QCoreApplication::processEvents(QEventLoop::AllEvents, 5);
  152. }
  153. // compare results
  154. QtSoapType *soapTypeResult = m_NetWorkConnectorQtSoap->response();
  155. if(soapTypeResult)
  156. qDebug("%s", soapTypeResult->toString().toLatin1().constData());
  157. }
  158. void ctkNetworkConnectorQtSoapTest::ctkNetworkConnectorQtSoapCommunictionPassingStringArrayTest() {
  159. //create soap client, initializing host and port
  160. m_NetWorkConnectorQtSoap->createClient("localhost", 7889);
  161. m_NetWorkConnectorQtSoap->setWSDL(WSDL_URL);
  162. // customize call
  163. ctkEventArgumentsList myList; // create list to send
  164. //inside there is ONE hash which has name, value
  165. ctkEventHash values;
  166. //this is value 1
  167. QList<QString> list1;
  168. list1.push_back("eventA1");
  169. list1.push_back("eventA2");
  170. //this is value 2
  171. QList<QString> list2;
  172. list2.push_back("dataA1");
  173. list2.push_back("dataA2");
  174. //incapsulate inside a QVariant
  175. QVariant v1(list1);
  176. QVariant v2(list2);
  177. //set the name and the value
  178. values.insert("arrEvent", v1);
  179. //set the name and the value
  180. values.insert("arrData", v2);
  181. //append inside the list
  182. myList.push_back(ctkEventArgument(ctkEventHash,values));
  183. // send call
  184. m_NetWorkConnectorQtSoap->setAction("testArray");
  185. m_NetWorkConnectorQtSoap->setPath(WSDL_URL);
  186. m_NetWorkConnectorQtSoap->send("testArray", &myList);
  187. //wait for response from remote server
  188. QTime dieTime = QTime::currentTime().addSecs(5);
  189. while(QTime::currentTime() < dieTime) {
  190. QCoreApplication::processEvents(QEventLoop::AllEvents, 5);
  191. }
  192. // compare results
  193. QtSoapType *soapTypeResult = m_NetWorkConnectorQtSoap->response();
  194. if(soapTypeResult)
  195. qDebug("%s", soapTypeResult->toString().toLatin1().constData());
  196. }
  197. void ctkNetworkConnectorQtSoapTest::ctkNetworkConnectorQtSoapCommunictionWithGSOAPServiceTest() {
  198. //create soap client, initializing host and port
  199. m_NetWorkConnectorQtSoap->createClient("ws.biomedtown.org", 80);
  200. m_NetWorkConnectorQtSoap->setWSDL("http://ws.biomedtown.org/hello.wsdl");
  201. // customize call
  202. ctkEventArgumentsList myList; // create list to send
  203. //inside there is ONE hash which has name, value
  204. ctkEventHash values;
  205. values.insert("input", "stringTest");
  206. //append inside the list
  207. myList.push_back(ctkEventArgument(ctkEventHash,values));
  208. // send call
  209. m_NetWorkConnectorQtSoap->registerNamespace("h", "http://tempuri.org/h.xsd");
  210. m_NetWorkConnectorQtSoap->setAction("");
  211. m_NetWorkConnectorQtSoap->setPath("hello.cgi"); //warning : the path of the service should be selected depending in which way the service is implemented.
  212. m_NetWorkConnectorQtSoap->send("h:hello", &myList);
  213. //wait for response from remote server
  214. QTime dieTime = QTime::currentTime().addSecs(5);
  215. while(QTime::currentTime() < dieTime) {
  216. QCoreApplication::processEvents(QEventLoop::AllEvents, 5);
  217. }
  218. // compare results
  219. QtSoapType *soapTypeResult = m_NetWorkConnectorQtSoap->response();
  220. if(soapTypeResult)
  221. qDebug("%s", soapTypeResult->toString().toLatin1().constData());
  222. }
  223. CTK_REGISTER_TEST(ctkNetworkConnectorQtSoapTest);
  224. #include "ctkNetworkConnectorQtSoapTest.moc"