[More Detail] [Collapse All]
Feature: Extend environment steps

Enviroment actions in sbuilder are given in setup extension
'extend-environment' as a sequence of steps. A step defines an
interface operation and its input parameters.

Parameter bindings (=domain values) of interface operation input
parameters are determined by 

* sbuilder when using 'bindExact=true' in setup step

* TLC model checker when using 'bindExact=false' in setup step
features/040-extend-steps/100-extend-environment.feature
- Background: Configure setups
link

This configuration defines:

- interface operation /customer(post)

- input parameters id,type,name for interface operation /customer(post)

- resolver in 'resolver-example.yaml' to identify domains for the input paramters

- a setup with the name 'setup1' pointing to files 
   -- 'extend-domains.yaml' to configure domain ranges
   -- 'extend-steps.yaml' to define interface operations
       with input parameter binding
features/040-extend-steps/100-extend-environment.feature:16
Given I successfully run `sbuilder.rb init`
# Configure interfaces
And a file named "cnf/sbuilder.yaml" with:
#
#  
interfaces:
    -  className: Sbuilder::ParamSetLoaderSwagger
       file: example_interface.yaml
And a file named "cnf/example_interface.yaml" with:
swagger: "2.0"
info:
  version: 1.0.0
  title: Sbuild demo customer
And YAML configuration file `cnf/example_interface.yaml` in path `paths`

