Clean up CSIT Test
[cps.git] / csit / tests / ncmp-passthrough / ncmp-passthrough.robot
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 *** Settings ***
22 Documentation         NCMP
23
24 Library               Collections
25 Library               OperatingSystem
26 Library               RequestsLibrary
27 Library               BuiltIn
28
29 Suite Setup           Create Session      CPS_URL    http://${CPS_CORE_HOST}:${CPS_CORE_PORT}
30
31 *** Variables ***
32
33 ${auth}                 Basic Y3BzdXNlcjpjcHNyMGNrcyE=
34 ${ncmpBasePath}         /ncmp
35 ${netconf}              NETCONF
36
37 *** Test Cases ***
38
39 Get for Passthrough Operational (CF, RO) with fields & topic
40     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-operational?resourceIdentifier=ietf-netconf-monitoring:netconf-state&options=(fields=schemas/schema)&topic=test-topic
41     ${headers}=          Create Dictionary  Authorization=${auth}
42     ${response}=         Get On Session     CPS_URL   ${uri}   headers=${headers}   expected_status=200
43     Should Be Equal As Strings              ${response.status_code}   200
44
45 Get for Passthrough Operational (CF, RO) with fields
46     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-operational?resourceIdentifier=ietf-netconf-monitoring:netconf-state&options=(fields=schemas/schema)
47     ${headers}=          Create Dictionary  Authorization=${auth}
48     ${response}=         Get On Session     CPS_URL   ${uri}   headers=${headers}   expected_status=200
49     ${responseJson}=     Set Variable       ${response.json()}
50     ${schemaCount}=      Get length         ${responseJson['ietf-netconf-monitoring:netconf-state']['schemas']}
51     Should Be True                          ${schemaCount} >0
52     Should Contain                          ${responseJson['ietf-netconf-monitoring:netconf-state']['schemas']['schema'][0]['location']}   ${netconf}
53
54 Create to bookstore using passthrough-running
55     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore
56     ${headers}=          Create Dictionary  Content-Type=application/json   Authorization=${auth}
57     ${jsonData}=         Get Binary File    ${DATADIR_NCMP}${/}bookstoreCreateExample.json
58     ${response}=         POST On Session    CPS_URL   ${uri}   headers=${headers}   data=${jsonData}
59     Should Be Equal As Strings              ${response.status_code}   201
60
61 Verify create to bookstore using passthrough-running
62     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore
63     ${headers}=          Create Dictionary  Authorization=${auth}
64     ${response}=         Get On Session     CPS_URL   ${uri}   headers=${headers}
65     Should Be Equal As Strings              ${response.status_code}   200
66     FOR   ${item}   IN  @{response.json()['stores:bookstore']['categories']}
67         IF   "${item['code']}" == "01"
68             Should Be Equal As Strings              "${item['name']}"  "Sci-Fi"
69             Should Be Equal As Strings              "${item['books']}[0][title]"  "A Sci-Fi book"
70         END
71         IF   "${item['code']}" == "02"
72             Should Be Equal As Strings              "${item['name']}"  "Horror"
73             Should Be Equal As Strings              "${item['books']}[0][title]"  "A Horror book"
74         END
75     END
76
77 Update Bookstore using passthrough-running for Category 01
78     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore/categories=01
79     ${headers}=          Create Dictionary  Content-Type=application/json   Authorization=${auth}
80     ${jsonData}=         Get Binary File    ${DATADIR_NCMP}${/}bookstoreUpdateExample.json
81     ${response}=         PUT On Session     CPS_URL   ${uri}   headers=${headers}   data=${jsonData}
82     Should Be Equal As Strings              ${response.status_code}   200
83
84 Verify update to bookstore using passthrough-running updated category 01
85     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore/categories=01
86     ${headers}=          Create Dictionary  Authorization=${auth}
87     ${response}=         Get On Session     CPS_URL   ${uri}   headers=${headers}
88     Should Be Equal As Strings              ${response.status_code}   200
89     FOR   ${item}   IN  @{response.json()['stores:categories']}
90         IF   "${item['code']}" == "01"
91             Should Be Equal As Strings              "${item['name']}"  "Updated Sci-Fi Category Name"
92         END
93     END
94
95 Verify update to bookstore using passthrough-running did not remove category 02
96     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore
97     ${headers}=          Create Dictionary  Authorization=${auth}
98     ${response}=         Get On Session     CPS_URL   ${uri}   headers=${headers}
99     Should Be Equal As Strings              ${response.status_code}   200
100     ${schemaCount}=      Get length         ${response.json()['stores:bookstore']['categories']}
101     Should Be Equal As Numbers              ${schemaCount}  2
102
103 Delete Bookstore using passthrough-running for Category 01
104     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore/categories=01
105     ${headers}=          Create Dictionary  Content-Type=application/json   Authorization=${auth}
106     ${response}=         DELETE On Session  CPS_URL   ${uri}   headers=${headers}
107     Should Be Equal As Strings              ${response.status_code}   204
108
109 Verify delete to bookstore using passthrough-running removed only category 01
110     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore
111     ${headers}=          Create Dictionary  Authorization=${auth}
112     ${response}=         Get On Session     CPS_URL   ${uri}   headers=${headers}
113     ${responseJson}=     Set Variable       ${response.json()['stores:bookstore']['categories']}
114     Should Be Equal As Strings              ${response.status_code}   200
115     ${schemaCount}=      Get length         ${responseJson}
116     Should Be Equal As Numbers              ${schemaCount}  1
117     FOR   ${item}   IN  @{responseJson}
118         IF   "${item['code']}" == "02"
119             Should Be Equal As Strings              "${item['name']}"  "Horror"
120         END
121     END
122
123 Patch will add new category with new book and add a new book to an existing category
124     ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore
125     ${headers}=          Create Dictionary  Content-Type=application/yang.patch+json   Authorization=${auth}
126     ${jsonData}=         Get Binary File    ${DATADIR_NCMP}${/}bookstorePatchExample.json
127     ${response}=         PATCH On Session   CPS_URL   ${uri}   headers=${headers}   data=${jsonData}
128     Should Be Equal As Strings              ${response.status_code}   200
129     ${verifyUri}=       Set Variable        ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore/categories=100
130     ${verifyHeaders}=    Create Dictionary  Authorization=${auth}
131     ${verifyResponse}=   Get On Session     CPS_URL   ${verifyUri}   headers=${verifyHeaders}
132     Should Be Equal As Strings              ${verifyResponse.status_code}   200
133     FOR   ${item}   IN  @{verifyResponse.json()['stores:categories']}
134         IF   "${item['code']}" == "100"
135             Should Be Equal As Strings              "${item['name']}"  "Category100"
136         END
137     END
138     ${verifyUri}=       Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore/categories=02/books=A%20New%20book%20in%20existing%20category
139     ${verifyResponse}=  Get On Session     CPS_URL   ${verifyUri}   headers=${verifyHeaders}
140     Should Be Equal As Strings             ${verifyResponse.status_code}   200