[More Detail] [Collapse All]
Feature: Resolve domains

Domain resolving maps a domain to interface parameter. Resolving
takes place in two phase: first a mapper match is found, and
secondly the mapper rules are used to find the domain for the
parameter.
features/005-domain-resolve/resolver-resolve.feature
- Background:
link

Interface configuration 'cnf/interface_customer.yaml' defines
operation /customer(post). This operation referes to Swagger
definition 'customer'.

Swagger definition 'Customer' defines attributes 'id', and 'name',
and sub document 'Address' with 'street' and 'city' attributes

Environment model in 'cnf/extensions.yaml' calls interface
'/customer(post)', and bind non-deterministically all domain value
combinations to '/customer(post)' parameters.
features/005-domain-resolve/resolver-resolve.feature:11
Given I use a fixture named "fixture-resolver"
And YAML configuration file `cnf/sbuilder.yaml`
#
# 'resolvers' section loads resolvers from file
# 'cnf/resolver_customer.yaml'

resolvers:
      - url: cnf/resolver_customer.yaml
And YAML configuration file `cnf/interface_customer.yaml` in path `paths`
  #
  # Application interface /customer(post) 
  #
  /customer:
    post: 
      operationId: postCustomer
      parameters:
        - name: customer
          in: body
          description: Customers to enter
          required: true
          schema:
              $ref: '#/definitions/Customer'
      responses:
         200:
            description: OK
And YAML configuration file `cnf/interface_customer.yaml` in path `definitions.Customer`
  #
  # Definition 'Customer' with properties 'id', 'name', and
  # 'address'. Property 'address' refers to definition 'Address'
  # (see below).
  #

         properties:
           id:
            type: string
           type:
            type: string
           name:
            type: string
           address:
              $ref: '#/definitions/Address'
And YAML configuration file `cnf/interface_customer.yaml` in path `definitions.Address`
#
# Definition 'Address'

         properties:
           street:
            type: string
           city:
            type: string
And YAML configuration file `cnf/extensions.yaml`
#
# Environment calls interfaces '/customer(post)', and passes input
# all input parameter combinations to the interface.

- step-extension:
       - interface: /customer(post)
- Scenario: Default resolvers with a default rule
link

Default resolver maps all input paramters to domain 'DefDom'.
Default cardinality is 1, an we observer domain values
'd_DefDom_1', and special Nil value for input fields to the
operation.
features/005-domain-resolve/resolver-resolve.feature:101
Given a file named "cnf/resolver_customer.yaml" with:
# default resolver with one regexp rule
-    Name: default-relsover
     Matcher: !ruby/regexp /.*/
     Rules: 
      - Matcher: !ruby/regexp /.*/
        Domain: DefDom
When I generate TLA+ model setup `test`
And I do PLC transformation for setup `test`
And I run TLC for setup `test`
Then I can observe domain assignement:
Field Domain
id "d_DefDom_1"
id Nil
name "d_DefDom_1"
name Nil
type "d_DefDom_1"
type Nil
- Scenario: Default resolvers with two rules.
link
features/005-domain-resolve/resolver-resolve.feature:132
Given a file named "cnf/resolver_customer.yaml" with:
# default resolver with two rules
# - 1:  match string id
# - 2: regexp to catch all
   -    Name: default-relsover
        Matcher: !ruby/regexp /.*/
        Rules: 
          - Matcher: id
            Domain: id_domi
          - Matcher: !ruby/regexp /.*/
            Domain: DefDom
When I generate TLA+ model setup `test`
And I do PLC transformation for setup `test`
And I run TLC for setup `test`
Then I can observe domain assignement:
Field Domain
id "d_id_domi_1"
id Nil
name "d_DefDom_1"
name Nil
type "d_DefDom_1"
type Nil
- Scenario: Use "ref" rule to find named resolver
link

In this scenariol, 'default-resolver' maps 'id' -> 'customer_id',
'name' -> 'customer_name', and 'type' --> 'customer_type'.

Resolver matcher map 'default-resolver' to parameter sets 'Error',
'Address', 'Customer', 'Customers', '/customer(post)',
'/customers(post)', '/customer(get)', '/customers(get)'.
features/005-domain-resolve/resolver-resolve.feature:160
Given a file named "cnf/resolver_customer.yaml" with:
# Define resulver with the name "default-resolver"
# - 1:  match string id
# - 2: regexp to catch all
   - Name: default-resolver
     Rules: 
         - Matcher: id
           Domain: customer_id
         - Matcher: type
           Domain: customer_type
         - Matcher: name
           Domain: customer_name
         - Matcher: !ruby/regexp /.*/
           Domain: DefDom

# Resolver for each data type, rules refer to  "default-resolver"
# customers(post), customer(post), customers(get), customer(get)
# matched using a regexp

   - Matcher: Error
     Rules: 
         - Ref: default-resolver
   - Matcher: Address
     Rules: 
         - Ref: default-resolver
   - Matcher: !ruby/regexp /Customers?/
     Rules: 
         - Ref: default-resolver
   - Matcher: !ruby/regexp /\/customers?\(get|post\)/
     Rules: 
         - Ref: default-resolver
When I generate TLA+ model setup `test`
When I do PLC transformation for setup `test`
And I run TLC for setup `test`
Then I can observe domain assignement:
Field Domain
id "d_customer_id_1"
id Nil
name "d_customer_name_1"
name Nil
type "d_customer_type_1"
type Nil
street "d_DefDom_1"
street Nil
city "d_DefDom_1"
city Nil
- Scenario: Mix "ref" rule with domain rule
link

Previous scenarion used catch-all rule to find domain for
'street', and 'city' fields in 'Address' definition. In this
scenario, we add rules to map these fields.
features/005-domain-resolve/resolver-resolve.feature:222
Given a file named "cnf/resolver_customer.yaml" with:
# Define resulver with the name "default-resolver"
# - 1:  match string id
# - 2: regexp to catch all
   - Name: default-resolver
     Rules: 
         - Matcher: id
           Domain: customer_id
         - Matcher: type
           Domain: customer_type
         - Matcher: name
           Domain: customer_name
         - Matcher: !ruby/regexp /.*/
           Domain: DefDom

# Resolver for each data type, rules refer to  "default-resolver"
# customers(post), customer(post), customers(get), customer(get)
# matched using a regexp.

   - Matcher: Error
     Rules: 
         - Ref: default-resolver
   - Matcher: Address
     Rules: 
           # domain for field 'street' resolved here
         - Matcher: street
           Domain: address_street
           # other fields delegate to 'default-resolver'
         - Ref: default-resolver
   - Matcher: !ruby/regexp /Customers?/
     Rules: 
         - Ref: default-resolver
   - Matcher: !ruby/regexp /\/customers?\(get|post\)/
     Rules: 
         - Ref: default-resolver
When I generate TLA+ model setup `test`
And I do PLC transformation for setup `test`
And I run TLC for setup `test`
Then I can observe domain assignement:
Field Domain
id "d_customer_id_1"
name "d_customer_name_1"
type "d_customer_type_1"
street "d_address_street_1"
city "d_DefDom_1"