Module: mockstarEnvironment

mockstarEnvironment

See mockstarEnvironment.define function or mockstarEnvironment.defineAndCreate to create a dedicated MockstarEnvironment Object.
Since:
  • 1.9.2

Classes

MockstarEnvironment

Methods

<inner> define(definition, connection) → {module:mockstarEnvironment~MockstarEnvironment}

Creates a MockstarEnvironment object with an initial definition. MockstarEnvironment offers functions that helps you to test a model (e.g. view or procedure) in an isolated way. It offers functions to:
  • define the test model
  • define the dependent tables/views that should be replaced in the test model by test tables
  • fill those test tables with data/from csv file.
Note that for each dependent table/view a test table is created automatically via the test helper functions TableUtils.copyIntoUserSchema and TableUtils.createTestTableFromView unless you have specified the test table explicitly via the 'testTable' property.
Parameters:
Name Type Argument Description
definition Object
Properties
Name Type Argument Default Description
schema String <optional>
the schema, that should be used, when no schema is explicitly specified
model String | Object the name of the original model without schema or the original model with the properties as described below
Properties
Name Type Argument Default Description
schema String <optional>
automatically determined, definition.schema on failure the schema of the original model
name String <optional>
the name of the original model (without schema), e.g. "package.subpackage/ca_view"
targetPackage String <optional>
"tmp.unittest.<username>" the package name where the test model should be created into
mockstarProperties Object <optional>
defines the options for mockstar.createTestModel
Properties
Name Type Argument Default Description
truncOption String <optional>
TruncOptions.NONE per default the target package gets prefixed with the package of the original model
useHdbConnection String <optional>
false if true, jasmine.hdbConnection is used instead of jasmine.dbConnection. The flag is ignored when the connection parameter is filled. The flag is also ignored if the $.hdb API is not available
csvPackage String <optional>
the package name of the .csv files
csvProperties Object <optional>
defines the options for tableUtils.fillFromCsvFile
Properties
Name Type Argument Default Description
separator String <optional>
";" overwrites the value separator
headers Boolean <optional>
true indicates whether the data contains a header line
decSeparator String <optional>
"." overwrites the decimal separator
substituteTables Object <optional>
list of table dependencies that should be substituted within the copied test model hierarchy
Properties
Name Type Description
<id> String | Object the name of the original table without schema
"tableId": "package.subpackage::context.entity"
or a substitution rule with the properties as described below
"tableId": {...}
Properties
Name Type Argument Default Description
schema String <optional>
definition.schema schema of the table to be substituted
name String name of the table to be substituted (without schema)
data String <optional>
data to be inserted into the test table tableUtils.insertData
csvFile String <optional>
name of the .csv file to be uploaded into the test table. In that case you need to specify definition.csvPackage
testTable String <optional>
the full test table name including the schema that should be used as table substitution e.g. '"TESTSCHEMA"."MY_TEST_TABLE"'
substituteViews Object <optional>
list of view dependencies that should be substituted within the copied test model hierarchy
Properties
Name Type Description
<id> String | Object the name of the original view without schema
"viewId": "package.subpackage/ca_view"
or a substitution rule with the properties as described below
"viewId": {...}
Properties
Name Type Argument Default Description
schema String <optional>
definition.schema|"_SYS_BIC" schema of the view to be substituted
name String name of the view to be substituted (without schema)
data String <optional>
data to be inserted into the test table tableUtils.insertData
csvFile String <optional>
name of the .csv file to be uploaded into the test table. In that case you need to specify definition.csvPackage
testTable String <optional>
the full test table name including the schema that should be used as table substitution e.g. '"TESTSCHEMA"."MY_TEST_TABLE"'
substituteProcedures Object <optional>
list of procedure dependencies that should be substituted within the copied test model hierarchy
Properties
Name Type Description
<id> Object a substitution rule with the properties as described below
"viewId": {...}
Properties
Name Type Argument Description
schema String <optional>
schema of the procedure to be substituted
name String name of the procedure to be substituted (without schema)
testProcedure String the full test procedure name including the schema that should be used as substitution e.g. '"TESTSCHEMA"."MY_PROCEDURE_STUB"'
substituteFunctions Object <optional>
list of table function dependencies that should be substituted within the copied test model hierarchy
Properties
Name Type Description
<id> String | Object the name of the original function without schema
"functionId": "package.subpackage/table_function"
or a substitution rule with the properties as described below
"viewId": {...}
Properties
Name Type Argument Description
schema String <optional>
schema of the function to be substituted
name String name of the function to be substituted (without schema)
data String <optional>
data to be inserted into the test table tableUtils.insertData
csvFile String <optional>
name of the .csv file to be uploaded into the test table. In that case you need to specify definition.csvPackage
testTable String <optional>
the full test table name including the schema that should be used as function substitution e.g. '"TESTSCHEMA"."MY_TEST_TABLE"'
connection $.db.Connection <optional>
Connection to database. If not specified, jasmine.hdbConnection or jasmine.dbConnection is used depending on whether definition.mockstarProperties.useHdbConnection is true or false, respectively. Do not pass jasmine.dbConnection or jasmine.hdbConnection explicitly, as this might cause errors!
Since:
  • 1.10.10 (connection parameter)
    1.10.12 (useHdbConnection flag)
See:
Returns:
Mockstar environment object that contains several definition methods to create a test model and test tables in order to test a model in an isolated way.
Type
module:mockstarEnvironment~MockstarEnvironment
Example
var mockstarEnvironment = $.import("sap.hana.testtools.mockstar", "mockstarEnvironment");

var testData = { Id: "1", col2: "A", COL3: 10.1 };
var definition = {
      schema: "SCHEMA",
      model: {
              schema : "_SYS_BIC",
              name: "package.subpackage/calculationview",
      },
      substituteTables: {
          "table_id": {
              name: "package.db::basis.t_table",
              csvFile: "table.csv"
          }
      },
      substituteViews: {
          "view_id": {
              name: "package.db::basis.v_item",
              testTable: '"USER"."v_item_table"',
              data: testData
          }
      },
      substituteProcedures: {
          "proc_id": {
              name: "package.db::basis.p_proc",
              testProcedure: '"USER"."p_proc_stub"'
          }
      }
};
var testEnvironment = mockstarEnvironment.define(definition);

<inner> defineAndCreate(definition, connection) → {module:mockstarEnvironment~MockstarEnvironment}

Creates a MockstarEnvironment Object with a given definition. After calling this function the test model as well as the defined test tables are created (mockstarEnvironment.create).
Equivalent to
define(definition).create()
Parameters:
Name Type Argument Description
definition Object like in mockstarEnvironment.define
connection $.db.Connection <optional>
like in mockstarEnvironment.define
See:
Returns:
mockstarEnvironment that contains several definition methods to fill test tables in order to test a model in an isolated way.
Type
module:mockstarEnvironment~MockstarEnvironment