Module: mockstar

mockstar

Members

<static> TruncOptions

Set of TruncOption constants.
Properties:
Name Type Default Description
FULL String full The target package gets prefixed with the package of the original model
NONE String none the target package is used

Methods

<inner> createTestModel(originalModel, targetPackage, dependencySubstitutions, truncOption) → {Object}

Creates and activates a copy of the original model in the HANA repository with the dependencies to other views/tables being replaced. At least one dependency substitution must be applied.

Supported HANA model types:
  • Graphic Calculation/Analytic/Attribute Views
  • Scripted Views
  • Stored Procedures

Supported dependency types that can be replaced with test tables:
  • Graphic Calculation/Analytic/Attribute Views
  • Scripted Views
  • Tables


In HANA, "_SYS_REPO" needs select permission (with grant option) to the test schema in order to activate the generated test model with its underlying catalog objects. Therefore make sure that "_SYS_REPO" has select permission to the schema of the test tables. Its recommended to take the user schema as test schema. That allows the parallel execution of the same test by different users. Either you can execute the following SQL statements once per system while you create the test schema:
create schema MY_TEST_SCHEMA;
grant select on schema MY_TEST_SCHEMA to _SYS_REPO with grant option;
... or you can do it even programmatically within your test.
var testSchema = $.session.getUsername().toUpperCase();
function grantSelectUserSchemaToSysRepo() {
    var connection = $.db.getConnection();
    var sqlExecutor = new sap.hana.testtools.unit.util.sqlExecutor.SqlExecutor(connection);
    sqlExecutor.execSingle('grant select on schema ' + testSchema + ' to _SYS_REPO with grant option');
    connection.close();
}
Parameters:
Name Type Argument Default Description
originalModel String the name of the original model
targetPackage String the target package where the test model should be created, e.g. tmp.<username>
dependencySubstitutions Array list of dependency substitution rules
truncOption module:mockstar.TruncOptions <optional>
TruncOptions.NONE per default the target package gets prefixed with the package of the original model
Deprecated:
Returns:
the property runTimePath contains the runtime name, the property designTimePath the designtime name of the created test model
Type
Object
Example
var testPackage = 'tmp.' + $.session.getUsername().toLowerCase();
var mockstar = $.import("sap.hana.testtools.mockstar", "apiFacade");
var dependencySubstitutions = [ {
    original : {
        schema : 'SCHEMA',
        name : 'ORDERS'
    },
    substitute : {
        schema : 'D123456',
        name : 'ORDERS'
    }
}, {
    original : 'package.subpackage/OTHER_VIEW',
    substitute : '"D123456"."OTHER_VIEW"'
} ];

var testModel = mockstar.createTestModel('package/MY_VIEW', testPackage, dependencySubstitutions, mockstar.TruncOptions.FULL);