# Interface operation /customer(post) in swagger configuration

  /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/example_interface.yaml` in path `definitions`

# Defition 'Customer' in swagger YAML


 Customer:
         properties:
           id:
            type: string
           type:
            type: string
           name:
            type: string
# ------------------------------------------------------------------
# resolver
Given YAML configuration file `cnf/sbuilder.yaml`
#
# Define domain resolvers in 'cnf/sbuilder.yaml'
#
resolvers:
      - url: cnf/resolver-example.yaml
And a file named "cnf/resolver-example.yaml" with:
# Common domain resolver: maps interface parameter values
# to domain names
#
-    Name: default-resolver
     Matcher: !ruby/regexp /.*/
     Rules: 
          - Matcher: id
            Domain: id_domain
          - Matcher: name
            Domain: name_domain
          - Matcher: type
            Domain: type_domain
          - Matcher: !ruby/regexp /.*/
            Domain: default_domain
And a file named "cnf/extend-domains.yaml" with:
# Extend domains: sets domain cardinality for 'id_domain', 
# set fixed domain values for 'name_domain'
#
- domain-extension:
       - domain: id_domain
         cardinality: 1000
       - domain: name_domain
         values:
             - name1
             - name2
# ------------------------------------------------------------------
# Setup
When YAML configuration file `cnf/sbuilder.yaml`
#
# 'extend-domain' configured below
# 'setup-steps' configures in scenarios 1,2,3,4

setups:
- setupDirectory: setup1
  extensions:
      -  url: cnf/extend-domains.yaml
      -  url: cnf/extend-steps.yaml
- Scenario: Sbuilder determines bindings
link

Use 'bindExact: true' in setup setp.

Validators -property defines an array of validator elements.

A validator: 

- MUST define 'rule' property
- MAY define 'rule_value' property
- MUST define 'action' property
- MAY define 'action_value' property            

The set of domain values for an interface operation input paramer
is determined using 'action' -property, and possibly
'action_value', of the first validator, where 'rule', and possible
'rule_value', matches with the input parameter. An error is
raised, if no validator rule is applicable.

In this scenario,

- step 1: 'customer.name' iterates full domain range, and all
other parameters use fixed domain value 1

- step 2: 'customer.name', 'customer.type' iterate full domain
  range, and all other parameters use fixed domain value 0 (Nil).
features/040-extend-steps/100-extend-environment.feature:155
Given a file named "cnf/extend-steps.yaml" with:
# Setup1:
#
- extend-environment:
       - interface: /customer(post)
         bindExact: true
         validators:
            - rule: path
              rule_value: [customer, name]
              action: all
            - rule: default
              action: domain
              action_value: 1

       - interface: /customer(post)
         bindExact: true
         validators:
            - rule: path
              rule_value: [customer, name]
              action: all
            - rule: path
              rule_value: [customer, type]
              action: all
            - rule: default
              action: domain
              action_value: 0

# - step-extension:
#        - interface: /customer(post)
#          bindExact: true
#          inputs:
#            - input: 
#                customer:
#                    _default: 1
#                    id: 1
#                    name: 2
#            - input: 
#                customer:
#                    _default: 1
#                    id: 0
#                    name: 1
When I successfully run `sbuilder.rb generate setup1`
And I cd to "gen/setup1/tla"
And I successfully run command `java -cp $TLATOOLS pcal.trans model`
And I successfully run command `java -cp $TLATOOLS tlc2.TLC setup`
Then the stdout should contain "Model checking completed. No error has been found."
And I can observe execution trace:
Operation Tick
/customer(post) 0
/customer(post) 1
And I can observe domain assignement:
Field Domain
id "d_id_domain_1"
name "name1"
name "name2"
name Nil
type "d_type_domain_1"
type Nil
- Scenario: Sbuilder reports 'Set cardinality too large'
link

Use 'bindExact: true' in setup setp.

In this scenario, 'customer.id' iterates full domain range, and
all other parameters use fixed domain value.

Sbuilder reports an error 'Set cardinality too large' because, the
cardinality of id -parameter results too large input set for
/customer(post).
features/040-extend-steps/100-extend-environment.feature:247
And a file named "cnf/extend-steps.yaml" with:
# Setup1:
#
- extend-environment:
       - interface: /customer(post)
         bindExact: true
         validators:
            - rule: path
              rule_value: [customer, id]
              action: all
            - rule: default
              action: domain
              action_value: 1
When I run `sbuilder.rb generate setup1`
Then it should fail with regex:
Set cardinality '\d+' too large
- Scenario: Sbuilder reports 'Set cardinality too large'
link

Use 'bindExact: true' in setup setp.

In this scenario, 'customer.id' iterates full domain range, and
all other parameters use fixed domain value.

Sbuilder reports an error 'Set cardinality too large' because, the
cardinality of id -parameter results too large input set for
/customer(post).
features/040-extend-steps/100-extend-environment.feature:283
And a file named "cnf/extend-steps.yaml" with:
# Setup1:
#
- extend-environment:
       - interface: /customer(post)
         bindExact: false
         validators:
            - rule: path
              rule_value: [customer, id]
              action: domain
              action_value: 1
            - rule: default
              action: none
When I successfully run `sbuilder.rb generate setup1`
And I cd to "gen/setup1/tla"
And I successfully run command `java -cp $TLATOOLS pcal.trans model`
And I successfully run command `java -cp $TLATOOLS tlc2.TLC setup`
Then the stdout should contain "Model checking completed. No error has been found."
And I can observe execution trace:
Operation Tick
/customer(post) 0
And I can observe domain assignement:
Field Domain
id "d_id_domain_1"
name Nil
name "name1"
name "name2"
type "d_type_domain_1"
type Nil
- Scenario: Extend step using 'input'
link

Bind exactly one input to '/customer(post)'
features/040-extend-steps/100-extend-environment.feature:331
Given a file named "cnf/extend-steps.yaml" with:
# Setup1:
#
- extend-environment:
       - interface: /customer(post)
         bindExact: true
         input:
            customer:
                 _default: 0
                 name: 1
When I successfully run `sbuilder.rb generate setup1`
And I cd to "gen/setup1/tla"
And I successfully run command `java -cp $TLATOOLS pcal.trans model`
And I successfully run command `java -cp $TLATOOLS tlc2.TLC setup`
Then the stdout should contain "Model checking completed. No error has been found."
And I can observe domain assignement:
Field Domain
id Nil
name "name1"
type Nil
- Scenario: Extend step using 'inputs'
link

Bind exactly one input to '/customer(post)'
features/040-extend-steps/100-extend-environment.feature:362
Given a file named "cnf/extend-steps.yaml" with:
# Setup1:
#
- extend-environment:
       - interface: /customer(post)
         bindExact: true
         inputs: 
           - input:
               customer:
                 _default: 0
                 name: 1
           - input:
               customer:
                 _default: 1
                 name: 1
When I successfully run `sbuilder.rb generate setup1`
And I cd to "gen/setup1/tla"
And I successfully run command `java -cp $TLATOOLS pcal.trans model`
And I successfully run command `java -cp $TLATOOLS tlc2.TLC setup`
Then the stdout should contain "Model checking completed. No error has been found."
And I can observe domain assignement:
Field Domain
id Nil
id "d_id_domain_1"
name "name1"
type "d_type_domain_1"
type Nil