aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/test/java/org/onap/vid/api/pProbeMsoApiTest.java
blob: 534dc6934255be34aef175e07b5229655f384a6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package org.onap.vid.api;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.text.StringEscapeUtils;
import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId;
import org.onap.simulator.presetGenerator.presets.mso.configuration.PresetMSOActOnConfiguration;
import org.onap.simulator.presetGenerator.presets.mso.configuration.PresetMSOCreateConfiguration;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.testng.annotations.Test;

import java.io.IOException;
import java.net.URISyntaxException;

public class pProbeMsoApiTest extends BaseMsoApiTest{

    //Urls
    private static final String MSO_REMOVE_RELATIONSHIP = "/mso/mso_remove_relationship/f36f5734-e9df-4fbf-9f35-61be13f028a1";
    private static final String MSO_ADD_RELATIONSHIP = "/mso/mso_add_relationship/f36f5734-e9df-4fbf-9f35-61be13f028a1";
    public static final String MSO_CREATE_CONFIGURATION = "mso/mso_create_configuration_instance/f36f5734-e9df-4fbf-9f35-61be13f028a1/configurations/";
    public static final String MSO_ACTIVATE_CONFIGURATION = "mso/mso_activate_configuration/c187e9fe-40c3-4862-b73e-84ff056205f6/configurations/9533-config-LB1113";



    //Request Details
    private static final String ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_dissociate_pnf_from_service.json";

    //Request Details
    private static final String CREATE_CONFIGURATION_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_create_configuration.json";
    private static final String ACTIVATE_CONFIGURATION_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_activate_configuration.json";
    //Jsons
    private static final String DISSOCIATE_OK_JSON = "dissociate_pnf_from_service_instance.json";
    private static final String DISSOCIATE_FAILED_JSON = "dissociate_pnf_from_service_instance_error.json";
    private static final String ASSOCIATE_OK_JSON = "mso_add_relationships.json";
    private static final String ASSOCIATE_FAILED_JSON = "mso_add_relationships_error.json";

    //Expected Responses
    private static final String EXPECTED_SUCCESS_MSO_RESPONSE = "{\"requestReferences\": {\"instanceId\": \"f36f5734-e9df-4fbf-9f35-61be13f028a1\", \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"}}";
    private static final String EXPECTED_ERROR_MSO_RESPONSE = "{\"error\":\"222\",\"message\":\"error message\"}";


    @Test
    public void testRemovePnfFromServiceInstanceSucceed() throws Exception {
        String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
        callMsoWithFineRequest(DISSOCIATE_OK_JSON, ImmutableMap.of(), buildUri(MSO_REMOVE_RELATIONSHIP), requestBody,
                HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
    }

    @Test
    public void testRemovePnfFromServiceInstanceFailed() throws Exception {
        String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
        callMsoWithSimulatedErrorResponse(DISSOCIATE_FAILED_JSON, ImmutableMap.of(), buildUri(MSO_REMOVE_RELATIONSHIP), requestBody,
                HttpStatus.NOT_FOUND.value(), "", HttpMethod.POST);
    }


    @Test
    public void testAddPnf2ServiceInstanceSucceed() throws Exception {
        String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
        callMsoWithFineRequest(ASSOCIATE_OK_JSON, ImmutableMap.of(), buildUri(MSO_ADD_RELATIONSHIP), requestBody,
                HttpStatus.ACCEPTED.value(),EXPECTED_SUCCESS_MSO_RESPONSE , HttpMethod.POST);
    }

    @Test(dataProvider = "errorCodes")
    public void testAddPnf2ServiceInstanceError(int errorCode) throws IOException, URISyntaxException {
        String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
        callMsoWithSimulatedErrorResponse(ASSOCIATE_FAILED_JSON,
                ImmutableMap.of("500", Integer.toString(errorCode),"\"ERROR_PAYLOAD\"", StringEscapeUtils.escapeJson(EXPECTED_ERROR_MSO_RESPONSE)),
                buildUri(MSO_ADD_RELATIONSHIP), requestBody,errorCode,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);

    }

    @Test
    public void testCreateConfigurationSucceed() throws Exception {
        String requestBody = TestUtils.convertRequest(objectMapper, CREATE_CONFIGURATION_REQUEST_DETAILS);
        callMsoWithFineRequest(ImmutableList.of(
                new PresetMSOCreateConfiguration("f36f5734-e9df-4fbf-9f35-61be13f028a1"),
                PresetAAIGetCloudOwnersByCloudRegionId.PRESET_AAIAIC25_TO_ATT_AIC
                ),
                buildUri(MSO_CREATE_CONFIGURATION), requestBody,
                HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
    }

    @Test
    public void testActivateConfigurationSucceed() throws Exception {
        String requestBody = TestUtils.convertRequest(objectMapper, ACTIVATE_CONFIGURATION_REQUEST_DETAILS);
        callMsoWithFineRequest(ImmutableList.of(
                new PresetMSOActOnConfiguration("activate", "b6dc9806-b094-42f7-9386-a48de8218ce8", "f36f5734-e9df-4fbf-9f35-61be13f028a1"),
                PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MDT1_TO_ATT_NC
                ),
                buildUri(MSO_ACTIVATE_CONFIGURATION),
                requestBody, HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
    }

    @Test(dataProvider = "errorCodes")
    public void testCreateConfigurationError(int errorCode) throws IOException, URISyntaxException {
        String requestBody = TestUtils.convertRequest(objectMapper, CREATE_CONFIGURATION_REQUEST_DETAILS);
        callMsoWithSimulatedErrorResponse(ImmutableList.of(
                new PresetMSOCreateConfiguration("f36f5734-e9df-4fbf-9f35-61be13f028a1", errorCode, EXPECTED_ERROR_MSO_RESPONSE),
                PresetAAIGetCloudOwnersByCloudRegionId.PRESET_AAIAIC25_TO_ATT_AIC),
                buildUri(MSO_CREATE_CONFIGURATION), requestBody,errorCode,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);

    }

    @Test
    public void testCreateConfigurationFail() throws Exception {
        String requestBody = "498/*ht5ru7 mjhnb";
        callMsoWithSimulatedErrorResponse(ImmutableList.of(
                new PresetMSOCreateConfiguration("f36f5734-e9df-4fbf-9f35-61be13f028a1", 500, EXPECTED_ERROR_MSO_RESPONSE),
                PresetAAIGetCloudOwnersByCloudRegionId.PRESET_AAIAIC25_TO_ATT_AIC),
                buildUri(MSO_CREATE_CONFIGURATION), requestBody,500,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);

    }
}