/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import factory from '@ohos.data.distributedData';
import abilityFeatureAbility from '@ohos.ability.featureAbility';

var context = abilityFeatureAbility.getContext();
var contextApplication = context.getApplicationContext()

const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
var kvManager = null;
var kvStore = null;
const STORE_KEY = 'key_test_string';
const STORE_VALUE = 'value-test-string';
var kvStoreNew = null;

export default function kvManagerPromiseTest(){
describe('kvManagerPromiseTest', function () {
    const config = {
        bundleName: TEST_BUNDLE_NAME,
        userInfo: {
            userId: '0',
            userType: factory.UserType.SAME_USER_ID
        }
    }

    const options = {
        createIfMissing: true,
        encrypt: false,
        backup: false,
        autoSync: true,
        kvStoreType: factory.KVStoreType.SINGLE_VERSION,
        schema: '',
        securityLevel: factory.SecurityLevel.S2,
    }

    beforeAll(async function (done) {
        console.info('beforeAll');
        await factory.createKVManager(config).then((manager) => {
            kvManager = manager;
            console.info('beforeAll createKVManager success');
            kvManager.getKVStore(TEST_STORE_ID, options).then((store) => {
                console.info("beforeAll getKVStore success");
                kvStoreNew = store;
            }).catch((err) => {
                console.info("beforeAll getKVStore err: "  + JSON.stringify(err));
            });
        }).catch((err) => {
            console.info('beforeAll createKVManager err ' + err);
        });
        console.info('beforeAll end');
        done();
    })

    afterAll(async function (done) {
        console.info('afterAll');
        done();
    })

    beforeEach(async function (done) {
        console.info('beforeEach');
        done();
    })

    afterEach(async function (done) {
        console.info('afterEach');
        await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore).then(async () => {
            console.info('afterEach closeKVStore success');
            await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID).then(() => {
                console.info('afterEach deleteKVStore success');
            }).catch((err) => {
                console.info('afterEach deleteKVStore err ' + err);
            });
        }).catch((err) => {
            console.info('afterEach closeKVStore err ' + err);
        });
        kvStore = null;
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_1000
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 001
     */
    it('testKVManagerGetKVStore001', 0, async function (done) {
        console.info('testKVManagerGetKVStore001');
        try {
            await kvManager.getKVStore(TEST_STORE_ID).then((store) => {
                console.info('testKVManagerGetKVStore001 getKVStore success');
                expect(null).assertFail();
            }).catch((err) => {
                console.info('testKVManagerGetKVStore001 getKVStore err ' + err);
            });
        } catch (e) {
            console.info('testKVManagerGetKVStore001 getKVStore e ' + e);
        }
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_2000
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 002
     */
    it('testKVManagerGetKVStore002', 0, async function (done) {
        console.info('testKVManagerGetKVStore002');
        try {
            await kvManager.getKVStore(options).then((store) => {
                console.info('testKVManagerGetKVStore002 getKVStore success');
                expect(null).assertFail();
            }).catch((err) => {
                console.info('testKVManagerGetKVStore002 getKVStore err ' + err);
            });
        } catch (e) {
            console.info('testKVManagerGetKVStore002 getKVStore e ' + e);
        }
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_0300
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 003
     */
    it('testKVManagerGetKVStore003', 0, async function (done) {
        console.info('testKVManagerGetKVStore003');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.SINGLE_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.NO_LEVEL,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore003 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore003 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_0400
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 004
     */
    it('testKVManagerGetKVStore004', 0, async function (done) {
        console.info('testKVManagerGetKVStore004');
        const optionsInfo = {
            createIfMissing: false,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.SINGLE_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S1,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore004 getKVStore success');
            expect(null).assertFail();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore004 getKVStore err ' + err);
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_0500
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 005
     */
    it('testKVManagerGetKVStore005', 0, async function (done) {
        console.info('testKVManagerGetKVStore005');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: true,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.SINGLE_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S2,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore005 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore005 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_0600
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 006
     */
    it('testKVManagerGetKVStore006', 0, async function (done) {
        console.info('testKVManagerGetKVStore006');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.SINGLE_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S3,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore006 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore006 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_0700
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 007
     */
    it('testKVManagerGetKVStore007', 0, async function (done) {
        console.info('testKVManagerGetKVStore006');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: true,
            autoSync: true,
            kvStoreType: factory.KVStoreType.SINGLE_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S4,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore007 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore007 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_0800
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 008
     */
    it('testKVManagerGetKVStore008', 0, async function (done) {
        console.info('testKVManagerGetKVStore008');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.DEVICE_COLLABORATION,
            schema: '',
            securityLevel: factory.SecurityLevel.NO_LEVEL,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore008 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore008 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_0900
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 009
     */
    it('testKVManagerGetKVStore009', 0, async function (done) {
        console.info('testKVManagerGetKVStore009');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.DEVICE_COLLABORATION,
            schema: '',
            securityLevel: factory.SecurityLevel.S0,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore009 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore009 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1000
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 010
     */
    it('testKVManagerGetKVStore010', 0, async function (done) {
        console.info('testKVManagerGetKVStore010');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: false,
            kvStoreType: factory.KVStoreType.DEVICE_COLLABORATION,
            schema: '',
            securityLevel: factory.SecurityLevel.S1,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore010 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore010 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1100
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 011
     */
    it('testKVManagerGetKVStore011', 0, async function (done) {
        console.info('testKVManagerGetKVStore011');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.DEVICE_COLLABORATION,
            schema: '',
            securityLevel: factory.SecurityLevel.S2,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore011 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore011 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1200
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 012
     */
    it('testKVManagerGetKVStore012', 0, async function (done) {
        console.info('testKVManagerGetKVStore012');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.DEVICE_COLLABORATION,
            schema: '',
            securityLevel: factory.SecurityLevel.S3,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore012 getKVStore success');
            kvStore = store;
            expect(store != null).assertTrue();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore012 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1300
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 013
     */
    it('testKVManagerGetKVStore013', 0, async function (done) {
        console.info('testKVManagerGetKVStore013');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.DEVICE_COLLABORATION,
            schema: '',
            securityLevel: factory.SecurityLevel.S4,
        }
        try {
            await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
                console.info('testKVManagerGetKVStore013 getKVStore success');
            }).catch((err) => {
                console.info('testKVManagerGetKVStore013 getKVStore err ' + err);
                expect(null).assertFail();
            });
        } catch (e) {
            console.info('testKVManagerGetKVStore013 getKVStore e ' + e);
        }
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1400
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 014
     */
    it('testKVManagerGetKVStore014', 0, async function (done) {
        console.info('testKVManagerGetKVStore014');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.MULTI_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.NO_LEVEL,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore014 getKVStore success');
            expect(null).assertFail();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore014 getKVStore err ' + err);
            expect(true).assertTrue();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1500
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 015
     */
    it('testKVManagerGetKVStore015', 0, async function (done) {
        console.info('testKVManagerGetKVStore015');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.MULTI_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S0,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore015 getKVStore success');
            expect(null).assertFail();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore015 getKVStore err ' + err);
            expect(true).assertTrue();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1600
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 016
     */
    it('testKVManagerGetKVStore016', 0, async function (done) {
        console.info('testKVManagerGetKVStore016');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.MULTI_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S1,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore016 getKVStore success');
            expect(null).assertFail();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore016 getKVStore err ' + err);
            expect(true).assertTrue();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1700
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 017
     */
    it('testKVManagerGetKVStore017', 0, async function (done) {
        console.info('testKVManagerGetKVStore017');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.MULTI_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S2,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore017 getKVStore success');
            expect(null).assertFail();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore017 getKVStore err ' + err);
            expect(true).assertTrue();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1800
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 018
     */
    it('testKVManagerGetKVStore018', 0, async function (done) {
        console.info('testKVManagerGetKVStore018');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.MULTI_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S3,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore018 getKVStore success');
            expect(null).assertFail();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore018 getKVStore err ' + err);
            expect(true).assertTrue();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETKVSTORE_PROMISE_1900
     * @tc.name [JS-API8]KVManager.GetKVStore.
     * @tc.desc Test Js Api KVManager.GetKVStore testcase 019
     */
    it('testKVManagerGetKVStore019', 0, async function (done) {
        console.info('testKVManagerGetKVStore019');
        const optionsInfo = {
            createIfMissing: true,
            encrypt: false,
            backup: false,
            autoSync: true,
            kvStoreType: factory.KVStoreType.MULTI_VERSION,
            schema: '',
            securityLevel: factory.SecurityLevel.S4,
        }
        await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
            console.info('testKVManagerGetKVStore019 getKVStore success');
            expect(null).assertFail();
        }).catch((err) => {
            console.info('testKVManagerGetKVStore019 getKVStore err ' + err);
            expect(true).assertTrue();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_CLOSEKVSTORE_0100
     * @tc.name [JS-API8]KVManager.CloseKVStore.
     * @tc.desc Test Js Api KVManager.CloseKVStore testcase 001
     */
    it('testKVManagerCloseKVStore001', 0, async function (done) {
        console.info('testKVManagerCloseKVStore004');
        await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) {
            console.info('testKVManagerCloseKVStore001 getKVStore success');
            kvStore = store;
            await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore);
        });
        console.info('testKVManagerCloseKVStore001 closeKVStore redo.');
        await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore).then(() => {
            console.info('testKVManagerCloseKVStore001 closeKVStore twice');
            expect(null).assertFail();
        }).catch((err) => {
            console.info('testKVManagerCloseKVStore001 closeKVStore twice err ' + err);
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_DELETEKVSTORE_0100
     * @tc.name [JS-API8]KVManager.DeleteKVStore.
     * @tc.desc Test Js Api KVManager.DeleteKVStore testcase 001
     */
    it('testKVManagerDeleteKVStore001', 0, async function (done) {
        console.info('testKVManagerDeleteKVStore001');
        await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID).then(() => {
            console.info('testKVManagerDeleteKVStore001 deleteKVStore success');
        }).catch((err) => {
            expect(null).assertFail();
            console.info('testKVManagerDeleteKVStore001 deleteKVStore err ' + err);
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETALLKVSTOREID_0100
     * @tc.name [JS-API8]KVManager.GetAllKVStoreId.
     * @tc.desc Test Js Api KVManager.GetAllKVStoreId testcase 001
     */
    it('testKVManagerGetAllKVStoreId001', 0, async function (done) {
        console.info('testKVManagerGetAllKVStoreId001');
        await kvManager.getAllKVStoreId(TEST_BUNDLE_NAME).then((data) => {
            console.info('testKVManagerGetAllKVStoreId001 getAllKVStoreId success');
            console.info('testKVManagerGetAllKVStoreId001 size = ' + data.length);
            expect(0).assertEqual(data.length);
        }).catch((err) => {
            console.info('testKVManagerGetAllKVStoreId001 getAllKVStoreId err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_GETALLKVSTOREID_0200
     * @tc.name [JS-API8]KVManager.GetAllKVStoreId.
     * @tc.desc Test Js Api KVManager.GetAllKVStoreId testcase 002
     */
    it('testKVManagerGetAllKVStoreId002', 0, async function (done) {
        console.info('testKVManagerGetAllKVStoreId002');
        await kvManager.getKVStore(TEST_STORE_ID, options).then(async (store) => {
            console.info('testKVManagerGetAllKVStoreId002 getKVStore success');
            kvStore = store;
            await kvManager.getAllKVStoreId(TEST_BUNDLE_NAME).then((data) => {
                console.info('testKVManagerGetAllKVStoreId002 getAllKVStoreId success');
                console.info('testKVManagerGetAllKVStoreId002 size = ' + data.length);
                expect(1).assertEqual(data.length);
                console.info('testKVManagerGetAllKVStoreId002 data[0] = ' + data[0]);
                expect(TEST_STORE_ID).assertEqual(data[0]);
            }).catch((err) => {
                console.info('testKVManagerGetAllKVStoreId002 getAllKVStoreId err ' + err);
                expect(null).assertFail();
            });
        }).catch((err) => {
            console.info('testKVManagerGetAllKVStoreId002 getKVStore err ' + err);
            expect(null).assertFail();
        });
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_ON_0100
     * @tc.name [JS-API8]KVManager.On.
     * @tc.desc Test Js Api KVManager.On testcase 001
     */
    it('testKVManagerOn001', 0, function (done) {
        console.info('testKVManagerOn001');
        var deathCallback = function () {
            console.info('death callback call');
        }
        kvManager.on('distributedDataServiceDie', deathCallback);
        kvManager.off('distributedDataServiceDie', deathCallback);
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_ON_0200
     * @tc.name [JS-API8]KVManager.On.
     * @tc.desc Test Js Api KVManager.On testcase 002
     */
    it('testKVManagerOn002', 0, function (done) {
        console.info('testKVManagerOn002');
        var deathCallback1 = function () {
            console.info('death callback call');
        }
        var deathCallback2 = function () {
            console.info('death callback call');
        }
        kvManager.on('distributedDataServiceDie', deathCallback1);
        kvManager.on('distributedDataServiceDie', deathCallback2);
        kvManager.off('distributedDataServiceDie', deathCallback1);
        kvManager.off('distributedDataServiceDie', deathCallback2);
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_ON_0300
     * @tc.name [JS-API8]KVManager.On.
     * @tc.desc Test Js Api KVManager.On testcase 003
     */
    it('testKVManagerOn003', 0, function (done) {
        console.info('testKVManagerOn003');
        var deathCallback = function () {
            console.info('death callback call');
        }
        kvManager.on('distributedDataServiceDie', deathCallback);
        kvManager.on('distributedDataServiceDie', deathCallback);
        kvManager.off('distributedDataServiceDie', deathCallback);
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_OFF_0100
     * @tc.name [JS-API8]KVManager.Off.
     * @tc.desc Test Js Api KVManager.Off testcase 001
     */
    it('testKVManagerOff001', 0, function (done) {
        console.info('testKVManagerOff001');
        var deathCallback = function () {
            console.info('death callback call');
        }
        kvManager.off('distributedDataServiceDie', deathCallback);
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_OFF_0200
     * @tc.name [JS-API8]KVManager.Off.
     * @tc.desc Test Js Api KVManager.Off testcase 002
     */
    it('testKVManagerOff002', 0, function (done) {
        console.info('testKVManagerOff002');
        var deathCallback = function () {
            console.info('death callback call');
        }
        kvManager.on('distributedDataServiceDie', deathCallback);
        kvManager.off('distributedDataServiceDie', deathCallback);
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_OFF_0300
     * @tc.name [JS-API8]KVManager.Off.
     * @tc.desc Test Js Api KVManager.Off testcase 003
     */
    it('testKVManagerOff003', 0, function (done) {
        console.info('testKVManagerOff003');
        var deathCallback1 = function () {
            console.info('death callback call');
        }
        var deathCallback2 = function () {
            console.info('death callback call');
        }
        kvManager.on('distributedDataServiceDie', deathCallback1);
        kvManager.on('distributedDataServiceDie', deathCallback2);
        kvManager.off('distributedDataServiceDie', deathCallback1);
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_OFF_0400
     * @tc.name [JS-API8]KVManager.Off.
     * @tc.desc Test Js Api KVManager.Off testcase 004
     */
    it('testKVManagerOff004', 0, function (done) {
        console.info('testKVManagerOff004');
        var deathCallback = function () {
            console.info('death callback call');
        }
        kvManager.on('distributedDataServiceDie', deathCallback);
        kvManager.off('distributedDataServiceDie', deathCallback);
        kvManager.off('distributedDataServiceDie', deathCallback);
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_OFF_0500
     * @tc.name [JS-API8]KVManager.Off.
     * @tc.desc Test Js Api KVManager.Off testcase 005
     */
    it('testKVManagerOff005', 0, function (done) {
        console.info('testKVManagerOff001');
        var deathCallback = function () {
            console.info('death callback call');
        }
        kvManager.on('distributedDataServiceDie', deathCallback);
        kvManager.off('distributedDataServiceDie');
        done();
    })

    /**
     * @tc.number SUB_DISTRIBUTEDDATAMGR_KVSTORE_PUT_1000
     * @tc.name [JS-API8]KVStore.Put
     * @tc.desc Test Js Api KVManager.Put testcase 001
     */
    it('testKVStorePut001', 0, async function (done) {
        console.info('testKVStorePut001');
        try {
            await kvStoreNew.put(TEST_BUNDLE_NAME, TEST_STORE_ID).then((data) => {
                if (err != undefined){
                    console.info('testKVStorePut001 put promise fail');
                } else {
                    console.info('testKVStorePut001 put promise success');
                    expect(null).assertFail();
                }
                done();
            });
        } catch (e) {
            console.info('testKVStorePut001 e ' + e);
            done();
        }
    })

    /**
      * @tc.number SUB_DISTRIBUTEDDATAMGR_KVSTORE_DELETE_1000
      * @tc.name [JS-API8]KVStore.Delete
      * @tc.desc Test Js Api KVManager.Delete testcase 001
      */
    it('testKVStoreDelete001', 0, async function (done) {
        console.info('testKVStoreDelete001');
        try {
            kvStoreNew.put(STORE_KEY, STORE_VALUE).then((data) => {
                console.info('testKVStoreDelete001 getKVStore success');
                kvStoreNew.delete(STORE_KEY).then((data) => {
                    console.info("testKVStoreDelete001  promise delete success");
                    expect(null).assertFail();
                }).catch((err) => {
                    console.info('testKVStoreDelete001 promise delete fail err' + err);
                });
            }).catch((err) => {
                console.info('testKVStoreDelete001 promise delete fail err' + err);
            });
        }catch (e) {
            console.info('testKVStoreDelete001 promise delete fail err' + err);
        }
        done();
    })

    /**
      * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_CONTEXT_1000
      * @tc.name [JS-API9]KVManagerConfig.context
      * @tc.desc Test Js Api createKVManager testcase 001
      */
     it('testcreateKVManager001', 0, async function (done) {
        console.info('testcreateKVManager001');
        const config = {
            bundleName: TEST_BUNDLE_NAME,
            userInfo: {
                userId: '0',
                userType: factory.UserType.SAME_USER_ID
            },
            context:context
        }
        try {
            await factory.createKVManager(config).then(async (manager) => {
                kvManager = manager;
                expect(manager !=null).assertTrue();
                console.info('testcreateKVManager001 createKVManager success');
                await kvManager.getKVStore(TEST_STORE_ID, options).then(async (store) => {
                    console.info("testcreateKVManager001 getKVStore success");
                    await store.put(STORE_KEY, STORE_VALUE).then(async (data) => {
                        console.info('testcreateKVManager001 put data success');
                        await store.get(STORE_KEY).then((data) => {
                            console.info("testcreateKVManager001  get data success");
                            expect(data).assertEqual(STORE_VALUE);
                        }).catch((err) => {
                            console.info('testcreateKVManager001 get data err' + err);
                        });
                    }).catch((err) => {
                        console.info('testcreateKVManager001 put data err' + err);
                    });
                }).catch((err) => {
                    console.info("testcreateKVManager001 getKVStore err: "  + JSON.stringify(err));
                    expect(null).assertFail();
                });
            }).catch((err) => {
                console.info('testcreateKVManager001 createKVManager err ' + err);
                expect(null).assertFail()
            });
        }catch (e) {
            console.info('testcreateKVManager001 promise delete fail err' + err);
            expect(null).assertFail();
        }
        done();
    })

    /**
      * @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_CONTEXTAPPLICATION_1000
      * @tc.name [JS-API9]KVManagerConfig.context
      * @tc.desc Test Js Api createKVManager testcase 001
      */
     it('testcreateKVManager002', 0, async function (done) {
        console.info('testcreateKVManager002');
        const config = {
            bundleName: TEST_BUNDLE_NAME,
            userInfo: {
                userId: '0',
                userType: factory.UserType.SAME_USER_ID
            },
            context:contextApplication
        }
        try {
            await factory.createKVManager(config).then(async (manager) => {
                kvManager = manager;
                console.info('testcreateKVManager002 createKVManager success');
                await kvManager.getKVStore(TEST_STORE_ID, options).then(async (store) => {
                    console.info("testcreateKVManager002 getKVStore success");
                    await store.put(STORE_KEY, STORE_VALUE).then(async (data) => {
                        console.info('testcreateKVManager002 put data success');
                        await store.get(STORE_KEY).then((data) => {
                            console.info("testcreateKVManager002  get data success");
                            expect(data).assertEqual(STORE_VALUE);
                        }).catch((err) => {
                            console.info('testcreateKVManager002 get data err' + err);
                        });
                    }).catch((err) => {
                        console.info('testcreateKVManager002 put data err' + err);
                    });
                }).catch((err) => {
                    console.info("testcreateKVManager002 getKVStore err: "  + JSON.stringify(err));
                    expect(null).assertFail();
                });
            }).catch((err) => {
                console.info('testcreateKVManager002 createKVManager err ' + err);
                expect(null).assertFail()
            });
        }catch (e) {
            console.info('testcreateKVManager002 promise delete fail err' + err);
            expect(null).assertFail();
        }
        done();
    })
    
})
}