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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # SPDX-License-Identifier: Apache-2.0
17 # ============LICENSE_END=========================================================
21 Library ConfluentKafkaLibrary
23 Library OperatingSystem
24 Library RequestsLibrary
26 Suite Setup Starting Test
30 ${auth} Basic Y3BzdXNlcjpjcHNyMGNrcyE=
31 ${basePath} /ncmpInventory/v1/ch
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
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}
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}
65 All Messages Are Produced and Consumed
66 [Arguments] ${GROUP_ID}
67 Produce group_id=${PRODUCER_ID} topic=${REQUEST_TOPIC} value=${ncmpInEventJsonGlobal} headers=${headersGlobal}
69 ${result}= Poll group_id=${GROUP_ID} only_value=False
70 ${headers} Set Variable ${result[0].headers()}
71 ${value} Set Variable ${result[0].value()}
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"
79 Dictionaries Should Be Equal ${valueAsDict} ${ncmpOutEventJsonGlobal}
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}
88 [Arguments] ${group_id}
89 Unsubscribe ${group_id}
90 Close Consumer ${group_id}