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