blob: ce2033c1169f07dbedc56dc4cb34ab9edefd7843 [file] [log] [blame]
lukegleesonfa389b52021-07-05 14:59:49 +01001# ============LICENSE_START=======================================================
2# Copyright (c) 2021 Pantheon.tech.
puthuparambil.adityaebfa4072022-02-14 10:56:35 +00003# Modifications Copyright (C) 2022 Bell Canada.
halil.cakalc4a583a2023-04-06 12:03:35 +01004# Modifications Copyright (C) 2022-2023 Nordix Foundation.
lukegleesonfa389b52021-07-05 14:59:49 +01005# ================================================================================
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
Ruslan Kashapovd44fcee2021-02-26 11:42:29 +020021*** Settings ***
22Documentation CPS Core - Data REST API
23
24Library Collections
25Library OperatingSystem
26Library RequestsLibrary
27
tragaitdd6021e2021-10-19 16:46:21 +010028Suite Setup Create Session CPS_URL http://${CPS_CORE_HOST}:${CPS_CORE_PORT}
Ruslan Kashapovd44fcee2021-02-26 11:42:29 +020029
30*** Variables ***
31
Bruno Sakotof05a5032021-03-03 18:27:54 -050032${auth} Basic Y3BzdXNlcjpjcHNyMGNrcyE=
Ruslan Kashapovd44fcee2021-02-26 11:42:29 +020033${basePath} /cps/api
34${dataspaceName} CSIT-Dataspace
35${anchorName} CSIT-Anchor
36
37*** Test Cases ***
38Create Data Node
39 ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/nodes
Bruno Sakotof05a5032021-03-03 18:27:54 -050040 ${headers} Create Dictionary Content-Type=application/json Authorization=${auth}
Ruslan Kashapovd44fcee2021-02-26 11:42:29 +020041 ${jsonData}= Get Binary File ${DATADIR}${/}test-tree.json
puthuparambil.adityab46d1372021-07-09 12:51:10 +010042 ${response}= POST On Session CPS_URL ${uri} headers=${headers} data=${jsonData}
Ruslan Kashapovd44fcee2021-02-26 11:42:29 +020043 Should Be Equal As Strings ${response.status_code} 201
44
halil.cakalc4a583a2023-04-06 12:03:35 +010045Patch 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}${/}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
53Get 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 Should Be Equal As Strings ${responseJson['birds']} ['Falcon', 'Eagle', 'Pigeon']
61
Ruslan Kashapovd44fcee2021-02-26 11:42:29 +020062Get Data Node by XPath
63 ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/node
emaclee5452b5e2022-12-21 09:29:24 +000064 ${params}= Create Dictionary xpath=/test-tree/branch[@name='LEFT/left']/nest
Bruno Sakotof05a5032021-03-03 18:27:54 -050065 ${headers}= Create Dictionary Authorization=${auth}
puthuparambil.adityab46d1372021-07-09 12:51:10 +010066 ${response}= Get On Session CPS_URL ${uri} params=${params} headers=${headers} expected_status=200
ToineSiebelink14e5bf92022-10-27 17:29:04 +010067 ${responseJson}= Set Variable ${response.json()['tree:nest']}
emaclee5452b5e2022-12-21 09:29:24 +000068 Should Be Equal As Strings ${responseJson['name']} SMALL/small
Ruslan Kashapovd44fcee2021-02-26 11:42:29 +020069
70