All files / output cl_osql_test_environment.clas.mjs

88.37% Statements 114/129
73.68% Branches 14/19
57.89% Functions 11/19
88.37% Lines 114/129

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 1291x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 6x 6x 6x 6x 6x             6x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 2x 2x 2x 2x 2x 2x               2x 2x 2x 2x 2x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 2x 1x 1x 1x 1x
const {cx_root} = await import("./cx_root.clas.mjs");
// cl_osql_test_environment.clas.abap
class cl_osql_test_environment {
  static INTERNAL_TYPE = 'CLAS';
  static INTERNAL_NAME = 'CL_OSQL_TEST_ENVIRONMENT';
  static IMPLEMENTED_INTERFACES = ["IF_OSQL_TEST_ENVIRONMENT"];
  static ATTRIBUTES = {"MT_TABLES": {"type": () => {return abap.types.TableFactory.construct(new abap.types.Character(30, {"qualifiedName":"abap_compname"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"name":"primary_key","type":"STANDARD","isUnique":false,"keyFields":[]},"secondary":[]}, "if_osql_test_environment=>ty_t_sobjnames");}, "visibility": "I", "is_constant": " ", "is_class": " "},
  "MO_SQL": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "CL_SQL_STATEMENT", RTTIName: "\\CLASS=CL_SQL_STATEMENT"});}, "visibility": "I", "is_constant": " ", "is_class": " "},
  "MV_SCHEMA": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "I", "is_constant": "X", "is_class": "X"}};
  static METHODS = {"INITIALIZE": {"visibility": "I", "parameters": {}},
  "VALIDATE": {"visibility": "I", "parameters": {}},
  "SET_RUNTIME_PREFIX": {"visibility": "I", "parameters": {}},
  "CREATE": {"visibility": "U", "parameters": {"R_RESULT": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "IF_OSQL_TEST_ENVIRONMENT", RTTIName: "\\INTERFACE=IF_OSQL_TEST_ENVIRONMENT"});}, "is_optional": " "}, "I_DEPENDENCY_LIST": {"type": () => {return abap.types.TableFactory.construct(new abap.types.Character(30, {"qualifiedName":"abap_compname"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"name":"primary_key","type":"STANDARD","isUnique":false,"keyFields":[]},"secondary":[]}, "if_osql_test_environment=>ty_t_sobjnames");}, "is_optional": " "}}}};
  #mt_tables;
  #mo_sql;
  constructor() {
    this.me = new abap.types.ABAPObject();
    this.me.set(this);
    this.INTERNAL_ID = abap.internalIdCounter++;
    this.FRIENDS_ACCESS_INSTANCE = {
      "initialize": this.#initialize.bind(this),
      "validate": this.#validate.bind(this),
      "set_runtime_prefix": this.#set_runtime_prefix.bind(this),
    };
    this.#mt_tables = abap.types.TableFactory.construct(new abap.types.Character(30, {"qualifiedName":"abap_compname"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"name":"primary_key","type":"STANDARD","isUnique":false,"keyFields":[]},"secondary":[]}, "if_osql_test_environment=>ty_t_sobjnames");
    this.FRIENDS_ACCESS_INSTANCE["mt_tables"] = this.#mt_tables;
    this.#mo_sql = new abap.types.ABAPObject({qualifiedName: "CL_SQL_STATEMENT", RTTIName: "\\CLASS=CL_SQL_STATEMENT"});
    this.FRIENDS_ACCESS_INSTANCE["mo_sql"] = this.#mo_sql;
    this.mv_schema = cl_osql_test_environment.mv_schema;
  }
  async constructor_(INPUT) {
    if (super.constructor_) { await super.constructor_(INPUT); }
    return this;
  }
  async create(INPUT) {
    return cl_osql_test_environment.create(INPUT);
  }
  static async create(INPUT) {
    let r_result = new abap.types.ABAPObject({qualifiedName: "IF_OSQL_TEST_ENVIRONMENT", RTTIName: "\\INTERFACE=IF_OSQL_TEST_ENVIRONMENT"});
    let i_dependency_list = INPUT?.i_dependency_list;
    if (i_dependency_list?.getQualifiedName === undefined || i_dependency_list.getQualifiedName() !== "IF_OSQL_TEST_ENVIRONMENT=>TY_T_SOBJNAMES") { i_dependency_list = undefined; }
    if (i_dependency_list === undefined) { i_dependency_list = abap.types.TableFactory.construct(new abap.types.Character(30, {"qualifiedName":"abap_compname"}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"name":"primary_key","type":"STANDARD","isUnique":false,"keyFields":[]},"secondary":[]}, "if_osql_test_environment=>ty_t_sobjnames").set(INPUT.i_dependency_list); }
    let lo_env = new abap.types.ABAPObject({qualifiedName: "CL_OSQL_TEST_ENVIRONMENT", RTTIName: "\\CLASS=CL_OSQL_TEST_ENVIRONMENT"});
    abap.statements.assert(abap.compare.eq(abap.builtin.sy.get().dbsys, abap.CharacterFactory.get(6, 'sqlite')));
    lo_env.set(await (new abap.Classes['CL_OSQL_TEST_ENVIRONMENT']()).constructor_());
    lo_env.get().FRIENDS_ACCESS_INSTANCE["mt_tables"].set(i_dependency_list);
    lo_env.get().FRIENDS_ACCESS_INSTANCE["mo_sql"].set(await (new abap.Classes['CL_SQL_STATEMENT']()).constructor_());
    await lo_env.get().FRIENDS_ACCESS_INSTANCE["initialize"]();
    r_result.set(lo_env);
    return r_result;
  }
  async #validate() {
    let ref = new abap.types.DataReference(new abap.types.Character(4));
    let lv_table = new abap.types.Character(30, {"qualifiedName":"abap_compname"});
    let fs_fs_ = new abap.types.FieldSymbol(new abap.types.Character(4));
    for await (const unique1292 of abap.statements.loop(this.#mt_tables)) {
      lv_table.set(unique1292);
      try {
        abap.statements.createData(ref,{"name": lv_table.get()});
        abap.statements.assign({target: fs_fs_, source: ref.dereference()});
        await abap.statements.select(fs_fs_, {select: "SELECT * FROM " + abap.buildDbTableName(lv_table.get().trimEnd().toLowerCase()) + " UP TO 1 ROWS"});
      } catch (e) {
        if ((abap.Classes['CX_SY_CREATE_DATA_ERROR'] && e instanceof abap.Classes['CX_SY_CREATE_DATA_ERROR']) || (abap.Classes['CX_SY_DYNAMIC_OSQL_SEMANTICS'] && e instanceof abap.Classes['CX_SY_DYNAMIC_OSQL_SEMANTICS'])) {
          throw new Error(`table ${lv_table.get().trimEnd()} invalid or does not exist`);
        } else {
          throw e;
        }
      }
    }
  }
  async #initialize() {
    let lv_table = new abap.types.Character(30, {"qualifiedName":"abap_compname"});
    let lv_sql = new abap.types.String({qualifiedName: "STRING"});
    let lo_result = new abap.types.ABAPObject({qualifiedName: "CL_SQL_RESULT_SET", RTTIName: "\\CLASS=CL_SQL_RESULT_SET"});
    let lr_ref = new abap.types.DataReference(new abap.types.Character(4));
    if (abap.dbo.schemaPrefix !== "") throw new Error("already prefixed");
    await this.#validate();
    await this.#mo_sql.get().execute_update({statement: new abap.types.String().set(`ATTACH DATABASE ':memory:' AS ${abap.templateFormatting(cl_osql_test_environment.mv_schema)};`)});
    for await (const unique1293 of abap.statements.loop(this.#mt_tables)) {
      lv_table.set(unique1293);
      lv_table.set(abap.builtin.to_lower({val: lv_table}));
      lo_result.set((await this.#mo_sql.get().execute_query({statement: new abap.types.String().set(`SELECT sql FROM main.sqlite_master WHERE type='table' AND name='${abap.templateFormatting(lv_table)}';`)})));
      lr_ref.assign(lv_sql);
      await lo_result.get().set_param({data_ref: lr_ref});
      await lo_result.get().next();
      await lo_result.get().close();
      abap.statements.replace({target: lv_sql, all: false, with: new abap.types.String().set(`${abap.templateFormatting(cl_osql_test_environment.mv_schema)}'.'${abap.templateFormatting(lv_table)}`), of: lv_table});
      abap.statements.assert(abap.compare.eq(abap.builtin.sy.get().subrc, abap.IntegerFactory.get(0)));
      await this.#mo_sql.get().execute_update({statement: lv_sql});
    }
    await this.#set_runtime_prefix();
  }
  async #set_runtime_prefix() {
    abap.dbo.schemaPrefix = this.mv_schema.get();
  }
  async if_osql_test_environment$clear_doubles() {
    let lv_table = new abap.types.Character(30, {"qualifiedName":"abap_compname"});
    for await (const unique1294 of abap.statements.loop(this.#mt_tables)) {
      lv_table.set(unique1294);
      lv_table.set(abap.builtin.to_lower({val: lv_table}));
      await this.#mo_sql.get().execute_update({statement: new abap.types.String().set(`DELETE FROM ${abap.templateFormatting(cl_osql_test_environment.mv_schema)}."${abap.templateFormatting(lv_table)}";`)});
    }
  }
  async if_osql_test_environment$destroy() {
    await this.#mo_sql.get().execute_update({statement: new abap.types.String().set(`DETACH DATABASE ${abap.templateFormatting(cl_osql_test_environment.mv_schema)};`)});
    abap.dbo.schemaPrefix = "";
  }
  async if_osql_test_environment$insert_test_data(INPUT) {
    let i_data = INPUT?.i_data;
    let lo_table_descr = new abap.types.ABAPObject({qualifiedName: "CL_ABAP_TABLEDESCR", RTTIName: "\\CLASS=CL_ABAP_TABLEDESCR"});
    let lo_struct_descr = new abap.types.ABAPObject({qualifiedName: "CL_ABAP_STRUCTDESCR", RTTIName: "\\CLASS=CL_ABAP_STRUCTDESCR"});
    let lv_table = new abap.types.String({qualifiedName: "STRING"});
    await abap.statements.cast(lo_table_descr, (await abap.Classes['CL_ABAP_TYPEDESCR'].describe_by_data({p_data: i_data})));
    await abap.statements.cast(lo_struct_descr, (await lo_table_descr.get().get_table_line_type()));
    lv_table.set((await lo_struct_descr.get().get_relative_name()));
    abap.statements.assert(abap.compare.initial(lv_table) === false);
    abap.statements.readTable(this.#mt_tables,{withKey: (i) => {return abap.compare.eq(i.table_line, lv_table);},
      withKeyValue: [{key: (i) => {return i.table_line}, value: lv_table}],
      usesTableLine: true,
      withKeySimple: {"table_line": lv_table}});
    abap.statements.assert(abap.compare.eq(abap.builtin.sy.get().subrc, abap.IntegerFactory.get(0)));
    await abap.statements.insertDatabase(lv_table.get().trimEnd().toLowerCase(), {"table": i_data});
    abap.statements.assert(abap.compare.eq(abap.builtin.sy.get().subrc, abap.IntegerFactory.get(0)));
  }
}
abap.Classes['CL_OSQL_TEST_ENVIRONMENT'] = cl_osql_test_environment;
cl_osql_test_environment.mv_schema = new abap.types.String({qualifiedName: "STRING"});
cl_osql_test_environment.mv_schema.set('double');
export {cl_osql_test_environment};