halil.cakal | 1340c57 | 2023-04-12 15:19:45 +0100 | [diff] [blame] | 1 | # ============LICENSE_START======================================================= |
| 2 | # Copyright (C) 2023 Nordix Foundation. |
| 3 | # ================================================================================ |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | # SPDX-License-Identifier: Apache-2.0 |
| 17 | # ============LICENSE_END========================================================= |
| 18 | |
| 19 | |
| 20 | *** Settings *** |
| 21 | Library ConfluentKafkaLibrary |
| 22 | Library Collections |
| 23 | Library OperatingSystem |
| 24 | Library RequestsLibrary |
| 25 | |
| 26 | Suite Setup Starting Test |
| 27 | |
| 28 | *** Variables *** |
| 29 | |
| 30 | ${auth} Basic Y3BzdXNlcjpjcHNyMGNrcyE= |
| 31 | ${basePath} /ncmpInventory/v1/ch |
| 32 | |
| 33 | |
| 34 | *** Test Cases *** |
| 35 | Create CM Handle |
| 36 | Create Session CPS_URL http://${CPS_CORE_HOST}:${CPS_CORE_PORT} |
| 37 | ${headers} Create Dictionary Content-Type=application/json Authorization=${auth} |
| 38 | ${jsonData}= Get Binary File ${DATADIR_SUBS_NOTIFICATION}${/}createCmHandleRequestBody.json |
| 39 | ${response}= POST On Session CPS_URL ${basePath} headers=${headers} data=${jsonData} |
| 40 | Should Be Equal As Strings ${response.status_code} 200 |
| 41 | Sleep 5 wait some time to get updated in the db |
| 42 | |
| 43 | Verify Kafka flow for Subscription Creation Notification |
| 44 | ${group_id}= Create Consumer |
| 45 | Subscribe Topic group_id=${group_id} topics=${RESPONSE_TOPIC} |
| 46 | Wait Until Keyword Succeeds 10x 3s All Messages Are Produced and Consumed ${group_id} |
| 47 | [Teardown] Basic Teardown ${group_id} |
| 48 | |
| 49 | *** Keywords *** |
| 50 | Starting Test |
| 51 | Set Suite Variable ${REQUEST_TOPIC} subscription |
| 52 | Set Suite Variable ${RESPONSE_TOPIC} subscription-response |
| 53 | ${ncmpOutEventJson}= Get File ${DATADIR_SUBS_NOTIFICATION}${/}cmSubscriptionNcmpOutEventForCsit.json |
| 54 | ${ncmpOutEventJson}= Evaluate json.loads("""${ncmpOutEventJson}""") json |
| 55 | Set Suite Variable ${ncmpOutEventJsonGlobal} ${ncmpOutEventJson} |
| 56 | ${thread}= Start Consumer Threaded topics=test |
| 57 | Set Suite Variable ${MAIN_THREAD} ${thread} |
| 58 | ${producer_group_id}= Create Producer |
| 59 | Set Suite Variable ${PRODUCER_ID} ${producer_group_id} |
| 60 | ${ncmpInEventJson}= Get File ${DATADIR_SUBS_NOTIFICATION}${/}cmSubscriptionNcmpInEventForCsit.json encoding=UTF-8 |
| 61 | Set Suite Variable ${ncmpInEventJsonGlobal} ${ncmpInEventJson} |
| 62 | ${headers}= Create Dictionary ce_specversion=1.0 ce_id=some-event-id ce_source=some-resource ce_type=subscriptionCreated ce_correlationid=test-cmhandle1 |
| 63 | Set Suite Variable ${headersGlobal} ${headers} |
| 64 | |
| 65 | All Messages Are Produced and Consumed |
| 66 | [Arguments] ${GROUP_ID} |
| 67 | Produce group_id=${PRODUCER_ID} topic=${REQUEST_TOPIC} value=${ncmpInEventJsonGlobal} headers=${headersGlobal} |
| 68 | Sleep 10sec |
| 69 | ${result}= Poll group_id=${GROUP_ID} only_value=False |
| 70 | ${headers} Set Variable ${result[0].headers()} |
| 71 | ${value} Set Variable ${result[0].value()} |
halil.cakal | bf89978 | 2023-09-11 12:34:37 +0100 | [diff] [blame] | 72 | ${valueAsDict}= Evaluate json.loads("""${value}""") json |
| 73 | FOR ${header_key_value_pair} IN @{headers} |
| 74 | Compare Header Values ${header_key_value_pair[0]} ${header_key_value_pair[1]} "ce_specversion" "1.0" |
| 75 | Compare Header Values ${header_key_value_pair[0]} ${header_key_value_pair[1]} "ce_source" "NCMP" |
| 76 | Compare Header Values ${header_key_value_pair[0]} ${header_key_value_pair[1]} "ce_type" "subscriptionCreatedStatus" |
| 77 | Compare Header Values ${header_key_value_pair[0]} ${header_key_value_pair[1]} "ce_correlationid" "SCO-9989752cm-subscription-001" |
| 78 | END |
halil.cakal | 1340c57 | 2023-04-12 15:19:45 +0100 | [diff] [blame] | 79 | Dictionaries Should Be Equal ${valueAsDict} ${ncmpOutEventJsonGlobal} |
halil.cakal | bf89978 | 2023-09-11 12:34:37 +0100 | [diff] [blame] | 80 | |
| 81 | Compare Header Values |
| 82 | [Arguments] ${header_key} ${header_value} ${header_to_check} ${expected_header_value} |
| 83 | IF "${header_key}" == ${header_to_check} |
| 84 | Should Be Equal As Strings "${header_value}" ${expected_header_value} |
| 85 | END |
halil.cakal | 1340c57 | 2023-04-12 15:19:45 +0100 | [diff] [blame] | 86 | |
| 87 | Basic Teardown |
| 88 | [Arguments] ${group_id} |
| 89 | Unsubscribe ${group_id} |
| 90 | Close Consumer ${group_id} |