Adds CSIT tests for Policy API
[integration/csit.git] / tests / policy / api / api-test.robot
1 *** Settings ***
2 Library     Collections
3 Library     RequestsLibrary
4 Library     OperatingSystem
5 Library     json
6
7 *** Test Cases ***
8 Healthcheck
9      [Documentation]    Runs Policy Api Health check
10      ${auth}=    Create List    healthcheck    zb!XztG34 
11      Log    Creating session https://${POLICY_API_IP}:6969
12      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
13      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
14      ${resp}=   Get Request     policy  /policy/api/v1/healthcheck     headers=${headers}
15      Log    Received response from policy ${resp.text}
16      Should Be Equal As Strings    ${resp.status_code}     200
17      Should Be Equal As Strings    ${resp.json()['code']}  200
18
19 Statistics
20      [Documentation]    Runs Policy Api Statistics
21      ${auth}=    Create List    healthcheck    zb!XztG34 
22      Log    Creating session https://${POLICY_API_IP}:6969
23      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
24      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
25      ${resp}=   Get Request     policy  /policy/api/v1/statistics     headers=${headers}
26      Log    Received response from policy ${resp.text}
27      Should Be Equal As Strings    ${resp.status_code}     200
28      Should Be Equal As Strings    ${resp.json()['code']}  200
29
30 RetrievePolicyTypes
31      [Documentation]    Gets Policy Types
32      ${auth}=    Create List    healthcheck    zb!XztG34 
33      Log    Creating session https://${POLICY_API_IP}:6969
34      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
35      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
36      ${resp}=   Get Request     policy  /policy/api/v1/policytypes     headers=${headers}
37      Log    Received response from policy ${resp.text}
38      Should Be Equal As Strings    ${resp.status_code}     200
39      Should Be Equal As Strings    ${resp.json()['version']}  1.0.0
40
41 CreateTCAPolicyType
42      [Documentation]    Create TCA Policy Type
43      ${auth}=    Create List    healthcheck    zb!XztG34 
44      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.cdap.tca.hi.lo.app.json
45      Log    Creating session https://${POLICY_API_IP}:6969
46      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
47      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
48      ${resp}=   Post Request   policy  /policy/api/v1/policytypes  data=${postjson}   headers=${headers}
49      Log    Received response from policy ${resp.text}
50      Should Be Equal As Strings    ${resp.status_code}     200
51      ${postjsonobject}   To Json    ${postjson}
52      Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version 
53      Dictionary Should Contain Key    ${postjsonobject} tosca_definitions_version
54
55 RetrieveMonitoringPolicyTypes
56      [Documentation]    Retrieve Monitoring related Policy Types
57      ${auth}=    Create List    healthcheck    zb!XztG34 
58      Log    Creating session https://${POLICY_API_IP}:6969
59      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
60      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
61      ${resp}=   Get Request   policy  /policy/api/v1/policytypes/onap.policies.Monitoring     headers=${headers}
62      Log    Received response from policy ${resp.text}
63      Should Be Equal As Strings    ${resp.status_code}     200
64      Dictionary Should Contain Key    ${resp.json()['policy_types'][0]}  onap.policies.Monitoring
65
66
67 CreateNewMonitoringPolicy
68      [Documentation]    Create a new Monitoring TCA policy
69      ${auth}=    Create List    healthcheck    zb!XztG34 
70      ${postjson}=  Get file  ${CURDIR}/data/vCPE.policy.monitoring.input.tosca.json
71      Log    Creating session https://${POLICY_API_IP}:6969
72      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
73      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
74      ${resp}=   Post Request   policy  /policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies  data=${postjson}   headers=${headers}
75      Log    Received response from policy ${resp.text}
76      ${postjsonobject}   To Json    ${postjson}
77      Should Be Equal As Strings    ${resp.status_code}     200
78      Dictionary Should Contain Key    ${resp.json()['topology_template']['policies'][0]}  onap.restart.tca
79      Dictionary Should Contain Key      ${postjsonobject['topology_template']['policies'][0]}  onap.restart.tca
80
81 RetrievePoliciesOfType
82      [Documentation]    Retrieve all Policies Created for a specific Policy Type
83      ${auth}=    Create List    healthcheck    zb!XztG34
84      ${expjson}=  Get file  ${CURDIR}/data/vCPE.policy.monitoring.input.tosca.json
85      Log    Creating session https://${POLICY_API_IP}:6969
86      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
87      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
88      ${resp}=   Get Request   policy  /policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies     headers=${headers}
89      Log    Received response from policy ${resp.text}
90      ${expjsonobject}   To Json    ${expjson}
91      Should Be Equal As Strings    ${resp.status_code}     200
92      Dictionary Should Contain Key    ${resp.json()['topology_template']['policies'][0]}  onap.restart.tca
93      Dictionary Should Contain Key      ${expjsonobject['topology_template']['policies'][0]}  onap.restart.tca
94
95 DeleteSpecificPolicy
96      [Documentation]    Delete Policy of a Type
97      ${auth}=    Create List    healthcheck    zb!XztG34
98      Log    Creating session https://${POLICY_API_IP}:6969
99      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
100      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
101      ${resp}=   Delete Request   policy  /policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/1.0.0     headers=${headers}
102      Log    Received response from policy ${resp.text}
103      Should Be Equal As Strings    ${resp.status_code}     200
104      ${resp}=   Delete Request   policy  /policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/1.0.0     headers=${headers}
105      Should Be Equal As Strings    ${resp.status_code}     404