vid-automation selenium tests
[vid.git] / vid-automation / src / test / java / org / opencomp / vid / api / pProbeMsoApiTest.java
1 package org.opencomp.vid.api;
2
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;
8
9 import java.io.IOException;
10 import java.net.URISyntaxException;
11
12 public class pProbeMsoApiTest extends BaseMsoApiTest{
13
14     //Urls
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";
19
20
21
22     //Request Details
23     private static final String ADD_REMOVE_RELATIONSHIP_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_dissociate_pnf_from_service.json";
24
25     //Request Details
26     private static final String CREATE_CONFIGURATION_REQUEST_DETAILS = "registration_to_simulator/body_jsons/mso_request_create_configuration.json";
27
28     //Jsons
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";
36
37     //Expected Responses
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\"}";
40
41
42     @Test
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);
47     }
48
49     @Test
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);
54     }
55
56
57     @Test
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);
62     }
63
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);
70
71     }
72
73     @Test
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);
78     }
79
80     @Test
81     public void testActivateConfigurationSucceed() throws Exception {
82         String requestBody = "" +
83                 "{" +
84                 "   \"val\": \"dummy payload\"" +
85                 "}";
86         callMsoWithFineRequest(ACTIVATE_CONFIGURATION_OK_JSON, ImmutableMap.of(), buildUri(MSO_ACTIVATE_CONFIGURATION),
87                 requestBody, HttpStatus.ACCEPTED.value(),EXPECTED_SUCCESS_MSO_RESPONSE , HttpMethod.POST);
88     }
89
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);
96
97     }
98
99     @Test
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);
105
106     }
107 }