*** Settings ***
Library           JSONSchemaLibrary    schemas/
Resource          environment/variables.txt    
Library           REST    ${NFVMANO_SCHEMA}://${NFVMANO_HOST}:${NFVMANO_PORT}    ssl_verify=false
Library           OperatingSystem
Library           JSONLibrary
Resource          NFVMANOLogManagementKeywords.robot
Library           MockServerLibrary
Library           Process
Suite Setup       Create Sessions
Suite Teardown    Terminate All Processes    kill=true

*** Test Cases ***
GET all Subscriptions
    [Documentation]    Test ID: 8.3.4.5.1
    ...    Test title: GET all Subscriptions
    ...    Test objective: The objective is to test the retrieval list of active subscriptions list to log management notifications and perform a JSON schema validation of the returned subscriptions data structure
    ...    Pre-conditions:  At least one subscription is available in the NFV-MANO.
    ...    Reference: clause 8.5.7.3.2 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none    
    Get all Subscriptions
    Check HTTP Response Status Code Is    200
    Check HTTP Response Body Json Schema Is    LogmSubscriptions

GET Subscriptions with attribute-based filter
    [Documentation]    Test ID:  8.3.4.5.2
    ...    Test title: GET Subscriptions with attribute-based filter
    ...    Test objective: The objective is to test the retrieval of active subscriptions list to log management notifications using attribute-based filter, perform a JSON schema validation of the collected indicators data structure, and verify that the retrieved information matches the issued attribute-based filters 
    ...    Pre-conditions: At least one subscription is available in the NFV-MANO.
    ...    Reference: clause 8.5.7.3.2 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none
    Get Subscriptions with attribute-based filters
    Check HTTP Response Status Code Is    200
    Check HTTP Response Body Json Schema Is    LogmSubscriptions
    
GET Subscriptions with Paged Response
    [Documentation]    Test ID: 8.3.4.5.3
    ...    Test title: GET Subscriptions with Paged Response
    ...    Test objective: The objective is to query information of active subscriptions list to log management notifications to get Paged Response.
    ...    Pre-conditions:  At least one subscription is available in the NFV-MANO.
    ...    Reference: clause 8.5.7.3.2 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none
    Get all Subscriptions
    Check HTTP Response Status Code Is    200
    Check HTTP Response Header Contains Link

GET Subscriptions - invalid attribute-based filter
    [Documentation]    Test ID: 8.3.4.5.4
    ...    Test title: GET Subscriptions - invalid attribute-based filter
    ...    Test objective: The objective is to test that the retrieval of active subscriptions list to log management notifications fails when using invalid attribute-based filters, and perform the JSON schema validation of the failed operation HTTP response. 
    ...    Pre-conditions: At least one subscription is available in the NFV-MANO.
    ...    Reference: clause 8.5.7.3.2 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none
    Get Subscriptions with invalid attribute-based filters
    Check HTTP Response Status Code Is    400
    Check HTTP Response Body Json Schema Is   ProblemDetails 

GET Subscriptions - Bad Request Response too Big
    [Documentation]    Test ID: 8.3.4.5.5
    ...    Test title: GET Subscriptions - Bad Request Response too Big
    ...    Test objective: The objective is to test that the retrieval of active subscriptions list to log management notifications fails when response is too big, and perform the JSON schema validation of the failed operation HTTP response.
    ...    Pre-conditions: At least one subscription is available in the NFV-MANO.
    ...    Reference: clause 8.5.7.3.2 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none
    Get all Subscriptions
    Check HTTP Response Status Code Is    400
    Check HTTP Response Body Json Schema Is    ProblemDetails

GET Subscriptions - invalid resource endpoint
    [Documentation]    Test ID: 8.3.4.5.6
    ...    Test title: GET Subscriptions - invalid resource endpoint
    ...    Test objective: The objective is to test that the retrieval of active subscriptions list to log management notifications fails when using invalid resource endpoint.
    ...    Pre-conditions: At least one subscription is available in the NFV-MANO.
    ...    Reference: clause 8.5.7.3.2 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none    
    Get all Subscriptions
    Check HTTP Response Status Code Is    404
    Check HTTP Response Body Json Schema Is    ProblemDetails
    
GET Subscription with attribute-based filter "id"
    [Documentation]    Test ID: 8.3.4.5.7
    ...    Test title: GET Subscription with attribute-based filter "id"
    ...    Test objective: The objective is to retrieve the list of active subscriptions with filter "id"
    ...    Pre-conditions: none 
    ...    Reference: clause 8.5.7.3.2 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability:  none 
    ...    Post-Conditions: none 
    Get subscriptions with filter "id"
    Check HTTP Response Status Code Is    200
    Check HTTP Response Body Json Schema Is   LogmSubscription
    Check PostCondition HTTP Response Body Subscription Matches the requested attribute-based filter "id"
    
