Merge "Clean up CSIT Test"
[cps.git] / csit / tests / cps-data / cps-data.robot
1 # ============LICENSE_START=======================================================
2 # Copyright (c) 2021 Pantheon.tech.
3 # Modifications Copyright (C) 2022 Bell Canada.
4 # Modifications Copyright (C) 2022-2023 Nordix Foundation.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
20
21 *** Settings ***
22 Documentation         CPS Core - Data REST API
23
24 Library               Collections
25 Library               OperatingSystem
26 Library               RequestsLibrary
27
28 Suite Setup           Create Session      CPS_URL    http://${CPS_CORE_HOST}:${CPS_CORE_PORT}
29
30 *** Variables ***
31
32 ${auth}                 Basic Y3BzdXNlcjpjcHNyMGNrcyE=
33 ${basePath}             /cps/api
34 ${dataspaceName}        CSIT-Dataspace
35 ${anchorName}           CSIT-Anchor
36
37 *** Test Cases ***
38 Create Data Node
39     ${uri}=             Set Variable        ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/nodes
40     ${headers}          Create Dictionary   Content-Type=application/json   Authorization=${auth}
41     ${jsonData}=        Get Binary File     ${DATADIR_CPS_CORE}${/}test-tree.json
42     ${response}=        POST On Session     CPS_URL   ${uri}   headers=${headers}   data=${jsonData}
43     Should Be Equal As Strings              ${response.status_code}   201
44
45 Patch Data Node
46     ${uri}=             Set Variable        ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/nodes
47     ${params}=          Create Dictionary   xpath=/test-tree/branch[@name='Right']
48     ${headers}          Create Dictionary   Content-Type=application/json   Authorization=${auth}
49     ${jsonData}=        Get Binary File     ${DATADIR_CPS_CORE}${/}testTreePatchExample.json
50     ${response}=        PATCH On Session    CPS_URL   ${uri}  params=${params}   headers=${headers}   data=${jsonData}
51     Should Be Equal As Strings              ${response.status_code}   200
52
53 Get Updated Data Node by XPath
54     ${uri}=             Set Variable        ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/node
55     ${params}=          Create Dictionary   xpath=/test-tree/branch[@name='Right']/nest
56     ${headers}=         Create Dictionary   Authorization=${auth}
57     ${response}=        Get On Session      CPS_URL   ${uri}   params=${params}   headers=${headers}   expected_status=200
58     ${responseJson}=    Set Variable        ${response.json()['tree:nest']}
59     Should Be Equal As Strings              ${responseJson['name']}   Bigger
60     ${length_birds}=    Get Length          ${responseJson['birds']}
61     Should Be Equal As Integers             ${length_birds}   3
62     ${expected_list}=         Create List   Pigeon   Falcon   Eagle
63     FOR      ${item_to_check}     IN      @{expected_list}
64         Should Contain     ${responseJson['birds']}     ${item_to_check}
65     END
66
67 Get Data Node by XPath
68     ${uri}=             Set Variable        ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/node
69     ${params}=          Create Dictionary   xpath=/test-tree/branch[@name='LEFT/left']/nest
70     ${headers}=         Create Dictionary   Authorization=${auth}
71     ${response}=        Get On Session      CPS_URL   ${uri}   params=${params}   headers=${headers}   expected_status=200
72     Should Be Equal As Strings              ${response.json()['tree:nest']['name']}   SMALL/small
73
74