Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The strong typed named query classes generated by scl-gen NamedQuery were missing a default constructor (constructor with no parameters). As a result the deserialization of those objects failed when passing a named query from the GUI client to the backend.

The templates used by scl-gen NamedQuery now include the default constructor. Developers will have to regenerate hte named query classes to include the constructor or add a default constructor manually, e.g.:

Code Block
languagec#
    /*------------------------------------------------------------------------------
        Purpose: Constructor for the SearchEmployeeQuery class
        Notes:
    ------------------------------------------------------------------------------*/
    CONSTRUCTOR PUBLIC SearchEmployeeQuery ():
        /* noop */
    END CONSTRUCTOR .

...

We have made the BufferDataSource class ( https://documentation.consultingwerkcloud.com/display/SCL/New+API+for+dynamic+DATA-SOURCE+objects ) mockable using our Generic Factory service ( https://documentation.consultingwerkcloud.com/display/SCL/Generic+Factory+Service ).

This allows a developer to test the data access of a regular DataAccess class (for complex query manipulation or BEFORE-ROW-FILL based row-level security implementation) using XML files. This is related to the MockDataAccess feature - however the MockDataAccess class replaces the whole DataAccess class with a generic XML file based implementation allowing the developer to test the Business Entity component without Data Access.

To mock the Data Access it is required to use the BufferDataSource instead of the ABL DATA-SOURCE object handles currently generated by the Business Entity Designer (enhancement SCL-2476 has been logged to implement an alternative Data Access class generation based on BufferDataSource classes). The definition of the BufferDataSource instance may be made as a global variable in the class header. When multiple temp-tables are included in the Data Access class, it may be required to defined multiple variables.

Code Block
languagec#
    DEFINE VARIABLE oDataSource AS IBufferDataSource NO-UNDO .



The method AttachDataSource is used here to retriev an IBufferDataSource instance through the factory. This may be an instance of the original Consultingwerk.OERA.BufferDataSource class or the Consultingwerk.SmartUnit.OERA.MockBufferDataSource.MockBufferDataSource class which supports mocking of database buffers with temp-table buffers for unit tests.

Code Block
languagec#
    METHOD OVERRIDE PROTECTED VOID AttachDataSources ():

        DEFINE VARIABLE oFactory AS IFactory.

        oDataSource = CAST ({Consultingwerk/get-service.i IFactory}:CreateInstance(GET-CLASS (IBufferDataSource),
                                                                                   ArrayHelper:Array (NEW CharacterHolder ("Order"))),
                            IBufferDataSource) .

        Consultingwerk.Util.DatasetHelper:SetTrackingChanges (DATASET dsOrder:HANDLE, FALSE) .

        THIS-OBJECT:AttachDataSource (BUFFER eOrder:HANDLE, oDataSource) .

    END METHOD.



The generic factory must be configured like this through an XML file to support the unit testing:

Code Block
languagexml
<?xml version="1.0"?>
<ttFactoryLoader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ttFactoryLoaderRow>
    <FactoryType>Consultingwerk.OERA.IBufferDataSource</FactoryType>
    <FactoryAlias></FactoryAlias>
    <InstanceType>Consultingwerk.SmartUnit.OERA.MockBufferDataSource.MockBufferDataSource</InstanceType>
  </ttFactoryLoaderRow>
</ttFactoryLoader>



In a production environment (no unit testing), the following entries should be uised in the factory.xml file:

Code Block
languagexml
<?xml version="1.0"?>
<ttFactoryLoader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ttFactoryLoaderRow>
    <FactoryType>Consultingwerk.OERA.IBufferDataSource</FactoryType>
    <FactoryAlias></FactoryAlias>
    <InstanceType>Consultingwerk.OERA.BufferDataSource</InstanceType>
  </ttFactoryLoaderRow>
</ttFactoryLoader>



The factory.xml files can be loaded via the JSON configuration file ( https://documentation.consultingwerkcloud.com/display/SCL/JSON+Configuration+File+Format ).

The MockBufferDataSource instance requires an instance of the Consultingwerk.SmartUnit.OERA.MockBufferDataSource.IMockBufferDataSourceProvider to return the Data-Source buffers from eiter temp-tables or database tables (one or multiple per IBufferDataSource). Through temp-table buffer handles, it's possible to mock the DataAccess using XML files:

Code Block
languagec#
CLASS Test.DataSourceDelegate.OrderMockBufferDataSource
    IMPLEMENTS IMockBufferDataSourceProvider:

    DEFINE TEMP-TABLE ttOrder NO-UNDO LIKE Order .

    DEFINE BUFFER Order FOR ttOrder .

    /**
     * Purpose: Constructor for the BufferDataSource class
     * Notes:
     */
    CONSTRUCTOR PUBLIC OrderMockBufferDataSource ():

        TEMP-TABLE ttOrder:READ-XML ("file", "Test/DataSourceDelegate/ttOrder.xml", "EMPTY", ?, ?) .

    END CONSTRUCTOR .

    METHOD PUBLIC HANDLE InitializeBuffer (poBufferSpec AS IBufferSpec):

        IF poBufferSpec:TableName = "Order" THEN
            RETURN BUFFER Order:HANDLE .
        ELSE
            RETURN ? .

    END METHOD.

END CLASS.

...

We've implemented the ability to load custom service.xml files through a .scenario file ( https://documentation.consultingwerkcloud.com/display/SCL/Scenario+based+Unit+Tests+for+Business+Entity+FetchData+%28read%29+operations ). Using the LoadServices property (JSON Array) developers can specify multiple service.xml files defining services (or mock services) used while performing the scenario based unit test.

Those services will be loaded into a separate service container only valid for the execution of the scenario based unit test.

Code Block
languagec#
{
  "SerializedType": "Consultingwerk.SmartUnit.OERA.RetrieveDataScenario.Scenario",
  "EntityName": "Consultingwerk.OeraTests.SCL2477.BinBusinessEntity",
  "EntityTables": "eBin",
  "QueryStrings": [
    "FOR EACH eBin WHERE eBin.Itemnum = 42 "
  ],
  "BatchSize": 100,
  "StopAfter": 5,
  "LoadServices": [
    "Consultingwerk/OeraTests/SCL2477/services1.xml", 
    "Consultingwerk/OeraTests/SCL2477/services2.xml"
  ]
}

...

The Business Entity Tester now supports the testing of Named Queries. Named queries will be entered in the Business Entity Tester filter dialog as JSON objects:

Code Block
languagec#
{ "NamedQuery": "QuickSearch", "parameter": [{"q": "Cologne}] }

...