Get subscriptions with filter "filter.notificationTypes"
    [Documentation]    Test ID: 8.3.4.5.8
    ...    Test title: GET Subscription with attribute-based filter "filter.notificationTypes"
    ...    Test objective: The objective is to retrieve the list of active subscriptions with filter "filter.notificationTypes"
    ...    Pre-conditions: none 
    ...    Reference: clause 8.5.7.3.2 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability:  none 
    ...    Post-Conditions: none 
    Get subscriptions with filter "filter_notificationTypes"
    Check HTTP Response Status Code Is    200
    Check HTTP Response Body Json Schema Is   LogmSubscriptions 
    Check PostCondition HTTP Response Body Subscriptions Matches the requested attribute-based filter "filter_notificationTypes"
    
Create new Subscription
    [Documentation]    Test ID 8.3.4.5.9
    ...    Test title: Create new Subscription
    ...    Test objective: The objective is to test the creation of a new subscription to log management notification and perform a JSON schema and content validation of the returned subscription data structure
    ...    Pre-conditions: none
    ...    Reference: clause 8.5.7.3.1 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: The subscription is successfully set and it matches the issued subscription    
    Send Post Request for Subscription
    Check HTTP Response Status Code Is    201
    Check HTTP Response Body Json Schema Is    LogmSubscription
    Check HTTP Response Body LogmSubscription Attributes Values Match the Issued Subscription
    Check Postcondition Subscription Is Set 

Create request for duplicated Subscription not creating duplicated subscriptions
    [Tags]    no-duplicated-subs
    [Documentation]    Test ID 8.3.4.5.10
    ...    Test title: Create request for duplicated Subscription not creating duplicated subscriptions
    ...    Test objective: The objective is to test the attempt of a creation of a duplicated subscription failed and check that no new subscription is created and a link to the original subscription is returned
    ...    Pre-conditions: At least one subscription is available in the NFV-MANO.
    ...    Reference: clause 8.5.7.3.1 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: The NFV-MANO does not support the creation of duplicated subscriptions
    ...    Post-Conditions: The existing Subscription returned is available in the NFV-MANO 
    Send Post Request for Duplicated Subscription
    Check HTTP Response Status Code Is    303
    Check HTTP Response Body Is Empty
    Check HTTP Response Header Contains    Location
    Check Postcondition Subscription Resource Returned in Location Header Is Available

Create request for duplicated Subscription creating duplicated subscriptions
    [Tags]    duplicated-subs
    [Documentation]    Test ID 8.3.4.5.11
    ...    Test title: Create request for duplicated Subscription creating duplicated subscriptions
    ...    Test objective: The objective is to test the creation of a duplicated subscription and perform a JSON schema and content validation of the returned duplicated subscription data structure
    ...    Pre-conditions: At least one subscription is available in the NFV-MANO.
    ...    Reference: clause 8.5.7.3.1 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: The NFV-MANO supports the creation of duplicated subscriptions
    ...    Post-Conditions: The duplicated subscription is successfully set and it matches the issued subscription
    Send Post Request for Duplicated Subscription
    Check HTTP Response Status Code Is    201
    Check HTTP Response Body Json Schema Is    PmSubscription
    Check HTTP Response Body LogmSubscription Attributes Values Match the Issued Subscription
    Check Postcondition Subscription Is Set 

PUT Subscriptions - Method not implemented
    [Documentation]    Test ID 8.3.4.5.12
    ...    Test title: PUT Subscriptions - Method not implemented
    ...    Test objective: The objective is to test that PUT method is not allowed to modify subscriptions
    ...    Pre-conditions: none
    ...    Reference: clause 8.5.7.3.3 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none
    Send Put Request for Subscriptions
    Check HTTP Response Status Code Is    405 
    
PATCH Subscriptions - Method not implemented
    [Documentation]    Test ID 8.3.4.5.13
    ...    Test title: PATCH Subscriptions - Method not implemented
    ...    Test objective: The objective is to test that PATCH method is not allowed to update subscriptions
    ...    Pre-conditions: none
    ...    Reference: clause 8.5.7.3.4 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none
    Send Patch Request for Subscriptions
    Check HTTP Response Status Code Is    405
    
DELETE Subscriptions - Method not implemented
    [Documentation]    Test ID 8.3.4.5.14
    ...    Test title: DELETE Subscriptions - Method not implemented
    ...    Test objective: The objective is to test that DELETE method is not allowed to delete subscriptions
    ...    Pre-conditions: none
    ...    Reference: clause 8.5.7.3.5 - ETSI GS NFV-SOL 009 [6] V3.3.1
    ...    Config ID: Config_prod_NFV-MANO
    ...    Applicability: none
    ...    Post-Conditions: none  
    Send Delete Request for Subscriptions
    Check HTTP Response Status Code Is    405