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

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

Merge pull request !9927 from yanglifeng/master
......@@ -23,245 +23,243 @@ const STORE_CONFIG = {
var rdbStore = undefined;
export default function rdbStoreUpdateTest() {
describe('rdbStoreUpdateTest', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await rdbStore.executeSql("DELETE FROM test");
rdbStore = null
await dataRdb.deleteRdbStore("UpdataTest.db");
})
describe('rdbStoreUpdateTest', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0010
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0001', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
//插入
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret);
console.info(TAG + "update done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
//更新
{
var u8 = new Uint8Array([4, 5, 6])
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 200.5,
"blobType": u8,
}
let predicates = await new dataRdb.RdbPredicates("test")
predicates.equalTo("id", "1")
let updatePromise = rdbStore.update(valueBucket, predicates)
await updatePromise.then(async (ret) => {
expect(1).assertEqual(ret);
console.info(TAG + "update done: " + ret);
let resultSet = await rdbStore.query(predicates)
afterEach(async function () {
console.info(TAG + 'afterEach')
await rdbStore.executeSql("DELETE FROM test");
rdbStore = null
await dataRdb.deleteRdbStore("UpdataTest.db");
})
expect(true).assertEqual(resultSet.goToFirstRow())
const id = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name = await resultSet.getString(resultSet.getColumnIndex("name"))
const age = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
afterAll(async function () {
console.info(TAG + 'afterAll')
})
expect(1).assertEqual(id);
expect("lisi").assertEqual(name);
expect(20).assertEqual(age);
expect(200.5).assertEqual(salary);
expect(4).assertEqual(blobType[0]);
expect(5).assertEqual(blobType[1]);
expect(6).assertEqual(blobType[2]);
console.info(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(false).assertEqual(resultSet.goToNextRow())
resultSet = null
}).catch((err) => {
console.info(TAG + "update error");
expect(null).assertFail();
})
//await updatePromise
}
done();
console.info(TAG + "************* testRdbStoreUpdate0001 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0020
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0002', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0002 start *************");
//更新
{
let errInfo = undefined;
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0010
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0001', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
try{
let predicates = new dataRdb.RdbPredicates("")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with null table name");
})
}catch(err){
errInfo = err
}
//插入
{
const emptyBucket = {};
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(emptyBucket, predicates)
updatePromise.then(async (ret) => {
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong valueBucket");
expect(null).assertFail();
})
await insertPromise
}
//更新
{
var u8 = new Uint8Array([4, 5, 6])
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 200.5,
"blobType": u8,
}
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("aaa", "null")
predicates.equalTo("id", "1")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await updatePromise.then(async (ret) => {
expect(1).assertEqual(ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
})
}
expect(errInfo.code).assertEqual("401")
}
done();
console.info(TAG + "************* testRdbStoreUpdate0002 end *************");
})
let resultSet = await rdbStore.query(predicates)
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0030
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0003', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0003 start *************");
//更新
{
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
"wrongColumn": 100.5,
}
{
let predicates = new dataRdb.RdbPredicates("wrongTable")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
expect(true).assertEqual(resultSet.goToFirstRow())
const id = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name = await resultSet.getString(resultSet.getColumnIndex("name"))
const age = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
expect(1).assertEqual(id);
expect("lisi").assertEqual(name);
expect(20).assertEqual(age);
expect(200.5).assertEqual(salary);
expect(4).assertEqual(blobType[0]);
expect(5).assertEqual(blobType[1]);
expect(6).assertEqual(blobType[2]);
console.info(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(false).assertEqual(resultSet.goToNextRow())
resultSet = null
}).catch((err) => {
console.info(TAG + "update with wrong table name");
})
//await updatePromise
}
{
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
console.info(TAG + "update error");
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong column name");
})
//await updatePromise
}
}
done();
console.info(TAG + "************* testRdbStoreUpdate0003 end *************");
})
done();
console.info(TAG + "************* testRdbStoreUpdate0001 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0040
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0004', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0004 start *************");
//更新
{
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0020
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0002', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0002 start *************");
//更新
{
let errInfo = undefined;
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
try{
let predicates = new dataRdb.RdbPredicates("")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with null table name");
})
}catch(err){
errInfo = err
}
{
const emptyBucket = {};
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(emptyBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong valueBucket");
})
}
{
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("aaa", "null")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
})
}
expect(errInfo.code).assertEqual("401")
}
done();
console.info(TAG + "************* testRdbStoreUpdate0002 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0030
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0003', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0003 start *************");
//更新
{
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("aaa", "null")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
})
//await updatePromise
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
"wrongColumn": 100.5,
}
{
let predicates = new dataRdb.RdbPredicates("wrongTable")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong table name");
})
//await updatePromise
}
{
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong column name");
})
//await updatePromise
}
}
done();
console.info(TAG + "************* testRdbStoreUpdate0003 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0040
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0004', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0004 start *************");
//更新
{
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) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
})
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
{
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("aaa", "null")
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();
})
}
{
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("name", "zhangsan")
await predicates.equalTo("age", 18)
await predicates.equalTo("null", 100.5)
await rdbStore.update(valueBucket, predicates).then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(ret).assertEqual(0);
}).catch((err) => {
console.info(TAG + "update with wrong condition");
expect(null).assertFail();
})
}
}
}
done();
console.info(TAG + "************* testRdbStoreUpdate0004 end *************");
done();
console.info(TAG + "************* testRdbStoreUpdate0004 end *************");
})
console.info(TAG + "*************Unit Test 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();
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册