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 java.io.IOException;
25 import java.io.InputStream;
26 import java.nio.file.Files;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.util.Properties;
30 import java.util.UUID;
31 import org.glassfish.grizzly.http.util.HttpStatus;
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.onap.vid.client.SyncRestClient;
36 import org.onap.vid.controllers.MsoController;
37 import org.onap.vid.mso.MsoInterface;
38 import org.onap.vid.mso.MsoProperties;
39 import org.onap.vid.mso.MsoResponseWrapper;
40 import org.onap.vid.mso.MsoResponseWrapperInterface;
41 import org.onap.vid.mso.RestObject;
43 public class MsoRestClientNewTest {
45 private static StubServer server;
46 private static StubServer securedServer;
47 private static Properties props = new Properties();
48 private static String msoCreateServiceInstanceJson;
49 private final static String CREATE_INSTANCE_RESPONSE_STR =
50 "{\"requestReferences\":{\"instanceId\":\"baa13544-0e95-4644-9565-9a198a29a294\","
51 + "\"requestId\":\"a42a1a35-3d63-4629-bbe0-4989fa7414cb\"}}";
52 private final static String SERVICE_INSTANCE_ID = "12345";
53 private static final String SAMPLE_VNF_INSTANCE_ID = "111";
54 private static final String SAMPLE_VNF_MODULE_ID = "987";
55 private static final String SAMPLE_NETWORK_INSTANCE_ID = "666";
56 private static final String SAMPLE_CONFIGURATION_ID = "997";
57 private static final String SAMPLE_REQUEST_ID = "7777";
61 public static void start() throws IOException {
62 server = new StubServer().run();
63 securedServer = new StubServer().secured().run();
65 Path resourceDirectory =
66 Paths.get("src", "test", "resources", "WEB-INF", "conf", "system.properties");
67 try(InputStream is = Files.newInputStream(resourceDirectory)) {
71 Path msoServiceInstantiationJsonFilePath =
72 Paths.get("src", "test", "resources", "payload_jsons", "mso_service_instantiation.json");
73 msoCreateServiceInstanceJson =
74 String.join("\n", Files.readAllLines(msoServiceInstantiationJsonFilePath));
78 public static void stop() {
84 private String baseUrl() {
85 return String.format("http://localhost:%d", server.getPort());
89 public void testCreateSvcInstance() throws Exception {
90 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_CONFIGURATIONS);
91 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
92 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
95 HttpStatus.ACCEPTED_202,
96 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
97 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createSvcInstance);
102 public void testCreateVnf() throws Exception {
103 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
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)) {
111 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVnf);
116 public void testCreateNwInstance() throws Exception {
117 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
118 String nw_endpoint = endpoint.replaceFirst(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)) {
124 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createNwInstance);
129 public void testCreateVolumeGroupInstance() throws Exception {
130 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
131 String vnf_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
132 vnf_endpoint = vnf_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_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()::createVolumeGroupInstance);
143 public void testCreateVfModuleInstance() throws Exception {
144 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
145 String partial_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
146 String vf_module_endpoint =
147 partial_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
150 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
153 HttpStatus.ACCEPTED_202,
154 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
155 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVfModuleInstance);
160 public void testCreateConfigurationInstance() throws Exception {
161 MsoRestClientNew testSubject;
162 RequestDetailsWrapper requestDetails = null;
163 String endpoint = "";
164 MsoResponseWrapper result;
168 testSubject = createTestSubject();
169 result = testSubject.createConfigurationInstance(requestDetails, endpoint);
170 } catch (Exception e) {
175 public void testDeleteSvcInstance() throws Exception {
176 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
177 endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
180 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
183 HttpStatus.NO_CONTENT_204,
184 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
185 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteSvcInstance);
190 public void testDeleteVnf() throws Exception {
191 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
192 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()::deleteVnf);
204 public void testDeleteVfModule() throws Exception {
205 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
206 String part_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
207 String vf_modules_endpoint = part_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
208 String delete_vf_endpoint = vf_modules_endpoint + '/' + SAMPLE_VNF_MODULE_ID;
210 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
213 HttpStatus.NO_CONTENT_204,
214 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
215 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVfModule);
220 public void testDeleteVolumeGroupInstance() throws Exception {
221 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
222 String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
223 String vnf_endpoint = svc_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
224 String delete_volume_group_endpoint = vnf_endpoint + "/" + SAMPLE_VNF_MODULE_ID;
226 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
228 delete_volume_group_endpoint,
229 HttpStatus.NO_CONTENT_204,
230 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
231 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVolumeGroupInstance);
236 public void testDeleteNwInstance() throws Exception {
237 String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
238 String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
239 String delete_nw_endpoint = svc_endpoint + "/" + SAMPLE_NETWORK_INSTANCE_ID;
241 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
244 HttpStatus.NO_CONTENT_204,
245 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
246 closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteNwInstance);
251 public void testGetOrchestrationRequest() {
252 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
253 String path = p + "/" + SAMPLE_REQUEST_ID;
255 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
259 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
260 closure.executeGet(msoRestClient()::getOrchestrationRequest);
265 public void testGetManualTasks() {
266 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
267 String path = p + "/" + UUID.randomUUID();
269 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
273 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
274 closure.executeGet(msoRestClient()::getManualTasks);
279 public void testGetOrchestrationRequestsForDashboard() throws Exception {
280 MsoRestClientNew testSubject;
282 String sourceId = "";
283 String endpoint = "";
284 RestObject restObject = null;
285 MsoResponseWrapper result;
289 testSubject = createTestSubject();
290 result = testSubject.getOrchestrationRequestsForDashboard(t, sourceId, endpoint, restObject);
291 } catch (Exception e) {
296 public void testGetManualTasksByRequestId() throws Exception {
297 MsoRestClientNew testSubject;
299 String sourceId = "";
300 String endpoint = "";
301 RestObject restObject = null;
302 MsoResponseWrapper result;
306 testSubject = createTestSubject();
307 result = testSubject.getManualTasksByRequestId(t, sourceId, endpoint, restObject);
308 } catch (Exception e) {
313 public void testCompleteManualTask() throws Exception {
314 MsoRestClientNew testSubject;
315 RequestDetails requestDetails = null;
317 String sourceId = "";
318 String endpoint = "";
319 RestObject restObject = null;
320 MsoResponseWrapper result;
324 testSubject = createTestSubject();
325 result = testSubject.completeManualTask(requestDetails, t, sourceId, endpoint, restObject);
326 } catch (Exception e) {
331 public void testDeleteConfiguration() throws Exception {
332 MsoRestClientNew testSubject;
333 RequestDetailsWrapper requestDetails = null;
334 String pmc_endpoint = "";
335 MsoResponseWrapper result;
339 testSubject = createTestSubject();
340 result = testSubject.deleteConfiguration(requestDetails, pmc_endpoint);
341 } catch (Exception e) {
346 public void testSetConfigurationActiveStatus() throws Exception {
347 String endpoint = "/serviceInstances/v5/<service_instance_id>/configurations/<configuration_id>";
348 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
349 endpoint = endpoint.replace(MsoController.CONFIGURATION_ID, SAMPLE_CONFIGURATION_ID);
350 endpoint = endpoint + "/activate";
352 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
355 HttpStatus.ACCEPTED_202,
356 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
357 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::setConfigurationActiveStatus);
362 public void testSetPortOnConfigurationStatus() throws Exception {
363 MsoRestClientNew testSubject;
364 RequestDetails request = null;
366 MsoResponseWrapper result;
370 testSubject = createTestSubject();
371 result = testSubject.setPortOnConfigurationStatus(request, path);
372 } catch (Exception e) {
377 public void testChangeManagementUpdate() throws Exception {
378 MsoRestClientNew testSubject;
379 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetails = null;
380 String endpoint = "";
381 MsoResponseWrapperInterface result;
385 testSubject = createTestSubject();
386 result = testSubject.changeManagementUpdate(requestDetails, endpoint);
387 } catch (Exception e) {
392 public void testSetServiceInstanceStatus() throws Exception {
393 MsoRestClientNew testSubject;
394 RequestDetails requestDetails = null;
396 String sourceId = "";
397 String endpoint = "";
398 RestObject<String> restObject = null;
402 testSubject = createTestSubject();
403 testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
404 } catch (Exception e) {
409 public void testRemoveRelationshipFromServiceInstance() throws Exception {
410 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
411 String removeRelationshipsPath = serviceEndpoint + "/" + SERVICE_INSTANCE_ID + "/removeRelationships";
413 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
415 removeRelationshipsPath,
416 HttpStatus.ACCEPTED_202,
417 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
418 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::removeRelationshipFromServiceInstance);
423 public void testAddRelationshipToServiceInstance() throws Exception {
424 MsoRestClientNew testSubject;
425 RequestDetails requestDetails = null;
426 String addRelationshipsPath = "";
427 MsoResponseWrapper result;
431 testSubject = createTestSubject();
432 result = testSubject.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
433 } catch (Exception e) {
437 private MsoRestClientNew msoRestClient() {
438 return new MsoRestClientNew(new SyncRestClient(MsoInterface.objectMapper()), baseUrl());
441 private MsoRestClientNew createTestSubject() {
442 return new MsoRestClientNew(null, "");