diff options
Diffstat (limited to 'test/resource-resolution')
16 files changed, 571 insertions, 0 deletions
diff --git a/test/resource-resolution/data-dict/RT-db.json b/test/resource-resolution/data-dict/RT-db.json new file mode 100644 index 0000000..d8e1daf --- /dev/null +++ b/test/resource-resolution/data-dict/RT-db.json @@ -0,0 +1,30 @@ +{ + "name": "RT-db", + "data_type": "string", + "description": "DB request for regression test", + "tags": "datetime", + "updatedBy": "Selfish", + "definition": { + "name": "RT-db", + "tags": "RT-db", + "updated-by": "Selffish", + "property": { + "description": "DB request for regression test", + "type": "string" + }, + "sources": { + "processor-db": { + "type": "source-db", + "properties": { + "endpoint-selector": "db-endpoint", + "type": "SQL", + "query": "select sdnctl.RESOURCE_RESOLUTION.value from sdnctl.RESOURCE_RESOLUTION where value='ok'", + "input-key-mapping": {}, + "output-key-mapping": { + "value": "value" + } + } + } + } + } +} diff --git a/test/resource-resolution/data-dict/RT-kotlin.json b/test/resource-resolution/data-dict/RT-kotlin.json new file mode 100644 index 0000000..c521792 --- /dev/null +++ b/test/resource-resolution/data-dict/RT-kotlin.json @@ -0,0 +1,26 @@ +{ + "name": "kotlin-script", + "data_type": "string", + "description": "Kotlin script used to read properties.", + "tags": "kotlin-script", + "updatedBy": "Self-fish", + "definition": { + "name": "kotlin-script", + "updated-by": "Selffish", + "tags": "properties-capability-source", + "property": { + "description": "Kotlin script used to read properties.", + "type": "string" + }, + "sources": { + "capability": { + "type": "source-capability", + "properties": { + "script-type": "kotlin", + "script-class-reference": "cba.cds.RT.ResolvPropertiesKt", + "instance-dependencies": [] + } + } + } + } +} diff --git a/test/resource-resolution/data-dict/RT-rest-delete.json b/test/resource-resolution/data-dict/RT-rest-delete.json new file mode 100644 index 0000000..c1cef3b --- /dev/null +++ b/test/resource-resolution/data-dict/RT-rest-delete.json @@ -0,0 +1,32 @@ +{ + "name": "RT-rest-delete", + "data_type": "string", + "description": "Rest DELETE request for regression test", + "tags": "RT-rest-delete", + "updatedBy": "Selfish", + "definition": { + "name": "RT-rest-delete", + "tags": "RT-rest-delete", + "updated-by": "Selffish", + "property": { + "description": "Rest DELETE request for regression test", + "type": "string" + }, + "sources": { + "sdnc": { + "type": "source-rest", + "properties": { + "type": "string", + "verb": "DELETE", + "url-path": "/delete", + "endpoint-selector": "rest-endpoint", + "path": "", + "input-key-mapping": {}, + "output-key-mapping": { + "value": "value" + } + } + } + } + } +} diff --git a/test/resource-resolution/data-dict/RT-rest-get-id.json b/test/resource-resolution/data-dict/RT-rest-get-id.json new file mode 100644 index 0000000..b665027 --- /dev/null +++ b/test/resource-resolution/data-dict/RT-rest-get-id.json @@ -0,0 +1,34 @@ +{ + "name": "RT-rest-get-id", + "data_type": "string", + "description": "Rest GET request using input key mapping", + "tags": "RT-rest-get-id", + "updatedBy": "Selfish", + "definition": { + "name": "RT-rest-get-id", + "tags": "RT-rest-get-id", + "updated-by": "Selffish", + "property": { + "description": "Rest GET request using input key mapping", + "type": "string" + }, + "sources": { + "sdnc": { + "type": "source-rest", + "properties": { + "type": "string", + "verb": "GET", + "url-path": "/get/$id/id", + "endpoint-selector": "rest-endpoint", + "path": "", + "input-key-mapping": { + "id": "j_get" + }, + "output-key-mapping": { + "value": "value" + } + } + } + } + } +} diff --git a/test/resource-resolution/data-dict/RT-rest-get.json b/test/resource-resolution/data-dict/RT-rest-get.json new file mode 100644 index 0000000..210ac27 --- /dev/null +++ b/test/resource-resolution/data-dict/RT-rest-get.json @@ -0,0 +1,32 @@ +{ + "name": "RT-rest-get", + "data_type": "string", + "description": "Rest GET request for regression test", + "tags": "RT-rest-get", + "updatedBy": "Selfish", + "definition": { + "name": "RT-rest-get", + "tags": "RT-rest-get", + "updated-by": "Selffish", + "property": { + "description": "Rest GET request for regression test", + "type": "string" + }, + "sources": { + "sdnc": { + "type": "source-rest", + "properties": { + "type": "string", + "verb": "GET", + "url-path": "/get", + "endpoint-selector": "rest-endpoint", + "path": "", + "input-key-mapping": {}, + "output-key-mapping": { + "value": "value" + } + } + } + } + } +} diff --git a/test/resource-resolution/data-dict/RT-rest-patch.json b/test/resource-resolution/data-dict/RT-rest-patch.json new file mode 100644 index 0000000..41f94da --- /dev/null +++ b/test/resource-resolution/data-dict/RT-rest-patch.json @@ -0,0 +1,32 @@ +{ + "name": "RT-rest-patch", + "data_type": "string", + "description": "Rest PATCH request for regression test", + "tags": "RT-rest-patch", + "updatedBy": "Selfish", + "definition": { + "name": "RT-rest-patch", + "tags": "RT-rest-patch", + "updated-by": "Selffish", + "property": { + "description": "Rest PATCH request for regression test", + "type": "string" + }, + "sources": { + "sdnc": { + "type": "source-rest", + "properties": { + "type": "string", + "verb": "PATCH", + "url-path": "/patch", + "endpoint-selector": "rest-endpoint", + "path": "", + "input-key-mapping": {}, + "output-key-mapping": { + "value": "value" + } + } + } + } + } +} diff --git a/test/resource-resolution/data-dict/RT-rest-post.json b/test/resource-resolution/data-dict/RT-rest-post.json new file mode 100644 index 0000000..63721bb --- /dev/null +++ b/test/resource-resolution/data-dict/RT-rest-post.json @@ -0,0 +1,32 @@ +{ + "name": "RT-rest-post", + "data_type": "string", + "description": "Rest POST request for regression test", + "tags": "RT-rest-post", + "updatedBy": "Selfish", + "definition": { + "name": "RT-rest-post", + "tags": "RT-rest-post", + "updated-by": "Selffish", + "property": { + "description": "Rest POST request for regression test", + "type": "string" + }, + "sources": { + "sdnc": { + "type": "source-rest", + "properties": { + "type": "string", + "verb": "POST", + "url-path": "/post", + "endpoint-selector": "rest-endpoint", + "path": "", + "input-key-mapping": {}, + "output-key-mapping": { + "value": "value" + } + } + } + } + } +} diff --git a/test/resource-resolution/data-dict/RT-rest-put.json b/test/resource-resolution/data-dict/RT-rest-put.json new file mode 100644 index 0000000..cf165d3 --- /dev/null +++ b/test/resource-resolution/data-dict/RT-rest-put.json @@ -0,0 +1,32 @@ +{ + "name": "RT-rest-put", + "data_type": "string", + "description": "Rest PUT request for regression test", + "tags": "RT-rest-put", + "updatedBy": "Selfish", + "definition": { + "name": "RT-rest-put", + "tags": "RT-rest-put", + "updated-by": "Selffish", + "property": { + "description": "Rest PUT request for regression test", + "type": "string" + }, + "sources": { + "sdnc": { + "type": "source-rest", + "properties": { + "type": "string", + "verb": "PUT", + "url-path": "/put", + "endpoint-selector": "rest-endpoint", + "path": "", + "input-key-mapping": {}, + "output-key-mapping": { + "value": "value" + } + } + } + } + } +} diff --git a/test/resource-resolution/dummy-request-payload.json b/test/resource-resolution/dummy-request-payload.json new file mode 100644 index 0000000..60b3442 --- /dev/null +++ b/test/resource-resolution/dummy-request-payload.json @@ -0,0 +1,14 @@ +{ + "commonHeader": { + "originatorId": "System", + "requestId": "dummy-request-should-fail", + "subRequestId": "11" + }, + "actionIdentifiers": { + "blueprintName": "RT-resource-resolution", + "blueprintVersion": "1.0.0", + "actionName": "dummy", + "mode": "sync" + }, + "payload": {} +} diff --git a/test/resource-resolution/init-mockserver.sh b/test/resource-resolution/init-mockserver.sh new file mode 100755 index 0000000..8a75a10 --- /dev/null +++ b/test/resource-resolution/init-mockserver.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# +# Copyright (C) 2020 Bell Canada. +# +# 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. +# + +OP=expectation +if [[ $1 == rm ]]; then + OP=clear +fi + +curl -vLk -X PUT "http://$CLUSTER_IP:$MOCKSERVER_NODEPORT/mockserver/$OP" -d @- <<EOF +{ + "httpRequest" : { + "method" : "GET", + "path" : "/mock-$CI_PIPELINE_ID/get" + }, + "httpResponse" : { + "body" : "{\"value\": \"A046E51D-44DC-43AE-BBA2-86FCA86C5265\"}" + } +} +EOF + +curl -vLk -X PUT "http://$CLUSTER_IP:$MOCKSERVER_NODEPORT/mockserver/$OP" -d @- <<EOF +{ + "httpRequest" : { + "method" : "GET", + "path" : "/mock-$CI_PIPELINE_ID/get/A046E51D-44DC-43AE-BBA2-86FCA86C5265/id" + }, + "httpResponse" : { + "body" : "{\"value\": \"74FE67C6-50F5-4557-B717-030D79903908\"}" + } +} +EOF + +curl -vLk -X PUT "http://$CLUSTER_IP:$MOCKSERVER_NODEPORT/mockserver/$OP" -d @- <<EOF +{ + "httpRequest" : { + "method" : "POST", + "path" : "/mock-$CI_PIPELINE_ID/post" + }, + "httpResponse" : { + "body" : "{\"value\": \"post:ok\"}" + } +} +EOF + +curl -vLk -X PUT "http://$CLUSTER_IP:$MOCKSERVER_NODEPORT/mockserver/$OP" -d @- <<EOF +{ + "httpRequest" : { + "method" : "PUT", + "path" : "/mock-$CI_PIPELINE_ID/put" + }, + "httpResponse" : { + "body" : "{\"value\": \"put:ok\"}" + } +} +EOF + +curl -vLk -X PUT "http://$CLUSTER_IP:$MOCKSERVER_NODEPORT/mockserver/$OP" -d @- <<EOF +{ + "httpRequest" : { + "method" : "PATCH", + "path" : "/mock-$CI_PIPELINE_ID/patch" + }, + "httpResponse" : { + "body" : "{\"value\": \"patch:ok\"}" + } +} +EOF + +curl -vLk -X PUT "http://$CLUSTER_IP:$MOCKSERVER_NODEPORT/mockserver/$OP" -d @- <<EOF +{ + "httpRequest" : { + "method" : "DELETE", + "path" : "/mock-$CI_PIPELINE_ID/delete" + }, + "httpResponse" : { + "body" : "{\"value\": \"delete:ok\"}" + } +} +EOF diff --git a/test/resource-resolution/resource-resolution-enrichment-test.sh b/test/resource-resolution/resource-resolution-enrichment-test.sh new file mode 100755 index 0000000..d700fa6 --- /dev/null +++ b/test/resource-resolution/resource-resolution-enrichment-test.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# Copyright (C) 2020 Bell Canada. +# +# 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. +# + +CBA_NAME="resource-resolution" +TEST_NAME="$CBA_NAME-enrichment" +TEST_NUMBER=$RANDOM +RESPONSE_HEADERS_FILE="$RESPONSES_DIRECTORY/$TEST_NAME-$TEST_NUMBER-response-headers" + +. ./$TEST_DIRECTORY/utils.sh + +export MOCK_SRV="http://cds-regression-mockserver/mock-$CI_PIPELINE_ID" +CDS_DB_SVC=${CDS_DB_SVC:-"cds-db"} +export DB_URL="jdbc:mysql://${CDS_DB_SVC}:3306/sdnctl" +apply_env_to_definition $CBA_NAME + +echo "Compressing CBA: $CBA_NAME" +compress_cba $CBA_NAME + +echo "Enriching CBA: $CBA_NAME" +enrich_cba $CBA_NAME $RESPONSE_HEADERS_FILE + +echo 'Assert status 200' +assert_status_code 200 $RESPONSE_HEADERS_FILE diff --git a/test/resource-resolution/resource-resolution-upload-dd.sh b/test/resource-resolution/resource-resolution-upload-dd.sh new file mode 100755 index 0000000..c67ff2e --- /dev/null +++ b/test/resource-resolution/resource-resolution-upload-dd.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# Copyright (C) 2020 Bell Canada. +# +# 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. +# + +TEST_NAME="upload-data-dict" +TEST_NUMBER=$RANDOM +REQUEST_DD_PAYLOAD_DIR="$TEST_DIRECTORY/resource-resolution/data-dict" + +. ./$TEST_DIRECTORY/utils.sh + +# delete useless log file +rm $FAILED_TESTS_LOG + +DD_PAYLOADS=$(ls $REQUEST_DD_PAYLOAD_DIR) +for DD_PAYLOAD in $DD_PAYLOADS +do + echo "Uploading DD : $DD_PAYLOAD" + PAYLOAD_NAME=$(echo "$DD_PAYLOAD" | cut -d '.' -f1) + RESPONSE_HEADERS_FILE="$RESPONSES_DIRECTORY/$TEST_NAME-$PAYLOAD_NAME-$TEST_NUMBER-response-headers" + RESPONSE_PAYLOAD_FILE="$RESPONSES_DIRECTORY/$TEST_NAME-$PAYLOAD_NAME-$TEST_NUMBER-response-payload" + PAYLOAD_FILE="$REQUEST_DD_PAYLOAD_DIR/$DD_PAYLOAD" + FAILED_TESTS_LOG="$FAILED_TESTS_DIRECTORY/$TEST_NAME-$PAYLOAD_NAME-$TEST_NUMBER.log" + + # create log life + touch $FAILED_TESTS_LOG + + upload_dd $PAYLOAD_FILE $RESPONSE_PAYLOAD_FILE $RESPONSE_HEADERS_FILE + + echo 'Assert status 200' + assert_status_code 200 $RESPONSE_HEADERS_FILE +done diff --git a/test/resource-resolution/resource-resolution-upload-test.sh b/test/resource-resolution/resource-resolution-upload-test.sh new file mode 100755 index 0000000..398cc45 --- /dev/null +++ b/test/resource-resolution/resource-resolution-upload-test.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright (C) 2020 Bell Canada. +# +# 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. +# + +CBA_NAME="resource-resolution" +TEST_NAME="$CBA_NAME-upload" +TEST_NUMBER=$RANDOM +RESPONSE_HEADERS_FILE="$RESPONSES_DIRECTORY/$TEST_NAME-$TEST_NUMBER-response-headers" +RESPONSE_PAYLOAD_FILE="$RESPONSES_DIRECTORY/$TEST_NAME-$TEST_NUMBER-response-payload" +REQUEST_PAYLOAD_FILE="$TEST_DIRECTORY/$CBA_NAME/dummy-request-payload.json" + +. ./$TEST_DIRECTORY/utils.sh + +echo "Uploading CBA: $CBA_NAME" +upload_cba $CBA_NAME $RESPONSE_PAYLOAD_FILE $RESPONSE_HEADERS_FILE + +echo 'Assert status 200' +assert_status_code 200 $RESPONSE_HEADERS_FILE + +# This step prevents a race-condition for parallel process requests +# when cba has not yet been written to filesystem +echo 'Send process request to force CDS to load CBA to filesystem' +process_cba $REQUEST_PAYLOAD_FILE '/dev/null' '/dev/null' diff --git a/test/resource-resolution/success/expected-payloads/expected-response.json b/test/resource-resolution/success/expected-payloads/expected-response.json new file mode 100644 index 0000000..51642f7 --- /dev/null +++ b/test/resource-resolution/success/expected-payloads/expected-response.json @@ -0,0 +1,31 @@ +{ + "correlationUUID": null, + "commonHeader": { + "timestamp": "2020-05-07T22:18:06.901Z", + "originatorId": "System", + "requestId": "RR-success-1", + "subRequestId": "1234-12234", + "flags": null + }, + "actionIdentifiers": { + "blueprintName": "RT-resource-resolution", + "blueprintVersion": "1.0.0", + "actionName": "resource-resolution", + "mode": "sync" + }, + "status": { + "code": 200, + "eventType": "EVENT_COMPONENT_EXECUTED", + "timestamp": "2020-05-07T22:18:22.289Z", + "errorMessage": null, + "message": "success" + }, + "payload": { + "resource-resolution-response": { + "meshed-template": { + "helloworld-velocity": "{\n \"default\": \"ok\",\n \"input\": \"ok\",\n \"script\": {\n \"python\": \"ok\",\n \"kotlin\": \"ok\"\n },\n \"db\": \"ok\",\n \"rest\": {\n \"GET\": \"A046E51D-44DC-43AE-BBA2-86FCA86C5265\",\n \"POST\": \"post:ok\",\n \"PUT\": \"put:ok\",\n \"PATCH\": \"patch:ok\",\n \"DELETE\": \"delete:ok\"\n }\n}\n", + "helloworld-jinja": "{\n \"default\": \"ok\",\n \"input\": \"ok\",\n \"script\": {\n \"python\": \"ok\",\n \"kotlin\": {\n \"base\": \"ok\"\n \"from suspend function\": \"ok\"\n }\n },\n \"db\": \"ok\",\n \"rest\": {\n \"GET\": \"A046E51D-44DC-43AE-BBA2-86FCA86C5265\",\n \"GET_ID\": \"74FE67C6-50F5-4557-B717-030D79903908\",\n \"POST\": \"post:ok\",\n \"PUT\": \"put:ok\",\n \"PATCH\": \"patch:ok\",\n \"DELETE\": \"delete:ok\"\n }\n}\n" + } + } + } +} diff --git a/test/resource-resolution/success/request-payloads/request-payload.json b/test/resource-resolution/success/request-payloads/request-payload.json new file mode 100644 index 0000000..cd9f3e6 --- /dev/null +++ b/test/resource-resolution/success/request-payloads/request-payload.json @@ -0,0 +1,26 @@ +{ + "commonHeader": { + "originatorId": "System", + "requestId": "RR-success-1", + "subRequestId": "1234-12234" + }, + "actionIdentifiers": { + "blueprintName": "RT-resource-resolution", + "blueprintVersion": "1.0.0", + "actionName": "resource-resolution", + "mode": "sync" + }, + "payload": { + "resource-resolution-request": { + "template-prefix": [ + "helloworld-velocity", + "helloworld-jinja" + ], + "resolution-key": "regression-test", + "resource-resolution-properties": { + "v_input": "ok", + "j_input": "ok" + } + } + } +} diff --git a/test/resource-resolution/success/test.sh b/test/resource-resolution/success/test.sh new file mode 100755 index 0000000..2454375 --- /dev/null +++ b/test/resource-resolution/success/test.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Copyright (C) 2020 Bell Canada. +# +# 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. +# + +CBA_NAME="resource-resolution" +TEST_NAME="success" +TEST_NUMBER=$RANDOM + +REQUEST_PAYLOAD_DIR="request-payloads" +EXPECTED_PAYLOAD_DIR="expected-payloads" + +mkdir -p "$RESPONSES_DIRECTORY/$CBA_NAME/$TEST_NAME/$TEST_NUMBER/" +RESPONSE_HEADERS_FILE="$RESPONSES_DIRECTORY/$CBA_NAME/$TEST_NAME/$TEST_NUMBER/response-headers" +RESPONSE_PAYLOAD_FILE="$RESPONSES_DIRECTORY/$CBA_NAME/$TEST_NAME/$TEST_NUMBER/response-payload" +REQUEST_PAYLOAD_FILE="$TEST_DIRECTORY/$CBA_NAME/$TEST_NAME/$REQUEST_PAYLOAD_DIR/request-payload.json" +EXPECTED_PAYLOAD_FILE="$TEST_DIRECTORY/$CBA_NAME/$TEST_NAME/$EXPECTED_PAYLOAD_DIR/expected-response.json" + +. ./$TEST_DIRECTORY/utils.sh + +echo "Running test: $CBA_NAME:$TEST_NUMBER:$TEST_NAME" +process_cba $REQUEST_PAYLOAD_FILE $RESPONSE_PAYLOAD_FILE $RESPONSE_HEADERS_FILE + +echo 'Assert statuscode' +assert_status_code 200 $RESPONSE_HEADERS_FILE + +echo 'Assert payload' +assert_cds_response_equals $EXPECTED_PAYLOAD_FILE $RESPONSE_PAYLOAD_FILE |