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.Ignore;
28 import org.junit.Test;
29 import org.onap.portalsdk.core.util.SystemProperties;
30 import org.onap.vid.client.SyncRestClient;
31 import org.onap.vid.controllers.MsoController;
32 import org.onap.vid.mso.MsoInterface;
33 import org.onap.vid.mso.MsoProperties;
34 import org.onap.vid.mso.MsoResponseWrapper;
35 import org.onap.vid.mso.MsoResponseWrapperInterface;
36 import org.onap.vid.mso.RestObject;
37 import org.springframework.test.context.ContextConfiguration;
39 import java.io.IOException;
40 import java.io.InputStream;
41 import java.nio.file.Files;
42 import java.nio.file.Path;
43 import java.nio.file.Paths;
44 import java.util.Properties;
45 import java.util.UUID;
47 import static org.onap.vid.controllers.MsoController.SVC_INSTANCE_ID;
48 import static org.onap.vid.controllers.MsoController.VNF_INSTANCE_ID;
50 @ContextConfiguration(classes = {SystemProperties.class})
51 public class MsoRestClientNewTest {
53 private static StubServer server;
54 private static StubServer securedServer;
55 private static Properties props = new Properties();
56 private static String msoCreateServiceInstanceJson;
57 private static String msoScaleOutVfModule;
58 private final static String CREATE_INSTANCE_RESPONSE_STR =
59 "{\"requestReferences\":{\"instanceId\":\"baa13544-0e95-4644-9565-9a198a29a294\","
60 + "\"requestId\":\"a42a1a35-3d63-4629-bbe0-4989fa7414cb\"}}";
61 private final static String SERVICE_INSTANCE_ID = "12345";
62 private static final String SAMPLE_VNF_INSTANCE_ID = "111";
63 private static final String SAMPLE_VNF_MODULE_ID = "987";
64 private static final String SAMPLE_NETWORK_INSTANCE_ID = "666";
65 private static final String SAMPLE_CONFIGURATION_ID = "997";
66 private static final String SAMPLE_REQUEST_ID = "7777";
70 public static void start() throws IOException {
71 server = new StubServer().run();
72 securedServer = new StubServer().secured().run();
74 Path resourceDirectory =
75 Paths.get("src", "test", "resources", "WEB-INF", "conf", "system.properties");
76 try (InputStream is = Files.newInputStream(resourceDirectory)) {
80 Path msoServiceInstantiationJsonFilePath =
81 Paths.get("src", "test", "resources", "payload_jsons", "mso_service_instantiation.json");
83 Path scaleOutJsonFilePath = Paths.get("src", "test", "resources", "payload_jsons", "scaleOutVfModulePayloadToMso.json");
84 msoCreateServiceInstanceJson =
85 String.join("\n", Files.readAllLines(msoServiceInstantiationJsonFilePath));
86 msoScaleOutVfModule = String.join("\n", Files.readAllLines(scaleOutJsonFilePath));
91 public static void stop() {
97 private String baseUrl() {
98 return String.format("http://localhost:%d", server.getPort());
102 public void testCreateSvcInstance() throws Exception {
103 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_CONFIGURATIONS);
104 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
105 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
108 HttpStatus.ACCEPTED_202,
109 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
110 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createSvcInstance);
115 public void testCreateVnf() throws Exception {
116 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
117 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
118 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
121 HttpStatus.ACCEPTED_202,
122 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
124 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVnf);
129 public void testCreateNwInstance() throws Exception {
130 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
131 String nw_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
132 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
135 HttpStatus.ACCEPTED_202,
136 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
137 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createNwInstance);
142 public void testCreateVolumeGroupInstance() throws Exception {
143 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
144 String vnf_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
145 vnf_endpoint = vnf_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
146 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
149 HttpStatus.ACCEPTED_202,
150 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
151 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVolumeGroupInstance);
156 public void testCreateVfModuleInstance() throws Exception {
157 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
158 String partial_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
159 String vf_module_endpoint =
160 partial_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
163 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
166 HttpStatus.ACCEPTED_202,
167 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
168 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVfModuleInstance);
173 public void testCreateConfigurationInstance() throws Exception {
174 MsoRestClientNew testSubject;
175 RequestDetailsWrapper requestDetails = null;
176 String endpoint = "";
177 MsoResponseWrapper result;
181 testSubject = createTestSubject();
182 result = testSubject.createConfigurationInstance(requestDetails, endpoint);
183 } catch (Exception e) {
188 public void testDeleteSvcInstance() throws Exception {
189 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
190 endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
193 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
196 HttpStatus.NO_CONTENT_204,
197 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
198 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteSvcInstance);
204 public void testDeleteVnf() throws Exception {
205 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
206 endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
208 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
211 HttpStatus.NO_CONTENT_204,
212 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
213 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVnf);
219 public void testDeleteVfModule() throws Exception {
220 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
221 String part_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
222 String vf_modules_endpoint = part_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
223 String delete_vf_endpoint = vf_modules_endpoint + '/' + SAMPLE_VNF_MODULE_ID;
225 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
228 HttpStatus.NO_CONTENT_204,
229 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
230 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVfModule);
236 public void testDeleteVolumeGroupInstance() throws Exception {
237 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
238 String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
239 String vnf_endpoint = svc_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
240 String delete_volume_group_endpoint = vnf_endpoint + "/" + SAMPLE_VNF_MODULE_ID;
242 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
244 delete_volume_group_endpoint,
245 HttpStatus.NO_CONTENT_204,
246 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
247 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVolumeGroupInstance);
253 public void testDeleteNwInstance() throws Exception {
254 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
255 String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
256 String delete_nw_endpoint = svc_endpoint + "/" + SAMPLE_NETWORK_INSTANCE_ID;
258 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
261 HttpStatus.NO_CONTENT_204,
262 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
263 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteNwInstance);
268 public void testGetOrchestrationRequest() {
269 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
270 String path = p + "/" + SAMPLE_REQUEST_ID;
272 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
276 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
277 closure.executeGet(msoRestClient()::getOrchestrationRequest);
282 public void testGetManualTasks() {
283 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
284 String path = p + "/" + UUID.randomUUID();
286 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
290 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
291 closure.executeGet(msoRestClient()::getManualTasks);
296 public void testGetOrchestrationRequestsForDashboard() throws Exception {
297 MsoRestClientNew testSubject;
299 String sourceId = "";
300 String endpoint = "";
301 RestObject restObject = null;
302 MsoResponseWrapper result;
306 testSubject = createTestSubject();
307 result = testSubject.getOrchestrationRequestsForDashboard(t, sourceId, endpoint, restObject);
308 } catch (Exception e) {
313 public void testGetManualTasksByRequestId() throws Exception {
314 MsoRestClientNew testSubject;
316 String sourceId = "";
317 String endpoint = "";
318 RestObject restObject = null;
319 MsoResponseWrapper result;
323 testSubject = createTestSubject();
324 result = testSubject.getManualTasksByRequestId(t, sourceId, endpoint, restObject);
325 } catch (Exception e) {
330 public void testCompleteManualTask() throws Exception {
331 MsoRestClientNew testSubject;
332 RequestDetails requestDetails = null;
334 String sourceId = "";
335 String endpoint = "";
336 RestObject restObject = null;
337 MsoResponseWrapper result;
341 testSubject = createTestSubject();
342 result = testSubject.completeManualTask(requestDetails, t, sourceId, endpoint, restObject);
343 } catch (Exception e) {
348 public void testDeleteConfiguration() throws Exception {
349 MsoRestClientNew testSubject;
350 RequestDetailsWrapper requestDetails = null;
351 String pmc_endpoint = "";
352 MsoResponseWrapper result;
356 testSubject = createTestSubject();
357 result = testSubject.deleteConfiguration(requestDetails, pmc_endpoint);
358 } catch (Exception e) {
363 public void testSetConfigurationActiveStatus() throws Exception {
364 String endpoint = "/serviceInstances/v5/<service_instance_id>/configurations/<configuration_id>";
365 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
366 endpoint = endpoint.replace(MsoController.CONFIGURATION_ID, SAMPLE_CONFIGURATION_ID);
367 endpoint = endpoint + "/activate";
369 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
372 HttpStatus.ACCEPTED_202,
373 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
374 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::setConfigurationActiveStatus);
379 public void testSetPortOnConfigurationStatus() throws Exception {
380 MsoRestClientNew testSubject;
381 RequestDetails request = null;
383 MsoResponseWrapper result;
387 testSubject = createTestSubject();
388 result = testSubject.setPortOnConfigurationStatus(request, path);
389 } catch (Exception e) {
394 public void testChangeManagementUpdate() throws Exception {
395 MsoRestClientNew testSubject;
396 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetails = null;
397 String endpoint = "";
398 MsoResponseWrapperInterface result;
402 testSubject = createTestSubject();
403 result = testSubject.changeManagementUpdate(requestDetails, endpoint);
404 } catch (Exception e) {
409 public void testSetServiceInstanceStatus() throws Exception {
410 MsoRestClientNew testSubject;
411 RequestDetails requestDetails = null;
413 String sourceId = "";
414 String endpoint = "";
415 RestObject<String> restObject = null;
419 testSubject = createTestSubject();
420 testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
421 } catch (Exception e) {
426 public void testRemoveRelationshipFromServiceInstance() throws Exception {
427 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
428 String removeRelationshipsPath = serviceEndpoint + "/" + SERVICE_INSTANCE_ID + "/removeRelationships";
430 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
432 removeRelationshipsPath,
433 HttpStatus.ACCEPTED_202,
434 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
435 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::removeRelationshipFromServiceInstance);
440 public void testAddRelationshipToServiceInstance() throws Exception {
441 MsoRestClientNew testSubject;
442 RequestDetails requestDetails = null;
443 String addRelationshipsPath = "";
444 MsoResponseWrapper result;
448 testSubject = createTestSubject();
449 result = testSubject.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
450 } catch (Exception e) {
454 public void testScaleOutVfModule() throws IOException {
455 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
456 String partial_endpoint = serviceEndpoint.replaceFirst(SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
457 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
458 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
461 HttpStatus.ACCEPTED_202,
462 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
463 closure.executePostCall(msoScaleOutVfModule, msoRestClient()::scaleOutVFModuleInstance);
468 private MsoRestClientNew msoRestClient() {
469 return new MsoRestClientNew(new SyncRestClient(MsoInterface.objectMapper()), baseUrl());
472 private MsoRestClientNew createTestSubject() {
473 return new MsoRestClientNew(null, "");