未验证 提交 8b14daa5 编写于 作者: O openharmony_ci 提交者: Gitee

!7283 【xts_acts】【分布式数据管理】【master】新增用例覆盖需求新接口

Merge pull request !7283 from 刘皓男/master
......@@ -1088,6 +1088,344 @@ describe('relationalStoreInsertTest', function () {
console.info(TAG + "************* testRdbStorebatchInsertCallback0007 end *************");
})
console.info(TAG + "*************Unit Test End*************");
/**
* @tc.name rdb inserttWithConflictResolution test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0001
* @tc.desc rdb insertWithConflictResolution test
*/
it('InsertWithConflictResolution0001', 0, async function (done) {
console.log(TAG + " ************* InsertWithConflictResolution0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_NONE);
}
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 200.5,
"blobType": u8,
}
try {
let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_NONE);
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret);
console.log(TAG + " InsertWithConflictResolution0001 insert first done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.log(TAG + " InsertWithConflictResolution0001 insert with wrong valuebucket and ConflictResolution is default")
done();
})
} catch(err) {
console.log(TAG + " InsertWithConflictResolution0001 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code);
expect(null).assertFail();
}
}
console.log(TAG + " ************* InsertWithConflictResolution_0001 end *************");
})
/**
* @tc.name rdb inserttWithConflictResolution test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0002
* @tc.desc rdb insertWithConflictResolution test
*/
it('InsertWithConflictResolution0002', 0, async function (done) {
console.log(TAG + " ************* InsertWithConflictResolution0002 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK);
}
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 200.5,
"blobType": u8,
}
try {
let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK);
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.log(TAG + " InsertWithConflictResolution0002 insert first done: " + ret)
expect(null).assertFail()
}).catch((err) => {
console.log(TAG + " InsertWithConflictResolution0002 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_ROLLBACK")
done()
})
} catch(err) {
console.log(TAG + " InsertWithConflictResolution0002 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code)
expect(null).assertFail()
}
}
console.log(TAG + " ************* InsertWithConflictResolution_0002 end *************");
})
/**
* @tc.name rdb inserttWithConflictResolution test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0003
* @tc.desc rdb insertWithConflictResolution test
*/
it('InsertWithConflictResolution0003', 0, async function (done) {
console.log(TAG + " ************* InsertWithConflictResolution0003 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_IGNORE);
}
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 200.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_IGNORE);
}
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
console.log(TAG + " InsertWithConflictResolution0003 resultSet query done");
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 );
expect(1).assertEqual(id);
expect(100.5).assertEqual(salary)
expect(false).assertEqual(resultSet.goToNextRow())
} catch (err) {
console.log(TAG + " InsertWithConflictResolution0003 insert error" + err);
}
resultSet = null
done()
console.log(TAG + " ************* InsertWithConflictResolution_0003 end *************");
})
/**
* @tc.name rdb inserttWithConflictResolution test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0004
* @tc.desc rdb insertWithConflictResolution test
*/
it('InsertWithConflictResolution0004', 0, async function (done) {
console.log(TAG + " ************* InsertWithConflictResolution0004 start *************");
{
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE);
}
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
console.log(TAG + " InsertWithConflictResolution0004 resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
expect(1).assertEqual(id);
expect(false).assertEqual(resultSet.goToNextRow())
} catch (err) {
console.log(TAG + " InsertWithConflictResolution0004 insert error" + err);
}
{
var u8 = new Uint8Array([4, 5, 6])
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 200.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE);
}
resultSet = await rdbStore.query(predicates)
try {
console.log(TAG + " InsertWithConflictResolution0004 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.log(TAG + " InsertWithConflictResolution0004 id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(1).assertEqual(id);
expect("zhangsan").assertEqual(name)
expect(18).assertEqual(age)
expect(200.5).assertEqual(salary)
expect(4).assertEqual(blobType[0])
expect(5).assertEqual(blobType[1])
expect(6).assertEqual(blobType[2])
expect(false).assertEqual(resultSet.goToNextRow())
} catch (err) {
console.log(TAG + " InsertWithConflictResolution0004 resultSet query error " + err);
}
resultSet = null
done()
console.log(TAG + " ************* InsertWithConflictResolution_0004 end *************");
})
/**
* @tc.name rdb inserttWithConflictResolution test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0005
* @tc.desc rdb insertWithConflictResolution test
*/
it('InsertWithConflictResolution0005', 0, async function (done) {
console.log(TAG + " ************* InsertWithConflictResolution0005 start *************");
{
var u8 = new Uint8Array([4, 5, 6])
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 200.5,
"blobType": u8,
}
try {
rdbStore.insert("test", valueBucket, 6);
expect(null).assertFail()
} catch(err) {
console.log(TAG + " InsertWithConflictResolution0005 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code)
done()
}
}
console.log(TAG + " ************* InsertWithConflictResolution_0005 end *************");
})
/**
* @tc.name rdb inserttWithConflictResolution test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0006
* @tc.desc rdb insertWithConflictResolution test
*/
it('InsertWithConflictResolution0006', 0, async function (done) {
console.log(TAG + " ************* InsertWithConflictResolution0006 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ABORT);
}
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 200.5,
"blobType": u8,
}
try {
let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ABORT);
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.log(TAG + " InsertWithConflictResolution0006 insert first done: " + ret)
expect(null).assertFail()
}).catch((err) => {
console.log(TAG + " InsertWithConflictResolution0006 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_ABORT")
done()
})
} catch(err) {
console.log(TAG + " InsertWithConflictResolution0006 catch err: failed, err: code=" + err.code + " message=" + err.message)
expect("401").assertEqual(err.code)
expect(null).assertFail()
}
}
console.log(TAG + " ************* InsertWithConflictResolution0006 end *************");
})
/**
* @tc.name rdb inserttWithConflictResolution test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0007
* @tc.desc rdb insertWithConflictResolution test
*/
it('InsertWithConflictResolution0007', 0, async function (done) {
console.log(TAG + " ************* InsertWithConflictResolution0007 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL);
}
{
const valueBucket = {
"id": 1,
"name": "zhangsan",
"age": 18,
"salary": 200.5,
"blobType": u8,
}
try {
let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL);
insertPromise.then(async (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")
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()
}
}
console.log(TAG + " ************* InsertWithConflictResolution0007 end *************");
})
console.info(TAG + " *************Unit Test End*************");
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册