未验证 提交 4dc6173e 编写于 作者: O openharmony_ci 提交者: Gitee

!9927 【Distributeddatamgr】【Master】relationalStore用例优化,优化用例执行时序

Merge pull request !9927 from yanglifeng/master
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import dataRdb from '@ohos.data.rdb';
const TAG = "[RDB_JSKITS_TEST]"
......@@ -24,36 +24,34 @@ const STORE_CONFIG = {
name: "InsertTest.db",
}
var rdbStore = undefined;
var resultSet = undefined;
let rdbStore = undefined;
let resultSet = undefined;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default function rdbstoreInsertTest() {
describe('rdbstoreInsertTest', function () {
describe('rdbstoreInsertTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null)
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
await rdbStore.executeSql("DELETE FROM test");
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null)
})
afterEach(async function () {
console.info(TAG + 'afterEach')
rdbStore = null
await dataRdb.deleteRdbStore("InsertTest.db")
})
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await dataRdb.deleteRdbStore("InsertTest.db").then(() => {
sleep(2)
});
})
console.info(TAG + "*************Unit Test Begin*************");
......@@ -96,8 +94,7 @@ describe('rdbstoreInsertTest', function () {
let predicates = new dataRdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
await rdbStore.query(predicates).then((resultSet) => {
console.info(TAG + "resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
......@@ -114,12 +111,15 @@ describe('rdbstoreInsertTest', function () {
expect(2).assertEqual(blobType[1])
expect(3).assertEqual(blobType[2])
expect(false).assertEqual(resultSet.goToNextRow())
} catch (e) {
console.info("insert1 error " + e);
}
resultSet = null
done()
done();
console.info(TAG + "************* testRdbStoreInsert0001 end *************");
resultSet.close();
resultSet = null;
}).catch((err) => {
console.error(`Query failed, code is ${err.code},message is ${err.message}`);
expect().assertFail();
done();
})
})
/**
......@@ -129,7 +129,7 @@ describe('rdbstoreInsertTest', function () {
*/
it('testRdbStoreInsert0002', 0, async function (done) {
console.info(TAG + "************* testRdbStoreInsert0002 start *************");
var u8 = new Uint8Array([1, 2, 3])
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
......@@ -137,17 +137,16 @@ describe('rdbstoreInsertTest', function () {
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("wrong", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.info(TAG + "insert first done: " + ret)
expect(null).assertFail()
await rdbStore.insert("wrong", valueBucket).then(async (ret) => {
expect(1).assertEqual(ret);
console.info(TAG + "insert first done: " + ret);
done();
console.info(TAG + "************* testRdbStoreInsert0002 end *************");
}).catch((err) => {
console.info(TAG + "insert with wrong table")
console.info(TAG + "insert with wrong table" + err)
done();
})
}
done()
console.info(TAG + "************* testRdbStoreInsert0002 end *************");
})
/**
......@@ -157,24 +156,29 @@ describe('rdbstoreInsertTest', function () {
*/
it('testRdbStoreInsert0003', 0, async function (done) {
console.info(TAG + "************* testRdbStoreInsert0003 start *************");
let errInfo = undefined;
var u8 = new Uint8Array([1, 2, 3])
{
let u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
try{
rdbStore.insert(null, valueBucket)
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
}
done()
try {
await rdbStore.insert(null, valueBucket).then(() => {
console.log("insert done");
expect().assertFail();
done();
}).catch((error) => {
console.log("insert error" + error);
expect().assertFail();
done();
})
} catch (err) {
console.log(`insert failed, code is ${err.code},message is ${err.message}`);
expect(err.code).assertEqual('401');
done();
console.info(TAG + "************* testRdbStoreInsert0003 end *************");
}
})
/**
......@@ -184,23 +188,23 @@ describe('rdbstoreInsertTest', function () {
*/
it('testRdbStoreInsert0004', 0, async function (done) {
console.log(TAG + "************* testRdbStoreInsert0004 start *************");
var u8 = new Uint8Array([1, 2, 3])
let u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": null,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.log(TAG + "insert first done: " + ret)
}).catch((err) => {
console.log(TAG + "insert with null table")
expect(null).assertFail()
})
await rdbStore.insert("test", valueBucket).then(async (ret) => {
expect(1).assertEqual(ret);
console.log(TAG + "insert first done: " + ret);
done();
console.log(TAG + "************* testRdbStoreInsert0004 end *************");
}).catch((err) => {
console.log(TAG + "insert with null table" + err);
expect().assertFail();
done();
})
})
/**
......@@ -233,14 +237,13 @@ describe('rdbstoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.batchInsert("test1", valueBuckets).then((number) => {
expect(3).assertEqual(number)
}).catch((err) =>{
expect(false).assertTrue();
}).catch((err) => {
expect().assertFail();
})
let predicates = new dataRdb.RdbPredicates("test1");
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
await rdbStore.query(predicates).then((resultSet) => {
console.info(TAG + "resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
......@@ -257,32 +260,15 @@ describe('rdbstoreInsertTest', function () {
expect(2).assertEqual(blobType[1])
expect(3).assertEqual(blobType[2])
expect(false).assertEqual(resultSet.goToNextRow())
} catch (e) {
console.info("BatchInsert1 error " + e);
}
predicates = new dataRdb.RdbPredicates("test1");
predicates.equalTo("name", "lisi")
resultSet = await rdbStore.query(predicates)
try {
console.info(TAG + "resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(2).assertEqual(id);
expect("lisi").assertEqual(name)
expect(23).assertEqual(age)
expect(200).assertEqual(salary)
expect(false).assertEqual(resultSet.goToNextRow())
} catch (e) {
console.info("BatchInsert1 error " + e);
}
resultSet = null
done()
done();
console.info(TAG + "************* testRdbStorebatchInsertPromise0001 end *************");
resultSet.close();
resultSet = null;
}).catch((err) => {
console.error(`Updated failed, err is ${err}`);
expect().assertFail();
done();
})
})
/**
......@@ -315,13 +301,12 @@ describe('rdbstoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.batchInsert("test2", valueBuckets).then((number) => {
expect(3).assertEqual(number)
}).catch((err) =>{
expect(false).assertTrue();
}).catch((err) => {
expect().assertFail();
})
let predicates = new dataRdb.RdbPredicates("test2");
predicates.equalTo("name", "lisi")
let resultSet = await rdbStore.query(predicates)
try {
await rdbStore.query(predicates).then(async (resultSet) => {
console.info(TAG + "resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
......@@ -334,19 +319,37 @@ describe('rdbstoreInsertTest', function () {
expect("lisi").assertEqual(name)
expect(23).assertEqual(age)
expect(200).assertEqual(salary)
await rdbStore.delete(predicates).then((number) => {
}).catch((err) => {
console.error(TAG +`Query failed, code is ${err.code},message is ${err.message}`);
expect().assertFail();
})
try {
await rdbStore.delete(predicates).then(async (number) => {
console.log(TAG +`delete done = ` + number);
expect(1).assertEqual(number)
}).then(async () => {
resultSet = await rdbStore.query(predicates).catch((err) =>{
expect(err != null).assertTrue();
}).catch((err) => {
console.error(TAG +`delete failed, code is ${err.code},message is ${err.message}`);
expect().assertFail();
})
await rdbStore.query(predicates).then(async (resultSet) => {
console.log(TAG +`Query done = ` + resultSet.rowCount);
expect(resultSet.rowCount).assertEqual(0);
done();
console.info(TAG + "************* testRdbStorebatchInsertPromise0002 end *************");
resultSet.close();
resultSet = null;
}).catch((error) => {
console.error(TAG +`Query failed, code is ${error.code},message is ${error.message}`);
expect().assertFail();
done();
})
} catch (e) {
console.info("BatchInsert2 error " + e);
console.info(TAG +" error " + e);
expect().assertFail();
done();
}
resultSet = null
done()
console.info(TAG + "************* testRdbStorebatchInsertPromise0002 end *************");
})
/**
......@@ -379,7 +382,7 @@ describe('rdbstoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.batchInsert("test3", valueBuckets).then((number) => {
expect(3).assertEqual(number)
}).catch((err) =>{
}).catch((err) => {
expect(false).assertTrue();
})
......@@ -394,6 +397,7 @@ describe('rdbstoreInsertTest', function () {
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
resultSet.close();
console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(1).assertEqual(id);
expect("zhangsan").assertEqual(name)
......@@ -416,6 +420,7 @@ describe('rdbstoreInsertTest', function () {
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
resultSet.close();
console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(2).assertEqual(id);
expect("lisi").assertEqual(name)
......@@ -427,7 +432,7 @@ describe('rdbstoreInsertTest', function () {
"salary": 500,
"blobType": u8,
}
await rdbStore.insert("test3",valueBucket4)
await rdbStore.insert("test3", valueBucket4)
predicates = new dataRdb.RdbPredicates("test3");
predicates.equalTo("name", "zhangmaowen")
resultSet = await rdbStore.query(predicates)
......@@ -438,6 +443,7 @@ describe('rdbstoreInsertTest', function () {
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
resultSet.close();
console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(4).assertEqual(id);
expect("zhangmaowen").assertEqual(name)
......@@ -449,7 +455,6 @@ describe('rdbstoreInsertTest', function () {
} catch (e) {
console.info("BatchInsert1 error " + e);
}
resultSet = null
done();
console.info(TAG + "************* testRdbStorebatchInsertPromise0003 end *************");
})
......@@ -464,11 +469,11 @@ describe('rdbstoreInsertTest', function () {
await rdbStore.executeSql(CREATE_TABLE_NAME + "4" + CREATE_TABLE)
var u8 = new Uint8Array([1, 2, 3])
var valueBuckets = new Array(100);
for(var i=0;i<valueBuckets.length;i++){
for (var i = 0;i < valueBuckets.length; i++) {
valueBuckets[i] = {
"name": "zhangsan" + i,
"age": i,
"salary": 1+i,
"salary": 1 + i,
"blobType": u8,
};
}
......@@ -476,7 +481,7 @@ describe('rdbstoreInsertTest', function () {
await rdbStore.batchInsert("test4", valueBuckets).then((number) => {
console.info(TAG + "Batch insert data end")
expect(100).assertEqual(number)
}).catch((err) =>{
}).catch((err) => {
expect(false).assertTrue();
})
......@@ -537,7 +542,7 @@ describe('rdbstoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.batchInsert("test5", valueBuckets).then((number) => {
expect(3).assertEqual(number)
}).catch((err) =>{
}).catch((err) => {
expect(false).assertTrue();
})
......@@ -596,9 +601,9 @@ describe('rdbstoreInsertTest', function () {
"blobType": u8,
}
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
try{
await rdbStore.batchInsert("test6","valueBuckets")
}catch(err){
try {
await rdbStore.batchInsert("test6", "valueBuckets")
} catch (err) {
console.info(TAG + "Batch insert data error: " + err)
errInfo = err
}
......@@ -616,9 +621,9 @@ describe('rdbstoreInsertTest', function () {
console.info(TAG + "************* testRdbStorebatchInsertPromise0007 start *************");
let errInfo = undefined;
await rdbStore.executeSql(CREATE_TABLE_NAME + "7" + CREATE_TABLE)
try{
try {
await rdbStore.batchInsert("test7")
}catch(err){
} catch (err) {
console.info(TAG + "Batch insert data error: " + err)
errInfo = err
}
......@@ -659,9 +664,9 @@ describe('rdbstoreInsertTest', function () {
await rdbStore.executeSql(CREATE_TABLE_NAME + "callback1" + CREATE_TABLE).then(async () => {
console.info(TAG + "Batch insert data start")
await rdbStore.batchInsert("testcallback1", valueBuckets, async (err, data) => {
if(err != null){
if (err != null) {
expect(false).assertTrue();
}else{
} else {
console.info(TAG + "Batch insert data end")
expect(3).assertEqual(data)
let predicates = new dataRdb.RdbPredicates("testcallback1");
......@@ -746,9 +751,9 @@ describe('rdbstoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback2" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallback2", valueBuckets, async (err, data) => {
if(err != null){
if (err != null) {
expect(false).assertTrue();
}else{
} else {
expect(3).assertEqual(data)
let predicates = new dataRdb.RdbPredicates("testCallback2");
predicates.equalTo("name", "lisi")
......@@ -769,7 +774,7 @@ describe('rdbstoreInsertTest', function () {
await rdbStore.delete(predicates).then((number) => {
expect(1).assertEqual(number)
}).then(async () => {
resultSet = await rdbStore.query(predicates).catch((err) =>{
resultSet = await rdbStore.query(predicates).catch((err) => {
expect(err != null).assertTrue();
})
})
......@@ -813,11 +818,11 @@ describe('rdbstoreInsertTest', function () {
"blobType": u8,
}
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () =>{
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallback3", valueBuckets, async (err, data) => {
if(err != null){
if (err != null) {
expect(false).assertTrue()
}else{
} else {
expect(3).assertEqual(data)
let predicates = new dataRdb.RdbPredicates("testCallback3");
predicates.equalTo("name", "zhangsan")
......@@ -858,7 +863,7 @@ describe('rdbstoreInsertTest', function () {
"salary": 500,
"blobType": u8,
}
await rdbStore.insert("testCallback3",valueBucket4)
await rdbStore.insert("testCallback3", valueBucket4)
predicates = new dataRdb.RdbPredicates("testCallback3");
predicates.equalTo("name", "zhangmaowen")
resultSet = await rdbStore.query(predicates)
......@@ -899,20 +904,20 @@ describe('rdbstoreInsertTest', function () {
console.info(TAG + "************* testRdbStorebatchInsertCallback0004 start *************");
var u8 = new Uint8Array([1, 2, 3])
var valueBuckets = new Array(100);
for(var i=0;i<valueBuckets.length;i++){
for (var i = 0;i < valueBuckets.length; i++) {
valueBuckets[i] = {
"name": "zhangsan" + i,
"age": i,
"salary": 1+i,
"salary": 1 + i,
"blobType": u8,
};
}
console.info(TAG + "Batch insert data start")
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callbak4" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallbak4", valueBuckets, async (err, data) => {
if(err != null){
if (err != null) {
expect(false).assertTrue();
}else{
} else {
console.info(TAG + "Batch insert data end")
expect(100).assertEqual(data)
let predicates = new dataRdb.RdbPredicates("testCallbak4");
......@@ -972,9 +977,9 @@ describe('rdbstoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback5" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallback5", valueBuckets, async (err, number) => {
if(err != null){
if (err != null) {
expect(false).assertTrue();
}else{
} else {
expect(3).assertEqual(number)
let predicates = new dataRdb.RdbPredicates("testCallback5");
predicates.equalTo("name", "zhangsan")
......@@ -1036,16 +1041,16 @@ describe('rdbstoreInsertTest', function () {
}
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback6" + CREATE_TABLE).then(async () => {
try{
try {
rdbStore.batchInsert("testCallback6", "valueBuckets", (err, data) => {
console.info(TAG + "Affect row is " + data)
if(err != null){
if (err != null) {
expect(null).assertFail();
}else{
} else {
expect(data).assertEqual(-1)
}
})
}catch(err){
} catch (err) {
console.info(TAG + "Batch insert data error: " + err)
errInfo = err
}
......@@ -1065,16 +1070,16 @@ describe('rdbstoreInsertTest', function () {
console.info(TAG + "************* testRdbStorebatchInsertCallback0007 start *************");
let errInfo = undefined;
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback7" + CREATE_TABLE).then(async () => {
try{
await rdbStore.batchInsert("testCallback7", (err,data) => {
try {
await rdbStore.batchInsert("testCallback7", (err, data) => {
console.info(TAG + "Affect row is " + data)
if(err != null){
if (err != null) {
expect(null).assertFail();
}else{
} else {
expect(data).assertEqual(-1)
}
})
}catch(err){
} catch (err) {
errInfo = err
}
}).catch((err) => {
......@@ -1086,5 +1091,5 @@ describe('rdbstoreInsertTest', function () {
})
console.info(TAG + "*************Unit Test End*************");
})
})
}
......@@ -26,7 +26,7 @@ const STORE_CONFIG = {
var rdbStore = undefined;
export default function rdbstoreTransactionTest() {
describe('rdbstoreTransactionTest', function () {
describe('rdbstoreTransactionTest', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
})
......@@ -75,7 +75,7 @@ describe('rdbstoreTransactionTest', function () {
console.info(TAG + "testRdbTransactionInsert0001 result count " + resultSet.rowCount)
expect(1).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
} catch (e) {
console.info(TAG + e);
expect(null).assertFail()
......@@ -126,7 +126,7 @@ describe('rdbstoreTransactionTest', function () {
let resultSet = await rdbStore.query(predicates)
expect(3).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
} catch (e) {
expect(null).assertFail()
console.info(TAG + "testRdbTransactionInsert0002 failed");
......@@ -167,7 +167,7 @@ describe('rdbstoreTransactionTest', function () {
let resultSet = await rdbStore.query(predicates)
expect(0).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
const valueBucket2 = {
"name": "wangwu",
"age": 16,
......@@ -214,7 +214,7 @@ describe('rdbstoreTransactionTest', function () {
console.info(TAG + "testRdbTransactionRollBack0001 result count " + resultSet.rowCount);
expect(0).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
}
done()
console.info(TAG + "************* testRdbTransactionRollBack0001 end *************");
......@@ -247,8 +247,7 @@ describe('rdbstoreTransactionTest', function () {
"salary": 220.5,
"blobType": u8,
}
let num = rdbStore.insert("test", valueBucket1)
num.then(async (ret) => {
await rdbStore.insert("test", valueBucket1).then(async (ret) => {
console.info(TAG + "testRdbTransactionMulti0001 * insert result " + ret);
expect(2).assertEqual(ret)
})
......@@ -257,16 +256,15 @@ describe('rdbstoreTransactionTest', function () {
await rdbStore.commit()
let predicates = new dataRdb.RdbPredicates("test");
num = rdbStore.query(predicates)
num.then(async (ret) => {
await rdbStore.query(predicates).then(async (ret) => {
expect(2).assertEqual(ret.rowCount)
done()
console.info(TAG + "************* testRdbTransactionMulti0001 end *************");
ret.close()
})
} catch (e) {
console.info(TAG + "testRdbTransactionMulti0001 fail ***** ");
}
done()
console.info(TAG + "************* testRdbTransactionMulti0001 end *************");
})
/**
......@@ -287,9 +285,7 @@ describe('rdbstoreTransactionTest', function () {
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, function (err, ret){
});
await rdbStore.insert("test", valueBucket);
await rdbStore.beginTransaction()
const valueBucket1 = {
......@@ -298,29 +294,29 @@ describe('rdbstoreTransactionTest', function () {
"salary": 220.5,
"blobType": u8,
}
let num = rdbStore.insert("test", valueBucket1)
num.then(async (ret) => {
console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret);
expect(2).assertEqual(ret)
ret.close()
})
await rdbStore.insert("test", valueBucket1, async function (err, ret1){
console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret1);
expect(2).assertEqual(ret1)
await rdbStore.rollBack()
await rdbStore.commit()
let predicates = new dataRdb.RdbPredicates("test");
num = rdbStore.query(predicates)
num.then(async (ret) => {
console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret.rowCount);
expect(1).assertEqual(ret.rowCount)
ret.close()
await rdbStore.query(predicates).then(async (ret2) => {
console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret2.rowCount);
expect(1).assertEqual(ret2.rowCount)
done()
console.info(TAG + "************* testRdbTransactionMulti0002 end *************");
ret2.close()
})
})
} catch (e) {
console.info(TAG + "testRdbTransactionMulti0002 fail ***** ");
expect().assertFail();
done();
}
done()
console.info(TAG + "************* testRdbTransactionMulti0002 end *************");
})
/**
......@@ -341,37 +337,41 @@ describe('rdbstoreTransactionTest', function () {
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, function (err, ret){
await rdbStore.insert("test", valueBucket);
});
await rdbStore.beginTransaction()
const valueBucket1 = {
await rdbStore.beginTransaction();
const valueBucket2 = {
"name": "zhangsan",
"age": 20,
"salary": 220.5,
"blobType": u8,
}
let num = await rdbStore.insert("test", valueBucket1)
await rdbStore.insert("test", valueBucket2);
await rdbStore.rollBack()
await rdbStore.rollBack();
await rdbStore.insert("test", valueBucket)
await rdbStore.commit()
const valueBucket3 = {
"name": "wangwu",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket3);
await rdbStore.commit();
let predicates = new dataRdb.RdbPredicates("test");
num = rdbStore.query(predicates)
num.then(async (ret) => {
await rdbStore.query(predicates).then(async (ret) => {
console.info(TAG + "testRdbTransactionMulti0003 * final query " + ret.rowCount);
expect(1).assertEqual(ret.rowCount)
ret.close()
expect(2).assertEqual(ret.rowCount);
done();
console.info(TAG + "************* testRdbTransactionMulti0003 end *************");
ret.close();
})
} catch (e) {
await rdbStore.rollBack()
console.info(TAG + "testRdbTransactionMulti0003 rollback ***** ");
}
done()
console.info(TAG + "************* testRdbTransactionMulti0003 end *************");
})
/**
......@@ -405,7 +405,7 @@ describe('rdbstoreTransactionTest', function () {
let resultSet = await rdbStore.query(predicates)
expect(0).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
const valueBucket2 = {
"name": "wangwu",
"age": 16,
......@@ -422,18 +422,18 @@ describe('rdbstoreTransactionTest', function () {
//删除
{
let predicates = await new dataRdb.RdbPredicates("test")
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
expect(3).assertEqual(ret)
await rdbStore.delete(predicates).then(async (ret) => {
expect(3).assertEqual(ret);
done()
console.info(TAG + "************* testRdbTransactionDelete0001 end *************");
console.info(TAG + "Delete done: " + ret)
}).catch((err) => {
expect(null).assertFail()
expect(null).assertFail();
done();
})
await deletePromise
}
done()
console.info(TAG + "************* testRdbTransactionDelete0001 end *************");
})
console.info(TAG + "*************Unit Test End*************");
})}
})}
......@@ -23,7 +23,7 @@ const STORE_CONFIG = {
var rdbStore = undefined;
export default function rdbStoreUpdateTest() {
describe('rdbStoreUpdateTest', function () {
describe('rdbStoreUpdateTest', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
})
......@@ -234,27 +234,25 @@ describe('rdbStoreUpdateTest', function () {
{
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("aaa", "null")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await rdbStore.update(valueBucket, predicates).then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
expect(err !== null).assertTrue();
})
//await updatePromise
}
{
const emptyBucket = {};
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("name", "zhangsan")
await predicates.equalTo("age", 18)
await predicates.equalTo("null", 100.5)
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await rdbStore.update(valueBucket, predicates).then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
expect(ret).assertEqual(0);
}).catch((err) => {
console.info(TAG + "update with wrong condition");
expect(null).assertFail();
})
}
}
......@@ -262,6 +260,6 @@ describe('rdbStoreUpdateTest', function () {
console.info(TAG + "************* testRdbStoreUpdate0004 end *************");
})
console.info(TAG + "*************Unit Test End*************");
})
})
}
......@@ -501,7 +501,7 @@ export default function relationalStoreAssetResultSetTest() {
done();
} catch (e) {
console.log(TAG + "testGetAssetUndefined get error" + JSON.stringify(e));
expect(14800000).assertEqual(e.code)
expect('401').assertEqual(e.code)
done();
}
})
......@@ -531,7 +531,7 @@ export default function relationalStoreAssetResultSetTest() {
done();
} catch (e) {
console.log(TAG + "testGetAssetNull get error" + JSON.stringify(e));
expect(14800000).assertEqual(e.code)
expect('401').assertEqual(e.code)
done();
}
})
......
......@@ -13,9 +13,10 @@
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility'
var context = ability_featureAbility.getContext();
const TAG = "[RelationalStore_JSKITS_TEST]"
......@@ -27,36 +28,32 @@ const STORE_CONFIG = {
securityLevel: data_Rdb.SecurityLevel.S1
}
var rdbStore = undefined;
var resultSet = undefined;
let rdbStore = undefined;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default function relationalStoreInsertTest() {
describe('relationalStoreInsertTest', function () {
describe('relationalStoreInsertTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG);
await rdbStore.executeSql(CREATE_TABLE_TEST, null)
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
await rdbStore.executeSql("DELETE FROM test");
rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG);
await rdbStore.executeSql(CREATE_TABLE_TEST, null)
})
afterEach(async function () {
console.info(TAG + 'afterEach')
rdbStore = null
await data_Rdb.deleteRdbStore(context, "InsertTest.db")
})
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await data_Rdb.deleteRdbStore(context, "InsertTest.db").then(() => {
sleep(2)
});
})
console.info(TAG + "*************Unit Test Begin*************");
......@@ -99,8 +96,7 @@ describe('relationalStoreInsertTest', function () {
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
await rdbStore.query(predicates).then(async (resultSet) => {
console.info(TAG + "resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
......@@ -117,12 +113,15 @@ describe('relationalStoreInsertTest', function () {
expect(2).assertEqual(blobType[1])
expect(3).assertEqual(blobType[2])
expect(false).assertEqual(resultSet.goToNextRow())
} catch (e) {
console.info("insert1 error " + e);
}
resultSet.close();
done()
done();
console.info(TAG + "************* testRdbStoreInsert0001 end *************");
resultSet.close();
resultSet = null;
}).catch((err) => {
console.info("insert1 error " + err);
expect().assertFail();
done();
})
})
/**
......@@ -132,7 +131,7 @@ describe('relationalStoreInsertTest', function () {
*/
it('testRdbStoreInsert0002', 0, async function (done) {
console.info(TAG + "************* testRdbStoreInsert0002 start *************");
var u8 = new Uint8Array([1, 2, 3])
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
......@@ -140,17 +139,17 @@ describe('relationalStoreInsertTest', function () {
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("wrong", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
await rdbStore.insert("wrong", valueBucket).then(async (ret) => {
console.info(TAG + "insert first done: " + ret)
expect(null).assertFail()
expect().assertFail();
done();
}).catch((err) => {
console.info(TAG + "insert with wrong table")
expect(err !== null).assertTrue();
done();
console.info(TAG + "************* testRdbStoreInsert0002 end *************");
})
}
done()
console.info(TAG + "************* testRdbStoreInsert0002 end *************");
})
/**
......@@ -160,8 +159,7 @@ describe('relationalStoreInsertTest', function () {
*/
it('testRdbStoreInsert0003', 0, async function (done) {
console.info(TAG + "************* testRdbStoreInsert0003 start *************");
let errInfo = undefined;
var u8 = new Uint8Array([1, 2, 3])
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
......@@ -169,15 +167,23 @@ describe('relationalStoreInsertTest', function () {
"salary": 100.5,
"blobType": u8,
}
try{
rdbStore.insert(null, valueBucket)
}catch(err){
errInfo = err
try {
await rdbStore.insert(null, valueBucket).then(()=>{
console.log("insert done");
expect().assertFail();
done();
}).catch((error) => {
console.log("insert error" + error);
expect().assertFail();
done();
})
} catch (err) {
console.log(`insert failed, code is ${err.code},message is ${err.message}`);
expect(err.code).assertEqual('401');
done();
console.info(TAG + "************* testRdbStoreInsert0003 end *************");
}
expect(errInfo.code).assertEqual("401")
}
done()
console.info(TAG + "************* testRdbStoreInsert0003 end *************");
})
/**
......@@ -187,23 +193,23 @@ describe('relationalStoreInsertTest', function () {
*/
it('testRdbStoreInsert0004', 0, async function (done) {
console.log(TAG + "************* testRdbStoreInsert0004 start *************");
var u8 = new Uint8Array([1, 2, 3])
let u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": null,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.log(TAG + "insert first done: " + ret)
}).catch((err) => {
console.log(TAG + "insert with null table")
expect(null).assertFail()
})
await rdbStore.insert("test", valueBucket).then(async (ret) => {
expect(1).assertEqual(ret);
console.log(TAG + "insert first done: " + ret);
done();
console.log(TAG + "************* testRdbStoreInsert0004 end *************");
}).catch((err) => {
console.log(TAG + "insert with null table" + err);
expect().assertFail();
done();
})
})
/**
......@@ -214,7 +220,7 @@ describe('relationalStoreInsertTest', function () {
it('testRdbStorebatchInsertPromise0001', 0, async function (done) {
console.info(TAG + "************* testRdbStorebatchInsertPromise0001 start *************");
await rdbStore.executeSql(CREATE_TABLE_NAME + "1" + CREATE_TABLE)
var u8 = new Uint8Array([1, 2, 3])
let u8 = new Uint8Array([1, 2, 3])
const valueBucket1 = {
"name": "zhangsan",
"age": 18,
......@@ -235,15 +241,16 @@ describe('relationalStoreInsertTest', function () {
}
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.batchInsert("test1", valueBuckets).then((number) => {
expect(3).assertEqual(number)
}).catch((err) =>{
expect(false).assertTrue();
console.info(TAG + "batchInsert number = " + number);
expect(3).assertEqual(number);
}).catch((err) => {
console.info(TAG + "batchInsert fail = " + err);
expect().assertFail();
})
let predicates = new data_Rdb.RdbPredicates("test1");
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
await rdbStore.query(predicates).then((resultSet) => {
console.info(TAG + "resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
......@@ -260,33 +267,15 @@ describe('relationalStoreInsertTest', function () {
expect(2).assertEqual(blobType[1])
expect(3).assertEqual(blobType[2])
expect(false).assertEqual(resultSet.goToNextRow())
} catch (e) {
console.info("BatchInsert1 error " + e);
}
resultSet.close();
predicates = new data_Rdb.RdbPredicates("test1");
predicates.equalTo("name", "lisi")
resultSet = await rdbStore.query(predicates)
try {
console.info(TAG + "resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(2).assertEqual(id);
expect("lisi").assertEqual(name)
expect(23).assertEqual(age)
expect(200).assertEqual(salary)
expect(false).assertEqual(resultSet.goToNextRow())
} catch (e) {
console.info("BatchInsert1 error " + e);
}
resultSet.close();
done()
done();
console.info(TAG + "************* testRdbStorebatchInsertPromise0001 end *************");
resultSet.close();
resultSet = null;
}).catch((err) => {
console.error(`Updated failed, err is ${err}`);
expect().assertFail();
done();
})
})
/**
......@@ -319,7 +308,7 @@ describe('relationalStoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.batchInsert("test2", valueBuckets).then((number) => {
expect(3).assertEqual(number)
}).catch((err) =>{
}).catch((err) => {
expect(false).assertTrue();
})
let predicates = new data_Rdb.RdbPredicates("test2");
......@@ -342,7 +331,7 @@ describe('relationalStoreInsertTest', function () {
await rdbStore.delete(predicates).then((number) => {
expect(1).assertEqual(number)
}).then(async () => {
resultSet = await rdbStore.query(predicates).catch((err) =>{
resultSet = await rdbStore.query(predicates).catch((err) => {
expect(err != null).assertTrue();
})
resultSet.close();
......@@ -384,7 +373,7 @@ describe('relationalStoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.batchInsert("test3", valueBuckets).then((number) => {
expect(3).assertEqual(number)
}).catch((err) =>{
}).catch((err) => {
expect(false).assertTrue();
})
......@@ -434,7 +423,7 @@ describe('relationalStoreInsertTest', function () {
"salary": 500,
"blobType": u8,
}
await rdbStore.insert("test3",valueBucket4)
await rdbStore.insert("test3", valueBucket4)
predicates = new data_Rdb.RdbPredicates("test3");
predicates.equalTo("name", "zhangmaowen")
resultSet = await rdbStore.query(predicates)
......@@ -471,11 +460,11 @@ describe('relationalStoreInsertTest', function () {
await rdbStore.executeSql(CREATE_TABLE_NAME + "4" + CREATE_TABLE)
var u8 = new Uint8Array([1, 2, 3])
var valueBuckets = new Array(100);
for(var i=0;i<valueBuckets.length;i++){
for (var i = 0;i < valueBuckets.length; i++) {
valueBuckets[i] = {
"name": "zhangsan" + i,
"age": i,
"salary": 1+i,
"salary": 1 + i,
"blobType": u8,
};
}
......@@ -483,7 +472,7 @@ describe('relationalStoreInsertTest', function () {
await rdbStore.batchInsert("test4", valueBuckets).then((number) => {
console.info(TAG + "Batch insert data end")
expect(100).assertEqual(number)
}).catch((err) =>{
}).catch((err) => {
expect(false).assertTrue();
})
......@@ -544,7 +533,7 @@ describe('relationalStoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.batchInsert("test5", valueBuckets).then((number) => {
expect(3).assertEqual(number)
}).catch((err) =>{
}).catch((err) => {
expect(false).assertTrue();
})
......@@ -603,9 +592,9 @@ describe('relationalStoreInsertTest', function () {
"blobType": u8,
}
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
try{
await rdbStore.batchInsert("test6","valueBuckets")
}catch(err){
try {
await rdbStore.batchInsert("test6", "valueBuckets")
} catch (err) {
console.info(TAG + "Batch insert data error: " + err)
errInfo = err
}
......@@ -623,9 +612,9 @@ describe('relationalStoreInsertTest', function () {
console.info(TAG + "************* testRdbStorebatchInsertPromise0007 start *************");
let errInfo = undefined;
await rdbStore.executeSql(CREATE_TABLE_NAME + "7" + CREATE_TABLE)
try{
try {
await rdbStore.batchInsert("test7")
}catch(err){
} catch (err) {
console.info(TAG + "Batch insert data error: " + err)
errInfo = err
}
......@@ -666,9 +655,9 @@ describe('relationalStoreInsertTest', function () {
await rdbStore.executeSql(CREATE_TABLE_NAME + "callback1" + CREATE_TABLE).then(async () => {
console.info(TAG + "Batch insert data start")
await rdbStore.batchInsert("testcallback1", valueBuckets, async (err, data) => {
if(err != null){
if (err != null) {
expect(false).assertTrue();
}else{
} else {
console.info(TAG + "Batch insert data end")
expect(3).assertEqual(data)
let predicates = new data_Rdb.RdbPredicates("testcallback1");
......@@ -754,9 +743,9 @@ describe('relationalStoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback2" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallback2", valueBuckets, async (err, data) => {
if(err != null){
if (err != null) {
expect(false).assertTrue();
}else{
} else {
expect(3).assertEqual(data)
let predicates = new data_Rdb.RdbPredicates("testCallback2");
predicates.equalTo("name", "lisi")
......@@ -778,7 +767,7 @@ describe('relationalStoreInsertTest', function () {
await rdbStore.delete(predicates).then((number) => {
expect(1).assertEqual(number)
}).then(async () => {
resultSet = await rdbStore.query(predicates).catch((err) =>{
resultSet = await rdbStore.query(predicates).catch((err) => {
expect(err != null).assertTrue();
})
resultSet.close();
......@@ -822,11 +811,11 @@ describe('relationalStoreInsertTest', function () {
"blobType": u8,
}
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () =>{
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallback3", valueBuckets, async (err, data) => {
if(err != null){
if (err != null) {
expect(false).assertTrue()
}else{
} else {
expect(3).assertEqual(data)
let predicates = new data_Rdb.RdbPredicates("testCallback3");
predicates.equalTo("name", "zhangsan")
......@@ -869,7 +858,7 @@ describe('relationalStoreInsertTest', function () {
"salary": 500,
"blobType": u8,
}
await rdbStore.insert("testCallback3",valueBucket4)
await rdbStore.insert("testCallback3", valueBucket4)
predicates = new data_Rdb.RdbPredicates("testCallback3");
predicates.equalTo("name", "zhangmaowen")
resultSet = await rdbStore.query(predicates)
......@@ -910,20 +899,20 @@ describe('relationalStoreInsertTest', function () {
console.info(TAG + "************* testRdbStorebatchInsertCallback0004 start *************");
var u8 = new Uint8Array([1, 2, 3])
var valueBuckets = new Array(100);
for(var i=0;i<valueBuckets.length;i++){
for (var i = 0;i < valueBuckets.length; i++) {
valueBuckets[i] = {
"name": "zhangsan" + i,
"age": i,
"salary": 1+i,
"salary": 1 + i,
"blobType": u8,
};
}
console.info(TAG + "Batch insert data start")
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callbak4" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallbak4", valueBuckets, async (err, data) => {
if(err != null){
if (err != null) {
expect(false).assertTrue();
}else{
} else {
console.info(TAG + "Batch insert data end")
expect(100).assertEqual(data)
let predicates = new data_Rdb.RdbPredicates("testCallbak4");
......@@ -983,9 +972,9 @@ describe('relationalStoreInsertTest', function () {
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback5" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallback5", valueBuckets, async (err, number) => {
if(err != null){
if (err != null) {
expect(false).assertTrue();
}else{
} else {
expect(3).assertEqual(number)
let predicates = new data_Rdb.RdbPredicates("testCallback5");
predicates.equalTo("name", "zhangsan")
......@@ -1047,16 +1036,16 @@ describe('relationalStoreInsertTest', function () {
}
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback6" + CREATE_TABLE).then(async () => {
try{
try {
rdbStore.batchInsert("testCallback6", "valueBuckets", (err, data) => {
console.info(TAG + "Affect row is " + data)
if(err != null){
if (err != null) {
expect(null).assertFail();
}else{
} else {
expect(data).assertEqual(-1)
}
})
}catch(err){
} catch (err) {
console.info(TAG + "Batch insert data error: " + err)
errInfo = err
}
......@@ -1076,16 +1065,16 @@ describe('relationalStoreInsertTest', function () {
console.info(TAG + "************* testRdbStorebatchInsertCallback0007 start *************");
let errInfo = undefined;
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback7" + CREATE_TABLE).then(async () => {
try{
await rdbStore.batchInsert("testCallback7", (err,data) => {
try {
await rdbStore.batchInsert("testCallback7", (err, data) => {
console.info(TAG + "Affect row is " + data)
if(err != null){
if (err != null) {
expect(null).assertFail();
}else{
} else {
expect(data).assertEqual(-1)
}
})
}catch(err){
} catch (err) {
errInfo = err
}
}).catch((err) => {
......@@ -1133,7 +1122,7 @@ describe('relationalStoreInsertTest', function () {
console.log(TAG + " InsertWithConflictResolution0001 insert with wrong valuebucket and ConflictResolution is default")
done();
})
} catch(err) {
} catch (err) {
console.log(TAG + " InsertWithConflictResolution0001 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code);
expect(null).assertFail();
......@@ -1180,7 +1169,7 @@ describe('relationalStoreInsertTest', function () {
console.log(TAG + " InsertWithConflictResolution0002 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_ROLLBACK")
done()
})
} catch(err) {
} catch (err) {
console.log(TAG + " InsertWithConflictResolution0002 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code)
expect(null).assertFail()
......@@ -1227,7 +1216,7 @@ describe('relationalStoreInsertTest', function () {
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
console.log(TAG + " InsertWithConflictResolution0004 id=" + id + ", salary=" + salary );
console.log(TAG + " InsertWithConflictResolution0004 id=" + id + ", salary=" + salary);
expect(1).assertEqual(id);
expect(100.5).assertEqual(salary)
expect(false).assertEqual(resultSet.goToNextRow())
......@@ -1327,7 +1316,7 @@ describe('relationalStoreInsertTest', function () {
try {
rdbStore.insert("test", valueBucket, 6);
expect(null).assertFail()
} catch(err) {
} catch (err) {
console.log(TAG + " InsertWithConflictResolution0005 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code)
done()
......@@ -1374,7 +1363,7 @@ describe('relationalStoreInsertTest', function () {
console.log(TAG + " InsertWithConflictResolution0006 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_ABORT")
done()
})
} catch(err) {
} catch (err) {
console.log(TAG + " InsertWithConflictResolution0006 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code)
expect(null).assertFail()
......@@ -1392,20 +1381,17 @@ describe('relationalStoreInsertTest', function () {
*/
it('InsertWithConflictResolution0007', 0, async function (done) {
console.log(TAG + " ************* InsertWithConflictResolution0007 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
let u8 = new Uint8Array([1, 2, 3])
const valueBucket1 = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL);
}
await rdbStore.insert("test", valueBucket1, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL);
{
const valueBucket = {
const valueBucket2 = {
"id": 1,
"name": "zhangsan",
"age": 18,
......@@ -1413,26 +1399,120 @@ describe('relationalStoreInsertTest', function () {
"blobType": u8,
}
try {
let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL);
let insertPromise = rdbStore.insert("test", valueBucket2, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL);
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
// expect(1).assertEqual(ret)
console.log(TAG + " InsertWithConflictResolution0007 insert first done: " + ret)
expect(null).assertFail()
}).catch((err) => {
console.log(TAG + " InsertWithConflictResolution0007 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_FAIL")
expect().assertFail();
done()
}).catch((err) => {
console.error(`insert failed, code is ${err.code},message is ${err.message}`);
expect(err !== null).assertTrue();
done();
})
} catch(err) {
console.log(TAG + " InsertWithConflictResolution0007 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code)
expect(null).assertFail()
} catch (err) {
console.log(TAG + " catch err: failed, err: code=" + err.code + " message=" + err.message)
expect().assertFail();
done();
}
console.log(TAG + " ************* InsertWithConflictResolution0007 end *************");
})
/**
* @tc.name rdb insert test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0100
* @tc.desc rdb insert test
*/
it('SUB_DDM_AppDataFWK_JSRDB_Insert_0100', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0100 start *************");
var u8 = new Uint8Array([1, 2, 3])
const valueBucket1 = {
"id": 1,
"name": "zhangsan",
"age": null,
"salary": undefined,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket1);
const valueBucket2 = {
"id": 2,
"name": "lisi",
"age": 19,
"salary": 200.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket2);
console.log(TAG + " ************* InsertWithConflictResolution0007 end *************");
let predicates = new data_Rdb.RdbPredicates("test");
await rdbStore.query(predicates).then((resultSet) => {
expect(true).assertEqual(resultSet.goToFirstRow());
expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("age")));
expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("salary")));
resultSet.close();
resultSet = null;
}).catch((err) => {
console.log("query1 error" + err);
expect().assertFail()
})
const valueBucket3 = {
"age": null,
"salary": undefined,
}
predicates.equalTo("name", "lisi");
await rdbStore.update(valueBucket3, predicates);
predicates.clear();
await rdbStore.query(predicates).then((resultSet) => {
expect(true).assertEqual(resultSet.goToFirstRow());
expect(true).assertEqual(resultSet.goToNextRow());
expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("age")));
expect(200.5).assertEqual(resultSet.getDouble(resultSet.getColumnIndex("salary")));
done();
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0100 end *************");
resultSet.close();
resultSet = null;
}).catch((err) => {
console.log("query2 error" + err);
expect().assertFail();
done();
})
})
/**
* @tc.name rdb insert test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0200
* @tc.desc rdb insert test
*/
it('SUB_DDM_AppDataFWK_JSRDB_Insert_0200', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0200 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": new Date(),
"salary": 100.5,
"blobType": u8,
}
try {
await rdbStore.insert("test", valueBucket).then(async (ret) => {
done();
expect().assertFail()
}).catch((err) => {
done();
expect().assertFail()
})
} catch (err) {
done();
console.log("catch err: failed, err: code=" + err.code + " message=" + err.message + typeof (err.code))
expect(err.code).assertEqual('401');
}
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0200 end *************");
})
console.info(TAG + " *************Unit Test End*************");
})
})
}
......@@ -29,7 +29,7 @@ const STORE_CONFIG = {
var rdbStore = undefined;
export default function relationalStoreTransactionTest() {
describe('relationalStoreTransactionTest', function () {
describe('relationalStoreTransactionTest', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
})
......@@ -78,7 +78,7 @@ describe('relationalStoreTransactionTest', function () {
console.info(TAG + "testRdbTransactionInsert0001 result count " + resultSet.rowCount)
expect(1).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
} catch (e) {
console.info(TAG + e);
expect(null).assertFail()
......@@ -129,7 +129,7 @@ describe('relationalStoreTransactionTest', function () {
let resultSet = await rdbStore.query(predicates)
expect(3).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
} catch (e) {
expect(null).assertFail()
console.info(TAG + "testRdbTransactionInsert0002 failed");
......@@ -170,7 +170,7 @@ describe('relationalStoreTransactionTest', function () {
let resultSet = await rdbStore.query(predicates)
expect(0).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
const valueBucket2 = {
"name": "wangwu",
"age": 16,
......@@ -217,7 +217,7 @@ describe('relationalStoreTransactionTest', function () {
console.info(TAG + "testRdbTransactionRollBack0001 result count " + resultSet.rowCount);
expect(0).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
}
done()
console.info(TAG + "************* testRdbTransactionRollBack0001 end *************");
......@@ -230,7 +230,7 @@ describe('relationalStoreTransactionTest', function () {
* db returns an exception, we need to catch exception and rollback.
*/
it('testRdbTransactionMulti0001', 0, async function (done) {
console.info(TAG + "************* testRdbTransactionMulti0001 start *************");
console.info('ttt' + "************* testRdbTransactionMulti0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
try {
await rdbStore.beginTransaction()
......@@ -251,25 +251,25 @@ describe('relationalStoreTransactionTest', function () {
"blobType": u8,
}
let num = rdbStore.insert("test", valueBucket1)
num.then(async (ret) => {
console.info(TAG + "testRdbTransactionMulti0001 * insert result " + ret);
expect(2).assertEqual(ret)
num.then(async (ret1) => {
console.info('ttt' + "testRdbTransactionMulti0001 * insert result " + ret1);
expect(2).assertEqual(ret1)
})
await rdbStore.commit()
await rdbStore.commit()
let predicates = new data_Rdb.RdbPredicates("test");
num = rdbStore.query(predicates)
num.then(async (ret) => {
expect(2).assertEqual(ret.rowCount)
ret.close()
await rdbStore.query(predicates).then(async (ret2) => {
console.info('ttt' + "testRdbTransactionMulti0001 ret.rowCount = " + ret2.rowCount);
expect(2).assertEqual(ret2.rowCount)
done()
console.info('ttt' + "************* testRdbTransactionMulti0001 end *************");
ret2.close()
})
} catch (e) {
console.info(TAG + "testRdbTransactionMulti0001 fail ***** ");
console.info('ttt' + "testRdbTransactionMulti0001 fail ***** ");
}
done()
console.info(TAG + "************* testRdbTransactionMulti0001 end *************");
})
/**
......@@ -280,7 +280,7 @@ describe('relationalStoreTransactionTest', function () {
*/
it('testRdbTransactionMulti0002', 0, async function (done) {
console.info(TAG + "************* testRdbTransactionMulti0002 start *************");
var u8 = new Uint8Array([1, 2, 3])
let u8 = new Uint8Array([1, 2, 3])
try {
await rdbStore.beginTransaction()
const valueBucket = {
......@@ -290,9 +290,7 @@ describe('relationalStoreTransactionTest', function () {
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, function (err, ret){
});
await rdbStore.insert("test", valueBucket)
await rdbStore.beginTransaction()
const valueBucket1 = {
......@@ -301,31 +299,30 @@ describe('relationalStoreTransactionTest', function () {
"salary": 220.5,
"blobType": u8,
}
let num = rdbStore.insert("test", valueBucket1)
num.then(async (ret) => {
console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret);
expect(2).assertEqual(ret)
ret.close()
})
await rdbStore.insert("test", valueBucket1, async function (err, ret1){
console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret1);
expect(2).assertEqual(ret1);
await rdbStore.rollBack()
await rdbStore.commit()
let predicates = new data_Rdb.RdbPredicates("test");
num = rdbStore.query(predicates)
num.then(async (ret) => {
console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret.rowCount);
expect(1).assertEqual(ret.rowCount)
ret.close()
await rdbStore.query(predicates).then(async (ret2) => {
console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret2.rowCount);
expect(1).assertEqual(ret2.rowCount)
done()
console.info(TAG + "************* testRdbTransactionMulti0002 end *************");
ret2.close()
})
})
} catch (e) {
console.info(TAG + "testRdbTransactionMulti0002 fail ***** ");
expect().assertFail();
done();
}
done()
console.info(TAG + "************* testRdbTransactionMulti0002 end *************");
})
/**
* @tc.name RelationalStore insert test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0003
......@@ -344,37 +341,41 @@ describe('relationalStoreTransactionTest', function () {
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, function (err, ret){
await rdbStore.insert("test", valueBucket);
});
await rdbStore.beginTransaction()
const valueBucket1 = {
await rdbStore.beginTransaction();
const valueBucket2 = {
"name": "zhangsan",
"age": 20,
"salary": 220.5,
"blobType": u8,
}
let num = await rdbStore.insert("test", valueBucket1)
await rdbStore.insert("test", valueBucket2);
await rdbStore.rollBack()
await rdbStore.rollBack();
await rdbStore.insert("test", valueBucket)
await rdbStore.commit()
const valueBucket3 = {
"name": "wangwu",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket3);
await rdbStore.commit();
let predicates = new data_Rdb.RdbPredicates("test");
num = rdbStore.query(predicates)
num.then(async (ret) => {
await rdbStore.query(predicates).then(async (ret) => {
console.info(TAG + "testRdbTransactionMulti0003 * final query " + ret.rowCount);
expect(1).assertEqual(ret.rowCount)
ret.close()
expect(2).assertEqual(ret.rowCount);
done();
console.info(TAG + "************* testRdbTransactionMulti0003 end *************");
ret.close();
})
} catch (e) {
await rdbStore.rollBack()
console.info(TAG + "testRdbTransactionMulti0003 rollback ***** ");
}
done()
console.info(TAG + "************* testRdbTransactionMulti0003 end *************");
})
/**
......@@ -408,7 +409,7 @@ describe('relationalStoreTransactionTest', function () {
let resultSet = await rdbStore.query(predicates)
expect(0).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
// resultSet == null;
const valueBucket2 = {
"name": "wangwu",
"age": 16,
......@@ -425,18 +426,18 @@ describe('relationalStoreTransactionTest', function () {
//删除
{
let predicates = await new data_Rdb.RdbPredicates("test")
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
expect(3).assertEqual(ret)
await rdbStore.delete(predicates).then(async (ret) => {
expect(3).assertEqual(ret);
done()
console.info(TAG + "************* testRdbTransactionDelete0001 end *************");
console.info(TAG + "Delete done: " + ret)
}).catch((err) => {
expect(null).assertFail()
expect(null).assertFail();
done();
})
await deletePromise
}
done()
console.info(TAG + "************* testRdbTransactionDelete0001 end *************");
})
console.info(TAG + "*************Unit Test End*************");
})}
})}
......@@ -237,32 +237,29 @@ export default function relationalStoreUpdateTest() {
{
let predicates = await new data_Rdb.RdbPredicates("test")
await predicates.equalTo("aaa", "null")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await rdbStore.update(valueBucket, predicates).then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
expect(err !== null).assertTrue();
console.info(TAG + "update with wrong condition");
})
//await updatePromise
}
{
const emptyBucket = {};
let predicates = await new data_Rdb.RdbPredicates("test")
await predicates.equalTo("name", "zhangsan")
await predicates.equalTo("age", 18)
await predicates.equalTo("null", 100.5)
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await rdbStore.update(valueBucket, predicates).then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
expect(ret).assertEqual(0);
done();
console.info(TAG + "************* testRdbStoreUpdate0004 end *************");
}).catch((err) => {
console.info(TAG + "update with wrong condition");
})
}
}
done();
console.info(TAG + "************* testRdbStoreUpdate0004 end *************");
})
/**
......@@ -401,21 +398,18 @@ export default function relationalStoreUpdateTest() {
}
let predicates = await new data_Rdb.RdbPredicates("test")
await predicates.equalTo("age", "19")
let updatePromise = rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_NONE);
updatePromise.then(async (ret) => {
await console.log(TAG + "testRdbStoreUpdateWithConflictResolution0002 done: " + ret);
expect(null).assertFail();
await rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_NONE).then(async (ret) => {
console.log(TAG + "testRdbStoreUpdateWithConflictResolution0002 done: " + ret);
expect().assertFail();
}).catch((err) => {
console.log(TAG + "testRdbStoreUpdateWithConflictResolution0002 error");
expect(null).assertFail();
console.log(TAG + "testRdbStoreUpdateWithConflictResolution0002 error" + err);
expect(err !== null).assertTrue();
})
done()
}
{
let predicates = await new data_Rdb.RdbPredicates("test")
let resultSet = await rdbStore.query(predicates)
await rdbStore.query(predicates).then(async (resultSet)=>{
expect(true).assertEqual(resultSet.goToFirstRow())
const id = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name = await resultSet.getString(resultSet.getColumnIndex("name"))
......@@ -423,37 +417,39 @@ export default function relationalStoreUpdateTest() {
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
await expect(1).assertEqual(id);
await expect("zhangsan").assertEqual(name);
await expect(18).assertEqual(age);
await expect(100.5).assertEqual(salary);
await expect(1).assertEqual(blobType[0]);
await expect(2).assertEqual(blobType[1]);
await expect(3).assertEqual(blobType[2]);
expect(1).assertEqual(id);
expect("zhangsan").assertEqual(name);
expect(18).assertEqual(age);
expect(100.5).assertEqual(salary);
expect(1).assertEqual(blobType[0]);
expect(2).assertEqual(blobType[1]);
expect(3).assertEqual(blobType[2]);
console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary="
+ salary + ", blobType=" + blobType);
await expect(true).assertEqual(resultSet.goToNextRow())
expect(true).assertEqual(resultSet.goToNextRow())
const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name_1 = await resultSet.getString(resultSet.getColumnIndex("name"))
const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
await expect(2).assertEqual(id_1);
await expect("lisi").assertEqual(name_1);
await expect(19).assertEqual(age_1);
await expect(200.5).assertEqual(salary_1);
await expect(4).assertEqual(blobType_1[0]);
await expect(5).assertEqual(blobType_1[1]);
await expect(6).assertEqual(blobType_1[2]);
expect(2).assertEqual(id_1);
expect("lisi").assertEqual(name_1);
expect(19).assertEqual(age_1);
expect(200.5).assertEqual(salary_1);
expect(4).assertEqual(blobType_1[0]);
expect(5).assertEqual(blobType_1[1]);
expect(6).assertEqual(blobType_1[2]);
console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary="
+ salary_1 + ", blobType=" + blobType_1);
await expect(false).assertEqual(resultSet.goToNextRow())
expect(false).assertEqual(resultSet.goToNextRow())
resultSet.close()
resultSet.close();
resultSet = null;
done()
console.log(TAG + "************* testRdbStoreUpdateWithConflictResolution0002 end *************");
})
}
})
......@@ -497,10 +493,9 @@ export default function relationalStoreUpdateTest() {
}
let predicates = await new data_Rdb.RdbPredicates("test")
await predicates.equalTo("age", "19")
let updatePromise = rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK);
updatePromise.then(async (ret) => {
await expect(1).assertEqual(ret);
await console.log(TAG + "testRdbStoreUpdateWithConflictResolution0003 done: " + ret);
await rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK).then(async (ret) => {
expect(1).assertEqual(ret);
console.log(TAG + "testRdbStoreUpdateWithConflictResolution0003 done: " + ret);
{
let predicates = await new data_Rdb.RdbPredicates("test")
let resultSet = await rdbStore.query(predicates)
......@@ -512,33 +507,33 @@ export default function relationalStoreUpdateTest() {
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
await expect(1).assertEqual(id);
await expect("zhangsan").assertEqual(name);
await expect(18).assertEqual(age);
await expect(100.5).assertEqual(salary);
await expect(1).assertEqual(blobType[0]);
await expect(2).assertEqual(blobType[1]);
await expect(3).assertEqual(blobType[2]);
expect(1).assertEqual(id);
expect("zhangsan").assertEqual(name);
expect(18).assertEqual(age);
expect(100.5).assertEqual(salary);
expect(1).assertEqual(blobType[0]);
expect(2).assertEqual(blobType[1]);
expect(3).assertEqual(blobType[2]);
console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary="
+ salary + ", blobType=" + blobType);
await expect(true).assertEqual(resultSet.goToNextRow())
expect(true).assertEqual(resultSet.goToNextRow())
const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name_1 = await resultSet.getString(resultSet.getColumnIndex("name"))
const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
await expect(3).assertEqual(id_1);
await expect("wangjing").assertEqual(name_1);
await expect(20).assertEqual(age_1);
await expect(300.5).assertEqual(salary_1);
await expect(7).assertEqual(blobType_1[0]);
await expect(8).assertEqual(blobType_1[1]);
await expect(9).assertEqual(blobType_1[2]);
expect(3).assertEqual(id_1);
expect("wangjing").assertEqual(name_1);
expect(20).assertEqual(age_1);
expect(300.5).assertEqual(salary_1);
expect(7).assertEqual(blobType_1[0]);
expect(8).assertEqual(blobType_1[1]);
expect(9).assertEqual(blobType_1[2]);
console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary="
+ salary_1 + ", blobType=" + blobType_1);
await expect(false).assertEqual(resultSet.goToNextRow())
expect(false).assertEqual(resultSet.goToNextRow())
resultSet.close()
done();
......@@ -593,21 +588,19 @@ export default function relationalStoreUpdateTest() {
}
let predicates = await new data_Rdb.RdbPredicates("test")
await predicates.equalTo("age", "19")
let updatePromise = rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK);
updatePromise.then(async (ret) => {
aexpect(null).assertFail();
await rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK).then(async (ret) => {
expect(null).assertFail();
await console.log(TAG + "testRdbStoreUpdateWithConflictResolution0004 done: " + ret);
}).catch((err) => {
expect(null).assertFail();
expect(err !== null).assertTrue();
console.log(TAG + "testRdbStoreUpdateWithConflictResolution0004 error");
})
done()
// done()
}
{
let predicates = await new data_Rdb.RdbPredicates("test")
let resultSet = await rdbStore.query(predicates)
await rdbStore.query(predicates).then(async (resultSet)=>{
expect(true).assertEqual(resultSet.goToFirstRow())
const id = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name = await resultSet.getString(resultSet.getColumnIndex("name"))
......@@ -615,37 +608,38 @@ export default function relationalStoreUpdateTest() {
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
await expect(1).assertEqual(id);
await expect("zhangsan").assertEqual(name);
await expect(18).assertEqual(age);
await expect(100.5).assertEqual(salary);
await expect(1).assertEqual(blobType[0]);
await expect(2).assertEqual(blobType[1]);
await expect(3).assertEqual(blobType[2]);
expect(1).assertEqual(id);
expect("zhangsan").assertEqual(name);
expect(18).assertEqual(age);
expect(100.5).assertEqual(salary);
expect(1).assertEqual(blobType[0]);
expect(2).assertEqual(blobType[1]);
expect(3).assertEqual(blobType[2]);
console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary="
+ salary + ", blobType=" + blobType);
await expect(true).assertEqual(resultSet.goToNextRow())
expect(true).assertEqual(resultSet.goToNextRow())
const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name_1 = await resultSet.getString(resultSet.getColumnIndex("name"))
const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
await expect(2).assertEqual(id_1);
await expect("lisi").assertEqual(name_1);
await expect(19).assertEqual(age_1);
await expect(200.5).assertEqual(salary_1);
await expect(4).assertEqual(blobType_1[0]);
await expect(5).assertEqual(blobType_1[1]);
await expect(6).assertEqual(blobType_1[2]);
expect(2).assertEqual(id_1);
expect("lisi").assertEqual(name_1);
expect(19).assertEqual(age_1);
expect(200.5).assertEqual(salary_1);
expect(4).assertEqual(blobType_1[0]);
expect(5).assertEqual(blobType_1[1]);
expect(6).assertEqual(blobType_1[2]);
console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary="
+ salary_1 + ", blobType=" + blobType_1);
await expect(false).assertEqual(resultSet.goToNextRow())
expect(false).assertEqual(resultSet.goToNextRow())
resultSet.close()
done()
console.log(TAG + "************* testRdbStoreUpdateWithConflictResolution0004 end *************");
})
}
})
......@@ -689,10 +683,9 @@ export default function relationalStoreUpdateTest() {
}
let predicates = await new data_Rdb.RdbPredicates("test")
await predicates.equalTo("age", "19")
let updatePromise = rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE);
updatePromise.then(async (ret) => {
await expect(1).assertEqual(ret);
await console.log(TAG + "testRdbStoreUpdateWithConflictResolution0005 done: " + ret);
await rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE).then(async (ret) => {
expect(1).assertEqual(ret);
console.log(TAG + "testRdbStoreUpdateWithConflictResolution0005 done: " + ret);
{
let predicates = await new data_Rdb.RdbPredicates("test")
let resultSet = await rdbStore.query(predicates)
......@@ -704,33 +697,33 @@ export default function relationalStoreUpdateTest() {
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
await expect(1).assertEqual(id);
await expect("zhangsan").assertEqual(name);
await expect(18).assertEqual(age);
await expect(100.5).assertEqual(salary);
await expect(1).assertEqual(blobType[0]);
await expect(2).assertEqual(blobType[1]);
await expect(3).assertEqual(blobType[2]);
expect(1).assertEqual(id);
expect("zhangsan").assertEqual(name);
expect(18).assertEqual(age);
expect(100.5).assertEqual(salary);
expect(1).assertEqual(blobType[0]);
expect(2).assertEqual(blobType[1]);
expect(3).assertEqual(blobType[2]);
console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary="
+ salary + ", blobType=" + blobType);
await expect(true).assertEqual(resultSet.goToNextRow())
expect(true).assertEqual(resultSet.goToNextRow())
const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name_1 = await resultSet.getString(resultSet.getColumnIndex("name"))
const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
await expect(3).assertEqual(id_1);
await expect("wangjing").assertEqual(name_1);
await expect(20).assertEqual(age_1);
await expect(300.5).assertEqual(salary_1);
await expect(7).assertEqual(blobType_1[0]);
await expect(8).assertEqual(blobType_1[1]);
await expect(9).assertEqual(blobType_1[2]);
expect(3).assertEqual(id_1);
expect("wangjing").assertEqual(name_1);
expect(20).assertEqual(age_1);
expect(300.5).assertEqual(salary_1);
expect(7).assertEqual(blobType_1[0]);
expect(8).assertEqual(blobType_1[1]);
expect(9).assertEqual(blobType_1[2]);
console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary="
+ salary_1 + ", blobType=" + blobType_1);
await expect(false).assertEqual(resultSet.goToNextRow())
expect(false).assertEqual(resultSet.goToNextRow())
resultSet.close()
done()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册