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