aboutsummaryrefslogtreecommitdiffstats
path: root/components/model-catalog/blueprint-model/uat-blueprints/README.md
blob: 56cb32989c4202623351cbd2d21953455f99916a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# Acceptance Testing Blueprints

## What is BP User Acceptance Tests (UATs)?

UATs aims to fully test the BlueprintsProcessor (BPP) using a blueprint.
The BPP runs in an almost production-like configuration with some minor exceptions:

- It uses an embedded, in-memory, and initially empty H2 database, running in MySQL/MariaDB compatibility mode;
- All external services are mocked.

## How it works?

The UATs are declarative, data-driven tests implemented in YAML 1.1 documents.
This YAML files express:

- Sequence of requests to be sent to the BPP for every process;
- The expected BPP responses;
- For every used external service:
  - The `selector` used internally to instantiate the rest client;
  - A variable set of expected requests and corresponding responses.

The UAT engine will perform the following validations:

- The BPP responses;
- The payloads in the external services requests and it's content type.

## Adding your BP to the suite of UATs

To add a new BP to the UAT suite, all you need to do is:
1. Add your blueprint folder under
CDS project's `components/model-catalog/blueprint-model/uat-blueprints` directory;
2. Create a `Tests/uat.yaml` document under your BP folder.

## `uat.yaml` reference

The structure of an UAT YAML file could be documented using the Protobuf language as follows:

```proto
message Uat {
    message Path {}
    message Json {}

    message Process {
        required string name = 1;
        required Json request = 2;
        required Json expectedResponse = 3;
        optional Json responseNormalizerSpec = 4;
    }

    message Request {
        required string method = 1;
        required Path path = 2;
        optional string contentType = 3 [default = None];
        optional Json body = 4;
    }

    message Response {
        optional int32 status = 1 [default = 200];
        optional Json body = 2;
    }

    message Expectation {
        required Request request = 1;
        required Response response = 2;
    }

    message ExternalService {
        required string selector = 1;
        repeated Expectation expectations = 2;      // min cardinality = 1
    }

    repeated Process processes = 1;                 // min cardinality = 1
    repeated ExternalService externalServices = 2;  // min cardinality = 0
}

```

The optional `responseNormalizerSpec` specifies transformations that may be needed to apply to the response
returned by BPP to get a full JSON representation. For example, it's possible to convert an string field "outer.inner"
into JSON using the following specification:

```yaml
    responseNormalizerSpec:
      outer:
        inner: ?from-json(.outer.inner)

```

The "?" must prefix every expression that is NOT a literal string. The `from-json()` function and
many others are documented [here](https://github.com/schibsted/jslt/blob/0.1.8/functions.md).

### Skeleton of a basic `uat.yaml`

```yaml
%YAML 1.1
---
processes:
  - name: process1
    request:
      commonHeader: &commonHeader
        originatorId: sdnc
        requestId: "123456-1000"
        subRequestId: sub-123456-1000
      actionIdentifiers: &assign-ai
        blueprintName: configuration_over_restconf
        blueprintVersion: "1.0.0"
        actionName: config-assign
        mode: sync
      payload:
        # ...
    expectedResponse:
      commonHeader: *commonHeader
      actionIdentifiers: *assign-ai
      status:
        code: 200
        eventType: EVENT_COMPONENT_EXECUTED
        errorMessage: null
        message: success
      payload:
        # ...
      stepData:
        name: config-assign
        properties:
          resource-assignment-params:
            # ...
          status: success
  - name: process2
    # ...

external-services:
  - selector: odl
    expectations:
      - request:
          method: GET
          path:
        response:
          status: 200  # optional, 200 is the default value
          body: # optional, default is an empty content
            # ...
      - request:
          method: POST
          path:
          content-type: application/json
          body:
            # JSON request body
        response:
          status: 201
```

### Composite URI paths

In case your YAML document contains many URI path definitions, it's recommended to keep the duplications
as low as possible in order to ease the document maintenance, and avoid inconsistencies.

Since YAML doesn't provide a standard mechanism to concatenate strings,
the UAT engine implements an ad-hoc mechanism based on multi-level lists.
Please note that currently this mechanism is only applied to URI paths.

To exemplify how it works, let's take the case of eliminating duplications when defining multiple OpenDaylight URLs.

You might start using the following definitions:
```yaml
   nodeId: &nodeId "new-netconf-device"
   # ...
   - request:
     path: &configUri [restconf/config, &nodeIdentifier [network-topology:network-topology/topology/topology-netconf/node, *nodeId]]
   # ...
   - request:
     path: [restconf/operational, *nodeIdentifier]
   # ...
   - request:
     path: [*configUri, &configletResourcePath yang-ext:mount/mynetconf:netconflist]
```

The UAT engine will expand the above multi-level lists, resulting on the following URI paths:
```yaml
   # ...
   - request:
     path: restconf/config/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device
   # ...
   - request:
     path: restconf/operational/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device
   # ...
   - request:
     path: restconf/config/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device/yang-ext:mount/mynetconf:netconflist
```

## License

Copyright (C) 2019 Nordix Foundation.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.