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.fasterxml.jackson.databind.ObjectMapper;
24 import com.xebialabs.restito.server.StubServer;
25 import org.glassfish.grizzly.http.util.HttpStatus;
26 import org.junit.AfterClass;
27 import org.junit.BeforeClass;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.onap.portalsdk.core.util.SystemProperties;
31 import org.onap.vid.client.SyncRestClient;
32 import org.onap.vid.controller.MsoController;
33 import org.onap.vid.controller.WebConfig;
34 import org.onap.vid.mso.MsoProperties;
35 import org.onap.vid.mso.MsoResponseWrapper;
36 import org.onap.vid.mso.MsoResponseWrapperInterface;
37 import org.onap.vid.mso.RestObject;
38 import org.springframework.test.context.ContextConfiguration;
40 import java.io.IOException;
41 import java.io.InputStream;
42 import java.nio.file.Files;
43 import java.nio.file.Path;
44 import java.nio.file.Paths;
45 import java.util.Properties;
46 import java.util.UUID;
48 import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
49 import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
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 testGetManualTasks() {
284 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
285 String path = p + "/" + UUID.randomUUID();
287 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
291 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
292 closure.executeGet(msoRestClient()::getManualTasks);
297 public void testGetOrchestrationRequestsForDashboard() throws Exception {
298 MsoRestClientNew testSubject;
300 String sourceId = "";
301 String endpoint = "";
302 RestObject restObject = null;
303 MsoResponseWrapper result;
307 testSubject = createTestSubject();
308 result = testSubject.getOrchestrationRequest(t, sourceId, endpoint, restObject, true);
309 } catch (Exception e) {
314 public void testGetManualTasksByRequestId() throws Exception {
315 MsoRestClientNew testSubject;
317 String sourceId = "";
318 String endpoint = "";
319 RestObject restObject = null;
320 MsoResponseWrapper result;
324 testSubject = createTestSubject();
325 result = testSubject.getManualTasksByRequestId(t, sourceId, endpoint, restObject);
326 } catch (Exception e) {
331 public void testCompleteManualTask() throws Exception {
332 MsoRestClientNew testSubject;
333 RequestDetails requestDetails = null;
335 String sourceId = "";
336 String endpoint = "";
337 RestObject restObject = null;
338 MsoResponseWrapper result;
342 testSubject = createTestSubject();
343 result = testSubject.completeManualTask(requestDetails, t, sourceId, endpoint, restObject);
344 } catch (Exception e) {
349 public void testDeleteConfiguration() throws Exception {
350 MsoRestClientNew testSubject;
351 RequestDetailsWrapper requestDetails = null;
352 String pmc_endpoint = "";
353 MsoResponseWrapper result;
357 testSubject = createTestSubject();
358 result = testSubject.deleteConfiguration(requestDetails, pmc_endpoint);
359 } catch (Exception e) {
364 public void testSetConfigurationActiveStatus() throws Exception {
365 String endpoint = "/serviceInstances/v5/<service_instance_id>/configurations/<configuration_id>";
366 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
367 endpoint = endpoint.replace(MsoController.CONFIGURATION_ID, SAMPLE_CONFIGURATION_ID);
368 endpoint = endpoint + "/activate";
370 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
373 HttpStatus.ACCEPTED_202,
374 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
375 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::setConfigurationActiveStatus);
380 public void testSetPortOnConfigurationStatus() throws Exception {
381 MsoRestClientNew testSubject;
382 RequestDetails request = null;
384 MsoResponseWrapper result;
388 testSubject = createTestSubject();
389 result = testSubject.setPortOnConfigurationStatus(request, path);
390 } catch (Exception e) {
395 public void testChangeManagementUpdate() throws Exception {
396 MsoRestClientNew testSubject;
397 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetails = null;
398 String endpoint = "";
399 MsoResponseWrapperInterface result;
403 testSubject = createTestSubject();
404 result = testSubject.changeManagementUpdate(requestDetails, endpoint);
405 } catch (Exception e) {
410 public void testSetServiceInstanceStatus() throws Exception {
411 MsoRestClientNew testSubject;
412 RequestDetails requestDetails = null;
414 String sourceId = "";
415 String endpoint = "";
416 RestObject<String> restObject = null;
420 testSubject = createTestSubject();
421 testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
422 } catch (Exception e) {
427 public void testRemoveRelationshipFromServiceInstance() throws Exception {
428 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
429 String removeRelationshipsPath = serviceEndpoint + "/" + SERVICE_INSTANCE_ID + "/removeRelationships";
431 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
433 removeRelationshipsPath,
434 HttpStatus.ACCEPTED_202,
435 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
436 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::removeRelationshipFromServiceInstance);
441 public void testAddRelationshipToServiceInstance() throws Exception {
442 MsoRestClientNew testSubject;
443 RequestDetails requestDetails = null;
444 String addRelationshipsPath = "";
445 MsoResponseWrapper result;
449 testSubject = createTestSubject();
450 result = testSubject.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
451 } catch (Exception e) {
455 public void testScaleOutVfModule() throws IOException {
456 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
457 String partial_endpoint = serviceEndpoint.replaceFirst(SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
458 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
459 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
462 HttpStatus.ACCEPTED_202,
463 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
464 closure.executePostCall(msoScaleOutVfModule, msoRestClient()::scaleOutVFModuleInstance);
469 private MsoRestClientNew msoRestClient() {
470 final WebConfig webConfig = new WebConfig();
471 return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl());
474 private MsoRestClientNew createTestSubject() {
475 return new MsoRestClientNew(null, "");