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.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.anyMap;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.when;
28 import static org.mockito.MockitoAnnotations.initMocks;
30 import io.joshworks.restclient.http.HttpResponse;
31 import io.joshworks.restclient.http.JsonMapper;
32 import org.apache.http.ProtocolVersion;
33 import org.apache.http.StatusLine;
34 import org.apache.http.message.BasicHttpResponse;
35 import org.apache.http.message.BasicStatusLine;
36 import org.mockito.Mock;
37 import org.onap.portalsdk.core.util.SystemProperties;
38 import org.onap.vid.changeManagement.RequestDetailsWrapper;
39 import org.onap.vid.client.SyncRestClient;
40 import org.onap.vid.controller.LocalWebConfig;
41 import org.onap.vid.model.RequestReferencesContainer;
42 import org.onap.vid.mso.MsoResponseWrapper;
43 import org.onap.vid.mso.MsoResponseWrapperInterface;
44 import org.onap.vid.mso.MsoUtil;
45 import org.onap.vid.mso.RestObject;
46 import org.onap.vid.mso.model.RequestReferences;
47 import org.springframework.test.context.ContextConfiguration;
48 import org.springframework.test.context.web.WebAppConfiguration;
49 import org.testng.annotations.BeforeClass;
50 import org.testng.annotations.Test;
53 @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
55 public class MsoRestClientTest {
58 private final String baseUrl = "http://testURL/";
61 private SyncRestClient client;
63 private MsoRestClientNew restClient;
69 restClient = new MsoRestClientNew(client,baseUrl,null);
74 public void shouldProperlyCreateServiceInstance() {
76 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
78 String endpoint = "testEndpoint";
79 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
80 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
82 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
85 MsoResponseWrapper response = restClient.createSvcInstance(requestDetails,endpoint);
88 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
91 @Test( expectedExceptions = MsoTestException.class)
92 public void shouldThrowExceptionWhenCreateSvcInstanceGetsWrongParameters() {
96 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(null),eq(String.class) ) ).
97 thenThrow(new MsoTestException("test-post-exception"));
100 restClient.createSvcInstance(null,endpoint);
104 public void shouldProperlyCreateE2eSvcInstance() {
106 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
108 String endpoint = "testEndpoint";
109 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
110 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
112 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
115 MsoResponseWrapper response = restClient.createE2eSvcInstance(requestDetails,endpoint);
118 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
122 public void shouldProperlyCreateVnf() {
124 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
126 String endpoint = "testEndpoint";
127 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
128 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
130 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
133 MsoResponseWrapper response = restClient.createVnf(requestDetails,endpoint);
136 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
140 public void shouldProperlyCreateNwInstance() {
142 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
144 String endpoint = "testEndpoint";
145 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
146 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
148 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
151 MsoResponseWrapper response = restClient.createNwInstance(requestDetails,endpoint);
154 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
158 public void shouldProperlyCreateVolumeGroupInstance() {
160 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
162 String endpoint = "testEndpoint";
163 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
164 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
166 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
169 MsoResponseWrapper response = restClient.createVolumeGroupInstance(requestDetails,endpoint);
172 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
176 public void shouldProperlyCreateVfModuleInstance() {
178 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
180 String endpoint = "testEndpoint";
181 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
182 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
184 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
187 MsoResponseWrapper response = restClient.createVfModuleInstance(requestDetails,endpoint);
190 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
194 public void shouldProperlyScaleOutVFModuleInstance() {
196 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
198 RequestDetailsWrapper<RequestDetails> wrappedRequestDetails = new RequestDetailsWrapper<>(requestDetails);
199 String endpoint = "testEndpoint";
200 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
201 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
203 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
206 MsoResponseWrapper response = restClient.scaleOutVFModuleInstance(wrappedRequestDetails,endpoint);
209 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
213 public void shouldProperlyCreateConfigurationInstance() {
215 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
217 org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
218 String endpoint = "testEndpoint";
219 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
220 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
222 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
225 MsoResponseWrapper response = restClient.createConfigurationInstance(wrappedRequestDetails,endpoint);
228 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
232 public void shouldProperlyDeleteE2eSvcInstance() {
234 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
236 org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
237 String endpoint = "testEndpoint";
238 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
239 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
241 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse);
244 MsoResponseWrapper response = restClient.deleteE2eSvcInstance(wrappedRequestDetails,endpoint);
247 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
251 public void shouldProperlyDeleteSvcInstance() {
253 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
255 String endpoint = "testEndpoint";
256 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
257 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
259 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
262 MsoResponseWrapper response = restClient.deleteSvcInstance(requestDetails,endpoint);
265 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
269 public void shouldProperlyUnassignSvcInstance() {
271 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
273 String endpoint = "testEndpoint";
274 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
275 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
277 when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
280 MsoResponseWrapper response = restClient.unassignSvcInstance(requestDetails,endpoint);
283 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
287 public void shouldProperlyDeleteVnf() {
289 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
291 String endpoint = "testEndpoint";
292 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
293 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
295 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
298 MsoResponseWrapper response = restClient.deleteVnf(requestDetails,endpoint);
301 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
305 public void shouldProperlyDeleteVfModule() {
307 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
309 String endpoint = "testEndpoint";
310 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
311 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
313 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
316 MsoResponseWrapper response = restClient.deleteVfModule(requestDetails,endpoint);
319 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
323 public void shouldProperlyDeleteVolumeGroupInstance() {
325 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
327 String endpoint = "testEndpoint";
328 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
329 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
331 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
334 MsoResponseWrapper response = restClient.deleteVolumeGroupInstance(requestDetails,endpoint);
337 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
341 public void shouldProperlyDeleteNwInstance() {
343 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
345 String endpoint = "testEndpoint";
346 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
347 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
349 when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse);
352 MsoResponseWrapper response = restClient.deleteNwInstance(requestDetails,endpoint);
355 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
359 public void shouldProperlyGetOrchestrationRequest() {
361 RestObject restObject = generateMockMsoRestObject();
363 String endpoint = "testEndpoint";
364 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
365 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
367 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
370 MsoResponseWrapper response = restClient.getOrchestrationRequest(null,null,endpoint,restObject,true);
373 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
377 public void shouldProperlyGetOrchestrationRequestWithOnlyEndpoint() {
379 String endpoint = "testEndpoint";
380 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
381 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
383 when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
386 MsoResponseWrapper response = restClient.getOrchestrationRequest(endpoint);
389 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
393 public void shouldProperlyGetManualTasksByRequestId() {
395 RestObject restObject = generateMockMsoRestObject();
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.getManualTasksByRequestId(null,null,endpoint,restObject);
407 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
410 @Test(expectedExceptions = MsoTestException.class)
411 public void shouldThrowExceptionWhenGetManualTasksByRequestIdGetsWrongParameter() {
413 when( client.get( eq(baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
416 restClient.getManualTasksByRequestId(null,null,"",null);
420 public void shouldProperlyCompleteManualTask() {
422 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
423 RestObject restObject = generateMockMsoRestObject();
425 String endpoint = "testEndpoint";
426 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
427 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
429 when( client.post( eq(baseUrl+endpoint), anyMap(), eq(requestDetails), eq(String.class) ) ).thenReturn(httpResponse);
432 MsoResponseWrapper response = restClient.completeManualTask(requestDetails,null,null,endpoint,restObject);
435 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
438 @Test(expectedExceptions = MsoTestException.class)
439 public void shouldThrowExceptionWhenCompleteManualTaskWrongParameter() {
441 when( client.post( eq(baseUrl),anyMap(),eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
444 restClient.completeManualTask(null, null,null,"",null);
448 public void shouldProperlyReplaceVnf() {
450 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
452 String endpoint = "testEndpoint";
453 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
454 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
456 when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse);
459 MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint);
462 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
466 public void shouldProperlyReplaceVnfWithStatus202() {
468 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
470 String endpoint = "testEndpoint";
471 HttpResponse<String> httpResponse = createOkResponse();
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);
483 @Test( expectedExceptions = MsoTestException.class)
484 public void shouldThrowExceptionWhenReplaceVnfGetsWrongParameters() {
486 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
488 when( client.post( eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenThrow(new MsoTestException("test-post-exception"));
491 restClient.replaceVnf(requestDetails, "");
495 public void shouldProperlyDeleteConfiguration() {
497 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
498 org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails);
500 String endpoint = "testEndpoint";
501 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
502 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
504 when( client.delete( eq(baseUrl+endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class) ) ).thenReturn(httpResponse);
507 MsoResponseWrapper response = restClient.deleteConfiguration(requestDetailsWrapper,endpoint);
510 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
513 @Test( expectedExceptions = MsoTestException.class )
514 public void shouldThrowExceptionWhenProperlyDeleteConfigurationGetsWrongParameters() {
516 when( client.delete( eq(baseUrl), anyMap(), eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("test-delete-exception"));
519 restClient.deleteConfiguration(null,"");
523 public void shouldProperlySetConfigurationActiveStatus() {
525 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
527 String endpoint = "testEndpoint";
528 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
529 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
531 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
534 MsoResponseWrapper response = restClient.setConfigurationActiveStatus(requestDetails, endpoint);
537 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
540 @Test(expectedExceptions = MsoTestException.class)
541 public void shouldThrowExceptionWhenSetConfigurationActiveStatusGetsWrongParameters() {
544 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
547 restClient.setConfigurationActiveStatus(null, "");
551 public void shouldProperlySetPortOnConfigurationStatus() {
553 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
555 String endpoint = "testEndpoint";
556 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
557 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
559 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
562 MsoResponseWrapper response = restClient.setPortOnConfigurationStatus(requestDetails, endpoint);
565 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
568 @Test(expectedExceptions = MsoTestException.class)
569 public void shouldThrowExceptionWhenSetPortOnConfigurationStatusGetsWrongParameters() {
571 String endpoint = "";
573 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
576 restClient.setPortOnConfigurationStatus(null, endpoint);
580 public void shouldProperlyChangeManagementUpdate() {
582 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
583 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
585 String endpoint = "testEndpoint";
586 HttpResponse<RequestReferencesContainer> httpResponse = HttpResponse.fallback(
587 new RequestReferencesContainer(
588 new RequestReferences()));
590 MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse);
592 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(RequestReferencesContainer.class))).thenReturn(httpResponse);
595 MsoResponseWrapperInterface response = restClient.changeManagementUpdate(requestDetailsWrapper, endpoint);
598 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
602 public void shouldProperlyUpdateVnfAndUpdateInstance() {
604 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
606 String endpoint = "testEndpoint";
607 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
608 MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse);
611 when(client.put(eq(baseUrl + endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenReturn(httpResponse);
614 MsoResponseWrapperInterface response = restClient.updateVnf(requestDetails, endpoint);
617 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
620 @Test( expectedExceptions = MsoTestException.class )
621 public void shouldThrowExceptionWhenUpdateVnfAndUpdateInstanceGetsWrongParameter() {
623 org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest();
624 String endpoint = "";
626 when(client.put(eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
629 restClient.updateVnf(requestDetails, endpoint);
635 public void shouldProperlySetServiceInstanceStatus() {
637 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
638 RestObject<String> restObject = generateMockMsoRestObject();
640 String endpoint = "testEndpoint";
641 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
643 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
646 restClient.setServiceInstanceStatus(requestDetails,"", "", endpoint, restObject);
649 @Test( expectedExceptions = MsoTestException.class)
650 public void shouldThrowExceptionWhenSetServiceInstanceStatusGetsWrongParameter() {
652 String endpoint = "";
654 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
657 restClient.setServiceInstanceStatus(null,"", "", endpoint, null);
661 public void shouldProperlyRemoveRelationshipFromServiceInstance() {
663 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
665 String endpoint = "testEndpoint";
666 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
667 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
669 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
672 MsoResponseWrapper response = restClient.removeRelationshipFromServiceInstance(requestDetails, endpoint);
675 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
678 @Test( expectedExceptions = MsoTestException.class)
679 public void shouldThrowExceptionWhenRemoveRelationshipFromServiceInstanceGetsWrongParameter() {
681 String endpoint = "";
683 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
686 restClient.removeRelationshipFromServiceInstance(null,endpoint);
690 public void shouldProperlyAddRelationshipToServiceInstance() {
692 RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
694 String endpoint = "testEndpoint";
695 HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
696 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
698 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
701 MsoResponseWrapper response = restClient.addRelationshipToServiceInstance(requestDetails, endpoint);
704 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
707 @Test( expectedExceptions = MsoTestException.class)
708 public void shouldThrowExceptionWhenAddRelationshipToServiceInstanceGetsWrongParameter() {
710 String endpoint = "";
712 when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
715 restClient.addRelationshipToServiceInstance(null,endpoint);
719 public void shouldProperlyPerformGetRequest() {
721 String endpoint = "testEndpoint";
722 HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
724 when(client.get(eq(baseUrl + endpoint), anyMap(), anyMap(), eq(String.class))).thenReturn(expectedResponse);
727 HttpResponse<String> response = restClient.get(endpoint, String.class);
730 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
734 public void shouldProperlyPerformPostRequest() {
737 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(MsoRestClientTestUtil.generateMockMsoRequest());
739 String endpoint = "testEndpoint";
740 HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse");
742 when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class))).thenReturn(expectedResponse);
745 HttpResponse<String> response = restClient.post(endpoint,requestDetailsWrapper, String.class);
748 assertThat(expectedResponse).isEqualToComparingFieldByField(response);
751 private class MsoTestException extends RuntimeException{
752 MsoTestException(String testException) {
753 super(testException);
757 private HttpResponse<String> createOkResponse() {
758 StatusLine statusline = new BasicStatusLine(
759 new ProtocolVersion("http",1,1), 202, "acceptResponse");
761 org.apache.http.HttpResponse responseBase = new BasicHttpResponse(statusline);
763 return new HttpResponse<>(responseBase ,String.class, new JsonMapper());
766 private RestObject<String> generateMockMsoRestObject() {
767 RestObject<String> restObject = new RestObject<>();
769 restObject.set("test-rest-object-body");
770 restObject.setRaw("test-rest-object-raw-string");
771 restObject.setStatusCode(202);