diff options
Diffstat (limited to 'vid-app-common/src/test/java/org')
4 files changed, 1224 insertions, 29 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java new file mode 100644 index 000000000..4cba53785 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java @@ -0,0 +1,421 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.mso; + +import io.joshworks.restclient.request.HttpRequest; +import org.glassfish.jersey.client.JerseyInvocation; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.util.HttpsAuthClient; +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.mso.rest.RequestDetails; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; + +import java.util.Optional; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +public class RestMsoImplementationTest { + + @Mock + private HttpRequest httpRequest; + + @Mock + private Client mockClient; + + @Mock + private HttpsAuthClient mockHttpsAuthClient; + + @Mock + private WebTarget webTarget; + + @Mock + private javax.ws.rs.client.Invocation.Builder builder; + + @Mock + private Response response; + + @Mock + private JerseyInvocation jerseyInvocation; + + @InjectMocks + private RestMsoImplementation restMsoImplementation = new RestMsoImplementation(mockHttpsAuthClient); + + String path = "/test_path/"; + String rawData = "test-row-data"; + + @BeforeClass + public void setUp(){ + initMocks(this); + } + + @Test + public void shouldProperlyInitMsoClient() { + // when + MultivaluedHashMap<String, Object> result = restMsoImplementation.initMsoClient(); + + // then + assertThat(result).containsKeys("Authorization","X-ONAP-PartnerName"); + assertThat(result).doesNotContainKey("notExistingKey"); + } + + @Test + public void shouldProperlyGetRestObjectWithRequestInfo() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + + prepareMocks(rawData, HttpStatus.ACCEPTED.value(),""); + + // when + RestObjectWithRequestInfo<HttpRequest> response = restMsoImplementation.Get(httpRequest, path, restObject,false); + + // then + assertThat(response.getRequestedUrl()).contains(path); + assertThat(response.getRawData()).isEqualTo(rawData); + assertThat(response.getHttpCode()).isEqualTo(HttpStatus.ACCEPTED.value()); + assertThat(response.getHttpMethod()).isEqualTo(HttpMethod.GET); + } + + @Test( expectedExceptions = GenericUncheckedException.class) + public void shouldThrowExceptionWhenGetRestObjectWithRequestInfoGetsWrongStatus() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + + prepareMocks("",HttpStatus.BAD_REQUEST.value(),""); + + // when + restMsoImplementation.Get(httpRequest, "", restObject,false); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenGetRestObjectWithRequestInfoGetsWrongParameters() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + + prepareMocks("",HttpStatus.ACCEPTED.value(),""); + when(mockClient.target(SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL))).thenThrow(new MsoTestException("test-target-exception")); + + // when + restMsoImplementation.Get(httpRequest, "", restObject,false); + } + + @Test() + public void shouldProperlyGetRestObjectForObjectWithRequestInfoAndAcceptCode() { + // given + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),""); + + // when + RestObject response = restMsoImplementation.GetForObject(path, HttpRequest.class); + + // then + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED.value()); + assertThat(response.getRaw()).isEqualTo(rawData); + } + + @Test() + public void shouldProperlyGetRestObjectForObjectWithRequestInfoAndBadRequestCode() { + // given + prepareMocks(rawData,HttpStatus.BAD_REQUEST.value(),""); + + // when + RestObject response = restMsoImplementation.GetForObject(path, HttpRequest.class); + + // then + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); + assertThat(response.getRaw()).isEqualTo(rawData); + } + + @Test() + public void shouldProperlyDeleteRestObjectWithStatusHttpAccepted() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE"); + + // when + restMsoImplementation.Delete(httpRequest, "testObject", path, restObject); + + // then + assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED.value()); + } + + @Test() + public void shouldProperlyDeleteRestObjectWithStatusOK() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + + prepareMocks(rawData,HttpStatus.OK.value(),"DELETE"); + + // when + restMsoImplementation.Delete(httpRequest, "testObject", path, restObject); + + // then + assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.OK.value()); + } + + @Test() + public void shouldProperlyReturnFromDeleteWithStatusBadRequest() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + + prepareMocks(rawData,HttpStatus.BAD_REQUEST.value(),"DELETE"); + + // when + restMsoImplementation.Delete(httpRequest, "testObject", path, restObject); + + // then + assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); + } + + @Test() + public void shouldProperlyReturnFromDeleteWithStatusOtherThenAbove() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + prepareMocks(rawData,HttpStatus.NOT_EXTENDED.value(),"DELETE"); + + // when + restMsoImplementation.Delete(httpRequest, "testObject", path, restObject); + + // then + assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.NOT_EXTENDED.value()); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenCallsDeleteWithWrongParameters() { + // given + when(mockClient.target(any(String.class))).thenThrow(new MsoTestException("testDeleteException")); + + // when + restMsoImplementation.Delete(httpRequest, "testObject", "", null); + } + + @Test( expectedExceptions = NullPointerException.class) + public void shouldThrowExceptionWhenCallsDeleteWithWrongObjectType() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE"); + + // when + restMsoImplementation.Delete(null, "testObject", path, restObject); + } + + @Test + public void shouldProperlyPostForObject() { + // given + RequestDetails requestDetails = new RequestDetails(); + + RestObject<HttpRequest> expectedResponse = new RestObject<>(); + expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value()); + expectedResponse.setRaw(rawData); + + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"POST"); + + // when + RestObject<HttpRequest> response = restMsoImplementation.PostForObject(requestDetails, path, HttpRequest.class); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyDeleteForObject() { + // given + RequestDetails requestDetails = new RequestDetails(); + + RestObject<HttpRequest> expectedResponse = new RestObject<>(); + expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value()); + expectedResponse.setRaw(rawData); + + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE"); + + // when + RestObject<HttpRequest> response = restMsoImplementation.DeleteForObject(requestDetails, path, HttpRequest.class); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyPost() { + // given + RequestDetails requestDetails = new RequestDetails(); + RestObject<String> response = new RestObject<>(); + + RestObject<String> expectedResponse = new RestObject<>(); + expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value()); + expectedResponse.setRaw(rawData); + + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"POST"); + + // when + restMsoImplementation.Post(rawData,requestDetails, path, response); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyPrepareClient() { + // given + String method = "POST"; + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),method); + + // when + javax.ws.rs.client.Invocation.Builder response = restMsoImplementation.prepareClient(path, method); + + // then + assertThat(response).isEqualTo(builder); + } + + @Test + public void shouldCreatRestObjectOnlyWithHttpMethod() { + // given + String method = "GET"; + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),method); + + RestObject<String> expectedResponse = new RestObject<>(); + expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value()); + expectedResponse.setRaw(rawData); + + // when + RestObject<String> response = restMsoImplementation.restCall(HttpMethod.GET, String.class, null, path, Optional.empty()); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenCreateRestObjectIsCalledWithoutDefinedClient() { + // given + when(mockClient.target(any(String.class))).thenThrow(new MsoTestException("testNoClientException")); + + // when + restMsoImplementation.restCall(HttpMethod.GET, String.class, null, "", Optional.empty()); + } + + @Test + public void shouldProperlyPutRestObjectWithProperParametersAndStatusAccepted() { + // given + String method = "PUT"; + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),method); + + org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); + RestObject<String> response = new RestObject<>(); + + RestObject<String> expectedResponse = new RestObject<>(); + expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value()); + expectedResponse.set(rawData); + + // when + restMsoImplementation.Put("testPutBody", requestDetailsWrapper , path, response); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyPutRestObjectWithProperParametersAndStatusMultipleChoices() { + // given + String method = "PUT"; + prepareMocks(rawData,HttpStatus.MULTIPLE_CHOICES.value(),method); + + org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); + RestObject<String> response = new RestObject<>(); + + RestObject<String> expectedResponse = new RestObject<>(); + expectedResponse.setStatusCode(HttpStatus.MULTIPLE_CHOICES.value()); + expectedResponse.set(rawData); + + // when + restMsoImplementation.Put("testPutBody", requestDetailsWrapper , path, response); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenCallsPutWithWrongParameters() { + // given + when(mockClient.target(any(String.class))).thenThrow(new MsoTestException("testDeleteException")); + org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); + + // when + restMsoImplementation.Put(null, requestDetailsWrapper, "", null); + } + + @Test( expectedExceptions = NullPointerException.class) + public void shouldThrowExceptionWhenCallsPutWithWrongObjectType() { + // given + RestObject<HttpRequest> restObject = new RestObject<>(); + org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); + + prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE"); + + // when + restMsoImplementation.Put(null, requestDetailsWrapper, path, restObject); + } + + + + private void prepareMocks(String rawData,int status,String httpMethod) { + + when(mockClient.target(any(String.class))).thenReturn(webTarget); + when(webTarget.request()).thenReturn(builder); + + + when(builder.accept(any(String.class))).thenReturn(builder); + when(builder.headers(any(MultivaluedMap.class))).thenReturn(builder); + when(builder.get()).thenReturn(response); + + when(builder.build( eq(httpMethod), any(Entity.class))).thenReturn(jerseyInvocation); + when(builder.build( eq(httpMethod))).thenReturn(jerseyInvocation); + + when(builder.put( any(Entity.class))).thenReturn(response); + when(jerseyInvocation.invoke()).thenReturn(response); + + + when(response.getStatus()).thenReturn(status); + when(response.readEntity(String.class)).thenReturn(rawData); + } + + private class MsoTestException extends RuntimeException{ + MsoTestException(String testException) { + super(testException); + } + } + +}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java index 6114552e6..f58462dd6 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java @@ -468,10 +468,10 @@ public class MsoRestClientNewTest { private MsoRestClientNew msoRestClient() { final WebConfig webConfig = new WebConfig(); - return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl()); + return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl(),null); } private MsoRestClientNew createTestSubject() { - return new MsoRestClientNew(null, ""); + return new MsoRestClientNew(null, "",null); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java index 5a0f93b45..39d633f70 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java @@ -20,65 +20,795 @@ */ package org.onap.vid.mso.rest; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.json.JSONObject; -import org.junit.Assert; +import io.joshworks.restclient.http.HttpResponse; +import io.joshworks.restclient.http.JsonMapper; +import org.apache.http.ProtocolVersion; +import org.apache.http.StatusLine; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; +import org.mockito.Mock; import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.changeManagement.RequestDetails; +import org.onap.vid.changeManagement.RelatedInstanceList; +import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.client.SyncRestClient; import org.onap.vid.controller.LocalWebConfig; -import org.onap.vid.mso.MsoBusinessLogic; -import org.onap.vid.mso.MsoBusinessLogicImpl; +import org.onap.vid.model.RequestReferencesContainer; +import org.onap.vid.mso.MsoResponseWrapper; +import org.onap.vid.mso.MsoResponseWrapperInterface; +import org.onap.vid.mso.MsoUtil; +import org.onap.vid.mso.RestObject; import org.onap.vid.mso.model.CloudConfiguration; import org.onap.vid.mso.model.ModelInfo; import org.onap.vid.mso.model.RequestInfo; import org.onap.vid.mso.model.RequestParameters; +import org.onap.vid.mso.model.RequestReferences; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.web.WebAppConfiguration; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import static org.mockito.ArgumentMatchers.any; + +import java.util.LinkedList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + @ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class}) @WebAppConfiguration public class MsoRestClientTest { - private MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogicImpl(new MsoRestClientNew(new SyncRestClient(), ""), null); - private ObjectMapper om = new ObjectMapper(); + private final String baseUrl = "http://testURL/"; + + @Mock + private SyncRestClient client; + + private MsoRestClientNew restClient; + + + @BeforeClass + private void setUp(){ + initMocks(this); + restClient = new MsoRestClientNew(client,baseUrl,null); + + } @Test - public void createInPlaceMsoRequest() { - String result = null; - try { - RequestDetails requestDetails = generateMockMsoRequest(); - result = om.writeValueAsString(msoBusinessLogic.generateInPlaceMsoRequest(requestDetails)); - } catch (Exception e) { - e.printStackTrace(); - } - if (result == null) { - Assert.fail("Failed to create mso request"); + public void shouldProperlyCreateServiceInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.createSvcInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenCreateSvcInstanceGetsWrongParameters() { + // given + String endpoint = ""; + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(null),eq(String.class) ) ). + thenThrow(new MsoTestException("test-post-exception")); + + // when + restClient.createSvcInstance(null,endpoint); + } + + @Test + public void shouldProperlyCreateE2eSvcInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.createE2eSvcInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyCreateVnf() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.createVnf(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyCreateNwInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.createNwInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyCreateVolumeGroupInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.createVolumeGroupInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyCreateVfModuleInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.createVfModuleInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyScaleOutVFModuleInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + RequestDetailsWrapper<RequestDetails> wrappedRequestDetails = new RequestDetailsWrapper<>(requestDetails); + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.scaleOutVFModuleInstance(wrappedRequestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyCreateConfigurationInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails); + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.createConfigurationInstance(wrappedRequestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyDeleteE2eSvcInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails); + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(wrappedRequestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.deleteE2eSvcInstance(wrappedRequestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyDeleteSvcInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.deleteSvcInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyUnassignSvcInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.unassignSvcInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyDeleteVnf() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.deleteVnf(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyDeleteVfModule() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.deleteVfModule(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyDeleteVolumeGroupInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.deleteVolumeGroupInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyDeleteNwInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.delete( eq(baseUrl+endpoint),anyMap(),eq(requestDetails),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.deleteNwInstance(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyGetOrchestrationRequest() { + // given + RestObject restObject = generateMockMsoRestObject(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.getOrchestrationRequest(null,null,endpoint,restObject,true); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyGetOrchestrationRequestWithOnlyEndpoint() { + // given + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.getOrchestrationRequest(endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyGetManualTasks() { + // given + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.getManualTasks(endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyGetManualTasksByRequestId() { + // given + RestObject restObject = generateMockMsoRestObject(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + /// WUT 'baseUrl+baseUrl+endpoint' + when( client.get( eq(baseUrl+baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.getManualTasksByRequestId(null,null,endpoint,restObject); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test(expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenGetManualTasksByRequestIdGetsWrongParameter() { + // given + when( client.get( eq(baseUrl+baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException")); + + // when + restClient.getManualTasksByRequestId(null,null,"",null); + } + + @Test + public void shouldProperlyCompleteManualTask() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + RestObject restObject = generateMockMsoRestObject(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint), anyMap(), eq(requestDetails), eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.completeManualTask(requestDetails,null,null,endpoint,restObject); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test(expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenCompleteManualTaskWrongParameter() { + // given + when( client.post( eq(baseUrl),anyMap(),eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("testsException")); + + // when + restClient.completeManualTask(null, null,null,"",null); + } + + @Test + public void shouldProperlyReplaceVnf() { + // given + org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test + public void shouldProperlyReplaceVnfWithStatus202() { + // given + org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = createOkResponse(); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.post( eq(baseUrl+endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.replaceVnf(requestDetails,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenReplaceVnfGetsWrongParameters() { + // given + org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + + when( client.post( eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenThrow(new MsoTestException("test-post-exception")); + + // when + restClient.replaceVnf(requestDetails, ""); + } + + @Test + public void shouldProperlyDeleteConfiguration() { + // given + org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when( client.delete( eq(baseUrl+endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class) ) ).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.deleteConfiguration(requestDetailsWrapper,endpoint); + + // then + assertThat(response).isEqualToComparingFieldByField(expectedResponse); + } + + @Test( expectedExceptions = MsoTestException.class ) + public void shouldThrowExceptionWhenProperlyDeleteConfigurationGetsWrongParameters() { + // given + when( client.delete( eq(baseUrl), anyMap(), eq(null), eq(String.class) ) ).thenThrow(new MsoTestException("test-delete-exception")); + + // when + restClient.deleteConfiguration(null,""); + } + + @Test + public void shouldProperlySetConfigurationActiveStatus() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.setConfigurationActiveStatus(requestDetails, endpoint); + + // then + assertThat(expectedResponse).isEqualToComparingFieldByField(response); + } + + @Test(expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenSetConfigurationActiveStatusGetsWrongParameters() { + // given + + when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception")); + + // when + restClient.setConfigurationActiveStatus(null, ""); + } + + @Test + public void shouldProperlySetPortOnConfigurationStatus() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.setPortOnConfigurationStatus(requestDetails, endpoint); + + // then + assertThat(expectedResponse).isEqualToComparingFieldByField(response); + } + + @Test(expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenSetPortOnConfigurationStatusGetsWrongParameters() { + // given + String endpoint = ""; + + when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception")); + + // when + restClient.setPortOnConfigurationStatus(null, endpoint); + } + + @Test + public void shouldProperlyChangeManagementUpdate() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails); + + String endpoint = "testEndpoint"; + HttpResponse<RequestReferencesContainer> httpResponse = HttpResponse.fallback( + new RequestReferencesContainer( + new RequestReferences())); + + MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(RequestReferencesContainer.class))).thenReturn(httpResponse); + + // when + MsoResponseWrapperInterface response = restClient.changeManagementUpdate(requestDetailsWrapper, endpoint); + + // then + assertThat(expectedResponse).isEqualToComparingFieldByField(response); + } + + @Test + public void shouldProperlyUpdateVnfAndUpdateInstance() { + // given + org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapperInterface expectedResponse = MsoUtil.wrapResponse(httpResponse); + + + when(client.put(eq(baseUrl + endpoint), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenReturn(httpResponse); + + // when + MsoResponseWrapperInterface response = restClient.updateVnf(requestDetails, endpoint); + + // then + assertThat(expectedResponse).isEqualToComparingFieldByField(response); + } + + @Test( expectedExceptions = MsoTestException.class ) + public void shouldThrowExceptionWhenUpdateVnfAndUpdateInstanceGetsWrongParameter() { + // given + org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + String endpoint = ""; + + when(client.put(eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenThrow(new MsoTestException("test-post-exception")); + + // when + restClient.updateVnf(requestDetails, endpoint); + + // then + } + + @Test + public void shouldProperlySetServiceInstanceStatus() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + RestObject<String> restObject = generateMockMsoRestObject(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + + when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse); + + // when + restClient.setServiceInstanceStatus(requestDetails,"", "", endpoint, restObject); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenSetServiceInstanceStatusGetsWrongParameter() { + // given + String endpoint = ""; + + when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception")); + + // when + restClient.setServiceInstanceStatus(null,"", "", endpoint, null); + } + + @Test + public void shouldProperlyRemoveRelationshipFromServiceInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.removeRelationshipFromServiceInstance(requestDetails, endpoint); + + // then + assertThat(expectedResponse).isEqualToComparingFieldByField(response); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenRemoveRelationshipFromServiceInstanceGetsWrongParameter() { + // given + String endpoint = ""; + + when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception")); + + // when + restClient.removeRelationshipFromServiceInstance(null,endpoint); + } + + @Test + public void shouldProperlyAddRelationshipToServiceInstance() { + // given + RequestDetails requestDetails = generateMockMsoRequest(); + + String endpoint = "testEndpoint"; + HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); + MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse); + + when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse); + + // when + MsoResponseWrapper response = restClient.addRelationshipToServiceInstance(requestDetails, endpoint); + + // then + assertThat(expectedResponse).isEqualToComparingFieldByField(response); + } + + @Test( expectedExceptions = MsoTestException.class) + public void shouldThrowExceptionWhenAddRelationshipToServiceInstanceGetsWrongParameter() { + // given + String endpoint = ""; + + when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception")); + + // when + restClient.addRelationshipToServiceInstance(null,endpoint); + } + + @Test + public void shouldProperlyPerformGetRequest() { + // given + String endpoint = "testEndpoint"; + HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse"); + + when(client.get(eq(baseUrl + endpoint), anyMap(), anyMap(), eq(String.class))).thenReturn(expectedResponse); + + // when + HttpResponse<String> response = restClient.get(endpoint, String.class); + + // then + assertThat(expectedResponse).isEqualToComparingFieldByField(response); + } + + @Test + public void shouldProperlyPerformPostRequest() { + // given + + RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(generateMockMsoRequest()); + + String endpoint = "testEndpoint"; + HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse"); + + when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetailsWrapper), eq(String.class))).thenReturn(expectedResponse); + + // when + HttpResponse<String> response = restClient.post(endpoint,requestDetailsWrapper, String.class); + + // then + assertThat(expectedResponse).isEqualToComparingFieldByField(response); + } + + private class MsoTestException extends RuntimeException{ + MsoTestException(String testException) { + super(testException); } - JSONObject jsonObj = new JSONObject(result); - Assert.assertNotNull(jsonObj.getJSONObject("requestDetails")); + } + + private HttpResponse<String> createOkResponse() { + StatusLine statusline = new BasicStatusLine( + new ProtocolVersion("http",1,1), 202, "acceptResponse"); + + org.apache.http.HttpResponse responseBase = new BasicHttpResponse(statusline); + + return new HttpResponse<>(responseBase ,String.class, new JsonMapper()); } private RequestDetails generateMockMsoRequest() { RequestDetails requestDetails = new RequestDetails(); - requestDetails.setVnfInstanceId("vnf-instance-id"); - requestDetails.setVnfName("vnf-name"); + CloudConfiguration cloudConfiguration = new CloudConfiguration(); cloudConfiguration.setTenantId("tenant-id"); cloudConfiguration.setLcpCloudRegionId("lcp-region"); requestDetails.setCloudConfiguration(cloudConfiguration); + ModelInfo modelInfo = new ModelInfo(); modelInfo.setModelInvariantId("model-invarient-id"); modelInfo.setModelCustomizationName("modelCustomizationName"); + modelInfo.setModelType("test-model-type"); requestDetails.setModelInfo(modelInfo); + RequestInfo requestInfo = new RequestInfo(); requestInfo.setRequestorId("ok883e"); requestInfo.setSource("VID"); requestDetails.setRequestInfo(requestInfo); RequestParameters requestParameters = new RequestParameters(); + requestParameters.setSubscriptionServiceType("subscriber-service-type"); requestParameters.setAdditionalProperty("a", 1); requestParameters.setAdditionalProperty("b", 2); @@ -90,4 +820,52 @@ public class MsoRestClientTest { requestDetails.setRequestParameters(requestParameters); return requestDetails; } + + private org.onap.vid.changeManagement.RequestDetails generateChangeManagementMockMsoRequest() { + List<RelatedInstanceList> relatedInstances = new LinkedList<>(); + relatedInstances.add(new RelatedInstanceList()); + + org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails(); + + requestDetails.setVnfName("test-vnf-name"); + requestDetails.setVnfInstanceId("test-vnf-instance_id"); + requestDetails.setRelatedInstList(relatedInstances); + + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setTenantId("tenant-id"); + cloudConfiguration.setLcpCloudRegionId("lcp-region"); + requestDetails.setCloudConfiguration(cloudConfiguration); + + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId("model-invarient-id"); + modelInfo.setModelCustomizationName("modelCustomizationName"); + modelInfo.setModelType("test-model-type"); + requestDetails.setModelInfo(modelInfo); + + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setRequestorId("ok883e"); + requestInfo.setSource("VID"); + requestDetails.setRequestInfo(requestInfo); + + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setSubscriptionServiceType("subscriber-service-type"); + requestParameters.setAdditionalProperty("a", 1); + requestParameters.setAdditionalProperty("b", 2); + requestParameters.setAdditionalProperty("c", 3); + requestParameters.setAdditionalProperty("d", 4); + String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}"; + requestParameters.setAdditionalProperty("payload", payload); + + requestDetails.setRequestParameters(requestParameters); + return requestDetails; + } + + private RestObject<String> generateMockMsoRestObject() { + RestObject<String> restObject = new RestObject<>(); + + restObject.set("test-rest-object-body"); + restObject.setRaw("test-rest-object-raw-string"); + restObject.setStatusCode(202); + return restObject; + } } diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java index b66899c31..e638605c1 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java @@ -26,6 +26,7 @@ import org.apache.commons.io.IOUtils; import org.mockito.ArgumentCaptor; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.util.HttpsAuthClient; import org.onap.vid.changeManagement.ChangeManagementRequest; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.client.SyncRestClient; @@ -116,11 +117,6 @@ public class ChangeManagementServiceUnitTest extends AbstractTestNGSpringContext @Configuration public static class TestMsoConfig extends MsoConfig { - public MsoRestClientNew getMsoClient() { - MsoRestClientNew spyClient = spy(new MsoRestClientNew(new SyncRestClient(), "")); - return spyClient; - } - @Bean public ChangeManagementService getChangeManagementService(DataAccessService dataAccessService, MsoBusinessLogic msoInterface, SchedulerRestInterfaceIfc schedulerRestInterface, CloudOwnerService cloudOwnerService) { return new ChangeManagementServiceImpl(dataAccessService, msoInterface, schedulerRestInterface, cloudOwnerService); |