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 com.fasterxml.jackson.core.JsonProcessingException;
33 import io.joshworks.restclient.http.HttpResponse;
34 import io.joshworks.restclient.http.JsonMapper;
35 import org.apache.http.ProtocolVersion;
36 import org.apache.http.StatusLine;
37 import org.apache.http.message.BasicHttpResponse;
38 import org.apache.http.message.BasicStatusLine;
39 import org.mockito.Mock;
40 import org.onap.portalsdk.core.util.SystemProperties;
41 import org.onap.vid.aai.HttpResponseWithRequestInfo;
42 import org.onap.vid.changeManagement.RequestDetailsWrapper;
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.RequestReferences;
53 import org.onap.vid.utils.SystemPropertiesWrapper;
54 import org.springframework.http.HttpMethod;
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.HashMap;
62 import java.util.UUID;
64 import static org.mockito.ArgumentMatchers.refEq;
65 import static org.mockito.hamcrest.MockitoHamcrest.argThat;
66 import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
69 @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
71 public class MsoRestClientTest {
74 private final String baseUrl = "http://testURL/";
77 private SyncRestClient client;
80 private SystemPropertiesWrapper systemProperties;
82 private MsoRestClientNew restClient;
88 when(systemProperties.getProperty(MsoProperties.MSO_PASSWORD)).thenReturn("OBF:1ghz1kfx1j1w1m7w1i271e8q1eas1hzj1m4i1iyy1kch1gdz");
89 when(systemProperties.getProperty("app_display_name")).thenReturn("vid");
90 restClient = new MsoRestClientNew(client,baseUrl,null,systemProperties);
94 public void shouldProperlyCreateServiceInstance() {
96 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
98 String endpoint = "testEndpoint";
99 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
100 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
102 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
105 MsoResponseWrapper response = restClient.createSvcInstance(requestDetails,endpoint);
108 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
111 @Test( expectedExceptions = MsoTestException.class)
112 public void shouldThrowExceptionWhenCreateSvcInstanceGetsWrongParameters() {
114 String endpoint = "";
116 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(null),eq(String.class) ) ).
117 thenThrow(new MsoTestException("test-post-exception"));
120 restClient.createSvcInstance(null,endpoint);
124 public void shouldProperlyCreateE2eSvcInstance() {
126 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
128 String endpoint = "testEndpoint";
129 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
130 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
132 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
135 MsoResponseWrapper response = restClient.createE2eSvcInstance(requestDetails,endpoint);
138 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
142 public void shouldProperlyCreateVnf() {
144 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
146 String endpoint = "testEndpoint";
147 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
148 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
150 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
153 MsoResponseWrapper response = restClient.createVnf(requestDetails,endpoint);
156 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
160 public void shouldProperlyCreateNwInstance() {
162 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
164 String endpoint = "testEndpoint";
165 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
166 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
168 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
171 MsoResponseWrapper response = restClient.createNwInstance(requestDetails,endpoint);
174 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
178 public void shouldProperlyCreateVolumeGroupInstance() {
180 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
182 String endpoint = "testEndpoint";
183 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
184 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
186 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
189 MsoResponseWrapper response = restClient.createVolumeGroupInstance(requestDetails,endpoint);
192 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
196 public void shouldProperlyCreateVfModuleInstance() {
198 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
200 String endpoint = "testEndpoint";
201 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
202 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
204 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
207 MsoResponseWrapper response = restClient.createVfModuleInstance(requestDetails,endpoint);
210 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
214 public void shouldProperlyScaleOutVFModuleInstance() {
216 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
218 RequestDetailsWrapper<RequestDetails> wrappedRequestDetails = new RequestDetailsWrapper<>(requestDetails);
219 String endpoint = "testEndpoint";
220 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
221 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
223 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
226 MsoResponseWrapper response = restClient.scaleOutVFModuleInstance(wrappedRequestDetails,endpoint);
229 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
233 public void shouldProperlyCreateConfigurationInstance() {
235 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
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);
242 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
245 MsoResponseWrapper response = restClient.createConfigurationInstance(wrappedRequestDetails,endpoint);
248 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
252 public void shouldProperlyDeleteE2eSvcInstance() {
254 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
256 org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
257 String endpoint = "testEndpoint";
258 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
259 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
261 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
264 MsoResponseWrapper response = restClient.deleteE2eSvcInstance(wrappedRequestDetails,endpoint);
267 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
271 public void shouldProperlyDeleteSvcInstance() {
273 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
275 String endpoint = "testEndpoint";
276 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
277 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
279 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
282 MsoResponseWrapper response = restClient.deleteSvcInstance(requestDetails,endpoint);
285 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
289 public void shouldProperlyUnassignSvcInstance() {
291 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
293 String endpoint = "testEndpoint";
294 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
295 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
297 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
300 MsoResponseWrapper response = restClient.unassignSvcInstance(requestDetails,endpoint);
303 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
307 public void shouldProperlyDeleteVnf() {
309 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
311 String endpoint = "testEndpoint";
312 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
313 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
315 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
318 MsoResponseWrapper response = restClient.deleteVnf(requestDetails,endpoint);
321 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
325 public void shouldProperlyDeleteVfModule() {
327 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
329 String endpoint = "testEndpoint";
330 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
331 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
333 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
336 MsoResponseWrapper response = restClient.deleteVfModule(requestDetails,endpoint);
339 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
343 public void shouldProperlyDeleteVolumeGroupInstance() {
345 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
347 String endpoint = "testEndpoint";
348 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
349 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
351 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
354 MsoResponseWrapper response = restClient.deleteVolumeGroupInstance(requestDetails,endpoint);
357 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
361 public void shouldProperlyDeleteNwInstance() {
363 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
365 String endpoint = "testEndpoint";
366 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
367 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
369 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
372 MsoResponseWrapper response = restClient.deleteNwInstance(requestDetails,endpoint);
375 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
379 public void shouldProperlyGetOrchestrationRequest() {
380 String endpoint = "testEndpoint";
381 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
382 String expectedPath = baseUrl+endpoint;
383 HttpResponseWithRequestInfo<String> expectedResponse = new HttpResponseWithRequestInfo<>(httpResponse, expectedPath, HttpMethod.GET);
385 when( client.get( eq(expectedPath), anyMap(), anyMap(), eq(String.class) )).thenReturn(httpResponse);
388 HttpResponseWithRequestInfo<String> response = restClient.getOrchestrationRequest(endpoint, true);
391 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
395 public void shouldProperlyGetOrchestrationRequestWithOnlyEndpoint() {
397 String endpoint = "testEndpoint";
398 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
399 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
401 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
404 MsoResponseWrapper response = restClient.getOrchestrationRequest(endpoint);
407 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
411 public void shouldProperlyGetManualTasksByRequestId() {
413 RestObject restObject = generateMockMsoRestObject();
415 String endpoint = "testEndpoint";
416 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
417 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
419 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
422 MsoResponseWrapper response = restClient.getManualTasksByRequestId(null,null,endpoint,restObject);
425 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
428 @Test(expectedExceptions = MsoTestException.class)
429 public void shouldThrowExceptionWhenGetManualTasksByRequestIdGetsWrongParameter() {
431 when( client.get( eq(baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
434 restClient.getManualTasksByRequestId(null,null,"",null);
438 public void shouldProperlyCompleteManualTask() {
440 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
441 RestObject restObject = generateMockMsoRestObject();
443 String endpoint = "testEndpoint";
444 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
445 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
447 when( client.post( eq(baseUrl+endpoint), anyMap(), eq(requestDetails), eq(String.class) ) ).thenReturn(httpResponse);
450 MsoResponseWrapper response = restClient.completeManualTask(requestDetails,null,null,endpoint,restObject);
453 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
456 @Test(expectedExceptions = MsoTestException.class)
457 public void shouldThrowExceptionWhenCompleteManualTaskWrongParameter() {
459 when( client.post( eq(baseUrl),anyMap(),eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
462 restClient.completeManualTask(null, null,null,"",null);
466 public void shouldProperlyReplaceVnf() {
468 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
470 String endpoint = "testEndpoint";
471 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
472 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
474 when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse);
477 MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
480 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
484 public void shouldProperlyReplaceVnfWithStatus202() {
486 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
488 String endpoint = "testEndpoint";
489 HttpResponse<String> httpResponse = createOkResponse();
490 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
492 when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse);
495 MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
498 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
501 @Test( expectedExceptions = MsoTestException.class)
502 public void shouldThrowExceptionWhenReplaceVnfGetsWrongParameters() {
504 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
506 when( client.post( eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenThrow(new MsoTestException("test-post-exception"));
509 restClient.replaceVnf(requestDetails, "");
513 public void shouldProperlyDeleteConfiguration() {
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);
518 String endpoint = "testEndpoint";
519 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
520 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
522 when( client.delete( eq(baseUrl+endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class) ) ).thenReturn(httpResponse);
525 MsoResponseWrapper response = restClient.deleteConfiguration(requestDetailsWrapper,endpoint);
528 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
531 @Test( expectedExceptions = MsoTestException.class )
532 public void shouldThrowExceptionWhenProperlyDeleteConfigurationGetsWrongParameters() {
534 when( client.delete( eq(baseUrl), anyMap(), eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("test-delete-exception"));
537 restClient.deleteConfiguration(null,"");
541 public void shouldProperlySetConfigurationActiveStatus() {
543 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
545 String endpoint = "testEndpoint";
546 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
547 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
549 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
552 MsoResponseWrapper response = restClient.setConfigurationActiveStatus(requestDetails, endpoint);
555 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
558 @Test(expectedExceptions = MsoTestException.class)
559 public void shouldThrowExceptionWhenSetConfigurationActiveStatusGetsWrongParameters() {
562 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
565 restClient.setConfigurationActiveStatus(null, "");
569 public void shouldProperlySetPortOnConfigurationStatus() {
571 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
573 String endpoint = "testEndpoint";
574 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
575 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
577 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
580 MsoResponseWrapper response = restClient.setPortOnConfigurationStatus(requestDetails, endpoint);
583 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
586 @Test(expectedExceptions = MsoTestException.class)
587 public void shouldThrowExceptionWhenSetPortOnConfigurationStatusGetsWrongParameters() {
589 String endpoint = "";
591 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
594 restClient.setPortOnConfigurationStatus(null, endpoint);
598 public void shouldProperlyChangeManagementUpdate() throws JsonProcessingException {
600 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
601 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
603 String endpoint = "testEndpoint";
604 RequestReferencesContainer entity = new RequestReferencesContainer(new RequestReferences());
605 HttpResponse<String> httpResponse = HttpResponse.fallback(JACKSON_OBJECT_MAPPER.writeValueAsString(entity));
607 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class))).thenReturn(httpResponse);
610 MsoResponseWrapperInterface response = restClient.changeManagementUpdate(requestDetailsWrapper, endpoint);
613 assertThat(response.getEntity()).isEqualToComparingFieldByField(entity);
614 assertThat(response.getStatus()).isEqualTo(0);
618 public void shouldProperlyUpdateVnfAndUpdateInstance() {
620 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
622 String endpoint = "testEndpoint";
623 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
624 MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse);
627 when(client.put(eq(baseUrl + endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenReturn(httpResponse);
630 MsoResponseWrapperInterface response = restClient.updateVnf(requestDetails, endpoint);
633 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
636 @Test( expectedExceptions = MsoTestException.class )
637 public void shouldThrowExceptionWhenUpdateVnfAndUpdateInstanceGetsWrongParameter() {
639 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
640 String endpoint = "";
642 when(client.put(eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
645 restClient.updateVnf(requestDetails, endpoint);
651 public void shouldProperlySetServiceInstanceStatus() {
653 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
654 RestObject<String> restObject = generateMockMsoRestObject();
656 String endpoint = "testEndpoint";
657 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
659 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
662 restClient.setServiceInstanceStatus(requestDetails, endpoint);
665 @Test( expectedExceptions = MsoTestException.class)
666 public void shouldThrowExceptionWhenSetServiceInstanceStatusGetsWrongParameter() {
668 String endpoint = "";
670 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
673 restClient.setServiceInstanceStatus(null, endpoint);
677 public void shouldProperlyRemoveRelationshipFromServiceInstance() {
679 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
681 String endpoint = "testEndpoint";
682 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
683 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
685 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
688 MsoResponseWrapper response = restClient.removeRelationshipFromServiceInstance(requestDetails, endpoint);
691 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
694 @Test( expectedExceptions = MsoTestException.class)
695 public void shouldThrowExceptionWhenRemoveRelationshipFromServiceInstanceGetsWrongParameter() {
697 String endpoint = "";
699 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
702 restClient.removeRelationshipFromServiceInstance(null,endpoint);
706 public void shouldProperlyAddRelationshipToServiceInstance() {
708 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
710 String endpoint = "testEndpoint";
711 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
712 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
714 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
717 MsoResponseWrapper response = restClient.addRelationshipToServiceInstance(requestDetails, endpoint);
720 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
723 @Test( expectedExceptions = MsoTestException.class)
724 public void shouldThrowExceptionWhenAddRelationshipToServiceInstanceGetsWrongParameter() {
726 String endpoint = "";
728 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
731 restClient.addRelationshipToServiceInstance(null,endpoint);
735 public void shouldProperlyPerformGetRequest() {
737 String endpoint = "testEndpoint";
738 HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
740 when(client.get(eq(baseUrl + endpoint), anyMap(), anyMap(), eq(String.class))).thenReturn(expectedResponse);
743 HttpResponse<String> response = restClient.get(endpoint, String.class);
746 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
750 public void shouldProperlyPerformPostRequest() {
753 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(MsoRestClientTestUtil.generateMockMsoRequest());
755 String endpoint = "testEndpoint";
756 HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
758 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class))).thenReturn(expectedResponse);
761 HttpResponse<String> response = restClient.post(endpoint,requestDetailsWrapper, String.class);
764 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
768 public void shouldProperlyInvokeWorkflows() {
770 String endpoint = "testPath";
771 HttpResponse expectedResponse = createOkResponse();
773 WorkflowRequestDetail workflowRequestDetail = MsoRestClientTestUtil.createWorkflowRequestDetail();
775 RequestDetailsWrapper<WorkflowRequestDetail> requestDetailsWrapper = new RequestDetailsWrapper<>(workflowRequestDetail);
777 UUID requestId = UUID.randomUUID();
779 when(client.post(eq(baseUrl + endpoint), argThat(allOf(hasEntry("X-ONAP-RequestID", requestId.toString()),hasEntry("Content-Type", "application/json"))), refEq(requestDetailsWrapper))).
780 thenReturn(expectedResponse);
782 Map<String,String> extraHeaders = new HashMap<>();
783 extraHeaders.put("X-ONAP-RequestID",requestId.toString());
784 extraHeaders.put("X-ONAP-PartnerName","VID");
785 extraHeaders.put("X-RequestorID","testRequester");
788 MsoResponseWrapper response = restClient.invokeWorkflow(workflowRequestDetail, endpoint, extraHeaders);
791 assertThat(response).isEqualToComparingFieldByField(MsoUtil.wrapResponse(expectedResponse));
795 private class MsoTestException extends RuntimeException{
796 MsoTestException(String testException) {
797 super(testException);
801 private HttpResponse<String> createOkResponse() {
802 StatusLine statusline = new BasicStatusLine(
803 new ProtocolVersion("http",1,1), 202, "acceptResponse");
805 org.apache.http.HttpResponse responseBase = new BasicHttpResponse(statusline);
807 return new HttpResponse<>(responseBase ,String.class, new JsonMapper());
810 private RestObject<String> generateMockMsoRestObject() {
811 RestObject<String> restObject = new RestObject<>();
813 restObject.set("test-rest-object-body");
814 restObject.setRaw("test-rest-object-raw-string");
815 restObject.setStatusCode(202);