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 ${specVersionHeaderValue} Set Variable ${headers[1][1]}
74 ${sourceHeaderValue} Set Variable ${headers[3][1]}
75 ${typeHeaderValue} Set Variable ${headers[4][1]}
76 ${correlationIdHeaderValue} Set Variable ${headers[6][1]}
77 Dictionaries Should Be Equal ${valueAsDict} ${ncmpOutEventJsonGlobal}
78 Should Be Equal As Strings ${specVersionHeaderValue} 1.0
79 Should Be Equal As Strings ${sourceHeaderValue} NCMP
80 Should Be Equal As Strings ${typeHeaderValue} subscriptionCreatedStatus
81 Should Be Equal As Strings ${correlationIdHeaderValue} SCO-9989752cm-subscription-001
84 [Arguments] ${group_id}
85 Unsubscribe ${group_id}
86 Close Consumer ${group_id}