1 package org.opencomp.vid.api;
3 import com.google.common.collect.ImmutableMap;
4 import org.apache.commons.text.StringEscapeUtils;
5 import org.springframework.http.HttpMethod;
6 import org.springframework.http.HttpStatus;
7 import org.testng.annotations.Test;
9 import java.io.IOException;
10 import java.net.URISyntaxException;
12 public class pProbeMsoApiTest extends BaseMsoApiTest{
15 private static final String MSO_REMOVE_RELATIONSHIP = "/mso/mso_remove_relationship/f36f5734-e9df-4fbf-9f35-61be13f028a1";
16 private static final String MSO_ADD_RELATIONSHIP = "/mso/mso_add_relationship/f36f5734-e9df-4fbf-9f35-61be13f028a1";
17 public static final String MSO_CREATE_CONFIGURATION = "mso/mso_create_configuration_instance/f36f5734-e9df-4fbf-9f35-61be13f028a1/configurations/";
18 public static final String MSO_ACTIVATE_CONFIGURATION = "mso/mso_activate_configuration/f36f5734-e9df-4fbf-9f35-61be13f028a1/configurations/a53c9ca8-8986-44da-9e5e-9e4179e6c78a";
23 private static final String ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_dissociate_pnf_from_service.json";
26 private static final String CREATE_CONFIGURATION_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_create_configuration.json";
29 private static final String DISSOCIATE_OK_JSON = "dissociate_pnf_from_service_instance.json";
30 private static final String DISSOCIATE_FAILED_JSON = "dissociate_pnf_from_service_instance_error.json";
31 private static final String ASSOCIATE_OK_JSON = "mso_add_relationships.json";
32 private static final String ASSOCIATE_FAILED_JSON = "mso_add_relationships_error.json";
33 private static final String CREATE_CONFIGURATION_OK_JSON = "mso_create_configurations.json";
34 private static final String CREATE_CONFIGURATION_FAILED_JSON = "mso_create_configurations_error.json";
35 private static final String ACTIVATE_CONFIGURATION_OK_JSON = "mso_activate_configurations.json";
38 private static final String EXPECTED_SUCCESS_MSO_RESPONSE = "{\"requestReferences\": {\"instanceId\": \"f36f5734-e9df-4fbf-9f35-61be13f028a1\", \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"}}";
39 private static final String EXPECTED_ERROR_MSO_RESPONSE = "{\"error\":\"222\",\"message\":\"error message\"}";
43 public void testRemovePnfFromServiceInstanceSucceed() throws Exception {
44 String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
45 callMsoWithFineRequest(DISSOCIATE_OK_JSON, ImmutableMap.of(), buildUri(MSO_REMOVE_RELATIONSHIP), requestBody,
46 HttpStatus.ACCEPTED.value(), EXPECTED_SUCCESS_MSO_RESPONSE, HttpMethod.POST);
50 public void testRemovePnfFromServiceInstanceFailed() throws Exception {
51 String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
52 callMsoWithSimulatedErrorResponse(DISSOCIATE_FAILED_JSON, ImmutableMap.of(), buildUri(MSO_REMOVE_RELATIONSHIP), requestBody,
53 HttpStatus.NOT_FOUND.value(), "", HttpMethod.POST);
58 public void testAddPnf2ServiceInstanceSucceed() throws Exception {
59 String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
60 callMsoWithFineRequest(ASSOCIATE_OK_JSON, ImmutableMap.of(), buildUri(MSO_ADD_RELATIONSHIP), requestBody,
61 HttpStatus.ACCEPTED.value(),EXPECTED_SUCCESS_MSO_RESPONSE , HttpMethod.POST);
64 @Test(dataProvider = "errorCodes")
65 public void testAddPnf2ServiceInstanceError(int errorCode) throws IOException, URISyntaxException {
66 String requestBody = TestUtils.convertRequest(objectMapper, ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS);
67 callMsoWithSimulatedErrorResponse(ASSOCIATE_FAILED_JSON,
68 ImmutableMap.of("500", Integer.toString(errorCode),"\"ERROR_PAYLOAD\"", StringEscapeUtils.escapeJson(EXPECTED_ERROR_MSO_RESPONSE)),
69 buildUri(MSO_ADD_RELATIONSHIP), requestBody,errorCode,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);
74 public void testCreateConfigurationSucceed() throws Exception {
75 String requestBody = TestUtils.convertRequest(objectMapper, CREATE_CONFIGURATION_REQUEST_DETAILS);
76 callMsoWithFineRequest(CREATE_CONFIGURATION_OK_JSON, ImmutableMap.of(), buildUri(MSO_CREATE_CONFIGURATION),
77 requestBody, HttpStatus.ACCEPTED.value(),EXPECTED_SUCCESS_MSO_RESPONSE , HttpMethod.POST);
81 public void testActivateConfigurationSucceed() throws Exception {
82 String requestBody = "" +
84 " \"val\": \"dummy payload\"" +
86 callMsoWithFineRequest(ACTIVATE_CONFIGURATION_OK_JSON, ImmutableMap.of(), buildUri(MSO_ACTIVATE_CONFIGURATION),
87 requestBody, HttpStatus.ACCEPTED.value(),EXPECTED_SUCCESS_MSO_RESPONSE , HttpMethod.POST);
90 @Test(dataProvider = "errorCodes")
91 public void testCreateConfigurationError(int errorCode) throws IOException, URISyntaxException {
92 String requestBody = TestUtils.convertRequest(objectMapper, CREATE_CONFIGURATION_REQUEST_DETAILS);
93 callMsoWithSimulatedErrorResponse(CREATE_CONFIGURATION_FAILED_JSON,
94 ImmutableMap.of("\"<ERROR_CODE>\"", Integer.toString(errorCode),"\"<ERROR_PAYLOAD>\"", StringEscapeUtils.escapeJson(EXPECTED_ERROR_MSO_RESPONSE)),
95 buildUri(MSO_CREATE_CONFIGURATION), requestBody,errorCode,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);
100 public void testCreateConfigurationFail() throws Exception {
101 String requestBody = "498/*ht5ru7 mjhnb";
102 callMsoWithSimulatedErrorResponse(CREATE_CONFIGURATION_FAILED_JSON,
103 ImmutableMap.of("\"<ERROR_CODE>\"", 500),
104 buildUri(MSO_CREATE_CONFIGURATION), requestBody,500,EXPECTED_ERROR_MSO_RESPONSE,HttpMethod.POST);