1 package org.onap.vid.api;
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.configuration.PresetMSOActOnConfiguration;
8 import org.onap.simulator.presetGenerator.presets.mso.configuration.PresetMSOCreateConfiguration;
9 import org.springframework.http.HttpMethod;
10 import org.springframework.http.HttpStatus;
11 import org.testng.annotations.Test;
13 import java.io.IOException;
14 import java.net.URISyntaxException;
16 public class pProbeMsoApiTest extends BaseMsoApiTest{
19 private static final String MSO_REMOVE_RELATIONSHIP = "/mso/mso_remove_relationship/f36f5734-e9df-4fbf-9f35-61be13f028a1";
20 private static final String MSO_ADD_RELATIONSHIP = "/mso/mso_add_relationship/f36f5734-e9df-4fbf-9f35-61be13f028a1";
21 public static final String MSO_CREATE_CONFIGURATION = "mso/mso_create_configuration_instance/f36f5734-e9df-4fbf-9f35-61be13f028a1/configurations/";
22 public static final String MSO_ACTIVATE_CONFIGURATION = "mso/mso_activate_configuration/c187e9fe-40c3-4862-b73e-84ff056205f6/configurations/9533-config-LB1113";
27 private static final String ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_dissociate_pnf_from_service.json";
30 private static final String CREATE_CONFIGURATION_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_create_configuration.json";
31 private static final String ACTIVATE_CONFIGURATION_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_activate_configuration.json";
33 private static final String DISSOCIATE_OK_JSON = "dissociate_pnf_from_service_instance.json";
34 private static final String DISSOCIATE_FAILED_JSON = "dissociate_pnf_from_service_instance_error.json";
35 private static final String ASSOCIATE_OK_JSON = "mso_add_relationships.json";
36 private static final String ASSOCIATE_FAILED_JSON = "mso_add_relationships_error.json";
39 private static final String EXPECTED_SUCCESS_MSO_RESPONSE = "{\"requestReferences\": {\"instanceId\": \"f36f5734-e9df-4fbf-9f35-61be13f028a1\", \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"}}";
40 private static final String EXPECTED_ERROR_MSO_RESPONSE = "{\"error\":\"222\",\"message\":\"error message\"}";
44 public void testRemovePnfFromServiceInstanceSucceed() throws Exception {
45 String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
46 callMsoWithFineRequest(DISSOCIATE_OK_JSON, ImmutableMap.of(), buildUri(MSO_REMOVE_RELATIONSHIP), requestBody,
47 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
51 public void testRemovePnfFromServiceInstanceFailed() throws Exception {
52 String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
53 callMsoWithSimulatedErrorResponse(DISSOCIATE_FAILED_JSON, ImmutableMap.of(), buildUri(MSO_REMOVE_RELATIONSHIP), requestBody,
54 HttpStatus.NOT_FOUND.value(), "", HttpMethod.POST);
59 public void testAddPnf2ServiceInstanceSucceed() throws Exception {
60 String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
61 callMsoWithFineRequest(ASSOCIATE_OK_JSON, ImmutableMap.of(), buildUri(MSO_ADD_RELATIONSHIP), requestBody,
62 HttpStatus.ACCEPTED.value(),EXPECTED_SUCCESS_MSO_RESPONSE , HttpMethod.POST);
65 @Test(dataProvider = "errorCodes")
66 public void testAddPnf2ServiceInstanceError(int errorCode) throws IOException, URISyntaxException {
67 String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
68 callMsoWithSimulatedErrorResponse(ASSOCIATE_FAILED_JSON,
69 ImmutableMap.of("500", Integer.toString(errorCode),"\"ERROR_PAYLOAD\"", StringEscapeUtils.escapeJson(EXPECTED_ERROR_MSO_RESPONSE)),
70 buildUri(MSO_ADD_RELATIONSHIP), requestBody,errorCode,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);
75 public void testCreateConfigurationSucceed() throws Exception {
76 String requestBody = TestUtils.convertRequest(objectMapper, CREATE_CONFIGURATION_REQUEST_DETAILS);
77 callMsoWithFineRequest(ImmutableList.of(
78 new PresetMSOCreateConfiguration("f36f5734-e9df-4fbf-9f35-61be13f028a1"),
79 PresetAAIGetCloudOwnersByCloudRegionId.PRESET_AAIAIC25_TO_ATT_AIC
81 buildUri(MSO_CREATE_CONFIGURATION), requestBody,
82 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
86 public void testActivateConfigurationSucceed() throws Exception {
87 String requestBody = TestUtils.convertRequest(objectMapper, ACTIVATE_CONFIGURATION_REQUEST_DETAILS);
88 callMsoWithFineRequest(ImmutableList.of(
89 new PresetMSOActOnConfiguration("activate", "b6dc9806-b094-42f7-9386-a48de8218ce8", "f36f5734-e9df-4fbf-9f35-61be13f028a1"),
90 PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MDT1_TO_ATT_NC
92 buildUri(MSO_ACTIVATE_CONFIGURATION),
93 requestBody, HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
96 @Test(dataProvider = "errorCodes")
97 public void testCreateConfigurationError(int errorCode) throws IOException, URISyntaxException {
98 String requestBody = TestUtils.convertRequest(objectMapper, CREATE_CONFIGURATION_REQUEST_DETAILS);
99 callMsoWithSimulatedErrorResponse(ImmutableList.of(
100 new PresetMSOCreateConfiguration("f36f5734-e9df-4fbf-9f35-61be13f028a1", errorCode, EXPECTED_ERROR_MSO_RESPONSE),
101 PresetAAIGetCloudOwnersByCloudRegionId.PRESET_AAIAIC25_TO_ATT_AIC),
102 buildUri(MSO_CREATE_CONFIGURATION), requestBody,errorCode,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);
107 public void testCreateConfigurationFail() throws Exception {
108 String requestBody = "498/*ht5ru7 mjhnb";
109 callMsoWithSimulatedErrorResponse(ImmutableList.of(
110 new PresetMSOCreateConfiguration("f36f5734-e9df-4fbf-9f35-61be13f028a1", 500, EXPECTED_ERROR_MSO_RESPONSE),
111 PresetAAIGetCloudOwnersByCloudRegionId.PRESET_AAIAIC25_TO_ATT_AIC),
112 buildUri(MSO_CREATE_CONFIGURATION), requestBody,500,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);