Align JSON DataNode for Get and Post/Put API in CPS
[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 # ================================================================================
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 *** Settings ***
21 Documentation         CPS Core - Data REST API
22
23 Library               Collections
24 Library               OperatingSystem
25 Library               RequestsLibrary
26
27 Suite Setup           Create Session      CPS_URL    http://${CPS_CORE_HOST}:${CPS_CORE_PORT}
28
29 *** Variables ***
30
31 ${auth}                 Basic Y3BzdXNlcjpjcHNyMGNrcyE=
32 ${basePath}             /cps/api
33 ${dataspaceName}        CSIT-Dataspace
34 ${anchorName}           CSIT-Anchor
35
36 *** Test Cases ***
37 Create Data Node
38     ${uri}=             Set Variable        ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/nodes
39     ${headers}          Create Dictionary   Content-Type=application/json   Authorization=${auth}
40     ${jsonData}=        Get Binary File     ${DATADIR}${/}test-tree.json
41     ${response}=        POST On Session     CPS_URL   ${uri}   headers=${headers}   data=${jsonData}
42     Should Be Equal As Strings              ${response.status_code}   201
43
44 Get Data Node by XPath
45     ${uri}=             Set Variable        ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/node
46     ${params}=          Create Dictionary   xpath=/test-tree/branch[@name='Left']/nest
47     ${headers}=         Create Dictionary   Authorization=${auth}
48     ${response}=        Get On Session      CPS_URL   ${uri}   params=${params}   headers=${headers}   expected_status=200
49     ${responseJson}=    Set Variable        ${response.json()['nest']}
50     Should Be Equal As Strings              ${responseJson['name']}   Small
51
52