Increasing test coverage for vid.mso.rest
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / rest / MsoRestClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
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 io.joshworks.restclient.http.HttpResponse;
24 import io.joshworks.restclient.http.JsonMapper;
25 import org.apache.http.ProtocolVersion;
26 import org.apache.http.StatusLine;
27 import org.apache.http.message.BasicHttpResponse;
28 import org.apache.http.message.BasicStatusLine;
29 import org.mockito.Mock;
30 import org.onap.portalsdk.core.util.SystemProperties;
31 import org.onap.vid.changeManagement.RelatedInstanceList;
32 import org.onap.vid.changeManagement.RequestDetailsWrapper;
33 import org.onap.vid.client.SyncRestClient;
34 import org.onap.vid.controller.LocalWebConfig;
35 import org.onap.vid.model.RequestReferencesContainer;
36 import org.onap.vid.mso.MsoResponseWrapper;
37 import org.onap.vid.mso.MsoResponseWrapperInterface;
38 import org.onap.vid.mso.MsoUtil;
39 import org.onap.vid.mso.RestObject;
40 import org.onap.vid.mso.model.CloudConfiguration;
41 import org.onap.vid.mso.model.ModelInfo;
42 import org.onap.vid.mso.model.RequestInfo;
43 import org.onap.vid.mso.model.RequestParameters;
44 import org.onap.vid.mso.model.RequestReferences;
45 import org.springframework.test.context.ContextConfiguration;
46 import org.springframework.test.context.web.WebAppConfiguration;
47 import org.testng.annotations.BeforeClass;
48 import org.testng.annotations.Test;
49
50 import static org.mockito.ArgumentMatchers.any;
51
52 import java.util.LinkedList;
53 import java.util.List;
54
55 import static org.assertj.core.api.Assertions.assertThat;
56 import static org.mockito.ArgumentMatchers.anyMap;
57 import static org.mockito.ArgumentMatchers.eq;
58 import static org.mockito.Mockito.when;
59 import static org.mockito.MockitoAnnotations.initMocks;
60
61
62 @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
63 @WebAppConfiguration
64 public class MsoRestClientTest {
65
66
67     private final String baseUrl = "http://testURL/";
68
69     @Mock
70     private SyncRestClient client;
71
72     private MsoRestClientNew restClient;
73
74
75     @BeforeClass
76     private void setUp(){
77         initMocks(this);
78         restClient = new MsoRestClientNew(client,baseUrl,null);
79
80     }
81
82     @Test
83     public void shouldProperlyCreateServiceInstance() {
84         //  given
85         RequestDetails requestDetails = generateMockMsoRequest();
86
87         String endpoint = "testEndpoint";
88         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
89         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
90
91         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
92
93         //  when
94         MsoResponseWrapper response = restClient.createSvcInstance(requestDetails,endpoint);
95
96         //  then
97         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
98     }
99
100     @Test( expectedExceptions = MsoTestException.class)
101     public void shouldThrowExceptionWhenCreateSvcInstanceGetsWrongParameters() {
102         //  given
103         String endpoint = "";
104
105         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(null),eq(String.class) )  ).
106                 thenThrow(new MsoTestException("test-post-exception"));
107
108         //  when
109         restClient.createSvcInstance(null,endpoint);
110     }
111
112     @Test
113     public void shouldProperlyCreateE2eSvcInstance() {
114         //  given
115         RequestDetails requestDetails = generateMockMsoRequest();
116
117         String endpoint = "testEndpoint";
118         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
119         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
120
121         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
122
123         //  when
124         MsoResponseWrapper response = restClient.createE2eSvcInstance(requestDetails,endpoint);
125
126         //  then
127         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
128     }
129
130     @Test
131     public void shouldProperlyCreateVnf() {
132         //  given
133         RequestDetails requestDetails = generateMockMsoRequest();
134
135         String endpoint = "testEndpoint";
136         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
137         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
138
139         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
140
141         //  when
142         MsoResponseWrapper response = restClient.createVnf(requestDetails,endpoint);
143
144         //  then
145         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
146     }
147
148     @Test
149     public void shouldProperlyCreateNwInstance() {
150         //  given
151         RequestDetails requestDetails = generateMockMsoRequest();
152
153         String endpoint = "testEndpoint";
154         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
155         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
156
157         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
158
159         //  when
160         MsoResponseWrapper response = restClient.createNwInstance(requestDetails,endpoint);
161
162         //  then
163         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
164     }
165
166     @Test
167     public void shouldProperlyCreateVolumeGroupInstance() {
168         //  given
169         RequestDetails requestDetails = generateMockMsoRequest();
170
171         String endpoint = "testEndpoint";
172         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
173         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
174
175         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
176
177         //  when
178         MsoResponseWrapper response = restClient.createVolumeGroupInstance(requestDetails,endpoint);
179
180         //  then
181         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
182     }
183
184     @Test
185     public void shouldProperlyCreateVfModuleInstance() {
186         //  given
187         RequestDetails requestDetails = generateMockMsoRequest();
188
189         String endpoint = "testEndpoint";
190         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
191         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
192
193         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
194
195         //  when
196         MsoResponseWrapper response = restClient.createVfModuleInstance(requestDetails,endpoint);
197
198         //  then
199         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
200     }
201
202     @Test
203     public void shouldProperlyScaleOutVFModuleInstance() {
204         //  given
205         RequestDetails requestDetails = generateMockMsoRequest();
206
207         RequestDetailsWrapper<RequestDetails> wrappedRequestDetails = new RequestDetailsWrapper<>(requestDetails);
208         String endpoint = "testEndpoint";
209         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
210         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
211
212         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) )  ).thenReturn(httpResponse);
213
214         //  when
215         MsoResponseWrapper response = restClient.scaleOutVFModuleInstance(wrappedRequestDetails,endpoint);
216
217         //  then
218         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
219     }
220
221     @Test
222     public void shouldProperlyCreateConfigurationInstance() {
223         //  given
224         RequestDetails requestDetails = generateMockMsoRequest();
225
226         org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new  org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
227         String endpoint = "testEndpoint";
228         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
229         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
230
231         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) )  ).thenReturn(httpResponse);
232
233         //  when
234         MsoResponseWrapper response = restClient.createConfigurationInstance(wrappedRequestDetails,endpoint);
235
236         //  then
237         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
238     }
239
240     @Test
241     public void shouldProperlyDeleteE2eSvcInstance() {
242         //  given
243         RequestDetails requestDetails = generateMockMsoRequest();
244
245         org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new  org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
246         String endpoint = "testEndpoint";
247         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
248         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
249
250         when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) )  ).thenReturn(httpResponse);
251
252         //  when
253         MsoResponseWrapper response = restClient.deleteE2eSvcInstance(wrappedRequestDetails,endpoint);
254
255         //  then
256         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
257     }
258
259     @Test
260     public void shouldProperlyDeleteSvcInstance() {
261         //  given
262         RequestDetails requestDetails = generateMockMsoRequest();
263
264         String endpoint = "testEndpoint";
265         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
266         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
267
268         when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
269
270         //  when
271         MsoResponseWrapper response = restClient.deleteSvcInstance(requestDetails,endpoint);
272
273         //  then
274         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
275     }
276
277     @Test
278     public void shouldProperlyUnassignSvcInstance() {
279         //  given
280         RequestDetails requestDetails = generateMockMsoRequest();
281
282         String endpoint = "testEndpoint";
283         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
284         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
285
286         when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
287
288         //  when
289         MsoResponseWrapper response = restClient.unassignSvcInstance(requestDetails,endpoint);
290
291         //  then
292         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
293     }
294
295     @Test
296     public void shouldProperlyDeleteVnf() {
297         //  given
298         RequestDetails requestDetails = generateMockMsoRequest();
299
300         String endpoint = "testEndpoint";
301         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
302         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
303
304         when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
305
306         //  when
307         MsoResponseWrapper response = restClient.deleteVnf(requestDetails,endpoint);
308
309         //  then
310         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
311     }
312
313     @Test
314     public void shouldProperlyDeleteVfModule() {
315         //  given
316         RequestDetails requestDetails = generateMockMsoRequest();
317
318         String endpoint = "testEndpoint";
319         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
320         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
321
322         when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
323
324         //  when
325         MsoResponseWrapper response = restClient.deleteVfModule(requestDetails,endpoint);
326
327         //  then
328         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
329     }
330
331     @Test
332     public void shouldProperlyDeleteVolumeGroupInstance() {
333         //  given
334         RequestDetails requestDetails = generateMockMsoRequest();
335
336         String endpoint = "testEndpoint";
337         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
338         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
339
340         when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
341
342         //  when
343         MsoResponseWrapper response = restClient.deleteVolumeGroupInstance(requestDetails,endpoint);
344
345         //  then
346         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
347     }
348
349     @Test
350     public void shouldProperlyDeleteNwInstance() {
351         //  given
352         RequestDetails requestDetails = generateMockMsoRequest();
353
354         String endpoint = "testEndpoint";
355         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
356         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
357
358         when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) )  ).thenReturn(httpResponse);
359
360         //  when
361         MsoResponseWrapper response = restClient.deleteNwInstance(requestDetails,endpoint);
362
363         //  then
364         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
365     }
366
367     @Test
368     public void shouldProperlyGetOrchestrationRequest() {
369         //  given
370         RestObject restObject = generateMockMsoRestObject();
371
372         String endpoint = "testEndpoint";
373         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
374         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
375
376         when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) )  ).thenReturn(httpResponse);
377
378         //  when
379         MsoResponseWrapper response = restClient.getOrchestrationRequest(null,null,endpoint,restObject,true);
380
381         //  then
382         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
383     }
384
385     @Test
386     public void shouldProperlyGetOrchestrationRequestWithOnlyEndpoint() {
387         //  given
388         String endpoint = "testEndpoint";
389         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
390         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
391
392         when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) )  ).thenReturn(httpResponse);
393
394         //  when
395         MsoResponseWrapper response = restClient.getOrchestrationRequest(endpoint);
396
397         //  then
398         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
399     }
400
401     @Test
402     public void shouldProperlyGetManualTasks() {
403         //  given
404         String endpoint = "testEndpoint";
405         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
406         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
407
408         when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) )  ).thenReturn(httpResponse);
409
410         //  when
411         MsoResponseWrapper response = restClient.getManualTasks(endpoint);
412
413         //  then
414         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
415     }
416
417     @Test
418     public void shouldProperlyGetManualTasksByRequestId() {
419         //  given
420         RestObject restObject = generateMockMsoRestObject();
421
422         String endpoint = "testEndpoint";
423         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
424         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
425
426         /// WUT 'baseUrl+baseUrl+endpoint'
427         when( client.get( eq(baseUrl+baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) )  ).thenReturn(httpResponse);
428
429         //  when
430         MsoResponseWrapper response = restClient.getManualTasksByRequestId(null,null,endpoint,restObject);
431
432         //  then
433         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
434     }
435
436     @Test(expectedExceptions = MsoTestException.class)
437     public void shouldThrowExceptionWhenGetManualTasksByRequestIdGetsWrongParameter() {
438         //  given
439         when( client.get( eq(baseUrl+baseUrl),anyMap(),anyMap(),eq(String.class) )  ).thenThrow(new MsoTestException("testsException"));
440
441         //  when
442         restClient.getManualTasksByRequestId(null,null,"",null);
443     }
444
445     @Test
446     public void shouldProperlyCompleteManualTask() {
447         //  given
448         RequestDetails requestDetails = generateMockMsoRequest();
449         RestObject restObject = generateMockMsoRestObject();
450
451         String endpoint = "testEndpoint";
452         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
453         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
454
455         when( client.post( eq(baseUrl+endpoint), anyMap(), eq(requestDetails), eq(String.class) )  ).thenReturn(httpResponse);
456
457         //  when
458         MsoResponseWrapper response = restClient.completeManualTask(requestDetails,null,null,endpoint,restObject);
459
460         //  then
461         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
462     }
463
464     @Test(expectedExceptions = MsoTestException.class)
465     public void shouldThrowExceptionWhenCompleteManualTaskWrongParameter() {
466         //  given
467         when( client.post( eq(baseUrl),anyMap(),eq(null), eq(String.class) )  ).thenThrow(new MsoTestException("testsException"));
468
469         //  when
470         restClient.completeManualTask(null, null,null,"",null);
471     }
472
473     @Test
474     public void shouldProperlyReplaceVnf() {
475         //  given
476         org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest();
477
478         String endpoint = "testEndpoint";
479         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
480         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
481
482         when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) )  ).thenReturn(httpResponse);
483
484         //  when
485         MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
486
487         //  then
488         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
489     }
490
491     @Test
492     public void shouldProperlyReplaceVnfWithStatus202() {
493         //  given
494         org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest();
495
496         String endpoint = "testEndpoint";
497         HttpResponse<String> httpResponse = createOkResponse();
498         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
499
500         when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) )  ).thenReturn(httpResponse);
501
502         //  when
503         MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
504
505         //  then
506         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
507     }
508
509     @Test( expectedExceptions = MsoTestException.class)
510     public void shouldThrowExceptionWhenReplaceVnfGetsWrongParameters() {
511         //  given
512         org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest();
513
514         when( client.post( eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) )  ).thenThrow(new MsoTestException("test-post-exception"));
515
516         //  when
517         restClient.replaceVnf(requestDetails, "");
518     }
519
520     @Test
521     public void shouldProperlyDeleteConfiguration() {
522         //  given
523         org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest();
524         org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
525
526         String endpoint = "testEndpoint";
527         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
528         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
529
530         when( client.delete( eq(baseUrl+endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class) )  ).thenReturn(httpResponse);
531
532         //  when
533         MsoResponseWrapper response = restClient.deleteConfiguration(requestDetailsWrapper,endpoint);
534
535         //  then
536         assertThat(response).isEqualToComparingFieldByField(expectedResponse);
537     }
538
539     @Test( expectedExceptions = MsoTestException.class )
540     public void shouldThrowExceptionWhenProperlyDeleteConfigurationGetsWrongParameters() {
541         //  given
542         when( client.delete( eq(baseUrl), anyMap(), eq(null), eq(String.class) )  ).thenThrow(new MsoTestException("test-delete-exception"));
543
544         //  when
545         restClient.deleteConfiguration(null,"");
546     }
547
548     @Test
549     public void shouldProperlySetConfigurationActiveStatus() {
550         //  given
551         RequestDetails requestDetails = generateMockMsoRequest();
552
553         String endpoint = "testEndpoint";
554         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
555         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
556
557         when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
558
559         //  when
560         MsoResponseWrapper response = restClient.setConfigurationActiveStatus(requestDetails, endpoint);
561
562         //  then
563         assertThat(expectedResponse).isEqualToComparingFieldByField(response);
564     }
565
566     @Test(expectedExceptions = MsoTestException.class)
567     public void shouldThrowExceptionWhenSetConfigurationActiveStatusGetsWrongParameters() {
568         //  given
569
570         when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
571
572         //  when
573         restClient.setConfigurationActiveStatus(null, "");
574     }
575
576     @Test
577     public void shouldProperlySetPortOnConfigurationStatus() {
578         //  given
579         RequestDetails requestDetails = generateMockMsoRequest();
580
581         String endpoint = "testEndpoint";
582         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
583         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
584
585         when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
586
587         //  when
588         MsoResponseWrapper response = restClient.setPortOnConfigurationStatus(requestDetails, endpoint);
589
590         //  then
591         assertThat(expectedResponse).isEqualToComparingFieldByField(response);
592     }
593
594     @Test(expectedExceptions = MsoTestException.class)
595     public void shouldThrowExceptionWhenSetPortOnConfigurationStatusGetsWrongParameters() {
596         //  given
597         String endpoint = "";
598
599         when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
600
601         //  when
602         restClient.setPortOnConfigurationStatus(null, endpoint);
603     }
604
605     @Test
606     public void shouldProperlyChangeManagementUpdate() {
607         //  given
608         RequestDetails requestDetails = generateMockMsoRequest();
609         RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
610
611         String endpoint = "testEndpoint";
612         HttpResponse<RequestReferencesContainer> httpResponse = HttpResponse.fallback(
613                 new RequestReferencesContainer(
614                         new RequestReferences()));
615
616         MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse);
617
618         when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(RequestReferencesContainer.class))).thenReturn(httpResponse);
619
620         //  when
621         MsoResponseWrapperInterface response = restClient.changeManagementUpdate(requestDetailsWrapper, endpoint);
622
623         //  then
624         assertThat(expectedResponse).isEqualToComparingFieldByField(response);
625     }
626
627     @Test
628     public void shouldProperlyUpdateVnfAndUpdateInstance() {
629         //  given
630         org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest();
631
632         String endpoint = "testEndpoint";
633         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
634         MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse);
635
636
637         when(client.put(eq(baseUrl + endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenReturn(httpResponse);
638
639         //  when
640         MsoResponseWrapperInterface response = restClient.updateVnf(requestDetails, endpoint);
641
642         //  then
643         assertThat(expectedResponse).isEqualToComparingFieldByField(response);
644     }
645
646     @Test( expectedExceptions = MsoTestException.class )
647     public void shouldThrowExceptionWhenUpdateVnfAndUpdateInstanceGetsWrongParameter() {
648         //  given
649         org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest();
650         String endpoint = "";
651
652         when(client.put(eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
653
654         //  when
655         restClient.updateVnf(requestDetails, endpoint);
656
657         //  then
658     }
659
660     @Test
661     public void shouldProperlySetServiceInstanceStatus() {
662         //  given
663         RequestDetails requestDetails = generateMockMsoRequest();
664         RestObject<String> restObject = generateMockMsoRestObject();
665
666         String endpoint = "testEndpoint";
667         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
668
669         when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
670
671         //  when
672         restClient.setServiceInstanceStatus(requestDetails,"", "", endpoint, restObject);
673     }
674
675     @Test( expectedExceptions = MsoTestException.class)
676     public void shouldThrowExceptionWhenSetServiceInstanceStatusGetsWrongParameter() {
677         //  given
678         String endpoint = "";
679
680         when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
681
682         //  when
683         restClient.setServiceInstanceStatus(null,"", "", endpoint, null);
684     }
685
686     @Test
687     public void shouldProperlyRemoveRelationshipFromServiceInstance() {
688         //  given
689         RequestDetails requestDetails = generateMockMsoRequest();
690
691         String endpoint = "testEndpoint";
692         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
693         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
694
695         when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
696
697         //  when
698         MsoResponseWrapper response = restClient.removeRelationshipFromServiceInstance(requestDetails, endpoint);
699
700         //  then
701         assertThat(expectedResponse).isEqualToComparingFieldByField(response);
702     }
703
704     @Test( expectedExceptions = MsoTestException.class)
705     public void shouldThrowExceptionWhenRemoveRelationshipFromServiceInstanceGetsWrongParameter() {
706         //  given
707         String endpoint = "";
708
709         when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
710
711         //  when
712         restClient.removeRelationshipFromServiceInstance(null,endpoint);
713     }
714
715     @Test
716     public void shouldProperlyAddRelationshipToServiceInstance() {
717         //  given
718         RequestDetails requestDetails = generateMockMsoRequest();
719
720         String endpoint = "testEndpoint";
721         HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
722         MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
723
724         when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
725
726         //  when
727         MsoResponseWrapper response = restClient.addRelationshipToServiceInstance(requestDetails, endpoint);
728
729         //  then
730         assertThat(expectedResponse).isEqualToComparingFieldByField(response);
731     }
732
733     @Test( expectedExceptions = MsoTestException.class)
734     public void shouldThrowExceptionWhenAddRelationshipToServiceInstanceGetsWrongParameter() {
735         //  given
736         String endpoint = "";
737
738         when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
739
740         //  when
741         restClient.addRelationshipToServiceInstance(null,endpoint);
742     }
743
744     @Test
745     public void shouldProperlyPerformGetRequest() {
746         //  given
747         String endpoint = "testEndpoint";
748         HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
749
750         when(client.get(eq(baseUrl + endpoint), anyMap(), anyMap(), eq(String.class))).thenReturn(expectedResponse);
751
752         //  when
753         HttpResponse<String>  response = restClient.get(endpoint, String.class);
754
755         //  then
756         assertThat(expectedResponse).isEqualToComparingFieldByField(response);
757     }
758
759     @Test
760     public void shouldProperlyPerformPostRequest() {
761         //  given
762
763         RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(generateMockMsoRequest());
764
765         String endpoint = "testEndpoint";
766         HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
767
768         when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class))).thenReturn(expectedResponse);
769
770         //  when
771         HttpResponse<String>  response = restClient.post(endpoint,requestDetailsWrapper, String.class);
772
773         //  then
774         assertThat(expectedResponse).isEqualToComparingFieldByField(response);
775     }
776
777     private class MsoTestException extends RuntimeException{
778         MsoTestException(String testException) {
779             super(testException);
780         }
781     }
782
783     private HttpResponse<String> createOkResponse() {
784         StatusLine statusline = new BasicStatusLine(
785                 new ProtocolVersion("http",1,1), 202, "acceptResponse");
786
787         org.apache.http.HttpResponse responseBase = new BasicHttpResponse(statusline);
788
789         return new HttpResponse<>(responseBase ,String.class, new JsonMapper());
790     }
791
792     private RequestDetails generateMockMsoRequest() {
793         RequestDetails requestDetails = new RequestDetails();
794
795         CloudConfiguration cloudConfiguration = new CloudConfiguration();
796         cloudConfiguration.setTenantId("tenant-id");
797         cloudConfiguration.setLcpCloudRegionId("lcp-region");
798         requestDetails.setCloudConfiguration(cloudConfiguration);
799
800         ModelInfo modelInfo = new ModelInfo();
801         modelInfo.setModelInvariantId("model-invarient-id");
802         modelInfo.setModelCustomizationName("modelCustomizationName");
803         modelInfo.setModelType("test-model-type");
804         requestDetails.setModelInfo(modelInfo);
805
806         RequestInfo requestInfo = new RequestInfo();
807         requestInfo.setRequestorId("ok883e");
808         requestInfo.setSource("VID");
809         requestDetails.setRequestInfo(requestInfo);
810         RequestParameters requestParameters = new RequestParameters();
811
812         requestParameters.setSubscriptionServiceType("subscriber-service-type");
813         requestParameters.setAdditionalProperty("a", 1);
814         requestParameters.setAdditionalProperty("b", 2);
815         requestParameters.setAdditionalProperty("c", 3);
816         requestParameters.setAdditionalProperty("d", 4);
817         String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}";
818         requestParameters.setAdditionalProperty("payload", payload);
819
820         requestDetails.setRequestParameters(requestParameters);
821         return requestDetails;
822     }
823
824     private org.onap.vid.changeManagement.RequestDetails generateChangeManagementMockMsoRequest() {
825         List<RelatedInstanceList> relatedInstances = new LinkedList<>();
826         relatedInstances.add(new RelatedInstanceList());
827
828         org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
829
830         requestDetails.setVnfName("test-vnf-name");
831         requestDetails.setVnfInstanceId("test-vnf-instance_id");
832         requestDetails.setRelatedInstList(relatedInstances);
833
834         CloudConfiguration cloudConfiguration = new CloudConfiguration();
835         cloudConfiguration.setTenantId("tenant-id");
836         cloudConfiguration.setLcpCloudRegionId("lcp-region");
837         requestDetails.setCloudConfiguration(cloudConfiguration);
838
839         ModelInfo modelInfo = new ModelInfo();
840         modelInfo.setModelInvariantId("model-invarient-id");
841         modelInfo.setModelCustomizationName("modelCustomizationName");
842         modelInfo.setModelType("test-model-type");
843         requestDetails.setModelInfo(modelInfo);
844
845         RequestInfo requestInfo = new RequestInfo();
846         requestInfo.setRequestorId("ok883e");
847         requestInfo.setSource("VID");
848         requestDetails.setRequestInfo(requestInfo);
849
850         RequestParameters requestParameters = new RequestParameters();
851         requestParameters.setSubscriptionServiceType("subscriber-service-type");
852         requestParameters.setAdditionalProperty("a", 1);
853         requestParameters.setAdditionalProperty("b", 2);
854         requestParameters.setAdditionalProperty("c", 3);
855         requestParameters.setAdditionalProperty("d", 4);
856         String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}";
857         requestParameters.setAdditionalProperty("payload", payload);
858
859         requestDetails.setRequestParameters(requestParameters);
860         return requestDetails;
861     }
862
863     private RestObject<String> generateMockMsoRestObject() {
864         RestObject<String> restObject = new RestObject<>();
865
866         restObject.set("test-rest-object-body");
867         restObject.setRaw("test-rest-object-raw-string");
868         restObject.setStatusCode(202);
869         return restObject;
870     }
871 }