bfc82ce2a0975056b019470c5e6208e9d80e5277
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / rest / MsoRestClientNewTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.vid.mso.rest;
22
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;
38
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;
46
47 import static org.onap.vid.controllers.MsoController.SVC_INSTANCE_ID;
48 import static org.onap.vid.controllers.MsoController.VNF_INSTANCE_ID;
49
50 @ContextConfiguration(classes = {SystemProperties.class})
51 public class MsoRestClientNewTest {
52
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";
67
68
69     @BeforeClass
70     public static void start() throws IOException {
71         server = new StubServer().run();
72         securedServer = new StubServer().secured().run();
73
74         Path resourceDirectory =
75                 Paths.get("src", "test", "resources", "WEB-INF", "conf", "system.properties");
76         try (InputStream is = Files.newInputStream(resourceDirectory)) {
77             props.load(is);
78         }
79
80         Path msoServiceInstantiationJsonFilePath =
81                 Paths.get("src", "test", "resources", "payload_jsons", "mso_service_instantiation.json");
82
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));
87
88     }
89
90     @AfterClass
91     public static void stop() {
92         server.stop();
93         securedServer.stop();
94     }
95
96
97     private String baseUrl() {
98         return String.format("http://localhost:%d", server.getPort());
99     }
100
101     @Test
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(
106                 server,
107                 endpoint,
108                 HttpStatus.ACCEPTED_202,
109                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
110             closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createSvcInstance);
111         }
112     }
113
114     @Test
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(
119                 server,
120                 endpoint,
121                 HttpStatus.ACCEPTED_202,
122                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
123
124             closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVnf);
125         }
126     }
127
128     @Test
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(
133                 server,
134                 nw_endpoint,
135                 HttpStatus.ACCEPTED_202,
136                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
137             closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createNwInstance);
138         }
139     }
140
141     @Test
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(
147                 server,
148                 vnf_endpoint,
149                 HttpStatus.ACCEPTED_202,
150                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
151             closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVolumeGroupInstance);
152         }
153     }
154
155     @Test
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);
161
162
163         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
164                 server,
165                 vf_module_endpoint,
166                 HttpStatus.ACCEPTED_202,
167                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
168             closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVfModuleInstance);
169         }
170     }
171
172     @Test
173     public void testCreateConfigurationInstance() throws Exception {
174         MsoRestClientNew testSubject;
175         RequestDetailsWrapper requestDetails = null;
176         String endpoint = "";
177         MsoResponseWrapper result;
178
179         // default test
180         try {
181             testSubject = createTestSubject();
182             result = testSubject.createConfigurationInstance(requestDetails, endpoint);
183         } catch (Exception e) {
184         }
185     }
186     @Ignore
187     @Test
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);
191
192
193         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
194                 server,
195                 endpoint,
196                 HttpStatus.NO_CONTENT_204,
197                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
198             closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteSvcInstance);
199         }
200     }
201
202     @Ignore
203     @Test
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);
207
208         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
209                 server,
210                 endpoint,
211                 HttpStatus.NO_CONTENT_204,
212                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
213             closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVnf);
214         }
215     }
216
217     @Ignore
218     @Test
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;
224
225         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
226                 server,
227                 delete_vf_endpoint,
228                 HttpStatus.NO_CONTENT_204,
229                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
230             closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVfModule);
231         }
232     }
233
234     @Ignore
235     @Test
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;
241
242         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
243                 server,
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);
248         }
249     }
250
251     @Ignore
252     @Test
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;
257
258         try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
259             server,
260             delete_nw_endpoint,
261             HttpStatus.NO_CONTENT_204,
262             CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
263             closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteNwInstance);
264         }
265     }
266
267     @Test
268     public void testGetOrchestrationRequest() {
269         String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
270         String path = p + "/" + SAMPLE_REQUEST_ID;
271
272         try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
273             server,
274             path,
275             HttpStatus.OK_200,
276             CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
277             closure.executeGet(msoRestClient()::getOrchestrationRequest);
278         }
279     }
280
281     @Test
282     public void testGetManualTasks() {
283         String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
284         String path = p + "/" + UUID.randomUUID();
285
286         try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
287             server,
288             path,
289             HttpStatus.OK_200,
290             CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
291             closure.executeGet(msoRestClient()::getManualTasks);
292         }
293     }
294
295     @Test
296     public void testGetOrchestrationRequestsForDashboard() throws Exception {
297         MsoRestClientNew testSubject;
298         String t = "";
299         String sourceId = "";
300         String endpoint = "";
301         RestObject restObject = null;
302         MsoResponseWrapper result;
303
304         // default test
305         try {
306             testSubject = createTestSubject();
307             result = testSubject.getOrchestrationRequestsForDashboard(t, sourceId, endpoint, restObject);
308         } catch (Exception e) {
309         }
310     }
311
312     @Test
313     public void testGetManualTasksByRequestId() throws Exception {
314         MsoRestClientNew testSubject;
315         String t = "";
316         String sourceId = "";
317         String endpoint = "";
318         RestObject restObject = null;
319         MsoResponseWrapper result;
320
321         // default test
322         try {
323             testSubject = createTestSubject();
324             result = testSubject.getManualTasksByRequestId(t, sourceId, endpoint, restObject);
325         } catch (Exception e) {
326         }
327     }
328
329     @Test
330     public void testCompleteManualTask() throws Exception {
331         MsoRestClientNew testSubject;
332         RequestDetails requestDetails = null;
333         String t = "";
334         String sourceId = "";
335         String endpoint = "";
336         RestObject restObject = null;
337         MsoResponseWrapper result;
338
339         // default test
340         try {
341             testSubject = createTestSubject();
342             result = testSubject.completeManualTask(requestDetails, t, sourceId, endpoint, restObject);
343         } catch (Exception e) {
344         }
345     }
346
347     @Test
348     public void testDeleteConfiguration() throws Exception {
349         MsoRestClientNew testSubject;
350         RequestDetailsWrapper requestDetails = null;
351         String pmc_endpoint = "";
352         MsoResponseWrapper result;
353
354         // default test
355         try {
356             testSubject = createTestSubject();
357             result = testSubject.deleteConfiguration(requestDetails, pmc_endpoint);
358         } catch (Exception e) {
359         }
360     }
361
362     @Test
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";
368
369         try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
370             server,
371             endpoint,
372             HttpStatus.ACCEPTED_202,
373             CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
374             closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::setConfigurationActiveStatus);
375         }
376     }
377
378     @Test
379     public void testSetPortOnConfigurationStatus() throws Exception {
380         MsoRestClientNew testSubject;
381         RequestDetails request = null;
382         String path = "";
383         MsoResponseWrapper result;
384
385         // default test
386         try {
387             testSubject = createTestSubject();
388             result = testSubject.setPortOnConfigurationStatus(request, path);
389         } catch (Exception e) {
390         }
391     }
392
393     @Test
394     public void testChangeManagementUpdate() throws Exception {
395         MsoRestClientNew testSubject;
396         org.onap.vid.changeManagement.RequestDetailsWrapper requestDetails = null;
397         String endpoint = "";
398         MsoResponseWrapperInterface result;
399
400         // default test
401         try {
402             testSubject = createTestSubject();
403             result = testSubject.changeManagementUpdate(requestDetails, endpoint);
404         } catch (Exception e) {
405         }
406     }
407
408     @Test
409     public void testSetServiceInstanceStatus() throws Exception {
410         MsoRestClientNew testSubject;
411         RequestDetails requestDetails = null;
412         String t = "";
413         String sourceId = "";
414         String endpoint = "";
415         RestObject<String> restObject = null;
416
417         // default test
418         try {
419             testSubject = createTestSubject();
420             testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
421         } catch (Exception e) {
422         }
423     }
424
425     @Test
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";
429
430         try (MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
431                 server,
432                 removeRelationshipsPath,
433                 HttpStatus.ACCEPTED_202,
434                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
435             closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::removeRelationshipFromServiceInstance);
436         }
437     }
438
439     @Test
440     public void testAddRelationshipToServiceInstance() throws Exception {
441         MsoRestClientNew testSubject;
442         RequestDetails requestDetails = null;
443         String addRelationshipsPath = "";
444         MsoResponseWrapper result;
445
446         // default test
447         try {
448             testSubject = createTestSubject();
449             result = testSubject.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
450         } catch (Exception e) {
451         }
452     }
453     @Test
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(
459                 server,
460                 vf_module_endpoint,
461                 HttpStatus.ACCEPTED_202,
462                 CREATE_INSTANCE_RESPONSE_STR, CREATE_INSTANCE_RESPONSE_STR)) {
463             closure.executePostCall(msoScaleOutVfModule, msoRestClient()::scaleOutVFModuleInstance);
464         }
465
466     }
467
468     private MsoRestClientNew msoRestClient() {
469         return new MsoRestClientNew(new SyncRestClient(MsoInterface.objectMapper()), baseUrl());
470     }
471
472     private MsoRestClientNew createTestSubject() {
473         return new MsoRestClientNew(null, "");
474     }
475 }