2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.vid.mso.rest;
23 import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
24 import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.xebialabs.restito.server.StubServer;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.nio.file.Files;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.Properties;
34 import java.util.UUID;
35 import org.glassfish.grizzly.http.util.HttpStatus;
36 import org.junit.AfterClass;
37 import org.junit.BeforeClass;
38 import org.junit.Ignore;
39 import org.junit.Test;
40 import org.onap.portalsdk.core.util.SystemProperties;
41 import org.onap.vid.client.SyncRestClient;
42 import org.onap.vid.controller.MsoController;
43 import org.onap.vid.controller.WebConfig;
44 import org.onap.vid.mso.MsoProperties;
45 import org.onap.vid.mso.MsoResponseWrapper;
46 import org.onap.vid.mso.MsoResponseWrapperInterface;
47 import org.onap.vid.mso.RestObject;
48 import org.onap.vid.utils.SystemPropertiesWrapper;
49 import org.springframework.test.context.ContextConfiguration;
51 @ContextConfiguration(classes = {SystemProperties.class})
52 public class MsoRestClientNewTest {
54 private static StubServer server;
55 private static StubServer securedServer;
56 private static Properties props = new Properties();
57 private static String msoCreateServiceInstanceJson;
58 private static String msoScaleOutVfModule;
59 private final static String CREATE_INSTANCE_RESPONSE_STR =
60 "{\"requestReferences\":{\"instanceId\":\"baa13544-0e95-4644-9565-9a198a29a294\","
61 + "\"requestId\":\"a42a1a35-3d63-4629-bbe0-4989fa7414cb\"}}";
62 private final static String SERVICE_INSTANCE_ID = "12345";
63 private static final String SAMPLE_VNF_INSTANCE_ID = "111";
64 private static final String SAMPLE_VNF_MODULE_ID = "987";
65 private static final String SAMPLE_NETWORK_INSTANCE_ID = "666";
66 private static final String SAMPLE_CONFIGURATION_ID = "997";
67 private static final String SAMPLE_REQUEST_ID = "7777";
71 public static void start() throws IOException {
72 server = new StubServer().run();
73 securedServer = new StubServer().secured().run();
75 Path resourceDirectory =
76 Paths.get("src", "test", "resources", "WEB-INF", "conf", "system.properties");
77 try (InputStream is = Files.newInputStream(resourceDirectory)) {
81 Path msoServiceInstantiationJsonFilePath =
82 Paths.get("src", "test", "resources", "payload_jsons", "mso_service_instantiation.json");
84 Path scaleOutJsonFilePath = Paths.get("src", "test", "resources", "payload_jsons", "scaleOutVfModulePayloadToMso.json");
85 msoCreateServiceInstanceJson =
86 String.join("\n", Files.readAllLines(msoServiceInstantiationJsonFilePath));
87 msoScaleOutVfModule = String.join("\n", Files.readAllLines(scaleOutJsonFilePath));
92 public static void stop() {
98 private String baseUrl() {
99 return String.format("http://localhost:%d", server.getPort());
103 public void testCreateSvcInstance() throws Exception {
104 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_CONFIGURATIONS);
105 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
106 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
109 HttpStatus.ACCEPTED_202,
110 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
111 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createSvcInstance);
116 public void testCreateVnf() throws Exception {
117 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
118 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
119 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
122 HttpStatus.ACCEPTED_202,
123 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
125 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVnf);
130 public void testCreateNwInstance() throws Exception {
131 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
132 String nw_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
133 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
136 HttpStatus.ACCEPTED_202,
137 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
138 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createNwInstance);
143 public void testCreateVolumeGroupInstance() throws Exception {
144 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
145 String vnf_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
146 vnf_endpoint = vnf_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
147 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
150 HttpStatus.ACCEPTED_202,
151 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
152 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVolumeGroupInstance);
157 public void testCreateVfModuleInstance() throws Exception {
158 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
159 String partial_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
160 String vf_module_endpoint =
161 partial_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
164 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
167 HttpStatus.ACCEPTED_202,
168 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
169 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVfModuleInstance);
174 public void testCreateConfigurationInstance() throws Exception {
175 MsoRestClientNew testSubject;
176 RequestDetailsWrapper requestDetails = null;
177 String endpoint = "";
178 MsoResponseWrapper result;
182 testSubject = createTestSubject();
183 result = testSubject.createConfigurationInstance(requestDetails, endpoint);
184 } catch (Exception e) {
189 public void testDeleteSvcInstance() throws Exception {
190 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
191 endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
194 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
197 HttpStatus.NO_CONTENT_204,
198 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
199 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteSvcInstance);
205 public void testDeleteVnf() throws Exception {
206 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
207 endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
209 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
212 HttpStatus.NO_CONTENT_204,
213 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
214 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVnf);
220 public void testDeleteVfModule() throws Exception {
221 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
222 String part_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
223 String vf_modules_endpoint = part_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
224 String delete_vf_endpoint = vf_modules_endpoint + '/' + SAMPLE_VNF_MODULE_ID;
226 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
229 HttpStatus.NO_CONTENT_204,
230 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
231 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVfModule);
237 public void testDeleteVolumeGroupInstance() throws Exception {
238 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
239 String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
240 String vnf_endpoint = svc_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
241 String delete_volume_group_endpoint = vnf_endpoint + "/" + SAMPLE_VNF_MODULE_ID;
243 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
245 delete_volume_group_endpoint,
246 HttpStatus.NO_CONTENT_204,
247 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
248 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVolumeGroupInstance);
254 public void testDeleteNwInstance() throws Exception {
255 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
256 String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
257 String delete_nw_endpoint = svc_endpoint + "/" + SAMPLE_NETWORK_INSTANCE_ID;
259 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
262 HttpStatus.NO_CONTENT_204,
263 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
264 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteNwInstance);
269 public void testGetOrchestrationRequest() {
270 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
271 String path = p + "/" + SAMPLE_REQUEST_ID;
273 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
277 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
278 closure.executeGet(msoRestClient()::getOrchestrationRequest);
283 public void testGetManualTasksByRequestId() {
284 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
285 String path = p + "/" + UUID.randomUUID();
286 String validResponse = ""
288 + " \"taskList\": [ "
290 + " \"taskId\": \"daf4dd84-b77a-42da-a051-3239b7a9392c\", "
291 + " \"type\": \"fallout\", "
292 + " \"nfRole\": \"vEsmeralda\", "
293 + " \"subscriptionServiceType\": \"Emanuel\", "
294 + " \"originalRequestId\": \"d352c70d-5ef8-4977-9ea8-4c8cbe860422\", "
295 + " \"originalRequestorId\": \"ss835w\", "
296 + " \"errorSource\": \"A&AI\", "
297 + " \"errorCode\": \"404\", "
298 + " \"errorMessage\": \"Failed in A&AI 404\", "
299 + " \"validResponses\": [ "
310 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
314 validResponse,validResponse)) {
315 closure.executeGet(endpoint -> msoRestClient().getManualTasksByRequestId(null, null, endpoint, null));
320 public void testGetOrchestrationRequestsForDashboard() throws Exception {
321 MsoRestClientNew testSubject;
323 String sourceId = "";
324 String endpoint = "";
325 RestObject restObject = null;
326 MsoResponseWrapper result;
330 testSubject = createTestSubject();
331 result = testSubject.getOrchestrationRequest(t, sourceId, endpoint, restObject, true);
332 } catch (Exception e) {
337 public void testCompleteManualTask() throws Exception {
338 MsoRestClientNew testSubject;
339 RequestDetails requestDetails = null;
341 String sourceId = "";
342 String endpoint = "";
343 RestObject restObject = null;
344 MsoResponseWrapper result;
348 testSubject = createTestSubject();
349 result = testSubject.completeManualTask(requestDetails, t, sourceId, endpoint, restObject);
350 } catch (Exception e) {
355 public void testDeleteConfiguration() throws Exception {
356 MsoRestClientNew testSubject;
357 RequestDetailsWrapper requestDetails = null;
358 String pmc_endpoint = "";
359 MsoResponseWrapper result;
363 testSubject = createTestSubject();
364 result = testSubject.deleteConfiguration(requestDetails, pmc_endpoint);
365 } catch (Exception e) {
370 public void testSetConfigurationActiveStatus() throws Exception {
371 String endpoint = "/serviceInstances/v5/<service_instance_id>/configurations/<configuration_id>";
372 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
373 endpoint = endpoint.replace(MsoController.CONFIGURATION_ID, SAMPLE_CONFIGURATION_ID);
374 endpoint = endpoint + "/activate";
376 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
379 HttpStatus.ACCEPTED_202,
380 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
381 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::setConfigurationActiveStatus);
386 public void testSetPortOnConfigurationStatus() throws Exception {
387 MsoRestClientNew testSubject;
388 RequestDetails request = null;
390 MsoResponseWrapper result;
394 testSubject = createTestSubject();
395 result = testSubject.setPortOnConfigurationStatus(request, path);
396 } catch (Exception e) {
401 public void testChangeManagementUpdate() throws Exception {
402 MsoRestClientNew testSubject;
403 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetails = null;
404 String endpoint = "";
405 MsoResponseWrapperInterface result;
409 testSubject = createTestSubject();
410 result = testSubject.changeManagementUpdate(requestDetails, endpoint);
411 } catch (Exception e) {
416 public void testSetServiceInstanceStatus() throws Exception {
417 MsoRestClientNew testSubject;
418 RequestDetails requestDetails = null;
420 String sourceId = "";
421 String endpoint = "";
422 RestObject<String> restObject = null;
426 testSubject = createTestSubject();
427 testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
428 } catch (Exception e) {
433 public void testRemoveRelationshipFromServiceInstance() throws Exception {
434 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
435 String removeRelationshipsPath = serviceEndpoint + "/" + SERVICE_INSTANCE_ID + "/removeRelationships";
437 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
439 removeRelationshipsPath,
440 HttpStatus.ACCEPTED_202,
441 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
442 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::removeRelationshipFromServiceInstance);
447 public void testAddRelationshipToServiceInstance() throws Exception {
448 MsoRestClientNew testSubject;
449 RequestDetails requestDetails = null;
450 String addRelationshipsPath = "";
451 MsoResponseWrapper result;
455 testSubject = createTestSubject();
456 result = testSubject.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
457 } catch (Exception e) {
461 public void testScaleOutVfModule() throws IOException {
462 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
463 String partial_endpoint = serviceEndpoint.replaceFirst(SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
464 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
465 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
468 HttpStatus.ACCEPTED_202,
469 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
470 closure.executePostCall(msoScaleOutVfModule, msoRestClient()::scaleOutVFModuleInstance);
475 private MsoRestClientNew msoRestClient() {
476 final WebConfig webConfig = new WebConfig();
477 return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl(), null, new SystemPropertiesWrapper());
480 private MsoRestClientNew createTestSubject() {
481 return new MsoRestClientNew(null, "", null, new SystemPropertiesWrapper());