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.ArgumentMatchers.refEq;
30 import static org.mockito.Mockito.when;
31 import static org.mockito.MockitoAnnotations.initMocks;
32 import static org.mockito.hamcrest.MockitoHamcrest.argThat;
33 import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
35 import com.fasterxml.jackson.core.JsonProcessingException;
36 import io.joshworks.restclient.http.HttpResponse;
37 import io.joshworks.restclient.http.JsonMapper;
38 import java.util.HashMap;
40 import java.util.UUID;
41 import org.apache.http.ProtocolVersion;
42 import org.apache.http.StatusLine;
43 import org.apache.http.message.BasicHttpResponse;
44 import org.apache.http.message.BasicStatusLine;
45 import org.mockito.Mock;
46 import org.onap.portalsdk.core.util.SystemProperties;
47 import org.onap.vid.aai.HttpResponseWithRequestInfo;
48 import org.onap.vid.changeManagement.RequestDetailsWrapper;
49 import org.onap.vid.changeManagement.WorkflowRequestDetail;
50 import org.onap.vid.client.SyncRestClient;
51 import org.onap.vid.controller.LocalWebConfig;
52 import org.onap.vid.model.RequestReferencesContainer;
53 import org.onap.vid.mso.MsoProperties;
54 import org.onap.vid.mso.MsoResponseWrapper;
55 import org.onap.vid.mso.MsoResponseWrapperInterface;
56 import org.onap.vid.mso.MsoUtil;
57 import org.onap.vid.mso.RestObject;
58 import org.onap.vid.mso.model.RequestReferences;
59 import org.onap.vid.utils.Logging;
60 import org.onap.vid.utils.SystemPropertiesWrapper;
61 import org.springframework.http.HttpMethod;
62 import org.springframework.test.context.ContextConfiguration;
63 import org.springframework.test.context.web.WebAppConfiguration;
64 import org.testng.annotations.BeforeClass;
65 import org.testng.annotations.Test;
68 @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
70 public class MsoRestClientTest {
73 private final String baseUrl = "http://testURL/";
76 private SyncRestClient client;
79 private SystemPropertiesWrapper systemProperties;
82 private Logging loggingService;
84 private MsoRestClientNew restClient;
90 when(systemProperties.getProperty(MsoProperties.MSO_PASSWORD)).thenReturn("OBF:1ghz1kfx1j1w1m7w1i271e8q1eas1hzj1m4i1iyy1kch1gdz");
91 when(systemProperties.getProperty("app_display_name")).thenReturn("vid");
92 restClient = new MsoRestClientNew(client, baseUrl, systemProperties);
96 public void shouldProperlyCreateServiceInstance() {
98 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
100 String endpoint = "testEndpoint";
101 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
102 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
104 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
107 MsoResponseWrapper response = restClient.createSvcInstance(requestDetails,endpoint);
110 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
113 @Test( expectedExceptions = MsoTestException.class)
114 public void shouldThrowExceptionWhenCreateSvcInstanceGetsWrongParameters() {
116 String endpoint = "";
118 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(null),eq(String.class) ) ).
119 thenThrow(new MsoTestException("test-post-exception"));
122 restClient.createSvcInstance(null,endpoint);
126 public void shouldProperlyCreateE2eSvcInstance() {
128 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
130 String endpoint = "testEndpoint";
131 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
132 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
134 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
137 MsoResponseWrapper response = restClient.createE2eSvcInstance(requestDetails,endpoint);
140 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
144 public void shouldProperlyCreateVnf() {
146 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
148 String endpoint = "testEndpoint";
149 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
150 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
152 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
155 MsoResponseWrapper response = restClient.createVnf(requestDetails,endpoint);
158 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
162 public void shouldProperlyCreateNwInstance() {
164 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
166 String endpoint = "testEndpoint";
167 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
168 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
170 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
173 MsoResponseWrapper response = restClient.createNwInstance(requestDetails,endpoint);
176 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
180 public void shouldProperlyCreateVolumeGroupInstance() {
182 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
184 String endpoint = "testEndpoint";
185 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
186 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
188 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
191 MsoResponseWrapper response = restClient.createVolumeGroupInstance(requestDetails,endpoint);
194 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
198 public void shouldProperlyCreateVfModuleInstance() {
200 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
202 String endpoint = "testEndpoint";
203 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
204 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
206 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
209 MsoResponseWrapper response = restClient.createVfModuleInstance(requestDetails,endpoint);
212 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
216 public void shouldProperlyScaleOutVFModuleInstance() {
218 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
220 RequestDetailsWrapper<RequestDetails> wrappedRequestDetails = new RequestDetailsWrapper<>(requestDetails);
221 String endpoint = "testEndpoint";
222 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
223 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
225 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
228 MsoResponseWrapper response = restClient.scaleOutVFModuleInstance(wrappedRequestDetails,endpoint);
231 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
235 public void shouldProperlyCreateConfigurationInstance() {
237 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
239 org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
240 String endpoint = "testEndpoint";
241 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
242 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
244 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
247 MsoResponseWrapper response = restClient.createConfigurationInstance(wrappedRequestDetails,endpoint);
250 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
254 public void shouldProperlyDeleteE2eSvcInstance() {
256 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
258 org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
259 String endpoint = "testEndpoint";
260 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
261 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
263 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
266 MsoResponseWrapper response = restClient.deleteE2eSvcInstance(wrappedRequestDetails,endpoint);
269 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
273 public void shouldProperlyDeleteSvcInstance() {
275 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
277 String endpoint = "testEndpoint";
278 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
279 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
281 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
284 MsoResponseWrapper response = restClient.deleteSvcInstance(requestDetails,endpoint);
287 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
291 public void shouldProperlyUnassignSvcInstance() {
293 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
295 String endpoint = "testEndpoint";
296 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
297 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
299 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
302 MsoResponseWrapper response = restClient.unassignSvcInstance(requestDetails,endpoint);
305 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
309 public void shouldProperlyDeleteVnf() {
311 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
313 String endpoint = "testEndpoint";
314 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
315 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
317 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
320 MsoResponseWrapper response = restClient.deleteVnf(requestDetails,endpoint);
323 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
327 public void shouldProperlyDeleteVfModule() {
329 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
331 String endpoint = "testEndpoint";
332 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
333 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
335 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
338 MsoResponseWrapper response = restClient.deleteVfModule(requestDetails,endpoint);
341 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
345 public void shouldProperlyDeleteVolumeGroupInstance() {
347 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
349 String endpoint = "testEndpoint";
350 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
351 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
353 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
356 MsoResponseWrapper response = restClient.deleteVolumeGroupInstance(requestDetails,endpoint);
359 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
363 public void shouldProperlyDeleteNwInstance() {
365 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
367 String endpoint = "testEndpoint";
368 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
369 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
371 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
374 MsoResponseWrapper response = restClient.deleteNwInstance(requestDetails,endpoint);
377 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
381 public void shouldProperlyGetOrchestrationRequest() {
382 String endpoint = "testEndpoint";
383 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
384 String expectedPath = baseUrl+endpoint;
385 HttpResponseWithRequestInfo<String> expectedResponse = new HttpResponseWithRequestInfo<>(httpResponse, expectedPath, HttpMethod.GET);
387 when( client.get( eq(expectedPath), anyMap(), anyMap(), eq(String.class) )).thenReturn(httpResponse);
390 HttpResponseWithRequestInfo<String> response = restClient.getOrchestrationRequest(endpoint, true);
393 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
397 public void shouldProperlyGetOrchestrationRequestWithOnlyEndpoint() {
399 String endpoint = "testEndpoint";
400 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
401 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
403 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
406 MsoResponseWrapper response = restClient.getOrchestrationRequest(endpoint);
409 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
413 public void shouldProperlyGetManualTasksByRequestId() {
415 RestObject restObject = generateMockMsoRestObject();
417 String endpoint = "testEndpoint";
418 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
419 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
421 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
424 MsoResponseWrapper response = restClient.getManualTasksByRequestId(null,null,endpoint,restObject);
427 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
430 @Test(expectedExceptions = MsoTestException.class)
431 public void shouldThrowExceptionWhenGetManualTasksByRequestIdGetsWrongParameter() {
433 when( client.get( eq(baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
436 restClient.getManualTasksByRequestId(null,null,"",null);
440 public void shouldProperlyCompleteManualTask() {
442 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
443 RestObject restObject = generateMockMsoRestObject();
445 String endpoint = "testEndpoint";
446 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
447 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
449 when( client.post( eq(baseUrl+endpoint), anyMap(), eq(requestDetails), eq(String.class) ) ).thenReturn(httpResponse);
452 MsoResponseWrapper response = restClient.completeManualTask(requestDetails,null,null,endpoint,restObject);
455 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
458 @Test(expectedExceptions = MsoTestException.class)
459 public void shouldThrowExceptionWhenCompleteManualTaskWrongParameter() {
461 when( client.post( eq(baseUrl),anyMap(),eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
464 restClient.completeManualTask(null, null,null,"",null);
468 public void shouldProperlyReplaceVnf() {
470 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
472 String endpoint = "testEndpoint";
473 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
474 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
476 when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse);
479 MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
482 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
486 public void shouldProperlyReplaceVnfWithStatus202() {
488 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
490 String endpoint = "testEndpoint";
491 HttpResponse<String> httpResponse = createOkResponse();
492 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
494 when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse);
497 MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
500 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
503 @Test( expectedExceptions = MsoTestException.class)
504 public void shouldThrowExceptionWhenReplaceVnfGetsWrongParameters() {
506 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
508 when( client.post( eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenThrow(new MsoTestException("test-post-exception"));
511 restClient.replaceVnf(requestDetails, "");
515 public void shouldProperlyDeleteConfiguration() {
517 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
518 org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
520 String endpoint = "testEndpoint";
521 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
522 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
524 when( client.delete( eq(baseUrl+endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class) ) ).thenReturn(httpResponse);
527 MsoResponseWrapper response = restClient.deleteConfiguration(requestDetailsWrapper,endpoint);
530 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
533 @Test( expectedExceptions = MsoTestException.class )
534 public void shouldThrowExceptionWhenProperlyDeleteConfigurationGetsWrongParameters() {
536 when( client.delete( eq(baseUrl), anyMap(), eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("test-delete-exception"));
539 restClient.deleteConfiguration(null,"");
543 public void shouldProperlySetConfigurationActiveStatus() {
545 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
547 String endpoint = "testEndpoint";
548 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
549 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
551 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
554 MsoResponseWrapper response = restClient.setConfigurationActiveStatus(requestDetails, endpoint);
557 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
560 @Test(expectedExceptions = MsoTestException.class)
561 public void shouldThrowExceptionWhenSetConfigurationActiveStatusGetsWrongParameters() {
564 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
567 restClient.setConfigurationActiveStatus(null, "");
571 public void shouldProperlySetPortOnConfigurationStatus() {
573 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
575 String endpoint = "testEndpoint";
576 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
577 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
579 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
582 MsoResponseWrapper response = restClient.setPortOnConfigurationStatus(requestDetails, endpoint);
585 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
588 @Test(expectedExceptions = MsoTestException.class)
589 public void shouldThrowExceptionWhenSetPortOnConfigurationStatusGetsWrongParameters() {
591 String endpoint = "";
593 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
596 restClient.setPortOnConfigurationStatus(null, endpoint);
600 public void shouldProperlyChangeManagementUpdate() throws JsonProcessingException {
602 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
603 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
605 String endpoint = "testEndpoint";
606 RequestReferencesContainer entity = new RequestReferencesContainer(new RequestReferences());
607 HttpResponse<String> httpResponse = HttpResponse.fallback(JACKSON_OBJECT_MAPPER.writeValueAsString(entity));
609 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class))).thenReturn(httpResponse);
612 MsoResponseWrapperInterface response = restClient.changeManagementUpdate(requestDetailsWrapper, endpoint);
615 assertThat(response.getEntity()).isEqualToComparingFieldByField(entity);
616 assertThat(response.getStatus()).isEqualTo(0);
620 public void shouldProperlyUpdateVnfAndUpdateInstance() {
622 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
624 String endpoint = "testEndpoint";
625 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
626 MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse);
629 when(client.put(eq(baseUrl + endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenReturn(httpResponse);
632 MsoResponseWrapperInterface response = restClient.updateVnf(requestDetails, endpoint);
635 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
638 @Test( expectedExceptions = MsoTestException.class )
639 public void shouldThrowExceptionWhenUpdateVnfAndUpdateInstanceGetsWrongParameter() {
641 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
642 String endpoint = "";
644 when(client.put(eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
647 restClient.updateVnf(requestDetails, endpoint);
653 public void shouldProperlySetServiceInstanceStatus() {
655 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
656 RestObject<String> restObject = generateMockMsoRestObject();
658 String endpoint = "testEndpoint";
659 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
661 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
664 restClient.setServiceInstanceStatus(requestDetails, endpoint);
667 @Test( expectedExceptions = MsoTestException.class)
668 public void shouldThrowExceptionWhenSetServiceInstanceStatusGetsWrongParameter() {
670 String endpoint = "";
672 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
675 restClient.setServiceInstanceStatus(null, endpoint);
679 public void shouldProperlyRemoveRelationshipFromServiceInstance() {
681 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
683 String endpoint = "testEndpoint";
684 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
685 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
687 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
690 MsoResponseWrapper response = restClient.removeRelationshipFromServiceInstance(requestDetails, endpoint);
693 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
696 @Test( expectedExceptions = MsoTestException.class)
697 public void shouldThrowExceptionWhenRemoveRelationshipFromServiceInstanceGetsWrongParameter() {
699 String endpoint = "";
701 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
704 restClient.removeRelationshipFromServiceInstance(null,endpoint);
708 public void shouldProperlyAddRelationshipToServiceInstance() {
710 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
712 String endpoint = "testEndpoint";
713 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
714 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
716 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
719 MsoResponseWrapper response = restClient.addRelationshipToServiceInstance(requestDetails, endpoint);
722 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
725 @Test( expectedExceptions = MsoTestException.class)
726 public void shouldThrowExceptionWhenAddRelationshipToServiceInstanceGetsWrongParameter() {
728 String endpoint = "";
730 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
733 restClient.addRelationshipToServiceInstance(null,endpoint);
737 public void shouldProperlyPerformGetRequest() {
739 String endpoint = "testEndpoint";
740 HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
742 when(client.get(eq(baseUrl + endpoint), anyMap(), anyMap(), eq(String.class))).thenReturn(expectedResponse);
745 HttpResponse<String> response = restClient.get(endpoint, String.class);
748 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
752 public void shouldProperlyPerformPostRequest() {
755 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(MsoRestClientTestUtil.generateMockMsoRequest());
757 String endpoint = "testEndpoint";
758 HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
760 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class))).thenReturn(expectedResponse);
763 HttpResponse<String> response = restClient.post(endpoint,requestDetailsWrapper, String.class);
766 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
770 public void shouldProperlyInvokeWorkflows() {
772 String endpoint = "testPath";
773 HttpResponse expectedResponse = createOkResponse();
775 WorkflowRequestDetail workflowRequestDetail = MsoRestClientTestUtil.createWorkflowRequestDetail();
777 RequestDetailsWrapper<WorkflowRequestDetail> requestDetailsWrapper = new RequestDetailsWrapper<>(workflowRequestDetail);
779 UUID requestId = UUID.randomUUID();
781 when(client.post(eq(baseUrl + endpoint), argThat(allOf(hasEntry("X-ONAP-RequestID", requestId.toString()),hasEntry("Content-Type", "application/json"))), refEq(requestDetailsWrapper))).
782 thenReturn(expectedResponse);
784 Map<String,String> extraHeaders = new HashMap<>();
785 extraHeaders.put("X-ONAP-RequestID",requestId.toString());
786 extraHeaders.put("X-ONAP-PartnerName","VID.VID");
787 extraHeaders.put("X-RequestorID","testRequester");
790 MsoResponseWrapper response = restClient.invokeWorkflow(workflowRequestDetail, endpoint, extraHeaders);
793 assertThat(response).isEqualToComparingFieldByField(MsoUtil.wrapResponse(expectedResponse));
797 private class MsoTestException extends RuntimeException{
798 MsoTestException(String testException) {
799 super(testException);
803 private HttpResponse<String> createOkResponse() {
804 StatusLine statusline = new BasicStatusLine(
805 new ProtocolVersion("http",1,1), 202, "acceptResponse");
807 org.apache.http.HttpResponse responseBase = new BasicHttpResponse(statusline);
809 return new HttpResponse<>(responseBase ,String.class, new JsonMapper());
812 private RestObject<String> generateMockMsoRestObject() {
813 RestObject<String> restObject = new RestObject<>();
815 restObject.set("test-rest-object-body");
816 restObject.setRaw("test-rest-object-raw-string");
817 restObject.setStatusCode(202);