1/* 2 * Copyright (C) 2021-2024 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 * @tc.size MediumTest 15 * @tc.type Function 16 * @tc.level Level 2 17 */ 18 19import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; 20import data_Rdb from '@ohos.data.relationalStore'; 21import ability_featureAbility from '@ohos.ability.featureAbility'; 22 23const ERRCODE = 801; 24var context = ability_featureAbility.getContext(); 25var sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + 26"id INTEGER PRIMARY KEY AUTOINCREMENT," + 27"name TEXT NOT NULL," +"age INTEGER)" 28sqlStatement = "CREATE TABLE IF NOT EXISTS product (" + 29"id INTEGER PRIMARY KEY AUTOINCREMENT," + 30"name TEXT NOT NULL," +"price REAL," + 31"vendor INTEGER," +"describe TEXT)" 32const TAG = "[RelationalStore_JSKITS_TEST_Distributed]" 33const STORE_NAME = "distributed_rdb.db" 34var rdbStore = undefined; 35const config = { 36 "name": STORE_NAME, 37 securityLevel: data_Rdb.SecurityLevel.S1 38} 39 40async function executeSql1() { 41 let sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + 42 "id INTEGER PRIMARY KEY AUTOINCREMENT," + 43 "name TEXT NOT NULL," + 44 "age INTEGER)" 45try { 46 await rdbStore.executeSql(sqlStatement, null) 47 console.info(TAG + "create table employee success") 48} catch (err) { 49 console.info(TAG + "create table employee failed") 50 expect(null).assertFail() 51} 52} 53 54async function executeSql2() { 55 let sqlStatement = "CREATE TABLE IF NOT EXISTS product (" + 56 "id INTEGER PRIMARY KEY AUTOINCREMENT," + 57 "name TEXT NOT NULL," + 58 "price REAL," + 59 "vendor INTEGER," + 60 "describe TEXT)" 61try { 62 await rdbStore.executeSql(sqlStatement, null) 63 console.info(TAG + "create table product success") 64} catch (err) { 65 console.info(TAG + "create table product failed") 66 expect(null).assertFail() 67} 68} 69async function executeSql3() { 70 let sqlStatement = "CREATE TABLE IF NOT EXISTS test (" + 71 "id INTEGER PRIMARY KEY AUTOINCREMENT," + 72 "name TEXT NOT NULL," + 73 "price REAL," + 74 "vendor INTEGER," + 75 "describe TEXT)" 76 try { 77 await rdbStore.executeSql(sqlStatement, null) 78 console.info(TAG + "create table product success") 79 } catch (err) { 80 console.info(TAG + "create table product failed") 81 expect(null).assertFail() 82 } 83} 84 85function storeObserver(devices) { 86 console.info(TAG + devices + " dataChange"); 87 expect(devices).assertEqual(null) 88} 89 90export default function relationalStoreDistributedTest() { 91describe('relationalStoreDistributedTest', function () { 92 beforeAll(async function () { 93 console.info(TAG + 'beforeAll') 94 }) 95 96 beforeEach(async function () { 97 console.info(TAG + 'beforeEach') 98 rdbStore = await data_Rdb.getRdbStore(context, config); 99 console.info(TAG + "create RelationalStore store success") 100 await executeSql1(); 101 await executeSql2(); 102 await executeSql3(); 103 }) 104 105 afterEach(async function () { 106 console.info(TAG + 'afterEach') 107 await data_Rdb.deleteRdbStore(context, STORE_NAME); 108 }) 109 110 afterAll(async function () { 111 console.info(TAG + 'afterAll') 112 }) 113 114 console.info(TAG + "*************Unit Test Begin*************"); 115 116 /** 117 * @tc.name testRdbStoreDistributed0002 118 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0100 119 * @tc.desc RelationalStore set distributed table using none table as argment 120 * @tc.size MediumTest 121 * @tc.type Function 122 * @tc.level Level 2 123 */ 124 it('testRdbStoreDistributed0002', 0, async function (done) { 125 console.info(TAG + "************* testRdbStoreDistributed002 start *************"); 126 try { 127 await rdbStore.setDistributedTables([]) 128 console.info(TAG + "set none to be distributed table success"); 129 expect(rdbStore).assertEqual(rdbStore) 130 } catch (err) { 131 console.info(TAG + "setDistributed002 failed"+ `, error code is ${err.code}, message is ${err.message}`); 132 expect(err.code).assertEqual(ERRCODE); 133 } 134 done() 135 console.info(TAG + "************* testRdbStoreDistributed002 end *************"); 136 }) 137 138 /** 139 * @tc.name testRdbStoreDistributed0003 140 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0200 141 * @tc.desc set distributed table using one table name 142 * @tc.size MediumTest 143 * @tc.type Function 144 * @tc.level Level 2 145 */ 146 it('testRdbStoreDistributed0003', 0, async function (done) { 147 console.info(TAG + "************* testRdbStoreDistributed003 start *************"); 148 try { 149 await rdbStore.setDistributedTables(['employee']) 150 console.info(TAG + "set employee to be distributed table success"); 151 expect(rdbStore).assertEqual(rdbStore) 152 } catch (err) { 153 console.info(TAG + "setDistributed003 failed"+ `, error code is ${err.code}, message is ${err.message}`); 154 expect(err.code).assertEqual(ERRCODE); 155 } 156 done() 157 console.info(TAG + "************* testRdbStoreDistributed003 end *************"); 158 }) 159 160 /** 161 * @tc.name testRdbStoreDistributed0004 162 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0300 163 * @tc.desc set distributed table using two table name 164 * @tc.size MediumTest 165 * @tc.type Function 166 * @tc.level Level 2 167 */ 168 it('testRdbStoreDistributed0004', 0, async function (done) { 169 console.info(TAG + "************* testRdbStoreDistributed004 start *************"); 170 try { 171 await rdbStore.setDistributedTables(['employee', 'product']) 172 console.info(TAG + "set employee and product to be distributed table success"); 173 expect(rdbStore).assertEqual(rdbStore) 174 } catch (err) { 175 console.info(TAG + "setDistributed004 failed"+ `, error code is ${err.code}, message is ${err.message}`); 176 expect(err.code).assertEqual(ERRCODE); 177 } 178 done() 179 console.info(TAG + "************* testRdbStoreDistributed004 end *************"); 180 }) 181 182 /** 183 * @tc.name testRdbStoreDistributed0005 184 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0400 185 * @tc.desc insert record after setting distributed table 186 * @tc.size MediumTest 187 * @tc.type Function 188 * @tc.level Level 2 189 */ 190 it('testRdbStoreDistributed0005', 0, async function (done) { 191 console.info(TAG + "************* testRdbStoreDistributed005 start *************"); 192 const record = { 193 "name": "Jim", 194 "age": 20, 195 } 196 try { 197 let rowId = await rdbStore.insert("employee", record) 198 console.info(TAG + "insert one record success " + rowId) 199 expect(1).assertEqual(rowId) 200 } catch (err) { 201 console.info(TAG + "insert one record failed" + err); 202 expect(null).assertFail(); 203 } 204 done() 205 console.info(TAG + "************* testRdbStoreDistributed005 end *************"); 206 }) 207 208 /** 209 * @tc.name testRdbStoreDistributed0006 210 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0500 211 * @tc.desc update record after setting distributed table 212 * @tc.size MediumTest 213 * @tc.type Function 214 * @tc.level Level 2 215 */ 216 it('testRdbStoreDistributed0006', 0, async function (done) { 217 console.info(TAG + "************* testRdbStoreDistributed006 start *************"); 218 const record1 = { 219 "name": "Jim", 220 "age": 20, 221 } 222 const record2 = { 223 "name": "Jim", 224 "age": 30, 225 } 226 await rdbStore.insert("employee", record1); 227 try { 228 let predicate = new data_Rdb.RdbPredicates("employee"); 229 predicate.equalTo("id", 1); 230 try { 231 let rowId = await rdbStore.update(record2, predicate); 232 console.info(TAG + "update one record success " + rowId) 233 expect(1).assertEqual(rowId) 234 } catch (err) { 235 console.info(TAG + "update one record failed" + err); 236 expect(null).assertFail(); 237 } 238 } catch (err) { 239 console.info(TAG + "construct predicate failed"); 240 expect(null).assertFail(); 241 } 242 done() 243 console.info(TAG + "************* testRdbStoreDistributed006 end *************"); 244 }) 245 246 /** 247 * @tc.name testRdbStoreDistributed0007 248 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0600 249 * @tc.desc query record after setting distributed table 250 * @tc.size MediumTest 251 * @tc.type Function 252 * @tc.level Level 2 253 */ 254 it('testRdbStoreDistributed0007', 0, async function (done) { 255 console.info(TAG + "************* testRdbStoreDistributed0007 start *************"); 256 const record1 = { 257 "name": "Jim", 258 "age": 30, 259 } 260 await rdbStore.insert("employee", record1); 261 try { 262 let predicates = new data_Rdb.RdbPredicates("employee") 263 let resultSet = await rdbStore.query(predicates) 264 try { 265 console.info(TAG + "product resultSet query done"); 266 expect(true).assertEqual(resultSet.goToFirstRow()) 267 const id = await resultSet.getLong(resultSet.getColumnIndex("id")) 268 const name = await resultSet.getString(resultSet.getColumnIndex("name")) 269 const age = await resultSet.getLong(resultSet.getColumnIndex("age")) 270 271 await expect(1).assertEqual(id); 272 await expect("Jim").assertEqual(name); 273 await expect(30).assertEqual(age); 274 resultSet.close(); 275 expect(true).assertEqual(resultSet.isClosed) 276 } catch (e) { 277 console.info(TAG + "result get value failed") 278 expect(null).assertFail(); 279 } 280 } catch (err) { 281 console.info("query failed"); 282 expect(null).assertFail(); 283 } 284 done(); 285 console.info(TAG + "************* testRdbStoreDistributed0007 end *************"); 286 }) 287 288 /** 289 * @tc.name testRdbStoreDistributed0008 290 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0700 291 * @tc.desc delete record after setting distributed table 292 * @tc.size MediumTest 293 * @tc.type Function 294 * @tc.level Level 2 295 */ 296 it('testRdbStoreDistributed0008', 0, async function (done) { 297 console.info(TAG + "************* testRdbStoreDistributed0008 start *************"); 298 const record1 = { 299 "name": "Jim", 300 "age": 20, 301 } 302 await rdbStore.insert("employee", record1); 303 let predicates = new data_Rdb.RdbPredicates("employee") 304 try { 305 let number = await rdbStore.delete(predicates) 306 console.info(TAG + "employee Delete done: " + number) 307 expect(1).assertEqual(number) 308 } catch (err) { 309 console.info(TAG + "delete record failed"); 310 expect(null).assertFail() 311 } 312 done(); 313 console.info(TAG + "************* testRdbStoreDistributed0008 end *************"); 314 }) 315 316 /** 317 * @tc.name testRdbStoreDistributed0009 318 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0800 319 * @tc.desc predicates inDevice 320 * @tc.size MediumTest 321 * @tc.type Function 322 * @tc.level Level 2 323 */ 324 it('testRdbStoreDistributed0009', 0, async function (done) { 325 console.info(TAG + "************* testRdbStoreDistributed0009 start *************"); 326 let predicates = new data_Rdb.RdbPredicates("employee") 327 try { 328 let pr = predicates.inDevices(["1234567890"]); 329 console.info(TAG + "inDevices success"); 330 expect(pr !== null).assertTrue(); 331 done(); 332 } catch (err) { 333 console.info(TAG + "inDevices failed"); 334 expect(null).assertFail(); 335 done(); 336 } 337 console.info(TAG + "************* testRdbStoreDistributed0009 end *************"); 338 }) 339 340 /** 341 * @tc.name testRdbStoreDistributed0010 342 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_0900 343 * @tc.desc predicates inAllDevices 344 * @tc.size MediumTest 345 * @tc.type Function 346 * @tc.level Level 2 347 */ 348 it('testRdbStoreDistributed0010', 0, async function (done) { 349 console.info(TAG + "************* testRdbStoreDistributed0010 start *************"); 350 let predicates = new data_Rdb.RdbPredicates("employee") 351 try { 352 predicates = predicates.inAllDevices(); 353 console.info(TAG + "inAllDevices success"); 354 expect(predicates).assertEqual(predicates); 355 } catch (err) { 356 console.info(TAG + "inAllDevices failed"); 357 expect(null).assertFail(); 358 } 359 done(); 360 console.info(TAG + "************* testRdbStoreDistributed0010 end *************"); 361 }) 362 363 /** 364 * @tc.name testRdbStoreDistributed0011 365 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1000 366 * @tc.desc sync test 367 * @tc.size MediumTest 368 * @tc.type Function 369 * @tc.level Level 2 370 */ 371 it('testRdbStoreDistributed0011', 0, async function (done) { 372 console.info(TAG + "************* testRdbStoreDistributed0011 start *************"); 373 let predicates = new data_Rdb.RdbPredicates("employee") 374 let pr = predicates.inDevices(["12345678abcd"]); 375 await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates).then(() => { 376 console.info(TAG + "sync push success"); 377 }).catch((err) => { 378 console.info(TAG + "err.code:" + err.code + "err.msg:" + err.message) 379 expect(err.code).assertEqual(14800000) 380 }); 381 await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PULL, predicates).then(() => { 382 console.info(TAG + "sync pull success"); 383 }).catch((err) => { 384 console.info(TAG + "err.code:" + err.code + "err.msg:" + err.message) 385 expect(err.code).assertEqual(14800000) 386 }); 387 done(); 388 console.info(TAG + "************* testRdbStoreDistributed0011 end *************"); 389 }) 390 391 /** 392 * @tc.name testRdbStoreDistributedCallback0011 393 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1100 394 * @tc.desc sync Callback test 395 * @tc.size MediumTest 396 * @tc.type Function 397 * @tc.level Level 2 398 */ 399 it('testRdbStoreDistributedCallback0011', 0, async function (done) { 400 console.info(TAG + "************* testRdbStoreDistributedCallback0011 start *************"); 401 function sleep(ms) { 402 return new Promise(resolve => setTimeout(resolve, ms)); 403 } 404 let predicates = new data_Rdb.RdbPredicates("employee") 405 predicates = predicates.inDevices(["12345678abcd"]); 406 await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates, async (err,ret)=>{ 407 if(err){ 408 console.info(TAG + "err.code:" + err.code + "err.msg:" + err.message) 409 expect(err.code).assertEqual(14800000) 410 } 411 console.info(TAG + "sync push success"); 412 await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PULL, predicates,(err,ret)=>{ 413 if(err){ 414 console.info(TAG + "err.code:" + err.code + "err.msg:" + err.message) 415 expect(err.code).assertEqual(14800000) 416 } 417 console.info(TAG + "sync push success"); 418 done(); 419 }); 420 }); 421 console.info(TAG + "************* testRdbStoreDistributedCallback0011 end *************"); 422 }) 423 424 /** 425 * @tc.name testRdbStoreDistributed0012 426 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1200 427 * @tc.desc subscribe test 428 * @tc.size MediumTest 429 * @tc.type Function 430 * @tc.level Level 2 431 */ 432 it('testRdbStoreDistributed0012', 0, async function (done) { 433 console.info(TAG + "************* testRdbStoreDistributed0012 start *************"); 434 try{ 435 rdbStore.on("dataChange", data_Rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 436 console.info(TAG + "on dataChange success "); 437 }catch(err){ 438 console.info(TAG + "on dataChange " + err); 439 expect(err !== null).assertFalse(); 440 } 441 done() 442 console.info(TAG + "************* testRdbStoreDistributed0012 end *************"); 443 }) 444 445 /** 446 * @tc.name testRdbStoreDistributed0013 447 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1300 448 * @tc.desc subscribe test 449 * @tc.size MediumTest 450 * @tc.type Function 451 * @tc.level Level 2 452 */ 453 it('testRdbStoreDistributed0013', 0, function (done) { 454 console.info(TAG + "************* testRdbStoreDistributed0013 start *************"); 455 try{ 456 rdbStore.off("dataChange", data_Rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 457 console.info(TAG + "off dataChange success "); 458 }catch(err){ 459 console.info(TAG + "off dataChange " + err); 460 expect(err !== null).assertFalse(); 461 } 462 done() 463 console.info(TAG + "************* testRdbStoreDistributed0013 end *************"); 464 }) 465 466 /** 467 * @tc.name testRdbStoreDistributed0014 468 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1400 469 * @tc.desc obtainDistributedTableName test 470 * @tc.size MediumTest 471 * @tc.type Function 472 * @tc.level Level 2 473 */ 474 it('testRdbStoreDistributed0014', 0, async function (done){ 475 let errInfo = undefined; 476 try{ 477 rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE", function (err, tableName) { 478 expect(err != null).assertTrue(); 479 console.info('ObtainDistributedTableName failed, Unauthorized.' + err) 480 }) 481 }catch(err){ 482 errInfo = err 483 } 484 expect(errInfo.code).assertEqual("401") 485 done(); 486 }) 487 488 /** 489 * @tc.name testRdbStoreDistributed0015 490 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1500 491 * @tc.desc obtainDistributedTableName test 492 * @tc.size MediumTest 493 * @tc.type Function 494 * @tc.level Level 2 495 */ 496 it('testRdbStoreDistributed0015',0,async function (done){ 497 await data_Rdb.deleteRdbStore(context, STORE_NAME); 498 const config = { 499 "name": STORE_NAME, 500 securityLevel: data_Rdb.SecurityLevel.S1 501 } 502 rdbStore = await data_Rdb.getRdbStore(context, config); 503 let errInfo = undefined 504 try{ 505 rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE") 506 }catch(err){ 507 errInfo = err 508 } 509 expect(errInfo.code).assertEqual("401") 510 done(); 511 }) 512 513 /** 514 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_016 515 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1600 516 * @tc.desc sync test 517 * @tc.size MediumTest 518 * @tc.type Function 519 * @tc.level Level 2 520 */ 521 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_016', 0, function (done) { 522 let predicates = new data_Rdb.RdbPredicates("employee") 523 predicates = predicates.inDevices(["12345678abcd"]); 524 console.info(TAG + `SYNC_MODE_TIME_FIRST = ` + data_Rdb.SyncMode.SYNC_MODE_TIME_FIRST); 525 expect(data_Rdb.SyncMode.SYNC_MODE_TIME_FIRST).assertEqual(4); 526 console.info(TAG + "DATA_CHANGE = " + data_Rdb.ChangeType.DATA_CHANGE); 527 expect(data_Rdb.ChangeType.DATA_CHANGE).assertEqual(0); 528 console.info(TAG + "ASSET_CHANGE = " + data_Rdb.ChangeType.ASSET_CHANGE); 529 expect(data_Rdb.ChangeType.ASSET_CHANGE).assertEqual(1); 530 try{ 531 rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_TIME_FIRST, predicates, function (err, result) { 532 if (err) { 533 console.error(TAG + `Sync failed, code is ${err.code},message is ${err.message}`); 534 expect(err === null).assertFail(); 535 } 536 console.info(TAG + `Sync done.` + result); 537 expect(result !== null).assertFail(); 538 }) 539 }catch(error){ 540 console.error(TAG + `failed, code is ${error.code},message is ${error.message}`); 541 expect(error.code).assertEqual('401'); 542 done(); 543 } 544 }) 545 546 /** 547 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_017 548 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1700 549 * @tc.desc sync test 550 * @tc.size MediumTest 551 * @tc.type Function 552 * @tc.level Level 2 553 */ 554 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_017', 0, function (done) { 555 let predicates = new data_Rdb.RdbPredicates("employee") 556 predicates = predicates.inDevices(["12345678abcd"]); 557 console.info(TAG + `SYNC_MODE_NATIVE_FIRST = ` + data_Rdb.SyncMode.SYNC_MODE_NATIVE_FIRST); 558 expect(data_Rdb.SyncMode.SYNC_MODE_NATIVE_FIRST).assertEqual(5); 559 try{ 560 rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_NATIVE_FIRST, predicates, function (err, result) { 561 if (err) { 562 console.error(TAG + `Sync failed, code is ${err.code},message is ${err.message}`); 563 expect(err === null).assertFail(); 564 } 565 console.info(TAG + `Sync done.` + result); 566 expect(result !== null).assertFail(); 567 }) 568 }catch(error){ 569 console.error(TAG + `failed, code is ${error.code},message is ${error.message}`); 570 expect(error.code).assertEqual('401'); 571 done(); 572 } 573 }) 574 575 /** 576 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_018 577 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1800 578 * @tc.desc sync test 579 * @tc.size MediumTest 580 * @tc.type Function 581 * @tc.level Level 2 582 */ 583 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_018', 0, function (done) { 584 let predicates = new data_Rdb.RdbPredicates("employee") 585 predicates = predicates.inDevices(["12345678abcd"]); 586 console.info(TAG + `SYNC_MODE_CLOUD_FIRST = ` + data_Rdb.SyncMode.SYNC_MODE_CLOUD_FIRST); 587 expect(data_Rdb.SyncMode.SYNC_MODE_CLOUD_FIRST).assertEqual(6); 588 try{ 589 rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_CLOUD_FIRST, predicates, function (err, result) { 590 if (err) { 591 console.error(TAG + `Sync failed, code is ${err.code},message is ${err.message}`); 592 expect(err === null).assertFail(); 593 } 594 console.info(TAG + `Sync done.` + result); 595 expect(result !== null).assertFail(); 596 }) 597 }catch(error){ 598 console.error(TAG + `failed, code is ${error.code},message is ${error.message}`); 599 expect(error.code).assertEqual('401'); 600 done(); 601 } 602 }) 603 604 /** 605 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_019 606 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_1900 607 * @tc.desc sync test 608 * @tc.size MediumTest 609 * @tc.type Function 610 * @tc.level Level 2 611 */ 612 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_019', 0, function (done) { 613 try{ 614 rdbStore.on("dataChange", data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD, function (devices) { 615 console.info(TAG + devices + " dataChange"); 616 expect(devices).assertEqual(null); 617 }); 618 }catch(err){ 619 console.info(TAG + "on dataChange " + err); 620 expect(err !== null).assertFalse(); 621 } 622 done(); 623 }) 624 625 /** 626 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_020 627 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_2000 628 * @tc.desc sync test 629 * @tc.size MediumTest 630 * @tc.type Function 631 * @tc.level Level 2 632 */ 633 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_020', 0, function (done) { 634 try{ 635 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, function (table) { 636 console.info(TAG + table + " dataChange"); 637 expect(table).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 SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_021 648 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_2100 649 * @tc.desc sync test 650 * @tc.size MediumTest 651 * @tc.type Function 652 * @tc.level Level 2 653 */ 654 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_021', 0, function (done) { 655 try{ 656 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, function (type) { 657 console.info(TAG + type + " dataChange"); 658 expect(type).assertEqual(null); 659 }); 660 }catch(err){ 661 console.info(TAG + "on dataChange " + err); 662 expect(err !== null).assertFalse(); 663 } 664 done(); 665 }) 666 667 /** 668 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_022 669 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_2200 670 * @tc.desc sync test 671 * @tc.size MediumTest 672 * @tc.type Function 673 * @tc.level Level 2 674 */ 675 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_022', 0, function (done) { 676 function Observer(inserted) { 677 console.info(TAG + inserted + " dataChange"); 678 expect(inserted).assertEqual(null); 679 } 680 try{ 681 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, Observer); 682 }catch(err){ 683 console.info(TAG + "on dataChange " + err); 684 expect(err !== null).assertFalse(); 685 } 686 done(); 687 }) 688 689 /** 690 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_023 691 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_2300 692 * @tc.desc sync test 693 * @tc.size MediumTest 694 * @tc.type Function 695 * @tc.level Level 2 696 */ 697 698 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_023', 0, function (done) { 699 try{ 700 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, function (updated) { 701 console.info(TAG + updated + " dataChange"); 702 expect(updated).assertEqual(null); 703 }); 704 }catch(err){ 705 console.info(TAG + "on dataChange " + err); 706 expect(err !== null).assertFalse(); 707 } 708 done(); 709 }) 710 711 /** 712 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_024 713 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_2400 714 * @tc.desc sync test 715 * @tc.size MediumTest 716 * @tc.type Function 717 * @tc.level Level 2 718 */ 719 720 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_024', 0, function (done) { 721 try{ 722 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_CLOUD_DETAILS, function (deleted) { 723 console.info(TAG + deleted + " dataChange"); 724 expect(deleted).assertEqual(null); 725 }); 726 }catch(err){ 727 console.info(TAG + "on dataChange " + err); 728 expect(err !== null).assertFalse(); 729 } 730 done(); 731 }) 732 733 /** 734 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_025 735 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_2500 736 * @tc.desc set distributed table type DISTRIBUTED_DEVICE 737 * @tc.size MediumTest 738 * @tc.type Function 739 * @tc.level Level 2 740 */ 741 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_025', 0, async function (done) { 742 try { 743 await rdbStore.setDistributedTables(['employee'], data_Rdb.DistributedType.DISTRIBUTED_DEVICE, function (err){ 744 if (err) { 745 console.error(TAG + `SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 746 expect(null).assertFail(); 747 done(); 748 } 749 console.info(TAG + `SetDistributedTables successfully.`); 750 expect(err == undefined).assertTrue(); 751 done(); 752 }) 753 } catch (err) { 754 console.info(TAG + "set employee to be distributed table failed"); 755 expect(null).assertFail(); 756 done() 757 } 758 }) 759 760 /** 761 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_026 762 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_2600 763 * @tc.desc set distributed table type DISTRIBUTED_CLOUD 764 * @tc.size MediumTest 765 * @tc.type Function 766 * @tc.level Level 2 767 */ 768 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_026', 0, async function (done) { 769 try { 770 await rdbStore.setDistributedTables(['test'], data_Rdb.DistributedType.DISTRIBUTED_CLOUD, function (err){ 771 if (err) { 772 console.error(TAG + `SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 773 expect(null).assertFail(); 774 done(); 775 } 776 console.info(TAG + `SetDistributedTables successfully.`); 777 expect(err == undefined).assertTrue(); 778 done(); 779 }) 780 } catch (err) { 781 console.info(TAG + "set employee and product to be distributed table failed"); 782 expect(null).assertFail(); 783 done() 784 } 785 }) 786 787 /** 788 * @tc.name SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_027 789 * @tc.number SUB_DistributedData_RelationalStore_SDK_SetDistributeJsAPITest_2700 790 * @tc.desc sync test 791 * @tc.size MediumTest 792 * @tc.type Function 793 * @tc.level Level 2 794 */ 795 it('SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_027', 0, async function (done) { 796 try{ 797 rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, function (table) { 798 console.info(TAG + table + " dataChange"); 799 expect(table).assertEqual(null); 800 }); 801 }catch(err){ 802 console.info(TAG + "on dataChange " + err); 803 expect(err !== null).assertFalse(); 804 } 805 done(); 806 807 }) 808 809 810 console.info(TAG + "*************Unit Test End*************"); 811}) 812} 813