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.springframework.test.context.ContextConfiguration;
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 testGetManualTasksByRequestId() {
283 String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
284 String path = p + "/" + UUID.randomUUID();
285 String validResponse = ""
287 + " \"taskList\": [ "
289 + " \"taskId\": \"daf4dd84-b77a-42da-a051-3239b7a9392c\", "
290 + " \"type\": \"fallout\", "
291 + " \"nfRole\": \"vEsmeralda\", "
292 + " \"subscriptionServiceType\": \"Emanuel\", "
293 + " \"originalRequestId\": \"d352c70d-5ef8-4977-9ea8-4c8cbe860422\", "
294 + " \"originalRequestorId\": \"ss835w\", "
295 + " \"errorSource\": \"A&AI\", "
296 + " \"errorCode\": \"404\", "
297 + " \"errorMessage\": \"Failed in A&AI 404\", "
298 + " \"validResponses\": [ "
309 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
313 validResponse,validResponse)) {
314 closure.executeGet(endpoint -> msoRestClient().getManualTasksByRequestId(null, null, endpoint, null));
319 public void testGetOrchestrationRequestsForDashboard() throws Exception {
320 MsoRestClientNew testSubject;
322 String sourceId = "";
323 String endpoint = "";
324 RestObject restObject = null;
325 MsoResponseWrapper result;
329 testSubject = createTestSubject();
330 result = testSubject.getOrchestrationRequest(t, sourceId, endpoint, restObject, true);
331 } catch (Exception e) {
336 public void testCompleteManualTask() throws Exception {
337 MsoRestClientNew testSubject;
338 RequestDetails requestDetails = null;
340 String sourceId = "";
341 String endpoint = "";
342 RestObject restObject = null;
343 MsoResponseWrapper result;
347 testSubject = createTestSubject();
348 result = testSubject.completeManualTask(requestDetails, t, sourceId, endpoint, restObject);
349 } catch (Exception e) {
354 public void testDeleteConfiguration() throws Exception {
355 MsoRestClientNew testSubject;
356 RequestDetailsWrapper requestDetails = null;
357 String pmc_endpoint = "";
358 MsoResponseWrapper result;
362 testSubject = createTestSubject();
363 result = testSubject.deleteConfiguration(requestDetails, pmc_endpoint);
364 } catch (Exception e) {
369 public void testSetConfigurationActiveStatus() throws Exception {
370 String endpoint = "/serviceInstances/v5/<service_instance_id>/configurations/<configuration_id>";
371 endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
372 endpoint = endpoint.replace(MsoController.CONFIGURATION_ID, SAMPLE_CONFIGURATION_ID);
373 endpoint = endpoint + "/activate";
375 try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
378 HttpStatus.ACCEPTED_202,
379 CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
380 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::setConfigurationActiveStatus);
385 public void testSetPortOnConfigurationStatus() throws Exception {
386 MsoRestClientNew testSubject;
387 RequestDetails request = null;
389 MsoResponseWrapper result;
393 testSubject = createTestSubject();
394 result = testSubject.setPortOnConfigurationStatus(request, path);
395 } catch (Exception e) {
400 public void testChangeManagementUpdate() throws Exception {
401 MsoRestClientNew testSubject;
402 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetails = null;
403 String endpoint = "";
404 MsoResponseWrapperInterface result;
408 testSubject = createTestSubject();
409 result = testSubject.changeManagementUpdate(requestDetails, endpoint);
410 } catch (Exception e) {
415 public void testSetServiceInstanceStatus() throws Exception {
416 MsoRestClientNew testSubject;
417 RequestDetails requestDetails = null;
419 String sourceId = "";
420 String endpoint = "";
421 RestObject<String> restObject = null;
425 testSubject = createTestSubject();
426 testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
427 } catch (Exception e) {
432 public void testRemoveRelationshipFromServiceInstance() throws Exception {
433 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
434 String removeRelationshipsPath = serviceEndpoint + "/" + SERVICE_INSTANCE_ID + "/removeRelationships";
436 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
438 removeRelationshipsPath,
439 HttpStatus.ACCEPTED_202,
440 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
441 closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::removeRelationshipFromServiceInstance);
446 public void testAddRelationshipToServiceInstance() throws Exception {
447 MsoRestClientNew testSubject;
448 RequestDetails requestDetails = null;
449 String addRelationshipsPath = "";
450 MsoResponseWrapper result;
454 testSubject = createTestSubject();
455 result = testSubject.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
456 } catch (Exception e) {
460 public void testScaleOutVfModule() throws IOException {
461 String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
462 String partial_endpoint = serviceEndpoint.replaceFirst(SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
463 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
464 try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
467 HttpStatus.ACCEPTED_202,
468 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
469 closure.executePostCall(msoScaleOutVfModule, msoRestClient()::scaleOutVFModuleInstance);
474 private MsoRestClientNew msoRestClient() {
475 final WebConfig webConfig = new WebConfig();
476 return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl(),null);
479 private MsoRestClientNew createTestSubject() {
480 return new MsoRestClientNew(null, "",null);