Add Tests for VNF Package Mgmt - Subscribe and Notify
[integration/csit.git] / tests / so / etsi / etsi_vnf_subscription_tests.robot
1 *** Settings ***
2 Library     Collections
3 Library     RequestsLibrary
4 Library     OperatingSystem
5 Library     json
6
7 *** Variables ***
8 ${SLEEP_INTERVAL_SEC}=   5
9 ${MAXIMUM_ATTEMPTS_BEFORE_TIMEOUT}=     48     # Represents the maximum number of attempts that will be made before a timeout. It sleeps for SLEEP_INTERVAL_SEC seconds before retry.
10 ${PACKAGE_MANAGEMENT_BASE_URL}=    /so/vnfm-adapter/v1/vnfpkgm/v1
11 ${BASIC_AUTH}=    Basic dm5mbTpwYXNzd29yZDEk
12 ${ACCESS_TOKEN}=    ""
13 ${SUBSCRIPTION_ID}=    ""
14
15 *** Test Cases ***
16 Subscribe for Notifications
17     Create Session    vnfm_simulator_session    http://${REPO_IP}:9093
18     &{headers1}=    Create Dictionary    Authorization=${BASIC_AUTH}    Content-Type=application/json    Accept=application/json
19     Log To Console    \nGetting Access Token
20     ${response}=    Post On Session    vnfm_simulator_session    url=/oauth/token?grant_type=client_credentials    headers=${headers1}
21     Log To Console    \nResponse:${response}
22     Run Keyword If    '${response.status_code}' == '200'    Log To Console    \nexecuted with expected result
23     Should Be Equal As Strings    '${response.status_code}'    '200'
24     Log To Console    \nResponse Content:\n${response.content}
25     ${json_response}    Evaluate    json.loads(r"""${response.content}""", strict=False)    json
26     Set Global Variable    ${ACCESS_TOKEN}    ${json_response}[access_token]
27     ${data}=    Get Binary File     ${CURDIR}${/}data${/}subscriptionRequest.json
28     &{headers2}=    Create Dictionary    Authorization=Bearer ${ACCESS_TOKEN}    Content-Type=application/json    Accept=application/json
29     Log To Console    \nSubscribing For VNF Package Notifications
30     ${response2}=    Post On Session    vnfm_simulator_session    /vnfpkgm/v1/subscribe    data=${data}    headers=${headers2}
31     Log To Console    \nResponse:\n${response2}
32     Log To Console    \nResponse Content:\n${response2.content}
33     Run Keyword If    '${response2.status_code}' == '200'    Log To Console    \nexecuted with expected result
34     Should Be Equal As Strings    '${response2.status_code}'    '200'
35     ${json_response2}=    Evaluate    json.loads(r"""${response2.content}""", strict=False)    json
36     Dictionary Should Contain Key    ${json_response2}    id
37     Set Global Variable    ${SUBSCRIPTION_ID}    ${json_response2}[id]
38     Log To Console    \nid: ${SUBSCRIPTION_ID}
39     Dictionary Should Contain Key    ${json_response2}    filter
40     ${filter}=    Set Variable    ${json_response2}[filter]
41     Dictionary Should Contain Key    ${filter}    notificationTypes
42     Dictionary Should Contain Key    ${filter}    vnfdId
43     Dictionary Should Contain Key    ${filter}    operationalState
44     Dictionary Should Contain Key    ${json_response2}    callbackUri
45     Dictionary Should Contain Key    ${json_response2}    _links
46     Log To Console    \nexecuted with expected result
47
48 Get Subscriptions
49     Create Session    so_vnfm_adapter_session    http://${REPO_IP}:9092
50     &{headers}=    Create Dictionary    Authorization=${BASIC_AUTH}    Content-Type=application/json    Accept=application/json
51     Log To Console    \nGetting Subscriptions from so-vnfm-adapter
52     ${response}=    Get On Session    so_vnfm_adapter_session    ${PACKAGE_MANAGEMENT_BASE_URL}/subscriptions    headers=${headers}
53     Log To Console    \nResponse:${response}
54     Run Keyword If    '${response.status_code}' == '200'    Log To Console    \nexecuted with expected result
55     Should Be Equal As Strings    '${response.status_code}'    '200'
56     Log To Console    \nResponse Content:\n${response.content}
57     ${json_response}    Evaluate    json.loads(r"""${response.content}""", strict=False)    json
58     ${subscription}=    Set Variable    ${json_response}[0]
59     Dictionary Should Contain Key    ${subscription}    id
60     ${sub_id}=    Set Variable    ${subscription}[id]
61     Should Be Equal As Strings    '${sub_id}'    '${SUBSCRIPTION_ID}'
62     Dictionary Should Contain Key    ${subscription}    filter
63     ${filter}=    Set Variable    ${subscription}[filter]
64     Dictionary Should Contain Key    ${filter}    notificationTypes
65     Dictionary Should Contain Key    ${filter}    vnfdId
66     Dictionary Should Contain Key    ${filter}    operationalState
67     Dictionary Should Contain Key    ${subscription}    callbackUri
68     Log To Console    \nexecuted with expected result
69
70 Get Subscription By Subscription Id
71     Create Session    so_vnfm_adapter_session    http://${REPO_IP}:9092
72     &{headers}=    Create Dictionary    Authorization=${BASIC_AUTH}    Content-Type=application/json    Accept=application/json
73     Log To Console    \nGetting Subscription with id ${SUBSCRIPTION_ID} from so-vnfm-adapter
74     ${response}=    Get On Session    so_vnfm_adapter_session    ${PACKAGE_MANAGEMENT_BASE_URL}/subscriptions/${SUBSCRIPTION_ID}    headers=${headers}
75     Log To Console    \nResponse:${response}
76     Run Keyword If    '${response.status_code}' == '200'    Log To Console    \nexecuted with expected result
77     Should Be Equal As Strings    '${response.status_code}'    '200'
78     Log To Console    \nResponse Content:\n${response.content}
79     ${json_response}    Evaluate    json.loads(r"""${response.content}""", strict=False)    json
80     Dictionary Should Contain Key    ${json_response}    id
81     ${sub_id}=    Set Variable    ${json_response}[id]
82     Should Be Equal As Strings    '${sub_id}'    '${SUBSCRIPTION_ID}'
83     Dictionary Should Contain Key    ${json_response}    filter
84     ${filter}=    Set Variable    ${json_response}[filter]
85     Dictionary Should Contain Key    ${filter}    notificationTypes
86     Dictionary Should Contain Key    ${filter}    vnfdId
87     Dictionary Should Contain Key    ${filter}    operationalState
88     Dictionary Should Contain Key    ${json_response}    callbackUri
89     Log To Console    \nexecuted with expected result