2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.vid.mso.rest;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.hamcrest.Matchers.allOf;
25 import static org.hamcrest.Matchers.hasEntry;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.anyMap;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.Mockito.when;
30 import static org.mockito.MockitoAnnotations.initMocks;
32 import io.joshworks.restclient.http.HttpResponse;
33 import io.joshworks.restclient.http.JsonMapper;
34 import org.apache.http.ProtocolVersion;
35 import org.apache.http.StatusLine;
36 import org.apache.http.message.BasicHttpResponse;
37 import org.apache.http.message.BasicStatusLine;
38 import org.jetbrains.annotations.NotNull;
39 import org.mockito.Mock;
40 import org.onap.portalsdk.core.util.SystemProperties;
41 import org.onap.vid.changeManagement.RequestDetailsWrapper;
42 import org.onap.vid.changeManagement.RequestParameters;
43 import org.onap.vid.changeManagement.WorkflowRequestDetail;
44 import org.onap.vid.client.SyncRestClient;
45 import org.onap.vid.controller.LocalWebConfig;
46 import org.onap.vid.model.RequestReferencesContainer;
47 import org.onap.vid.mso.MsoProperties;
48 import org.onap.vid.mso.MsoResponseWrapper;
49 import org.onap.vid.mso.MsoResponseWrapperInterface;
50 import org.onap.vid.mso.MsoUtil;
51 import org.onap.vid.mso.RestObject;
52 import org.onap.vid.mso.model.CloudConfiguration;
53 import org.onap.vid.mso.model.RequestReferences;
54 import org.onap.vid.utils.SystemPropertiesWrapper;
55 import org.springframework.test.context.ContextConfiguration;
56 import org.springframework.test.context.web.WebAppConfiguration;
57 import org.testng.annotations.BeforeClass;
58 import org.testng.annotations.Test;
60 import java.util.ArrayList;
61 import java.util.HashMap;
62 import java.util.List;
64 import java.util.UUID;
66 import static org.mockito.ArgumentMatchers.refEq;
67 import static org.mockito.hamcrest.MockitoHamcrest.argThat;
70 @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
72 public class MsoRestClientTest {
75 private final String baseUrl = "http://testURL/";
78 private SyncRestClient client;
81 private SystemPropertiesWrapper systemProperties;
83 private MsoRestClientNew restClient;
89 when(systemProperties.getProperty(MsoProperties.MSO_PASSWORD)).thenReturn("OBF:1ghz1kfx1j1w1m7w1i271e8q1eas1hzj1m4i1iyy1kch1gdz");
90 when(systemProperties.getProperty("app_display_name")).thenReturn("vid");
91 restClient = new MsoRestClientNew(client,baseUrl,null,systemProperties);
95 public void shouldProperlyCreateServiceInstance() {
97 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
99 String endpoint = "testEndpoint";
100 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
101 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
103 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
106 MsoResponseWrapper response = restClient.createSvcInstance(requestDetails,endpoint);
109 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
112 @Test( expectedExceptions = MsoTestException.class)
113 public void shouldThrowExceptionWhenCreateSvcInstanceGetsWrongParameters() {
115 String endpoint = "";
117 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(null),eq(String.class) ) ).
118 thenThrow(new MsoTestException("test-post-exception"));
121 restClient.createSvcInstance(null,endpoint);
125 public void shouldProperlyCreateE2eSvcInstance() {
127 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
129 String endpoint = "testEndpoint";
130 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
131 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
133 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
136 MsoResponseWrapper response = restClient.createE2eSvcInstance(requestDetails,endpoint);
139 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
143 public void shouldProperlyCreateVnf() {
145 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
147 String endpoint = "testEndpoint";
148 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
149 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
151 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
154 MsoResponseWrapper response = restClient.createVnf(requestDetails,endpoint);
157 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
161 public void shouldProperlyCreateNwInstance() {
163 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
165 String endpoint = "testEndpoint";
166 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
167 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
169 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
172 MsoResponseWrapper response = restClient.createNwInstance(requestDetails,endpoint);
175 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
179 public void shouldProperlyCreateVolumeGroupInstance() {
181 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
183 String endpoint = "testEndpoint";
184 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
185 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
187 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
190 MsoResponseWrapper response = restClient.createVolumeGroupInstance(requestDetails,endpoint);
193 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
197 public void shouldProperlyCreateVfModuleInstance() {
199 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
201 String endpoint = "testEndpoint";
202 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
203 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
205 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
208 MsoResponseWrapper response = restClient.createVfModuleInstance(requestDetails,endpoint);
211 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
215 public void shouldProperlyScaleOutVFModuleInstance() {
217 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
219 RequestDetailsWrapper<RequestDetails> wrappedRequestDetails = new RequestDetailsWrapper<>(requestDetails);
220 String endpoint = "testEndpoint";
221 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
222 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
224 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
227 MsoResponseWrapper response = restClient.scaleOutVFModuleInstance(wrappedRequestDetails,endpoint);
230 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
234 public void shouldProperlyCreateConfigurationInstance() {
236 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
238 org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
239 String endpoint = "testEndpoint";
240 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
241 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
243 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
246 MsoResponseWrapper response = restClient.createConfigurationInstance(wrappedRequestDetails,endpoint);
249 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
253 public void shouldProperlyDeleteE2eSvcInstance() {
255 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
257 org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
258 String endpoint = "testEndpoint";
259 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
260 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
262 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
265 MsoResponseWrapper response = restClient.deleteE2eSvcInstance(wrappedRequestDetails,endpoint);
268 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
272 public void shouldProperlyDeleteSvcInstance() {
274 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
276 String endpoint = "testEndpoint";
277 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
278 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
280 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
283 MsoResponseWrapper response = restClient.deleteSvcInstance(requestDetails,endpoint);
286 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
290 public void shouldProperlyUnassignSvcInstance() {
292 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
294 String endpoint = "testEndpoint";
295 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
296 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
298 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
301 MsoResponseWrapper response = restClient.unassignSvcInstance(requestDetails,endpoint);
304 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
308 public void shouldProperlyDeleteVnf() {
310 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
312 String endpoint = "testEndpoint";
313 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
314 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
316 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
319 MsoResponseWrapper response = restClient.deleteVnf(requestDetails,endpoint);
322 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
326 public void shouldProperlyDeleteVfModule() {
328 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
330 String endpoint = "testEndpoint";
331 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
332 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
334 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
337 MsoResponseWrapper response = restClient.deleteVfModule(requestDetails,endpoint);
340 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
344 public void shouldProperlyDeleteVolumeGroupInstance() {
346 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
348 String endpoint = "testEndpoint";
349 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
350 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
352 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
355 MsoResponseWrapper response = restClient.deleteVolumeGroupInstance(requestDetails,endpoint);
358 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
362 public void shouldProperlyDeleteNwInstance() {
364 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
366 String endpoint = "testEndpoint";
367 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
368 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
370 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
373 MsoResponseWrapper response = restClient.deleteNwInstance(requestDetails,endpoint);
376 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
380 public void shouldProperlyGetOrchestrationRequest() {
382 RestObject restObject = generateMockMsoRestObject();
384 String endpoint = "testEndpoint";
385 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
386 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
388 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
391 MsoResponseWrapper response = restClient.getOrchestrationRequest(null,null,endpoint,restObject,true);
394 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
398 public void shouldProperlyGetOrchestrationRequestWithOnlyEndpoint() {
400 String endpoint = "testEndpoint";
401 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
402 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
404 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
407 MsoResponseWrapper response = restClient.getOrchestrationRequest(endpoint);
410 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
414 public void shouldProperlyGetManualTasksByRequestId() {
416 RestObject restObject = generateMockMsoRestObject();
418 String endpoint = "testEndpoint";
419 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
420 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
422 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
425 MsoResponseWrapper response = restClient.getManualTasksByRequestId(null,null,endpoint,restObject);
428 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
431 @Test(expectedExceptions = MsoTestException.class)
432 public void shouldThrowExceptionWhenGetManualTasksByRequestIdGetsWrongParameter() {
434 when( client.get( eq(baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
437 restClient.getManualTasksByRequestId(null,null,"",null);
441 public void shouldProperlyCompleteManualTask() {
443 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
444 RestObject restObject = generateMockMsoRestObject();
446 String endpoint = "testEndpoint";
447 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
448 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
450 when( client.post( eq(baseUrl+endpoint), anyMap(), eq(requestDetails), eq(String.class) ) ).thenReturn(httpResponse);
453 MsoResponseWrapper response = restClient.completeManualTask(requestDetails,null,null,endpoint,restObject);
456 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
459 @Test(expectedExceptions = MsoTestException.class)
460 public void shouldThrowExceptionWhenCompleteManualTaskWrongParameter() {
462 when( client.post( eq(baseUrl),anyMap(),eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
465 restClient.completeManualTask(null, null,null,"",null);
469 public void shouldProperlyReplaceVnf() {
471 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
473 String endpoint = "testEndpoint";
474 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
475 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
477 when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse);
480 MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
483 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
487 public void shouldProperlyReplaceVnfWithStatus202() {
489 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
491 String endpoint = "testEndpoint";
492 HttpResponse<String> httpResponse = createOkResponse();
493 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
495 when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse);
498 MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
501 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
504 @Test( expectedExceptions = MsoTestException.class)
505 public void shouldThrowExceptionWhenReplaceVnfGetsWrongParameters() {
507 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
509 when( client.post( eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenThrow(new MsoTestException("test-post-exception"));
512 restClient.replaceVnf(requestDetails, "");
516 public void shouldProperlyDeleteConfiguration() {
518 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
519 org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
521 String endpoint = "testEndpoint";
522 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
523 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
525 when( client.delete( eq(baseUrl+endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class) ) ).thenReturn(httpResponse);
528 MsoResponseWrapper response = restClient.deleteConfiguration(requestDetailsWrapper,endpoint);
531 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
534 @Test( expectedExceptions = MsoTestException.class )
535 public void shouldThrowExceptionWhenProperlyDeleteConfigurationGetsWrongParameters() {
537 when( client.delete( eq(baseUrl), anyMap(), eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("test-delete-exception"));
540 restClient.deleteConfiguration(null,"");
544 public void shouldProperlySetConfigurationActiveStatus() {
546 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
548 String endpoint = "testEndpoint";
549 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
550 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
552 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
555 MsoResponseWrapper response = restClient.setConfigurationActiveStatus(requestDetails, endpoint);
558 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
561 @Test(expectedExceptions = MsoTestException.class)
562 public void shouldThrowExceptionWhenSetConfigurationActiveStatusGetsWrongParameters() {
565 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
568 restClient.setConfigurationActiveStatus(null, "");
572 public void shouldProperlySetPortOnConfigurationStatus() {
574 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
576 String endpoint = "testEndpoint";
577 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
578 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
580 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
583 MsoResponseWrapper response = restClient.setPortOnConfigurationStatus(requestDetails, endpoint);
586 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
589 @Test(expectedExceptions = MsoTestException.class)
590 public void shouldThrowExceptionWhenSetPortOnConfigurationStatusGetsWrongParameters() {
592 String endpoint = "";
594 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
597 restClient.setPortOnConfigurationStatus(null, endpoint);
601 public void shouldProperlyChangeManagementUpdate() {
603 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
604 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
606 String endpoint = "testEndpoint";
607 HttpResponse<RequestReferencesContainer> httpResponse = HttpResponse.fallback(
608 new RequestReferencesContainer(
609 new RequestReferences()));
611 MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse);
613 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(RequestReferencesContainer.class))).thenReturn(httpResponse);
616 MsoResponseWrapperInterface response = restClient.changeManagementUpdate(requestDetailsWrapper, endpoint);
619 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
623 public void shouldProperlyUpdateVnfAndUpdateInstance() {
625 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
627 String endpoint = "testEndpoint";
628 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
629 MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse);
632 when(client.put(eq(baseUrl + endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenReturn(httpResponse);
635 MsoResponseWrapperInterface response = restClient.updateVnf(requestDetails, endpoint);
638 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
641 @Test( expectedExceptions = MsoTestException.class )
642 public void shouldThrowExceptionWhenUpdateVnfAndUpdateInstanceGetsWrongParameter() {
644 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
645 String endpoint = "";
647 when(client.put(eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
650 restClient.updateVnf(requestDetails, endpoint);
656 public void shouldProperlySetServiceInstanceStatus() {
658 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
659 RestObject<String> restObject = generateMockMsoRestObject();
661 String endpoint = "testEndpoint";
662 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
664 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
667 restClient.setServiceInstanceStatus(requestDetails,"", "", endpoint, restObject);
670 @Test( expectedExceptions = MsoTestException.class)
671 public void shouldThrowExceptionWhenSetServiceInstanceStatusGetsWrongParameter() {
673 String endpoint = "";
675 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
678 restClient.setServiceInstanceStatus(null,"", "", endpoint, null);
682 public void shouldProperlyRemoveRelationshipFromServiceInstance() {
684 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
686 String endpoint = "testEndpoint";
687 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
688 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
690 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
693 MsoResponseWrapper response = restClient.removeRelationshipFromServiceInstance(requestDetails, endpoint);
696 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
699 @Test( expectedExceptions = MsoTestException.class)
700 public void shouldThrowExceptionWhenRemoveRelationshipFromServiceInstanceGetsWrongParameter() {
702 String endpoint = "";
704 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
707 restClient.removeRelationshipFromServiceInstance(null,endpoint);
711 public void shouldProperlyAddRelationshipToServiceInstance() {
713 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
715 String endpoint = "testEndpoint";
716 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
717 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
719 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
722 MsoResponseWrapper response = restClient.addRelationshipToServiceInstance(requestDetails, endpoint);
725 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
728 @Test( expectedExceptions = MsoTestException.class)
729 public void shouldThrowExceptionWhenAddRelationshipToServiceInstanceGetsWrongParameter() {
731 String endpoint = "";
733 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
736 restClient.addRelationshipToServiceInstance(null,endpoint);
740 public void shouldProperlyPerformGetRequest() {
742 String endpoint = "testEndpoint";
743 HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
745 when(client.get(eq(baseUrl + endpoint), anyMap(), anyMap(), eq(String.class))).thenReturn(expectedResponse);
748 HttpResponse<String> response = restClient.get(endpoint, String.class);
751 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
755 public void shouldProperlyPerformPostRequest() {
758 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(MsoRestClientTestUtil.generateMockMsoRequest());
760 String endpoint = "testEndpoint";
761 HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
763 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class))).thenReturn(expectedResponse);
766 HttpResponse<String> response = restClient.post(endpoint,requestDetailsWrapper, String.class);
769 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
773 public void shouldProperlyInvokeWorkflows() {
775 String endpoint = "testPath";
776 HttpResponse expectedResponse = createOkResponse();
778 WorkflowRequestDetail workflowRequestDetail = MsoRestClientTestUtil.createWorkflowRequestDetail();
780 RequestDetailsWrapper<WorkflowRequestDetail> requestDetailsWrapper = new RequestDetailsWrapper<>(workflowRequestDetail);
782 UUID requestId = UUID.randomUUID();
784 when(client.post(eq(baseUrl + endpoint), argThat(allOf(hasEntry("X-ONAP-RequestID", requestId.toString()),hasEntry("Content-Type", "application/json"))), refEq(requestDetailsWrapper))).
785 thenReturn(expectedResponse);
787 Map<String,String> extraHeaders = new HashMap<>();
788 extraHeaders.put("X-ONAP-RequestID",requestId.toString());
789 extraHeaders.put("X-ONAP-PartnerName","VID");
790 extraHeaders.put("X-RequestorID","testRequester");
793 MsoResponseWrapper response = restClient.invokeWorkflow(workflowRequestDetail, endpoint, extraHeaders);
796 assertThat(response).isEqualToComparingFieldByField(MsoUtil.wrapResponse(expectedResponse));
800 private class MsoTestException extends RuntimeException{
801 MsoTestException(String testException) {
802 super(testException);
806 private HttpResponse<String> createOkResponse() {
807 StatusLine statusline = new BasicStatusLine(
808 new ProtocolVersion("http",1,1), 202, "acceptResponse");
810 org.apache.http.HttpResponse responseBase = new BasicHttpResponse(statusline);
812 return new HttpResponse<>(responseBase ,String.class, new JsonMapper());
815 private RestObject<String> generateMockMsoRestObject() {
816 RestObject<String> restObject = new RestObject<>();
818 restObject.set("test-rest-object-body");
819 restObject.setRaw("test-rest-object-raw-string");
820 restObject.setStatusCode(202);