Merge from ecomp 718fd196 - Integration Tests
[vid.git] / vid-automation / src / test / java / org / onap / vid / api / ServiceInstanceMsoApiTest.java
1 package org.onap.vid.api;
2
3 import com.google.common.collect.ImmutableList;
4 import com.google.common.collect.ImmutableMap;
5 import org.apache.commons.text.StringEscapeUtils;
6 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId;
7 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOActivateFabricConfiguration;
8 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOActivateFabricConfigurationErrorResponse;
9 import org.onap.simulator.presetGenerator.presets.mso.PresetMSODeactivateAndCloudDelete;
10 import org.onap.simulator.presetGenerator.presets.mso.PresetMSODeactivateAndCloudDeleteErrorResponse;
11 import org.springframework.http.HttpMethod;
12 import org.springframework.http.HttpStatus;
13 import org.testng.annotations.Test;
14
15 import java.io.IOException;
16 import java.net.URISyntaxException;
17
18 public class ServiceInstanceMsoApiTest extends BaseMsoApiTest{
19
20     //Urls
21     private static final String MSO_ACTIVATE_SERVICE_INSTANCE = "mso/mso_activate_service_instance/f36f5734-e9df-4fbf-9f35-61be13f028a1";
22     public static final String MSO_DEACTIVATE_SERVICE_INSTANCE = "mso/mso_deactivate_service_instance/f36f5734-e9df-4fbf-9f35-61be13f028a1";
23     public static final String MSO_DELETE_SERVICE_INSTANCE = "mso/mso_delete_svc_instance/f36f5734-e9df-4fbf-9f35-61be13f028a1?serviceStatus=active";
24     public static final String MSO_UNASSIGN_SERVICE_INSTANCE = "mso/mso_delete_svc_instance/f36f5734-e9df-4fbf-9f35-61be13f028a1?serviceStatus=created";
25     public static final String MSO_ACTIVATE_FABRIC_CONFIGURATION = "mso/mso_activate_fabric_configuration/f36f5734-e9df-4fbf-9f35-61be13f028a1";
26     public static final String MSO_DEACTIVATE_AND_CLOUD_DELETE = "mso/mso_vfmodule_soft_delete/f36f5734-e9df-4fbf-9f35-61be13f028a1/vnfId/vfModuleId";
27
28     //Request Details
29     private static final String ACTIVATE_SERVICE_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_activate_service_instance.json";
30     private static final String DEACTIVATE_SERVICE_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_deactivate_service_instance.json";
31     private static final String DELETE_AND_UNASSIGN_SERVICE_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_delete_or_unassign_service_instance.json";
32     private static final String ACTIVATE_FABRIC_CONFIGURATION_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_activate_fabric_configuration.json";
33     private static final String DEACTIVATE_AND_CLOUD_DELETE_DATA = "registration_to_simulator/body_jsons/mso_request_deactivate_and_cloud_delete.json";
34
35     //Jsons
36     private static final String ACTIVATE_OK_JSON = "activate_service_instance.json";
37     private static final String ACTIVATE_FAILED_JSON = "activate_service_instance_error.json";
38     public static final String DEACTIVATE_OK_JSON = "deactivate_service_instance.json";
39     private static final String DEACTIVATE_FAILED_JSON = "deactivate_service_instance_error.json";
40     private static final String UNASSIGN_OK_JSON = "unassign_service_instance.json";
41     private static final String DELETE_SERVICE_REQUEST_DETAILS = "delete_service_instance1802.json";
42     private static final String DELETE_OR_UNASSIGN_FAILED_JSON = "delete_or_unassign_service_instance_error.json";
43
44     //Expected Responses
45     private static final String EXPECTED_SUCCESS_MSO_RESPONSE = "{\"requestReferences\": {\"instanceId\": \"f36f5734-e9df-4fbf-9f35-61be13f028a1\", \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"}}";
46     private static final String EXPECTED_ERROR_MSO_RESPONSE = "{\"message\":\"error message\",\"error\":\"222\"}";
47
48
49     @Test
50     public void testActivateServiceInstanceSucceed() throws Exception {
51         String requestBody = TestUtils.convertRequest(objectMapper, ACTIVATE_SERVICE_REQUEST_DETAILS);
52         callMsoWithFineRequest(ACTIVATE_OK_JSON, ImmutableMap.of(), buildUri(MSO_ACTIVATE_SERVICE_INSTANCE), requestBody,
53                 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
54     }
55
56     @Test(dataProvider = "errorCodes")
57     public void testActivateServiceInstanceFailed(int errorCode) throws IOException, URISyntaxException {
58         String requestBody = TestUtils.convertRequest(objectMapper, ACTIVATE_SERVICE_REQUEST_DETAILS);
59         callMsoWithSimulatedErrorResponse(ACTIVATE_FAILED_JSON,
60                 ImmutableMap.of("500", Integer.toString(errorCode),"\"ERROR_PAYLOAD\"", StringEscapeUtils.escapeJson(EXPECTED_ERROR_MSO_RESPONSE)),
61                 buildUri(MSO_ACTIVATE_SERVICE_INSTANCE), requestBody, errorCode, EXPECTED_ERROR_MSO_RESPONSE, HttpMethod.POST);
62
63     }
64
65     @Test
66     public void testUnassignServiceInstanceSucceed() throws Exception {
67         String requestBody = TestUtils.convertRequest(objectMapper, DELETE_AND_UNASSIGN_SERVICE_REQUEST_DETAILS);
68         callMsoWithFineRequest(UNASSIGN_OK_JSON, ImmutableMap.of(), buildUri(MSO_UNASSIGN_SERVICE_INSTANCE), requestBody,
69                 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
70     }
71
72
73     @Test
74     public void testDeleteServiceInstanceSucceed() throws Exception {
75         String requestBody = TestUtils.convertRequest(objectMapper, DELETE_AND_UNASSIGN_SERVICE_REQUEST_DETAILS);
76         callMsoWithFineRequest(UNASSIGN_OK_JSON, ImmutableMap.of(
77                 "/unassign", "",
78                 "POST", "DELETE"), buildUri(MSO_DELETE_SERVICE_INSTANCE), requestBody,
79                 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
80     }
81
82     @Test(dataProvider = "errorCodes")
83     public void testUnassignServiceInstanceFailed(int errorCode) throws IOException {
84         String requestBody = TestUtils.convertRequest(objectMapper, DELETE_AND_UNASSIGN_SERVICE_REQUEST_DETAILS);
85         callMsoWithSimulatedErrorResponse(DELETE_OR_UNASSIGN_FAILED_JSON,
86                 ImmutableMap.of("500", Integer.toString(errorCode),"\"ERROR_PAYLOAD\"", StringEscapeUtils.escapeJson(EXPECTED_ERROR_MSO_RESPONSE)),
87                 buildUri(MSO_UNASSIGN_SERVICE_INSTANCE), requestBody, errorCode, EXPECTED_ERROR_MSO_RESPONSE, HttpMethod.POST);
88
89     }
90
91     @Test(dataProvider = "errorCodes")
92     public void testDeleteServiceInstanceFailed(int errorCode) throws IOException {
93         String requestBody = TestUtils.convertRequest(objectMapper, DELETE_AND_UNASSIGN_SERVICE_REQUEST_DETAILS);
94         callMsoWithSimulatedErrorResponse(DELETE_OR_UNASSIGN_FAILED_JSON,
95                 ImmutableMap.of("/unassign", "",
96                         "POST", "DELETE",
97                         "500", Integer.toString(errorCode),
98                         "\"ERROR_PAYLOAD\"", StringEscapeUtils.escapeJson(EXPECTED_ERROR_MSO_RESPONSE)),
99                 buildUri(MSO_DELETE_SERVICE_INSTANCE), requestBody, errorCode, EXPECTED_ERROR_MSO_RESPONSE, HttpMethod.POST);
100
101     }
102
103     @Test
104     public void testDeactivateServiceInstanceSucceed() throws Exception {
105         String requestBody = TestUtils.convertRequest(objectMapper, DEACTIVATE_SERVICE_REQUEST_DETAILS);
106         callMsoWithFineRequest(DEACTIVATE_OK_JSON, ImmutableMap.of(), buildUri(MSO_DEACTIVATE_SERVICE_INSTANCE), requestBody,
107                 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
108     }
109
110     @Test(dataProvider = "errorCodes")
111     public void testDeactivateServiceInstanceFailed(int errorCode) throws IOException, URISyntaxException {
112         String requestBody = TestUtils.convertRequest(objectMapper, DEACTIVATE_SERVICE_REQUEST_DETAILS);
113         callMsoWithSimulatedErrorResponse(DEACTIVATE_FAILED_JSON,
114                 ImmutableMap.of("500", Integer.toString(errorCode),"\"ERROR_PAYLOAD\"", StringEscapeUtils.escapeJson(EXPECTED_ERROR_MSO_RESPONSE)),
115                 buildUri(MSO_DEACTIVATE_SERVICE_INSTANCE), requestBody, errorCode, EXPECTED_ERROR_MSO_RESPONSE, HttpMethod.POST);
116
117     }
118
119     @Test
120     public void testActivateFabricConfigurationSucceed() throws Exception {
121         String requestBody = TestUtils.convertRequest(objectMapper, ACTIVATE_FABRIC_CONFIGURATION_REQUEST_DETAILS);
122         callMsoWithFineRequest(new PresetMSOActivateFabricConfiguration("f36f5734-e9df-4fbf-9f35-61be13f028a1", "b6dc9806-b094-42f7-9386-a48de8218ce8"), buildUri(MSO_ACTIVATE_FABRIC_CONFIGURATION), requestBody,
123                 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
124     }
125
126     @Test(dataProvider = "errorCodes")
127     public void testActivateFabricConfigurationFailed(int errorCode) throws IOException, URISyntaxException {
128         String requestBody = TestUtils.convertRequest(objectMapper, ACTIVATE_FABRIC_CONFIGURATION_REQUEST_DETAILS);
129         callMsoWithSimulatedErrorResponse(new PresetMSOActivateFabricConfigurationErrorResponse("f36f5734-e9df-4fbf-9f35-61be13f028a1", errorCode),
130                 buildUri(MSO_ACTIVATE_FABRIC_CONFIGURATION), requestBody, errorCode, EXPECTED_ERROR_MSO_RESPONSE, HttpMethod.POST);
131     }
132
133     @Test
134     public void testDeactivateAndCloudDeleteSucceed() throws Exception {
135         String requestBody = TestUtils.convertRequest(objectMapper, DEACTIVATE_AND_CLOUD_DELETE_DATA);
136         callMsoWithFineRequest(ImmutableList.of(
137                     new PresetMSODeactivateAndCloudDelete("f36f5734-e9df-4fbf-9f35-61be13f028a1", "vnfId", "vfModuleId", "b6dc9806-b094-42f7-9386-a48de8218ce8", "irma-aic"),
138                     PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN6_TO_ATT_AIC),
139                 buildUri(MSO_DEACTIVATE_AND_CLOUD_DELETE), requestBody,
140                 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
141     }
142
143     @Test(dataProvider = "errorCodes")
144     public void testDeactivateAndCloudDeleteFailed(int errorCode) throws IOException, URISyntaxException {
145         String requestBody = TestUtils.convertRequest(objectMapper, DEACTIVATE_AND_CLOUD_DELETE_DATA);
146         callMsoWithSimulatedErrorResponse(ImmutableList.of(
147                     new PresetMSODeactivateAndCloudDeleteErrorResponse("f36f5734-e9df-4fbf-9f35-61be13f028a1", "vnfId", "vfModuleId", errorCode, "irma-aic"),
148                     PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN6_TO_ATT_AIC),
149                 buildUri(MSO_DEACTIVATE_AND_CLOUD_DELETE), requestBody, errorCode, EXPECTED_ERROR_MSO_RESPONSE, HttpMethod.POST);
150     }
151 }