1/* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; 17import data_Rdb from '@ohos.data.relationalStore'; 18import ability_featureAbility from '@ohos.ability.featureAbility'; 19 20const ERRCODE = 801; 21var context = ability_featureAbility.getContext(); 22var sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + 23"id INTEGER PRIMARY KEY AUTOINCREMENT," + 24"name TEXT NOT NULL," +"age INTEGER)" 25sqlStatement = "CREATE TABLE IF NOT EXISTS product (" + 26"id INTEGER PRIMARY KEY AUTOINCREMENT," + 27"name TEXT NOT NULL," +"price REAL," + 28"vendor INTEGER," +"describe TEXT)" 29const TAG = "[RelationalStore_JSKITS_TEST_Distributed]" 30const STORE_NAME = "distributed_rdb.db" 31var rdbStore = undefined; 32const config = { 33 "name": STORE_NAME, 34 securityLevel: data_Rdb.SecurityLevel.S1 35} 36 37async function executeSql1() { 38 let sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + 39 "id INTEGER PRIMARY KEY AUTOINCREMENT," + 40 "name TEXT NOT NULL," + 41 "age INTEGER)" 42try { 43 await rdbStore.executeSql(sqlStatement, null) 44 console.info(TAG + "create table employee success") 45} catch (err) { 46 console.info(TAG + "create table employee failed") 47 expect(null).assertFail() 48} 49} 50 51async function executeSql2() { 52 let sqlStatement = "CREATE TABLE IF NOT EXISTS product (" + 53 "id INTEGER PRIMARY KEY AUTOINCREMENT," + 54 "name TEXT NOT NULL," + 55 "price REAL," + 56 "vendor INTEGER," + 57 "describe TEXT)" 58try { 59 await rdbStore.executeSql(sqlStatement, null) 60 console.info(TAG + "create table product success") 61} catch (err) { 62 console.info(TAG + "create table product failed") 63 expect(null).assertFail() 64} 65} 66async function executeSql3() { 67 let sqlStatement = "CREATE TABLE IF NOT EXISTS test (" + 68 "id INTEGER PRIMARY KEY AUTOINCREMENT," + 69 "name TEXT NOT NULL," + 70 "price REAL," + 71 "vendor INTEGER," + 72 "describe TEXT)" 73 try { 74 await rdbStore.executeSql(sqlStatement, null) 75 console.info(TAG + "create table product success") 76 } catch (err) { 77 console.info(TAG + "create table product failed") 78 expect(null).assertFail() 79 } 80} 81 82function storeObserver(devices) { 83 console.info(TAG + devices + " dataChange"); 84 expect(devices).assertEqual(null) 85} 86 87export default function relationalStoreDistributedTest() { 88describe('relationalStoreDistributedTest', function () { 89 beforeAll(async function () { 90 console.info(TAG + 'beforeAll') 91 }) 92 93 beforeEach(async function () { 94 console.info(TAG + 'beforeEach') 95 rdbStore = await data_Rdb.getRdbStore(context, config); 96 console.info(TAG + "create RelationalStore store success") 97 await executeSql1(); 98 await executeSql2(); 99 await executeSql3(); 100 }) 101 102 afterEach(async function () { 103 console.info(TAG + 'afterEach') 104 await data_Rdb.deleteRdbStore(context, STORE_NAME); 105 }) 106 107 afterAll(async function () { 108 console.info(TAG + 'afterAll') 109 }) 110 111 console.info(TAG + "*************Unit Test Begin*************"); 112 113 /** 114 * @tc.name set_distributed_table_none_table 115 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_002 116 * @tc.desc RelationalStore set distributed table using none table as argment 117 */ 118 it('testRdbStoreDistributed0002', 0, async function (done) { 119 console.info(TAG + "************* testRdbStoreDistributed002 start *************"); 120 try { 121 await rdbStore.setDistributedTables([]) 122 console.info(TAG + "set none to be distributed table success"); 123 expect(rdbStore).assertEqual(rdbStore) 124 } catch (err) { 125 console.info(TAG + "setDistributed002 failed"+ `, error code is ${err.code}, message is ${err.message}`); 126 expect(err.code).assertEqual(ERRCODE); 127 } 128 done() 129 console.info(TAG + "************* testRdbStoreDistributed002 end *************"); 130 }) 131 132 /** 133 * @tc.name set distributed table using one table name 134 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_003 135 * @tc.desc set distributed table using one table name 136 */ 137 it('testRdbStoreDistributed0003', 0, async function (done) { 138 console.info(TAG + "************* testRdbStoreDistributed003 start *************"); 139 try { 140 await rdbStore.setDistributedTables(['employee']) 141 console.info(TAG + "set employee to be distributed table success"); 142 expect(rdbStore).assertEqual(rdbStore) 143 } catch (err) { 144 console.info(TAG + "setDistributed003 failed"+ `, error code is ${err.code}, message is ${err.message}`); 145 expect(err.code).assertEqual(ERRCODE); 146 } 147 done() 148 console.info(TAG + "************* testRdbStoreDistributed003 end *************"); 149 }) 150 151 /** 152 * @tc.name set distributed table using two table name 153 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_004 154 * @tc.desc set distributed table using two table name 155 */ 156 it('testRdbStoreDistributed0004', 0, async function (done) { 157 console.info(TAG + "************* testRdbStoreDistributed004 start *************"); 158 try { 159 await rdbStore.setDistributedTables(['employee', 'product']) 160 console.info(TAG + "set employee and product to be distributed table success"); 161 expect(rdbStore).assertEqual(rdbStore) 162 } catch (err) { 163 console.info(TAG + "setDistributed004 failed"+ `, error code is ${err.code}, message is ${err.message}`); 164 expect(err.code).assertEqual(ERRCODE); 165 } 166 done() 167 console.info(TAG + "************* testRdbStoreDistributed004 end *************"); 168 }) 169 170 /** 171 * @tc.name insert record after setting distributed table 172 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_005 173 * @tc.desc insert record after setting distributed table 174 */ 175 it('testRdbStoreDistributed0005', 0, async function (done) { 176 console.info(TAG + "************* testRdbStoreDistributed005 start *************"); 177 const record = { 178 "name": "Jim", 179 "age": 20, 180 } 181 try { 182 let rowId = await rdbStore.insert("employee", record) 183 console.info(TAG + "insert one record success " + rowId) 184 expect(1).assertEqual(rowId) 185 } catch (err) { 186 console.info(TAG + "insert one record failed" + err); 187 expect(null).assertFail(); 188 } 189 done() 190 console.info(TAG + "************* testRdbStoreDistributed005 end *************"); 191 }) 192 193 /** 194 * @tc.name update record after setting distributed table 195 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_006 196 * @tc.desc update record after setting distributed table 197 */ 198 it('testRdbStoreDistributed0006', 0, async function (done) { 199 console.info(TAG + "************* testRdbStoreDistributed006 start *************"); 200 const record1 = { 201 "name": "Jim", 202 "age": 20, 203 } 204 const record2 = { 205 "name": "Jim", 206 "age": 30, 207 } 208 await rdbStore.insert("employee", record1); 209 try { 210 let predicate = new data_Rdb.RdbPredicates("employee"); 211 predicate.equalTo("id", 1); 212 try { 213 let rowId = await rdbStore.update(record2, predicate); 214 console.info(TAG + "update one record success " + rowId) 215 expect(1).assertEqual(rowId) 216 } catch (err) { 217 console.info(TAG + "update one record failed" + err); 218 expect(null).assertFail(); 219 } 220 } catch (err) { 221 console.info(TAG + "construct predicate failed"); 222 expect(null).assertFail(); 223 } 224 done() 225 console.info(TAG + "************* testRdbStoreDistributed006 end *************"); 226 }) 227 228 /** 229 * @tc.name query record after setting distributed table 230 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_007 231 * @tc.desc query record after setting distributed table 232 */ 233 it('testRdbStoreDistributed0007', 0, async function (done) { 234 console.info(TAG + "************* testRdbStoreDistributed0007 start *************"); 235 const record1 = { 236 "name": "Jim", 237 "age": 30, 238 } 239 await rdbStore.insert("employee", record1); 240 try { 241 let predicates = new data_Rdb.RdbPredicates("employee") 242 let resultSet = await rdbStore.query(predicates) 243 try { 244 console.info(TAG + "product resultSet query done"); 245 expect(true).assertEqual(resultSet.goToFirstRow()) 246 const id = await resultSet.getLong(resultSet.getColumnIndex("id")) 247 const name = await resultSet.getString(resultSet.getColumnIndex("name")) 248 const age = await resultSet.getLong(resultSet.getColumnIndex("age")) 249 250 await expect(1).assertEqual(id); 251 await expect("Jim").assertEqual(name); 252 await expect(30).assertEqual(age); 253 resultSet.close(); 254 expect(true).assertEqual(resultSet.isClosed) 255 } catch (e) { 256 console.info(TAG + "result get value failed") 257 expect(null).assertFail(); 258 } 259 } catch (err) { 260 console.info("query failed"); 261 expect(null).assertFail(); 262 } 263 done(); 264 console.info(TAG + "************* testRdbStoreDistributed0007 end *************"); 265 }) 266 267 /** 268 * @tc.name delete record after setting distributed table 269 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_008 270 * @tc.desc delete record after setting distributed table 271 */ 272 it('testRdbStoreDistributed0008', 0, async function (done) { 273 console.info(TAG + "************* testRdbStoreDistributed0008 start *************"); 274 const record1 = { 275 "name": "Jim", 276 "age": 20, 277 } 278 await rdbStore.insert("employee", record1); 279 let predicates = new data_Rdb.RdbPredicates("employee") 280 try { 281 let number = await rdbStore.delete(predicates) 282 console.info(TAG + "employee Delete done: " + number) 283 expect(1).assertEqual(number) 284 } catch (err) { 285 console.info(TAG + "delete record failed"); 286 expect(null).assertFail() 287 } 288 done(); 289 console.info(TAG + "************* testRdbStoreDistributed0008 end *************"); 290 }) 291 292 /** 293 * @tc.name predicates inDevice 294 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_009 295 * @tc.desc predicates inDevice 296 */ 297 it('testRdbStoreDistributed0009', 0, async function (done) { 298 console.info(TAG + "************* testRdbStoreDistributed0009 start *************"); 299 let predicates = new data_Rdb.RdbPredicates("employee") 300 try { 301 let pr = predicates.inDevices(["1234567890"]); 302 console.info(TAG + "inDevices success"); 303 expect(pr !== null).assertTrue(); 304 done(); 305 } catch (err) { 306 console.info(TAG + "inDevices failed"); 307 expect(null).assertFail(); 308 done(); 309 } 310 console.info(TAG + "************* testRdbStoreDistributed0009 end *************"); 311 }) 312 313 /** 314 * @tc.name predicates inAllDevices 315 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_010 316 * @tc.desc predicates inAllDevices 317 */ 318 it('testRdbStoreDistributed0010', 0, async function (done) { 319 console.info(TAG + "************* testRdbStoreDistributed0010 start *************"); 320 let predicates = new data_Rdb.RdbPredicates("employee") 321 try { 322 predicates = predicates.inAllDevices(); 323 console.info(TAG + "inAllDevices success"); 324 expect(predicates).assertEqual(predicates); 325 } catch (err) { 326 console.info(TAG + "inAllDevices failed"); 327 expect(null).assertFail(); 328 } 329 done(); 330 console.info(TAG + "************* testRdbStoreDistributed0010 end *************"); 331 }) 332 333 /** 334 * @tc.name sync test 335 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_011 336 * @tc.desc sync test 337 */ 338 it('testRdbStoreDistributed0011', 0, async function (done) { 339 console.info(TAG + "************* testRdbStoreDistributed0011 start *************"); 340 let predicates = new data_Rdb.RdbPredicates("employee") 341 let pr = predicates.inDevices(["12345678abcd"]); 342 let push = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates); 343 expect(push !== null).assertTrue(); 344 console.info(TAG + "sync push success"); 345 let pull = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PULL, predicates); 346 console.info(TAG + "sync pull success"); 347 expect(pull !== null).assertTrue(); 348 done(); 349 console.info(TAG + "************* testRdbStoreDistributed0011 end *************"); 350 }) 351 352 /** 353 * @tc.name sync Callback test 354 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_Callback_011 355 * @tc.desc sync Callback test 356 */ 357 it('testRdbStoreDistributedCallback0011', 0, async function (done) { 358 console.info(TAG + "************* testRdbStoreDistributedCallback0011 start *************"); 359 function sleep(ms) { 360 return new Promise(resolve => setTimeout(resolve, ms)); 361 } 362 let predicates = new data_Rdb.RdbPredicates("employee") 363 predicates = predicates.inDevices(["12345678abcd"]); 364 await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates, async (err,ret)=>{ 365 console.info(TAG + "sync push success"); 366 expect(err !== null).assertTrue(); 367 await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PULL, predicates,(err,ret)=>{ 368 console.info(TAG + "sync push success"); 369 expect(err !== null).assertTrue(); 370 done(); 371 }); 372 }); 373 console.info(TAG + "************* testRdbStoreDistributedCallback0011 end *************"); 374 }) 375 376 /** 377 * @tc.name subscribe test 378 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_012 379 * @tc.desc subscribe test 380 */ 381 it('testRdbStoreDistributed0012', 0, async function (done) { 382 console.info(TAG + "************* testRdbStoreDistributed0012 start *************"); 383 try{ 384 rdbStore.on("dataChange", data_Rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 385 console.info(TAG + "on dataChange success "); 386 }catch(err){ 387 console.info(TAG + "on dataChange " + err); 388 expect(err !== null).assertFalse(); 389 } 390 done() 391 console.info(TAG + "************* testRdbStoreDistributed0012 end *************"); 392 }) 393 394 /** 395 * @tc.name subscribe test 396 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_013 397 * @tc.desc subscribe test 398 */ 399 it('testRdbStoreDistributed0013', 0, function (done) { 400 console.info(TAG + "************* testRdbStoreDistributed0013 start *************"); 401 try{ 402 rdbStore.off("dataChange", data_Rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 403 console.info(TAG + "off dataChange success "); 404 }catch(err){ 405 console.info(TAG + "off dataChange " + err); 406 expect(err !== null).assertFalse(); 407 } 408 done() 409 console.info(TAG + "************* testRdbStoreDistributed0013 end *************"); 410 }) 411 412 /** 413 * @tc.name obtainDistributedTableName Callback interface test 414 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_014 415 * @tc.desc obtainDistributedTableName test 416 */ 417 it('testRdbStoreDistributed0014', 0, async function (done){ 418 let errInfo = undefined; 419 try{ 420 rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE", function (err, tableName) { 421 expect(err != null).assertTrue(); 422 console.info('ObtainDistributedTableName failed, Unauthorized.' + err) 423 }) 424 }catch(err){ 425 errInfo = err 426 } 427 expect(errInfo.code).assertEqual("401") 428 done(); 429 }) 430 431 /** 432 * @tc.name obtainDistributedTableName Promise interface test 433 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_015 434 * @tc.desc obtainDistributedTableName test 435 */ 436 it('testRdbStoreDistributed0015',0,async function (done){ 437 await data_Rdb.deleteRdbStore(context, STORE_NAME); 438 const config = { 439 "name": STORE_NAME, 440 securityLevel: data_Rdb.SecurityLevel.S1 441 } 442 rdbStore = await data_Rdb.getRdbStore(context, config); 443 let errInfo = undefined 444 try{ 445 rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE") 446 }catch(err){ 447 errInfo = err 448 } 449 expect(errInfo.code).assertEqual("401") 450 done(); 451 }) 452 453 /** 454 * @tc.name sync test 455 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_016 456 * @tc.desc sync test 457 */ 458 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_016', 0, function (done) { 459 let predicates = new data_Rdb.RdbPredicates("employee") 460 predicates = predicates.inDevices(["12345678abcd"]); 461 console.info(TAG + `SYNC_MODE_TIME_FIRST = ` + data_Rdb.SyncMode.SYNC_MODE_TIME_FIRST); 462 expect(data_Rdb.SyncMode.SYNC_MODE_TIME_FIRST).assertEqual(4); 463 console.info(TAG + "DATA_CHANGE = " + data_Rdb.ChangeType.DATA_CHANGE); 464 expect(data_Rdb.ChangeType.DATA_CHANGE).assertEqual(0); 465 console.info(TAG + "ASSET_CHANGE = " + data_Rdb.ChangeType.ASSET_CHANGE); 466 expect(data_Rdb.ChangeType.ASSET_CHANGE).assertEqual(1); 467 try{ 468 rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_TIME_FIRST, predicates, function (err, result) { 469 if (err) { 470 console.error(TAG + `Sync failed, code is ${err.code},message is ${err.message}`); 471 expect(err === null).assertFail(); 472 } 473 console.info(TAG + `Sync done.` + result); 474 expect(result !== null).assertFail(); 475 }) 476 }catch(error){ 477 console.error(TAG + `failed, code is ${error.code},message is ${error.message}`); 478 expect(error.code).assertEqual('401'); 479 done(); 480 } 481 }) 482 483 /** 484 * @tc.name sync test 485 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_016 486 * @tc.desc sync test 487 */ 488 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_017', 0, function (done) { 489 let predicates = new data_Rdb.RdbPredicates("employee") 490 predicates = predicates.inDevices(["12345678abcd"]); 491 console.info(TAG + `SYNC_MODE_NATIVE_FIRST = ` + data_Rdb.SyncMode.SYNC_MODE_NATIVE_FIRST); 492 expect(data_Rdb.SyncMode.SYNC_MODE_NATIVE_FIRST).assertEqual(5); 493 try{ 494 rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_NATIVE_FIRST, predicates, function (err, result) { 495 if (err) { 496 console.error(TAG + `Sync failed, code is ${err.code},message is ${err.message}`); 497 expect(err === null).assertFail(); 498 } 499 console.info(TAG + `Sync done.` + result); 500 expect(result !== null).assertFail(); 501 }) 502 }catch(error){ 503 console.error(TAG + `failed, code is ${error.code},message is ${error.message}`); 504 expect(error.code).assertEqual('401'); 505 done(); 506 } 507 }) 508 509 /** 510 * @tc.name sync test 511 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_018 512 * @tc.desc sync test 513 */ 514 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_018', 0, function (done) { 515 let predicates = new data_Rdb.RdbPredicates("employee") 516 predicates = predicates.inDevices(["12345678abcd"]); 517 console.info(TAG + `SYNC_MODE_CLOUD_FIRST = ` + data_Rdb.SyncMode.SYNC_MODE_CLOUD_FIRST); 518 expect(data_Rdb.SyncMode.SYNC_MODE_CLOUD_FIRST).assertEqual(6); 519 try{ 520 rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_CLOUD_FIRST, predicates, function (err, result) { 521 if (err) { 522 console.error(TAG + `Sync failed, code is ${err.code},message is ${err.message}`); 523 expect(err === null).assertFail(); 524 } 525 console.info(TAG + `Sync done.` + result); 526 expect(result !== null).assertFail(); 527 }) 528 }catch(error){ 529 console.error(TAG + `failed, code is ${error.code},message is ${error.message}`); 530 expect(error.code).assertEqual('401'); 531 done(); 532 } 533 }) 534 535 /** 536 * @tc.name sync test 537 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_019 538 * @tc.desc sync test 539 */ 540 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_019', 0, function (done) { 541 try{ 542 rdbStore.on("dataChange", data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD, function (devices) { 543 console.info(TAG + devices + " dataChange"); 544 expect(devices).assertEqual(null); 545 }); 546 }catch(err){ 547 console.info(TAG + "on dataChange " + err); 548 expect(err !== null).assertFalse(); 549 } 550 done(); 551 }) 552 553 /** 554 * @tc.name sync test 555 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_020 556 * @tc.desc sync test 557 */ 558 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_020', 0, function (done) { 559 try{ 560 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, function (table) { 561 console.info(TAG + table + " dataChange"); 562 expect(table).assertEqual(null); 563 }); 564 }catch(err){ 565 console.info(TAG + "on dataChange " + err); 566 expect(err !== null).assertFalse(); 567 } 568 done(); 569 }) 570 571 /** 572 * @tc.name sync test 573 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_021 574 * @tc.desc sync test 575 */ 576 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_021', 0, function (done) { 577 try{ 578 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, function (type) { 579 console.info(TAG + type + " dataChange"); 580 expect(type).assertEqual(null); 581 }); 582 }catch(err){ 583 console.info(TAG + "on dataChange " + err); 584 expect(err !== null).assertFalse(); 585 } 586 done(); 587 }) 588 589 /** 590 * @tc.name sync test 591 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_022 592 * @tc.desc sync test 593 */ 594 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_022', 0, function (done) { 595 function Observer(inserted) { 596 console.info(TAG + inserted + " dataChange"); 597 expect(inserted).assertEqual(null); 598 } 599 try{ 600 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, Observer); 601 }catch(err){ 602 console.info(TAG + "on dataChange " + err); 603 expect(err !== null).assertFalse(); 604 } 605 done(); 606 }) 607 608 /** 609 * @tc.name sync test 610 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_023 611 * @tc.desc sync test 612 */ 613 614 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_023', 0, function (done) { 615 try{ 616 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, function (updated) { 617 console.info(TAG + updated + " dataChange"); 618 expect(updated).assertEqual(null); 619 }); 620 }catch(err){ 621 console.info(TAG + "on dataChange " + err); 622 expect(err !== null).assertFalse(); 623 } 624 done(); 625 }) 626 627 /** 628 * @tc.name sync test 629 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_024 630 * @tc.desc sync test 631 */ 632 633 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_024', 0, function (done) { 634 try{ 635 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, function (deleted) { 636 console.info(TAG + deleted + " dataChange"); 637 expect(deleted).assertEqual(null); 638 }); 639 }catch(err){ 640 console.info(TAG + "on dataChange " + err); 641 expect(err !== null).assertFalse(); 642 } 643 done(); 644 }) 645 646 /** 647 * @tc.name set distributed table using two table name 648 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_025 649 * @tc.desc set distributed table type DISTRIBUTED_DEVICE 650 */ 651 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_025', 0, async function (done) { 652 try { 653 await rdbStore.setDistributedTables(['employee'], data_Rdb.DistributedType.DISTRIBUTED_DEVICE, function (err){ 654 if (err) { 655 console.error(TAG + `SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 656 expect(null).assertFail(); 657 done(); 658 } 659 console.info(TAG + `SetDistributedTables successfully.`); 660 expect(err == undefined).assertTrue(); 661 done(); 662 }) 663 } catch (err) { 664 console.info(TAG + "set employee to be distributed table failed"); 665 expect(null).assertFail(); 666 done() 667 } 668 }) 669 670 /** 671 * @tc.name set distributed table using two table name 672 * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_026 673 * @tc.desc set distributed table type DISTRIBUTED_CLOUD 674 */ 675 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_026', 0, async function (done) { 676 try { 677 await rdbStore.setDistributedTables(['test'], data_Rdb.DistributedType.DISTRIBUTED_CLOUD, function (err){ 678 if (err) { 679 console.error(TAG + `SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 680 expect(null).assertFail(); 681 done(); 682 } 683 console.info(TAG + `SetDistributedTables successfully.`); 684 expect(err == undefined).assertTrue(); 685 done(); 686 }) 687 } catch (err) { 688 console.info(TAG + "set employee and product to be distributed table failed"); 689 expect(null).assertFail(); 690 done() 691 } 692 }) 693 694 695 console.info(TAG + "*************Unit Test End*************"); 696}) 697} 698