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 Default 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>
definition.schema|"_SYS_BIC" 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
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 the original table 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 the original view 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"'
connection $.db.Connection <optional>
jasmine.dbConnection Connection to database
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
          }
      }
};
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
<pre>
define(definition).create()
</pre>
Parameters:
Name Type Argument Default Description
definition Object like in mockstarEnvironment.define
connection $.db.Connection <optional>
jasmine.dbConnection Connection to database
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