2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 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 com.xebialabs.restito.server.StubServer;
24 import org.glassfish.grizzly.http.util.HttpStatus;
25 import org.junit.AfterClass;
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28 import org.onap.portalsdk.core.util.SystemProperties;
29 import org.onap.vid.client.SyncRestClient;
30 import org.onap.vid.controllers.MsoController;
31 import org.onap.vid.mso.MsoInterface;
32 import org.onap.vid.mso.MsoProperties;
33 import org.onap.vid.mso.MsoResponseWrapper;
34 import org.onap.vid.mso.MsoResponseWrapperInterface;
35 import org.onap.vid.mso.RestObject;
36 import org.springframework.test.context.ContextConfiguration;
38 import java.io.IOException;
39 import java.io.InputStream;
40 import java.nio.file.Files;
41 import java.nio.file.Path;
42 import java.nio.file.Paths;
43 import java.util.Properties;
44 import java.util.UUID;
46 import static org.onap.vid.controllers.MsoController.SVC_INSTANCE_ID;
47 import static org.onap.vid.controllers.MsoController.VNF_INSTANCE_ID;
49 @ContextConfiguration(classes = {SystemProperties.class})
50 public class MsoRestClientNewTest {
52 private static StubServer server;
53 private static StubServer securedServer;
54 private static Properties props = new Properties();
55 private static String msoCreateServiceInstanceJson;
56 private static String msoScaleOutVfModule;
57 private final static String CREATE_INSTANCE_RESPONSE_STR =
58 "{\"requestReferences\":{\"instanceId\":\"baa13544-0e95-4644-9565-9a198a29a294\","
59 + "\"requestId\":\"a42a1a35-3d63-4629-bbe0-4989fa7414cb\"}}";
60 private final static String SERVICE_INSTANCE_ID = "12345";
61 private static final String SAMPLE_VNF_INSTANCE_ID = "111";
62 private static final String SAMPLE_VNF_MODULE_ID = "987";
63 private static final String SAMPLE_NETWORK_INSTANCE_ID = "666";
64 private static final String SAMPLE_CONFIGURATION_ID = "997";
65 private static final String SAMPLE_REQUEST_ID = "7777";
69 public static void start() throws IOException {
70 server = new StubServer().run();
71 securedServer = new StubServer().secured().run();
73 Path resourceDirectory =
74 Paths.get("src", "test", "resources", "WEB-INF", "conf", "system.properties");
75 try (InputStream is = Files.newInputStream(resourceDirectory)) {
79 Path msoServiceInstantiationJsonFilePath =
80 Paths.get("src", "test", "resources", "payload_jsons", "mso_service_instantiation.json");
82 Path scaleOutJsonFilePath = Paths.get("src", "test", "resources", "payload_jsons", "scaleOutVfModulePayloadToMso.json");
83 msoCreateServiceInstanceJson =
84 String.join("\n", Files.readAllLines(msoServiceInstantiationJsonFilePath));
85 msoScaleOutVfModule = String.join("\n", Files.readAllLines(scaleOutJsonFilePath));
90 public static void stop() {
96 private String baseUrl() {
97 return String.format("http://localhost:%d", server.getPort());
101 public void testCreateSvcInstance() throws Exception {
102 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_CONFIGURATIONS);
103 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
104 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
107 HttpStatus.ACCEPTED_202,
108 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
109 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createSvcInstance);
114 public void testCreateVnf() throws Exception {
115 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
116 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
117 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
120 HttpStatus.ACCEPTED_202,
121 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
123 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVnf);
128 public void testCreateNwInstance() throws Exception {
129 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
130 String nw_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
131 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
134 HttpStatus.ACCEPTED_202,
135 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
136 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createNwInstance);
141 public void testCreateVolumeGroupInstance() throws Exception {
142 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
143 String vnf_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
144 vnf_endpoint = vnf_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
145 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
148 HttpStatus.ACCEPTED_202,
149 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
150 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVolumeGroupInstance);
155 public void testCreateVfModuleInstance() throws Exception {
156 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
157 String partial_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
158 String vf_module_endpoint =
159 partial_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
162 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
165 HttpStatus.ACCEPTED_202,
166 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
167 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVfModuleInstance);
172 public void testCreateConfigurationInstance() throws Exception {
173 MsoRestClientNew testSubject;
174 RequestDetailsWrapper requestDetails = null;
175 String endpoint = "";
176 MsoResponseWrapper result;
180 testSubject = createTestSubject();
181 result = testSubject.createConfigurationInstance(requestDetails, endpoint);
182 } catch (Exception e) {
187 public void testDeleteSvcInstance() throws Exception {
188 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
189 endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
192 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
195 HttpStatus.NO_CONTENT_204,
196 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
197 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteSvcInstance);
202 public void testDeleteVnf() throws Exception {
203 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
204 endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
206 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
209 HttpStatus.NO_CONTENT_204,
210 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
211 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVnf);
216 public void testDeleteVfModule() throws Exception {
217 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
218 String part_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
219 String vf_modules_endpoint = part_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
220 String delete_vf_endpoint = vf_modules_endpoint + '/' + SAMPLE_VNF_MODULE_ID;
222 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
225 HttpStatus.NO_CONTENT_204,
226 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
227 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVfModule);
232 public void testDeleteVolumeGroupInstance() throws Exception {
233 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
234 String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
235 String vnf_endpoint = svc_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
236 String delete_volume_group_endpoint = vnf_endpoint + "/" + SAMPLE_VNF_MODULE_ID;
238 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
240 delete_volume_group_endpoint,
241 HttpStatus.NO_CONTENT_204,
242 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
243 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVolumeGroupInstance);
248 public void testDeleteNwInstance() throws Exception {
249 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
250 String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
251 String delete_nw_endpoint = svc_endpoint + "/" + SAMPLE_NETWORK_INSTANCE_ID;
253 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
256 HttpStatus.NO_CONTENT_204,
257 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
258 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteNwInstance);
263 public void testGetOrchestrationRequest() {
264 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
265 String path = p + "/" + SAMPLE_REQUEST_ID;
267 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
271 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
272 closure.executeGet(msoRestClient()::getOrchestrationRequest);
277 public void testGetManualTasks() {
278 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
279 String path = p + "/" + UUID.randomUUID();
281 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
285 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
286 closure.executeGet(msoRestClient()::getManualTasks);
291 public void testGetOrchestrationRequestsForDashboard() throws Exception {
292 MsoRestClientNew testSubject;
294 String sourceId = "";
295 String endpoint = "";
296 RestObject restObject = null;
297 MsoResponseWrapper result;
301 testSubject = createTestSubject();
302 result = testSubject.getOrchestrationRequestsForDashboard(t, sourceId, endpoint, restObject);
303 } catch (Exception e) {
308 public void testGetManualTasksByRequestId() throws Exception {
309 MsoRestClientNew testSubject;
311 String sourceId = "";
312 String endpoint = "";
313 RestObject restObject = null;
314 MsoResponseWrapper result;
318 testSubject = createTestSubject();
319 result = testSubject.getManualTasksByRequestId(t, sourceId, endpoint, restObject);
320 } catch (Exception e) {
325 public void testCompleteManualTask() throws Exception {
326 MsoRestClientNew testSubject;
327 RequestDetails requestDetails = null;
329 String sourceId = "";
330 String endpoint = "";
331 RestObject restObject = null;
332 MsoResponseWrapper result;
336 testSubject = createTestSubject();
337 result = testSubject.completeManualTask(requestDetails, t, sourceId, endpoint, restObject);
338 } catch (Exception e) {
343 public void testDeleteConfiguration() throws Exception {
344 MsoRestClientNew testSubject;
345 RequestDetailsWrapper requestDetails = null;
346 String pmc_endpoint = "";
347 MsoResponseWrapper result;
351 testSubject = createTestSubject();
352 result = testSubject.deleteConfiguration(requestDetails, pmc_endpoint);
353 } catch (Exception e) {
358 public void testSetConfigurationActiveStatus() throws Exception {
359 String endpoint = "/serviceInstances/v5/<service_instance_id>/configurations/<configuration_id>";
360 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
361 endpoint = endpoint.replace(MsoController.CONFIGURATION_ID, SAMPLE_CONFIGURATION_ID);
362 endpoint = endpoint + "/activate";
364 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
367 HttpStatus.ACCEPTED_202,
368 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
369 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::setConfigurationActiveStatus);
374 public void testSetPortOnConfigurationStatus() throws Exception {
375 MsoRestClientNew testSubject;
376 RequestDetails request = null;
378 MsoResponseWrapper result;
382 testSubject = createTestSubject();
383 result = testSubject.setPortOnConfigurationStatus(request, path);
384 } catch (Exception e) {
389 public void testChangeManagementUpdate() throws Exception {
390 MsoRestClientNew testSubject;
391 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetails = null;
392 String endpoint = "";
393 MsoResponseWrapperInterface result;
397 testSubject = createTestSubject();
398 result = testSubject.changeManagementUpdate(requestDetails, endpoint);
399 } catch (Exception e) {
404 public void testSetServiceInstanceStatus() throws Exception {
405 MsoRestClientNew testSubject;
406 RequestDetails requestDetails = null;
408 String sourceId = "";
409 String endpoint = "";
410 RestObject<String> restObject = null;
414 testSubject = createTestSubject();
415 testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
416 } catch (Exception e) {
421 public void testRemoveRelationshipFromServiceInstance() throws Exception {
422 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
423 String removeRelationshipsPath = serviceEndpoint + "/" + SERVICE_INSTANCE_ID + "/removeRelationships";
425 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
427 removeRelationshipsPath,
428 HttpStatus.ACCEPTED_202,
429 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
430 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::removeRelationshipFromServiceInstance);
435 public void testAddRelationshipToServiceInstance() throws Exception {
436 MsoRestClientNew testSubject;
437 RequestDetails requestDetails = null;
438 String addRelationshipsPath = "";
439 MsoResponseWrapper result;
443 testSubject = createTestSubject();
444 result = testSubject.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
445 } catch (Exception e) {
449 public void testScaleOutVfModule() throws IOException {
450 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
451 String partial_endpoint = serviceEndpoint.replaceFirst(SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
452 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
453 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
456 HttpStatus.ACCEPTED_202,
457 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
458 closure.executePostCall(msoScaleOutVfModule, msoRestClient()::scaleOutVFModuleInstance);
463 private MsoRestClientNew msoRestClient() {
464 return new MsoRestClientNew(new SyncRestClient(MsoInterface.objectMapper()), baseUrl());
467 private MsoRestClientNew createTestSubject() {
468 return new MsoRestClientNew(null, "");