CSIT: Integration tests for CPS Core
+ also fixes issue with fragment_id sequence not reflecting data loaded
Issue-ID: CPS-261
Change-Id: If590d6a0859a1acc9005dd2da952b7dd93a23059
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
diff --git a/csit/data/test-tree.json b/csit/data/test-tree.json
new file mode 100644
index 0000000..bc9cbd7
--- /dev/null
+++ b/csit/data/test-tree.json
@@ -0,0 +1,28 @@
+{
+ "test-tree": {
+ "branch": [
+ {
+ "name": "Left",
+ "nest": {
+ "name": "Small",
+ "birds": [
+ "Sparrow",
+ "Robin",
+ "Finch"
+ ]
+ }
+ },
+ {
+ "name": "Right",
+ "nest": {
+ "name": "Big",
+ "birds": [
+ "Owl",
+ "Raven",
+ "Crow"
+ ]
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/csit/data/test-tree.yang b/csit/data/test-tree.yang
new file mode 100644
index 0000000..faba8a1
--- /dev/null
+++ b/csit/data/test-tree.yang
@@ -0,0 +1,24 @@
+module test-tree {
+ yang-version 1.1;
+
+ namespace "org:onap:cps:test:test-tree";
+ prefix tree;
+ revision "2020-02-02";
+
+ container test-tree {
+ list branch {
+ key "name";
+ leaf name {
+ type string;
+ }
+ container nest {
+ leaf name {
+ type string;
+ }
+ leaf-list birds {
+ type string;
+ }
+ }
+ }
+ }
+}
diff --git a/csit/data/yang-resources.zip b/csit/data/yang-resources.zip
new file mode 100644
index 0000000..8e58086
--- /dev/null
+++ b/csit/data/yang-resources.zip
Binary files differ
diff --git a/csit/plans/default/setup.sh b/csit/plans/default/setup.sh
index e7e8f4b..4d5d1c8 100755
--- a/csit/plans/default/setup.sh
+++ b/csit/plans/default/setup.sh
@@ -18,6 +18,8 @@
# Modifications copyright (c) 2020-2021 Samsung Electronics Co., Ltd.
# Modifications Copyright (C) 2021 Pantheon.tech
#
+# Branched from ccsdk/distribution to this repository Feb 23, 2021
+#
# Copy docker-compose.yml and application.yml to archives
mkdir -p $WORKSPACE/archives/docker-compose
@@ -31,18 +33,22 @@
# Use latest image version
export VERSION=latest
+# download docker-compose of a required version (1.25.0 supports configuration of version 3.7)
+curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > docker-compose
+chmod +x docker-compose
+
# start CPS and PostgreSQL containers with docker compose
-docker-compose up -d
+./docker-compose up -d
# Validate CPS service initialization completed via periodic log checking for line like below:
# org.onap.cps.Application ... Started Application in X.XXX seconds
TIME_OUT=300
-INTERVAL=10
+INTERVAL=5
TIME=0
while [ "$TIME" -le "$TIME_OUT" ]; do
- LOG_FOUND=$( docker-compose logs --tail="all" | grep "org.onap.cps.Application" | egrep -c "Started Application in" )
+ LOG_FOUND=$( ./docker-compose logs --tail="all" | grep "org.onap.cps.Application" | egrep -c "Started Application in" )
if [ "$LOG_FOUND" -gt 0 ]; then
echo "CPS Service started"
@@ -59,9 +65,9 @@
exit 1;
fi
-# TODO localhost works on a local environment, check if it's ok on jenkins
+# The CPS host according to docker-compose.yml
CPS_HOST="http://localhost:8883"
# Pass variables required for Robot test suites in ROBOT_VARIABLES
-ROBOT_VARIABLES="-v SCRIPTS:$SCRIPTS -v CPS_HOST:$CPS_HOST"
+ROBOT_VARIABLES="-v CPS_HOST:$CPS_HOST -v DATADIR:$WORKSPACE/data"
diff --git a/csit/plans/default/teardown.sh b/csit/plans/default/teardown.sh
index 9028025..f9368f9 100755
--- a/csit/plans/default/teardown.sh
+++ b/csit/plans/default/teardown.sh
@@ -18,6 +18,8 @@
# Modifications copyright (c) 2020 Samsung Electronics Co., Ltd.
# Modifications Copyright (C) 2021 Pantheon.tech
#
+# Branched from ccsdk/distribution to this repository Feb 23, 2021
+#
cd $WORKSPACE/archives/docker-compose
-docker-compose down -v
+./docker-compose down -v
diff --git a/csit/plans/default/testplan.txt b/csit/plans/default/testplan.txt
index edcad0d..e4e8759 100644
--- a/csit/plans/default/testplan.txt
+++ b/csit/plans/default/testplan.txt
@@ -1,4 +1,6 @@
# Test suites are relative paths under csit/tests/.
# Place the suites in run order.
actuator
+cps-admin
+cps-data
diff --git a/csit/prepare-csit.sh b/csit/prepare-csit.sh
index 05d99a7..d46b17a 100755
--- a/csit/prepare-csit.sh
+++ b/csit/prepare-csit.sh
@@ -1,6 +1,7 @@
#!/bin/bash -x
#
# Copyright 2019-2021 © Samsung Electronics Co., Ltd.
+# Modifications Copyright (C) 2021 Pantheon.tech
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,8 +17,7 @@
#
# This script installs common libraries required by CSIT tests
#
-
-# Branched from integration/csit to this repository 18.2.2021
+# Branched from ccsdk/distribution to this repository Feb 23, 2021
#
if [ -z "$WORKSPACE" ]; then
@@ -43,10 +43,5 @@
source /tmp/ci-management/jjb/integration/include-raw-integration-install-robotframework.sh
fi
-# install eteutils
-mkdir -p ${ROBOT_VENV}/src/onap
-rm -rf ${ROBOT_VENV}/src/onap/testsuite
-#pip install --upgrade --extra-index-url="https://nexus3.onap.org/repository/PyPi.staging/simple" 'robotframework-onap==0.5.1.*' --pre
-
pip freeze
diff --git a/csit/run-csit.sh b/csit/run-csit.sh
index e23e84a..9220ef9 100755
--- a/csit/run-csit.sh
+++ b/csit/run-csit.sh
@@ -18,8 +18,7 @@
# $1 project/functionality
# $2 robot options
-# Branched from integration/csit to this repository 18.2.2021
-#
+# Branched from ccsdk/distribution to this repository Feb 23, 2021
#
# functions
diff --git a/csit/run-project-csit.sh b/csit/run-project-csit.sh
index 1df8267..a231c5e 100755
--- a/csit/run-project-csit.sh
+++ b/csit/run-project-csit.sh
@@ -1,6 +1,7 @@
#!/bin/bash -x
#
# Copyright 2020-2021 © Samsung Electronics Co., Ltd.
+# Modifications Copyright (C) 2021 Pantheon.tech
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# Modifications Copyright (C) 2021 Pantheon.tech
+# Branched from ccsdk/distribution to this repository Feb 23, 2021
#
# $1 test options (passed on to run-csit.sh as such)
diff --git a/csit/scripts/actuator/check_endpoint.sh b/csit/scripts/actuator/check_endpoint.sh
deleted file mode 100755
index 7a8cac7..0000000
--- a/csit/scripts/actuator/check_endpoint.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/bash
-#
-# ============LICENSE_START=======================================================
-# Copyright (C) 2021 Pantheon.tech
-# ================================================================================
-# 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
-#
-# http://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.
-#
-# SPDX-License-Identifier: Apache-2.0
-# ============LICENSE_END=========================================================
-#
-
-# $1 is endpoint for GET request
-
-echo "Testing CPS actuator endpoint $1"
-
-response=$(curl -o /dev/null -s -w "%{http_code}\n" -H "Accept: application/json" -H "Content-Type: application/json" -X GET $1)
-
-if [ "$response" == "200" ]; then
- echo "CPS Actuator endpoint check successful."
- exit 0;
-fi
-
-echo "CPS Actuator endpoint check failed with response code ${response}."
-exit 1
diff --git a/csit/tests/actuator/__init__.robot b/csit/tests/actuator/__init__.robot
deleted file mode 100644
index 714f3c3..0000000
--- a/csit/tests/actuator/__init__.robot
+++ /dev/null
@@ -1,2 +0,0 @@
-*** Settings ***
-Documentation CPS - Actuator endpoints
diff --git a/csit/tests/actuator/actuator.robot b/csit/tests/actuator/actuator.robot
index 59c7607..1253dff 100644
--- a/csit/tests/actuator/actuator.robot
+++ b/csit/tests/actuator/actuator.robot
@@ -1,18 +1,19 @@
*** Settings ***
-Library OperatingSystem
-Library Process
+Documentation CPS - Actuator endpoints
+
+Library Collections
+Library RequestsLibrary
+
+Suite Setup Create Session CPS_HOST ${CPS_HOST}
*** Variables ***
-${check} ${SCRIPTS}/actuator/check_endpoint.sh
*** Test Cases ***
-Liveness Probe for CPS
- [Documentation] Liveness Probe
- ${result}= Run Process bash ${check} ${CPS_HOST}/manage/health/liveness >> actuator-test.log shell=yes
- Should Be Equal As Integers ${result.rc} 0
+Test Liveness Probe Endpoint
+ ${response}= GET On Session CPS_HOST /manage/health/liveness expected_status=200
+ Should Be Equal As Strings ${response.json()['status']} UP
-Readiness Probe for CPS
- [Documentation] Readiness Probe
- ${result}= Run Process bash ${check} ${CPS_HOST}/manage/health/readiness >> actuator-test.log shell=yes
- Should Be Equal As Integers ${result.rc} 0
+Test Readiness Probe Endpoint
+ ${response}= GET On Session CPS_HOST /manage/health/readiness expected_status=200
+ Should Be Equal As Strings ${response.json()['status']} UP
\ No newline at end of file
diff --git a/csit/tests/cps-admin/cps-admin.robot b/csit/tests/cps-admin/cps-admin.robot
new file mode 100644
index 0000000..446a59b
--- /dev/null
+++ b/csit/tests/cps-admin/cps-admin.robot
@@ -0,0 +1,53 @@
+*** Settings ***
+Documentation CPS Core - Admin REST API
+
+Library Collections
+Library OperatingSystem
+Library RequestsLibrary
+
+Suite Setup Create Session CPS_HOST ${CPS_HOST}
+
+*** Variables ***
+
+${basePath} /cps/api
+${dataspaceName} CSIT-Dataspace
+${schemaSetName} CSIT-SchemaSet
+${anchorName} CSIT-Anchor
+
+*** Test Cases ***
+Create Dataspace
+ ${uri}= Set Variable ${basePath}/v1/dataspaces
+ ${params}= Create Dictionary dataspace-name=${dataspaceName}
+ ${response}= POST On Session CPS_HOST ${uri} params=${params}
+ Should Be Equal As Strings ${response.status_code} 201
+
+Create Schema Set from YANG file
+ ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/schema-sets
+ ${params}= Create Dictionary schema-set-name=${schemaSetName}
+ ${fileData}= Get Binary File ${DATADIR}${/}test-tree.yang
+ ${fileTuple}= Create List test.yang ${fileData} application/zip
+ &{files}= Create Dictionary file=${fileTuple}
+ ${response}= POST On Session CPS_HOST ${uri} files=${files} params=${params}
+ Should Be Equal As Strings ${response.status_code} 201
+
+Create Schema Set from ZIP file
+ ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/schema-sets
+ ${params}= Create Dictionary schema-set-name=ZipTestSchemaSet
+ ${fileData}= Get Binary File ${DATADIR}${/}yang-resources.zip
+ ${fileTuple}= Create List test.zip ${fileData} application/zip
+ &{files}= Create Dictionary file=${fileTuple}
+ ${response}= POST On Session CPS_HOST ${uri} files=${files} params=${params}
+ Should Be Equal As Strings ${response.status_code} 201
+
+Get Schema Set info
+ ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/schema-sets/${schemaSetName}
+ ${response}= Get On Session CPS_HOST ${uri} expected_status=200
+ ${responseJson}= Set Variable ${response.json()}
+ Should Be Equal As Strings ${responseJson['name']} ${schemaSetName}
+ Should Be Equal As Strings ${responseJson['dataspaceName']} ${dataspaceName}
+
+Create Anchor
+ ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/anchors
+ ${params}= Create Dictionary schema-set-name=${schemaSetName} anchor-name=${anchorName}
+ ${response}= POST On Session CPS_HOST ${uri} params=${params}
+ Should Be Equal As Strings ${response.status_code} 201
\ No newline at end of file
diff --git a/csit/tests/cps-data/cps-data.robot b/csit/tests/cps-data/cps-data.robot
new file mode 100644
index 0000000..8b0202b
--- /dev/null
+++ b/csit/tests/cps-data/cps-data.robot
@@ -0,0 +1,31 @@
+*** Settings ***
+Documentation CPS Core - Data REST API
+
+Library Collections
+Library OperatingSystem
+Library RequestsLibrary
+
+Suite Setup Create Session CPS_HOST ${CPS_HOST}
+
+*** Variables ***
+
+${basePath} /cps/api
+${dataspaceName} CSIT-Dataspace
+${anchorName} CSIT-Anchor
+
+*** Test Cases ***
+Create Data Node
+ ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/nodes
+ ${headers} Create Dictionary Content-Type=application/json
+ ${jsonData}= Get Binary File ${DATADIR}${/}test-tree.json
+ ${response}= POST On Session CPS_HOST ${uri} headers=${headers} data=${jsonData}
+ Should Be Equal As Strings ${response.status_code} 201
+
+Get Data Node by XPath
+ ${uri}= Set Variable ${basePath}/v1/dataspaces/${dataspaceName}/anchors/${anchorName}/node
+ ${params}= Create Dictionary xpath=/test-tree/branch[@name='Left']/nest
+ ${response}= Get On Session CPS_HOST ${uri} params=${params} expected_status=200
+ ${responseJson}= Set Variable ${response.json()}
+ Should Be Equal As Strings ${responseJson['name']} Small
+
+