PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/project/network/jWebSocketClient-1.0/test/js/jwsJDBCTests.js

https://gitlab.com/BGCX261/zlatnaspirala2-svn-to-git
JavaScript | 479 lines | 308 code | 91 blank | 80 comment | 0 complexity | bbfd2bba0273c0b997d4bd7e851a0026 MD5 | raw file
  1. // ---------------------------------------------------------------------------
  2. // jWebSocket TestSpecs for the JDBC Plug-in
  3. // (C) 2011 jWebSocket.org, Alexander Schulze, Innotrade GmbH, Herzogenrath
  4. // ---------------------------------------------------------------------------
  5. // This program is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License as published by the
  7. // Free Software Foundation; either version 3 of the License, or (at your
  8. // option) any later version.
  9. // This program is distributed in the hope that it will be useful, but WITHOUT
  10. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  12. // more details.
  13. // You should have received a copy of the GNU Lesser General Public License along
  14. // with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
  15. // ---------------------------------------------------------------------------
  16. jws.tests.JDBC = {
  17. NS: "jws.tests.jdbc",
  18. TEST_TABLE: "jwebsocket_automated_test",
  19. TEST_STRING_1: "This is an automated demo text",
  20. TEST_STRING_2: "This is an updated demo text",
  21. // this spec tests the jdbc plug-in, creating a temporary table for test purposes
  22. testCreateTable: function() {
  23. var lSpec = this.NS + ": create table (admin)";
  24. it( lSpec, function () {
  25. // init response
  26. var lResponse = {};
  27. // perform the native create table...
  28. jws.Tests.getAdminConn().jdbcExecSQL(
  29. "create table " + jws.tests.JDBC.TEST_TABLE + " (id int, text varchar(80))",
  30. { OnResponse: function( aToken ) {
  31. lResponse = aToken;
  32. }
  33. }
  34. );
  35. // wait for result, consider reasonable timeout
  36. waitsFor(
  37. function() {
  38. // check response
  39. return( lResponse.msg !== undefined );
  40. },
  41. lSpec,
  42. 1500
  43. );
  44. // check result if ok
  45. runs( function() {
  46. expect( lResponse.msg ).toEqual( "ok" );
  47. });
  48. });
  49. },
  50. // this spec tests the jdbc plug-in, dropping a temporary table for test purposes
  51. testDropTable: function() {
  52. var lSpec = this.NS + ": drop table (admin)";
  53. it( lSpec, function () {
  54. // init response
  55. var lResponse = {};
  56. // perform the native drop table...
  57. jws.Tests.getAdminConn().jdbcExecSQL(
  58. "drop table " + jws.tests.JDBC.TEST_TABLE,
  59. { OnResponse: function( aToken ) {
  60. lResponse = aToken;
  61. }
  62. }
  63. );
  64. // wait for result, consider reasonable timeout
  65. waitsFor(
  66. function() {
  67. // check response
  68. return( lResponse.msg !== undefined );
  69. },
  70. lSpec,
  71. 1500
  72. );
  73. // check result if ok
  74. runs( function() {
  75. expect( lResponse.msg ).toEqual( "ok" );
  76. });
  77. });
  78. },
  79. // this spec tests the native SQL select function of the JDBC plug-in
  80. testSelectSQL: function() {
  81. var lSpec = this.NS + ": selectSQL (admin)";
  82. it( lSpec, function () {
  83. // init response
  84. var lResponse = {};
  85. // perform the native select...
  86. jws.Tests.getAdminConn().jdbcQuerySQL(
  87. "select * from " + jws.tests.JDBC.TEST_TABLE,
  88. { OnResponse: function( aToken ) {
  89. lResponse = aToken;
  90. }
  91. }
  92. );
  93. // wait for result, consider reasonable timeout
  94. waitsFor(
  95. function() {
  96. // check response
  97. return( lResponse.code !== undefined );
  98. },
  99. lSpec,
  100. 1500
  101. );
  102. // check result if ok
  103. runs( function() {
  104. expect( lResponse.code ).toEqual( 0 );
  105. });
  106. });
  107. },
  108. // this spec tests the native SQL insert function of the JDBC plug-in
  109. testInsertSQL: function() {
  110. var lSpec = this.NS + ": insertSQL (admin)";
  111. it( lSpec, function () {
  112. // init response
  113. var lResponse = {};
  114. // perform the native insert...
  115. jws.Tests.getAdminConn().jdbcUpdateSQL(
  116. "insert into "
  117. + jws.tests.JDBC.TEST_TABLE
  118. + " (id, text) values (1, '"
  119. + jws.tests.JDBC.TEST_STRING_1 + "')",
  120. { OnResponse: function( aToken ) {
  121. lResponse = aToken;
  122. }
  123. }
  124. );
  125. // wait for result, consider reasonable timeout
  126. waitsFor(
  127. function() {
  128. return( lResponse.code !== undefined );
  129. },
  130. lSpec,
  131. 1500
  132. );
  133. // check result if ok
  134. runs( function() {
  135. expect( lResponse.msg ).toEqual( "ok" );
  136. expect( lResponse.rowsAffected[0] ).toEqual( 1 );
  137. });
  138. });
  139. },
  140. // this spec tests the native SQL update function of the JDBC plug-in
  141. testUpdateSQL: function() {
  142. var lSpec = this.NS + ": updateSQL (admin)";
  143. it( lSpec, function () {
  144. // init response
  145. var lResponse = {};
  146. // perform the native update...
  147. jws.Tests.getAdminConn().jdbcUpdateSQL(
  148. "update "
  149. + jws.tests.JDBC.TEST_TABLE
  150. + " set text = '" + jws.tests.JDBC.TEST_STRING_2 + "'"
  151. + " where id = 1",
  152. { OnResponse: function( aToken ) {
  153. lResponse = aToken;
  154. }
  155. }
  156. );
  157. // wait for result, consider reasonable timeout
  158. waitsFor(
  159. function() {
  160. return( lResponse.code !== undefined );
  161. },
  162. lSpec,
  163. 1500
  164. );
  165. // check result if ok
  166. runs( function() {
  167. expect( lResponse.msg ).toEqual( "ok" );
  168. expect( lResponse.rowsAffected[0] ).toEqual( 1 );
  169. });
  170. });
  171. },
  172. // this spec tests the native SQL delete function of the JDBC plug-in
  173. testDeleteSQL: function() {
  174. var lSpec = this.NS + ": deleteSQL (admin)";
  175. it( lSpec, function () {
  176. // init response
  177. var lResponse = {};
  178. // perform the native delete...
  179. jws.Tests.getAdminConn().jdbcUpdateSQL(
  180. "delete from "
  181. + jws.tests.JDBC.TEST_TABLE
  182. + " where id = 1",
  183. { OnResponse: function( aToken ) {
  184. lResponse = aToken;
  185. }
  186. }
  187. );
  188. // wait for result, consider reasonable timeout
  189. waitsFor(
  190. function() {
  191. return( lResponse.code !== undefined );
  192. },
  193. lSpec,
  194. 1500
  195. );
  196. // check result if ok
  197. runs( function() {
  198. expect( lResponse.msg ).toEqual( "ok" );
  199. expect( lResponse.rowsAffected[0] ).toEqual( 1 );
  200. });
  201. });
  202. },
  203. // this spec tests the abstract select function of the JDBC plug-in
  204. testSelect: function() {
  205. var lSpec = this.NS + ": select (admin)";
  206. it( lSpec, function () {
  207. // init response
  208. var lResponse = {};
  209. // perform the abstract select command...
  210. jws.Tests.getAdminConn().jdbcSelect(
  211. { tables: [ jws.tests.JDBC.TEST_TABLE ],
  212. fields: [ "id", "text" ],
  213. where: "id=1"
  214. },
  215. { OnResponse: function( aToken ) {
  216. lResponse = aToken;
  217. }
  218. }
  219. );
  220. // wait for result, consider reasonable timeout
  221. waitsFor(
  222. function() {
  223. return( lResponse.code !== undefined );
  224. },
  225. lSpec,
  226. 1500
  227. );
  228. // check result if ok
  229. runs( function() {
  230. expect( lResponse.msg ).toEqual( "ok" );
  231. expect( lResponse.data.length ).toEqual( 1 );
  232. expect( lResponse.data[0][1] ).toEqual( jws.tests.JDBC.TEST_STRING_2 );
  233. });
  234. });
  235. },
  236. // this spec tests the abstract insert function of the JDBC plug-in
  237. testInsert: function() {
  238. var lSpec = this.NS + ": insert (admin)";
  239. it( lSpec, function () {
  240. // init response
  241. var lResponse = {};
  242. // perform the abstract insert command
  243. jws.Tests.getAdminConn().jdbcInsert(
  244. { table: jws.tests.JDBC.TEST_TABLE ,
  245. fields: [ "id", "text" ],
  246. values: [ 1, jws.tests.JDBC.TEST_STRING_1 ]
  247. },
  248. { OnResponse: function( aToken ) {
  249. lResponse = aToken;
  250. }
  251. }
  252. );
  253. // wait for result, consider reasonable timeout
  254. waitsFor(
  255. function() {
  256. return( lResponse.code !== undefined );
  257. },
  258. lSpec,
  259. 1500
  260. );
  261. // check result if ok
  262. runs( function() {
  263. expect( lResponse.msg ).toEqual( "ok" );
  264. expect( lResponse.rowsAffected[0] ).toEqual( 1 );
  265. });
  266. });
  267. },
  268. // this spec tests the abstract update function of the JDBC plug-in
  269. testUpdate: function() {
  270. var lSpec = this.NS + ": update (admin)";
  271. it( lSpec, function () {
  272. // init response
  273. var lResponse = {};
  274. // perform the abstract update command
  275. jws.Tests.getAdminConn().jdbcUpdate(
  276. { table: jws.tests.JDBC.TEST_TABLE ,
  277. fields: [ "text" ],
  278. values: [ jws.tests.JDBC.TEST_STRING_2 ],
  279. where: "id=1"
  280. },
  281. { OnResponse: function( aToken ) {
  282. lResponse = aToken;
  283. }
  284. }
  285. );
  286. // wait for result, consider reasonable timeout
  287. waitsFor(
  288. function() {
  289. return( lResponse.code !== undefined );
  290. },
  291. lSpec,
  292. 1500
  293. );
  294. // check result if ok
  295. runs( function() {
  296. expect( lResponse.msg ).toEqual( "ok" );
  297. expect( lResponse.rowsAffected[0] ).toEqual( 1 );
  298. });
  299. });
  300. },
  301. // this spec tests the abstract delete function of the JDBC plug-in
  302. testDelete: function() {
  303. var lSpec = this.NS + ": delete (admin)";
  304. it( lSpec, function () {
  305. // init response
  306. var lResponse = {};
  307. // perform the abstract delete command
  308. jws.Tests.getAdminConn().jdbcDelete(
  309. { table: jws.tests.JDBC.TEST_TABLE,
  310. where: "id=1"
  311. },
  312. { OnResponse: function( aToken ) {
  313. lResponse = aToken;
  314. }
  315. }
  316. );
  317. // wait for result, consider reasonable timeout
  318. waitsFor(
  319. function() {
  320. return( lResponse.code !== undefined );
  321. },
  322. lSpec,
  323. 1500
  324. );
  325. // check result if ok
  326. runs( function() {
  327. expect( lResponse.msg ).toEqual( "ok" );
  328. expect( lResponse.rowsAffected[0] ).toEqual( 1 );
  329. });
  330. });
  331. },
  332. // this spec tests the native SQL select function of the JDBC plug-in
  333. testGetPrimaryKeys: function() {
  334. var lSpec = this.NS + ": getPrimaryKeys (admin)";
  335. it( lSpec, function () {
  336. // init response
  337. var lResponse = {};
  338. // try to get 3 new primary keys...
  339. jws.Tests.getAdminConn().jdbcGetPrimaryKeys(
  340. "sq_pk_system_log",
  341. { count: 3,
  342. OnResponse: function( aToken ) {
  343. lResponse = aToken;
  344. }
  345. }
  346. );
  347. // wait for result, consider reasonable timeout
  348. waitsFor(
  349. function() {
  350. // check response
  351. return( lResponse.code !== undefined );
  352. },
  353. lSpec,
  354. 1500
  355. );
  356. // check result if ok
  357. runs( function() {
  358. expect( lResponse.code ).toEqual( 0 );
  359. expect( lResponse.values.length ).toEqual( 3 );
  360. });
  361. });
  362. },
  363. runSpecs: function() {
  364. // run alls tests within an outer test suite
  365. // create a temporary table (test for DDL commands)
  366. this.testCreateTable();
  367. // run native tests
  368. this.testInsertSQL();
  369. this.testUpdateSQL();
  370. this.testSelectSQL();
  371. this.testDeleteSQL();
  372. // run abstract tests
  373. this.testInsert();
  374. this.testUpdate();
  375. this.testSelect();
  376. this.testDelete();
  377. this.testGetPrimaryKeys();
  378. // drop the temporary table (test for DDL commands)
  379. this.testDropTable();
  380. },
  381. runSuite: function() {
  382. // run alls tests as a separate test suite
  383. var lThis = this;
  384. describe( "Performing test suite: " + this.NS + "...", function () {
  385. lThis.runSpecs();
  386. });
  387. }
  388. };