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