Merge "Fix CSIT for PMSH"
[integration/csit.git] / tests / policy / apex-pdp / apex-pdp-test.robot
1 *** Settings ***
2 Library     Collections
3 Library     RequestsLibrary
4 Library     OperatingSystem
5 Library     json
6
7 *** Test Cases ***
8
9 Healthcheck
10      [Documentation]    Runs Apex PDP Health check
11      ${auth}=    Create List    healthcheck    zb!XztG34
12      Log    Creating session https://${APEX_IP}:6969
13      ${session}=    Create Session      policy  https://${APEX_IP}:6969   auth=${auth}
14      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
15      ${resp}=   Get Request     policy  /policy/apex-pdp/v1/healthcheck     headers=${headers}
16      Log    Received response from policy1 ${resp.text}
17      Should Be Equal As Strings    ${resp.status_code}     200
18      Should Be Equal As Strings    ${resp.json()['code']}  200
19
20 ExecuteApexPolicy
21      Wait Until Keyword Succeeds    2 min    5 sec    CreatePolicy
22      Wait Until Keyword Succeeds    2 min    5 sec    DeployPolicy
23      Wait Until Keyword Succeeds    4 min    10 sec    RunEventOnApexEngine
24
25 *** Keywords ***
26
27 CreatePolicy
28      [Documentation]    Create a new Apex policy
29      ${auth}=    Create List    healthcheck    zb!XztG34
30      ${postjson}=  Get file  ${CURDIR}/data/onap.policies.native.Apex.tosca.json
31      Log    Creating session https://${POLICY_API_IP}:6969
32      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
33      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
34      ${resp}=   Post Request   policy  /policy/api/v1/policytypes/onap.policies.native.Apex/versions/1.0.0/policies  data=${postjson}   headers=${headers}
35      Log    Received response from policy4 ${resp.text}
36      ${postjsonobject}   To Json    ${postjson}
37      Should Be Equal As Strings    ${resp.status_code}     200
38      Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version
39      Dictionary Should Contain Key    ${postjsonobject}    tosca_definitions_version
40
41 DeployPolicy
42      [Documentation]    Deploy the policy in apex-pdp engine
43      ${auth}=    Create List    healthcheck    zb!XztG34
44      ${postjson}=  Get file  ${CURDIR}/data/pdp_update.json
45      Log    Creating session https://${POLICY_PAP_IP}:6969
46      ${session}=    Create Session      policy  https://${POLICY_PAP_IP}:6969   auth=${auth}
47      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
48      ${resp}=   Post Request   policy  /policy/pap/v1/pdps/deployments/batch  data=${postjson}   headers=${headers}
49      Log    Received response from policy5 ${resp.text}
50      ${postjsonobject}   To Json    ${postjson}
51      Should Be Equal As Strings    ${resp.status_code}     202
52
53 RunEventOnApexEngine
54     Create Session   apexSession  http://${APEX_IP}:23324   max_retries=1
55     ${data}=    Get Binary File     ${CURDIR}${/}data${/}event.json
56     &{headers}=  Create Dictionary    Content-Type=application/json    Accept=application/json
57     ${resp}=    Put Request    apexSession    /apex/FirstConsumer/EventIn    data=${data}   headers=${headers}
58     Should Be Equal As Strings    ${resp.status_code}   200